use of pcgen.cdom.helper.ShieldProfProvider in project pcgen by PCGen.
the class ShieldProfFacet method dataAdded.
/**
* Processes added CDOMObjects to determine whether they contained an
* AUTO:SHIELDPROF, and if so, processes the contents of that token to add
* the appropriate ShieldProfProviders to the Player Character.
*
* Triggered when one of the Facets to which ShieldProfFacet listens fires a
* DataFacetChangeEvent to indicate a CDOMObject was added to a Player
* Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
List<ShieldProfProvider> shieldProfs = cdo.getListFor(ListKey.AUTO_SHIELDPROF);
if (shieldProfs != null) {
shieldProfProviderFacet.addAll(dfce.getCharID(), shieldProfs, cdo);
}
}
use of pcgen.cdom.helper.ShieldProfProvider in project pcgen by PCGen.
the class PCClass method inheritAttributesFrom.
/*
* REFACTOR Some derivative of this method will be in PCClass only as part
* of the factory creation of a PCClassLevel... or perhaps in PCClassLevel
* so it can steal some information from other PCClassLevels of that
* PCClass. Either way, this will be far from its current form in the final
* solution.
*/
/*
* CONSIDER Why does this not inherit classSkillChoices?
*/
public void inheritAttributesFrom(final PCClass otherClass) {
Boolean hbss = otherClass.get(ObjectKey.HAS_BONUS_SPELL_STAT);
if (hbss != null) {
put(ObjectKey.HAS_BONUS_SPELL_STAT, hbss);
CDOMSingleRef<PCStat> bss = otherClass.get(ObjectKey.BONUS_SPELL_STAT);
if (bss != null) {
put(ObjectKey.BONUS_SPELL_STAT, bss);
}
}
Boolean usbs = otherClass.get(ObjectKey.USE_SPELL_SPELL_STAT);
if (usbs != null) {
put(ObjectKey.USE_SPELL_SPELL_STAT, usbs);
}
Boolean cwss = otherClass.get(ObjectKey.CASTER_WITHOUT_SPELL_STAT);
if (cwss != null) {
put(ObjectKey.CASTER_WITHOUT_SPELL_STAT, cwss);
}
CDOMSingleRef<PCStat> ss = otherClass.get(ObjectKey.SPELL_STAT);
if (ss != null) {
put(ObjectKey.SPELL_STAT, ss);
}
TransitionChoice<CDOMListObject<Spell>> slc = otherClass.get(ObjectKey.SPELLLIST_CHOICE);
if (slc != null) {
put(ObjectKey.SPELLLIST_CHOICE, slc);
}
List<QualifiedObject<CDOMReference<Equipment>>> e = otherClass.getListFor(ListKey.EQUIPMENT);
if (e != null) {
addAllToListFor(ListKey.EQUIPMENT, e);
}
List<WeaponProfProvider> wp = otherClass.getListFor(ListKey.WEAPONPROF);
if (wp != null) {
addAllToListFor(ListKey.WEAPONPROF, wp);
}
QualifiedObject<Boolean> otherWP = otherClass.get(ObjectKey.HAS_DEITY_WEAPONPROF);
if (otherWP != null) {
put(ObjectKey.HAS_DEITY_WEAPONPROF, otherWP);
}
List<ArmorProfProvider> ap = otherClass.getListFor(ListKey.AUTO_ARMORPROF);
if (ap != null) {
addAllToListFor(ListKey.AUTO_ARMORPROF, ap);
}
List<ShieldProfProvider> sp = otherClass.getListFor(ListKey.AUTO_SHIELDPROF);
if (sp != null) {
addAllToListFor(ListKey.AUTO_SHIELDPROF, sp);
}
List<BonusObj> bonusList = otherClass.getListFor(ListKey.BONUS);
if (bonusList != null) {
addAllToListFor(ListKey.BONUS, bonusList);
}
try {
ownBonuses(this);
} catch (CloneNotSupportedException ce) {
// TODO Auto-generated catch block
ce.printStackTrace();
}
for (VariableKey vk : otherClass.getVariableKeys()) {
put(vk, otherClass.get(vk));
}
if (otherClass.containsListFor(ListKey.CSKILL)) {
removeListFor(ListKey.CSKILL);
addAllToListFor(ListKey.CSKILL, otherClass.getListFor(ListKey.CSKILL));
}
if (otherClass.containsListFor(ListKey.LOCALCCSKILL)) {
removeListFor(ListKey.LOCALCCSKILL);
addAllToListFor(ListKey.LOCALCCSKILL, otherClass.getListFor(ListKey.LOCALCCSKILL));
}
removeListFor(ListKey.KIT_CHOICE);
addAllToListFor(ListKey.KIT_CHOICE, otherClass.getSafeListFor(ListKey.KIT_CHOICE));
remove(ObjectKey.REGION_CHOICE);
if (otherClass.containsKey(ObjectKey.REGION_CHOICE)) {
put(ObjectKey.REGION_CHOICE, otherClass.get(ObjectKey.REGION_CHOICE));
}
removeListFor(ListKey.SAB);
addAllToListFor(ListKey.SAB, otherClass.getSafeListFor(ListKey.SAB));
/*
* TODO Does this need to have things from the Class Level objects?
* I don't think so based on deferred processing of levels...
*/
addAllToListFor(ListKey.DAMAGE_REDUCTION, otherClass.getListFor(ListKey.DAMAGE_REDUCTION));
for (CDOMReference<Vision> ref : otherClass.getSafeListMods(Vision.VISIONLIST)) {
for (AssociatedPrereqObject apo : otherClass.getListAssociations(Vision.VISIONLIST, ref)) {
putToList(Vision.VISIONLIST, ref, apo);
}
}
/*
* TODO This is a clone problem, but works for now - thpr 10/3/08
*/
if (otherClass instanceof SubClass) {
levelMap.clear();
copyLevelsFrom(otherClass);
}
addAllToListFor(ListKey.NATURAL_WEAPON, otherClass.getListFor(ListKey.NATURAL_WEAPON));
put(ObjectKey.LEVEL_HITDIE, otherClass.get(ObjectKey.LEVEL_HITDIE));
}
use of pcgen.cdom.helper.ShieldProfProvider in project pcgen by PCGen.
the class ShieldProfTokenTest method loadTypeProf.
@Override
protected void loadTypeProf(String... types) {
CDOMGroupRef<Equipment> ref = primaryContext.getReferenceContext().getCDOMTypeReference(Equipment.class, types);
List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<>();
List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
equipTypes.add(ref);
ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
primaryProf.addToListFor(ListKey.AUTO_SHIELDPROF, pp);
}
use of pcgen.cdom.helper.ShieldProfProvider in project pcgen by PCGen.
the class ShieldProfToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
String shieldProf;
// Do not initialize, null is significant!
Prerequisite prereq = null;
boolean isPre = false;
if (value.indexOf("[") == -1) {
// Supported version of PRExxx using |. Needs to be at the front of the
// Parsing code because many objects expect the pre to have been determined
// Ahead of time. Until deprecated code is removed, it will have to stay
// like this.
shieldProf = value;
StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (PreParserFactory.isPreReqString(token)) {
if (isPre) {
String errorText = "Invalid " + getTokenName() + ": " + value + " PRExxx must be at the END of the Token";
Logging.errorPrint(errorText);
return new ParseResult.Fail(errorText, context);
}
prereq = getPrerequisite(token);
if (prereq == null) {
return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
}
int preStart = value.indexOf(token) - 1;
shieldProf = value.substring(0, preStart);
isPre = true;
}
}
} else {
return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
}
ParseResult pr = checkForIllegalSeparator('|', shieldProf);
if (!pr.passed()) {
return pr;
}
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE);
List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<>();
List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
while (tok.hasMoreTokens()) {
String aProf = tok.nextToken();
if (Constants.LST_PERCENT_LIST.equals(aProf)) {
foundOther = true;
ChooseSelectionActor<ShieldProf> cra;
if (prereq == null) {
cra = this;
} else {
ConditionalSelectionActor<ShieldProf> cca = new ConditionalSelectionActor<>(this);
cca.addPrerequisite(prereq);
cra = cca;
}
context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
} else if (Constants.LST_ALL.equalsIgnoreCase(aProf)) {
foundAny = true;
shieldProfs.add(context.getReferenceContext().getCDOMAllReference(SHIELDPROF_CLASS));
} else if (aProf.startsWith("SHIELDTYPE.") || aProf.startsWith("SHIELDTYPE=")) {
foundOther = true;
CDOMReference<Equipment> ref = TokenUtilities.getTypeReference(context, EQUIPMENT_CLASS, "SHIELD." + aProf.substring(11));
if (ref == null) {
return ParseResult.INTERNAL_ERROR;
}
equipTypes.add(ref);
} else {
foundOther = true;
shieldProfs.add(context.getReferenceContext().getCDOMReference(SHIELDPROF_CLASS, aProf));
}
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
if (!shieldProfs.isEmpty() || !equipTypes.isEmpty()) {
ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
if (prereq != null) {
pp.addPrerequisite(prereq);
}
context.getObjectContext().addToList(obj, ListKey.AUTO_SHIELDPROF, pp);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.helper.ShieldProfProvider in project pcgen by PCGen.
the class ShieldProfToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<ShieldProfProvider> changes = context.getObjectContext().getListChanges(obj, ListKey.AUTO_SHIELDPROF);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
Collection<ShieldProfProvider> added = changes.getAdded();
Set<String> set = new TreeSet<>();
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
boolean foundAny = false;
boolean foundOther = false;
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> cra : listAdded) {
if (cra.getSource().equals(getTokenName())) {
try {
set.add(cra.getLstFormat());
foundOther = true;
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (added != null) {
for (ShieldProfProvider spp : added) {
StringBuilder sb = new StringBuilder();
sb.append(spp.getLstFormat());
if (spp.hasPrerequisites()) {
sb.append('|');
sb.append(getPrerequisiteString(context, spp.getPrerequisiteList()));
}
String ab = sb.toString();
boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
foundAny |= isUnconditionalAll;
foundOther |= !isUnconditionalAll;
set.add(ab);
}
}
if (foundAny && foundOther) {
context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + set);
return null;
}
if (set.isEmpty()) {
//okay
return null;
}
return set.toArray(new String[set.size()]);
}
Aggregations