Search in sources :

Example 1 with ScopeInstance

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);
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance)

Example 2 with ScopeInstance

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);
                }
            }
        }
    }
}
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 3 with ScopeInstance

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) RemoteModifier(pcgen.cdom.content.RemoteModifier) VarScoped(pcgen.base.formula.base.VarScoped) CharID(pcgen.cdom.enumeration.CharID)

Example 4 with ScopeInstance

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) RemoteModifier(pcgen.cdom.content.RemoteModifier) VarScoped(pcgen.base.formula.base.VarScoped) CharID(pcgen.cdom.enumeration.CharID)

Example 5 with ScopeInstance

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);
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) VariableID(pcgen.base.formula.base.VariableID)

Aggregations

ScopeInstance (pcgen.base.formula.base.ScopeInstance)24 LegalScope (pcgen.base.formula.base.LegalScope)8 Equipment (pcgen.core.Equipment)7 VariableID (pcgen.base.formula.base.VariableID)6 CDOMObject (pcgen.cdom.base.CDOMObject)6 VarModifier (pcgen.cdom.content.VarModifier)6 Test (org.junit.Test)5 ParseResult (pcgen.rules.persistence.token.ParseResult)5 CharID (pcgen.cdom.enumeration.CharID)4 EquipmentHead (pcgen.cdom.inst.EquipmentHead)4 VarScoped (pcgen.base.formula.base.VarScoped)3 VariableLibrary (pcgen.base.formula.base.VariableLibrary)3 ScopeInstanceFactory (pcgen.base.formula.inst.ScopeInstanceFactory)3 SimpleNode (pcgen.base.formula.parse.SimpleNode)3 ReconstructionVisitor (pcgen.base.formula.visitor.ReconstructionVisitor)3 RemoteModifier (pcgen.cdom.content.RemoteModifier)3 PCGenModifier (pcgen.base.calculation.PCGenModifier)2 FormulaSemantics (pcgen.base.formula.base.FormulaSemantics)2 ManagerFactory (pcgen.base.formula.base.ManagerFactory)2 SemanticsVisitor (pcgen.base.formula.visitor.SemanticsVisitor)2