Search in sources :

Example 1 with ChangeArmorType

use of pcgen.cdom.processor.ChangeArmorType in project pcgen by PCGen.

the class ArmortypeTokenTest method testUnparseMultiple.

@Test
public void testUnparseMultiple() throws PersistenceLayerException {
    primaryProf.addToListFor(ListKey.ARMORTYPE, new ChangeArmorType("Medium", "Light"));
    primaryProf.addToListFor(ListKey.ARMORTYPE, new ChangeArmorType("Heavy", "Medium"));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    assertNotNull(unparsed);
    assertEquals(2, unparsed.length);
    List<String> upList = Arrays.asList(unparsed);
    assertTrue(upList.contains("Medium|Light"));
    assertTrue(upList.contains("Heavy|Medium"));
}
Also used : ChangeArmorType(pcgen.cdom.processor.ChangeArmorType) Test(org.junit.Test)

Example 2 with ChangeArmorType

use of pcgen.cdom.processor.ChangeArmorType in project pcgen by PCGen.

the class ArmortypeToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, EquipmentModifier mod, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    ChangeArmorType cat;
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " has no PIPE character: Must be of the form old|new", context);
    } else if (pipeLoc != value.lastIndexOf(Constants.PIPE)) {
        return new ParseResult.Fail(getTokenName() + " has too many PIPE characters: " + "Must be of the form old|new", context);
    } else {
        /*
			 * TODO Are the ArmorTypes really a subset of Encumbrence?
			 */
        String oldType = value.substring(0, pipeLoc);
        String newType = value.substring(pipeLoc + 1);
        /*
			 * TODO Need some check if the Armor Types in value are not valid...
			 */
        cat = new ChangeArmorType(oldType, newType);
    }
    context.getObjectContext().addToList(mod, ListKey.ARMORTYPE, cat);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ChangeArmorType(pcgen.cdom.processor.ChangeArmorType)

Example 3 with ChangeArmorType

use of pcgen.cdom.processor.ChangeArmorType in project pcgen by PCGen.

the class ArmortypeToken method unparse.

@Override
public String[] unparse(LoadContext context, EquipmentModifier mod) {
    Changes<ChangeArmorType> changes = context.getObjectContext().getListChanges(mod, ListKey.ARMORTYPE);
    Collection<ChangeArmorType> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    TreeSet<String> set = new TreeSet<>();
    for (ChangeArmorType cat : added) {
        set.add(cat.getLSTformat());
    }
    return set.toArray(new String[set.size()]);
}
Also used : TreeSet(java.util.TreeSet) ChangeArmorType(pcgen.cdom.processor.ChangeArmorType)

Example 4 with ChangeArmorType

use of pcgen.cdom.processor.ChangeArmorType in project pcgen by PCGen.

the class Equipment method typeList.

/**
	 * Returns a list of the types of this item.
	 * 
	 * @param bPrimary
	 *            if true return the types if the primary head, otherwise
	 *            return the types of the secondary head
	 * @return a list of the types of this item.
	 */
private List<String> typeList(final boolean bPrimary) {
    if (bPrimary && usePrimaryCache) {
        return typeListCachePrimary;
    }
    if (!bPrimary && useSecondaryCache) {
        return typeListCacheSecondary;
    }
    // Use the primary type(s) if none defined for secondary
    List<Type> initializingList = getEquipmentHead(2).getListFor(ListKey.TYPE);
    if (bPrimary || (initializingList == null) || initializingList.isEmpty()) {
        initializingList = getTrueTypeList(false);
    } else if (!isDouble()) {
        return new ArrayList<>();
    }
    Set<String> calculatedTypeList = new LinkedHashSet<>();
    if (initializingList != null) {
        for (Type t : initializingList) {
            calculatedTypeList.add(t.getComparisonString());
        }
    }
    final Collection<String> modTypeList = new ArrayList<>();
    //
    // Add in all type modfiers from "ADDTYPE" modifier
    //
    EquipmentModifier aEqMod = getEqModifierKeyed("ADDTYPE", bPrimary);
    if (aEqMod != null) {
        for (String aType : getAssociationList(aEqMod)) {
            aType = aType.toUpperCase();
            if (!calculatedTypeList.contains(aType)) {
                modTypeList.add(aType);
            }
        }
    }
    /*
		 * CONSIDER I think there is a weird order of operations issue nere, need to check
		 * if it existed way back, e.g. SVN 6206.  The issue is if a Type is introduced by a 
		 * MOD, then the ChangeArmorType system doesn't seem to be able to grab/modify it
		 * Is that correct? - thpr 10/3/08
		 */
    //
    // Add in all of the types from each EquipmentModifier
    // currently applied to this piece of equipment
    //
    final List<EquipmentModifier> eqModList = getEqModifierList(bPrimary);
    for (EquipmentModifier eqMod : eqModList) {
        //
        // If we've just replaced the armor type, then make sure it is
        // not in the equipment modifier list
        //
        Set<String> newTypeList = new LinkedHashSet<>(calculatedTypeList);
        for (ChangeArmorType cat : eqMod.getSafeListFor(ListKey.ARMORTYPE)) {
            List<String> tempTypeList = cat.applyProcessor(newTypeList);
            LinkedHashSet<String> tempTypeSet = new LinkedHashSet<>(tempTypeList);
            boolean noMatch = newTypeList.size() != tempTypeList.size() || newTypeList.equals(tempTypeSet);
            newTypeList = tempTypeSet;
            if (!noMatch) {
                break;
            }
        }
        Collection<String> removedTypeList = new ArrayList<>(calculatedTypeList);
        removedTypeList.removeAll(newTypeList);
        modTypeList.removeAll(removedTypeList);
        calculatedTypeList = newTypeList;
        for (String aType : eqMod.getSafeListFor(ListKey.ITEM_TYPES)) {
            aType = aType.toUpperCase();
            // (melee and ranged)
            if (calculatedTypeList.contains("BOTH") && calculatedTypeList.contains("MELEE") && ("RANGED".equals(aType) || "THROWN".equals(aType))) {
                continue;
            }
            if (!calculatedTypeList.contains(aType) && !modTypeList.contains(aType)) {
                modTypeList.add(aType);
            }
        }
    }
    calculatedTypeList.addAll(modTypeList);
    //
    // Make sure MAGIC tag is the 1st entry
    //
    List<String> resultingTypeList = new ArrayList<>(calculatedTypeList);
    final int idx = resultingTypeList.indexOf("MAGIC");
    if (idx > 0) {
        resultingTypeList.remove(idx);
        resultingTypeList.add(0, "MAGIC");
    }
    if (bPrimary) {
        typeListCachePrimary = resultingTypeList;
        usePrimaryCache = true;
    } else {
        typeListCacheSecondary = resultingTypeList;
        useSecondaryCache = true;
    }
    return resultingTypeList;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ChangeArmorType(pcgen.cdom.processor.ChangeArmorType) ChangeArmorType(pcgen.cdom.processor.ChangeArmorType) MessageType(pcgen.core.utils.MessageType) Type(pcgen.cdom.enumeration.Type)

Example 5 with ChangeArmorType

use of pcgen.cdom.processor.ChangeArmorType in project pcgen by PCGen.

the class ArmortypeTokenTest method testUnparseNullTarget.

@Test
public void testUnparseNullTarget() throws PersistenceLayerException {
    try {
        primaryProf.addToListFor(ListKey.ARMORTYPE, new ChangeArmorType("Heavy", null));
        assertBadUnparse();
    } catch (IllegalArgumentException e) {
    // Good here too :)
    }
}
Also used : ChangeArmorType(pcgen.cdom.processor.ChangeArmorType) Test(org.junit.Test)

Aggregations

ChangeArmorType (pcgen.cdom.processor.ChangeArmorType)7 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 TreeSet (java.util.TreeSet)1 Type (pcgen.cdom.enumeration.Type)1 MessageType (pcgen.core.utils.MessageType)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1