Search in sources :

Example 56 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class PCClass method copyLevelsFrom.

public void copyLevelsFrom(PCClass cl) {
    for (Map.Entry<Integer, PCClassLevel> me : cl.levelMap.entrySet()) {
        try {
            PCClassLevel lvl = me.getValue().clone();
            lvl.put(StringKey.QUALIFIED_KEY, getQualifiedKey());
            lvl.put(ObjectKey.SOURCE_CAMPAIGN, get(ObjectKey.SOURCE_CAMPAIGN));
            lvl.put(StringKey.SOURCE_PAGE, get(StringKey.SOURCE_PAGE));
            lvl.put(StringKey.SOURCE_LONG, get(StringKey.SOURCE_LONG));
            lvl.put(StringKey.SOURCE_SHORT, get(StringKey.SOURCE_SHORT));
            lvl.put(StringKey.SOURCE_WEB, get(StringKey.SOURCE_WEB));
            lvl.put(ObjectKey.SOURCE_DATE, get(ObjectKey.SOURCE_DATE));
            lvl.put(ObjectKey.TOKEN_PARENT, this);
            lvl.setName(getDisplayName() + "(" + lvl.get(IntegerKey.LEVEL) + ")");
            lvl.ownBonuses(this);
            levelMap.put(me.getKey(), lvl);
        } catch (CloneNotSupportedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 57 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class PCClass method addLevel.

/**
	 * Adds a level of this class to the character.
	 *
	 * TODO: Split the PlayerCharacter code out of PCClass (i.e. the level
	 * property). Then have a joining class assigned to PlayerCharacter that
	 * maps PCClass and number of levels in the class.
	 *
	 *
	 * @param argLevelMax
	 *            True if we should only allow extra levels if there are still
	 *            levels in this class to take. (i.e. a lot of prestige classes
	 *            stop at level 10, so if this is true it would not allow an
	 *            11th level of the class to be added
	 * @param bSilent
	 *            True if we are not to show any dialog boxes about errors or
	 *            questions.
	 * @param aPC
	 *            The character we are adding the level to.
	 * @param ignorePrereqs
	 *            True if prereqs for the level should be ignored. Used in
	 *            situations such as when the character is being loaded.
	 * @return true or false
	 */
/*
	 * REFACTOR Clearly this is part of the PCClass factory method that produces
	 * PCClassLevels combined with some other work that will need to be done to
	 * extract some of the complicated gunk out of here that goes out and puts
	 * information into PCLevelInfo and PlayerCharacter.
	 */
public boolean addLevel(final boolean argLevelMax, final boolean bSilent, final PlayerCharacter aPC, final boolean ignorePrereqs) {
    // Check to see if we can add a level of this class to the
    // current character
    final int newLevel = aPC.getLevel(this) + 1;
    boolean levelMax = argLevelMax;
    aPC.setAllowInteraction(false);
    aPC.setLevelWithoutConsequence(this, newLevel);
    if (!ignorePrereqs) {
        // When loading a character, classes are added before feats, so
        // this test would always fail on loading if feats are required
        boolean doReturn = false;
        if (!qualifies(aPC, this)) {
            doReturn = true;
            if (!bSilent) {
                ShowMessageDelegate.showMessageDialog("This character does not qualify for level " + newLevel, Constants.APPLICATION_NAME, MessageType.ERROR);
            }
        }
        aPC.setLevelWithoutConsequence(this, newLevel - 1);
        if (doReturn) {
            return false;
        }
    }
    aPC.setAllowInteraction(true);
    if (isMonster()) {
        levelMax = false;
    }
    if (hasMaxLevel() && (newLevel > getSafe(IntegerKey.LEVEL_LIMIT)) && levelMax) {
        if (!bSilent) {
            ShowMessageDelegate.showMessageDialog("This class cannot be raised above level " + Integer.toString(getSafe(IntegerKey.LEVEL_LIMIT)), Constants.APPLICATION_NAME, MessageType.ERROR);
        }
        return false;
    }
    // Add the level to the current character
    int total = aPC.getTotalLevels();
    // No longer need this since the race now sets a bonus itself and Templates
    // are not able to reassign their feats.  There was nothing else returned in
    // this number
    //		if (total == 0) {
    //			aPC.setFeats(aPC.getInitialFeats());
    //		}
    setLevel(newLevel, aPC);
    // the level has now been added to the character,
    // so now assign the attributes of this class level to the
    // character...
    PCClassLevel classLevel = aPC.getActiveClassLevel(this, newLevel);
    // Make sure that if this Class adds a new domain that
    // we record where that domain came from
    final int dnum = aPC.getMaxCharacterDomains(this, aPC) - aPC.getDomainCount();
    if (dnum > 0 && !aPC.hasDefaultDomainSource()) {
        aPC.setDefaultDomainSource(new ClassSource(this, newLevel));
    }
    // out
    if (Globals.getUseGUI()) {
        final int levels = SettingsHandler.isHPMaxAtFirstClassLevel() ? aPC.totalNonMonsterLevels() : aPC.getTotalLevels();
        final boolean isFirst = levels == 1;
        aPC.rollHP(this, aPC.getLevel(this), isFirst);
    }
    if (!aPC.isImporting()) {
        DomainApplication.addDomainsUpToLevel(this, newLevel, aPC);
    }
    int levelUpStats = 0;
    // i.e. a bonus feat every 3 levels
    if (aPC.getTotalLevels() > total) {
        boolean processBonusStats = true;
        total = aPC.getTotalLevels();
        if (isMonster()) {
            // If we have less levels that the races monster levels
            // then we can not give a stat bonus (i.e. an Ogre has
            // 4 levels of Giant, so it does not get a stat increase at
            // 4th level because that is already taken into account in
            // its racial stat modifiers, but it will get one at 8th
            LevelCommandFactory lcf = aPC.getRace().get(ObjectKey.MONSTER_CLASS);
            int monLevels = 0;
            if (lcf != null) {
                monLevels = lcf.getLevelCount().resolve(aPC, "").intValue();
            }
            if (total <= monLevels) {
                processBonusStats = false;
            }
        }
        if (!aPC.isImporting()) {
            if (processBonusStats) {
                final int bonusStats = Globals.getBonusStatsForLevel(total, aPC);
                if (bonusStats > 0) {
                    aPC.setPoolAmount(aPC.getPoolAmount() + bonusStats);
                    if (!bSilent && SettingsHandler.getShowStatDialogAtLevelUp()) {
                        levelUpStats = StatApplication.askForStatIncrease(aPC, bonusStats, true);
                    }
                }
            }
        }
    }
    int spMod = getSkillPointsForLevel(aPC, classLevel, total);
    PCLevelInfo pcl;
    if (aPC.getLevelInfoSize() > 0) {
        pcl = aPC.getLevelInfo(aPC.getLevelInfoSize() - 1);
        if (pcl != null) {
            pcl.setClassLevel(aPC.getLevel(this));
            pcl.setSkillPointsGained(aPC, spMod);
            pcl.setSkillPointsRemaining(pcl.getSkillPointsGained(aPC));
        }
    }
    Integer currentPool = aPC.getSkillPool(this);
    int newSkillPool = spMod + (currentPool == null ? 0 : currentPool);
    aPC.setSkillPool(this, newSkillPool);
    if (!aPC.isImporting()) {
        //
        if (levelUpStats > 0) {
            StatApplication.askForStatIncrease(aPC, levelUpStats, false);
        }
        if (newLevel == 1) {
            AddObjectActions.doBaseChecks(this, aPC);
            CDOMObjectUtilities.addAdds(this, aPC);
            CDOMObjectUtilities.checkRemovals(this, aPC);
        }
        for (TransitionChoice<Kit> kit : classLevel.getSafeListFor(ListKey.KIT_CHOICE)) {
            kit.act(kit.driveChoice(aPC), classLevel, aPC);
        }
        TransitionChoice<Region> region = classLevel.get(ObjectKey.REGION_CHOICE);
        if (region != null) {
            region.act(region.driveChoice(aPC), classLevel, aPC);
        }
    }
    // this is a monster class, so don't worry about experience
    if (isMonster()) {
        return true;
    }
    if (!aPC.isImporting()) {
        CDOMObjectUtilities.checkRemovals(this, aPC);
        final int minxp = aPC.minXPForECL();
        if (aPC.getXP() < minxp) {
            aPC.setXP(minxp);
        } else if (aPC.getXP() >= aPC.minXPForNextECL()) {
            if (!bSilent) {
                ShowMessageDelegate.showMessageDialog(SettingsHandler.getGame().getLevelUpMessage(), Constants.APPLICATION_NAME, MessageType.INFORMATION);
            }
        }
    }
    //
    if (containsKey(ObjectKey.EXCHANGE_LEVEL) && (aPC.getLevel(this) == 1) && !aPC.isImporting()) {
        ExchangeLevelApplication.exchangeLevels(aPC, this);
    }
    return true;
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) Region(pcgen.cdom.enumeration.Region) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) ClassSource(pcgen.cdom.helper.ClassSource) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 58 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method getClassLevel.

private PCClassLevel getClassLevel(CharacterLevelFacade level) {
    if (level == null || !(level instanceof CharacterLevelFacadeImpl)) {
        return null;
    }
    CharacterLevelFacadeImpl levelImpl = (CharacterLevelFacadeImpl) level;
    int lvlIdx = levelImpl.getCharacterLevel() - 1;
    final String classKeyName = charDisplay.getLevelInfoClassKeyName(lvlIdx);
    PCClass aClass = theCharacter.getClassKeyed(classKeyName);
    if (aClass != null) {
        final int clsLvl = charDisplay.getLevelInfoClassLevel(lvlIdx);
        PCClassLevel pcl = charDisplay.getActiveClassLevel(aClass, clsLvl - 1);
        return pcl;
    }
    return null;
}
Also used : PCClass(pcgen.core.PCClass) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 59 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method setHPRolled.

/**
	 * @see pcgen.core.facade.CharacterLevelsFacade#setHPRolled(int, int)
	 */
@Override
public void setHPRolled(CharacterLevelFacade level, int hp) {
    PCClassLevel classLevel = getClassLevel(level);
    if (classLevel != null) {
        theCharacter.setHP(classLevel, hp);
        fireHitPointEvent(this, getLevelIndex(level), false);
    }
}
Also used : PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 60 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class PreVarTest method test2856622.

public void test2856622() {
    LoadContext context = Globals.getContext();
    final PCClass warrior = new PCClass();
    warrior.setName("Warrior");
    PCClassLevel level1 = warrior.getOriginalClassLevel(1);
    context.unconditionallyProcess(level1, "SAB", "Test Works|PREVARGTEQ:CL,3");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PlayerCharacter character = this.getCharacter();
    character.incrementClassLevel(1, warrior);
    PCClassLoader loader = new PCClassLoader();
    try {
        SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
        loader.completeObject(context, se, warrior);
        List<SpecialAbility> sabList = level1.getListFor(ListKey.SAB);
        assertNotNull(sabList);
        assertEquals(1, sabList.size());
        SpecialAbility sab = sabList.get(0);
        assertFalse(sab.qualifies(character, warrior));
        character.incrementClassLevel(1, warrior);
        assertFalse(sab.qualifies(character, warrior));
        character.incrementClassLevel(1, warrior);
        assertTrue(sab.qualifies(character, warrior));
    } catch (URISyntaxException | PersistenceLayerException e) {
        fail(e.getMessage());
    }
}
Also used : SpecialAbility(pcgen.core.SpecialAbility) URISyntaxException(java.net.URISyntaxException) PCClass(pcgen.core.PCClass) URI(java.net.URI) PCClassLevel(pcgen.cdom.inst.PCClassLevel) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PlayerCharacter(pcgen.core.PlayerCharacter) Campaign(pcgen.core.Campaign) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) SourceEntry(pcgen.persistence.lst.SourceEntry) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry)

Aggregations

PCClassLevel (pcgen.cdom.inst.PCClassLevel)69 PCClass (pcgen.core.PCClass)26 Test (org.junit.Test)25 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)9 CDOMObject (pcgen.cdom.base.CDOMObject)8 ArrayList (java.util.ArrayList)5 CharID (pcgen.cdom.enumeration.CharID)5 ParseResult (pcgen.rules.persistence.token.ParseResult)5 CDOMReference (pcgen.cdom.base.CDOMReference)4 SpecialAbility (pcgen.core.SpecialAbility)4 LoadContext (pcgen.rules.context.LoadContext)4 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)4 StringTokenizer (java.util.StringTokenizer)3 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)3 Domain (pcgen.core.Domain)3 Skill (pcgen.core.Skill)3 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)3 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2