Search in sources :

Example 1 with PlayerCharacter

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

the class ExportHandler method doPartyForToken.

/**
	 * Deal with the FOR. token, but at a party level
	 * 
	 * @param PCs The PCs to export
	 * @param out The Output we are writing to
	 * @param tokenString The token string to process
	 */
private void doPartyForToken(PlayerCharacter[] PCs, BufferedWriter out, String tokenString) {
    PartyForParser forParser = new PartyForParser(tokenString, PCs.length);
    int x = 0;
    for (int i = forParser.min(); i < forParser.max(); i++) {
        if (x == 0) {
            FileAccess.write(out, forParser.startOfLine());
        }
        PlayerCharacter currPC = ((i >= 0) && (i < PCs.length)) ? PCs[i] : null;
        String[] tokens = forParser.tokenString().split("\\\\\\\\");
        for (String tok : tokens) {
            if (tok.startsWith("%.")) {
                if (currPC != null) {
                    replaceToken(tok.substring(2), out, currPC);
                }
            } else {
                FileAccess.write(out, tok);
            }
        }
        // Note: This was changed from == to && since I can't see how
        // == could possibly be correct behaviour.  If we were not
        // just printing characters that exist the loop would
        // terminate after printing one character. 
        boolean breakloop = (forParser.existsOnly() && (currPC == null));
        ++x;
        if (x == forParser.step() || breakloop) {
            x = 0;
            FileAccess.write(out, forParser.endOfLine());
            if (breakloop) {
                break;
            }
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter)

Example 2 with PlayerCharacter

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

the class ExportHandler method processPipedLine.

/**
	 * Helper method to process a line that begins with a | (and may end with a |)
	 * 
	 * @param PCs List of PCs to output
	 * @param aLine Line to parse
	 * @param buf 
	 * @param out character sheet we are building up
	 * @param between Whether we are processing a line between pipes
	 * @return true if we processed successfully
	 */
private boolean processPipedLine(PlayerCharacter[] PCs, String aLine, StringBuilder buf, BufferedWriter out, boolean between) {
    final StringTokenizer aTok = new StringTokenizer(aLine, "|", false);
    boolean noPipes = false;
    if (aTok.countTokens() == 1) {
        noPipes = true;
    }
    boolean betweenPipes = between;
    while (aTok.hasMoreTokens()) {
        String tok = aTok.nextToken();
        // removing tab characters if asked to do so
        if (!betweenPipes) {
            if (manualWhitespace) {
                tok = tok.replaceAll("[ \\t]", "");
            }
            FileAccess.write(out, tok);
        } else // Guaranteed to be between pipes here
        if (!noPipes && !aTok.hasMoreTokens()) {
            buf.append(tok);
        } else {
            buf.append(tok);
            String aString = buf.toString();
            // We have finished dealing with section
            // between the pipe characters so clear out the
            // StringBuilder
            int l = buf.length();
            buf.delete(0, l);
            if (aString.startsWith("FOR.")) {
                doPartyForToken(PCs, out, aString);
            } else {
                Matcher mat = Pattern.compile("^(\\d+)").matcher(aString);
                int charNum = mat.matches() ? Integer.parseInt(mat.group()) : -1;
                // just be written to the output verbatim
                if ((charNum >= 0) && (charNum < Globals.getPCList().size())) {
                    PlayerCharacter currPC = PCs[charNum];
                    replaceToken(aString, out, currPC);
                } else if (aString.startsWith("EXPORT")) {
                    // We can safely do EXPORT tags with no PC
                    replaceToken(aString, out, null);
                }
            }
        }
        if (aTok.hasMoreTokens() || noPipes) {
            betweenPipes = !betweenPipes;
        }
    }
    return betweenPipes;
}
Also used : StringTokenizer(java.util.StringTokenizer) PlayerCharacter(pcgen.core.PlayerCharacter) Matcher(java.util.regex.Matcher)

Example 3 with PlayerCharacter

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

the class DomainSpellsFacet method dataAdded.

/**
	 * Adds Domain Spells allowed / granted to the Player Character due to the
	 * Domain selections of the Player Character.
	 * 
	 * Triggered when one of the Facets to which DomainSpellsFacet listens fires
	 * a DataFacetChangeEvent to indicate a Domain 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, Domain> dfce) {
    Domain domain = dfce.getCDOMObject();
    CharID id = dfce.getCharID();
    ClassSource source = domainFacet.getSource(id, domain);
    if (source != null) {
        String classKey = source.getPcclass().getKeyName();
        PCClass domainClass = getClassKeyed(id, classKey);
        if (domainClass != null) {
            PlayerCharacter pc = trackingFacet.getPC(id);
            final int maxLevel = pc.getSpellSupport(domainClass).getMaxCastLevel();
            DomainApplication.addSpellsToClassForLevels(pc, domain, domainClass, 0, maxLevel);
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) ClassSource(pcgen.cdom.helper.ClassSource)

Example 4 with PlayerCharacter

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

the class BonusActiviationFacet method dataAdded.

/**
	 * Activates BonusObj objects on the CDOMObject that was added to the Player
	 * Character.
	 * 
	 * Triggered when one of the Facets to which BonusActivationFacet 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();
    PlayerCharacter aPC = trackingFacet.getPC(id);
    if (!aPC.isImporting()) {
        CDOMObject cdo = dfce.getCDOMObject();
        cdo.activateBonuses(aPC);
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID)

Example 5 with PlayerCharacter

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

the class BonusCheckingFacet method getExpandedBonusInfo.

/**
	 * Get back a Collection of bonus info with %LIST entries replaced with the
	 * choices made.
	 * 
	 * This method is value-semantic in that ownership of the returned
	 * Collection is transferred to the class calling this method. Since this is
	 * a remove all function, modification of the returned Collection will not
	 * modify this BonusCheckingFacet and modification of this
	 * BonusCheckingFacet will not modify the returned Collection. Modifications
	 * to the returned Collection will also not modify any future or previous
	 * objects returned by this (or other) methods on BonusCheckingFacet. If you
	 * wish to modify the information stored in this BonusCheckingFacet, you
	 * must use the add*() and remove*() methods of BonusCheckingFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the list
	 *            of bonus information should be returned
	 * @param bonusName
	 *            The Bonus name used to select which Bonus objects to expand to
	 *            get their information
	 * @return A Collection of bonus info with %LIST entries replaced with the
	 *         choices made
	 */
public Collection<String> getExpandedBonusInfo(CharID id, String bonusName) {
    PlayerCharacter pc = trackingFacet.getPC(id);
    List<String> list = new ArrayList<>();
    for (BonusObj bonus : pc.getActiveBonusList()) {
        if (bonus.getTypeOfBonus().equals(bonusName)) {
            String bonusInfo = bonus.getBonusInfo();
            if (bonusInfo.contains("%LIST")) {
                // We have a %LIST that needs to be expanded
                List<BonusPair> bpList = pc.getStringListFromBonus(bonus);
                for (BonusPair bonusPair : bpList) {
                    String key = bonusPair.fullyQualifiedBonusType;
                    // Strip off the bonus name and the trailing . 
                    if (key.startsWith(bonusName)) {
                        key = key.substring(bonusName.length() + 1);
                    }
                    list.add(key);
                }
            } else {
                list.add(bonus.getBonusInfo());
            }
        }
    }
    return list;
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) BonusPair(pcgen.core.bonus.BonusPair)

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