Search in sources :

Example 1 with CharacterDisplay

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

the class WeaponToken method getTotalHitToken.

/**
	 * Get total hit token
	 * @param pc
	 * @param eq
	 * @param range
	 * @param content
	 * @param ammo
	 * @param attackNum
	 * @return total hit token
	 */
public static String getTotalHitToken(PlayerCharacter pc, Equipment eq, int range, int content, int ammo, int attackNum) {
    CharacterDisplay display = pc.getDisplay();
    boolean isDouble = (eq.isDouble() && (eq.getLocation() == EquipmentLocation.EQUIPPED_TWO_HANDS));
    boolean isDoubleSplit = (eq.isType("Head1") || eq.isType("Head2"));
    int hitMode = HITMODE_TOTALHIT;
    // First do unarmed.
    if (eq.isUnarmed()) {
        hitMode = HITMODE_BASEHIT;
    } else // next do Double weapons
    if (isDouble && !isDoubleSplit) {
        hitMode = HITMODE_TWOHIT;
    } else if (!isDouble && isDoubleSplit) {
        hitMode = HITMODE_THHIT;
    } else // eq is Primary
    if (display.isPrimaryWeapon(eq) && display.hasSecondaryWeapons()) {
        Equipment sEq = display.getSecondaryWeapons().iterator().next();
        if (sEq == null) {
            // Hmm, weird
            // default to off-hand light
            hitMode = HITMODE_TWPHITL;
        } else if (sEq.isWeaponLightForPC(pc)) {
            // offhand light
            hitMode = HITMODE_TWPHITL;
        } else {
            // offhand heavy
            hitMode = HITMODE_TWPHITH;
        }
    } else // eq is Secondary
    if (display.isSecondaryWeapon(eq) && display.hasPrimaryWeapons()) {
        if (eq.isWeaponLightForPC(pc)) {
            // offhand light
            hitMode = HITMODE_TWFOHL;
        } else {
            // offhand heavy
            hitMode = HITMODE_TWFOHH;
        }
    } else // Just a single off-hand weapon
    if (display.isSecondaryWeapon(eq) && !display.hasPrimaryWeapons()) {
        hitMode = HITMODE_OHHIT;
    } else // Just a single primary weapon
    if (display.isPrimaryWeapon(eq) && !display.hasSecondaryWeapons()) {
        if (eq.getLocation() == EquipmentLocation.EQUIPPED_BOTH) {
            // both hands
            hitMode = HITMODE_THHIT;
        } else {
            // single hand
            hitMode = HITMODE_BASEHIT;
        }
    } else {
        // probably just carried
        if (eq.isWeaponTwoHanded(pc)) {
            // Two Handed weapon
            hitMode = HITMODE_THHIT;
        } else {
            // one handed weapon
            hitMode = HITMODE_BASEHIT;
        }
    }
    return getToHit(pc, eq, range, content, ammo, hitMode, attackNum);
}
Also used : Equipment(pcgen.core.Equipment) CharacterDisplay(pcgen.core.display.CharacterDisplay)

Example 2 with CharacterDisplay

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

the class TempBonusHelper method getListOfApplicableEquipment.

/**
	 * Build a list of what equipment is possible to apply this bonus to.
	 * @param originObj The rules object providing the bonus.
	 * @param theCharacter The target character.
	 * @return The list of possible equipment.
	 */
public static List<InfoFacade> getListOfApplicableEquipment(CDOMObject originObj, PlayerCharacter theCharacter) {
    CharacterDisplay charDisplay = theCharacter.getDisplay();
    List<InfoFacade> possibleEquipment = new ArrayList<>();
    if (originObj == null) {
        return possibleEquipment;
    }
    boolean found = false;
    theCharacter.setCalcEquipmentList(theCharacter.getUseTempMods());
    for (Equipment aEq : charDisplay.getEquipmentSet()) {
        found = false;
        for (EquipBonus eb : originObj.getSafeListFor(ListKey.BONUS_EQUIP)) {
            String conditions = eb.conditions;
            boolean passesConditions = passesConditions(aEq, conditions);
            if (passesConditions && !found) {
                possibleEquipment.add(aEq);
                found = true;
            }
        }
    }
    return possibleEquipment;
}
Also used : EquipBonus(pcgen.core.bonus.EquipBonus) Equipment(pcgen.core.Equipment) InfoFacade(pcgen.facade.core.InfoFacade) CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList)

Example 3 with CharacterDisplay

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

the class SkillLevelToken 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) {
    CharacterDisplay display = pc.getDisplay();
    SkillDetails details = buildSkillDetails(tokenSource);
    if (details.getPropertyCount() > 0 && "TOTAL".equals(details.getProperty(0))) {
        final int aLevelOffset;
        try {
            aLevelOffset = Integer.parseInt(details.getSkillId()) - 1;
            if ((aLevelOffset >= display.getLevelInfoSize()) || (aLevelOffset < 0)) {
                return "0";
            }
            final PCLevelInfo wLevelInfo = display.getLevelInfo(aLevelOffset);
            final int wOutput = wLevelInfo.getSkillPointsGained(pc);
            return Integer.toString(wOutput);
        } catch (NumberFormatException nfe) {
            Logging.errorPrint("Error replacing SKILLLEVEL." + tokenSource, nfe);
            return "";
        }
    }
    return "";
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 4 with CharacterDisplay

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

the class ClassToken method getClassSpecialAbilityList.

/**
	 * Get the list of Special Abilities for a class that the PC is eligible
	 * for.
	 * 
	 * @param pcclass
	 *            The class to get the special abilities for
	 * @param aPC
	 *            The PC
	 * @return List of special abilities
	 */
public static List<String> getClassSpecialAbilityList(PCClass pcclass, final PlayerCharacter aPC) {
    CharacterDisplay display = aPC.getDisplay();
    final List<String> formattedList = new ArrayList<>();
    final List<SpecialAbility> saList = new ArrayList<>();
    saList.addAll(display.getResolvedUserSpecialAbilities(pcclass));
    saList.addAll(display.getResolvedSpecialAbilities(pcclass));
    for (int i = 1; i <= display.getLevel(pcclass); i++) {
        PCClassLevel pcl = display.getActiveClassLevel(pcclass, i);
        saList.addAll(display.getResolvedUserSpecialAbilities(pcl));
        saList.addAll(display.getResolvedSpecialAbilities(pcl));
    }
    if (saList.isEmpty()) {
        return formattedList;
    }
    Collections.sort(saList);
    // to include all of the variables
    for (SpecialAbility sa : saList) {
        String str = sa.getDisplayName();
        if (str == null || str.isEmpty()) {
            continue;
        }
        StringTokenizer varTok = new StringTokenizer(str, Constants.PIPE);
        final String aString = varTok.nextToken();
        int[] varValue = null;
        int varCount = varTok.countTokens();
        if (varCount != 0) {
            varValue = new int[varCount];
            for (int j = 0; j < varCount; ++j) {
                // Get the value for each variable
                final String vString = varTok.nextToken();
                varValue[j] = aPC.getVariable(vString, true).intValue();
            }
        }
        final StringBuilder newAbility = new StringBuilder();
        varTok = new StringTokenizer(aString, "%", true);
        varCount = 0;
        boolean isZero = false;
        // Fill in each % with the value of the appropriate token
        while (varTok.hasMoreTokens()) {
            final String nextTok = varTok.nextToken();
            if ("%".equals(nextTok)) {
                if (varCount == 0) {
                    // If this is the first token, then set the count of
                    // successful token replacements to 0
                    isZero = true;
                }
                if ((varValue != null) && (varCount < varValue.length)) {
                    final int thisVar = varValue[varCount++];
                    // Update isZero if this token has a value of anything
                    // other than 0
                    isZero &= (thisVar == 0);
                    newAbility.append(thisVar);
                } else {
                    newAbility.append('%');
                }
            } else {
                newAbility.append(nextTok);
            }
        }
        if (!isZero) {
            // If all of the tokens for this ability were 0 then we do not
            // show it,
            // otherwise we add it to the return list.
            formattedList.add(newAbility.toString());
        }
    }
    return formattedList;
}
Also used : StringTokenizer(java.util.StringTokenizer) CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 5 with CharacterDisplay

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

the class TemplateToken method getSAToken.

/**
	 * Get value of SA sub token
	 * @param template
	 * @param pc
	 * @return value of SA sub token
	 */
public static String getSAToken(PCTemplate template, PlayerCharacter pc) {
    CharacterDisplay display = pc.getDisplay();
    List<SpecialAbility> saList = new ArrayList<>();
    saList.addAll(display.getResolvedUserSpecialAbilities(template));
    saList.addAll(display.getResolvedSpecialAbilities(template));
    List<PCTemplate> subList = new ArrayList<>();
    subList.addAll(template.getConditionalTemplates(display.getTotalLevels(), display.totalHitDice()));
    for (PCTemplate subt : subList) {
        saList.addAll(display.getResolvedUserSpecialAbilities(subt));
        saList.addAll(display.getResolvedSpecialAbilities(subt));
    }
    List<String> saDescList = new ArrayList<>();
    for (SpecialAbility sa : saList) {
        if (!sa.qualifies(pc, template)) {
            continue;
        }
        final String saText = sa.getParsedText(pc, pc, template);
        if (saText != null && !saText.equals("")) {
            saDescList.add(saText);
        }
    }
    return StringUtil.join(saDescList, ", ");
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList) SpecialAbility(pcgen.core.SpecialAbility) PCTemplate(pcgen.core.PCTemplate)

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