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);
}
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);
}
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);
}
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 "";
}
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 "";
}
Aggregations