use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class ResultFacet method getGlobalVariable.
public Object getGlobalVariable(CharID id, String varName) {
ScopeInstance scope = scopeFacet.getGlobalScope(id);
VariableID<?> varID = variableLibraryFacet.getVariableID(id.getDatasetID(), scope, varName);
return variableStoreFacet.getValue(id, varID);
}
use of pcgen.base.formula.base.ScopeInstance 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.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class RemoteModifierFacet method dataAdded.
@Override
public void dataAdded(DataFacetChangeEvent<CharID, VarScoped> dfce) {
CharID id = dfce.getCharID();
VarScoped vs = dfce.getCDOMObject();
/*
* If this can have local variables, find what may have been modified by
* previous objects
*/
for (RemoteModifier<?> rm : getSet(id)) {
VarScoped src = get(id, rm);
ScopeInstance inst = scopeFacet.get(id, src);
processAdd(id, rm, vs, inst);
if (vs instanceof Equipment) {
Equipment e = (Equipment) vs;
for (EquipmentHead head : e.getEquipmentHeads()) {
processAdd(id, rm, head, inst);
}
}
}
/*
* Look at what newly added object can modify on others
*/
if (vs instanceof CDOMObject) {
ScopeInstance inst = scopeFacet.get(id, vs);
List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
if (list != null) {
Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
for (RemoteModifier<?> rm : list) {
set(id, rm, vs);
//Apply to existing as necessary
for (VarScoped obj : targets) {
processAdd(id, rm, obj, inst);
if (obj instanceof Equipment) {
Equipment e = (Equipment) obj;
for (EquipmentHead head : e.getEquipmentHeads()) {
processAdd(id, rm, head, inst);
}
}
}
}
}
}
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class RemoteModifierFacet method dataRemoved.
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, VarScoped> dfce) {
CharID id = dfce.getCharID();
VarScoped vs = dfce.getCDOMObject();
/*
* If this can have local variables, find what had been modified by
* previous objects
*/
for (RemoteModifier<?> rm : getSet(id)) {
VarScoped src = get(id, rm);
ScopeInstance inst = scopeFacet.get(id, src);
processRemove(id, rm, vs, inst);
if (vs instanceof Equipment) {
Equipment e = (Equipment) vs;
for (EquipmentHead head : e.getEquipmentHeads()) {
processRemove(id, rm, head, inst);
}
}
}
/*
* Look at what newly added object can modify on others
*/
if (vs instanceof CDOMObject) {
ScopeInstance inst = scopeFacet.get(id, vs);
List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
if (list != null) {
Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
for (RemoteModifier<?> rm : list) {
remove(id, rm);
//RemoveFrom existing as necessary
for (VarScoped obj : targets) {
processRemove(id, rm, obj, inst);
if (obj instanceof Equipment) {
Equipment e = (Equipment) obj;
for (EquipmentHead head : e.getEquipmentHeads()) {
processRemove(id, rm, head, inst);
}
}
}
}
}
}
}
use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.
the class SolverManagerFacet method addModifier.
public <T> void addModifier(CharID id, VarModifier<T> vm, VarScoped target, ScopeInstance source) {
ScopeInstance scope = scopeFacet.get(id, vm.getLegalScope().getName(), target);
VariableID<T> varID = (VariableID<T>) variableLibraryFacet.getVariableID(id.getDatasetID(), scope, vm.getVarName());
get(id).addModifier(varID, vm.getModifier(), source);
}
Aggregations