Search in sources :

Example 1 with EquipSet

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

the class PCGIOHandler method resolveDuplicateEquipmentSets.

/**
	 * Check all equipment sets to ensure there are no duplicate paths. Where a 
	 * duplicate path is found, report it and try to move one non-container to 
	 * a new path.
	 * 
	 * @param currentPC The character being loaded.
	 */
private void resolveDuplicateEquipmentSets(PlayerCharacter currentPC) {
    boolean anyMoved = false;
    Iterable<EquipSet> equipSetList = new ArrayList<>(currentPC.getDisplay().getEquipSet());
    Map<String, EquipSet> idMap = new HashMap<>();
    for (final EquipSet es : equipSetList) {
        String idPath = es.getIdPath();
        if (idMap.containsKey(idPath)) {
            EquipSet existingEs = idMap.get(idPath);
            EquipSet esToBeMoved = chooseItemToBeMoved(existingEs, es);
            if (esToBeMoved == null) {
                warnings.add(String.format("Found two equipment items equipped to the " + "path %s. Items were %s and %s.", idPath, es.getItem(), existingEs.getItem()));
                continue;
            }
            // change the item's location
            currentPC.moveEquipSetToNewPath(esToBeMoved);
            EquipSet esStaying = esToBeMoved == es ? existingEs : es;
            // erroneously held to the item remaining in place
            for (int j = esToBeMoved.getItem().getContainedEquipmentCount() - 1; j >= 0; j--) {
                Equipment containedItem = esToBeMoved.getItem().getContainedEquipment(j);
                esToBeMoved.getItem().removeChild(currentPC, containedItem);
                esStaying.getItem().insertChild(currentPC, containedItem);
            }
            Logging.log(Logging.WARNING, String.format("Moved item %s from path %s to %s as it " + "clashed with %s", esToBeMoved.getItem(), idPath, esToBeMoved.getIdPath(), esToBeMoved == es ? existingEs.getItem() : es.getItem()));
            idMap.put(es.getIdPath(), es);
            idMap.put(existingEs.getIdPath(), existingEs);
            anyMoved = true;
        } else {
            idMap.put(idPath, es);
        }
    }
    if (anyMoved) {
        warnings.add("Some equipment was moved as it was incorrectly stored." + " Please see the log for details.");
    }
}
Also used : Equipment(pcgen.core.Equipment) HashMap(java.util.HashMap) EquipSet(pcgen.core.character.EquipSet) ArrayList(java.util.ArrayList)

Example 2 with EquipSet

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

the class PCGVer2Creator method appendEquipmentSetLines.

private void appendEquipmentSetLines(StringBuilder buffer) {
    // Output all the EquipSets
    final List<EquipSet> eqSetList = new ArrayList<>(charDisplay.getEquipSet());
    Collections.sort(eqSetList);
    for (EquipSet eqSet : eqSetList) {
        buffer.append(IOConstants.TAG_EQUIPSET).append(':');
        buffer.append(EntityEncoder.encode(eqSet.getName()));
        buffer.append('|');
        buffer.append(IOConstants.TAG_ID).append(':');
        buffer.append(eqSet.getIdPath());
        if (!eqSet.getValue().isEmpty()) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_VALUE).append(':');
            buffer.append(EntityEncoder.encode(eqSet.getValue()));
            buffer.append('|');
            buffer.append(IOConstants.TAG_QUANTITY).append(':');
            buffer.append(eqSet.getQty());
        }
        if (!eqSet.getNote().isEmpty()) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_NOTE).append(':');
            buffer.append(eqSet.getNote());
        }
        if (eqSet.getUseTempMods()) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_USETEMPMODS).append(':');
            buffer.append(eqSet.getUseTempMods() ? 'Y' : 'N');
        }
        buffer.append(IOConstants.LINE_SEP);
    }
    // Then output EquipSet used for "working" equipmentList
    final String calcEquipSet = thePC.getCalcEquipSetId();
    buffer.append(IOConstants.TAG_CALCEQUIPSET).append(':');
    buffer.append(calcEquipSet);
    buffer.append(IOConstants.LINE_SEP);
}
Also used : EquipSet(pcgen.core.character.EquipSet) ArrayList(java.util.ArrayList)

Example 3 with EquipSet

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

the class EquipSetFacet method getEquipSetCount.

/**
	 * Search the PCs equipment sets rooted on idPath and return a count of the items
	 * named "name".
	 * @param id The ID of the PC
	 * @param idPath The
	 * @param name The name of the EqSet.
	 * @return The count fo the number of instances of the named equipSet on the given path.
	 */
public Float getEquipSetCount(CharID id, String idPath, String name) {
    float count = 0;
    for (EquipSet eSet : getSet(id)) {
        final String esID = eSet.getIdPath() + Constants.EQUIP_SET_PATH_SEPARATOR;
        final String abID = idPath + Constants.EQUIP_SET_PATH_SEPARATOR;
        if (esID.startsWith(abID)) {
            if (eSet.getValue().equals(name)) {
                count += eSet.getQty();
            }
        }
    }
    return count;
}
Also used : EquipSet(pcgen.core.character.EquipSet)

Example 4 with EquipSet

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

the class EquipSetFacet method delEquipSet.

/**
	 * Remove an EqSet from the PC's Equipped Equipment.
	 * @param id The identifier of the PC
	 * @param eSet The EquipSet to remove.
	 * @return true if the object was removed.
	 */
public boolean delEquipSet(CharID id, EquipSet eSet) {
    Collection<EquipSet> componentSet = getCachedSet(id);
    if (componentSet == null) {
        return false;
    }
    boolean found = false;
    final String pid = eSet.getIdPath();
    // first remove this EquipSet
    componentSet.remove(eSet);
    // now find and remove all it's children
    for (Iterator<EquipSet> e = componentSet.iterator(); e.hasNext(); ) {
        final EquipSet es = e.next();
        final String abParentId = es.getParentIdPath() + Constants.EQUIP_SET_PATH_SEPARATOR;
        final String abPid = pid + Constants.EQUIP_SET_PATH_SEPARATOR;
        if (abParentId.startsWith(abPid)) {
            e.remove();
            found = true;
        }
    }
    return found;
}
Also used : EquipSet(pcgen.core.character.EquipSet)

Example 5 with EquipSet

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

the class PCGVer2Parser method parseEquipSetTempBonusLine.

/**
	 * ###############################################################
	 * EquipSet Temp Bonuses
	 * ###############################################################
	 * @param line
	 **/
private void parseEquipSetTempBonusLine(final String line) {
    PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalEquipSetTempBonus", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    String tag;
    String tagString = null;
    for (PCGElement element : tokens.getElements()) {
        tag = element.getName();
        if (IOConstants.TAG_EQSETBONUS.equals(tag)) {
            tagString = EntityEncoder.decode(element.getText());
        }
    }
    if (tagString == null) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.InvalidEquipSetTempBonus", line);
        warnings.add(msg);
        return;
    }
    final EquipSet eSet = thePC.getEquipSetByIdPath(tagString);
    if (eSet == null) {
        return;
    }
    //# EquipSet Temp Bonuses
    //EQSETBONUS:0.2|TEMPBONUS:NAME=Haste|TBTARGET:PC|TEMPBONUS:SPELL=Shield of Faith|TBTARGET:PC
    final Map<BonusObj, BonusManager.TempBonusInfo> aList = new IdentityHashMap<>();
    for (final PCGElement element : tokens.getElements()) {
        tag = element.getName();
        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            final String aString = EntityEncoder.decode(element.getText());
            // Parse aString looking for
            // TEMPBONUS and TBTARGET pairs
            StringTokenizer aTok = new StringTokenizer(aString, IOConstants.TAG_SEPARATOR);
            if (aTok.countTokens() < 2) {
                continue;
            }
            String sName = aTok.nextToken();
            String tName = aTok.nextToken();
            aList.putAll(getBonusFromName(sName, tName));
        }
    }
    eSet.setTempBonusList(aList);
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) BonusObj(pcgen.core.bonus.BonusObj) EquipSet(pcgen.core.character.EquipSet) IdentityHashMap(java.util.IdentityHashMap)

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