use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCClassKeyChange method renameBonusTarget.
private static void renameBonusTarget(CDOMObject cdo, String oldClass, String newClass) {
//
// Go through the bonus list (BONUS) and adjust the class to the new
// name
//
List<BonusObj> bonusList = cdo.getListFor(ListKey.BONUS);
if (bonusList != null) {
for (BonusObj bonusObj : bonusList) {
final String bonus = bonusObj.toString();
int offs = -1;
for (; ; ) {
offs = bonus.indexOf('=' + oldClass, offs + 1);
if (offs < 0) {
break;
}
LoadContext context = Globals.getContext();
final BonusObj aBonus = Bonus.newBonus(context, bonus.substring(0, offs + 1) + newClass + bonus.substring(offs + oldClass.length() + 1));
if (aBonus != null) {
cdo.addToListFor(ListKey.BONUS, aBonus);
}
cdo.removeFromListFor(ListKey.BONUS, bonusObj);
}
}
}
}
use of pcgen.rules.context.LoadContext 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.rules.context.LoadContext in project pcgen by PCGen.
the class GameModeFileLoader method loadGameModes.
private void loadGameModes(String[] gameFiles) {
SystemCollections.clearGameModeList();
File gameModeDir = new File(ConfigurationSettings.getSystemsDir(), "gameModes");
int progress = 0;
for (final String gameFile : gameFiles) {
File specGameModeDir = new File(gameModeDir, gameFile);
File miscInfoFile = new File(specGameModeDir, "miscinfo.lst");
final GameMode gm = GameModeFileLoader.loadGameModeMiscInfo(gameFile, miscInfoFile.toURI());
if (gm != null) {
String gmName = gm.getName();
//SettingsHandler.setGame(gmName);
LoadContext context = gm.getModeContext();
loadGameModeInfoFile(gm, new File(specGameModeDir, "level.lst").toURI(), "level");
loadGameModeInfoFile(gm, new File(specGameModeDir, "rules.lst").toURI(), "rules");
// Load equipmentslot.lst
GameModeFileLoader.loadGameModeLstFile(context, eqSlotLoader, gmName, gameFile, "equipmentslots.lst");
// Load paperInfo.lst
GameModeFileLoader.loadGameModeLstFile(context, paperLoader, gmName, gameFile, "paperInfo.lst");
// Load bio files
GameModeFileLoader.loadGameModeLstFile(context, traitLoader, gmName, gameFile, "bio" + File.separator + "traits.lst");
GameModeFileLoader.loadGameModeLstFile(context, locationLoader, gmName, gameFile, "bio" + File.separator + "locations.lst");
// Load load.lst and check for completeness
GameModeFileLoader.loadGameModeLstFile(context, loadInfoLoader, gmName, gameFile, "load.lst");
// Load sizeAdjustment.lst
GameModeFileLoader.loadGameModeLstFile(context, sizeLoader, gmName, gameFile, "sizeAdjustment.lst");
// Load statsandchecks.lst
GameModeFileLoader.loadGameModeLstFile(context, statCheckLoader, gmName, gameFile, "statsandchecks.lst");
// Load equipIcons.lst
GameModeFileLoader.loadGameModeLstFile(context, equipIconLoader, gmName, gameFile, "equipIcons.lst");
GameModeFileLoader.loadGameModeLstFile(context, codeControlLoader, gmName, gameFile, "codeControl.lst");
// Load pointbuymethods.lst
loadPointBuyFile(context, gameFile, gmName);
for (final PointBuyCost pbc : context.getReferenceContext().getConstructedCDOMObjects(PointBuyCost.class)) {
gm.addPointBuyStatCost(pbc);
}
// Load migration.lst
GameModeFileLoader.loadGameModeLstFile(context, migrationLoader, gmName, gameFile, "migration.lst");
GameModeFileLoader.loadGameModeLstFile(context, bioLoader, gmName, gameFile, "bio" + File.separator + "biosettings.lst");
}
try {
GameModeFileLoader.addDefaultWieldCategories(gm.getModeContext());
} catch (final PersistenceLayerException ple) {
Logging.errorPrint("Error Initializing PreParserFactory");
Logging.errorPrint(" " + ple.getMessage(), ple);
throw new UnreachableError();
}
progress++;
setProgress(progress);
}
SystemCollections.sortGameModeList();
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class Gui2InfoFactory method appendFacts.
private void appendFacts(HtmlInfoBuilder infoText, CDOMObject cdo) {
Class<? extends CDOMObject> cl = cdo.getClass();
LoadContext context = Globals.getContext();
Collection<FactDefinition> defs = context.getReferenceContext().getConstructedCDOMObjects(FactDefinition.class);
for (FactDefinition<?, ?> def : defs) {
if (def.getUsableLocation().isAssignableFrom(cl)) {
Visibility visibility = def.getVisibility();
if (visibility != null && visibility.isVisibleTo(View.VISIBLE_DISPLAY)) {
FactKey<?> fk = def.getFactKey();
Indirect<?> fact = cdo.get(fk);
if (fact != null) {
infoText.appendSpacer();
infoText.append("<b>");
infoText.append(fk.toString());
infoText.append(":</b> ");
infoText.append(fact.getUnconverted());
}
}
}
}
Collection<FactSetDefinition> setdefs = context.getReferenceContext().getConstructedCDOMObjects(FactSetDefinition.class);
for (FactSetDefinition<?, ?> def : setdefs) {
if (def.getUsableLocation().isAssignableFrom(cl)) {
Visibility visibility = def.getVisibility();
if (visibility != null && visibility.isVisibleTo(View.VISIBLE_DISPLAY)) {
FactSetKey<?> fk = def.getFactSetKey();
String s = getSetString(cdo, fk);
if (s != null) {
infoText.appendSpacer();
infoText.append("<b>");
infoText.append(fk.toString());
infoText.append(":</b> ");
infoText.append(s);
}
}
}
}
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class GenericLocalVariableLoader method loadLstFiles.
/**
* @see pcgen.persistence.lst.LstObjectFileLoader#loadLstFiles(pcgen.rules.context.LoadContext,
* java.util.List)
*/
@Override
public void loadLstFiles(LoadContext context, List<CampaignSourceEntry> fileList) throws PersistenceLayerException {
LoadContext subContext = context.dropIntoContext(varScope);
super.loadLstFiles(subContext, fileList);
}
Aggregations