use of pcgen.core.EquipmentModifier in project pcgen by PCGen.
the class AbstractContentTokenTest method testFromEqMod.
@Test
public void testFromEqMod() throws PersistenceLayerException {
EquipmentModifier source = create(EquipmentModifier.class, "Source");
processToken(source);
assertEquals(baseCount(), targetFacetCount());
activeEqModFacet.add(id, source, this);
assertTrue(containsExpected());
assertEquals(baseCount() + 1, targetFacetCount());
activeEqModFacet.remove(id, source, this);
assertEquals(baseCount(), targetFacetCount());
}
use of pcgen.core.EquipmentModifier in project pcgen by PCGen.
the class AbstractGrantedListTokenTest method testFromEqMod.
@Test
public void testFromEqMod() throws PersistenceLayerException {
EquipmentModifier source = create(EquipmentModifier.class, "Source");
T granted = createGrantedObject();
processToken(source);
assertEquals(0, getCount());
activeEqModFacet.add(id, source, this);
assertTrue(containsExpected(granted));
assertEquals((activeEqModFacet == getTargetFacet()) ? 2 : 1, getCount());
activeEqModFacet.remove(id, source, this);
assertEquals(0, getCount());
assertTrue(cleanedSideEffects());
}
use of pcgen.core.EquipmentModifier in project pcgen by PCGen.
the class EquipmentBuilderFacadeImpl method getSpellChoiceForEqMod.
private boolean getSpellChoiceForEqMod(EquipmentModifier eqMod) {
String choiceValue = eqMod.getSafe(StringKey.CHOICE_STRING).substring(15);
SpellBuilderFacadeImpl spellBuilderFI = new SpellBuilderFacadeImpl(choiceValue, character, equip);
if (!delegate.showCustomSpellDialog(spellBuilderFI)) {
return false;
}
InfoFacade castingClass = spellBuilderFI.getClassRef().get();
Spell theSpell = (Spell) spellBuilderFI.getSpellRef().get();
String variant = spellBuilderFI.getVariantRef().get();
if (variant == null) {
variant = "";
}
String spellType = spellBuilderFI.getSpellTypeRef().get();
int baseSpellLevel = spellBuilderFI.getSpellLevelRef().get();
int casterLevel = spellBuilderFI.getCasterLevelRef().get();
ListFacade<AbilityFacade> metamagicFeatsList = spellBuilderFI.getSelectedMetamagicFeats();
Object[] metamagicFeats = new Object[metamagicFeatsList.getSize()];
for (int i = 0; i < metamagicFeats.length; i++) {
metamagicFeats[i] = metamagicFeatsList.getElementAt(i);
}
int charges = getNumCharges(eqMod);
EquipmentModifier existingEqMod = equip.getEqModifierKeyed(eqMod.getKeyName(), true);
if (existingEqMod == null) {
equip.addEqModifier(eqMod, true, character);
}
existingEqMod = equip.getEqModifierKeyed(eqMod.getKeyName(), true);
EqModSpellInfo.setSpellInfo(equip, existingEqMod, (PObject) castingClass, theSpell, variant, spellType, baseSpellLevel, casterLevel, metamagicFeats, charges);
return true;
}
use of pcgen.core.EquipmentModifier in project pcgen by PCGen.
the class EquipmentBuilderFacadeImpl method addModToEquipment.
@Override
public boolean addModToEquipment(EquipModFacade modifier, EquipmentHead head) {
if (modifier == null || !(modifier instanceof EquipmentModifier) || head == null) {
return false;
}
EquipmentModifier equipMod = (EquipmentModifier) modifier;
// Trash the cost modifications
equip.setCostMod("0");
// Handle spells
if (equipMod.getSafe(StringKey.CHOICE_STRING).startsWith("EQBUILDER.SPELL")) {
if (!getSpellChoiceForEqMod(equipMod)) {
return false;
}
}
equip.addEqModifier(equipMod, head.isPrimary(), character);
if (equip.isDouble() && equipMod.getSafe(ObjectKey.ASSIGN_TO_ALL)) {
equip.addEqModifier(equipMod, !head.isPrimary(), character);
}
equip.nameItemFromModifiers(character);
refreshAvailList();
refreshSelectedList();
return true;
}
use of pcgen.core.EquipmentModifier in project pcgen by PCGen.
the class EqmodToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, KitGear kitGear, String value) {
StringTokenizer dotTok = new StringTokenizer(value, Constants.DOT);
while (dotTok.hasMoreTokens()) {
String aEqModName = dotTok.nextToken();
if (aEqModName.equalsIgnoreCase(Constants.LST_NONE)) {
return new ParseResult.Fail("Embedded " + Constants.LST_NONE + " is prohibited in " + getTokenName(), context);
}
ParseResult pr = checkForIllegalSeparator('|', aEqModName);
if (!pr.passed()) {
return pr;
}
StringTokenizer pipeTok = new StringTokenizer(aEqModName, Constants.PIPE);
// The type of EqMod, eg: ABILITYPLUS
final String eqModKey = pipeTok.nextToken();
CDOMSingleRef<EquipmentModifier> eqMod = context.getReferenceContext().getCDOMReference(EQUIPMENT_MODIFIER_CLASS, eqModKey);
EqModRef modRef = new EqModRef(eqMod);
while (pipeTok.hasMoreTokens()) {
String assocTok = pipeTok.nextToken();
if (assocTok.indexOf(']') != -1) {
if (assocTok.indexOf("[]") != -1) {
return new ParseResult.Fail("Found empty assocation in " + getTokenName() + ": " + value, context);
}
StringTokenizer bracketTok = new StringTokenizer(assocTok, "]");
while (bracketTok.hasMoreTokens()) {
String assoc = bracketTok.nextToken();
int openBracketLoc = assoc.indexOf('[');
if (openBracketLoc == -1) {
return new ParseResult.Fail("Found close bracket without open bracket " + "in assocation in " + getTokenName() + ": " + value, context);
}
if (openBracketLoc != assoc.lastIndexOf('[')) {
return new ParseResult.Fail("Found open bracket without close bracket " + "in assocation in " + getTokenName() + ": " + value, context);
}
}
}
modRef.addChoice(assocTok);
}
kitGear.addModRef(modRef);
}
return ParseResult.SUCCESS;
}
Aggregations