Search in sources :

Example 11 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class PCGVer2Parser method parseTempBonusLine.

/**
	 * ###############################################################
	 * Temporary Bonuses
	 * ###############################################################
	 * @param line
	 **/
private void parseTempBonusLine(final String line) {
    PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal TempBonus line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    String cTag = null;
    String tName = null;
    boolean active = true;
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_TEMPBONUS.equals(tag)) {
            cTag = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSTARGET.equals(tag)) {
            tName = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSACTIVE.equals(tag)) {
            active = element.getText().endsWith(IOConstants.VALUE_Y);
        }
    }
    if ((cTag == null) || (tName == null)) {
        warnings.add("Illegal TempBonus line ignored: " + line);
        return;
    }
    //$NON-NLS-1$
    final StringTokenizer aTok = new StringTokenizer(cTag, "=", false);
    if (aTok.countTokens() < 2) {
        return;
    }
    final String cType = aTok.nextToken();
    final String cKey = aTok.nextToken();
    Equipment aEq = null;
    if (!tName.equals(IOConstants.TAG_PC)) {
        // bonus is applied to an equipment item
        // so create a new one and add to PC
        final Equipment eq = thePC.getEquipmentNamed(tName);
        if (eq == null) {
            return;
        }
        aEq = eq.clone();
        //aEq.setWeight("0");
        aEq.resetTempBonusList();
    }
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        final String bonus;
        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            bonus = EntityEncoder.decode(element.getText());
        } else {
            continue;
        }
        if ((bonus == null) || (bonus.length() <= 0)) {
            continue;
        }
        BonusObj newB = null;
        Object creator = null;
        LoadContext context = Globals.getContext();
        // type of object to set as the creator
        if (cType.equals(IOConstants.TAG_FEAT)) {
            for (AbilityCategory aCat : SettingsHandler.getGame().getAllAbilityCategories()) {
                Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, aCat, cKey);
                if (a != null) {
                    newB = Bonus.newBonus(context, bonus);
                    creator = a;
                    break;
                }
            }
        } else if (cType.equals(IOConstants.TAG_EQUIPMENT)) {
            Equipment aEquip = thePC.getEquipmentNamed(cKey);
            if (aEquip == null) {
                aEquip = context.getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, cKey);
            }
            if (aEquip != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aEquip;
            }
        } else if (cType.equals(IOConstants.TAG_CLASS)) {
            final PCClass aClass = thePC.getClassKeyed(cKey);
            if (aClass == null) {
                continue;
            }
            int idx = bonus.indexOf('|');
            newB = Bonus.newBonus(context, bonus.substring(idx + 1));
            creator = aClass;
        } else if (cType.equals(IOConstants.TAG_TEMPLATE)) {
            PCTemplate aTemplate = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, cKey);
            if (aTemplate != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aTemplate;
            }
        } else if (cType.equals(IOConstants.TAG_SKILL)) {
            Skill aSkill = context.getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, cKey);
            if (aSkill != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSkill;
            }
        } else if (cType.equals(IOConstants.TAG_SPELL)) {
            final Spell aSpell = context.getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, cKey);
            if (aSpell != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSpell;
            }
        } else if (cType.equals(IOConstants.TAG_NAME)) {
            newB = Bonus.newBonus(context, bonus);
        //newB.setCreatorObject(thePC);
        }
        if (newB == null) {
            return;
        }
        TempBonusInfo tempBonusInfo;
        // Check to see if the target was the PC or an Item
        if (tName.equals(IOConstants.TAG_PC)) {
            thePC.setApplied(newB, true);
            tempBonusInfo = thePC.addTempBonus(newB, creator, thePC);
        } else {
            thePC.setApplied(newB, true);
            aEq.addTempBonus(newB);
            tempBonusInfo = thePC.addTempBonus(newB, creator, aEq);
        }
        if (!active) {
            String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
            thePC.setTempBonusFilter(bonusName);
        }
    }
    if (aEq != null) {
        aEq.setAppliedName(cKey);
        thePC.addTempBonusItemList(aEq);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) BonusObj(pcgen.core.bonus.BonusObj) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) Equipment(pcgen.core.Equipment) LoadContext(pcgen.rules.context.LoadContext) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory)

Example 12 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class PCGVer2Creator method appendClassLines.

/*
	 * ###############################################################
	 * Character Class(es) methods
	 * ###############################################################
	 */
private void appendClassLines(StringBuilder buffer) {
    Cache specials = new Cache();
    for (PCClass pcClass : charDisplay.getClassSet()) {
        int classLevel = charDisplay.getLevel(pcClass);
        buffer.append(IOConstants.TAG_CLASS).append(':');
        buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        final String subClassKey = charDisplay.getSubClassName(pcClass);
        if (subClassKey != null && !Constants.EMPTY_STRING.equals(subClassKey)) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SUBCLASS).append(':');
            buffer.append(EntityEncoder.encode(subClassKey));
        }
        buffer.append('|');
        buffer.append(IOConstants.TAG_LEVEL).append(':');
        buffer.append(classLevel);
        buffer.append('|');
        buffer.append(IOConstants.TAG_SKILLPOOL).append(':');
        Integer currentPool = thePC.getSkillPool(pcClass);
        buffer.append(currentPool == null ? 0 : currentPool);
        // determine if this class can cast spells
        boolean isCaster = false;
        if (!thePC.getSpellSupport(pcClass).canCastSpells(thePC)) {
            isCaster = true;
        }
        boolean isPsionic = thePC.getSpellSupport(pcClass).hasKnownList() && !isCaster;
        if (isCaster || isPsionic) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SPELLBASE).append(':');
            buffer.append(EntityEncoder.encode(pcClass.getSpellBaseStat()));
            buffer.append('|');
            buffer.append(IOConstants.TAG_CANCASTPERDAY).append(':');
            buffer.append(StringUtil.join(thePC.getSpellSupport(pcClass).getCastListForLevel(classLevel), ","));
        }
        Collection<? extends SpellProhibitor> prohib = charDisplay.getProhibitedSchools(pcClass);
        if (prohib != null) {
            Set<String> set = new TreeSet<>();
            for (SpellProhibitor sp : prohib) {
                set.addAll(sp.getValueList());
            }
            if (!set.isEmpty()) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_PROHIBITED).append(':');
                buffer.append(EntityEncoder.encode(StringUtil.join(set, ",")));
            }
        }
        appendAddTokenInfo(buffer, pcClass);
        buffer.append(IOConstants.LINE_SEP);
        String spec = thePC.getAssoc(pcClass, AssociationKey.SPECIALTY);
        if (spec != null) {
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + '0', spec);
        }
        String key;
        key = pcClass.getKeyName() + IOConstants.TAG_SAVE + '0';
        List<? extends SpecialAbility> salist = charDisplay.getUserSpecialAbilityList(pcClass);
        if (salist != null && !salist.isEmpty()) {
            SpecialAbility sa = salist.get(0);
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SA + 0, sa.getKeyName());
        }
        for (BonusObj save : thePC.getSaveableBonusList(pcClass)) {
            specials.put(key, "BONUS|" + save);
        }
        for (int i = 1; i <= charDisplay.getLevel(pcClass); i++) {
            key = pcClass.getKeyName() + IOConstants.TAG_SAVE + (i - 1);
            PCClassLevel pcl = charDisplay.getActiveClassLevel(pcClass, i);
            for (BonusObj save : thePC.getSaveableBonusList(pcl)) {
                specials.put(key, "BONUS|" + save);
            }
        }
    }
    //
    for (PCLevelInfo pcl : charDisplay.getLevelInfo()) {
        final String classKeyName = pcl.getClassKeyName();
        int lvl = pcl.getClassLevel() - 1;
        PCClass pcClass = thePC.getClassKeyed(classKeyName);
        buffer.append(IOConstants.TAG_CLASSABILITIESLEVEL).append(':');
        if (pcClass == null) {
            pcClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKeyName);
            if (pcClass != null) {
                pcClass = thePC.getClassKeyed(pcClass.get(ObjectKey.EX_CLASS).get().getKeyName());
            }
        }
        if (pcClass != null) {
            buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        } else {
            //$NON-NLS-1$
            buffer.append(EntityEncoder.encode("???"));
        }
        buffer.append('=').append(lvl + 1);
        if (pcClass != null) {
            String aKey = charDisplay.getSubstitutionClassName(charDisplay.getActiveClassLevel(pcClass, lvl + 1));
            if (aKey != null) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_SUBSTITUTIONLEVEL).append(':');
                buffer.append(aKey);
            }
            buffer.append('|');
            buffer.append(IOConstants.TAG_HITPOINTS).append(':');
            PCClassLevel classLevel = charDisplay.getActiveClassLevel(pcClass, lvl);
            Integer hp = charDisplay.getHP(classLevel);
            buffer.append(hp == null ? 0 : hp);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SAVE + lvl), IOConstants.TAG_SAVES, IOConstants.TAG_SAVE, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + lvl), IOConstants.TAG_SPECIALTIES, IOConstants.TAG_SPECIALTY, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + lvl), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, lvl);
            if (lvl == 0) {
                appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + (lvl - 1)), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, -1);
            }
            //
            // Remember what choices were made for each of the ADD: tags
            //
            appendAddTokenInfo(buffer, charDisplay.getActiveClassLevel(pcClass, lvl + 1));
        }
        List<PCLevelInfoStat> statList = pcl.getModifiedStats(true);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        statList = pcl.getModifiedStats(false);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        int sp = pcl.getSkillPointsGained(thePC);
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSGAINED).append(':').append(sp);
        }
        sp = pcl.getSkillPointsRemaining();
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSREMAINING).append(':').append(sp);
        }
        buffer.append(IOConstants.LINE_SEP);
    }
}
Also used : PCLevelInfoStat(pcgen.core.pclevelinfo.PCLevelInfoStat) BonusObj(pcgen.core.bonus.BonusObj) SpecialAbility(pcgen.core.SpecialAbility) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor) PCClassLevel(pcgen.cdom.inst.PCClassLevel) TreeSet(java.util.TreeSet) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 13 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class PCGVer2Creator method writeAbilityToBuffer.

private void writeAbilityToBuffer(StringBuilder buffer, CNAbility cna) {
    Category<Ability> cat = cna.getAbilityCategory();
    Nature nature = cna.getNature();
    Ability ability = cna.getAbility();
    buffer.append(IOConstants.TAG_ABILITY).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(cat.getKeyName())).append(IOConstants.TAG_SEPARATOR);
    buffer.append(IOConstants.TAG_TYPE).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(nature.toString())).append(IOConstants.TAG_SEPARATOR);
    buffer.append(IOConstants.TAG_CATEGORY).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(ability.getCategory())).append(IOConstants.TAG_SEPARATOR);
    buffer.append(IOConstants.TAG_MAPKEY).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(ability.getKeyName())).append(IOConstants.TAG_SEPARATOR);
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        buffer.append(IOConstants.TAG_APPLIEDTO).append(IOConstants.TAG_END);
        List<String> assocList = thePC.getAssociationList(cna);
        boolean first = true;
        for (String assoc : assocList) {
            if (!first) {
                buffer.append(Constants.COMMA);
            }
            first = false;
            buffer.append(EntityEncoder.encode(assoc));
        }
        buffer.append(IOConstants.TAG_SEPARATOR);
    }
    buffer.append(IOConstants.TAG_TYPE).append(IOConstants.TAG_END);
    buffer.append(EntityEncoder.encode(ability.getType()));
    for (final BonusObj save : thePC.getSaveableBonusList(ability)) {
        buffer.append('|');
        buffer.append(IOConstants.TAG_SAVE).append(':');
        buffer.append(EntityEncoder.encode("BONUS|" + save));
    }
    for (final Description desc : ability.getSafeListFor(ListKey.DESCRIPTION)) {
        buffer.append(Constants.PIPE);
        buffer.append(IOConstants.TAG_DESC).append(':');
        buffer.append(EntityEncoder.encode(desc.getPCCText()));
    }
    buffer.append(IOConstants.LINE_SEP);
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) SpecialAbility(pcgen.core.SpecialAbility) Nature(pcgen.cdom.enumeration.Nature) Description(pcgen.core.Description) BonusObj(pcgen.core.bonus.BonusObj)

Example 14 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class PCGVer2Creator method appendTempBonuses.

private void appendTempBonuses(StringBuilder buffer) {
    final List<String> trackList = new ArrayList<>();
    TreeSet<Map.Entry<BonusObj, BonusManager.TempBonusInfo>> sortedbonus = new TreeSet<>(new Comparator<Map.Entry<BonusObj, BonusManager.TempBonusInfo>>() {

        @Override
        public int compare(Map.Entry<BonusObj, BonusManager.TempBonusInfo> a, Map.Entry<BonusObj, BonusManager.TempBonusInfo> b) {
            BonusObj keyA = a.getKey();
            BonusObj keyB = b.getKey();
            if (!keyA.getBonusName().equals(keyB.getBonusName())) {
                return keyA.getBonusName().compareTo(keyB.getBonusName());
            }
            if (!keyA.getBonusInfo().equals(keyB.getBonusInfo())) {
                return keyA.getBonusInfo().compareTo(keyB.getBonusInfo());
            }
            return keyA.getPCCText().compareTo(keyB.getPCCText());
        }
    });
    sortedbonus.addAll(thePC.getTempBonusMap().entrySet());
    //for (BonusManager.TempBonusInfo tbi : thePC.getTempBonusMap().values())
    for (Map.Entry<BonusObj, BonusManager.TempBonusInfo> me : sortedbonus) {
        BonusObj bonus = me.getKey();
        TempBonusInfo tbi = me.getValue();
        Object creObj = tbi.source;
        Object tarObj = tbi.target;
        final String outString = tempBonusName(creObj, tarObj);
        if (trackList.contains(outString)) {
            continue;
        }
        trackList.add(outString);
        buffer.append(outString);
        String bonusName = BonusDisplay.getBonusDisplayName(tbi);
        if (thePC.getTempBonusFilters().contains(bonusName)) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_TEMPBONUSACTIVE).append(":N");
        }
        /*
			 * Why do we loop through the bonuses again? It is looped through
			 * again so that only items associated with this source (e.g.
			 * Template and Target object) are written, but that ALL of the
			 * items are written on one line.
			 */
        for (Map.Entry<BonusObj, BonusManager.TempBonusInfo> subme : sortedbonus) {
            BonusObj subBonus = subme.getKey();
            TempBonusInfo subtbi = subme.getValue();
            Object cObj = subtbi.source;
            Object tObj = subtbi.target;
            final String inString = tempBonusName(cObj, tObj);
            if (inString.equals(outString)) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_TEMPBONUSBONUS).append(':');
                buffer.append(EntityEncoder.encode(subBonus.getPCCText()));
            }
        }
        buffer.append(IOConstants.LINE_SEP);
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) ChronicleEntry(pcgen.core.ChronicleEntry) TreeSet(java.util.TreeSet) BonusManager(pcgen.core.BonusManager) CDOMListObject(pcgen.cdom.base.CDOMListObject) CDOMObject(pcgen.cdom.base.CDOMObject) Map(java.util.Map)

Example 15 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class PCGVer2Parser method parseEquipSetTempBonusLine.

/**
	 * ###############################################################
	 * EquipSet Temp Bonuses
	 * ###############################################################
	 * @param line
	 **/
private void parseEquipSetTempBonusLine(final String line) {
    PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalEquipSetTempBonus", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    String tag;
    String tagString = null;
    for (PCGElement element : tokens.getElements()) {
        tag = element.getName();
        if (IOConstants.TAG_EQSETBONUS.equals(tag)) {
            tagString = EntityEncoder.decode(element.getText());
        }
    }
    if (tagString == null) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.InvalidEquipSetTempBonus", line);
        warnings.add(msg);
        return;
    }
    final EquipSet eSet = thePC.getEquipSetByIdPath(tagString);
    if (eSet == null) {
        return;
    }
    //# EquipSet Temp Bonuses
    //EQSETBONUS:0.2|TEMPBONUS:NAME=Haste|TBTARGET:PC|TEMPBONUS:SPELL=Shield of Faith|TBTARGET:PC
    final Map<BonusObj, BonusManager.TempBonusInfo> aList = new IdentityHashMap<>();
    for (final PCGElement element : tokens.getElements()) {
        tag = element.getName();
        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            final String aString = EntityEncoder.decode(element.getText());
            // Parse aString looking for
            // TEMPBONUS and TBTARGET pairs
            StringTokenizer aTok = new StringTokenizer(aString, IOConstants.TAG_SEPARATOR);
            if (aTok.countTokens() < 2) {
                continue;
            }
            String sName = aTok.nextToken();
            String tName = aTok.nextToken();
            aList.putAll(getBonusFromName(sName, tName));
        }
    }
    eSet.setTempBonusList(aList);
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) BonusObj(pcgen.core.bonus.BonusObj) EquipSet(pcgen.core.character.EquipSet) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

BonusObj (pcgen.core.bonus.BonusObj)126 LoadContext (pcgen.rules.context.LoadContext)48 PlayerCharacter (pcgen.core.PlayerCharacter)29 ArrayList (java.util.ArrayList)22 CDOMObject (pcgen.cdom.base.CDOMObject)18 PCClass (pcgen.core.PCClass)14 Prerequisite (pcgen.core.prereq.Prerequisite)13 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)13 EquipSet (pcgen.core.character.EquipSet)11 IdentityHashMap (java.util.IdentityHashMap)10 Map (java.util.Map)10 TreeSet (java.util.TreeSet)10 Ability (pcgen.core.Ability)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 TempBonusInfo (pcgen.core.BonusManager.TempBonusInfo)8 Equipment (pcgen.core.Equipment)8 HashMap (java.util.HashMap)7 Race (pcgen.core.Race)7 StringTokenizer (java.util.StringTokenizer)6 CNAbility (pcgen.cdom.content.CNAbility)6