Search in sources :

Example 76 with BonusObj

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

the class Equipment method adjustACForSize.

/**
	 * Gets the acModAdjustedForSize attribute of the Equipment object
	 * 
	 * @param aPC    The PC with the Equipment
	 * @param baseEq The unmodified Equipment
	 * @param newSA  The size to adjust for
	 */
private void adjustACForSize(final PlayerCharacter aPC, final Equipment baseEq, final SizeAdjustment newSA) {
    if ((getRawBonusList(aPC) != null) && isArmor()) {
        double mult = 1.0;
        final SizeAdjustment currSA = baseEq.getSafe(ObjectKey.SIZE).get();
        if ((newSA != null) && aPC != null) {
            mult = aPC.getSizeBonusTo(newSA, "ACVALUE", baseEq.typeList(), 1.0) / aPC.getSizeBonusTo(currSA, "ACVALUE", baseEq.typeList(), 1.0);
        }
        final List<BonusObj> baseEqBonusList = baseEq.getRawBonusList(aPC);
        final List<BonusObj> eqBonusList = getRawBonusList(aPC);
        //
        for (int i = eqBonusList.size() - 1; i >= 0; --i) {
            final BonusObj aBonus = eqBonusList.get(i);
            String aString = aBonus.toString();
            if (aString.startsWith("COMBAT|AC|")) {
                final int iOffs = aString.indexOf('|', 10);
                if (iOffs > 10) {
                    /*
						 * TODO This is bad behavior to alter this list, 
						 * which - theoretically - shouldn't be altered 
						 * after data load.  However, given .REPLACE
						 * potential in BONUS objects, I can't find
						 * another quick solution to this problem
						 * - thpr 10/9/08
						 */
                    removeFromListFor(ListKey.BONUS, aBonus);
                }
            }
        }
        for (final BonusObj aBonus : baseEqBonusList) {
            String aString = aBonus.toString();
            if (aString.startsWith("COMBAT|AC|")) {
                final int iOffs = aString.indexOf('|', 10);
                if (iOffs > 10) {
                    Integer acCombatBonus = Integer.valueOf(aString.substring(10, iOffs));
                    double d = acCombatBonus.doubleValue() * mult;
                    acCombatBonus = (int) d;
                    aString = aString.substring(0, 10) + acCombatBonus.toString() + aString.substring(iOffs);
                    /*
						 * TODO This is bad behavior to alter this list, 
						 * which - theoretically - shouldn't be altered 
						 * after data load.  However, given .REPLACE
						 * potential in BONUS objects, I can't find
						 * another quick solution to this problem
						 * - thpr 10/9/08
						 */
                    BonusObj b = Bonus.newBonus(Globals.getContext(), aString);
                    if (b != null) {
                        addToListFor(ListKey.BONUS, b);
                    }
                }
            }
        }
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

Example 77 with BonusObj

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

the class StartfeatsToken method parseToken.

@Override
public ParseResult parseToken(LoadContext context, Race race, String value) {
    int bonusValue;
    try {
        bonusValue = Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
        return new ParseResult.Fail("Error encountered in " + getTokenName() + " was expecting value to be an integer, found: " + value, context);
    }
    BonusObj bon = Bonus.newBonus(context, "FEAT|POOL|" + bonusValue);
    if (bon == null) {
        return new ParseResult.Fail("Internal Error: " + getTokenName() + " had invalid bonus", context);
    }
    Prerequisite prereq = getPrerequisite("PREMULT:1,[PREHD:MIN=1],[PRELEVEL:MIN=1]");
    if (prereq == null) {
        return new ParseResult.Fail("Internal Error: " + getTokenName() + " had invalid prerequisite", context);
    }
    bon.addPrerequisite(prereq);
    bon.setTokenSource(getTokenName());
    context.getObjectContext().addToList(race, ListKey.BONUS, bon);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) BonusObj(pcgen.core.bonus.BonusObj) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 78 with BonusObj

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

the class BonusToken method unparse.

@Override
public String[] unparse(LoadContext context, PointBuyMethod pbm) {
    Collection<BonusObj> added = pbm.getBonuses();
    String tokenName = getTokenName();
    Set<String> bonusSet = new TreeSet<>();
    for (BonusObj bonus : added) {
        if (tokenName.equals(bonus.getTokenSource())) {
            bonusSet.add(bonus.toString());
        }
    }
    if (bonusSet.isEmpty()) {
        // This is okay - just no BONUSes from this token
        return null;
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) TreeSet(java.util.TreeSet)

Example 79 with BonusObj

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

the class PCClassTest method testBypassClassPrereqs.

/**
	 * Test the interaction of prerequisites on PCClasses and bonuses and the
	 * Bypass Class Prereqs flag.
	 * @throws Exception
	 */
public void testBypassClassPrereqs() throws Exception {
    LoadContext context = Globals.getContext();
    // Setup class with prereqs and var based abilities with prereqs.
    final PreVariableParser parser = new PreVariableParser();
    final Prerequisite aPrereq = parser.parse("VARGTEQ", "Foo,1", false, false);
    final GameMode gameMode = SettingsHandler.getGame();
    RuleCheck aClassPreRule = gameMode.getModeContext().getReferenceContext().silentlyGetConstructedCDOMObject(RuleCheck.class, "CLASSPRE");
    if (aClassPreRule == null) {
        aClassPreRule = new RuleCheck();
        aClassPreRule.setName("CLASSPRE");
        gameMode.getModeContext().getReferenceContext().importObject(aClassPreRule);
    }
    aClassPreRule.setDefault(false);
    final PCClass aPrClass = new PCClass();
    aPrClass.setName("PreReqClass");
    aPrClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
    final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
    if (aBonus != null) {
        aPrClass.addToListFor(ListKey.BONUS, aBonus);
    }
    aPrClass.addPrerequisite(aPrereq);
    final PCClass aQClass = new PCClass();
    aQClass.setName("QualClass");
    aQClass.put(StringKey.KEY_NAME, "KEY_QualClass");
    CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(aPrClass);
    aQClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
    //aQClass.setQualifyString("KEY_PreReqClass|PreReqVar");
    final PCClass aNqClass = new PCClass();
    aNqClass.setName("NonQualClass");
    aNqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
    aNqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
    aNqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
    // Setup character without prereqs
    final PlayerCharacter character = getCharacter();
    // Test no prereqs and no bypass fails class and var
    assertFalse("PC with no prereqs should fail class qual test.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with no prereqs should fail var qual test.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test no prereqs and bypass passes class and fails var
    aClassPreRule.setDefault(true);
    assertTrue("PC with no prereqs should pass class qual test when bypassing prereqs is on.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with no prereqs should fail var qual test when bypass prereqs is on.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test prereqs and bypass pass class and var
    character.incrementClassLevel(1, aNqClass);
    assertTrue("PC with prereqs and bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
    character.incrementClassLevel(1, aNqClass);
    assertEquals("PC with prereqs and bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test prereqs and no bypass passes class and var
    aClassPreRule.setDefault(false);
    assertTrue("PC with prereqs and no bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with prereqs and no bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) PreVariableParser(plugin.pretokens.parser.PreVariableParser) LoadContext(pcgen.rules.context.LoadContext) Qualifier(pcgen.cdom.reference.Qualifier) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 80 with BonusObj

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

the class PCClassTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    Campaign customCampaign = new Campaign();
    customCampaign.setName("Unit Test");
    customCampaign.setName("KEY_Unit Test");
    customCampaign.addToListFor(ListKey.DESCRIPTION, new Description("Unit Test data"));
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(customCampaign, new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    // Create the monseter class type
    GameMode gamemode = SettingsHandler.getGame();
    gamemode.addClassType("Monster		CRFORMULA:0			ISMONSTER:YES	XPPENALTY:NO");
    gamemode.setSkillMultiplierLevels("4");
    // Create the humanoid class
    String classDef = "CLASS:Humanoid	KEY:KEY_Humanoid	HD:8		CLASSTYPE:Monster	STARTSKILLPTS:1	" + "MODTOSKILLS:NO	MONSKILL:6+INT	MONNONSKILLHD:1|PRESIZELTEQ:M	" + "MONNONSKILLHD:2|PRESIZEEQ:L";
    PCClassLoader classLoader = new PCClassLoader();
    LoadContext context = Globals.getContext();
    humanoidClass = classLoader.parseLine(context, null, classDef, source);
    Globals.getContext().getReferenceContext().importObject(humanoidClass);
    classDef = "CLASS:Nymph		KEY:KEY_Nymph	CLASSTYPE:Monster	HD:6	STARTSKILLPTS:6	MODTOSKILLS:YES	";
    classLoader = new PCClassLoader();
    nymphClass = classLoader.parseLine(context, null, classDef, source);
    Globals.getContext().getReferenceContext().importObject(nymphClass);
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
    // Create the large size mod
    // Create the BugBear race
    bugbearRace = new Race();
    bugbearRace.setName("Bugbear");
    bugbearRace.put(StringKey.KEY_NAME, "KEY_Bugbear");
    bugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    bugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
    bugbearRace.put(IntegerKey.INITIAL_SKILL_MULT, 1);
    Globals.getContext().getReferenceContext().importObject(bugbearRace);
    bigBugbearRace = new Race();
    bigBugbearRace.setName("BigBugbear");
    bigBugbearRace.put(StringKey.KEY_NAME, "KEY_BigBugbear");
    bigBugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(largeRef));
    bigBugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
    bigBugbearRace.put(IntegerKey.INITIAL_SKILL_MULT, 1);
    Globals.getContext().getReferenceContext().importObject(bigBugbearRace);
    // Create the Nymph race
    nymphRace = new Race();
    nymphRace.setName("Nymph");
    nymphRace.put(StringKey.KEY_NAME, "KEY_Nymph");
    nymphRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    nymphRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
    nymphRace.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(nymphClass), FormulaFactory.getFormulaFor(0)));
    Globals.getContext().getReferenceContext().importObject(nymphRace);
    // Setup class with prereqs and var based abilities with prereqs.
    PreVariableParser parser = new PreVariableParser();
    prereq = parser.parse("VARGTEQ", "Foo,1", false, false);
    classPreRule = new RuleCheck();
    classPreRule.setName("CLASSPRE");
    classPreRule.setDefault(false);
    gamemode.getModeContext().getReferenceContext().importObject(classPreRule);
    prClass = new PCClass();
    prClass.setName("PreReqClass");
    prClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
    final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
    if (aBonus != null) {
        prClass.addToListFor(ListKey.BONUS, aBonus);
    }
    prClass.addPrerequisite(prereq);
    qClass = new PCClass();
    qClass.setName("QualClass");
    qClass.put(StringKey.KEY_NAME, "KEY_QualClass");
    CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(prClass);
    qClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
    nqClass = new PCClass();
    nqClass.setName("NonQualClass");
    nqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
    nqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
    nqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) BonusObj(pcgen.core.bonus.BonusObj) PreVariableParser(plugin.pretokens.parser.PreVariableParser) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) Qualifier(pcgen.cdom.reference.Qualifier)

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