Skip to content

Commit

Permalink
Add method to get all items from equipment slots
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Apr 20, 2024
1 parent a28525f commit 5a3bc31
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/games/stendhal/common/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* (C) Copyright 2003-2020 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -15,6 +15,11 @@
* Constants about slots
*/
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).
Expand Down
16 changes: 15 additions & 1 deletion src/games/stendhal/server/entity/RPEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* (C) Copyright 2003-2023 - Marauroa *
* (C) Copyright 2003-2024 - Marauroa *
***************************************************************************
***************************************************************************
* *
Expand Down Expand Up @@ -2372,6 +2372,18 @@ private List<Item> getAllEquipped(Predicate<Item> condition) {
return equippedStream().filter(condition).collect(Collectors.toList());
}

/**
* Retrieves items carried in equipment slots (weapons, armor, etc.).
*
* @return
* Equipped items.
*/
protected List<Item> getAllEquipment() {
final Stream<String> slotNames = Slots.EQUIPMENT.getNames().stream();
final Stream<RPSlot> 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.
*
Expand Down Expand Up @@ -3417,6 +3429,8 @@ private Stream<Item> slotStream(RPSlot slot) {
/**
* Get a stream of all equipped items.
*
* FIXME: perhaps should be renamed to avoid confusion with equipment slots (weapons, armor, etc.)
*
* @return equipped items
*/
private Stream<Item> equippedStream() {
Expand Down
4 changes: 3 additions & 1 deletion src/games/stendhal/server/entity/slot/Slots.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* (C) Copyright 2014 - Faiumoni e. V. *
* (C) Copyright 2014-2024 - Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
Expand All @@ -22,6 +22,8 @@
*/
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)
*/
Expand Down

0 comments on commit 5a3bc31

Please sign in to comment.