ItemManager created
This commit is contained in:
@@ -11,6 +11,7 @@ package engine.devcmd.cmds;
|
|||||||
|
|
||||||
import engine.Enum;
|
import engine.Enum;
|
||||||
import engine.devcmd.AbstractDevCmd;
|
import engine.devcmd.AbstractDevCmd;
|
||||||
|
import engine.gameManager.ItemManager;
|
||||||
import engine.objects.*;
|
import engine.objects.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +88,7 @@ public class PrintStatsCmd extends AbstractDevCmd {
|
|||||||
//get weapons
|
//get weapons
|
||||||
|
|
||||||
if (tar.charItemManager.equipped.isEmpty() == false)
|
if (tar.charItemManager.equipped.isEmpty() == false)
|
||||||
if (tar.charItemManager.equipped.get(Enum.EquipSlotType.LHELD) != null && !ItemTemplate.isShield(tar.charItemManager.equipped.get(Enum.EquipSlotType.LHELD))) {
|
if (tar.charItemManager.equipped.get(Enum.EquipSlotType.LHELD) != null && !ItemManager.isShield(tar.charItemManager.equipped.get(Enum.EquipSlotType.LHELD))) {
|
||||||
//off hand weapon
|
//off hand weapon
|
||||||
out += "Attack Rating: " + tar.atrHandTwo + newline;
|
out += "Attack Rating: " + tar.atrHandTwo + newline;
|
||||||
out += "Damage: " + tar.minDamageHandTwo + " - " + tar.maxDamageHandTwo + newline;
|
out += "Damage: " + tar.minDamageHandTwo + " - " + tar.maxDamageHandTwo + newline;
|
||||||
|
|||||||
@@ -490,7 +490,7 @@ public enum CombatManager {
|
|||||||
return 75;
|
return 75;
|
||||||
else if (required.equals("Sword")) {
|
else if (required.equals("Sword")) {
|
||||||
|
|
||||||
if (ItemTemplate.isTwoHanded(template))
|
if (ItemManager.isTwoHanded(template))
|
||||||
return 105;
|
return 105;
|
||||||
else
|
else
|
||||||
return 98;
|
return 98;
|
||||||
@@ -500,7 +500,7 @@ public enum CombatManager {
|
|||||||
} else if (required.equals("Spear")) {
|
} else if (required.equals("Spear")) {
|
||||||
return 92;
|
return 92;
|
||||||
} else if (required.equals("Hammer") || required.equals("Axe")) {
|
} else if (required.equals("Hammer") || required.equals("Axe")) {
|
||||||
if (ItemTemplate.isTwoHanded(template)) {
|
if (ItemManager.isTwoHanded(template)) {
|
||||||
return 105;
|
return 105;
|
||||||
} else if (mastery.equals("Throwing")) {
|
} else if (mastery.equals("Throwing")) {
|
||||||
return 115;
|
return 115;
|
||||||
@@ -517,7 +517,7 @@ public enum CombatManager {
|
|||||||
return 110;
|
return 110;
|
||||||
} else if (required.equals("Bow")) {
|
} else if (required.equals("Bow")) {
|
||||||
return 109;
|
return 109;
|
||||||
} else if (ItemTemplate.isTwoHanded(template)) {
|
} else if (ItemManager.isTwoHanded(template)) {
|
||||||
return 105;
|
return 105;
|
||||||
} else {
|
} else {
|
||||||
return 100;
|
return 100;
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
package engine.gameManager;
|
||||||
|
|
||||||
|
import engine.Enum;
|
||||||
|
import engine.objects.*;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// Magicbane Emulator Project © 2013 - 2022
|
||||||
|
// www.magicbane.com
|
||||||
|
|
||||||
|
public enum ItemManager {
|
||||||
|
ITEMMANAGER;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTwoHanded(Item item) {
|
||||||
|
|
||||||
|
if (!item.template.item_type.equals(Enum.ItemType.WEAPON))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return item.template.item_eq_slots_and.contains(EnumSet.of(Enum.EquipSlotType.LHELD, Enum.EquipSlotType.RHELD));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTwoHanded(ItemTemplate template) {
|
||||||
|
|
||||||
|
if (!template.item_type.equals(Enum.ItemType.WEAPON))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return template.item_eq_slots_and.contains(EnumSet.of(Enum.EquipSlotType.LHELD, Enum.EquipSlotType.RHELD));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isShield(Item item) {
|
||||||
|
|
||||||
|
if (item.template.item_skill_required.containsKey("Block"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isShield(ItemTemplate template) {
|
||||||
|
|
||||||
|
if (template.item_skill_required.containsKey("Block"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean validForSlot(Enum.EquipSlotType slot, ConcurrentHashMap<Enum.EquipSlotType, Item> equipped, Item item) {
|
||||||
|
|
||||||
|
boolean validSlot = false;
|
||||||
|
|
||||||
|
if (equipped == null)
|
||||||
|
return false;
|
||||||
|
//Item not valid for slot
|
||||||
|
|
||||||
|
if (item.template.item_eq_slots_or.contains(slot) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Slot is taken
|
||||||
|
|
||||||
|
if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Two handed weapons take up two slots
|
||||||
|
|
||||||
|
if ((isTwoHanded(item)) &&
|
||||||
|
((slot == Enum.EquipSlotType.LHELD && equipped.get(Enum.EquipSlotType.RHELD) != null) ||
|
||||||
|
(slot == Enum.EquipSlotType.RHELD && equipped.get(Enum.EquipSlotType.LHELD) != null)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (item.template.item_type.equals(Enum.ItemType.WEAPON))
|
||||||
|
if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canEquip(Enum.EquipSlotType slot, CharacterItemManager itemManager, AbstractCharacter abstractCharacter, Item item) {
|
||||||
|
|
||||||
|
if (itemManager == null || abstractCharacter == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Early exit for mobiles and NPCS.
|
||||||
|
// Perhaps not needed now that mobs have skills.
|
||||||
|
|
||||||
|
if (EnumSet.of(Enum.GameObjectType.NPC, Enum.GameObjectType.Mob).contains(abstractCharacter.getObjectType()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!validForSlot(slot, itemManager.getEquipped(), item))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!validForSkills(item, abstractCharacter.getSkills()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (canCharacterEquip(item, abstractCharacter) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//players can't wear 0 value items.
|
||||||
|
|
||||||
|
return item.template.item_value != 0 || Kit.IsNoobGear(item.templateID);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -322,7 +322,7 @@ public enum NPCManager {
|
|||||||
guard.maxDamageHandOne = (int) ((guard.mobBase.getDamageMax() + weapon.template.item_weapon_damage.values().iterator().next()[1]) * rankModifier) + primaryStat;
|
guard.maxDamageHandOne = (int) ((guard.mobBase.getDamageMax() + weapon.template.item_weapon_damage.values().iterator().next()[1]) * rankModifier) + primaryStat;
|
||||||
guard.speedHandOne = weapon.template.item_weapon_wepspeed;
|
guard.speedHandOne = weapon.template.item_weapon_wepspeed;
|
||||||
guard.rangeHandOne = weapon.template.item_weapon_max_range;
|
guard.rangeHandOne = weapon.template.item_weapon_max_range;
|
||||||
} else if (guard.charItemManager.equipped.containsKey(Enum.EquipSlotType.LHELD) && !ItemTemplate.isShield(guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template)) {
|
} else if (guard.charItemManager.equipped.containsKey(Enum.EquipSlotType.LHELD) && !ItemManager.isShield(guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template)) {
|
||||||
//has off hand weapon
|
//has off hand weapon
|
||||||
Item weapon = guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD);
|
Item weapon = guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD);
|
||||||
if (weapon.template.item_primary_attr.equals(Enum.AttributeType.Strength))
|
if (weapon.template.item_primary_attr.equals(Enum.AttributeType.Strength))
|
||||||
@@ -350,7 +350,7 @@ public enum NPCManager {
|
|||||||
int baseDef = guard.mobBase.getDefenseRating();
|
int baseDef = guard.mobBase.getDefenseRating();
|
||||||
int armorDefense = 0;
|
int armorDefense = 0;
|
||||||
for (Item equipped : guard.charItemManager.equipped.values())
|
for (Item equipped : guard.charItemManager.equipped.values())
|
||||||
if (equipped.template.item_type.equals(Enum.ItemType.ARMOR) || ItemTemplate.isShield(equipped.template))
|
if (equipped.template.item_type.equals(Enum.ItemType.ARMOR) || ItemManager.isShield(equipped.template))
|
||||||
armorDefense += equipped.template.item_defense_rating;
|
armorDefense += equipped.template.item_defense_rating;
|
||||||
guard.defenseRating = dexterity + baseDef + armorDefense;
|
guard.defenseRating = dexterity + baseDef + armorDefense;
|
||||||
}
|
}
|
||||||
@@ -360,7 +360,7 @@ public enum NPCManager {
|
|||||||
int baseAtr = guard.mobBase.getAttackRating();
|
int baseAtr = guard.mobBase.getAttackRating();
|
||||||
if (guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD) != null)
|
if (guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD) != null)
|
||||||
guard.atrHandOne = baseAtr + (int) ((strength * 0.5f) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD).template.item_skill_required.values().toArray()[0] * 4) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD).template.item_skill_required.values().toArray()[0] * 3));
|
guard.atrHandOne = baseAtr + (int) ((strength * 0.5f) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD).template.item_skill_required.values().toArray()[0] * 4) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.RHELD).template.item_skill_required.values().toArray()[0] * 3));
|
||||||
else if (guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD) != null && !ItemTemplate.isShield(guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template))
|
else if (guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD) != null && !ItemManager.isShield(guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template))
|
||||||
guard.atrHandTwo = baseAtr + (int) ((strength * 0.5f) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template.item_skill_required.values().toArray()[0] * 4) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template.item_skill_required.values().toArray()[0] * 3));
|
guard.atrHandTwo = baseAtr + (int) ((strength * 0.5f) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template.item_skill_required.values().toArray()[0] * 4) + ((int) guard.charItemManager.equipped.get(Enum.EquipSlotType.LHELD).template.item_skill_required.values().toArray()[0] * 3));
|
||||||
else
|
else
|
||||||
guard.atrHandOne = baseAtr;
|
guard.atrHandOne = baseAtr;
|
||||||
|
|||||||
@@ -909,7 +909,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
|
|||||||
if (shield == null)
|
if (shield == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ItemTemplate.isShield(shield) == false)
|
if (ItemManager.isShield(shield) == false)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ItemTemplate template = shield.template;
|
ItemTemplate template = shield.template;
|
||||||
@@ -995,7 +995,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
|
|||||||
|
|
||||||
if (weapon == null) {
|
if (weapon == null) {
|
||||||
weapon = equipped.get(EquipSlotType.LHELD);
|
weapon = equipped.get(EquipSlotType.LHELD);
|
||||||
if (weapon == null || ItemTemplate.isShield(weapon))
|
if (weapon == null || ItemManager.isShield(weapon))
|
||||||
unarmed = true;
|
unarmed = true;
|
||||||
else
|
else
|
||||||
weaponTemplate = weapon.template;
|
weaponTemplate = weapon.template;
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ package engine.objects;
|
|||||||
import engine.Enum;
|
import engine.Enum;
|
||||||
import engine.Enum.GameObjectType;
|
import engine.Enum.GameObjectType;
|
||||||
import engine.Enum.ItemType;
|
import engine.Enum.ItemType;
|
||||||
import engine.gameManager.BuildingManager;
|
import engine.gameManager.*;
|
||||||
import engine.gameManager.ChatManager;
|
|
||||||
import engine.gameManager.ConfigManager;
|
|
||||||
import engine.gameManager.DbManager;
|
|
||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
import engine.net.Dispatch;
|
import engine.net.Dispatch;
|
||||||
import engine.net.DispatchMessage;
|
import engine.net.DispatchMessage;
|
||||||
@@ -923,7 +920,7 @@ public class CharacterItemManager {
|
|||||||
if (!this.inventory.contains(i) && this.absCharacter.getObjectType() != GameObjectType.Mob)
|
if (!this.inventory.contains(i) && this.absCharacter.getObjectType() != GameObjectType.Mob)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!ItemTemplate.canEquip(slot, this, absCharacter, i) && this.absCharacter.getObjectType() != GameObjectType.Mob)
|
if (!ItemManager.canEquip(slot, this, absCharacter, i) && this.absCharacter.getObjectType() != GameObjectType.Mob)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// check to see if item is already there.
|
// check to see if item is already there.
|
||||||
@@ -1486,7 +1483,7 @@ public class CharacterItemManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ItemTemplate.validForSkills(item, pc.getSkills())) {
|
if (!ItemManager.validForSkills(item, pc.getSkills())) {
|
||||||
this.forceToInventory(slot, item, pc, initialized);
|
this.forceToInventory(slot, item, pc, initialized);
|
||||||
pc.applyBonuses();
|
pc.applyBonuses();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public class ItemFactory {
|
|||||||
case "Hammer":
|
case "Hammer":
|
||||||
case "Unarmed Combat":
|
case "Unarmed Combat":
|
||||||
|
|
||||||
if (ItemTemplate.isTwoHanded(template))
|
if (ItemManager.isTwoHanded(template))
|
||||||
galvorAmount = 20;
|
galvorAmount = 20;
|
||||||
else
|
else
|
||||||
galvorAmount = 10;
|
galvorAmount = 10;
|
||||||
@@ -819,7 +819,7 @@ public class ItemFactory {
|
|||||||
case "Hammer":
|
case "Hammer":
|
||||||
case "Unarmed Combat":
|
case "Unarmed Combat":
|
||||||
|
|
||||||
if (ItemTemplate.isTwoHanded(template))
|
if (ItemManager.isTwoHanded(template))
|
||||||
galvorAmount = 22;
|
galvorAmount = 22;
|
||||||
else
|
else
|
||||||
galvorAmount = 11;
|
galvorAmount = 11;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import org.pmw.tinylog.Logger;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class ItemTemplate {
|
public class ItemTemplate {
|
||||||
|
|
||||||
@@ -405,183 +404,6 @@ public class ItemTemplate {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.error(e);
|
Logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTwoHanded(Item item) {
|
|
||||||
|
|
||||||
if (!item.template.item_type.equals(Enum.ItemType.WEAPON))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return item.template.item_eq_slots_and.contains(EnumSet.of(Enum.EquipSlotType.LHELD, Enum.EquipSlotType.RHELD));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isTwoHanded(ItemTemplate template) {
|
|
||||||
|
|
||||||
if (!template.item_type.equals(Enum.ItemType.WEAPON))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return template.item_eq_slots_and.contains(EnumSet.of(Enum.EquipSlotType.LHELD, Enum.EquipSlotType.RHELD));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isShield(Item item) {
|
|
||||||
|
|
||||||
if (item.template.item_skill_required.containsKey("Block"))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isShield(ItemTemplate template) {
|
|
||||||
|
|
||||||
if (template.item_skill_required.containsKey("Block"))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean validForSlot(Enum.EquipSlotType slot, ConcurrentHashMap<Enum.EquipSlotType, Item> equipped, Item item) {
|
|
||||||
|
|
||||||
boolean validSlot = false;
|
|
||||||
|
|
||||||
if (equipped == null)
|
|
||||||
return false;
|
|
||||||
//Item not valid for slot
|
|
||||||
|
|
||||||
if (item.template.item_eq_slots_or.contains(slot) == false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Slot is taken
|
|
||||||
|
|
||||||
if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Two handed weapons take up two slots
|
|
||||||
|
|
||||||
if ((isTwoHanded(item)) &&
|
|
||||||
((slot == Enum.EquipSlotType.LHELD && equipped.get(Enum.EquipSlotType.RHELD) != null) ||
|
|
||||||
(slot == Enum.EquipSlotType.RHELD && equipped.get(Enum.EquipSlotType.LHELD) != null)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (item.template.item_type.equals(Enum.ItemType.WEAPON))
|
|
||||||
if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canEquip(Enum.EquipSlotType slot, CharacterItemManager itemManager, AbstractCharacter abstractCharacter, Item item) {
|
|
||||||
|
|
||||||
if (itemManager == null || abstractCharacter == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Early exit for mobiles and NPCS.
|
|
||||||
// Perhaps not needed now that mobs have skills.
|
|
||||||
|
|
||||||
if (EnumSet.of(Enum.GameObjectType.NPC, Enum.GameObjectType.Mob).contains(abstractCharacter.getObjectType()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!validForSlot(slot, itemManager.getEquipped(), item))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!validForSkills(item, abstractCharacter.getSkills()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (canCharacterEquip(item, abstractCharacter) == false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//players can't wear 0 value items.
|
|
||||||
|
|
||||||
return item.template.item_value != 0 || Kit.IsNoobGear(item.templateID);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3776,7 +3776,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
|||||||
//set block if block found
|
//set block if block found
|
||||||
this.bonuses.setBool(ModType.Block, SourceType.None, false);
|
this.bonuses.setBool(ModType.Block, SourceType.None, false);
|
||||||
if (this.baseClass != null && (this.baseClass.getObjectUUID() == 2500 || this.baseClass.getObjectUUID() == 2501))
|
if (this.baseClass != null && (this.baseClass.getObjectUUID() == 2500 || this.baseClass.getObjectUUID() == 2501))
|
||||||
if (off != null && off.template != null && ItemTemplate.isShield(off))
|
if (off != null && off.template != null && ItemManager.isShield(off))
|
||||||
this.bonuses.setBool(ModType.Block, SourceType.None, true);
|
this.bonuses.setBool(ModType.Block, SourceType.None, true);
|
||||||
|
|
||||||
//set dodge if rogue
|
//set dodge if rogue
|
||||||
|
|||||||
Reference in New Issue
Block a user