Add method to get all items from equipment slots

This commit is contained in:
Jordan Irwin 2024-04-07 17:07:42 -07:00
parent 68b99deaec
commit d5f3712ee7
No known key found for this signature in database
GPG key ID: E3E358C2F44C290A
3 changed files with 22 additions and 1 deletions

View file

@ -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).

View file

@ -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<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.
*
@ -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<Item> equippedStream() {

View file

@ -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)
*/