use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class AbilityLoader method getObjectKeyed.
/**
* @see pcgen.persistence.lst.LstObjectFileLoader#getObjectKeyed(LoadContext, java.lang.String)
*/
@Override
protected Ability getObjectKeyed(LoadContext context, String aKey) {
if (aKey == null || aKey.isEmpty()) {
return null;
}
String abilityCatName;
String abilityKey;
String[] parts = aKey.split("\\|");
if (parts.length == 2 && parts[0].startsWith("CATEGORY=")) {
abilityCatName = parts[0].substring(9);
abilityKey = parts[1];
} else {
String message = "Attempt to Modify/Copy/Forget an Ability (" + aKey + ") without a CATEGORY=\n" + " Proper format is CATEGORY=cat|abilityKey";
Logging.log(Logging.LST_ERROR, message);
return null;
}
AbilityCategory ac = SettingsHandler.getGame().getAbilityCategory(abilityCatName);
return context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, ac, abilityKey);
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class QualifyIntegrationTest method testRoundRobinNoReset.
@Test
public void testRoundRobinNoReset() throws PersistenceLayerException {
verifyCleanStart();
AbilityCategory pac = primaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
AbilityCategory sac = secondaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
Ability ab = primaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
primaryContext.getReferenceContext().reassociateCategory(pac, ab);
ab = secondaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
secondaryContext.getReferenceContext().reassociateCategory(sac, ab);
TestContext tc = new TestContext();
commit(testCampaign, tc, "ABILITY=NEWCAT|Abil3");
emptyCommit(modCampaign, tc);
completeRoundRobin(tc);
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class PCGVer2Parser method parseTempBonusLine.
/**
* ###############################################################
* Temporary Bonuses
* ###############################################################
* @param line
**/
private void parseTempBonusLine(final String line) {
PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String message = "Illegal TempBonus line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
warnings.add(message);
return;
}
String cTag = null;
String tName = null;
boolean active = true;
for (PCGElement element : tokens.getElements()) {
final String tag = element.getName();
if (IOConstants.TAG_TEMPBONUS.equals(tag)) {
cTag = EntityEncoder.decode(element.getText());
} else if (IOConstants.TAG_TEMPBONUSTARGET.equals(tag)) {
tName = EntityEncoder.decode(element.getText());
} else if (IOConstants.TAG_TEMPBONUSACTIVE.equals(tag)) {
active = element.getText().endsWith(IOConstants.VALUE_Y);
}
}
if ((cTag == null) || (tName == null)) {
warnings.add("Illegal TempBonus line ignored: " + line);
return;
}
//$NON-NLS-1$
final StringTokenizer aTok = new StringTokenizer(cTag, "=", false);
if (aTok.countTokens() < 2) {
return;
}
final String cType = aTok.nextToken();
final String cKey = aTok.nextToken();
Equipment aEq = null;
if (!tName.equals(IOConstants.TAG_PC)) {
// bonus is applied to an equipment item
// so create a new one and add to PC
final Equipment eq = thePC.getEquipmentNamed(tName);
if (eq == null) {
return;
}
aEq = eq.clone();
//aEq.setWeight("0");
aEq.resetTempBonusList();
}
for (PCGElement element : tokens.getElements()) {
final String tag = element.getName();
final String bonus;
if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
bonus = EntityEncoder.decode(element.getText());
} else {
continue;
}
if ((bonus == null) || (bonus.length() <= 0)) {
continue;
}
BonusObj newB = null;
Object creator = null;
LoadContext context = Globals.getContext();
// type of object to set as the creator
if (cType.equals(IOConstants.TAG_FEAT)) {
for (AbilityCategory aCat : SettingsHandler.getGame().getAllAbilityCategories()) {
Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, aCat, cKey);
if (a != null) {
newB = Bonus.newBonus(context, bonus);
creator = a;
break;
}
}
} else if (cType.equals(IOConstants.TAG_EQUIPMENT)) {
Equipment aEquip = thePC.getEquipmentNamed(cKey);
if (aEquip == null) {
aEquip = context.getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, cKey);
}
if (aEquip != null) {
newB = Bonus.newBonus(context, bonus);
creator = aEquip;
}
} else if (cType.equals(IOConstants.TAG_CLASS)) {
final PCClass aClass = thePC.getClassKeyed(cKey);
if (aClass == null) {
continue;
}
int idx = bonus.indexOf('|');
newB = Bonus.newBonus(context, bonus.substring(idx + 1));
creator = aClass;
} else if (cType.equals(IOConstants.TAG_TEMPLATE)) {
PCTemplate aTemplate = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, cKey);
if (aTemplate != null) {
newB = Bonus.newBonus(context, bonus);
creator = aTemplate;
}
} else if (cType.equals(IOConstants.TAG_SKILL)) {
Skill aSkill = context.getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, cKey);
if (aSkill != null) {
newB = Bonus.newBonus(context, bonus);
creator = aSkill;
}
} else if (cType.equals(IOConstants.TAG_SPELL)) {
final Spell aSpell = context.getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, cKey);
if (aSpell != null) {
newB = Bonus.newBonus(context, bonus);
creator = aSpell;
}
} else if (cType.equals(IOConstants.TAG_NAME)) {
newB = Bonus.newBonus(context, bonus);
//newB.setCreatorObject(thePC);
}
if (newB == null) {
return;
}
TempBonusInfo tempBonusInfo;
// Check to see if the target was the PC or an Item
if (tName.equals(IOConstants.TAG_PC)) {
thePC.setApplied(newB, true);
tempBonusInfo = thePC.addTempBonus(newB, creator, thePC);
} else {
thePC.setApplied(newB, true);
aEq.addTempBonus(newB);
tempBonusInfo = thePC.addTempBonus(newB, creator, aEq);
}
if (!active) {
String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
thePC.setTempBonusFilter(bonusName);
}
}
if (aEq != null) {
aEq.setAppliedName(cKey);
thePC.addTempBonusItemList(aEq);
}
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class PCGVer2Creator method appendAbilityLines.
/*
* ###############################################################
* Character Ability methods
* ###############################################################
*/
private void appendAbilityLines(StringBuilder buffer) {
ArrayList<AbilityCategory> categories = new ArrayList<>(getGameMode().getAllAbilityCategories());
categories.add(AbilityCategory.LANGBONUS);
Collection<CNAbilitySelection> virtSave = thePC.getSaveAbilities();
categories.sort(new Comparator<AbilityCategory>() {
@Override
public int compare(AbilityCategory a, AbilityCategory b) {
return a.getKeyName().compareTo(b.getKeyName());
}
});
for (final AbilityCategory cat : categories) {
final List<CNAbility> normalAbilitiesToSave = new ArrayList<>(thePC.getPoolAbilities(cat, Nature.NORMAL));
// ABILITY:FEAT|NORMAL|Feat Key|APPLIEDTO:xxx|TYPE:xxx|SAVE:xxx|DESC:xxx
Collections.sort(normalAbilitiesToSave);
for (final CNAbility ability : normalAbilitiesToSave) {
writeAbilityToBuffer(buffer, ability);
}
boolean hasVirt = false;
for (final CNAbilitySelection ability : virtSave) {
CNAbility cnAbility = ability.getCNAbility();
if (cnAbility.getAbilityCategory().equals(cat)) {
//TODO Need to write each CNAbility only once :/
writeAbilityToBuffer(buffer, cnAbility);
hasVirt = true;
}
}
if (!normalAbilitiesToSave.isEmpty() || hasVirt || thePC.getUserPoolBonus(cat) != 0.0) {
buffer.append(IOConstants.TAG_USERPOOL).append(IOConstants.TAG_END);
buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
buffer.append(IOConstants.TAG_POOLPOINTS).append(IOConstants.TAG_END);
buffer.append(thePC.getUserPoolBonus(cat));
buffer.append(IOConstants.LINE_SEP);
}
}
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class PCGVer2Parser method parseUserPoolLine.
private void parseUserPoolLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalAbilityPool", line, pcgpex.getMessage());
warnings.add(msg);
return;
}
final Iterator<PCGElement> it = tokens.getElements().iterator();
final String cat = EntityEncoder.decode(it.next().getText());
final AbilityCategory category = SettingsHandler.getGame().getAbilityCategory(cat);
try {
thePC.setUserPoolBonus(category, new BigDecimal(it.next().getText()));
} catch (NumberFormatException nfe) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalAbilityPool", line);
warnings.add(msg);
}
}
Aggregations