Search in sources :

Example 61 with Equipment

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

the class EquipmentQualifierTokenTest method initializeObjects.

private void initializeObjects() {
    wp1 = new WeaponProf();
    wp1.setName("Eq1");
    primaryContext.getReferenceContext().importObject(wp1);
    eq1 = new Equipment();
    eq1.setName("Eq1");
    primaryContext.getReferenceContext().importObject(eq1);
    primaryContext.unconditionallyProcess(eq1, "TYPE", "WEAPON");
    primaryContext.unconditionallyProcess(eq1, "PROFICIENCY", "WEAPON|Eq1");
    sp1 = new ShieldProf();
    sp1.setName("Eq2");
    primaryContext.getReferenceContext().importObject(sp1);
    eq2 = new Equipment();
    eq2.setName("Eq2");
    primaryContext.getReferenceContext().importObject(eq2);
    primaryContext.unconditionallyProcess(eq2, "TYPE", "SHIELD");
    primaryContext.unconditionallyProcess(eq2, "PROFICIENCY", "SHIELD|Eq2");
    ap1 = new ArmorProf();
    ap1.setName("Eq3");
    primaryContext.getReferenceContext().importObject(ap1);
    eq3 = new Equipment();
    eq3.setName("Eq3");
    primaryContext.getReferenceContext().importObject(eq3);
    primaryContext.unconditionallyProcess(eq3, "TYPE", "ARMOR.Masterful");
    primaryContext.unconditionallyProcess(eq3, "PROFICIENCY", "ARMOR|Eq3");
    sp2 = new ShieldProf();
    sp2.setName("Wp2");
    primaryContext.getReferenceContext().importObject(sp2);
    eq4 = new Equipment();
    eq4.setName("Eq4");
    primaryContext.getReferenceContext().importObject(eq4);
    primaryContext.unconditionallyProcess(eq4, "TYPE", "SHIELD.Masterful");
    primaryContext.unconditionallyProcess(eq4, "PROFICIENCY", "SHIELD|Wp2");
}
Also used : ShieldProf(pcgen.core.ShieldProf) Equipment(pcgen.core.Equipment) WeaponProf(pcgen.core.WeaponProf) ArmorProf(pcgen.core.ArmorProf)

Example 62 with Equipment

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

the class EquipmentQualifierTokenTest method initializeObjects.

private void initializeObjects() {
    wp1 = new WeaponProf();
    wp1.setName("Eq1");
    primaryContext.getReferenceContext().importObject(wp1);
    eq1 = new Equipment();
    eq1.setName("Eq1");
    primaryContext.getReferenceContext().importObject(eq1);
    primaryContext.unconditionallyProcess(eq1, "TYPE", "WEAPON");
    primaryContext.unconditionallyProcess(eq1, "PROFICIENCY", "WEAPON|Eq1");
    sp1 = new ShieldProf();
    sp1.setName("Eq2");
    primaryContext.getReferenceContext().importObject(sp1);
    eq2 = new Equipment();
    eq2.setName("Eq2");
    primaryContext.getReferenceContext().importObject(eq2);
    primaryContext.unconditionallyProcess(eq2, "TYPE", "SHIELD.Masterful");
    primaryContext.unconditionallyProcess(eq2, "PROFICIENCY", "SHIELD|Eq2");
    ap1 = new ArmorProf();
    ap1.setName("Eq3");
    primaryContext.getReferenceContext().importObject(ap1);
    eq3 = new Equipment();
    eq3.setName("Eq3");
    primaryContext.getReferenceContext().importObject(eq3);
    primaryContext.unconditionallyProcess(eq3, "TYPE", "ARMOR");
    primaryContext.unconditionallyProcess(eq3, "PROFICIENCY", "ARMOR|Eq3");
    ap2 = new ArmorProf();
    ap2.setName("Ap2");
    primaryContext.getReferenceContext().importObject(ap2);
    eq4 = new Equipment();
    eq4.setName("Eq4");
    primaryContext.getReferenceContext().importObject(eq4);
    primaryContext.unconditionallyProcess(eq4, "TYPE", "ARMOR.Masterful");
    primaryContext.unconditionallyProcess(eq4, "PROFICIENCY", "ARMOR|Ap2");
}
Also used : ShieldProf(pcgen.core.ShieldProf) Equipment(pcgen.core.Equipment) WeaponProf(pcgen.core.WeaponProf) ArmorProf(pcgen.core.ArmorProf)

Example 63 with Equipment

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

the class EncounterPlugin method canAddEquip.

private static boolean canAddEquip(PlayerCharacter pc, EquipSet eSet, String locName, Equipment eqI) {
    String idPath = eSet.getIdPath();
    // allow as many as they would like
    if (locName.startsWith(Constants.EQUIP_LOCATION_CARRIED) || locName.startsWith(Constants.EQUIP_LOCATION_EQUIPPED) || locName.startsWith(Constants.EQUIP_LOCATION_NOTCARRIED)) {
        return true;
    }
    // allow as many unarmed items as you'd like
    if (eqI.isUnarmed()) {
        return true;
    }
    // allow many Secondary Natural weapons
    if (locName.equals(Constants.EQUIP_LOCATION_NATURAL_SECONDARY)) {
        return true;
    }
    // Don't allow weapons that are too large for PC
    if (eqI.isWeaponTooLargeForPC(pc)) {
        return false;
    }
    // make a HashMap to keep track of the number of each
    // item that is already equipped to a slot
    Map<String, String> slotMap = new HashMap<>();
    for (EquipSet eqSet : pc.getDisplay().getEquipSet()) {
        if (!eqSet.getParentIdPath().startsWith(idPath)) {
            continue;
        }
        // an item in that particular location
        if (eqSet.getName().equals(locName)) {
            Equipment eItem = eqSet.getItem();
            String nString = slotMap.get(locName);
            int existNum = 0;
            if (nString != null) {
                existNum = Integer.parseInt(nString);
            }
            if (eItem != null) {
                existNum += eItem.getSlots(pc);
            }
            slotMap.put(locName, String.valueOf(existNum));
        }
    }
    for (EquipSet eqSet : pc.getDisplay().getEquipSet()) {
        if (!eqSet.getParentIdPath().startsWith(idPath)) {
            continue;
        }
        // checks for hands already in use
        if (eqI.isWeapon()) {
            // weapons can never occupy the same slot
            if (eqSet.getName().equals(locName)) {
                return false;
            }
            // other weapon slots can be occupied
            if ((locName.equals(Constants.EQUIP_LOCATION_BOTH) || locName.equals(Constants.EQUIP_LOCATION_DOUBLE) || locName.equals(Constants.EQUIP_LOCATION_TWOWEAPONS)) && (eqSet.getName().equals(Constants.EQUIP_LOCATION_PRIMARY) || eqSet.getName().equals(Constants.EQUIP_LOCATION_SECONDARY) || eqSet.getName().equals(Constants.EQUIP_LOCATION_BOTH) || eqSet.getName().equals(Constants.EQUIP_LOCATION_DOUBLE) || eqSet.getName().equals(Constants.EQUIP_LOCATION_TWOWEAPONS))) {
                return false;
            }
            // inverse of above case
            if ((locName.equals(Constants.EQUIP_LOCATION_PRIMARY) || locName.equals(Constants.EQUIP_LOCATION_SECONDARY)) && (eqSet.getName().equals(Constants.EQUIP_LOCATION_BOTH) || eqSet.getName().equals(Constants.EQUIP_LOCATION_DOUBLE) || eqSet.getName().equals(Constants.EQUIP_LOCATION_TWOWEAPONS))) {
                return false;
            }
        }
        // check to see how many are allowed in that slot
        if (eqSet.getName().equals(locName)) {
            final String nString = slotMap.get(locName);
            int existNum = 0;
            if (nString != null) {
                existNum = Integer.parseInt(nString);
            }
            existNum += eqI.getSlots(pc);
            EquipSlot eSlot = Globals.getEquipSlotByName(locName);
            if (eSlot == null) {
                return true;
            }
            for (String slotType : eSlot.getContainType()) {
                if (eqI.isType(slotType)) {
                    // if the item takes more slots, return false
                    if (existNum > (eSlot.getSlotCount() + (int) pc.getTotalBonusTo("SLOTS", slotType))) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
    return true;
}
Also used : EquipSlot(pcgen.core.character.EquipSlot) Equipment(pcgen.core.Equipment) HashMap(java.util.HashMap) EquipSet(pcgen.core.character.EquipSet)

Example 64 with Equipment

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

the class NaturalattacksLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<Equipment> changes = context.getObjectContext().getListChanges(obj, ListKey.NATURAL_WEAPON);
    Collection<Equipment> eqadded = changes.getAdded();
    if (eqadded == null || eqadded.isEmpty()) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Equipment lstw : eqadded) {
        if (!first) {
            sb.append(Constants.PIPE);
        }
        Equipment eq = Equipment.class.cast(lstw);
        String name = eq.getDisplayName();
        // TODO objcontext.getString(eq, StringKey.NAME);
        if (name == null) {
            context.addWriteMessage(getTokenName() + " expected Equipment to have a name");
            return null;
        }
        sb.append(name).append(Constants.COMMA);
        List<Type> type = eq.getListFor(ListKey.TYPE);
        if (type == null || type.isEmpty()) {
            context.addWriteMessage(getTokenName() + " expected Equipment to have a type");
            return null;
        }
        sb.append(StringUtil.join(type, Constants.DOT));
        sb.append(Constants.COMMA);
        Boolean attProgress = eq.get(ObjectKey.ATTACKS_PROGRESS);
        if (attProgress == null) {
            context.addWriteMessage(getTokenName() + " expected Equipment to know ATTACKS_PROGRESS state");
            return null;
        } else if (!attProgress.booleanValue()) {
            sb.append(Constants.CHAR_ASTERISK);
        }
        List<BonusObj> bonuses = eq.getListFor(ListKey.BONUS);
        if (bonuses == null || bonuses.isEmpty()) {
            sb.append('1');
        } else {
            if (bonuses.size() != 1) {
                context.addWriteMessage(getTokenName() + " expected only one BONUS on Equipment: " + bonuses);
                return null;
            }
            // TODO Validate BONUS type?
            BonusObj extraAttacks = bonuses.iterator().next();
            sb.append(Integer.parseInt(extraAttacks.getValue()) + 1);
        }
        sb.append(Constants.COMMA);
        EquipmentHead head = eq.getEquipmentHeadReference(1);
        if (head == null) {
            context.addWriteMessage(getTokenName() + " expected an EquipmentHead on Equipment");
            return null;
        }
        String damage = head.get(StringKey.DAMAGE);
        if (damage == null) {
            context.addWriteMessage(getTokenName() + " expected a Damage on EquipmentHead");
            return null;
        }
        sb.append(damage);
        Integer hands = eq.get(IntegerKey.SLOTS);
        if (hands != null && hands != 0) {
            sb.append(',').append(hands);
        }
        List<SpecialProperty> spropList = eq.getSafeListFor(ListKey.SPECIAL_PROPERTIES);
        for (SpecialProperty sprop : spropList) {
            sb.append(",SPROP=").append(sprop.toString());
        }
        first = false;
    }
    return new String[] { sb.toString() };
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Type(pcgen.cdom.enumeration.Type) Equipment(pcgen.core.Equipment) SpecialProperty(pcgen.core.SpecialProperty)

Example 65 with Equipment

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

the class NaturalattacksLst method process.

@Override
public boolean process(LoadContext context, CDOMObject obj) {
    List<Equipment> natWeapons = obj.getListFor(ListKey.NATURAL_WEAPON);
    if (natWeapons != null) {
        Formula sizeFormula = obj.getSafe(FormulaKey.SIZE);
        // If the size was just a default, check for a size prereq and use that instead.
        if (obj.get(FormulaKey.SIZE) == null && obj.hasPreReqTypeOf("SIZE")) {
            Integer requiredSize = getRequiredSize(obj);
            if (requiredSize != null) {
                sizeFormula = FormulaFactory.getFormulaFor(requiredSize);
            }
        }
        if (sizeFormula.isStatic()) {
            int isize = sizeFormula.resolveStatic().intValue();
            SizeAdjustment size = context.getReferenceContext().getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(isize);
            for (Equipment e : natWeapons) {
                CDOMDirectSingleRef<SizeAdjustment> sizeRef = CDOMDirectSingleRef.getRef(size);
                e.put(ObjectKey.BASESIZE, sizeRef);
                e.put(ObjectKey.SIZE, sizeRef);
            }
        } else {
            Logging.errorPrint("SIZE in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName() + " must not be a variable " + "if it contains a NATURALATTACKS token");
        }
    }
    return true;
}
Also used : Formula(pcgen.base.formula.Formula) Equipment(pcgen.core.Equipment) SizeAdjustment(pcgen.core.SizeAdjustment)

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