use of pcgen.base.util.WrappedMapSet in project pcgen by PCGen.
the class EquippedEquipmentFacet method reset.
/**
* Triggered ("manually") when the equipped equipment on a Player Character
* has changed. Evaluates all Equipment available to the Player Character
* and places the Equipped Equipment into this EquippedEquipmentFacet.
*
* @param id
* The CharID representing the Player Character for which the
* equipped Equipment should be updated
*/
public void reset(CharID id) {
Set<Equipment> oldEquipped = (Set<Equipment>) removeCache(id);
Set<Equipment> currentEquipment = equipmentFacet.getSet(id);
Set<Equipment> newEquipped = new WrappedMapSet<>(IdentityHashMap.class);
setCache(id, newEquipped);
if (oldEquipped != null) {
// Delete items that the PC no longer has at all
for (Equipment e : oldEquipped) {
if (!currentEquipment.contains(e)) {
fireDataFacetChangeEvent(id, e, DataFacetChangeEvent.DATA_REMOVED);
}
}
}
for (Equipment e : currentEquipment) {
if (e.isEquipped()) {
newEquipped.add(e);
// If not old, it's added
if (oldEquipped == null || !oldEquipped.contains(e)) {
fireDataFacetChangeEvent(id, e, DataFacetChangeEvent.DATA_ADDED);
}
} else {
// If old, it's removed
if (oldEquipped != null && oldEquipped.contains(e)) {
fireDataFacetChangeEvent(id, e, DataFacetChangeEvent.DATA_REMOVED);
}
}
}
}
Aggregations