Search in sources :

Example 1 with Region

use of pcgen.cdom.enumeration.Region in project pcgen by PCGen.

the class BioSet method copyRaceTags.

/**
	 * Copies the bio data for one race to a new race.
	 *
	 * @param origRegion The region of the original race
	 * @param origRace   The name of the original race
	 * @param copyRegion The region of the target race
	 * @param copyRace   The name of the target race
	 */
public void copyRaceTags(final String origRegion, final String origRace, final String copyRegion, final String copyRace) {
    Region oldr = Region.getConstant(origRegion);
    Region newr = Region.getConstant(copyRegion);
    for (String key : userMap.getTertiaryKeySet(oldr, origRace)) {
        userMap.addAllToListFor(newr, copyRace, key, userMap.getListFor(oldr, origRace, key));
    }
    final int idx = origRace.indexOf('(');
    String otherRace;
    if (idx >= 0) {
        otherRace = origRace.substring(0, idx).trim() + '%';
    } else {
        otherRace = origRace + '%';
    }
    for (String key : userMap.getTertiaryKeySet(oldr, otherRace)) {
        userMap.addAllToListFor(newr, copyRace, key, userMap.getListFor(oldr, otherRace, key));
    }
}
Also used : Region(pcgen.cdom.enumeration.Region)

Example 2 with Region

use of pcgen.cdom.enumeration.Region in project pcgen by PCGen.

the class BioSet method addToUserMap.

/**
	 * Add the supplied line to the user map. The user map contains an array with
	 * an entry for each age set. The supplied index is used to ensure that the
	 * value is placed in the correct age bracket.
	 *
	 * @param regionString The region the race is defined in.
	 * @param race The race to be updated.
	 * @param tag The tag to be entered. Must be in the form key:value
	 * @param ageSetIndex The age set to be updated.
	 */
public void addToUserMap(String regionString, final String race, final String tag, final int ageSetIndex) {
    final int x = tag.indexOf(':');
    if (x < 0) {
        Logging.errorPrint("Invalid value sent to map: " + tag + " (for Race " + race + ")");
        // invalid tag
        return;
    }
    Region region = Region.getConstant(regionString);
    String key = tag.substring(0, x);
    List<String> r = userMap.getListFor(region, race, key);
    for (int i = (r == null) ? 0 : r.size(); i < ageSetIndex; i++) {
        userMap.addToListFor(region, race, key, "0");
    }
    userMap.addToListFor(region, race, key, tag.substring(x + 1));
}
Also used : Region(pcgen.cdom.enumeration.Region)

Example 3 with Region

use of pcgen.cdom.enumeration.Region in project pcgen by PCGen.

the class RegionLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (obj instanceof NonInteractive) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
    }
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    String item = tok.nextToken();
    Formula count = FormulaFactory.getFormulaFor(item);
    if (!count.isValid()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (count.isStatic()) {
        if (!tok.hasMoreTokens()) {
            return new ParseResult.Fail(getTokenName() + " cannot have only a count: " + value, context);
        }
        item = tok.nextToken();
        if (count.resolveStatic().intValue() <= 0) {
            return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0: " + value, context);
        }
    } else {
        count = FormulaFactory.ONE;
    }
    List<Region> regions = new ArrayList<>();
    while (true) {
        regions.add(Region.getConstant(item));
        if (!tok.hasMoreTokens()) {
            break;
        }
        item = tok.nextToken();
    }
    SimpleChoiceSet<Region> rcs = new SimpleChoiceSet<>(regions);
    ChoiceSet<Region> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Region Selection");
    TransitionChoice<Region> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(obj, ObjectKey.REGION_CHOICE, tc);
    tc.setRequired(false);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) SimpleChoiceSet(pcgen.cdom.choiceset.SimpleChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) Ungranted(pcgen.cdom.base.Ungranted) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) SimpleChoiceSet(pcgen.cdom.choiceset.SimpleChoiceSet) NonInteractive(pcgen.cdom.base.NonInteractive) Region(pcgen.cdom.enumeration.Region)

Example 4 with Region

use of pcgen.cdom.enumeration.Region in project pcgen by PCGen.

the class RegionToken method unparse.

@Override
public String[] unparse(LoadContext context, PCTemplate pct) {
    Boolean useName = context.getObjectContext().getObject(pct, ObjectKey.USETEMPLATENAMEFORREGION);
    Region region = context.getObjectContext().getObject(pct, ObjectKey.REGION);
    if (useName != null && useName) {
        if (region != null) {
            context.addWriteMessage("Cannot have Template with " + getTokenName() + " YES and specific value");
        }
        return new String[] { "YES" };
    }
    if (region == null) {
        // Okay, nothing set
        return null;
    }
    return new String[] { region.toString() };
}
Also used : Region(pcgen.cdom.enumeration.Region)

Example 5 with Region

use of pcgen.cdom.enumeration.Region 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)

Aggregations

Region (pcgen.cdom.enumeration.Region)12 Test (org.junit.Test)2 Formula (pcgen.base.formula.Formula)2 ArrayList (java.util.ArrayList)1 SortedMap (java.util.SortedMap)1 StringTokenizer (java.util.StringTokenizer)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 ChoiceSet (pcgen.cdom.base.ChoiceSet)1 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)1 NonInteractive (pcgen.cdom.base.NonInteractive)1 Ungranted (pcgen.cdom.base.Ungranted)1 SimpleChoiceSet (pcgen.cdom.choiceset.SimpleChoiceSet)1 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)1 CharID (pcgen.cdom.enumeration.CharID)1 ClassSource (pcgen.cdom.helper.ClassSource)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 AgeSet (pcgen.core.AgeSet)1 PlayerCharacter (pcgen.core.PlayerCharacter)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1