Search in sources :

Example 6 with PlayerCharacter

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

the class TemplateFeatFacet method dataAdded.

/**
	 * Adds all of the feats to the Player Character triggered by the FEAT token'
	 * on the given PCTemplate
	 * 
	 * Triggered when one of the Facets to which ConditionalTemplateFacet
	 * listens fires a DataFacetChangeEvent to indicate a PCTemplate was added
	 * to a Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, PCTemplate> dfce) {
    CharID id = dfce.getCharID();
    PCTemplate source = dfce.getCDOMObject();
    if (!containsFrom(id, source)) {
        PersistentTransitionChoice<CNAbilitySelection> choice = source.get(ObjectKey.TEMPLATE_FEAT);
        if (choice != null) {
            PlayerCharacter pc = trackingFacet.getPC(id);
            Collection<? extends CNAbilitySelection> result = choice.driveChoice(pc);
            choice.act(result, source, pc);
            for (CNAbilitySelection cas : result) {
                add(id, cas, source);
            }
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID)

Example 7 with PlayerCharacter

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

the class MonsterClassFacet method dataRemoved.

/**
	 * Removes monster classes from the Player Character when the CDOMObject
	 * which granted the monster classes is removed from the Player Character.
	 * 
	 * Triggered when one of the Facets to which MonsterClassFacet listens fires
	 * a DataFacetChangeEvent to indicate a CDOMObject was removed from a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    LevelCommandFactory lcf = cdo.get(ObjectKey.MONSTER_CLASS);
    if (lcf != null) {
        CharID id = dfce.getCharID();
        int levelCount = formulaResolvingFacet.resolve(id, lcf.getLevelCount(), "").intValue();
        PlayerCharacter pc = trackingFacet.getPC(id);
        pc.incrementClassLevel(-levelCount, lcf.getPCClass(), true);
    }
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) PlayerCharacter(pcgen.core.PlayerCharacter) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Example 8 with PlayerCharacter

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

the class MonsterClassFacet method dataAdded.

/**
	 * Adds monster classes to the Player Character when a CDOMObject which
	 * grants monster classes is added to the Player Character.
	 * 
	 * Triggered when one of the Facets to which MonsterClassFacet listens fires
	 * a DataFacetChangeEvent to indicate a CDOMObject was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CharID id = dfce.getCharID();
    CDOMObject cdo = dfce.getCDOMObject();
    // Get existing classes
    ClassInfo ci = classFacet.removeAllClasses(id);
    //
    for (int i = levelInfoFacet.getCount(id) - 1; i >= 0; --i) {
        PCLevelInfo pli = levelInfoFacet.get(id, i);
        final String classKeyName = pli.getClassKeyName();
        final PCClass aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKeyName);
        if (aClass.isMonster()) {
            levelInfoFacet.remove(id, pli);
        }
    }
    PlayerCharacter pc = trackingFacet.getPC(id);
    final List<PCLevelInfo> existingLevelInfo = new ArrayList<>(levelInfoFacet.getSet(id));
    levelInfoFacet.removeAll(id);
    // Make sure monster classes are added first
    if (!pc.isImporting()) {
        LevelCommandFactory lcf = cdo.get(ObjectKey.MONSTER_CLASS);
        if (lcf != null) {
            int levelCount = formulaResolvingFacet.resolve(id, lcf.getLevelCount(), "").intValue();
            pc.incrementClassLevel(levelCount, lcf.getPCClass(), true);
        }
    }
    levelInfoFacet.addAll(id, existingLevelInfo);
    //
    if (!pc.isImporting() && ci != null && !ci.isEmpty()) {
        int totalLevels = levelFacet.getTotalLevels(id);
        for (PCClass pcClass : ci.getClassSet()) {
            //
            if (!pcClass.isMonster()) {
                classFacet.addClass(id, pcClass);
                int cLevels = ci.getLevel(pcClass);
                classFacet.setLevel(id, pcClass, cLevels);
                pc.setSkillPool(pcClass, 0);
                int cMod = 0;
                for (int j = 0; j < cLevels; ++j) {
                    cMod += pc.recalcSkillPointMod(pcClass, ++totalLevels);
                }
                pc.setSkillPool(pcClass, cMod);
            }
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) ClassInfo(pcgen.cdom.facet.model.ClassFacet.ClassInfo)

Example 9 with PlayerCharacter

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

the class HitPointFacet method rollHP.

/**
	 * Rolls the hit points for a given PCClass and level.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character on which the hit
	 *            points are to be rolled
	 * @param pcc
	 *            The PCClass for which the hit points are to be rolled
	 * @param level
	 *            The class level for which the hit points are to be rolled
	 * @param first
	 *            And identifier indicating if this is the Player Character's
	 *            first level.
	 */
public void rollHP(CharID id, PCClass pcc, int level, boolean first) {
    int roll = 0;
    HitDie lvlDie = getLevelHitDie(id, pcc, level);
    if ((lvlDie == null) || (lvlDie.getDie() == 0)) {
        roll = 0;
    } else {
        final int min = 1 + (int) bonusCheckingFacet.getBonus(id, "HD", "MIN") + (int) bonusCheckingFacet.getBonus(id, "HD", "MIN;CLASS." + pcc.getKeyName());
        final int max = getLevelHitDie(id, pcc, level).getDie() + (int) bonusCheckingFacet.getBonus(id, "HD", "MAX") + (int) bonusCheckingFacet.getBonus(id, "HD", "MAX;CLASS." + pcc.getKeyName());
        if (SettingsHandler.getGame().getHPFormula().isEmpty()) {
            if (first && level == 1 && SettingsHandler.isHPMaxAtFirstLevel() && (!SettingsHandler.isHPMaxAtFirstPCClassLevelOnly() || pcc.isType("PC"))) {
                roll = max;
            } else {
                PlayerCharacter pc = trackingFacet.getPC(id);
                if (!pc.isImporting()) {
                    roll = rollHP(min, max, levelFacet.getTotalLevels(id));
                }
            }
        }
        roll += ((int) bonusCheckingFacet.getBonus(id, "HP", "CURRENTMAXPERLEVEL"));
    }
    PCClassLevel classLevel = classFacet.getClassLevel(id, pcc, level - 1);
    set(id, classLevel, roll);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) HitDie(pcgen.cdom.content.HitDie) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 10 with PlayerCharacter

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

the class PrerequisiteFacet method qualifies.

/**
	 * Returns true if the Player Character identified by the given CharID
	 * qualifies for the given QualifyingObject when the QualifyingObject is
	 * from the given source.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character on which the
	 *            prerequisite test will be performed
	 * @param obj
	 *            The QualifyingObject which contains the prerequisite(s) to be
	 *            tested
	 * @param source
	 *            The source of the QualifyingObject, which is used to given
	 *            context to the prerequisites being tested
	 * @return true if the Player Character identified by the given CharID
	 *         qualifies for the given QualifyingObject when the
	 *         QualifyingObject is from the given source; false otherwise
	 */
public boolean qualifies(CharID id, QualifyingObject obj, Object source) {
    PlayerCharacter pc = trackingFacet.getPC(id);
    CDOMObject cdo = null;
    if (source instanceof CDOMObject) {
        cdo = (CDOMObject) source;
    }
    return obj.qualifies(pc, cdo);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CDOMObject(pcgen.cdom.base.CDOMObject)

Aggregations

PlayerCharacter (pcgen.core.PlayerCharacter)438 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)89 PCClass (pcgen.core.PCClass)61 LoadContext (pcgen.rules.context.LoadContext)58 Ability (pcgen.core.Ability)54 Equipment (pcgen.core.Equipment)41 PCTemplate (pcgen.core.PCTemplate)38 EquipSet (pcgen.core.character.EquipSet)32 BonusObj (pcgen.core.bonus.BonusObj)29 Race (pcgen.core.Race)28 CharID (pcgen.cdom.enumeration.CharID)25 ExportHandler (pcgen.io.ExportHandler)24 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)16 PreClassTester (plugin.pretokens.test.PreClassTester)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Skill (pcgen.core.Skill)14 CNAbility (pcgen.cdom.content.CNAbility)13 URI (java.net.URI)11 URISyntaxException (java.net.URISyntaxException)11