Search in sources :

Example 16 with EquipmentModifier

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());
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 17 with EquipmentModifier

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());
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) Test(org.junit.Test)

Example 18 with EquipmentModifier

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;
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) InfoFacade(pcgen.facade.core.InfoFacade) AbilityFacade(pcgen.facade.core.AbilityFacade) PObject(pcgen.core.PObject) Spell(pcgen.core.spell.Spell)

Example 19 with EquipmentModifier

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;
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier)

Example 20 with EquipmentModifier

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) EquipmentModifier(pcgen.core.EquipmentModifier) ParseResult(pcgen.rules.persistence.token.ParseResult) EqModRef(pcgen.cdom.helper.EqModRef)

Aggregations

EquipmentModifier (pcgen.core.EquipmentModifier)25 Equipment (pcgen.core.Equipment)8 EqModRef (pcgen.cdom.helper.EqModRef)5 StringTokenizer (java.util.StringTokenizer)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 BigDecimal (java.math.BigDecimal)3 Test (org.junit.Test)3 EquipmentHead (pcgen.cdom.inst.EquipmentHead)3 BonusObj (pcgen.core.bonus.BonusObj)3 EquipSet (pcgen.core.character.EquipSet)3 ArrayList (java.util.ArrayList)2 Formula (pcgen.base.formula.Formula)2 CharID (pcgen.cdom.enumeration.CharID)2 GameMode (pcgen.core.GameMode)2 PCTemplate (pcgen.core.PCTemplate)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 Race (pcgen.core.Race)2 SizeAdjustment (pcgen.core.SizeAdjustment)2 LoadContext (pcgen.rules.context.LoadContext)2 HashSet (java.util.HashSet)1