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);
}
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations