Search in sources :

Example 1 with EquipSlot

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

the class PlayerCharacter method getSingleLocation.

/**
	 * If an item can only go in one location, return the name of that location
	 * to add to an EquipSet
	 *
	 * @param eqI
	 * @return single location
	 */
private String getSingleLocation(Equipment eqI) {
    // Handle natural weapons
    String loc = getNaturalWeaponLocation(eqI);
    if (loc != null) {
        return loc;
    }
    // unless they are also armor (ie: with Armor Spikes)
    if ((eqI.isWeapon()) && !(eqI.isArmor())) {
        return Constants.EMPTY_STRING;
    }
    List<EquipSlot> eqSlotList = SystemCollections.getUnmodifiableEquipSlotList();
    if ((eqSlotList == null) || eqSlotList.isEmpty()) {
        return Constants.EMPTY_STRING;
    }
    for (EquipSlot es : eqSlotList) {
        // see if this EquipSlot can contain this item TYPE
        if (es.canContainType(eqI.getType())) {
            return es.getSlotName();
        }
    }
    return Constants.EMPTY_STRING;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot)

Example 2 with EquipSlot

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

the class DataSet method initLists.

private void initLists() {
    List<Race> raceList = new ArrayList<>(context.getReferenceContext().getConstructedCDOMObjects(Race.class));
    raceList.sort(new RaceComparator());
    for (Race race : raceList) {
        if (race.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            races.addElement(race);
        }
    }
    List<PCClass> classList = new ArrayList<>(context.getReferenceContext().getConstructedCDOMObjects(PCClass.class));
    classList.sort(new PCClassComparator());
    for (PCClass pcClass : classList) {
        if (pcClass.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            classes.addElement(pcClass);
        }
    }
    for (Skill skill : context.getReferenceContext().getConstructedCDOMObjects(Skill.class)) {
        if (skill.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            skills.addElement(skill);
        }
    }
    for (Deity deity : context.getReferenceContext().getConstructedCDOMObjects(Deity.class)) {
        deities.addElement(deity);
    }
    for (PCTemplate template : context.getReferenceContext().getConstructedCDOMObjects(PCTemplate.class)) {
        if (template.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            templates.addElement(template);
        }
    }
    for (Kit kit : context.getReferenceContext().getConstructedCDOMObjects(Kit.class)) {
        kits.addElement(kit);
    }
    for (PCAlignment alignment : context.getReferenceContext().getOrderSortedCDOMObjects(PCAlignment.class)) {
        alignments.addElement(alignment);
    }
    for (PCStat stat : context.getReferenceContext().getOrderSortedCDOMObjects(PCStat.class)) {
        stats.addElement(stat);
    }
    //			new AbilityCategoryComparator());
    for (AbilityCategory category : gameMode.getAllAbilityCategories()) {
        if (category.isVisibleTo(View.VISIBLE_DISPLAY)) {
            //				categories.addElement(category);
            List<Ability> abList = new ArrayList<>(Globals.getContext().getReferenceContext().getManufacturer(Ability.class, category).getAllObjects());
            Globals.sortPObjectListByName(abList);
            DefaultListFacade<AbilityFacade> abilityList = new DefaultListFacade<>(abList);
            for (Iterator<AbilityFacade> iterator = abilityList.iterator(); iterator.hasNext(); ) {
                AbilityFacade facade = iterator.next();
                if (facade instanceof Ability) {
                    Ability ability = (Ability) facade;
                    if (!(ability.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY))) {
                        iterator.remove();
                    }
                }
            }
            abilityMap.put(category, abilityList);
        }
    }
    Map<String, BodyStructure> structMap = new HashMap<>(SystemCollections.getUnmodifiableBodyStructureList().size() + 3);
    for (String name : SystemCollections.getUnmodifiableBodyStructureList()) {
        // TODO i18n the display name and correct the DataSetTest
        String displayName = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
        final BodyStructure bodyStructure = new BodyStructure(displayName);
        bodyStructures.addElement(bodyStructure);
        structMap.put(name, bodyStructure);
    }
    Set<Type> typesWithDesignatedSlots = buildSlottedTypeList();
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_EQUIPPED, true, typesWithDesignatedSlots));
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_CARRIED, true));
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_NOTCARRIED, true));
    for (EquipSlot es : SystemCollections.getUnmodifiableEquipSlotList()) {
        if (structMap.containsKey(es.getBodyStructureName())) {
            structMap.get(es.getBodyStructureName()).addEquipSlot(es);
        }
    }
    for (Equipment eq : context.getReferenceContext().getConstructedCDOMObjects(Equipment.class)) {
        if (eq.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            equipment.addElement(eq);
        }
    }
    for (String xpTableName : gameMode.getXPTableNames()) {
        xpTableNames.addElement(xpTableName);
    }
    for (String characterType : gameMode.getCharacterTypeList()) {
        characterTypes.addElement(characterType);
    }
    for (SizeAdjustment size : context.getReferenceContext().getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER)) {
        sizes.addElement(size);
    }
    createGearBuySellSchemes();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EquipSlot(pcgen.core.character.EquipSlot) Type(pcgen.cdom.enumeration.Type) AbilityFacade(pcgen.facade.core.AbilityFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 3 with EquipSlot

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

the class EquipmentSetFacadeImpl method buildNodeList.

private void buildNodeList() {
    nodeList = new DefaultListFacade<>();
    equipSlotNodeMap = new LinkedHashMap<>();
    int index = 0;
    for (BodyStructureFacade bodyStruct : dataSet.getEquipmentLocations()) {
        String structString = bodyStruct.toString();
        EquipNodeImpl node = new EquipNodeImpl((BodyStructure) bodyStruct, index++);
        nodeList.addElement(node);
        // Add locations for this body structure
        for (EquipSlot slot : SystemCollections.getUnmodifiableEquipSlotList()) {
            String bodyStructureName = slot.getBodyStructureName();
            final String hands = "HANDS";
            if ("Ring".equalsIgnoreCase(slot.getSlotName()) || "Fingers".equalsIgnoreCase(slot.getSlotName())) {
                bodyStructureName = hands;
            }
            if (bodyStructureName.equalsIgnoreCase(structString)) {
                if (slot.canContainType("WEAPON")) {
                    // Add phantom nodes for the various weapon slots
                    if (getPCHands() > 0) {
                        addEquipNodeForEquipSlot(node, createWeaponEquipSlot(slot, Constants.EQUIP_LOCATION_PRIMARY), true);
                    }
                    for (int i = 1; i < getPCHands(); ++i) {
                        if (i > 1) {
                            addEquipNodeForEquipSlot(node, createWeaponEquipSlot(slot, Constants.EQUIP_LOCATION_SECONDARY + " " + i), true);
                        } else {
                            addEquipNodeForEquipSlot(node, createWeaponEquipSlot(slot, Constants.EQUIP_LOCATION_SECONDARY), true);
                        }
                    }
                    addEquipNodeForEquipSlot(node, createWeaponEquipSlot(slot, Constants.EQUIP_LOCATION_DOUBLE), true);
                    addEquipNodeForEquipSlot(node, createWeaponEquipSlot(slot, Constants.EQUIP_LOCATION_BOTH), true);
                    addEquipNodeForEquipSlot(node, createWeaponEquipSlot(slot, Constants.EQUIP_LOCATION_UNARMED), true);
                } else {
                    addEquipNodeForEquipSlot(node, slot, false);
                }
            }
        }
    }
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) BodyStructureFacade(pcgen.facade.core.BodyStructureFacade)

Example 4 with EquipSlot

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

the class EquipmentSetFacadeImpl method canEquip.

/**
	 * @see pcgen.core.facade.EquipmentSetFacade#canEquip(pcgen.core.facade.EquipmentSetFacade.EquipNode, pcgen.core.facade.EquipmentFacade)
	 */
@Override
public boolean canEquip(EquipNode node, EquipmentFacade equipment) {
    if (!(equipment instanceof Equipment) || (node == null)) {
        return false;
    }
    Equipment item = (Equipment) equipment;
    // Check for a required location (i.e. you can't carry a natural weapon)
    EquipNode requiredLoc = getNaturalWeaponLoc(equipment);
    if (requiredLoc != null) {
        return validLocationForNaturalWeapon(node, item, requiredLoc);
    }
    // Is this a container? Then check if the object can fit in
    if (node.getNodeType() == NodeType.EQUIPMENT) {
        EquipmentFacade parent = node.getEquipment();
        if ((parent instanceof Equipment) && ((Equipment) parent).isContainer()) {
            // Check if it fits
            if (((Equipment) parent).canContain(theCharacter, item) == 1) {
                return true;
            }
        }
    }
    if (node.getNodeType() == NodeType.PHANTOM_SLOT) {
        // Check first for an already full or taken slot
        if (!getNodes().containsElement(node)) {
            return false;
        }
        EquipSlot slot = ((EquipNodeImpl) node).getSlot();
        if (slot.canContainType(item.getType())) {
            if (item.isWeapon()) {
                final String slotName = slot.getSlotName();
                if (item.isUnarmed() && slotName.equals(Constants.EQUIP_LOCATION_UNARMED)) {
                    return true;
                }
                if (item.isShield() && slotName.equals(Constants.EQUIP_LOCATION_SHIELD)) {
                    return true;
                }
                // If it is outsized, they can't equip it to a weapon slot
                if (item.isWeaponOutsizedForPC(theCharacter)) {
                    return false;
                }
                if (slotName.startsWith(Constants.EQUIP_LOCATION_BOTH)) {
                    return true;
                }
                if (item.isMelee() && item.isDouble() && slotName.equals(Constants.EQUIP_LOCATION_DOUBLE)) {
                    return true;
                }
                if (item.isWeaponOneHanded(theCharacter)) {
                    if (slotName.equals(Constants.EQUIP_LOCATION_PRIMARY) || slotName.startsWith(Constants.EQUIP_LOCATION_SECONDARY)) {
                        return true;
                    }
                }
            } else {
                return true;
            }
        }
    }
    // Is this a body structure? Then check if the object be placed there
    if (node.getNodeType() == NodeType.BODY_SLOT) {
        BodyStructure root = (BodyStructure) node.getBodyStructure();
        if (root.isHoldsAnyType()) {
            return !root.isForbidden(item.getTrueTypeList(false));
        }
    }
    // This item can't be equipped in this location
    return false;
}
Also used : EquipmentFacade(pcgen.facade.core.EquipmentFacade) EquipSlot(pcgen.core.character.EquipSlot) Equipment(pcgen.core.Equipment) BodyStructure(pcgen.core.BodyStructure)

Example 5 with EquipSlot

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

the class EquipmentSetFacadeImpl method getIncompatibleWeaponSlots.

/**
	 * Calculate a list of weapon slots that are not compatible with the
	 * supplied slot. These can then be removed from the list to be displayed
	 * when the slot is filled and added back in when the slot is empty.
	 *
	 * @param targetNode The node to be check.
	 * @return The list of incompatible nodes, empty if the target is not a weapon slot.
	 */
private List<EquipNode> getIncompatibleWeaponSlots(EquipNodeImpl targetNode) {
    List<EquipNode> wpnList = new ArrayList<>();
    if (targetNode.getNodeType() != NodeType.PHANTOM_SLOT) {
        return wpnList;
    }
    String[] incompatLocNames = {};
    final String slotName = targetNode.getSlot().toString();
    if (Constants.EQUIP_LOCATION_PRIMARY.equals(slotName)) {
        incompatLocNames = new String[] { Constants.EQUIP_LOCATION_BOTH, Constants.EQUIP_LOCATION_DOUBLE };
    } else if (Constants.EQUIP_LOCATION_SECONDARY.equals(slotName)) {
        incompatLocNames = new String[] { Constants.EQUIP_LOCATION_BOTH, Constants.EQUIP_LOCATION_DOUBLE, Constants.EQUIP_LOCATION_SHIELD };
    } else if (Constants.EQUIP_LOCATION_SHIELD.equals(slotName)) {
        incompatLocNames = new String[] { Constants.EQUIP_LOCATION_BOTH, Constants.EQUIP_LOCATION_DOUBLE, Constants.EQUIP_LOCATION_SECONDARY };
    } else if (Constants.EQUIP_LOCATION_BOTH.equals(slotName)) {
        incompatLocNames = new String[] { Constants.EQUIP_LOCATION_PRIMARY, Constants.EQUIP_LOCATION_DOUBLE, Constants.EQUIP_LOCATION_SECONDARY, Constants.EQUIP_LOCATION_SHIELD };
    } else if (Constants.EQUIP_LOCATION_DOUBLE.equals(slotName)) {
        incompatLocNames = new String[] { Constants.EQUIP_LOCATION_PRIMARY, Constants.EQUIP_LOCATION_BOTH, Constants.EQUIP_LOCATION_SECONDARY, Constants.EQUIP_LOCATION_SHIELD };
    }
    //TODO: Extra secondary locations for more than 2 arms
    List<String> namesList = Arrays.asList(incompatLocNames);
    for (EquipSlot slot : equipSlotNodeMap.keySet()) {
        if (namesList.contains(slot.toString())) {
            wpnList.add(equipSlotNodeMap.get(slot));
        }
    }
    return wpnList;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) ArrayList(java.util.ArrayList)

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