From b3b6a9a9136974390697e62ef31057755f7be094 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 8 Feb 2024 13:11:37 -0500 Subject: [PATCH] Class requirements refactored to enumset. --- src/engine/Enum.java | 147 +++++++++++------- src/engine/db/archive/GuildRecord.java | 2 +- .../handlers/ChangeGuildLeaderHandler.java | 2 +- .../client/handlers/ChangeRankHandler.java | 2 +- .../GuildCreationFinalizeHandler.java | 4 +- .../client/handlers/InviteToGuildHandler.java | 4 +- .../net/client/msg/guild/GuildListMsg.java | 2 +- src/engine/objects/Guild.java | 6 +- 8 files changed, 103 insertions(+), 66 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 62950b2d..7fe0a7c4 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -2318,8 +2318,10 @@ public class Enum { } } - public enum GuildType { - NONE("None", new String[][]{{"None"}}, new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}), + public enum GuildCharterType { + NONE("None", new String[][]{{"None"}}, new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}, + EnumSet.noneOf(PromoteType.class)), + CATHEDRAL("Church of the All-Father", new String[][]{ {"Acolyte", "Acolyte"}, {"Catechist"}, @@ -2329,7 +2331,9 @@ public class Enum { {"Bishop", "Bishop"}, {"Lord Cardinal", "Lady Cardinal"}, {"Patriarch", "Matriarch"}}, - new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}), + new String[]{"Thearchy", "Common Rule", "Theocracy", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), MILITARY("Military", new String[][]{ {"Recruit"}, {"Footman"}, @@ -2339,7 +2343,9 @@ public class Enum { {"Captain"}, {"General"}, {"Lord Marshall", "Lady Marshall"}}, - new String[]{"Autocracy", "Common Rule", "Council Rule", "Militocracy"}), + new String[]{"Autocracy", "Common Rule", "Council Rule", "Militocracy"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), TEMPLE("Temple of the Cleansing Flame", new String[][]{ {"Aspirant"}, {"Novice"}, @@ -2350,7 +2356,9 @@ public class Enum { {"Lictor"}, {"Justiciar"}, {"Pontifex", "Pontifectrix"}}, - new String[]{"Despot Rule", "Common Rule", "Protectorship", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Protectorship", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), BARBARIAN("Barbarian Clan", new String[][]{ {"Barbarian"}, {"Skald"}, @@ -2359,7 +2367,9 @@ public class Enum { {"Jarl"}, {"Chieftain"}, {"Thane"}}, - new String[]{"Chiefdom", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Chiefdom", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), RANGER("Ranger's Brotherhood", new String[][]{ {"Yeoman"}, {"Pathfinder"}, @@ -2368,7 +2378,9 @@ public class Enum { {"Protector"}, {"Guardian"}, {"Lord Protector", "Lady Protector"}}, - new String[]{"Despot Rule", "Collectivism", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Collectivism", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), AMAZON("Amazon Temple", new String[][]{ {"Amazon Thrall", "Amazon"}, {"Amazon Slave", "Amazon Warrior"}, @@ -2376,7 +2388,9 @@ public class Enum { {"Amazon Consort", "Amazon Princess"}, {"Amazon Seneschal", "Majestrix"}, {"Amazon Regent", "Imperatrix"}}, - new String[]{"Despot Rule", "Common Rule", "Gynarchy", "Gynocracy"}), + new String[]{"Despot Rule", "Common Rule", "Gynarchy", "Gynocracy"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), NOBLE("Noble House", new String[][]{ {"Serf"}, {"Vassal"}, @@ -2387,7 +2401,9 @@ public class Enum { {"Duke", "Duchess"}, {"King", "Queen"}, {"Emperor", "Empress"}}, - new String[]{"Monarchy", "Common Rule", "Feodality", "Republic"}), + new String[]{"Monarchy", "Common Rule", "Feodality", "Republic"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), WIZARD("Wizard's Conclave", new String[][]{ {"Apprentice"}, {"Neophyte"}, @@ -2396,7 +2412,9 @@ public class Enum { {"Magus"}, {"High Magus"}, {"Archmagus"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Magocracy"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Magocracy"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), MERCENARY("Mercenary Company", new String[][]{ {"Soldier"}, {"Man-at-Arms"}, @@ -2406,7 +2424,9 @@ public class Enum { {"Commander"}, {"High Commander"}, {"Warlord"}}, - new String[]{"Magistrature", "Mob Law", "Council Rule", "Republic Rule"}), + new String[]{"Magistrature", "Mob Law", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), THIEVES("Thieve's Den", new String[][]{ {"Urchin"}, {"Footpad"}, @@ -2417,7 +2437,9 @@ public class Enum { {"Treasurer"}, {"Grandmaster Thief"}, {"Grandfather"}}, - new String[]{"Despot Rule", "Common Rule", "Oligarchy", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Oligarchy", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), DWARF("Dwarf Hold", new String[][]{ {"Citizen"}, {"Master"}, @@ -2425,7 +2447,9 @@ public class Enum { {"Thane"}, {"Great Thane"}, {"High Thane"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), HIGHCOURT("High Court", new String[][]{ {"Eccekebe"}, {"Saedulor"}, @@ -2436,7 +2460,9 @@ public class Enum { {"Dar Thaelostor", "Dar Thaelostril"}, {"Aglaeron"}, {"Ellestor", "Elestril"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), VIRAKT("Virakt", new String[][]{ {"Jov'uus"}, {"Urikhan"}, @@ -2446,7 +2472,9 @@ public class Enum { {"Khal'uvho"}, {"Khar'uus"}, {"Kryqh'khalin"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), BRIALIA("Coven of Brialia", new String[][]{ // Unknown Rank names {"Devotee"}, {"Initiated"}, @@ -2456,7 +2484,9 @@ public class Enum { {"Elder"}, {"Hierophant"}, {"Witch King", "Witch Queen"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), UNHOLY("Unholy Legion", new String[][]{ // Unknown Rank names {"Footman"}, {"Fell Legionaire"}, @@ -2466,14 +2496,18 @@ public class Enum { {"Dark Master", "Dark Mistress"}, {"Dread Master", "Dread Mistress"}, {"Dread Lord", "Dread Lady"}}, - new String[]{"Despot Rule", "Despot Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Despot Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), SCOURGE("Cult of the Scourge", new String[][]{ {"Thrall"}, {"Mudir"}, {"Dark Brother", "Dark Sister"}, {"Hand of the Dark"}, {"Dark Father", "Dark Mother"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), PIRATE("Pirate Crew", new String[][]{ {"Midshipman", "Midshipwoman"}, {"Sailor"}, @@ -2481,7 +2515,9 @@ public class Enum { {"Second Mat"}, {"First Mate"}, {"Captain"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), HERALD("Academy of Heralds", new String[][]{ {"Pupil"}, {"Scribe"}, @@ -2491,7 +2527,9 @@ public class Enum { {"Scholar"}, {"Archivist"}, {"Loremaster"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), CENTAUR("Centaur Cohort", new String[][]{ {"Hoplite"}, {"Peltast"}, @@ -2501,7 +2539,9 @@ public class Enum { {"Septenrion"}, {"Praetorian"}, {"Paragon"}}, - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}), + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)), KHREE("Aracoix Kh'ree", new String[][]{ {"Duriacor"}, {"Exarch"}, @@ -2513,107 +2553,104 @@ public class Enum { {"Erentar"}, {"Araceos"}, {"Hierarch"}}, - - new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}); + new String[]{"Despot Rule", "Common Rule", "Council Rule", "Republic Rule"}, + EnumSet.of(PromoteType.Bard, PromoteType.Channeler, PromoteType.Crusader, PromoteType.Nightstalker, + PromoteType.Prelate, PromoteType.Priest, PromoteType.Sentinel, PromoteType.Scout)); private final String name; private final String[][] ranks; //Stored Rank#->Gender(M,F) private final String[] leadershipTypes; - public final ArrayList requiredClasses; + public final EnumSet requiredClasses; public final ArrayList requiredRaces; public final SexType sexRequired; - GuildType(String name, String[][] ranks, String[] leadershipTypes) { + GuildCharterType(String name, String[][] ranks, String[] leadershipTypes, EnumSet requiredClasses) { this.name = name; this.ranks = ranks; this.leadershipTypes = leadershipTypes; - this.requiredClasses = DbManager.GuildQueries.LOAD_CHARTER_CLASS_RESTRICTIONS(this.name); + this.requiredClasses = requiredClasses; 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) { + public static GuildCharterType getGuildTypeFromCharter(ItemBase itemBase) { - GuildType charterType; + GuildCharterType charterType; // Must be a valid charter object if (itemBase.getType().equals(ItemType.GUILDCHARTER) == false) - return GuildType.NONE; //No guild Type - - // No switches on long in java. Cast to int - // when refactor to long uuid's. Loss won't matter - // with values this small. + return GuildCharterType.NONE; //No guild Type switch (itemBase.getUUID()) { case 559: - charterType = GuildType.CATHEDRAL; + charterType = GuildCharterType.CATHEDRAL; break; case 560: - charterType = GuildType.MILITARY; + charterType = GuildCharterType.MILITARY; break; case 561: - charterType = GuildType.TEMPLE; + charterType = GuildCharterType.TEMPLE; break; case 562: - charterType = GuildType.BARBARIAN; + charterType = GuildCharterType.BARBARIAN; break; case 563: - charterType = GuildType.RANGER; + charterType = GuildCharterType.RANGER; break; case 564: - charterType = GuildType.AMAZON; + charterType = GuildCharterType.AMAZON; break; case 565: - charterType = GuildType.NOBLE; + charterType = GuildCharterType.NOBLE; break; case 566: - charterType = GuildType.WIZARD; + charterType = GuildCharterType.WIZARD; break; case 567: - charterType = GuildType.MERCENARY; + charterType = GuildCharterType.MERCENARY; break; case 568: - charterType = GuildType.THIEVES; + charterType = GuildCharterType.THIEVES; break; case 569: - charterType = GuildType.DWARF; + charterType = GuildCharterType.DWARF; break; case 570: - charterType = GuildType.HIGHCOURT; + charterType = GuildCharterType.HIGHCOURT; break; case 571: - charterType = GuildType.VIRAKT; + charterType = GuildCharterType.VIRAKT; break; case 572: - charterType = GuildType.SCOURGE; + charterType = GuildCharterType.SCOURGE; break; case 573: - charterType = GuildType.KHREE; + charterType = GuildCharterType.KHREE; break; case 574: - charterType = GuildType.CENTAUR; + charterType = GuildCharterType.CENTAUR; break; case 575: - charterType = GuildType.UNHOLY; + charterType = GuildCharterType.UNHOLY; break; case 576: - charterType = GuildType.PIRATE; + charterType = GuildCharterType.PIRATE; break; case 577: - charterType = GuildType.BRIALIA; + charterType = GuildCharterType.BRIALIA; break; default: - charterType = GuildType.HERALD; + charterType = GuildCharterType.HERALD; } return charterType; } - public static GuildType getGuildTypeFromInt(int i) { - return GuildType.values()[i]; + public static GuildCharterType getGuildTypeFromInt(int i) { + return GuildCharterType.values()[i]; } public String getCharterName() { diff --git a/src/engine/db/archive/GuildRecord.java b/src/engine/db/archive/GuildRecord.java index 9447fd54..213b000b 100644 --- a/src/engine/db/archive/GuildRecord.java +++ b/src/engine/db/archive/GuildRecord.java @@ -89,7 +89,7 @@ public class GuildRecord extends DataRecord { guildRecord.guildHash = guildRecord.guild.getHash(); guildRecord.guildID = guildRecord.guild.getObjectUUID(); guildRecord.guildName = guildRecord.guild.getName(); - guildRecord.charterName = Enum.GuildType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName(); + guildRecord.charterName = Enum.GuildCharterType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName(); guildRecord.GLHash = DataWarehouse.hasher.encrypt(guildRecord.guild.getGuildLeaderUUID()); diff --git a/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java b/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java index fe21996b..2fa29725 100644 --- a/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java +++ b/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java @@ -76,7 +76,7 @@ public class ChangeGuildLeaderHandler extends AbstractClientMsgHandler { boolean isMale = true; boolean updateTarget; - Enum.GuildType t = Enum.GuildType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter()); + Enum.GuildCharterType t = Enum.GuildCharterType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter()); if (!DbManager.GuildQueries.SET_GUILD_LEADER(targetPlayer.getObjectUUID(), glGuild.getObjectUUID())) { diff --git a/src/engine/net/client/handlers/ChangeRankHandler.java b/src/engine/net/client/handlers/ChangeRankHandler.java index 8197fbff..36b5fcaf 100644 --- a/src/engine/net/client/handlers/ChangeRankHandler.java +++ b/src/engine/net/client/handlers/ChangeRankHandler.java @@ -60,7 +60,7 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { boolean isMale; if (msg.getPreviousRank() != msg.getNewRank()) { - Enum.GuildType t = Enum.GuildType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter()); + Enum.GuildCharterType t = Enum.GuildCharterType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter()); if (targetPlayer != null) { targetPlayer.setGuildTitle(msg.getNewRank()); diff --git a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java index aed341f4..0bcdb7b3 100644 --- a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java +++ b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java @@ -43,7 +43,7 @@ public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { PlayerCharacter player; GuildCreationFinalizeMsg msg; - Enum.GuildType charterType; + Enum.GuildCharterType charterType; Guild newGuild; Guild playerGuild; ItemBase itemBase; @@ -78,7 +78,7 @@ public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { return true; } - charterType = Enum.GuildType.getGuildTypeFromCharter(itemBase); + charterType = Enum.GuildCharterType.getGuildTypeFromCharter(itemBase); if (charterType == null) { ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND); diff --git a/src/engine/net/client/handlers/InviteToGuildHandler.java b/src/engine/net/client/handlers/InviteToGuildHandler.java index cce00445..34d63d7a 100644 --- a/src/engine/net/client/handlers/InviteToGuildHandler.java +++ b/src/engine/net/client/handlers/InviteToGuildHandler.java @@ -84,9 +84,9 @@ public class InviteToGuildHandler extends AbstractClientMsgHandler { return true; } - Enum.GuildType guildType = Enum.GuildType.values()[sourcePlayer.getGuild().getCharter()]; + Enum.GuildCharterType guildCharterType = Enum.GuildCharterType.values()[sourcePlayer.getGuild().getCharter()]; - if (guildType == null) { + if (guildCharterType == null) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, GuildManager.NO_CHARTER_FOUND); return true; } diff --git a/src/engine/net/client/msg/guild/GuildListMsg.java b/src/engine/net/client/msg/guild/GuildListMsg.java index f40783be..80cc6cef 100644 --- a/src/engine/net/client/msg/guild/GuildListMsg.java +++ b/src/engine/net/client/msg/guild/GuildListMsg.java @@ -125,7 +125,7 @@ class GuildListMessageType1 extends GuildListMessageType { @Override void _serialize(ByteBufferWriter writer) { - Enum.GuildType gt = Enum.GuildType.getGuildTypeFromInt(g.getCharter()); + Enum.GuildCharterType gt = Enum.GuildCharterType.getGuildTypeFromInt(g.getCharter()); writer.putInt(1); writer.putInt(gt.ordinal()); //Charter Type diff --git a/src/engine/objects/Guild.java b/src/engine/objects/Guild.java index 9ea566e4..b84f6def 100644 --- a/src/engine/objects/Guild.java +++ b/src/engine/objects/Guild.java @@ -965,12 +965,12 @@ public class Guild extends AbstractWorldObject { DataWarehouse.writeHash(Enum.DataRecordType.GUILD, this.getObjectUUID()); } - public Enum.GuildType getGuildType() { + public GuildCharterType getGuildType() { try { - return Enum.GuildType.values()[this.charter]; + return GuildCharterType.values()[this.charter]; } catch (Exception e) { Logger.error(e); - return Enum.GuildType.NONE; + return GuildCharterType.NONE; } }