Search in sources :

Example 6 with WrappedMapSet

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);
            }
        }
    }
}
Also used : WrappedMapSet(pcgen.base.util.WrappedMapSet) Set(java.util.Set) Equipment(pcgen.core.Equipment) WrappedMapSet(pcgen.base.util.WrappedMapSet)

Aggregations

WrappedMapSet (pcgen.base.util.WrappedMapSet)6 IdentityHashMap (java.util.IdentityHashMap)2 Set (java.util.Set)2 CDOMObject (pcgen.cdom.base.CDOMObject)2 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CNAbility (pcgen.cdom.content.CNAbility)1 Type (pcgen.cdom.enumeration.Type)1 FollowerLimit (pcgen.cdom.helper.FollowerLimit)1 CompanionList (pcgen.cdom.list.CompanionList)1 Ability (pcgen.core.Ability)1 AbilityCategory (pcgen.core.AbilityCategory)1 Deity (pcgen.core.Deity)1 Equipment (pcgen.core.Equipment)1 BonusObj (pcgen.core.bonus.BonusObj)1 BonusPair (pcgen.core.bonus.BonusPair)1 MissingObject (pcgen.core.bonus.util.MissingObject)1 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)1