use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class ChannelUtilities method getChannel.
/**
* Retrieves a Channel for the given CharID, owning object, and name of the
* channel.
*
* @param id
* The CharID identifying the PlayerCharacter on which the
* Channel resides
* @param owner
* The owning object of the Channel
* @param name
* The name of the channel
* @return A Channel for the given CharID, owning object, and name of the
* channel
*/
public static VariableChannel<?> getChannel(CharID id, VarScoped owner, String name) {
ScopeInstanceFactory instFactory = SCOPE_FACET.get(id);
ScopeInstance scopeInst = instFactory.get(owner.getLocalScopeName(), owner);
return getChannel(id, scopeInst, name);
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class ModifyLst method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Campaign) {
return new ParseResult.Fail(getTokenName() + " may not be used in Campaign Files. " + "Please use the Global Modifier file", context);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " may not be empty", context);
}
String varName = sep.next();
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed 2nd argument: " + value, context);
}
String modIdentification = sep.next();
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed third argument: " + value, context);
}
String modInstructions = sep.next();
//Defaults to zero
int priorityNumber = 0;
if (sep.hasNext()) {
String priority = sep.next();
if (priority.length() < 10) {
return new ParseResult.Fail(getTokenName() + " was expecting PRIORITY= but got " + priority + " in " + value, context);
}
if ("PRIORITY=".equalsIgnoreCase(priority.substring(0, 9))) {
try {
priorityNumber = Integer.parseInt(priority.substring(9));
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " requires Priority to be an integer: " + priority.substring(9) + " was not an integer");
}
if (priorityNumber < 0) {
return new ParseResult.Fail(getTokenName() + " Priority requires an integer >= 0. " + priorityNumber + " was not positive");
}
} else {
return new ParseResult.Fail(getTokenName() + " was expecting PRIORITY=x but got " + priority + " in " + value, context);
}
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " had too many arguments: " + value, context);
}
}
ScopeInstance scopeInst = context.getActiveScope();
LegalScope scope = scopeInst.getLegalScope();
if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
return new ParseResult.Fail(getTokenName() + " found invalid var name: " + varName + "(scope: " + scope.getName() + ") Modified on " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName(), context);
}
FormatManager<?> format = context.getVariableContext().getVariableFormat(scope, varName);
return finishProcessing(context, obj, format, varName, modIdentification, modInstructions, priorityNumber);
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class ModifyOtherLst method continueParsing.
private <GT extends VarScoped> ParseResult continueParsing(LoadContext context, CDOMObject obj, String value, ParsingSeparator sep) {
ScopeInstance scopeInst = context.getActiveScope();
@SuppressWarnings("unchecked") final LegalScope scope = scopeInst.getLegalScope();
final String groupingName = sep.next();
ObjectGrouping group;
if (groupingName.startsWith("GROUP=")) {
final String groupName = groupingName.substring(6);
group = new ObjectGrouping() {
@Override
public boolean contains(VarScoped item) {
return (item instanceof CDOMObject) && ((CDOMObject) item).containsInList(ListKey.GROUP, groupName);
}
@Override
public LegalScope getScope() {
return scope;
}
@Override
public String getIdentifier() {
return "GROUP=" + groupName;
}
};
} else if ("ALL".equals(groupingName)) {
group = new ObjectGrouping() {
@Override
public boolean contains(VarScoped cdo) {
return true;
}
@Override
public LegalScope getScope() {
return scope;
}
@Override
public String getIdentifier() {
return "ALL";
}
};
} else {
group = new ObjectGrouping() {
@Override
public boolean contains(VarScoped cdo) {
return cdo.getKeyName().equalsIgnoreCase(groupingName);
}
@Override
public LegalScope getScope() {
return scope;
}
@Override
public String getIdentifier() {
return groupingName;
}
};
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed 3rd argument: " + value, context);
}
String varName = sep.next();
if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
return new ParseResult.Fail(getTokenName() + " found invalid var name: " + varName + " Modified on " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName(), context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed 4th argument: " + value, context);
}
String modType = sep.next();
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " needed 5th argument: " + value, context);
}
String modValue = sep.next();
//Defaults to zero
int priorityNumber = 0;
if (sep.hasNext()) {
String priority = sep.next();
if (priority.length() < 10) {
return new ParseResult.Fail(getTokenName() + " was expecting PRIORITY= but got " + priority + " in " + value, context);
}
if ("PRIORITY=".equalsIgnoreCase(priority.substring(0, 9))) {
try {
priorityNumber = Integer.parseInt(priority.substring(9));
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " requires Priority to be an integer: " + priority.substring(9) + " was not an integer");
}
if (priorityNumber < 0) {
return new ParseResult.Fail(getTokenName() + " Priority requires an integer >= 0. " + priorityNumber + " was not positive");
}
} else {
return new ParseResult.Fail(getTokenName() + " was expecting PRIORITY=x but got " + priority + " in " + value, context);
}
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " had too many arguments: " + value, context);
}
}
PCGenModifier<?> modifier;
try {
FormatManager<?> format = context.getVariableContext().getVariableFormat(scope, varName);
modifier = context.getVariableContext().getModifier(modType, modValue, priorityNumber, scope, format);
} catch (IllegalArgumentException iae) {
return new ParseResult.Fail(getTokenName() + " Modifier " + modType + " had value " + modValue + " but it was not valid: " + iae.getMessage(), context);
}
VarModifier<?> vm = new VarModifier<>(varName, scope, modifier);
RemoteModifier<?> rm = new RemoteModifier<>(group, vm);
context.getObjectContext().addToList(obj, ListKey.REMOTE_MODIFIER, rm);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class ModifierFacet method dataAdded.
/**
* Triggered when one of the Facets to which ModifierFacet 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) {
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) {
processAddition(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) {
processAddition(id, head, vm, inst);
}
}
}
}
}
Aggregations