Search in sources :

Example 56 with EquipSet

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

the class EquipmentSetFacadeImpl method sortEquipment.

@Override
public boolean sortEquipment(EquipNode parentNode) {
    // Confirm our assumptions
    if (!(parentNode instanceof EquipNodeImpl) || !(parentNode.getBodyStructure() instanceof BodyStructure) || ((parentNode.getNodeType() != NodeType.EQUIPMENT) && (parentNode.getNodeType() != NodeType.BODY_SLOT))) {
        return false;
    }
    BodyStructure bodyStruct = (BodyStructure) parentNode.getBodyStructure();
    if (!bodyStruct.isHoldsAnyType()) {
        return false;
    }
    String pid = ((EquipNodeImpl) parentNode).idPath;
    boolean isBodyStructure = parentNode.getBodyStructure() instanceof BodyStructure;
    List<EquipNodeImpl> childList = new ArrayList<>();
    Map<String, EquipNodeImpl> origPathToNode = buildPathNodeMap();
    Map<String, EquipSet> origPathToEquipSet = buildPathEquipSetMap();
    for (Map.Entry<String, EquipNodeImpl> entry : origPathToNode.entrySet()) {
        final String origPath = entry.getKey();
        final EquipNodeImpl node = entry.getValue();
        EquipSet es = origPathToEquipSet.get(origPath);
        if (node.parent == parentNode) {
            childList.add(node);
            if (pid == null) {
                pid = es.getParentIdPath();
            }
        }
    }
    // Sort child list
    childList.sort(new EquipNameComparator());
    // Renumber paths
    // need to start from a unique id if only sorting some nodes at a level
    int id = isBodyStructure ? theCharacter.getNewChildId(pid) : 1;
    NumberFormat format = new DecimalFormat("00");
    for (EquipNodeImpl childNode : childList) {
        String origPath = childNode.idPath;
        String newPath = pid + '.' + format.format(id);
        nodeList.removeElement(childNode);
        EquipSet es = origPathToEquipSet.get(origPath);
        es.setIdPath(newPath);
        updateContainerPath(origPath, newPath, origPathToNode, origPathToEquipSet);
        childNode.setIdPath(newPath);
        nodeList.addElement(childNode);
        id++;
    }
    return true;
}
Also used : EquipSet(pcgen.core.character.EquipSet) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) BodyStructure(pcgen.core.BodyStructure) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NumberFormat(java.text.NumberFormat)

Example 57 with EquipSet

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

the class CharacterFacadeImpl method initEquipSet.

/**
	 * Initialise the equipment set facades, ensuring that the character has a 
	 * default equipment set. 
	 */
private void initEquipSet() {
    // Setup the default EquipSet if not already present
    if (!charDisplay.hasEquipSet()) {
        String id = EquipmentSetFacadeImpl.getNewIdPath(charDisplay, null);
        EquipSet eSet = new EquipSet(id, LanguageBundle.getString("in_ieDefault"));
        theCharacter.addEquipSet(eSet);
        theCharacter.setCalcEquipSetId(id);
    }
    // Detach listeners from old set
    if (equipSet.get() != null) {
        EquipmentListFacade equippedItems = equipSet.get().getEquippedItems();
        equippedItems.removeListListener(this);
        equippedItems.removeEquipmentListListener(this);
    }
    // Make facades for each root equipset.
    List<EquipmentSetFacade> eqSetList = new ArrayList<>();
    EquipmentSetFacade currSet = null;
    String currIdPath = theCharacter.getCalcEquipSetId();
    for (EquipSet es : charDisplay.getEquipSet()) {
        if (es.getParentIdPath().equals("0")) {
            final EquipmentSetFacadeImpl facade = new EquipmentSetFacadeImpl(delegate, theCharacter, es, dataSet, purchasedEquip, todoManager, this);
            eqSetList.add(facade);
            if (es.getIdPath().equals(currIdPath)) {
                currSet = facade;
            }
        }
    }
    equipmentSets.updateContents(eqSetList);
    if (currSet != null) {
        equipSet.set(currSet);
    }
    EquipmentSetFacade set = equipSet.get();
    set.getEquippedItems().addListListener(this);
    set.getEquippedItems().addEquipmentListListener(this);
    refreshTotalWeight();
}
Also used : EquipmentSetFacade(pcgen.facade.core.EquipmentSetFacade) EquipSet(pcgen.core.character.EquipSet) EquipmentListFacade(pcgen.facade.core.EquipmentListFacade) ArrayList(java.util.ArrayList)

Example 58 with EquipSet

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

the class EquipSetLoopDirective method execute.

@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    if (body == null) {
        throw new TemplateModelException("This directive must have content.");
    }
    List<EquipSet> eqSetList = new ArrayList<>();
    EquipSet currSet = null;
    String currIdPath = pc.getCalcEquipSetId();
    for (EquipSet es : pc.getDisplay().getEquipSet()) {
        if (es.getParentIdPath().equals("0")) {
            eqSetList.add(es);
            if (es.getIdPath().equals(currIdPath)) {
                currSet = es;
            }
        }
    }
    for (EquipSet equipSet : eqSetList) {
        pc.setCalcEquipSetId(equipSet.getIdPath());
        pc.setCalcEquipmentList(equipSet.getUseTempMods());
        // Executes the nested body (same as <#nested> in FTL). In this
        // case we don't provide a special writer as the parameter:
        body.render(env.getOut());
    }
    if (currSet != null) {
        pc.setCalcEquipSetId(currSet.getIdPath());
        pc.setCalcEquipmentList(currSet.getUseTempMods());
    }
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) EquipSet(pcgen.core.character.EquipSet) ArrayList(java.util.ArrayList)

Example 59 with EquipSet

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

the class EquipSetMigration method renumberEquipmentSets.

/**
	 * Renumber the equipment sets so that they are sortable in current output 
	 * order. For each equipment set, change the format of the idpaths from 
	 * 0.1.1.1 to 0.1.01.01 and renumber items in a container in accordance with 
	 * their output order
	 * @param pc The character to have equipment sets renumbered.
	 */
static void renumberEquipmentSets(PlayerCharacter pc) {
    Collection<EquipSet> allEquipSets = pc.getDisplay().getEquipSet();
    List<EquipSet> sortedChildrenEs = getSortedChildren(allEquipSets, "0");
    for (EquipSet equipSet : sortedChildrenEs) {
        List<EquipSet> children = getSortedChildren(allEquipSets, equipSet.getIdPath());
        renumberChildren(children, allEquipSets, equipSet.getIdPath());
    }
}
Also used : EquipSet(pcgen.core.character.EquipSet)

Example 60 with EquipSet

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

the class ACTokenTest method testNonMagic.

/**
	 * Test the character's AC calcs with armor with no equip mods applied.
	 * @throws Exception
	 */
public void testNonMagic() throws Exception {
    PlayerCharacter character = getCharacter();
    EquipSet es = new EquipSet("0.1.2", "Chain Shirt", chainShirt.getName(), chainShirt);
    character.addEquipSet(es);
    character.setCalcEquipmentList();
    character.calcActiveBonuses();
    assertEquals("Ability AC normal armor", "2", new ACToken().getToken("AC.Ability", getCharacter(), null));
    assertEquals("Armor AC with normal armor", "4", new ACToken().getToken("AC.Armor", getCharacter(), null));
    assertEquals("Total AC with normal armor", "16", new ACToken().getToken("AC.Total", getCharacter(), null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) 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