Search in sources :

Example 11 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead 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 EquipmentHead

use of pcgen.cdom.inst.EquipmentHead 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 EquipmentHead

use of pcgen.cdom.inst.EquipmentHead 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 14 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.

the class CharacterFacadeImpl method openCustomizer.

private Equipment openCustomizer(Equipment aEq) {
    if (aEq == null) {
        return null;
    }
    Equipment newEquip = aEq.clone();
    if (!newEquip.containsKey(ObjectKey.BASE_ITEM)) {
        newEquip.put(ObjectKey.BASE_ITEM, CDOMDirectSingleRef.getRef(aEq));
    }
    List<VarModifier<?>> modifiers = newEquip.getListFor(ListKey.MODIFY);
    if (modifiers != null) {
        for (VarModifier<?> vm : modifiers) {
            theCharacter.addModifier(vm, newEquip, newEquip);
        }
    }
    for (EquipmentHead head : newEquip.getEquipmentHeads()) {
        modifiers = head.getListFor(ListKey.MODIFY);
        if (modifiers != null) {
            for (VarModifier<?> vm : modifiers) {
                theCharacter.addModifier(vm, head, head);
            }
        }
    }
    EquipmentBuilderFacadeImpl builder = new EquipmentBuilderFacadeImpl(newEquip, theCharacter, delegate);
    CustomEquipResult result = delegate.showCustomEquipDialog(this, builder);
    if (newEquip != null && result != CustomEquipResult.CANCELLED) {
        dataSet.addEquipment(newEquip);
    }
    //TODO if this is returning null, then the SolverManager needs to destroy the unused channels :/
    return result == CustomEquipResult.PURCHASE ? newEquip : null;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) VarModifier(pcgen.cdom.content.VarModifier) CustomEquipResult(pcgen.facade.core.UIDelegate.CustomEquipResult)

Example 15 with EquipmentHead

use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.

the class WeaponToken method getCritToken.

/**
	 * Get critical token
	 * @param pc
	 * @param eq
	 * @return critical token
	 */
public static String getCritToken(PlayerCharacter pc, Equipment eq) {
    StringBuilder sb = new StringBuilder();
    String critRangeVar = ControlUtilities.getControlToken(Globals.getContext(), CControl.CRITRANGE);
    if (critRangeVar != null) {
        EquipmentHead head = eq.getEquipmentHead(1);
        return getCritRangeHead(pc, head, critRangeVar).toString();
    }
    boolean isDouble = (eq.isDouble() && (eq.getLocation() == EquipmentLocation.EQUIPPED_TWO_HANDS));
    int rawCritRange = eq.getRawCritRange(true);
    // see if the weapon has any crit range
    if (rawCritRange == 0) {
        // no crit range!
        return "none";
    }
    String profName = getProfName(eq);
    int dbl = (int) pc.getTotalBonusTo("WEAPONPROF=" + profName, "CRITRANGEDOUBLE") + getWeaponProfTypeBonuses(pc, eq, "CRITRANGEDOUBLE", WPTYPEBONUS_PC);
    int iAdd = (int) pc.getTotalBonusTo("WEAPONPROF=" + profName, "CRITRANGEADD") + getWeaponProfTypeBonuses(pc, eq, "CRITRANGEADD", WPTYPEBONUS_PC);
    int eqDbl = dbl + (int) eq.bonusTo(pc, "EQMWEAPON", "CRITRANGEDOUBLE", true);
    int critrange = eq.getRawCritRange(true) * (eqDbl + 1);
    critrange = 21 - (critrange + iAdd + (int) eq.bonusTo(pc, "EQMWEAPON", "CRITRANGEADD", true));
    sb.append(critrange + "");
    if (critrange < 20) {
        sb.append("-20");
    }
    if (isDouble && (EqToken.getOldBonusedCritRange(pc, eq, false) > 0)) {
        eqDbl = dbl + (int) eq.bonusTo(pc, "EQMWEAPON", "CRITRANGEDOUBLE", false);
        int altCritRange = eq.getRawCritRange(false) * (eqDbl + 1);
        altCritRange = 21 - (altCritRange + iAdd + (int) eq.bonusTo(pc, "EQMWEAPON", "CRITRANGEADD", false));
        if (altCritRange != critrange) {
            sb.append("/" + altCritRange);
            if (altCritRange < 20) {
                sb.append("-20");
            }
        }
    }
    return sb.toString();
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead)

Aggregations

EquipmentHead (pcgen.cdom.inst.EquipmentHead)43 Equipment (pcgen.core.Equipment)10 BigDecimal (java.math.BigDecimal)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 CDOMObject (pcgen.cdom.base.CDOMObject)5 EqModRef (pcgen.cdom.helper.EqModRef)5 StringTokenizer (java.util.StringTokenizer)4 ScopeInstance (pcgen.base.formula.base.ScopeInstance)4 CharID (pcgen.cdom.enumeration.CharID)4 Type (pcgen.cdom.enumeration.Type)4 ArrayList (java.util.ArrayList)3 VarScoped (pcgen.base.formula.base.VarScoped)3 VarModifier (pcgen.cdom.content.VarModifier)3 EquipmentModifier (pcgen.core.EquipmentModifier)3 TreeSet (java.util.TreeSet)2 Formula (pcgen.base.formula.Formula)2 RemoteModifier (pcgen.cdom.content.RemoteModifier)2 WeaponProf (pcgen.core.WeaponProf)2 BonusObj (pcgen.core.bonus.BonusObj)2 AbstractObjectContext (pcgen.rules.context.AbstractObjectContext)2