use of pcgen.cdom.helper.Aspect in project pcgen by PCGen.
the class AbilityToken method getHasAspectString.
/**
* Gets the boolean (Y/N) string for the presence of the named aspect.
*
* @param ability
* The ability being queried.
* @param key
* The key (name only) of the aspect to check
*
* @return Y if the aspect is present, N if not.
*/
private String getHasAspectString(PlayerCharacter pc, Ability ability, AspectName key) {
List<Aspect> aspects = ability.get(MapKey.ASPECT, key);
Aspect aspect = Aspect.lastPassingAspect(aspects, pc, ability);
if (aspect == null) {
return "N";
}
return "Y";
}
use of pcgen.cdom.helper.Aspect in project pcgen by PCGen.
the class AbilityTokenTest method setUp.
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
PlayerCharacter character = getCharacter();
// Make some ability categories and add them to the game mode
Ability ab1 = TestHelper.makeAbility("Perform (Dance)", AbilityCategory.FEAT, "General.Fighter");
ab1.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
ab1.put(ObjectKey.VISIBILITY, Visibility.DEFAULT);
List<Aspect> colourList = new ArrayList<>();
colourList.add(new Aspect("Colour", "Green"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Colour"), colourList);
List<Aspect> sizeList = new ArrayList<>();
sizeList.add(new Aspect("Size", "L"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Size"), sizeList);
List<Aspect> shapeList = new ArrayList<>();
Aspect cube = new Aspect("Shape", "Cube");
Prerequisite prereq = new Prerequisite();
prereq.setKind("ALIGN");
prereq.setKey("LG");
prereq.setOperator(PrerequisiteOperator.EQ);
cube.addPrerequisite(prereq);
shapeList.add(cube);
shapeList.add(new Aspect("Shape", "Icosahedron"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Shape"), shapeList);
List<Aspect> sidesList = new ArrayList<>();
sidesList.add(new Aspect("Sides", "20"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Sides"), sidesList);
List<Aspect> ageList = new ArrayList<>();
ageList.add(new Aspect("Age In Years", "2000"));
ab1.addToMapFor(MapKey.ASPECT, AspectName.getConstant("Age In Years"), ageList);
addAbility(AbilityCategory.FEAT, ab1);
TestHelper.makeSkill("Bluff", "Charisma", cha, true, SkillArmorCheck.NONE);
TestHelper.makeSkill("Listen", "Wisdom", wis, true, SkillArmorCheck.NONE);
skillFocus = TestHelper.makeAbility("Skill Focus", AbilityCategory.FEAT, "General");
BonusObj aBonus = Bonus.newBonus(Globals.getContext(), "SKILL|LIST|3");
if (aBonus != null) {
skillFocus.addToListFor(ListKey.BONUS, aBonus);
}
skillFocus.put(ObjectKey.MULTIPLE_ALLOWED, true);
Globals.getContext().unconditionallyProcess(skillFocus, "CHOOSE", "SKILL|ALL");
AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, skillFocus, "KEY_Bluff");
AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, skillFocus, "KEY_Listen");
character.calcActiveBonuses();
}
use of pcgen.cdom.helper.Aspect in project pcgen by PCGen.
the class AspectToken method unparse.
/*
* (non-Javadoc)
*
* @see pcgen.rules.persistence.token.CDOMPrimaryParserToken#unparse(pcgen.rules.context.LoadContext,
* java.lang.Object)
*/
@Override
public String[] unparse(LoadContext context, Ability ability) {
MapChanges<AspectName, List<Aspect>> changes = context.getObjectContext().getMapChanges(ability, MapKey.ASPECT);
if (changes == null || changes.isEmpty()) {
return null;
}
Set<String> set = new TreeSet<>();
Set<AspectName> keys = changes.getAdded().keySet();
for (AspectName an : keys) {
List<Aspect> aspects = changes.getAdded().get(an);
for (int i = 0; i < aspects.size(); i++) {
Aspect q = aspects.get(i);
set.add(new StringBuilder().append(q.getName()).append(Constants.PIPE).append(q.getPCCText()).toString());
}
}
return set.toArray(new String[set.size()]);
}
use of pcgen.cdom.helper.Aspect in project pcgen by PCGen.
the class AspectToken method parseAspect.
/**
* Parses the ASPECT tag into a Aspect object.
*
* @param aspectDef
* The LST tag
* @return A <tt>Aspect</tt> object
*/
public Aspect parseAspect(final String name, final String aspectDef) {
final StringTokenizer tok = new StringTokenizer(aspectDef, Constants.PIPE);
String firstToken = tok.nextToken();
/*if (PreParserFactory.isPreReqString(firstToken))
{
Logging.errorPrint("Invalid " + getTokenName() + ": " + name);
Logging.errorPrint(" PRExxx can not be only value");
return null;
}*/
final Aspect aspect = new Aspect(name, EntityEncoder.decode(firstToken));
boolean isPre = false;
while (tok.hasMoreTokens()) {
final String token = tok.nextToken();
if (PreParserFactory.isPreReqString(token)) {
Prerequisite prereq = getPrerequisite(token);
if (prereq == null) {
Logging.errorPrint(getTokenName() + " had invalid prerequisite : " + token);
return null;
}
aspect.addPrerequisite(prereq);
isPre = true;
} else {
if (isPre) {
Logging.errorPrint("Invalid " + getTokenName() + ": " + name);
Logging.errorPrint(" PRExxx must be at the END of the Token");
return null;
}
aspect.addVariable(token);
}
}
return aspect;
}
use of pcgen.cdom.helper.Aspect in project pcgen by PCGen.
the class MapKeyMapTest method testAddToMapFor.
/**
* Test adding an entry to the map overwriting an existing entry.
*/
@Test
public void testAddToMapFor() {
assertEquals("Validate initial value of age", ageAspect, mapKeyMap.get(MapKey.ASPECT, ageKey).get(0));
Aspect newage = new Aspect("age", "2");
List<Aspect> ageList = new ArrayList<>();
ageList.add(newage);
mapKeyMap.addToMapFor(MapKey.ASPECT, ageKey, ageList);
assertEquals("Validate new value of age", newage, mapKeyMap.get(MapKey.ASPECT, ageKey).get(0));
}
Aggregations