Search in sources :

Example 26 with EquipSet

use of pcgen.core.character.EquipSet in project pcgen by PCGen.

the class WeaponTokenTest method testAmmunition.

/**
	 * test the AMUNITION count sub token
	 */
public void testAmmunition() {
    PlayerCharacter character = getCharacter();
    character.addEquipment(largeSword);
    EquipSet es = new EquipSet("0.1.3", "Large Sword", largeSword.getName(), largeSword);
    character.addEquipSet(es);
    character.addEquipment(longbow);
    es = new EquipSet("0.1.4", "Longbow", longbow.getName(), longbow);
    character.addEquipSet(es);
    character.setCalcEquipmentList();
    WeaponToken token = new WeaponToken();
    assertEquals("non-ammo weapon", largeSword.getName(), token.getToken("WEAPON.4.NAME", character, null));
    assertEquals("Ammo weapon", longbow.getName(), token.getToken("WEAPON.3.NAME", character, null));
    assertEquals("Ammo count for a non-ammo weapon", "0", token.getToken("WEAPON.4.AMMUNITION", character, null));
    String result = token.getToken("WEAPON.3.AMMUNITION", character, null);
    assertEquals("Ammo count for an empty ammo weapon", "0", result);
    character.addEquipment(arrow);
    es = new EquipSet("0.1.4.1", "Arrow", arrow.getName(), arrow);
    character.addEquipSet(es);
    character.setCalcEquipmentList();
    result = token.getToken("WEAPON.3.AMMUNITION", character, null);
    assertEquals("Ammo count for longbow with one arrow", "1", result);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) EquipSet(pcgen.core.character.EquipSet)

Example 27 with EquipSet

use of pcgen.core.character.EquipSet 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 28 with EquipSet

use of pcgen.core.character.EquipSet 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 29 with EquipSet

use of pcgen.core.character.EquipSet 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 30 with EquipSet

use of pcgen.core.character.EquipSet in project pcgen by PCGen.

the class EncounterPlugin method canAddEquip.

private static boolean canAddEquip(PlayerCharacter pc, EquipSet eSet, String locName, Equipment eqI) {
    String idPath = eSet.getIdPath();
    // allow as many as they would like
    if (locName.startsWith(Constants.EQUIP_LOCATION_CARRIED) || locName.startsWith(Constants.EQUIP_LOCATION_EQUIPPED) || locName.startsWith(Constants.EQUIP_LOCATION_NOTCARRIED)) {
        return true;
    }
    // allow as many unarmed items as you'd like
    if (eqI.isUnarmed()) {
        return true;
    }
    // allow many Secondary Natural weapons
    if (locName.equals(Constants.EQUIP_LOCATION_NATURAL_SECONDARY)) {
        return true;
    }
    // Don't allow weapons that are too large for PC
    if (eqI.isWeaponTooLargeForPC(pc)) {
        return false;
    }
    // make a HashMap to keep track of the number of each
    // item that is already equipped to a slot
    Map<String, String> slotMap = new HashMap<>();
    for (EquipSet eqSet : pc.getDisplay().getEquipSet()) {
        if (!eqSet.getParentIdPath().startsWith(idPath)) {
            continue;
        }
        // an item in that particular location
        if (eqSet.getName().equals(locName)) {
            Equipment eItem = eqSet.getItem();
            String nString = slotMap.get(locName);
            int existNum = 0;
            if (nString != null) {
                existNum = Integer.parseInt(nString);
            }
            if (eItem != null) {
                existNum += eItem.getSlots(pc);
            }
            slotMap.put(locName, String.valueOf(existNum));
        }
    }
    for (EquipSet eqSet : pc.getDisplay().getEquipSet()) {
        if (!eqSet.getParentIdPath().startsWith(idPath)) {
            continue;
        }
        // checks for hands already in use
        if (eqI.isWeapon()) {
            // weapons can never occupy the same slot
            if (eqSet.getName().equals(locName)) {
                return false;
            }
            // other weapon slots can be occupied
            if ((locName.equals(Constants.EQUIP_LOCATION_BOTH) || locName.equals(Constants.EQUIP_LOCATION_DOUBLE) || locName.equals(Constants.EQUIP_LOCATION_TWOWEAPONS)) && (eqSet.getName().equals(Constants.EQUIP_LOCATION_PRIMARY) || eqSet.getName().equals(Constants.EQUIP_LOCATION_SECONDARY) || eqSet.getName().equals(Constants.EQUIP_LOCATION_BOTH) || eqSet.getName().equals(Constants.EQUIP_LOCATION_DOUBLE) || eqSet.getName().equals(Constants.EQUIP_LOCATION_TWOWEAPONS))) {
                return false;
            }
            // inverse of above case
            if ((locName.equals(Constants.EQUIP_LOCATION_PRIMARY) || locName.equals(Constants.EQUIP_LOCATION_SECONDARY)) && (eqSet.getName().equals(Constants.EQUIP_LOCATION_BOTH) || eqSet.getName().equals(Constants.EQUIP_LOCATION_DOUBLE) || eqSet.getName().equals(Constants.EQUIP_LOCATION_TWOWEAPONS))) {
                return false;
            }
        }
        // check to see how many are allowed in that slot
        if (eqSet.getName().equals(locName)) {
            final String nString = slotMap.get(locName);
            int existNum = 0;
            if (nString != null) {
                existNum = Integer.parseInt(nString);
            }
            existNum += eqI.getSlots(pc);
            EquipSlot eSlot = Globals.getEquipSlotByName(locName);
            if (eSlot == null) {
                return true;
            }
            for (String slotType : eSlot.getContainType()) {
                if (eqI.isType(slotType)) {
                    // if the item takes more slots, return false
                    if (existNum > (eSlot.getSlotCount() + (int) pc.getTotalBonusTo("SLOTS", slotType))) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
    return true;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) Equipment(pcgen.core.Equipment) HashMap(java.util.HashMap) EquipSet(pcgen.core.character.EquipSet)

Aggregations

EquipSet (pcgen.core.character.EquipSet)79 PlayerCharacter (pcgen.core.PlayerCharacter)32 Equipment (pcgen.core.Equipment)22 ArrayList (java.util.ArrayList)12 BonusObj (pcgen.core.bonus.BonusObj)11 HashMap (java.util.HashMap)9 LoadContext (pcgen.rules.context.LoadContext)8 EquipNode (pcgen.facade.core.EquipmentSetFacade.EquipNode)7 DecimalFormat (java.text.DecimalFormat)4 NumberFormat (java.text.NumberFormat)4 List (java.util.List)4 Map (java.util.Map)4 EquipmentList (pcgen.core.EquipmentList)4 PCTemplate (pcgen.core.PCTemplate)4 EquipSlot (pcgen.core.character.EquipSlot)4 LinkedHashMap (java.util.LinkedHashMap)3 Ability (pcgen.core.Ability)3 EquipmentModifier (pcgen.core.EquipmentModifier)3 StringTokenizer (java.util.StringTokenizer)2 CNAbility (pcgen.cdom.content.CNAbility)2