From 9024987ed24bc96818e193292e7ae1f33f6d4b4f Mon Sep 17 00:00:00 2001 From: Ceikry Date: Thu, 10 Mar 2022 05:17:07 +0000 Subject: [PATCH] Refactored god item definitions to be more general purpose --- .../content/activity/gwd/GodWarsFaction.java | 41 +++++++------------ Server/src/main/kotlin/api/ContentAPI.kt | 12 ++++++ Server/src/main/kotlin/api/God.kt | 10 +++++ 3 files changed, 36 insertions(+), 27 deletions(-) create mode 100644 Server/src/main/kotlin/api/God.kt diff --git a/Server/src/main/java/core/game/content/activity/gwd/GodWarsFaction.java b/Server/src/main/java/core/game/content/activity/gwd/GodWarsFaction.java index 582c02a57..d2508a87f 100644 --- a/Server/src/main/java/core/game/content/activity/gwd/GodWarsFaction.java +++ b/Server/src/main/java/core/game/content/activity/gwd/GodWarsFaction.java @@ -1,17 +1,21 @@ package core.game.content.activity.gwd; +import api.ContentAPIKt; +import api.God; import core.game.node.entity.player.Player; import core.game.node.item.Item; +import static api.ContentAPIKt.hasGodItem; + /** * The god wars factions. * @author Emperor */ public enum GodWarsFaction { - ARMADYL(6222, 6246, 87, 11694, 11718, 11720, 11722, 12670, 12671, 14671), - BANDOS(6260, 6283, 11061, 11696, 11724, 11726, 11728), - SARADOMIN(6247, 6259, 1718, 2412, 2415, 2661, 2663, 2665, 2667, 3479, 3675, 3489, 3840, 4682, 6762, 8055, 10384, 10386, 10388, 10390, 10440, 10446, 10452, 10458, 10464, 10470, 11181, 11698, 11730,542,544), - ZAMORAK(6203, 6221, 11716, 11700, 1724, 2414, 2417, 2653, 2655, 2657, 2659, 3478, 3674, 3841, 3842, 3852, 4683, 6764, 8056, 10368, 10370, 10372, 10374, 10444, 10450, 10456, 10460, 10468, 10474, 10776, 10786, 10790, 14662); + ARMADYL(6222, 6246, God.ARMADYL), + BANDOS(6260, 6283, God.BANDOS), + SARADOMIN(6247, 6259, God.SARADOMIN), + ZAMORAK(6203, 6221, God.ZAMORAK); /** * The start NPC id. @@ -24,20 +28,20 @@ public enum GodWarsFaction { private final int endId; /** - * The protection items. + * The god this faction represents */ - private final int[] protectionItems; + private final God god; /** * Constructs a new {@code GodWarsFaction} {@code Object}. * @param startId The start NPC id. * @param endId The end NPC id. - * @param protectionItems The protection items for this faction. + * @param god The god this faction represents. */ - private GodWarsFaction(int startId, int endId, int... protectionItems) { + private GodWarsFaction(int startId, int endId, God god) { this.startId = startId; this.endId = endId; - this.protectionItems = protectionItems; + this.god = god; } /** @@ -61,16 +65,7 @@ public enum GodWarsFaction { * player. */ public boolean isProtected(Player player) { - for (Item item : player.getEquipment().toArray()) { - if (item != null) { - for (int id : protectionItems) { - if (item.getId() == id) { - return true; - } - } - } - } - return false; + return hasGodItem(player, god); } /** @@ -88,12 +83,4 @@ public enum GodWarsFaction { public int getEndId() { return endId; } - - /** - * Gets the protectionItems. - * @return The protectionItems. - */ - public int[] getProtectionItems() { - return protectionItems; - } } \ No newline at end of file diff --git a/Server/src/main/kotlin/api/ContentAPI.kt b/Server/src/main/kotlin/api/ContentAPI.kt index fe9ed4168..0eba26e02 100644 --- a/Server/src/main/kotlin/api/ContentAPI.kt +++ b/Server/src/main/kotlin/api/ContentAPI.kt @@ -261,6 +261,18 @@ fun inEquipment(player: Player, item: Int, amount: Int = 1): Boolean { return player.equipment.contains(item, amount) } +/** + * Check if a player has an item equipped which corresponds to the given God + * @param player the player to check + * @param god the God whose equipment we are checking for + * @return true if the player has an item corresponding to the given god, false otherwise + */ +fun hasGodItem(player: Player, god: God): Boolean +{ + god.validItems.forEach { if(amountInEquipment(player, it) > 0) return true } + return false +} + /** * Get number of free slots in a player's inventory * @param player the player to check diff --git a/Server/src/main/kotlin/api/God.kt b/Server/src/main/kotlin/api/God.kt new file mode 100644 index 000000000..6bbeaa0d0 --- /dev/null +++ b/Server/src/main/kotlin/api/God.kt @@ -0,0 +1,10 @@ +package api + +enum class God(vararg val validItems: Int) { + ARMADYL(87, 11694, 11718, 11720, 11722, 12670, 12671, 14671), + BANDOS(11061, 11696, 11724, 11726, 11728), + SARADOMIN(1718, 2412, 2415, 2661, 2663, 2665, 2667, 3479, 3675, 3489, 3840, 4682, 6762, 8055, 10384, 10386, 10388, 10390, 10440, 10446, 10452, 10458, 10464, 10470, 11181, 11698, 11730,542,544), + ZAMORAK(11716, 11700, 1724, 2414, 2417, 2653, 2655, 2657, 2659, 3478, 3674, 3841, 3842, 3852, 4683, 6764, 8056, 10368, 10370, 10372, 10374, 10444, 10450, 10456, 10460, 10468, 10474, 10776, 10786, 10790, 14662), + GUTHIX, + ZAROS +} \ No newline at end of file