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"));
}
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;
}
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()]);
}
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;
}
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 :)
}
}
Aggregations