From d5f3712ee7c9becc7c6e29952bac437f65482c19 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Sun, 7 Apr 2024 17:07:42 -0700 Subject: [PATCH] Add method to get all items from equipment slots --- src/games/stendhal/common/Constants.java | 5 +++++ src/games/stendhal/server/entity/RPEntity.java | 14 ++++++++++++++ src/games/stendhal/server/entity/slot/Slots.java | 4 +++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/games/stendhal/common/Constants.java b/src/games/stendhal/common/Constants.java index 1e409acfdf..f4f2b35c13 100644 --- a/src/games/stendhal/common/Constants.java +++ b/src/games/stendhal/common/Constants.java @@ -15,6 +15,11 @@ package games.stendhal.common; * General constants. */ public final class Constants { + + public static final String[] EQUIPMENT_SLOTS = { + "head", "rhand", "lhand", "armor", "finger", "cloak", "legs", "feet" + }; + /** * All the slots considered to be "with" the entity. Listed in priority * order (i.e. bag first). diff --git a/src/games/stendhal/server/entity/RPEntity.java b/src/games/stendhal/server/entity/RPEntity.java index e0f9f3abaf..cd023fe4bd 100644 --- a/src/games/stendhal/server/entity/RPEntity.java +++ b/src/games/stendhal/server/entity/RPEntity.java @@ -2378,6 +2378,18 @@ public abstract class RPEntity extends CombatEntity { return equippedStream().filter(condition).collect(Collectors.toList()); } + /** + * Retrieves items carried in equipment slots (weapons, armor, etc.). + * + * @return + * Equipped items. + */ + protected List getAllEquipment() { + final Stream slotNames = Slots.EQUIPMENT.getNames().stream(); + final Stream slots = slotNames.map(this::getSlot).filter(Objects::nonNull); + return slots.flatMap(this::slotStream).collect(Collectors.toList()); + } + /** * Retrieves all of an item with matching info string. * @@ -3451,6 +3463,8 @@ public abstract class RPEntity extends CombatEntity { /** * Get a stream of all equipped items. * + * FIXME: perhaps should be renamed to avoid confusion with equipment slots (weapons, armor, etc.) + * * @return equipped items */ protected Stream equippedStream() { diff --git a/src/games/stendhal/server/entity/slot/Slots.java b/src/games/stendhal/server/entity/slot/Slots.java index a8bdf10d26..0e06b7146f 100644 --- a/src/games/stendhal/server/entity/slot/Slots.java +++ b/src/games/stendhal/server/entity/slot/Slots.java @@ -1,5 +1,5 @@ /*************************************************************************** - * (C) Copyright 2014 - Faiumoni e. V. * + * (C) Copyright 2014-2024 - Faiumoni e. V. * *************************************************************************** *************************************************************************** * * @@ -22,6 +22,8 @@ import games.stendhal.common.Constants; */ public enum Slots { + /** Slots where equipment can be carried for use (weapons, armor, and rings). */ + EQUIPMENT(ImmutableList.copyOf(Constants.EQUIPMENT_SLOTS)), /** * slots which may be carried by an entity (e. g. a bag) */