Search in sources :

Example 1 with VarModifier

use of pcgen.cdom.content.VarModifier in project pcgen by PCGen.

the class ModifierFacet method dataRemoved.

/**
	 * Triggered when one of the Facets to which ModifierFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was removed from a Player
	 * Character.
	 * 
	 * Long term this method needs to be symmetric with dataAdded.
	 * 
	 * @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 dataRemoved(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CharID id = dfce.getCharID();
    CDOMObject obj = dfce.getCDOMObject();
    List<VarModifier<?>> modifiers = obj.getListFor(ListKey.MODIFY);
    if (modifiers != null) {
        ScopeInstance inst = scopeFacet.get(id, obj);
        for (VarModifier<?> vm : modifiers) {
            processRemoval(id, obj, vm, inst);
        }
    }
    if (obj instanceof Equipment) {
        Equipment equip = (Equipment) obj;
        for (EquipmentHead head : equip.getEquipmentHeads()) {
            ScopeInstance inst = scopeFacet.get(id, head);
            modifiers = head.getListFor(ListKey.MODIFY);
            if (modifiers != null) {
                for (VarModifier<?> vm : modifiers) {
                    processRemoval(id, equip, vm, inst);
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) VarModifier(pcgen.cdom.content.VarModifier) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Example 2 with VarModifier

use of pcgen.cdom.content.VarModifier in project pcgen by PCGen.

the class CharacterFacadeImpl method openCustomizer.

private Equipment openCustomizer(Equipment aEq) {
    if (aEq == null) {
        return null;
    }
    Equipment newEquip = aEq.clone();
    if (!newEquip.containsKey(ObjectKey.BASE_ITEM)) {
        newEquip.put(ObjectKey.BASE_ITEM, CDOMDirectSingleRef.getRef(aEq));
    }
    List<VarModifier<?>> modifiers = newEquip.getListFor(ListKey.MODIFY);
    if (modifiers != null) {
        for (VarModifier<?> vm : modifiers) {
            theCharacter.addModifier(vm, newEquip, newEquip);
        }
    }
    for (EquipmentHead head : newEquip.getEquipmentHeads()) {
        modifiers = head.getListFor(ListKey.MODIFY);
        if (modifiers != null) {
            for (VarModifier<?> vm : modifiers) {
                theCharacter.addModifier(vm, head, head);
            }
        }
    }
    EquipmentBuilderFacadeImpl builder = new EquipmentBuilderFacadeImpl(newEquip, theCharacter, delegate);
    CustomEquipResult result = delegate.showCustomEquipDialog(this, builder);
    if (newEquip != null && result != CustomEquipResult.CANCELLED) {
        dataSet.addEquipment(newEquip);
    }
    //TODO if this is returning null, then the SolverManager needs to destroy the unused channels :/
    return result == CustomEquipResult.PURCHASE ? newEquip : null;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) VarModifier(pcgen.cdom.content.VarModifier) CustomEquipResult(pcgen.facade.core.UIDelegate.CustomEquipResult)

Example 3 with VarModifier

use of pcgen.cdom.content.VarModifier in project pcgen by PCGen.

the class FaceToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Race race, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
        return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
    }
    if (value.indexOf(',') == -1) {
        value = value + ',' + 0;
    }
    FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<OrderedPair> modifier;
    try {
        modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier " + MOD_IDENTIFICATION + " had value " + value + " but it was not valid: " + iae.getMessage(), context);
    }
    OrderedPair pair = modifier.process(null);
    if (pair.getPreciseX().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
    }
    if (pair.getPreciseY().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
    }
    if (!context.getVariableContext().isLegalVariableID(scope, VAR_NAME)) {
        return new ParseResult.Fail(getTokenName() + " internal error: found invalid var name: " + VAR_NAME + ", Modified on " + race.getClass().getSimpleName() + ' ' + race.getKeyName(), context);
    }
    VarModifier<OrderedPair> vm = new VarModifier<>(VAR_NAME, scope, modifier);
    context.getObjectContext().addToList(race, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier) OrderedPair(pcgen.base.math.OrderedPair) FormatManager(pcgen.base.util.FormatManager)

Example 4 with VarModifier

use of pcgen.cdom.content.VarModifier in project pcgen by PCGen.

the class ModifyLst method finishProcessing.

private <T> ParseResult finishProcessing(LoadContext context, CDOMObject obj, FormatManager<T> formatManager, String varName, String modIdentification, String modInstructions, int priorityNumber) {
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<T> modifier;
    try {
        modifier = context.getVariableContext().getModifier(modIdentification, modInstructions, priorityNumber, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier " + modIdentification + " had value " + modInstructions + " but it was not valid: " + iae.getMessage(), context);
    }
    VarModifier<T> vm = new VarModifier<>(varName, scope, modifier);
    context.getObjectContext().addToList(obj, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier)

Example 5 with VarModifier

use of pcgen.cdom.content.VarModifier in project pcgen by PCGen.

the class FaceToken method parseFace.

protected ParseResult parseFace(LoadContext context, PCTemplate fObj, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
        return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
    }
    if (value.indexOf(',') == -1) {
        value = value + ',' + 0;
    }
    @SuppressWarnings("unchecked") FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<OrderedPair> modifier;
    try {
        modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier SET had value " + value + " but it was not valid: " + iae.getMessage(), context);
    }
    OrderedPair pair = modifier.process(null);
    if (pair.getPreciseX().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
    }
    if (pair.getPreciseY().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
    }
    String varName = VAR_NAME;
    if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
        return new ParseResult.Fail(getTokenName() + " internal error: found invalid fact name: " + varName + ", Modified on " + fObj.getClass().getSimpleName() + ' ' + fObj.getKeyName(), context);
    }
    VarModifier<OrderedPair> vm = new VarModifier<>(varName, scope, modifier);
    context.getObjectContext().addToList(fObj, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) OrderedPair(pcgen.base.math.OrderedPair) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier) FormatManager(pcgen.base.util.FormatManager)

Aggregations

VarModifier (pcgen.cdom.content.VarModifier)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)6 LegalScope (pcgen.base.formula.base.LegalScope)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 CDOMObject (pcgen.cdom.base.CDOMObject)3 EquipmentHead (pcgen.cdom.inst.EquipmentHead)3 Equipment (pcgen.core.Equipment)3 OrderedPair (pcgen.base.math.OrderedPair)2 FormatManager (pcgen.base.util.FormatManager)2 CharID (pcgen.cdom.enumeration.CharID)2 VarScoped (pcgen.base.formula.base.VarScoped)1 ObjectGrouping (pcgen.cdom.base.ObjectGrouping)1 RemoteModifier (pcgen.cdom.content.RemoteModifier)1 CustomEquipResult (pcgen.facade.core.UIDelegate.CustomEquipResult)1