forked from MagicBane/Server
				
			
				 9 changed files with 211 additions and 196 deletions
			
			
		@ -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); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue