Search in sources :

Example 71 with EquipSet

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

the class WeaponTokenTest method testTwohandedNotequipped.

/**
	 * Test a two handed weapon that is not equipped.
	 */
public void testTwohandedNotequipped() {
    PlayerCharacter character = getCharacter();
    character.addEquipment(fineSword);
    LocaleDependentTestCase.before(Locale.US);
    EquipSet es = new EquipSet("0.1.3", EquipmentLocation.EQUIPPED_PRIMARY.toString(), fineSword.getName(), fineSword);
    character.addEquipSet(es);
    character.setCalcEquipmentList();
    character.addEquipment(longSpear);
    es = new EquipSet("0.1.4", EquipmentLocation.NOT_CARRIED.toString(), longSpear.getName(), longSpear);
    character.addEquipSet(es);
    es.equipItem(character);
    character.setCalcEquipmentList();
    character.preparePCForOutput();
    WeaponToken token = new WeaponToken();
    assertEquals("weapon name", longSpear.getName(), token.getToken("WEAPON.3.NAME", character, null));
    assertEquals("weapon name", "+14/+9/+4/-1", token.getToken("WEAPON.3.THHIT", character, null));
    assertEquals("weapon name", "+14/+9/+4/-1", token.getToken("WEAPON.3.TOTALHIT", character, null));
    LocaleDependentTestCase.after();
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) EquipSet(pcgen.core.character.EquipSet)

Example 72 with EquipSet

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

the class PCGVer2Parser method parseEquipmentSetLine.

private void parseEquipmentSetLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal EquipSet line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    String setName = null;
    String setID = null;
    String itemKey = null;
    String setNote = null;
    Float itemQuantity = null;
    boolean useTempMods = false;
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_EQUIPSET.equals(tag)) {
            setName = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_ID.equals(tag)) {
            setID = element.getText();
        } else if (IOConstants.TAG_VALUE.equals(tag)) {
            itemKey = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_QUANTITY.equals(tag)) {
            try {
                itemQuantity = new Float(element.getText());
            } catch (NumberFormatException nfe) {
                itemQuantity = 0.0f;
            }
        } else if (IOConstants.TAG_NOTE.equals(tag)) {
            setNote = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_USETEMPMODS.equals(tag)) {
            useTempMods = element.getText().endsWith(IOConstants.VALUE_Y);
        }
    }
    if ((setName == null) || Constants.EMPTY_STRING.equals(setName) || (setID == null) || Constants.EMPTY_STRING.equals(setID)) {
        final String message = "Illegal EquipSet line ignored: " + line;
        warnings.add(message);
        return;
    }
    final EquipSet aEquipSet;
    aEquipSet = new EquipSet(setID, setName);
    if (setNote != null) {
        aEquipSet.setNote(setNote);
    }
    if (itemKey != null) {
        aEquipSet.setValue(itemKey);
        Equipment eqI = thePC.getEquipmentNamed(itemKey);
        if (eqI == null) {
            eqI = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, itemKey);
        }
        if (eqI == null) {
            final String message = "Could not find equipment: " + itemKey;
            warnings.add(message);
            return;
        }
        Equipment aEquip = eqI.clone();
        if (itemQuantity != null) {
            aEquipSet.setQty(itemQuantity);
            aEquip.setQty(itemQuantity);
            aEquip.setNumberCarried(itemQuantity);
        }
        // it's inside a container
        if (//$NON-NLS-1$
        (new StringTokenizer(setID, ".")).countTokens() > 3) {
            // get parent EquipSet
            final EquipSet aEquipSet2 = thePC.getEquipSetByIdPath(aEquipSet.getParentIdPath());
            // get the container
            Equipment aEquip2 = null;
            if (aEquipSet2 != null) {
                aEquip2 = aEquipSet2.getItem();
            }
            // add the child to container
            if (aEquip2 != null) {
                aEquip2.insertChild(thePC, aEquip);
                aEquip.setParent(aEquip2);
            }
        }
        aEquipSet.setItem(aEquip);
    }
    aEquipSet.setUseTempMods(useTempMods);
    thePC.addEquipSet(aEquipSet);
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet)

Example 73 with EquipSet

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

the class PCGVer2Creator method appendEqSetBonuses.

/**
	 * For each EquipSet, check for a tempBonusList and if found, save each
	 * bonus
	 * 
	 * @param buffer
	 */
private void appendEqSetBonuses(StringBuilder buffer) {
    for (EquipSet eSet : charDisplay.getEquipSet()) {
        if (eSet.useTempBonusList()) {
            buffer.append(IOConstants.TAG_EQSETBONUS).append(':');
            buffer.append(eSet.getIdPath());
            List<String> trackList = new ArrayList<>();
            for (Map.Entry<BonusObj, BonusManager.TempBonusInfo> me : eSet.getTempBonusMap().entrySet()) {
                //BonusObj bObj = me.getKey();
                TempBonusInfo tbi = me.getValue();
                Object cObj = tbi.source;
                Object tObj = tbi.target;
                final String aName = tempBonusName(cObj, tObj);
                if (trackList.contains(aName)) {
                    continue;
                }
                trackList.add(aName);
                buffer.append('|');
                buffer.append(IOConstants.TAG_TEMPBONUSBONUS).append(':');
                buffer.append(EntityEncoder.encode(aName));
            }
            buffer.append(IOConstants.LINE_SEP);
        }
    }
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) BonusObj(pcgen.core.bonus.BonusObj) EquipSet(pcgen.core.character.EquipSet) ArrayList(java.util.ArrayList) CDOMListObject(pcgen.cdom.base.CDOMListObject) CDOMObject(pcgen.cdom.base.CDOMObject) Map(java.util.Map)

Example 74 with EquipSet

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

the class NaturalEquipSetFacet method dataAdded.

/**
	 * Adds a piece of TYPE=Natural Equipment to the Natural EquipSet when the
	 * Equipment is added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which MovementResultFacet listens
	 * fires a DataFacetChangeEvent to indicate a CDOMObject was added to a
	 * Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, Equipment> dfce) {
    PlayerCharacter pc = trackingFacet.getPC(dfce.getCharID());
    EquipSet eSet = pc.getEquipSetByIdPath(EquipSet.DEFAULT_SET_PATH);
    if (eSet != null) {
        Equipment eq = dfce.getCDOMObject();
        EquipSet es = pc.addEquipToTarget(eSet, null, "", eq, null);
        if (es == null) {
            pc.addEquipToTarget(eSet, null, Constants.EQUIP_LOCATION_CARRIED, eq, null);
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet)

Example 75 with EquipSet

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

the class EquipSetFacet method updateEquipSetItem.

/**
	 * Search all of the PC equipment sets and replace all instances of oldItem with newItem.
	 * @param id The ID of the PC.
	 * @param oldItem the item to search for.
	 * @param newItem The replacement item
	 */
public void updateEquipSetItem(CharID id, Equipment oldItem, Equipment newItem) {
    if (isEmpty(id)) {
        return;
    }
    final List<EquipSet> tmpList = new ArrayList<>();
    // find all oldItem EquipSet's
    for (EquipSet es : getSet(id)) {
        final Equipment eqI = es.getItem();
        if ((eqI != null) && oldItem.equals(eqI)) {
            tmpList.add(es);
        }
    }
    for (EquipSet es : tmpList) {
        es.setValue(newItem.getName());
        es.setItem(newItem);
    }
}
Also used : Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet) ArrayList(java.util.ArrayList)

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