Search in sources :

Example 6 with PCStat

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

the class DefineIntegrationTest method setUp.

@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    PCStat ps = BuildUtilities.createStat("Strength", "STR");
    primaryContext.getReferenceContext().importObject(ps);
    PCStat pi = BuildUtilities.createStat("Intelligence", "INT");
    primaryContext.getReferenceContext().importObject(pi);
    PCStat ss = BuildUtilities.createStat("Strength", "STR");
    secondaryContext.getReferenceContext().importObject(ss);
    PCStat si = BuildUtilities.createStat("Intelligence", "INT");
    secondaryContext.getReferenceContext().importObject(si);
}
Also used : PCStat(pcgen.core.PCStat)

Example 7 with PCStat

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

the class StatBonusFacet method getStatBonusTo.

/**
	 * Returns the aggregate Bonus value for the given Bonus type and given
	 * Bonus name which are applied by PCStat objects to the Player Character
	 * identified by the given CharID.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            aggregate Bonus value is to be calculated
	 * @param type
	 *            The Bonus type for which the aggregate Bonus value is to be
	 *            calculated
	 * @param name
	 *            The Bonus name for which the aggregate Bonus value is to be
	 *            calculated
	 * @return The aggregate Bonus value for the given Bonus type and given
	 *         Bonus name which are applied by PCStat objects to the Player
	 *         Character identified by the given CharID
	 */
public double getStatBonusTo(CharID id, String type, String name) {
    final Map<BonusObj, PCStat> map = getBonusListOfType(id, type.toUpperCase(), name.toUpperCase());
    for (Iterator<Map.Entry<BonusObj, PCStat>> it = map.entrySet().iterator(); it.hasNext(); ) {
        Entry<BonusObj, PCStat> me = it.next();
        BonusObj bo = me.getKey();
        if (!prerequisiteFacet.qualifies(id, bo, me.getValue())) {
            it.remove();
        }
    }
    return bonusCheckingFacet.calcBonus(id, map);
}
Also used : Entry(java.util.Map.Entry) BonusObj(pcgen.core.bonus.BonusObj) PCStat(pcgen.core.PCStat)

Example 8 with PCStat

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

the class PCGVer2Parser method parseStatLine.

/*
	 * ###############################################################
	 * Character Attributes methods
	 * ###############################################################
	 */
private void parseStatLine(final String line) throws PCGParseException {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        /*
			 * Ability scores are critical for characters,
			 * need to stop the load process
			 *
			 * Thomas Behr 09-09-02
			 */
        throw new PCGParseException("parseStatLine", line, //$NON-NLS-1$
        pcgpex.getMessage());
    }
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    if (it.hasNext()) {
        PCGElement element = it.next();
        final String statName = element.getText();
        PCStat stat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCStat.class, statName);
        if ((stat != null) && seenStats.add(statName.toUpperCase()) && (it.hasNext())) {
            element = it.next();
            try {
                thePC.setStat(stat, Integer.parseInt(element.getText()));
            } catch (NumberFormatException nfe) {
                throw new PCGParseException("parseStatLine", line, //$NON-NLS-1$
                nfe.getMessage());
            }
        } else {
            final String message = "Invalid attribute specification. " + "Cannot load character.";
            //$NON-NLS-1$
            throw new PCGParseException("parseStatLine", line, message);
        }
    } else {
        final String message = "Invalid attribute specification. " + "Cannot load character.";
        //$NON-NLS-1$
        throw new PCGParseException("parseStatLine", line, message);
    }
}
Also used : PCStat(pcgen.core.PCStat)

Example 9 with PCStat

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

the class CharacterFacadeImpl method setScoreBase.

/**
	 * @see pcgen.core.facade.CharacterFacade#setScoreBase(pcgen.core.facade.StatFacade, int)
	 */
@Override
public void setScoreBase(StatFacade stat, int score) {
    WriteableReferenceFacade<Number> facade = statScoreMap.get(stat);
    if (facade == null) {
        facade = new DefaultReferenceFacade<>(score);
        statScoreMap.put(stat, facade);
    }
    PCStat pcStat = null;
    final int pcPlayerLevels = charDisplay.totalNonMonsterLevels();
    Collection<PCStat> pcStatList = charDisplay.getStatSet();
    for (PCStat aStat : pcStatList) {
        if (stat.getKeyName().equals(aStat.getKeyName())) {
            pcStat = aStat;
            break;
        }
    }
    if (pcStat == null) {
        Logging.errorPrint("Unexpected stat '" + stat + "' found - ignoring.");
        return;
    }
    // Checking for bounds, locked stats and pool points
    String errorMsg = validateNewStatBaseScore(score, pcStat, pcPlayerLevels);
    if (StringUtils.isNotBlank(errorMsg)) {
        delegate.showErrorMessage(Constants.APPLICATION_NAME, errorMsg);
        return;
    }
    final int baseScore = charDisplay.getStat(pcStat);
    // Deal with a point pool based game mode where you buy skills and feats as well as stats
    if (Globals.getGameModeHasPointPool()) {
        if (pcPlayerLevels > 0) {
            int poolMod = getPurchaseCostForStat(theCharacter, score) - getPurchaseCostForStat(theCharacter, baseScore);
            //
            if (poolMod > 0) {
                if (poolMod > theCharacter.getSkillPoints()) {
                    delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_sumStatPoolEmpty", //$NON-NLS-1$
                    Globals.getGameModePointPoolName()));
                    return;
                }
            } else if (poolMod < 0) {
                if (theCharacter.getStatIncrease(pcStat, true) < Math.abs(score - baseScore)) {
                    delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
                    LanguageBundle.getString("in_sumStatStartedHigher"));
                    return;
                }
            }
            theCharacter.adjustAbilities(AbilityCategory.FEAT, new BigDecimal(-poolMod));
            showPointPool();
        }
    }
    theCharacter.setStat(pcStat, score);
    facade.set(score);
    theCharacter.saveStatIncrease(pcStat, score - baseScore, false);
    theCharacter.calcActiveBonuses();
    hpRef.set(theCharacter.hitPoints());
    refreshLanguageList();
    updateScorePurchasePool(true);
    if (charLevelsFacade != null) {
        charLevelsFacade.fireSkillBonusEvent(this, 0, true);
    }
}
Also used : PCStat(pcgen.core.PCStat) BigDecimal(java.math.BigDecimal)

Example 10 with PCStat

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

the class CharacterFacadeImpl method refreshRollMethod.

@Override
public void refreshRollMethod() {
    if (!canChangePurchasePool()) {
        return;
    }
    GameMode game = (GameMode) dataSet.getGameMode();
    rollMethodRef.set(game.getRollMethod());
    if (SettingsHandler.getGame().isPurchaseStatMode()) {
        int availablePool = RollingMethods.roll(SettingsHandler.getGame().getPurchaseModeMethodPoolFormula());
        theCharacter.setPointBuyPoints(availablePool);
        // Make sure all scores are within the valid range
        for (StatFacade stat : statScoreMap.keySet()) {
            WriteableReferenceFacade<Number> score = statScoreMap.get(stat);
            if (score.get().intValue() < SettingsHandler.getGame().getPurchaseScoreMin(theCharacter) && stat instanceof PCStat) {
                setStatToPurchaseNeutral((PCStat) stat, score);
            }
        }
    }
    hpRef.set(theCharacter.hitPoints());
    updateScorePurchasePool(false);
}
Also used : GameMode(pcgen.core.GameMode) StatFacade(pcgen.facade.core.StatFacade) PCStat(pcgen.core.PCStat)

Aggregations

PCStat (pcgen.core.PCStat)78 CDOMObject (pcgen.cdom.base.CDOMObject)10 GameMode (pcgen.core.GameMode)10 Before (org.junit.Before)9 Race (pcgen.core.Race)9 PCClass (pcgen.core.PCClass)7 PlayerCharacter (pcgen.core.PlayerCharacter)7 AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)7 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)6 PCTemplate (pcgen.core.PCTemplate)6 Skill (pcgen.core.Skill)6 ArrayList (java.util.ArrayList)5 StatLock (pcgen.cdom.helper.StatLock)5 BonusObj (pcgen.core.bonus.BonusObj)5 Test (org.junit.Test)4 Formula (pcgen.base.formula.Formula)4 CharID (pcgen.cdom.enumeration.CharID)4 LoadContext (pcgen.rules.context.LoadContext)4 StringTokenizer (java.util.StringTokenizer)3 Type (pcgen.cdom.enumeration.Type)3