Search in sources :

Example 51 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class PreCheckBaseTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    PCCheck obj = new PCCheck();
    obj.setName("Fortitude");
    Globals.getContext().getReferenceContext().importObject(obj);
    obj = new PCCheck();
    obj.setName("Reflex");
    Globals.getContext().getReferenceContext().importObject(obj);
    obj = new PCCheck();
    obj.setName("Will");
    Globals.getContext().getReferenceContext().importObject(obj);
    myClass.setName("My Class");
    myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
    final BonusObj fortRefBonus = Bonus.newBonus(context, "SAVE|BASE.Fortitude,BASE.Reflex|CL/3");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortRefBonus);
    final BonusObj willBonus = Bonus.newBonus(context, "SAVE|BASE.Will|CL/2+2");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, willBonus);
    Globals.getContext().getReferenceContext().importObject(myClass);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) PCCheck(pcgen.core.PCCheck)

Example 52 with BonusObj

use of pcgen.core.bonus.BonusObj 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 53 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class AnyPCToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, ListKey.BONUS_ANYPC);
    Collection<BonusObj> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token (and no global clear, so nothing to do)
        return null;
    }
    Set<String> bonusSet = new TreeSet<>();
    for (BonusObj bonus : added) {
        bonusSet.add(bonus.getLSTformat());
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) TreeSet(java.util.TreeSet)

Example 54 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class EQToken method parseTokenWithSeparator.

@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail("Expected " + getFullTokenName() + ":<type>|<conditions>|BONUS but did not find a second pipe");
    }
    String constraints = value.substring(0, pipeLoc);
    String bonus = value.substring(pipeLoc + 1);
    final String v = bonus.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
    BonusObj bon = Bonus.newBonus(context, v);
    if (bon == null) {
        return new ParseResult.Fail(getFullTokenName() + " was given invalid type: " + bonus, context);
    }
    bon.setTokenSource(getFullTokenName());
    EquipBonus eb = new EquipBonus(bon, constraints);
    context.getObjectContext().addToList(obj, ListKey.BONUS_EQUIP, eb);
    return ParseResult.SUCCESS;
}
Also used : EquipBonus(pcgen.core.bonus.EquipBonus) BonusObj(pcgen.core.bonus.BonusObj)

Example 55 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class BonusManagerTest method testStackingPositiveFirst.

/**
	 * Validate that the setActiveBonusStack method will correctly calculate the value of 
	 * a positive bonus followed by a negative bonus to a non-stackable value.
	 */
@Test
public void testStackingPositiveFirst() {
    PCTemplate testObj = TestHelper.makeTemplate("PostiveFirst");
    LoadContext context = Globals.getContext();
    final BonusObj posBonus = Bonus.newBonus(context, "COMBAT|AC|5|TYPE=Armor");
    testObj.addToListFor(ListKey.BONUS, posBonus);
    final BonusObj negBonus = Bonus.newBonus(context, "COMBAT|AC|-2|TYPE=Armor");
    testObj.addToListFor(ListKey.BONUS, negBonus);
    PlayerCharacter pc = getCharacter();
    pc.addTemplate(testObj);
    // Run the check a few times to ensure no randomness issues 
    for (int i = 0; i < 10; i++) {
        pc.calcActiveBonuses();
        assertEquals("Incorrect bonus total", 3.0, pc.getTotalBonusTo("COMBAT", "AC"), 0.0001);
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) Test(org.junit.Test)

Aggregations

BonusObj (pcgen.core.bonus.BonusObj)126 LoadContext (pcgen.rules.context.LoadContext)48 PlayerCharacter (pcgen.core.PlayerCharacter)29 ArrayList (java.util.ArrayList)22 CDOMObject (pcgen.cdom.base.CDOMObject)18 PCClass (pcgen.core.PCClass)14 Prerequisite (pcgen.core.prereq.Prerequisite)13 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)13 EquipSet (pcgen.core.character.EquipSet)11 IdentityHashMap (java.util.IdentityHashMap)10 Map (java.util.Map)10 TreeSet (java.util.TreeSet)10 Ability (pcgen.core.Ability)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 TempBonusInfo (pcgen.core.BonusManager.TempBonusInfo)8 Equipment (pcgen.core.Equipment)8 HashMap (java.util.HashMap)7 Race (pcgen.core.Race)7 StringTokenizer (java.util.StringTokenizer)6 CNAbility (pcgen.cdom.content.CNAbility)6