forked from MagicBane/Server
Item requirements and restrictions refactored.
This commit is contained in:
@@ -17,6 +17,7 @@ import org.pmw.tinylog.Logger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ItemTemplate {
|
||||
|
||||
@@ -376,4 +377,94 @@ public class ItemTemplate {
|
||||
|
||||
return template.item_eq_slots_or.contains(EnumSet.of(Enum.ItemEquipSlotType.LHELD, Enum.ItemEquipSlotType.RHELD));
|
||||
}
|
||||
|
||||
|
||||
public static Boolean ValidRace(Item item, Enum.MonsterType race) {
|
||||
|
||||
if (item.template.item_race_req.isEmpty() && item.template.item_race_res.isEmpty())
|
||||
return true;
|
||||
|
||||
if (item.template.item_race_req.isEmpty() == false)
|
||||
if (item.template.item_race_req.contains(race))
|
||||
return true;
|
||||
|
||||
if (item.template.item_race_res.isEmpty() == false)
|
||||
if (item.template.item_class_res.contains(race) == false)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean ValidClass(Item item, Enum.ClassType base, Enum.ClassType profession) {
|
||||
|
||||
// Early exit if no entry
|
||||
|
||||
if (item.template.item_class_req.isEmpty() && item.template.item_class_res.isEmpty())
|
||||
return true;
|
||||
|
||||
if (item.template.item_class_req.isEmpty() == false)
|
||||
if (item.template.item_class_req.contains(base) || item.template.item_class_req.contains(profession))
|
||||
return true;
|
||||
|
||||
if (item.template.item_class_res.isEmpty() == false)
|
||||
if (item.template.item_class_res.contains(base) == false && item.template.item_class_res.contains(profession) == false)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean ValidDiscipline(Item item, EnumSet<Enum.DisciplineType> discs) {
|
||||
|
||||
// Early exit if no entry
|
||||
|
||||
if (item.template.item_disc_req.isEmpty() && item.template.item_disc_res.isEmpty())
|
||||
return true;
|
||||
|
||||
EnumSet<Enum.DisciplineType> workSet = EnumSet.copyOf(discs);
|
||||
|
||||
if (item.template.item_disc_req.isEmpty() == false) {
|
||||
|
||||
workSet.retainAll(item.template.item_disc_req);
|
||||
|
||||
if (workSet.isEmpty() == false)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.template.item_disc_res.isEmpty() == false) {
|
||||
|
||||
workSet.retainAll(item.template.item_disc_res);
|
||||
|
||||
if (workSet.isEmpty() == false)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Boolean canCharacterEquip(Item item, AbstractCharacter character) {
|
||||
return ValidRace(item, character.absRace) && ValidClass(item, character.absBaseClass, character.absPromotionClass) && ValidDiscipline(item, character.absDisciplines);
|
||||
}
|
||||
|
||||
public static boolean validForSkills(Item item, ConcurrentHashMap<String, CharacterSkill> skills) {
|
||||
|
||||
CharacterSkill characterSkill;
|
||||
|
||||
if (item.template.item_skill_required.isEmpty())
|
||||
return true;
|
||||
|
||||
for (String skillRequired : item.template.item_skill_required.keySet()) {
|
||||
|
||||
int required_value = item.template.item_skill_required.get(skillRequired);
|
||||
characterSkill = skills.get(skillRequired);
|
||||
|
||||
if (characterSkill == null)
|
||||
return false;
|
||||
|
||||
if (characterSkill.getModifiedAmountBeforeMods() > required_value)
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user