From 8a769c60f20b1c9c965aaff3f107d8d8c2ef1896 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 13 Feb 2024 20:35:25 -0600 Subject: [PATCH] implement server side restrictions --- src/engine/Enum.java | 3 + src/engine/objects/AbstractCharacter.java | 7 +- src/engine/objects/ItemBase.java | 79 +++++++++++++---------- src/engine/objects/PlayerCharacter.java | 12 +++- 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 5889059c..a171d4d9 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -2767,6 +2767,9 @@ public class Enum { return leadershipTypes[i]; } + public boolean canJoin(AbstractCharacter character){ + return this.requiredRaces.contains(character.absRace) && this.requiredClasses.contains(character.absPromotionClass) && this.sexRequired.contains(character.absGender); + } } public enum MinionClass { diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 12898d1a..3c953c9b 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -35,6 +35,7 @@ import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -124,10 +125,12 @@ public abstract class AbstractCharacter extends AbstractWorldObject { public ArrayList runes; - public Enum.MonsterType absRace = null; - public ClassType absClass = null; + public Enum.MonsterType absRace; + public ClassType absBaseClass = null; + public ClassType absPromotionClass = null; public Enum.SexType absGender = null; + public EnumSet absDisciplines; public AbstractCharacter() { super(); diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index 269c073d..4200ab7f 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -486,13 +486,7 @@ public class ItemBase { if (!validForSkills(abstractCharacter.getSkills())) return false; - if (!validRace(item.getItemBase(), abstractCharacter)) - return false; - - if (!validClass(item.getItemBase(), abstractCharacter)) - return false; - - if (!validDisc(item.getItemBase(), abstractCharacter)) + if(this.canCharacterEquip(abstractCharacter) == false) return false; return item.getItemBase().value != 0 || Kit.IsNoobGear(item.getItemBase().uuid); @@ -502,34 +496,6 @@ public class ItemBase { return true; //Mobiles and NPC's don't need to check equip } - - public static boolean validRace(ItemBase ib, AbstractCharacter absChar){ - if(ib.requiredRaces == null || ib.requiredRaces.isEmpty()) - if(ib.restrictedRaces == null || ib.restrictedRaces.isEmpty()) - return true; - - return ib.requiredRaces.contains(absChar.absRace) && !ib.restrictedRaces.contains(absChar.absRace); - } - public static boolean validClass(ItemBase ib, AbstractCharacter absChar){ - if(ib.requiredClasses == null || ib.requiredClasses.isEmpty()) - if(ib.restrictedClasses == null || ib.restrictedClasses.isEmpty()) - return true; - - return ib.requiredClasses.contains(absChar.absClass) && !ib.restrictedClasses.contains(absChar.absClass); - } - - public static boolean validDisc(ItemBase ib, AbstractCharacter absChar){ - - if(ib.requiredDiscs == null || ib.requiredDiscs.isEmpty()) - if(ib.restrictedDiscs == null || ib.restrictedDiscs.isEmpty()) - return true; - - for(CharacterRune rune : absChar.runes) - if(ib.requiredDiscs.contains(rune.getRuneBaseID()) == true && ib.restrictedDiscs.contains(rune.getRuneBaseID()) == false) - return true; - - return false; - } public int getValidSlot() { int slotValue = 0; @@ -985,5 +951,48 @@ public class ItemBase { return false; } + public Boolean canCharacterEquip(AbstractCharacter character){ + return ValidRace(character.absRace) && ValidClass(character.absBaseClass,character.absPromotionClass) && ValidDiscipline(character.absDisciplines); + } + public Boolean ValidRace(Enum.MonsterType race){ + if(this.requiredRaces.isEmpty() && this.restrictedRaces.isEmpty()) + return true; + + if(this.requiredRaces.isEmpty() == false && race.elementOf(this.requiredRaces) == true) + return true; + + if(this.restrictedRaces.isEmpty() == false && race.elementOf(this.restrictedRaces) == false) + return true; + + return false; + } + + public Boolean ValidClass(Enum.ClassType base,Enum.ClassType profession){ + if(this.requiredClasses.isEmpty() && this.restrictedClasses.isEmpty()) + return true; + + if(this.requiredClasses.isEmpty() == false) + if(this.requiredClasses.contains(base) || this.requiredClasses.contains(profession)) + return true; + + if(this.restrictedClasses.isEmpty() == false) + if(this.restrictedClasses.contains(base) == false && this.restrictedClasses.contains(profession) == false) + return true; + + return false; + } + + public Boolean ValidDiscipline(EnumSet discs){ + if(this.requiredDiscs.isEmpty() && this.restrictedDiscs.isEmpty()) + return true; + + for(Enum.DisciplineType disc : discs){ + if(this.requiredDiscs.isEmpty() == false && this.requiredDiscs.contains(disc)) + return true; + if(this.restrictedDiscs.isEmpty() == false && this.restrictedDiscs.contains(disc)) + return false; + } + return false; + } } diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index ec87a8cd..477878c4 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -4564,13 +4564,23 @@ public class PlayerCharacter extends AbstractCharacter { String race = this.getRace().getName().replace("-","").replace(", Male","").replace(", Female",""); this.absRace = Enum.MonsterType.valueOf(race); + if(this.baseClass != null) + this.absBaseClass = ClassType.valueOf(this.getBaseClass().getName()); + if(this.promotionClass != null) - this.absClass = ClassType.valueOf(this.getPromotionClass().getName()); + this.absPromotionClass = ClassType.valueOf(this.getPromotionClass().getName()); if(this.isMale()) this.absGender = SexType.MALE; else this.absGender = SexType.FEMALE; + + for(CharacterRune rune : this.runes){ + DisciplineType disc = DisciplineType.valueOf(RuneBase.getRuneBase(rune.getRuneBaseID()).getName().replace("-", "").replace(" ", "")); + if(disc != null){ + this.absDisciplines.add(disc); + } + } } @Override