Search in sources :

Example 11 with ScopeInstance

use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.

the class DropIntoContext method evaluateFromObject.

private Object evaluateFromObject(EvaluateVisitor visitor, String legalScopeName, VarScoped vs, Node node, EvaluationManager manager) {
    FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
    ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory();
    ScopeInstance scopeInst = siFactory.get(legalScopeName, vs);
    //Rest of Equation
    return node.jjtAccept(visitor, manager.getWith(EvaluationManager.INSTANCE, scopeInst));
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) FormulaManager(pcgen.base.formula.base.FormulaManager) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Example 12 with ScopeInstance

use of pcgen.base.formula.base.ScopeInstance 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 13 with ScopeInstance

use of pcgen.base.formula.base.ScopeInstance 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 14 with ScopeInstance

use of pcgen.base.formula.base.ScopeInstance 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)

Example 15 with ScopeInstance

use of pcgen.base.formula.base.ScopeInstance in project pcgen by PCGen.

the class SetSolverManagerTest method testProcessDependentSet.

@Test
public void testProcessDependentSet() {
    sl.assertLegalVariableID("Regions", globalScope, arrayManager);
    ScopeInstance scopeInst = siFactory.getGlobalInstance(globalScope.getName());
    VariableID<String[]> regions = (VariableID<String[]>) sl.getVariableID(scopeInst, "Regions");
    manager.createChannel(regions);
    Object[] array = vc.get(regions);
    List<Object> list = Arrays.asList(array);
    assertEquals(0, array.length);
    assertTrue(vc.set.contains(regions));
    assertEquals(1, vc.set.size());
    vc.reset();
    ModifierFactory am1 = new plugin.modifier.set.AddModifierFactory<>();
    PCGenModifier mod = am1.getModifier(2000, "France,England", new ManagerFactory() {
    }, null, globalScope, arrayManager);
    manager.addModifier(regions, mod, scopeInst);
    array = vc.get(regions);
    assertThat(2, is(array.length));
    list = Arrays.asList(array);
    assertTrue(list.contains("England"));
    assertTrue(list.contains("France"));
    assertTrue(vc.set.contains(regions));
    assertEquals(1, vc.set.size());
    vc.reset();
    ModifierFactory am2 = new plugin.modifier.set.AddModifierFactory<>();
    mod = am2.getModifier(3000, "Greece,England", new ManagerFactory() {
    }, null, globalScope, arrayManager);
    manager.addModifier(regions, mod, scopeInst);
    array = vc.get(regions);
    assertThat(3, is(array.length));
    list = Arrays.asList(array);
    assertTrue(list.contains("England"));
    assertTrue(list.contains("France"));
    assertTrue(list.contains("Greece"));
    assertTrue(vc.set.contains(regions));
    assertEquals(1, vc.set.size());
    vc.reset();
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ManagerFactory(pcgen.base.formula.base.ManagerFactory) VariableID(pcgen.base.formula.base.VariableID) PCGenModifier(pcgen.base.calculation.PCGenModifier) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) Test(org.junit.Test)

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