Search in sources :

Example 11 with CharacterDisplay

use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.

the class HitDiceToken method getHitDiceToken.

/**
	 * Get the medium version of the HITDICE token
	 * @param pc
	 * @return the medium version of the HITDICE token
	 */
public static String getHitDiceToken(PlayerCharacter pc) {
    StringBuilder ret = new StringBuilder();
    String del = "";
    CharacterDisplay display = pc.getDisplay();
    for (PCClass pcClass : display.getClassSet()) {
        HashMap<Integer, Integer> hdMap = new LinkedHashMap<>();
        for (int i = 0; i < display.getLevel(pcClass); i++) {
            int hitDie = display.getLevelHitDie(pcClass, i + 1).getDie();
            if (hitDie != 0) {
                Integer num = hdMap.get(hitDie);
                if (num == null) {
                    hdMap.put(hitDie, 1);
                } else {
                    hdMap.put(hitDie, num.intValue() + 1);
                }
            }
        }
        Set<Integer> keys = hdMap.keySet();
        for (int key : keys) {
            Integer value = hdMap.get(key);
            ret.append(del);
            ret.append('(');
            ret.append(value).append('d').append(key);
            ret.append(')');
            del = "+";
        }
    }
    // Get CON bonus contribution to hitpoint total
    int temp = (int) display.getStatBonusTo("HP", "BONUS") * display.getTotalLevels();
    // Add in feat bonus
    temp += (int) pc.getTotalBonusTo("HP", "CURRENTMAX");
    if (temp != 0) {
        ret.append(Delta.toString(temp));
    }
    return ret.toString();
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) PCClass(pcgen.core.PCClass) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with CharacterDisplay

use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.

the class SpaceTokenTest method testSpaceToken.

/**
	 * Test the SPACE token.
	 */
public void testSpaceToken() {
    SpaceToken token = new SpaceToken();
    assertEquals(" ", token.getToken("SPACE", (CharacterDisplay) null, null));
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) SpaceToken(plugin.exporttokens.deprecated.SpaceToken)

Example 13 with CharacterDisplay

use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.

the class PlayerCharacterTest method testAdjustMoveRates.

/**
	 * Test the processing and order of operations of the adjustMoveRates method.
	 */
public void testAdjustMoveRates() {
    Ability quickFlySlowSwim = TestHelper.makeAbility("quickFlySlowSwim", AbilityCategory.FEAT.getKeyName(), "Foo");
    PCTemplate template = TestHelper.makeTemplate("slowFlyQuickSwim");
    PCTemplate template2 = TestHelper.makeTemplate("dig");
    LoadContext context = Globals.getContext();
    final BonusObj digBonus = Bonus.newBonus(context, "MOVEADD|TYPE.Dig|60");
    assertNotNull("Failed to create bonus", digBonus);
    template2.addToListFor(ListKey.BONUS, digBonus);
    //template.addm
    context.getReferenceContext().importObject(quickFlySlowSwim);
    context.getReferenceContext().importObject(template2);
    context.unconditionallyProcess(human, "MOVE", "Walk,30");
    context.unconditionallyProcess(quickFlySlowSwim, "MOVE", "Swim,10,Fly,30");
    context.unconditionallyProcess(template, "MOVE", "Swim,30,Fly,10");
    readyToRun();
    GameMode game = SettingsHandler.getGame();
    LoadInfo li = game.getModeContext().getReferenceContext().constructNowIfNecessary(LoadInfo.class, game.getName());
    li.addLoadScoreValue(0, new BigDecimal("100.0"));
    li.addLoadScoreValue(10, new BigDecimal("100.0"));
    li.addLoadMultiplier("LIGHT", new Float(100), "100", 0);
    PlayerCharacter pc = getCharacter();
    setPCStat(pc, str, 10);
    pc.setRace(human);
    pc.calcActiveBonuses();
    pc.adjustMoveRates();
    CharacterDisplay display = pc.getDisplay();
    assertEquals(0.0, display.movementOfType("Swim"), 0.1);
    assertEquals(0.0, display.movementOfType("Fly"), 0.1);
    addAbility(AbilityCategory.FEAT, quickFlySlowSwim);
    pc.calcActiveBonuses();
    pc.adjustMoveRates();
    assertEquals(10.0, display.movementOfType("Swim"), 0.1);
    assertEquals(30.0, display.movementOfType("Fly"), 0.1);
    pc.addTemplate(template);
    pc.adjustMoveRates();
    assertEquals(30.0, display.movementOfType("Swim"), 0.1);
    assertEquals(30.0, display.movementOfType("Fly"), 0.1);
    pc.addTemplate(template2);
    pc.adjustMoveRates();
    assertEquals(30.0, display.movementOfType("Swim"), 0.1);
    assertEquals(30.0, display.movementOfType("Fly"), 0.1);
    assertEquals(60.0, display.movementOfType("Dig"), 0.1);
}
Also used : LoadInfo(pcgen.core.system.LoadInfo) BonusObj(pcgen.core.bonus.BonusObj) CharacterDisplay(pcgen.core.display.CharacterDisplay) LoadContext(pcgen.rules.context.LoadContext) BigDecimal(java.math.BigDecimal)

Example 14 with CharacterDisplay

use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.

the class PlayerCharacterTest method testGetAvailableFollowers.

/**
	 * Validate the getAvailableFollowers function.
	 */
public void testGetAvailableFollowers() {
    readyToRun();
    Ability ab = TestHelper.makeAbility("Tester1", AbilityCategory.FEAT, "Empty Container");
    Ability mab = TestHelper.makeAbility("Tester2", AbilityCategory.FEAT, "Mount Container");
    Ability fab = TestHelper.makeAbility("Tester3", AbilityCategory.FEAT, "Familiar Container");
    PlayerCharacter pc = getCharacter();
    CharacterDisplay display = pc.getDisplay();
    addAbility(AbilityCategory.FEAT, ab);
    CDOMSingleRef<CompanionList> ref = new CDOMSimpleSingleRef<>(CompanionList.class, "Mount");
    CDOMReference<Race> race = new CDOMDirectSingleRef<>(giantRace);
    FollowerOption option = new FollowerOption(race, ref);
    mab.addToListFor(ListKey.COMPANIONLIST, option);
    ref = new CDOMSimpleSingleRef<>(CompanionList.class, "Familiar");
    race = new CDOMDirectSingleRef<>(human);
    option = new FollowerOption(race, ref);
    fab.addToListFor(ListKey.COMPANIONLIST, option);
    Set<FollowerOption> fo = display.getAvailableFollowers("Familiar", null).keySet();
    assertTrue("Initially familiar list should be empty", fo.isEmpty());
    fo = display.getAvailableFollowers("MOUNT", null).keySet();
    assertTrue("Initially mount list should be empty", fo.isEmpty());
    addAbility(AbilityCategory.FEAT, mab);
    fo = display.getAvailableFollowers("Familiar", null).keySet();
    assertTrue("Familiar list should still be empty", fo.isEmpty());
    fo = display.getAvailableFollowers("MOUNT", null).keySet();
    assertFalse("Mount list should not be empty anymore", fo.isEmpty());
    assertEquals("Mount should be the giant race", giantRace.getKeyName(), fo.iterator().next().getRace().getKeyName());
    assertEquals("Mount list should only have one entry", 1, fo.size());
    addAbility(AbilityCategory.FEAT, fab);
    fo = display.getAvailableFollowers("Familiar", null).keySet();
    assertFalse("Familiar list should not be empty anymore", fo.isEmpty());
    assertEquals("Familiar should be the human race", human.getKeyName(), fo.iterator().next().getRace().getKeyName());
    assertEquals("Familiar list should only have one entry", 1, fo.size());
    fo = display.getAvailableFollowers("MOUNT", null).keySet();
    assertFalse("Mount list should not be empty anymore", fo.isEmpty());
    assertEquals("Mount should be the giant race", giantRace.getKeyName(), fo.iterator().next().getRace().getKeyName());
    assertEquals("Mount list should only have one entry", 1, fo.size());
}
Also used : CDOMDirectSingleRef(pcgen.cdom.reference.CDOMDirectSingleRef) CompanionList(pcgen.cdom.list.CompanionList) CharacterDisplay(pcgen.core.display.CharacterDisplay) CDOMSimpleSingleRef(pcgen.cdom.reference.CDOMSimpleSingleRef)

Example 15 with CharacterDisplay

use of pcgen.core.display.CharacterDisplay in project pcgen by PCGen.

the class ArmorToken method _writeArmorProperty.

private static String _writeArmorProperty(Equipment eq, String property, PlayerCharacter aPC) {
    CharacterDisplay display = aPC.getDisplay();
    StringBuilder ret = new StringBuilder();
    if (property.startsWith("NAME")) {
        if (eq.isEquipped() && !property.equals("NAMENOSTAR")) {
            ret.append('*');
        }
        ret.append(OutputNameFormatting.parseOutputName(eq, aPC));
        ret.append(eq.getAppliedName());
    } else if (property.startsWith("OUTPUTNAME")) {
        // TODO this appears to be the same as above.  Should be refactored
        if (eq.isEquipped()) {
            ret.append('*');
        }
        ret.append(OutputNameFormatting.parseOutputName(eq, aPC));
        ret.append(eq.getAppliedName());
    } else if (property.startsWith("TOTALAC") || property.startsWith("ACBONUS")) {
        // adjustments for new equipment modifier
        // EQMARMOR|AC|x|TYPE=ENHANCEMENT changed to COMBAT|AC|x|TYPE=Armor.ENHANCEMENT
        //FileAccess.write(output, Delta.toString(eq.getACMod()));
        String acMod = aPC.getControl(CControl.EQACMOD);
        if (acMod != null) {
            Object o = aPC.getLocal(eq, acMod);
            int intValue = ((Number) o).intValue();
            ret.append(Delta.toString(intValue));
        } else {
            ret.append(Delta.toString((int) eq.bonusTo(aPC, "COMBAT", "AC", true)));
        }
    } else if (property.startsWith("BASEAC")) {
        // adjustments for new equipment modifier
        // EQMARMOR|AC|x|TYPE=ENHANCEMENT changed to COMBAT|AC|x|TYPE=Armor.ENHANCEMENT
        //FileAccess.write(output, Delta.toString(eq.getACMod()));
        String baseMod = aPC.getControl(CControl.EQBASEACMOD);
        if (baseMod != null) {
            Object o = aPC.getLocal(eq, baseMod);
            int intValue = ((Number) o).intValue();
            ret.append(Delta.toString(intValue));
        } else {
            ret.append(Delta.toString((int) BonusCalc.charBonusTo(eq, "COMBAT", "AC", aPC)));
        }
    } else if (property.startsWith("MAXDEX")) {
        final int iMax = EqToken.getMaxDexTokenInt(aPC, eq);
        if (iMax != Constants.MAX_MAXDEX) {
            ret.append(Delta.toString(iMax));
        }
    } else if (property.startsWith("ACCHECK")) {
        ret.append(Delta.toString(EqToken.getAcCheckTokenInt(aPC, eq)));
    } else if (property.startsWith("EDR")) {
        ret.append(Delta.toString(EqToken.getEdrTokenInt(aPC, eq)));
    } else if (property.startsWith("ISTYPE")) {
        if (eq.isType(property.substring(property.indexOf(".") + 1))) {
            ret.append("TRUE");
        } else {
            ret.append("FALSE");
        }
    } else if (property.startsWith("SPELLFAIL")) {
        ret.append(EqToken.getSpellFailureTokenInt(aPC, eq));
    } else if (property.startsWith("MOVE")) {
        final StringTokenizer aTok = new StringTokenizer(eq.moveString(), ",", false);
        String tempString = "";
        if (("M".equals(display.getSize()) || "S".equals(display.getSize())) && (aTok.countTokens() > 0)) {
            tempString = aTok.nextToken();
            if ("S".equals(display.getSize()) && (aTok.countTokens() > 1)) {
                tempString = aTok.nextToken();
            }
        }
        ret.append(tempString);
    } else if (property.startsWith("SPROP")) {
        ret.append(eq.getSpecialProperties(aPC));
    } else if (property.startsWith("TYPE")) {
        String typeString = "";
        if (eq.isLight()) {
            typeString = "Light";
        } else if (eq.isMedium()) {
            typeString = "Medium";
        } else if (eq.isHeavy()) {
            typeString = "Heavy";
        } else if (eq.isShield()) {
            typeString = "Shield";
        } else if (eq.isExtra()) {
            typeString = "Extra";
        }
        ret.append(typeString);
    } else if (property.startsWith("WT")) {
        ret.append(BigDecimalHelper.trimZeros(eq.getWeight(aPC).toString()));
    }
    return ret.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer) CharacterDisplay(pcgen.core.display.CharacterDisplay)

Aggregations

CharacterDisplay (pcgen.core.display.CharacterDisplay)32 StringTokenizer (java.util.StringTokenizer)9 PCClass (pcgen.core.PCClass)9 Equipment (pcgen.core.Equipment)5 ArrayList (java.util.ArrayList)4 PlayerCharacter (pcgen.core.PlayerCharacter)4 Skill (pcgen.core.Skill)4 Set (java.util.Set)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 PCClassLevel (pcgen.cdom.inst.PCClassLevel)3 PCTemplate (pcgen.core.PCTemplate)3 Follower (pcgen.core.character.Follower)3 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Type (pcgen.cdom.enumeration.Type)2 SpecialAbility (pcgen.core.SpecialAbility)2 Dice (gmgen.plugin.dice.Dice)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1