Search in sources :

Example 11 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class RemoteModifierFacet method dataAdded.

@Override
public void dataAdded(DataFacetChangeEvent<CharID, VarScoped> dfce) {
    CharID id = dfce.getCharID();
    VarScoped vs = dfce.getCDOMObject();
    /*
		 * If this can have local variables, find what may have been modified by
		 * previous objects
		 */
    for (RemoteModifier<?> rm : getSet(id)) {
        VarScoped src = get(id, rm);
        ScopeInstance inst = scopeFacet.get(id, src);
        processAdd(id, rm, vs, inst);
        if (vs instanceof Equipment) {
            Equipment e = (Equipment) vs;
            for (EquipmentHead head : e.getEquipmentHeads()) {
                processAdd(id, rm, head, inst);
            }
        }
    }
    /*
		 * Look at what newly added object can modify on others
		 */
    if (vs instanceof CDOMObject) {
        ScopeInstance inst = scopeFacet.get(id, vs);
        List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
        if (list != null) {
            Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
            for (RemoteModifier<?> rm : list) {
                set(id, rm, vs);
                //Apply to existing as necessary
                for (VarScoped obj : targets) {
                    processAdd(id, rm, obj, inst);
                    if (obj instanceof Equipment) {
                        Equipment e = (Equipment) obj;
                        for (EquipmentHead head : e.getEquipmentHeads()) {
                            processAdd(id, rm, head, inst);
                        }
                    }
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) RemoteModifier(pcgen.cdom.content.RemoteModifier) VarScoped(pcgen.base.formula.base.VarScoped) CharID(pcgen.cdom.enumeration.CharID)

Example 12 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class RemoteModifierFacet method dataRemoved.

@Override
public void dataRemoved(DataFacetChangeEvent<CharID, VarScoped> dfce) {
    CharID id = dfce.getCharID();
    VarScoped vs = dfce.getCDOMObject();
    /*
		 * If this can have local variables, find what had been modified by
		 * previous objects
		 */
    for (RemoteModifier<?> rm : getSet(id)) {
        VarScoped src = get(id, rm);
        ScopeInstance inst = scopeFacet.get(id, src);
        processRemove(id, rm, vs, inst);
        if (vs instanceof Equipment) {
            Equipment e = (Equipment) vs;
            for (EquipmentHead head : e.getEquipmentHeads()) {
                processRemove(id, rm, head, inst);
            }
        }
    }
    /*
		 * Look at what newly added object can modify on others
		 */
    if (vs instanceof CDOMObject) {
        ScopeInstance inst = scopeFacet.get(id, vs);
        List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
        if (list != null) {
            Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
            for (RemoteModifier<?> rm : list) {
                remove(id, rm);
                //RemoveFrom existing as necessary
                for (VarScoped obj : targets) {
                    processRemove(id, rm, obj, inst);
                    if (obj instanceof Equipment) {
                        Equipment e = (Equipment) obj;
                        for (EquipmentHead head : e.getEquipmentHeads()) {
                            processRemove(id, rm, head, inst);
                        }
                    }
                }
            }
        }
    }
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) RemoteModifier(pcgen.cdom.content.RemoteModifier) VarScoped(pcgen.base.formula.base.VarScoped) CharID(pcgen.cdom.enumeration.CharID)

Example 13 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class NaturalWeaponFacet method dataAdded.

/**
	 * Adds any Natural Attacks (TYPE=Natural Equipment) which are granted by a
	 * CDOMObject which was added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which NaturalWeaponFacet 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<Equipment> weapons = cdo.getListFor(ListKey.NATURAL_WEAPON);
    if (weapons != null) {
        CharID id = dfce.getCharID();
        for (Equipment e : weapons) {
            add(id, e, cdo);
        }
    }
}
Also used : Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Example 14 with Equipment

use of pcgen.core.Equipment in project pcgen by PCGen.

the class EquipmentLoader method process.

@Override
public List<CDOMObject> process(StringBuilder sb, int line, String lineString, ConversionDecider decider) throws PersistenceLayerException, InterruptedException {
    String[] tokens = lineString.split(FIELD_SEPARATOR);
    if (tokens.length == 0) {
        return null;
    }
    String objectName = tokens[0];
    sb.append(objectName);
    List<CDOMObject> list = new ArrayList<>();
    for (int tok = 1; tok < tokens.length; tok++) {
        String token = tokens[tok];
        sb.append(FIELD_SEPARATOR);
        if (token.isEmpty()) {
            continue;
        }
        Equipment obj = context.getReferenceContext().constructCDOMObject(EQUIPMENT_CLASS, line + "Test" + tok + " " + token);
        obj.put(StringKey.CONVERT_NAME, tokens[0]);
        List<CDOMObject> injected = processToken(sb, objectName, obj, token, decider, line);
        if (injected != null) {
            list.addAll(injected);
        }
        EquipmentHead h1 = obj.getEquipmentHeadReference(1);
        if (h1 != null) {
            context.purge(h1);
        }
        EquipmentHead h2 = obj.getEquipmentHeadReference(1);
        if (h2 != null) {
            context.purge(h2);
        }
        context.purge(obj);
        TokenConverter.clearConstants();
    }
    return list;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList)

Example 15 with Equipment

use of pcgen.core.Equipment 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);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) BonusObj(pcgen.core.bonus.BonusObj) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) Equipment(pcgen.core.Equipment) LoadContext(pcgen.rules.context.LoadContext) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory)

Aggregations

Equipment (pcgen.core.Equipment)166 PlayerCharacter (pcgen.core.PlayerCharacter)41 ArrayList (java.util.ArrayList)28 StringTokenizer (java.util.StringTokenizer)25 EquipSet (pcgen.core.character.EquipSet)22 CDOMObject (pcgen.cdom.base.CDOMObject)20 LoadContext (pcgen.rules.context.LoadContext)15 SizeAdjustment (pcgen.core.SizeAdjustment)11 EquipmentHead (pcgen.cdom.inst.EquipmentHead)10 WeaponProf (pcgen.core.WeaponProf)10 CharID (pcgen.cdom.enumeration.CharID)9 WieldCategory (pcgen.core.character.WieldCategory)9 CDOMReference (pcgen.cdom.base.CDOMReference)8 ArmorProf (pcgen.core.ArmorProf)8 EquipmentModifier (pcgen.core.EquipmentModifier)8 Race (pcgen.core.Race)8 ShieldProf (pcgen.core.ShieldProf)8 BonusObj (pcgen.core.bonus.BonusObj)8 Test (org.junit.Test)7 ScopeInstance (pcgen.base.formula.base.ScopeInstance)7