Search in sources :

Example 86 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class DropIntoContextFunctionTest method testDynamic.

@Test
public void testDynamic() {
    VariableLibrary vl = getVariableLibrary();
    LegalScope equipScope = getScopeLibrary().getScope("EQUIPMENT");
    LegalScope globalScope = getScopeLibrary().getScope("Global");
    vl.assertLegalVariableID("LocalVar", equipScope, numberManager);
    vl.assertLegalVariableID("EquipVar", globalScope, stringManager);
    String formula = "dropIntoContext(\"EQUIPMENT\",EquipVar,LocalVar)";
    SimpleNode node = TestUtilities.doParse(formula);
    SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
    FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
    semanticsVisitor.visit(node, semantics);
    if (!semantics.isValid()) {
        TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
    }
    isStatic(formula, node, false);
    Equipment equip = new Equipment();
    equip.setName("EquipKey");
    Equipment equipalt = new Equipment();
    equipalt.setName("EquipAlt");
    ScopeInstance scopeInste = getInstanceFactory().get("EQUIPMENT", equip);
    VariableID varIDe = vl.getVariableID(scopeInste, "LocalVar");
    getVariableStore().put(varIDe, 2);
    ScopeInstance scopeInsta = getInstanceFactory().get("EQUIPMENT", equipalt);
    VariableID varIDa = vl.getVariableID(scopeInsta, "LocalVar");
    getVariableStore().put(varIDa, 3);
    ScopeInstance globalInst = getInstanceFactory().getGlobalInstance("Global");
    VariableID varIDq = vl.getVariableID(globalInst, "EquipVar");
    getVariableStore().put(varIDq, "EquipKey");
    LoadContext context = new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
    context.getReferenceContext().importObject(equip);
    context.getReferenceContext().importObject(equipalt);
    evaluatesTo(formula, node, 2, context);
    Object rv = new ReconstructionVisitor().visit(node, new StringBuilder());
    assertEquals(rv.toString(), formula);
    getVariableStore().put(varIDq, "EquipAlt");
    evaluatesTo(formula, node, 3, context);
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ConsolidatedListCommitStrategy(pcgen.rules.context.ConsolidatedListCommitStrategy) FormulaSemantics(pcgen.base.formula.base.FormulaSemantics) RuntimeReferenceContext(pcgen.rules.context.RuntimeReferenceContext) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) SemanticsVisitor(pcgen.base.formula.visitor.SemanticsVisitor) RuntimeLoadContext(pcgen.rules.context.RuntimeLoadContext) Equipment(pcgen.core.Equipment) ReconstructionVisitor(pcgen.base.formula.visitor.ReconstructionVisitor) LegalScope(pcgen.base.formula.base.LegalScope) LoadContext(pcgen.rules.context.LoadContext) RuntimeLoadContext(pcgen.rules.context.RuntimeLoadContext) VariableID(pcgen.base.formula.base.VariableID) Test(org.junit.Test)

Example 87 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class DropIntoContextFunctionTest method testBasic.

@Test
public void testBasic() {
    VariableLibrary vl = getVariableLibrary();
    LegalScope equipScope = getScopeLibrary().getScope("EQUIPMENT");
    vl.assertLegalVariableID("LocalVar", equipScope, numberManager);
    String formula = "dropIntoContext(\"EQUIPMENT\",\"EquipKey\",LocalVar)";
    SimpleNode node = TestUtilities.doParse(formula);
    SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
    FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
    semanticsVisitor.visit(node, semantics);
    if (!semantics.isValid()) {
        TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
    }
    isStatic(formula, node, false);
    Equipment equip = new Equipment();
    equip.setName("EquipKey");
    ScopeInstance scopeInst = getInstanceFactory().get("EQUIPMENT", equip);
    VariableID varID = vl.getVariableID(scopeInst, "LocalVar");
    getVariableStore().put(varID, 2);
    LoadContext context = new RuntimeLoadContext(new RuntimeReferenceContext(), new ConsolidatedListCommitStrategy());
    context.getReferenceContext().importObject(equip);
    evaluatesTo(formula, node, 2, context);
    Object rv = new ReconstructionVisitor().visit(node, new StringBuilder());
    assertEquals(rv.toString(), formula);
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ConsolidatedListCommitStrategy(pcgen.rules.context.ConsolidatedListCommitStrategy) FormulaSemantics(pcgen.base.formula.base.FormulaSemantics) RuntimeReferenceContext(pcgen.rules.context.RuntimeReferenceContext) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) SemanticsVisitor(pcgen.base.formula.visitor.SemanticsVisitor) RuntimeLoadContext(pcgen.rules.context.RuntimeLoadContext) Equipment(pcgen.core.Equipment) ReconstructionVisitor(pcgen.base.formula.visitor.ReconstructionVisitor) LegalScope(pcgen.base.formula.base.LegalScope) LoadContext(pcgen.rules.context.LoadContext) RuntimeLoadContext(pcgen.rules.context.RuntimeLoadContext) VariableID(pcgen.base.formula.base.VariableID) Test(org.junit.Test)

Example 88 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class EquipSetMigrationTest method testRenumberEquipmentSetsMultipleEquipSet.

/**
	 * Test method for {@link pcgen.io.migration.EquipSetMigration#renumberEquipmentSets(pcgen.core.PlayerCharacter)}.
	 */
public void testRenumberEquipmentSetsMultipleEquipSet() {
    PlayerCharacter pc = getCharacter();
    EquipSet eSet = new EquipSet("0.1", "Battle gear");
    pc.addEquipSet(eSet);
    pc.setCalcEquipSetId("0.1");
    eSet = new EquipSet("0.3", "Around Town");
    pc.addEquipSet(eSet);
    Equipment eqItemOne = EquipmentList.getEquipmentFromName("Item One", pc);
    eqItemOne.setOutputIndex(1);
    Equipment eqItemTwo = EquipmentList.getEquipmentFromName("Item Two", pc);
    eqItemTwo.setOutputIndex(2);
    Equipment eqItemThree = EquipmentList.getEquipmentFromName("Item Three", pc);
    eqItemThree.setOutputIndex(3);
    Equipment eqBackpack = EquipmentList.getEquipmentFromName("Backpack", pc);
    eqBackpack.setOutputIndex(4);
    equipItem(pc, eqItemOne, 1.0f, "Carried", "0.1.1");
    equipItem(pc, eqItemTwo, 1.0f, "Carried", "0.1.6");
    equipItem(pc, eqItemThree, 1.0f, "Carried", "0.1.4");
    equipItem(pc, eqItemOne, 1.0f, "Carried", "0.3.6");
    equipItem(pc, eqItemTwo, 1.0f, "Backpack", "0.3.4.1");
    equipItem(pc, eqItemThree, 1.0f, "Backpack", "0.3.4.2");
    equipItem(pc, eqBackpack, 1.0f, "Carried", "0.3.4");
    EquipSetMigration.renumberEquipmentSets(pc);
    List<EquipSet> migratedList = (List<EquipSet>) pc.getDisplay().getEquipSet();
    assertEquals("Unexpected number of equipsets", 9, migratedList.size());
    verifyEquipSet(migratedList.get(0), "0.1", null);
    verifyEquipSet(migratedList.get(2), "0.1.01", eqItemOne);
    verifyEquipSet(migratedList.get(3), "0.1.02", eqItemTwo);
    verifyEquipSet(migratedList.get(4), "0.1.03", eqItemThree);
    verifyEquipSet(migratedList.get(1), "0.3", null);
    verifyEquipSet(migratedList.get(5), "0.3.01", eqItemOne);
    verifyEquipSet(migratedList.get(6), "0.3.02.01", eqItemTwo);
    verifyEquipSet(migratedList.get(7), "0.3.02.02", eqItemThree);
    verifyEquipSet(migratedList.get(8), "0.3.02", eqBackpack);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet) EquipmentList(pcgen.core.EquipmentList) List(java.util.List)

Example 89 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class WeaponoToken method getToken.

/**
	 * Get the value of the supplied output token.
	 *
	 * @param tokenSource The full source of the token
	 * @param pc The character to retrieve the value for.
	 * @param eh The ExportHandler that is managing the export
	 * 						(may be null for a once off conversion).
	 * @return The value of the token.
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
    //Weapono Token
    aTok.nextToken();
    final String ind = aTok.nextToken();
    final int index = Integer.parseInt(ind);
    Equipment eq = getWeaponEquipment(pc.getDisplay(), index);
    if (eq != null) {
        return getWeaponToken(pc, eq, aTok, tokenSource);
    } else if (eh != null && eh.getExistsOnly()) {
        eh.setNoMoreItems(true);
        if (eh.getCheckBefore()) {
            eh.setCanWrite(false);
        }
    }
    return "";
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment)

Example 90 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class WeaponpToken method getToken.

/**
	 * Get the value of the token.
	 *
	 * @param tokenSource The full source of the token
	 * @param pc The character to retrieve the value for.
	 * @param eh The ExportHandler that is managing the export.
	 * @return The value of the token.
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
    //Weaponp Token
    aTok.nextToken();
    if (pc.getDisplay().hasPrimaryWeapons()) {
        Equipment eq = pc.getDisplay().getPrimaryWeapons().iterator().next();
        return getWeaponToken(pc, eq, aTok, tokenSource);
    } else if (eh != null && eh.getExistsOnly()) {
        eh.setNoMoreItems(true);
        if (eh.getCheckBefore()) {
            eh.setCanWrite(false);
        }
    }
    return "";
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment)

Aggregations

Equipment (pcgen.core.Equipment)166 PlayerCharacter (pcgen.core.PlayerCharacter)41 ArrayList (java.util.ArrayList)28 StringTokenizer (java.util.StringTokenizer)25 EquipSet (pcgen.core.character.EquipSet)22 CDOMObject (pcgen.cdom.base.CDOMObject)20 LoadContext (pcgen.rules.context.LoadContext)15 SizeAdjustment (pcgen.core.SizeAdjustment)11 EquipmentHead (pcgen.cdom.inst.EquipmentHead)10 WeaponProf (pcgen.core.WeaponProf)10 CharID (pcgen.cdom.enumeration.CharID)9 WieldCategory (pcgen.core.character.WieldCategory)9 CDOMReference (pcgen.cdom.base.CDOMReference)8 ArmorProf (pcgen.core.ArmorProf)8 EquipmentModifier (pcgen.core.EquipmentModifier)8 Race (pcgen.core.Race)8 ShieldProf (pcgen.core.ShieldProf)8 BonusObj (pcgen.core.bonus.BonusObj)8 Test (org.junit.Test)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)7