Search in sources :

Example 81 with Equipment

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

the class BonusTest method testVarBonus.

/**
	 * Test the processing of bonusing variables using both 
	 * abilities and equipment.
	 */
public void testVarBonus() {
    LoadContext context = Globals.getContext();
    Ability dummyFeat = new Ability();
    dummyFeat.setName("DummyFeat");
    dummyFeat.setCDOMCategory(AbilityCategory.FEAT);
    final PlayerCharacter pc = getCharacter();
    // Create a variable
    dummyFeat.put(VariableKey.getConstant("NegLevels"), FormulaFactory.ZERO);
    // Create a bonus to it
    Ability dummyFeat2 = new Ability();
    dummyFeat2.setName("DummyFeat2");
    dummyFeat2.setCDOMCategory(AbilityCategory.FEAT);
    BonusObj aBonus = Bonus.newBonus(context, "VAR|NegLevels|7");
    if (aBonus != null) {
        dummyFeat2.addToListFor(ListKey.BONUS, aBonus);
    }
    Equipment equip = new Equipment();
    equip.setName("DummyEquip");
    aBonus = Bonus.newBonus(context, "VAR|NegLevels|2");
    if (aBonus != null) {
        equip.addToListFor(ListKey.BONUS, aBonus);
    }
    assertEquals("Variable value", 0.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    addAbility(AbilityCategory.FEAT, dummyFeat);
    assertEquals("Variable value", 0.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    assertEquals("Variable value", -0.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
    // Add a bonus to it
    addAbility(AbilityCategory.FEAT, dummyFeat2);
    assertEquals("Variable value", 7.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    assertEquals("Variable value", -7.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
    // Add the equipment that gives a bonus to NegLevels
    EquipSet def = new EquipSet("0.1", "Default");
    pc.addEquipSet(def);
    final EquipSet eqSet = new EquipSet("0.1.1", "Equipped", "Test", equip);
    pc.addEquipSet(eqSet);
    pc.setCalcEquipmentList();
    pc.calcActiveBonuses();
    BonusActivation.activateBonuses(dummyFeat, pc);
    assertEquals("Variable value", 9.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    assertEquals("Variable value", -9.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet) LoadContext(pcgen.rules.context.LoadContext)

Example 82 with Equipment

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

the class PreArmorTypeTest method testList.

/**
	 * Test LIST
	 * @throws Exception
	 */
public void testList() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Ability mediumProf = TestHelper.makeAbility("Armor Proficiency (Medium)", AbilityCategory.FEAT, "General");
    Globals.getContext().unconditionallyProcess(mediumProf, "AUTO", "ARMORPROF|ARMORTYPE.Medium");
    AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, mediumProf, null);
    final Equipment chainmail = new Equipment();
    chainmail.addToListFor(ListKey.TYPE, Type.getConstant("ARMOR"));
    chainmail.addToListFor(ListKey.TYPE, Type.getConstant("MEDIUM"));
    chainmail.setName("Chainmail");
    Globals.getContext().getReferenceContext().importObject(chainmail);
    assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("armortype");
    prereq.setKey("LIST");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertFalse("No armor equipped", PrereqHandler.passes(prereq, character, null));
    character.addEquipment(chainmail);
    chainmail.setIsEquipped(true, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    assertTrue("Proficient armor equipped", PrereqHandler.passes(prereq, character, null));
    chainmail.setIsEquipped(false, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    final Equipment fullPlate = new Equipment();
    fullPlate.addToListFor(ListKey.TYPE, Type.getConstant("ARMOR"));
    fullPlate.addToListFor(ListKey.TYPE, Type.getConstant("HEAVY"));
    fullPlate.setName("Full Plate");
    Globals.getContext().getReferenceContext().importObject(fullPlate);
    /*
		 * TODO This doesn't make a lot of sense - false? Shouldn't this be true
		 * to be a useful test?
		 */
    fullPlate.setIsEquipped(false, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    assertFalse("Not Proficient in armor equipped", PrereqHandler.passes(prereq, character, null));
}
Also used : Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment)

Example 83 with Equipment

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

the class ArmorToken method _replaceTokenArmorVarious.

/**
	 * select various stuff, that improves AC
	 * @param index
	 * @param type
	 * @param subtype
	 * @param property
	 * @param equipped
	 * @param merge
	 * @param aPC
	 * @param eh The ExportHandler to advise if there are no more items.
	 * @return int
	 */
private static String _replaceTokenArmorVarious(int index, String type, String subtype, String property, int equipped, int merge, PlayerCharacter aPC, ExportHandler eh) {
    final List<Equipment> aArrayList = new ArrayList<>();
    for (Equipment eq : aPC.getEquipmentOfTypeInOutputOrder(type, subtype, equipped, merge)) {
        if (eq.getACMod(aPC).intValue() > 0) {
            aArrayList.add(eq);
        } else if (eq.altersAC(aPC)) {
            aArrayList.add(eq);
        }
    }
    if (index < aArrayList.size()) {
        final Equipment eq = aArrayList.get(index);
        return _writeArmorProperty(eq, property, aPC);
    }
    eh.setNoMoreItems(true);
    return "";
}
Also used : Equipment(pcgen.core.Equipment) ArrayList(java.util.ArrayList)

Example 84 with Equipment

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

the class EqContainerToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    String retString = "";
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
    //clear EQCONTAINER Token
    aTok.nextToken();
    Equipment eq = null;
    if (aTok.hasMoreElements()) {
        try {
            int containerNo = Integer.parseInt(aTok.nextToken());
            eq = getContainer(pc, containerNo);
        } catch (NumberFormatException e) {
        // TODO - This exception needs to be handled
        }
    }
    if (eq != null) {
        String property = "NAME";
        if (aTok.hasMoreElements()) {
            property = aTok.nextToken();
        }
        if (property.equals("ACCHECK")) {
            retString = Integer.toString(EqToken.getAcCheckTokenInt(pc, eq));
        } else if (property.equals("ACMOD")) {
            retString = Integer.toString(getAcModToken(pc, eq));
        } else if (property.equals("ALTCRIT")) {
            retString = getAltCritToken(eq);
        } else if (property.equals("ALTDAMAGE")) {
            retString = getAltDamageToken(pc, eq);
        } else if (property.equals("ATTACKS")) {
            retString = Double.toString(getAttacksToken(pc, eq));
        } else if (property.equals("CARRIED")) {
            retString = Float.toString(getCarriedToken(eq));
        } else if (property.equals("CONTENTS")) {
            retString = getContentsToken(eq, aTok);
        } else if (property.equals("CONTENTWEIGHT")) {
            retString = BigDecimalHelper.trimZeros(Float.toString(getContentWeightToken(pc, eq)));
        } else if (property.equals("COST")) {
            retString = BigDecimalHelper.trimZeros(getCostToken(pc, eq));
        } else if (property.equals("CRITMULT")) {
            retString = getCritMultToken(eq);
        } else if (property.equals("CRITRANGE")) {
            retString = EqToken.getCritRangeToken(pc, eq);
        } else if (property.equals("DAMAGE")) {
            retString = getDamageToken(pc, eq);
        } else if (property.equals("EDR")) {
            retString = Integer.toString(EqToken.getEdrTokenInt(pc, eq));
        } else if (property.equals("EQUIPPED")) {
            retString = getEquippedToken(eq);
        } else if (property.equals("ITEMWEIGHT")) {
            retString = BigDecimalHelper.trimZeros(Float.toString(getItemWeightToken(pc, eq)));
        } else if (property.equals("LOCATION")) {
            retString = getLocationToken(eq);
        } else if (property.equals("LONGNAME")) {
            retString = getLongNameToken(eq);
        } else if (property.equals("MAXDEX")) {
            retString = Integer.toString(EqToken.getMaxDexTokenInt(pc, eq));
        } else if (property.equals("MOVE")) {
            retString = getMoveToken(eq);
        } else if (property.equals("NAME") || property.equals("OUTPUTNAME")) {
            retString = getNameToken(eq, pc);
        } else if (property.equals("PROF")) {
            retString = eq.consolidatedProfName();
        } else if (property.equals("QTY")) {
            retString = BigDecimalHelper.trimZeros(Double.toString((getQuantityToken(eq))));
        } else if (property.equals("RANGE")) {
            retString = Integer.toString(EqToken.getRange(pc, eq).intValue());
        } else if (property.equals("SIZE")) {
            retString = getSizeToken(eq);
        } else if (property.equals("SPELLFAILURE")) {
            retString = Integer.toString(EqToken.getSpellFailureTokenInt(pc, eq));
        } else if (property.equals("SPROP")) {
            retString = getSPropToken(pc, eq);
        } else if (property.equals("TOTALWEIGHT") || property.equals("WT")) {
            retString = BigDecimalHelper.trimZeros(Float.toString(getTotalWeightToken(pc, eq)));
        } else if (property.equals("TYPE")) {
            retString = getTypeToken(eq, aTok);
        }
    }
    return retString;
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment)

Example 85 with Equipment

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

the class EqContainerwToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    String retString = "";
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
    //clear EQCONTAINERW Token
    aTok.nextToken();
    Equipment eq = null;
    if (aTok.hasMoreElements()) {
        try {
            int containerNo = Integer.parseInt(aTok.nextToken());
            eq = getContainer(pc, containerNo);
        } catch (NumberFormatException e) {
        // TODO - This exception needs to be handled
        }
    }
    if (eq != null) {
        String property = "NAME";
        if (aTok.hasMoreElements()) {
            property = aTok.nextToken();
        }
        if (property.equals("ACCHECK")) {
            retString = Integer.toString(EqToken.getAcCheckTokenInt(pc, eq));
        } else if (property.equals("ACMOD")) {
            retString = Integer.toString(getAcModToken(pc, eq));
        } else if (property.equals("ALTCRIT")) {
            retString = getAltCritToken(eq);
        } else if (property.equals("ALTDAMAGE")) {
            retString = getAltDamageToken(pc, eq);
        } else if (property.equals("ATTACKS")) {
            retString = Double.toString(getAttacksToken(pc, eq));
        } else if (property.equals("CARRIED")) {
            retString = Float.toString(getCarriedToken(eq));
        } else if (property.equals("CONTENTS")) {
            retString = getContentsToken(eq, aTok);
        } else if (property.equals("CONTENTWEIGHT")) {
            retString = BigDecimalHelper.trimZeros(Float.toString(getContentWeightToken(pc, eq)));
        } else if (property.equals("COST")) {
            retString = BigDecimalHelper.trimZeros(getCostToken(pc, eq));
        } else if (property.equals("CRITMULT")) {
            retString = getCritMultToken(eq);
        } else if (property.equals("CRITRANGE")) {
            retString = EqToken.getCritRangeToken(pc, eq);
        } else if (property.equals("DAMAGE")) {
            retString = getDamageToken(pc, eq);
        } else if (property.equals("EDR")) {
            retString = Integer.toString(EqToken.getEdrTokenInt(pc, eq));
        } else if (property.equals("EQUIPPED")) {
            retString = getEquippedToken(eq);
        } else if (property.equals("ITEMWEIGHT")) {
            retString = BigDecimalHelper.trimZeros(Float.toString(getItemWeightToken(pc, eq)));
        } else if (property.equals("LOCATION")) {
            retString = getLocationToken(eq);
        } else if (property.equals("LONGNAME")) {
            retString = getLongNameToken(eq);
        } else if (property.equals("MAXDEX")) {
            retString = Integer.toString(EqToken.getMaxDexTokenInt(pc, eq));
        } else if (property.equals("MOVE")) {
            retString = getMoveToken(eq);
        } else if (property.equals("NAME") || property.equals("OUTPUTNAME")) {
            retString = getNameToken(eq, pc);
        } else if (property.equals("PROF")) {
            retString = eq.consolidatedProfName();
        } else if (property.equals("QTY")) {
            retString = BigDecimalHelper.trimZeros(Double.toString((getQuantityToken(eq))));
        } else if (property.equals("RANGE")) {
            retString = Integer.toString(EqToken.getRange(pc, eq).intValue());
        } else if (property.equals("SIZE")) {
            retString = getSizeToken(eq);
        } else if (property.equals("SPELLFAILURE")) {
            retString = Integer.toString(EqToken.getSpellFailureTokenInt(pc, eq));
        } else if (property.equals("SPROP")) {
            retString = getSPropToken(pc, eq);
        } else if (property.equals("TOTALWEIGHT") || property.equals("WT")) {
            retString = BigDecimalHelper.trimZeros(Float.toString(getTotalWeightToken(pc, eq)));
        } else if (property.equals("TYPE")) {
            retString = getTypeToken(eq, aTok);
        }
    }
    return retString;
}
Also used : StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment)

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