diff --git a/src/engine/Enum.java b/src/engine/Enum.java index e4b4b9a3..62950b2d 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -10,6 +10,7 @@ package engine; import ch.claude_martin.enumbitset.EnumBitSetHelper; import engine.gameManager.ConfigManager; +import engine.gameManager.DbManager; import engine.gameManager.PowersManager; import engine.gameManager.ZoneManager; import engine.math.Vector2f; @@ -2518,11 +2519,17 @@ public class Enum { private final String name; private final String[][] ranks; //Stored Rank#->Gender(M,F) private final String[] leadershipTypes; + public final ArrayList requiredClasses; + public final ArrayList requiredRaces; + public final SexType sexRequired; GuildType(String name, String[][] ranks, String[] leadershipTypes) { this.name = name; this.ranks = ranks; this.leadershipTypes = leadershipTypes; + this.requiredClasses = DbManager.GuildQueries.LOAD_CHARTER_CLASS_RESTRICTIONS(this.name); + this.requiredRaces = DbManager.GuildQueries.LOAD_CHARTER_RACE_RESTRICTIONS(this.name); + this.sexRequired = DbManager.GuildQueries.LOAD_CHARTER_SEX_RESTRICTIONS(this.name); } public static GuildType getGuildTypeFromCharter(ItemBase itemBase) { diff --git a/src/engine/db/handlers/dbGuildHandler.java b/src/engine/db/handlers/dbGuildHandler.java index a4f1998e..fcebe3ac 100644 --- a/src/engine/db/handlers/dbGuildHandler.java +++ b/src/engine/db/handlers/dbGuildHandler.java @@ -714,5 +714,68 @@ public class dbGuildHandler extends dbHandlerBase { // // } + public ArrayList LOAD_CHARTER_RACE_RESTRICTIONS(String name){ + ArrayList reqRaces= new ArrayList<>(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `lore_charter_restrictions` WHERE `GUILDTYPE` = ?")) { + + preparedStatement.setString(1, name); + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + String read = rs.getString("RACE_REQUIRED"); + if(read != null){ + for(String entry : read.split(";")) + reqRaces.add(Enum.MonsterType.valueOf(entry.replace("-",""))); + } + } + } catch (SQLException e) { + Logger.error(e); + } + + return reqRaces; + } + public ArrayList LOAD_CHARTER_CLASS_RESTRICTIONS(String name){ + ArrayList reqClasses= new ArrayList<>(); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `lore_charter_restrictions` WHERE `GUILDTYPE` = ?")) { + + preparedStatement.setString(1, name); + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + String read = rs.getString("CLASS_REQUIRED"); + if(read != null){ + for(String entry : read.split(";")) + reqClasses.add(Enum.PromoteType.valueOf(entry)); + } + } + + } catch (SQLException e) { + Logger.error(e); + } + + return reqClasses; + } + public Enum.SexType LOAD_CHARTER_SEX_RESTRICTIONS(String name){ + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `lore_charter_restrictions` WHERE `GUILDTYPE` = ?")) { + + preparedStatement.setString(1, name); + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + String read = rs.getString("SEX_REQUIRED"); + if(read != null){ + if(read == "Female") + return Enum.SexType.FEMALE; + } + } + + } catch (SQLException e) { + Logger.error(e); + } + return Enum.SexType.NONE; + } } diff --git a/src/engine/db/handlers/dbItemBaseHandler.java b/src/engine/db/handlers/dbItemBaseHandler.java index bf12b434..b2969c61 100644 --- a/src/engine/db/handlers/dbItemBaseHandler.java +++ b/src/engine/db/handlers/dbItemBaseHandler.java @@ -86,6 +86,7 @@ public class dbItemBaseHandler extends dbHandlerBase { while (rs.next()) { recordsRead++; itemBase = new ItemBase(rs); + ItemBase.addToCache(itemBase); } @@ -95,7 +96,19 @@ public class dbItemBaseHandler extends dbHandlerBase { Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size()); } - +public void LOAD_ALL_ITEM_REQUIREMENTS(){ + for(ItemBase itemBase : ItemBase._itemBaseByUUID.values()) + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_item_requirements WHERE 'itemID' = ?")) { + preparedStatement.setInt(1, itemBase.getUUID()); + ResultSet rs = preparedStatement.executeQuery(); + while(rs.next()) { + itemBase.LoadRequirements(rs.getString("racesRequired"),rs.getString("racesRestricted"),rs.getString("classesRequired"),rs.getString("classesRestricted"),rs.getString("discsRequired"),rs.getString("discsRestricted")); + } + } catch (SQLException e) { + Logger.error("No Entry In static_item_requirements for item UUID: " + itemBase.getUUID()); + } +} public HashMap> LOAD_RUNES_FOR_NPC_AND_MOBS() { HashMap> runeSets = new HashMap<>(); diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 03aebf86..092991a9 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -125,6 +125,11 @@ public abstract class AbstractCharacter extends AbstractWorldObject { public ArrayList runes; + public Enum.MonsterType absRace = null; + public Enum.PromoteType absClass = null; + + public Enum.SexType absGender = null; + public AbstractCharacter() { super(); this.firstName = ""; diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index dfc3c03b..3169d269 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -9,6 +9,7 @@ package engine.objects; +import engine.Enum; import engine.Enum.DamageType; import engine.Enum.GameObjectType; import engine.Enum.ItemType; @@ -77,6 +78,15 @@ public class ItemBase { private ArrayList offHandAnimations = new ArrayList<>(); private boolean autoID = false; + //requirements/restrictions + public ArrayList restrictedRaces; + public ArrayList requiredRaces; + public ArrayList restrictedClasses; + public ArrayList requiredClasses; + public ArrayList requiredDiscs; + public ArrayList restrictedDiscs; + public Enum.SexType requiredSex; + /** * ResultSet Constructor */ @@ -212,6 +222,7 @@ public class ItemBase { public static void loadAllItemBases() { DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES(); + DbManager.ItemBaseQueries.LOAD_ALL_ITEM_REQUIREMENTS(); AnniverseryGifts.add(971000); AnniverseryGifts.add(971001); AnniverseryGifts.add(971002); @@ -468,6 +479,15 @@ 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)) + return false; + return item.getItemBase().value != 0 || Kit.IsNoobGear(item.getItemBase().uuid); //players can't wear 0 value items. @@ -476,6 +496,33 @@ 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; @@ -931,4 +978,43 @@ public class ItemBase { return false; } + + public void LoadRequirements(String racesRequired, String racesRestricted, String classesRequired, String classesRestricted, String discsRequired, String discsRestricted){ + this.requiredRaces = new ArrayList<>(); + this.restrictedRaces = new ArrayList<>(); + this.requiredClasses = new ArrayList<>(); + this.restrictedClasses = new ArrayList<>(); + this.requiredDiscs = new ArrayList<>(); + this.restrictedDiscs = new ArrayList<>(); + if(racesRequired != null){ + for(String entry : racesRequired.split(";")){ + requiredRaces.add(Enum.MonsterType.valueOf(entry)); + } + } + if(racesRestricted != null){ + for(String entry : racesRestricted.split(";")){ + restrictedRaces.add(Enum.MonsterType.valueOf(entry)); + } + } + if(classesRequired != null){ + for(String entry : classesRequired.split(";")){ + requiredClasses.add(Enum.PromoteType.valueOf(entry)); + } + } + if(classesRestricted != null){ + for(String entry : classesRestricted.split(";")){ + restrictedClasses.add(Enum.PromoteType.valueOf(entry)); + } + } + if(discsRequired != null){ + for(String entry : discsRequired.split(";")){ + //TODO find way to load disc runebaseID from name + } + } + if(discsRestricted != null){ + for(String entry : discsRestricted.split(";")) { + //TODO find way to load disc runebaseID from name + } + } + } } diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index d68c16cd..36ed401e 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -4559,6 +4559,17 @@ public class PlayerCharacter extends AbstractCharacter { Bounds playerBounds = Bounds.borrow(); playerBounds.setBounds(this.getLoc()); this.setBounds(playerBounds); + + //assign enum values for restrictions + this.absRace = Enum.MonsterType.valueOf(this.getRace().getName().replace("-","")); + + if(this.promotionClass != null) + this.absClass = Enum.PromoteType.valueOf(this.getPromotionClass().getName()); + + if(this.isMale()) + this.absGender = SexType.MALE; + else + this.absGender = SexType.FEMALE; } @Override