Search in sources :

Example 1 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatLockFacet method dataAdded.

/**
	 * Adds StatLock objects granted by a CDOMObject which has been added to a
	 * Player Character.
	 * 
	 * Triggered when one of the Facets to which StatLockFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    List<StatLock> locks = cdo.getListFor(ListKey.STAT_LOCKS);
    if (locks != null) {
        addAll(dfce.getCharID(), locks, cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) StatLock(pcgen.cdom.helper.StatLock)

Example 2 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatMaxValueFacet method getStatMaxValue.

/**
	 * Returns the numerical maximum value for the given PCStat which has had a 
	 * max value set for the Player Character identified by the given CharID. 
	 * Returns null if no max value StatLock exists on the Player Character for 
	 * the given PCStat.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            maximum stat value is to be returned
	 * @param stat
	 *            The PCStat for which the numerical lock value is to be
	 *            returned
	 * @return The numerical value for the given PCStat which has been locked
	 *         for the Player Character identified by the given CharID; null if
	 *         no StatLock exists on the Player Character for the given PCStat
	 */
public Number getStatMaxValue(CharID id, PCStat stat) {
    Number max = Double.POSITIVE_INFINITY;
    boolean hit = false;
    Map<StatLock, Set<Object>> componentMap = getCachedMap(id);
    if (componentMap != null) {
        for (Entry<StatLock, Set<Object>> me : componentMap.entrySet()) {
            Set<Object> set = me.getValue();
            StatLock lock = me.getKey();
            if (lock.getLockedStat().equals(stat)) {
                for (Object source : set) {
                    String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
                    Number val = formulaResolvingFacet.resolve(id, lock.getLockValue(), sourceString);
                    if (val.doubleValue() < max.doubleValue()) {
                        hit = true;
                        max = val;
                    }
                }
            }
        }
    }
    return hit ? max : null;
}
Also used : Set(java.util.Set) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) StatLock(pcgen.cdom.helper.StatLock)

Example 3 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatMinValueFacet method getStatMinValue.

/**
	 * Returns the numerical minimum value for the given PCStat which has had a 
	 * min value set for the Player Character identified by the given CharID. 
	 * Returns null if no min value StatLock exists on the Player Character for 
	 * the given PCStat.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            minimum stat value is to be returned
	 * @param stat
	 *            The PCStat for which the numerical lock value is to be
	 *            returned
	 * @return The numerical value for the given PCStat which has been locked
	 *         for the Player Character identified by the given CharID; null if
	 *         no StatLock exists on the Player Character for the given PCStat
	 */
public Number getStatMinValue(CharID id, PCStat stat) {
    Number max = Double.NEGATIVE_INFINITY;
    boolean hit = false;
    Map<StatLock, Set<Object>> componentMap = getCachedMap(id);
    if (componentMap != null) {
        for (Iterator<Map.Entry<StatLock, Set<Object>>> it = componentMap.entrySet().iterator(); it.hasNext(); ) {
            Entry<StatLock, Set<Object>> me = it.next();
            Set<Object> set = me.getValue();
            StatLock lock = me.getKey();
            if (lock.getLockedStat().equals(stat)) {
                for (Object source : set) {
                    String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
                    Number val = formulaResolvingFacet.resolve(id, lock.getLockValue(), sourceString);
                    if (val.doubleValue() > max.doubleValue()) {
                        hit = true;
                        max = val;
                    }
                }
            }
        }
    }
    return hit ? max : null;
}
Also used : Entry(java.util.Map.Entry) Set(java.util.Set) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) StatLock(pcgen.cdom.helper.StatLock)

Example 4 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatTokenTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    boots = new Equipment();
    boots.setName("Boots of Dex");
    BonusObj aBonus = Bonus.newBonus(context, "STAT|DEX|2|TYPE=Enhancement");
    if (aBonus != null) {
        boots.addToListFor(ListKey.BONUS, aBonus);
    }
    spell = new Spell();
    spell.setName("Weasel's Slipperiness");
    aBonus = Bonus.newBonus(context, "STAT|DEX|4|TYPE=Enhancement");
    if (aBonus != null) {
        spell.addToListFor(ListKey.BONUS, aBonus);
    }
    template1 = new PCTemplate();
    template1.setName("Munchkiny Goodness I");
    aBonus = Bonus.newBonus(context, "STAT|STR,CON,DEX|1|TYPE=Luck");
    if (aBonus != null) {
        template1.addToListFor(ListKey.BONUS, aBonus);
    }
    template2 = new PCTemplate();
    template2.setName("Munchkiny Goodness II");
    aBonus = Bonus.newBonus(context, "STAT|STR,CON,DEX|1|TYPE=Enhancement");
    if (aBonus != null) {
        template2.addToListFor(ListKey.BONUS, aBonus);
    }
    template3 = new PCTemplate();
    template3.setName("Lock the stat");
    template3.addToListFor(ListKey.STAT_MINVALUE, new StatLock(context.getReferenceContext().getCDOMReference(PCStat.class, "WIS"), FormulaFactory.getFormulaFor("12")));
    template4 = new PCTemplate();
    template4.setName("Unwise");
    aBonus = Bonus.newBonus(context, "STAT|WIS|-8|TYPE=Enhancement");
    if (aBonus != null) {
        template4.addToListFor(ListKey.BONUS, aBonus);
    }
}
Also used : Equipment(pcgen.core.Equipment) BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) PCTemplate(pcgen.core.PCTemplate) Spell(pcgen.core.spell.Spell) StatLock(pcgen.cdom.helper.StatLock)

Example 5 with StatLock

use of pcgen.cdom.helper.StatLock in project pcgen by PCGen.

the class StatListTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    PlayerCharacter pc = getCharacter();
    LoadContext context = Globals.getContext();
    locker = new PCTemplate();
    locker.setName("locker");
    CDOMDirectSingleRef<PCStat> strRef = CDOMDirectSingleRef.getRef(str);
    locker.addToListFor(ListKey.STAT_LOCKS, new StatLock(strRef, FormulaFactory.getFormulaFor(12)));
    unlocker = new PCTemplate();
    unlocker.setName("unlocker");
    unlocker.addToListFor(ListKey.UNLOCKED_STATS, strRef);
    bonus = TestHelper.makeAbility("Bonus", AbilityCategory.FEAT, "General.Fighter");
    BonusObj aBonus = Bonus.newBonus(context, "STAT|STR|7|TYPE=Enhancement");
    if (aBonus != null) {
        bonus.addToListFor(ListKey.BONUS, aBonus);
    }
    lockedBonus = TestHelper.makeAbility("LockedBonus", AbilityCategory.FEAT, "General.Fighter");
    aBonus = Bonus.newBonus(context, "LOCKEDSTAT|STR|3|TYPE=Morale");
    if (aBonus != null) {
        lockedBonus.addToListFor(ListKey.BONUS, aBonus);
    }
    setPCStat(pc, str, 6);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) StatLock(pcgen.cdom.helper.StatLock)

Aggregations

StatLock (pcgen.cdom.helper.StatLock)15 CDOMObject (pcgen.cdom.base.CDOMObject)8 PCStat (pcgen.core.PCStat)5 Set (java.util.Set)3 Entry (java.util.Map.Entry)2 PCTemplate (pcgen.core.PCTemplate)2 BonusObj (pcgen.core.bonus.BonusObj)2 LoadContext (pcgen.rules.context.LoadContext)2 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 Formula (pcgen.base.formula.Formula)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 Ungranted (pcgen.cdom.base.Ungranted)1 FormulaResolvingFacet (pcgen.cdom.facet.FormulaResolvingFacet)1 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)1 AbstractExtractingFacetTest (pcgen.cdom.testsupport.AbstractExtractingFacetTest)1 Equipment (pcgen.core.Equipment)1 Race (pcgen.core.Race)1 Spell (pcgen.core.spell.Spell)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1