Search in sources :

Example 11 with EquipSlot

use of pcgen.core.character.EquipSlot 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)

Example 12 with EquipSlot

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

the class EquipmentSetFacadeImplTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    dataset = new MockDataSetFacade(SettingsHandler.getGame());
    dataset.addEquipmentLocation(new BodyStructure(Constants.EQUIP_LOCATION_EQUIPPED, true));
    dataset.addEquipmentLocation(new BodyStructure(LOC_HANDS, false));
    dataset.addEquipmentLocation(new BodyStructure(LOC_BODY, false));
    if (SystemCollections.getUnmodifiableEquipSlotList().isEmpty()) {
        EquipSlot equipSlot = new EquipSlot();
        equipSlot.setSlotName(SLOT_WEAPON);
        equipSlot.addContainedType("Weapon");
        equipSlot.setContainNum(1);
        equipSlot.setSlotNumType("HANDS");
        SystemCollections.addToEquipSlotsList(equipSlot, SettingsHandler.getGame().getName());
        Globals.setEquipSlotTypeCount("HANDS", "2");
        equipSlot = new EquipSlot();
        equipSlot.setSlotName(SLOT_RING);
        equipSlot.addContainedType("Ring");
        equipSlot.setContainNum(2);
        equipSlot.setSlotNumType("BODY");
        SystemCollections.addToEquipSlotsList(equipSlot, SettingsHandler.getGame().getName());
        Globals.setEquipSlotTypeCount("BODY", "1");
    }
    uiDelegate = new MockUIDelegate();
    todoManager = new TodoManager();
    equipmentList = new EquipmentListFacadeImpl();
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) BodyStructure(pcgen.core.BodyStructure)

Example 13 with EquipSlot

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

the class PlayerCharacter method canEquipItem.

/**
	 * returns true if you can put Equipment into a location in EquipSet
	 *
	 * @param eSet
	 * @param locName
	 * @param eqI
	 * @param eqTarget
	 * @return true if equipment can be added
	 */
private boolean canEquipItem(EquipSet eSet, String locName, Equipment eqI, Equipment eqTarget) {
    final String idPath = eSet.getIdPath();
    // If target is a container, allow it
    if ((eqTarget != null) && eqTarget.isContainer()) {
        // TODO - Should make sure eqI can be contained by eqTarget
        return true;
    }
    // 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.isWeapon() && eqI.isWeaponOutsizedForPC(this) && !eqI.isNatural()) {
        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 es : getEquipSet()) {
        String esID = es.getParentIdPath() + Constants.EQUIP_SET_PATH_SEPARATOR;
        String abID = idPath + Constants.EQUIP_SET_PATH_SEPARATOR;
        if (!esID.startsWith(abID)) {
            continue;
        }
        // an item in that particular location
        if (es.getName().equals(locName)) {
            final Equipment eItem = es.getItem();
            final String nString = slotMap.get(locName);
            int existNum = 0;
            if (nString != null) {
                existNum = Integer.parseInt(nString);
            }
            if (eItem != null) {
                existNum += eItem.getSlots(this);
            }
            slotMap.put(locName, String.valueOf(existNum));
        }
    }
    for (EquipSet es : getEquipSet()) {
        String esID = es.getParentIdPath() + Constants.EQUIP_SET_PATH_SEPARATOR;
        String abID = idPath + Constants.EQUIP_SET_PATH_SEPARATOR;
        if (!esID.startsWith(abID)) {
            continue;
        }
        // checks for hands already in use
        if (eqI.isWeapon() && !eqI.isNatural()) {
            // weapons can never occupy the same slot
            if (es.getName().equals(locName)) {
                return false;
            }
            // other weapon slots can be occupied
            if ((locName.equals(Constants.EQUIP_LOCATION_BOTH) || locName.equals(Constants.EQUIP_LOCATION_DOUBLE)) && (es.getName().equals(Constants.EQUIP_LOCATION_PRIMARY) || es.getName().equals(Constants.EQUIP_LOCATION_SECONDARY) || es.getName().equals(Constants.EQUIP_LOCATION_BOTH) || es.getName().equals(Constants.EQUIP_LOCATION_DOUBLE))) {
                return false;
            }
            // inverse of above case
            if ((locName.equals(Constants.EQUIP_LOCATION_PRIMARY) || locName.equals(Constants.EQUIP_LOCATION_SECONDARY)) && (es.getName().equals(Constants.EQUIP_LOCATION_BOTH) || es.getName().equals(Constants.EQUIP_LOCATION_DOUBLE))) {
                return false;
            }
        }
        // check to see how many are allowed in that slot
        if (es.getName().equals(locName)) {
            final String nString = slotMap.get(locName);
            int existNum = 0;
            if (nString != null) {
                existNum = Integer.parseInt(nString);
            }
            existNum += eqI.getSlots(this);
            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) getTotalBonusTo("SLOTS", slotType))) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
    return true;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) HashMap(java.util.HashMap) EquipSet(pcgen.core.character.EquipSet)

Example 14 with EquipSlot

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

the class EquipSlotLoader method parseLine.

/**
	 * @see LstLineFileLoader#parseLine(LoadContext, String, URI)
	 */
@Override
public void parseLine(LoadContext context, String lstLine, URI sourceURI) {
    final EquipSlot eqSlot = new EquipSlot();
    final StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
    Map<String, LstToken> tokenMap = TokenStore.inst().getTokenMap(EquipSlotLstToken.class);
    while (colToken.hasMoreTokens()) {
        final String colString = colToken.nextToken().trim();
        final int idxColon = colString.indexOf(':');
        String key = "";
        try {
            key = colString.substring(0, idxColon);
        } catch (StringIndexOutOfBoundsException e) {
        // TODO Handle Exception
        }
        EquipSlotLstToken token = (EquipSlotLstToken) tokenMap.get(key);
        //TODO: (DJ) Sick hack, remove in 5.11.x
        if (token != null && key.equals("NUMSLOTS")) {
            final String value = colString.substring(idxColon + 1);
            LstUtils.deprecationCheck(token, eqSlot.getSlotName(), sourceURI, value);
            if (!token.parse(eqSlot, lstLine, getGameMode())) {
                Logging.errorPrint("Error parsing equip slots " + eqSlot.getSlotName() + ':' + sourceURI + ':' + colString + "\"");
            }
            break;
        } else if (token != null) {
            final String value = colString.substring(idxColon + 1);
            LstUtils.deprecationCheck(token, eqSlot.getSlotName(), sourceURI, value);
            if (!token.parse(eqSlot, value, getGameMode())) {
                Logging.errorPrint("Error parsing equip slots " + eqSlot.getSlotName() + ':' + sourceURI + ':' + colString + "\"");
            }
        } else {
            Logging.errorPrint("Illegal slot info '" + lstLine + "' in " + sourceURI.toString());
        }
    }
    SystemCollections.addToEquipSlotsList(eqSlot, getGameMode());
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) StringTokenizer(java.util.StringTokenizer)

Example 15 with EquipSlot

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

the class EquipmentSetFacadeImpl method createNaturalWeaponSlot.

private void createNaturalWeaponSlot(EquipSlot slot, EquipNode node, String locName) {
    EquipSlot natWpnEquipSlot = createWeaponEquipSlot(slot, locName);
    EquipNodeImpl slotNode = new EquipNodeImpl((EquipNodeImpl) node, natWpnEquipSlot, true);
    naturalWeaponNodes.put(locName, slotNode);
}
Also used : EquipSlot(pcgen.core.character.EquipSlot)

Aggregations

EquipSlot (pcgen.core.character.EquipSlot)15 EquipSet (pcgen.core.character.EquipSet)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Equipment (pcgen.core.Equipment)3 BodyStructure (pcgen.core.BodyStructure)2 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 Type (pcgen.cdom.enumeration.Type)1 AbilityFacade (pcgen.facade.core.AbilityFacade)1 BodyStructureFacade (pcgen.facade.core.BodyStructureFacade)1 EquipmentFacade (pcgen.facade.core.EquipmentFacade)1 DefaultListFacade (pcgen.facade.util.DefaultListFacade)1