Search in sources :

Example 51 with Equipment

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

the class EquipSetMigrationTest method testRenumberEquipmentSetsNestedEquipSet.

/**
	 * Test method for {@link pcgen.io.migration.EquipSetMigration#renumberEquipmentSets(pcgen.core.PlayerCharacter)}.
	 */
public void testRenumberEquipmentSetsNestedEquipSet() {
    PlayerCharacter pc = getCharacter();
    EquipSet eSet = new EquipSet("0.1", "Battle gear");
    pc.addEquipSet(eSet);
    pc.setCalcEquipSetId("0.1");
    Equipment eqItemOne = EquipmentList.getEquipmentFromName("Item One", pc);
    eqItemOne.setOutputIndex(4);
    Equipment eqBackpack = EquipmentList.getEquipmentFromName("Backpack", pc);
    eqBackpack.setOutputIndex(1);
    Equipment eqItemTwo = EquipmentList.getEquipmentFromName("Item Two", pc);
    eqItemTwo.setOutputIndex(3);
    Equipment eqItemThree = EquipmentList.getEquipmentFromName("Item Three", pc);
    eqItemThree.setOutputIndex(2);
    equipItem(pc, eqItemOne, 1.0f, "Carried", "0.1.1");
    equipItem(pc, eqBackpack, 1.0f, "Carried", "0.1.2");
    equipItem(pc, eqItemTwo, 1.0f, "Carried", "0.1.2.1");
    equipItem(pc, eqItemThree, 1.0f, "Carried", "0.1.2.2");
    EquipSetMigration.renumberEquipmentSets(pc);
    List<EquipSet> migratedList = (List<EquipSet>) pc.getDisplay().getEquipSet();
    assertEquals("Unexpected number of equipsets", 5, migratedList.size());
    verifyEquipSet(migratedList.get(0), "0.1", null);
    verifyEquipSet(migratedList.get(1), "0.1.02", eqItemOne);
    verifyEquipSet(migratedList.get(2), "0.1.01", eqBackpack);
    verifyEquipSet(migratedList.get(3), "0.1.01.02", eqItemTwo);
    verifyEquipSet(migratedList.get(4), "0.1.01.01", eqItemThree);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet) EquipmentList(pcgen.core.EquipmentList) List(java.util.List)

Example 52 with Equipment

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

the class EquipmentSetFacadeImplTest method prepareEquipmentSet.

private EquipmentSetFacadeImpl prepareEquipmentSet() {
    PlayerCharacter pc = getCharacter();
    EquipSet es = new EquipSet("0.1", "Unit Test Equip");
    pc.addEquipSet(es);
    Equipment item = new Equipment();
    item.setName(SATCHEL);
    Equipment item2 = new Equipment();
    item2.setName(BOOK);
    Equipment item3 = new Equipment();
    item3.setName(QUARTERSTAFF);
    Equipment item4 = new Equipment();
    item4.setName(BEDROLL);
    EquipSet satchelEs = addEquipToEquipSet(pc, es, item, 1.0f);
    addEquipToEquipSet(pc, satchelEs, item2, 1.0f);
    addEquipToEquipSet(pc, es, item3, 1.0f);
    addEquipToEquipSet(pc, es, item4, 1.0f);
    return new EquipmentSetFacadeImpl(uiDelegate, getCharacter(), es, dataset, equipmentList, todoManager, null);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet)

Example 53 with Equipment

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

the class EquipmentSetFacadeImplTest method testSlotManagementOnInitWithEquipment.

/**
	 * Check that EquipmentSetFacadeImpl when initialised with a dataset 
	 * containing equipment hides and shows the correct weapon slots.  
	 */
public void testSlotManagementOnInitWithEquipment() {
    PlayerCharacter pc = getCharacter();
    EquipSet es = new EquipSet("0.1", "Unit Test Equip");
    Equipment weapon = new Equipment();
    weapon.setName("Morningstar");
    addEquipToEquipSet(pc, es, weapon, 1.0f, LOC_PRIMARY);
    EquipmentSetFacadeImpl esfi = new EquipmentSetFacadeImpl(uiDelegate, pc, es, dataset, equipmentList, todoManager, null);
    ListFacade<EquipNode> nodes = esfi.getNodes();
    Map<String, EquipNode> nodeMap = new HashMap<>();
    for (EquipNode equipNode : nodes) {
        nodeMap.put(equipNode.toString(), equipNode);
    }
    EquipNode testNode = nodeMap.get("Morningstar");
    assertNotNull("Morningstar should be present", testNode);
    assertEquals("Morningstar type", EquipNode.NodeType.EQUIPMENT, testNode.getNodeType());
    assertEquals("Morningstar location", LOC_PRIMARY, esfi.getLocation(testNode));
    // Test for removed slots
    String[] removedSlots = { "Primary Hand", "Double Weapon", "Both Hands" };
    for (String slotName : removedSlots) {
        testNode = nodeMap.get(slotName);
        assertNull(slotName + " should not be present", testNode);
    }
    // Test for still present slots
    String[] retainedSlots = { "Secondary Hand", "Ring" };
    for (String slotName : retainedSlots) {
        testNode = nodeMap.get(slotName);
        assertNotNull(slotName + " should be present", testNode);
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) HashMap(java.util.HashMap) EquipSet(pcgen.core.character.EquipSet) EquipNode(pcgen.facade.core.EquipmentSetFacade.EquipNode)

Example 54 with Equipment

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

the class PreArmorTypeTest method testPassesPrerequisitePlayerCharacter.

/*
	 * Class under test for int passes(Prerequisite, PlayerCharacter)
	 */
public void testPassesPrerequisitePlayerCharacter() {
    final PlayerCharacter character = getCharacter();
    final Equipment armor = new Equipment();
    armor.setName("Leather");
    armor.addToListFor(ListKey.TYPE, Type.getConstant("ARMOR"));
    character.addEquipment(armor);
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("armortype");
    prereq.setKey("CHAINMAIL");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertFalse("Doesn't have chainmail equipped", PrereqHandler.passes(prereq, character, null));
    armor.setName("Chainmail");
    assertFalse("Chainmail is not equipped", PrereqHandler.passes(prereq, character, null));
    armor.setIsEquipped(true, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    assertTrue("Chainmail is equipped", PrereqHandler.passes(prereq, character, null));
    armor.setName("Chainmail (Masterwork)");
    assertFalse("Should be an exact match only", PrereqHandler.passes(prereq, character, null));
    prereq.setKey("CHAINMAIL%");
    assertTrue("Should be allow wildcard match", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment)

Example 55 with Equipment

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

the class PreArmorTypeTest method testType.

/**
	 * Test armor type tests
	 * @throws Exception
	 */
public void testType() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Equipment armor = new Equipment();
    armor.setName("Chainmail");
    character.addEquipment(armor);
    armor.setIsEquipped(true, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("armortype");
    prereq.setKey("TYPE=Medium");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertFalse("Equipment has no type", PrereqHandler.passes(prereq, character, null));
    armor.addType(Type.getConstant("ARMOR"));
    armor.addType(Type.getConstant("MEDIUM"));
    assertTrue("Armor is medium", PrereqHandler.passes(prereq, character, null));
    prereq.setKey("TYPE.Heavy");
    assertFalse("Armor is not heavy", PrereqHandler.passes(prereq, character, null));
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREARMORTYPE:2,TYPE=Medium,Full%");
    assertFalse("Armor is not Full something", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREARMORTYPE:2,TYPE=Medium,Chain%");
    assertTrue("Armor is medium and Chain", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) 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