Search in sources :

Example 1 with ChooseInformation

use of pcgen.cdom.base.ChooseInformation in project pcgen by PCGen.

the class AbilityTargetSelector method applyChoice.

@Override
public void applyChoice(ChooseDriver obj, T choice, PlayerCharacter pc) {
    Ability ab = ability.get();
    ChooseInformation ci = ab.get(ObjectKey.CHOOSE_INFO);
    detailedApply(obj, ci, choice, pc);
}
Also used : Ability(pcgen.core.Ability) ChooseInformation(pcgen.cdom.base.ChooseInformation)

Example 2 with ChooseInformation

use of pcgen.cdom.base.ChooseInformation in project pcgen by PCGen.

the class PlayerCharacter method setMaster.

/**
	 * Set the master for this object also set the level dependent stats based
	 * on the masters level and info contained in the companionModList Array
	 * such as HitDie, SR, BONUS, SA, etc.
	 *
	 * @param aM
	 *            The master to be set.
	 */
public void setMaster(final Follower aM) {
    masterFacet.set(id, aM);
    final PlayerCharacter mPC = getMasterPC();
    if (mPC == null) {
        return;
    }
    // make sure masters Name and fileName are correct
    if (!aM.getFileName().equals(mPC.getFileName())) {
        aM.setFileName(mPC.getFileName());
        setDirty(true);
    }
    if (!aM.getName().equals(mPC.getName())) {
        aM.setName(mPC.getName());
        setDirty(true);
    }
    // Get total wizard + sorcerer levels as they stack like a mother
    int mTotalLevel = 0;
    int addHD = 0;
    for (PCClass mClass : mPC.getClassSet()) {
        boolean found = false;
        for (CompanionMod cMod : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, aM.getType()).getAllObjects()) {
            if ((cMod.getLevelApplied(mClass) > 0) && !found) {
                mTotalLevel += getLevel(mClass);
                found = true;
            }
        }
    }
    List<CompanionMod> newCompanionMods = new ArrayList<>();
    // Clear the companionModList so we can add everything to it
    Collection<CompanionMod> oldCompanionMods = companionModFacet.removeAll(id);
    for (CompanionMod cMod : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, aM.getType()).getAllObjects()) {
        // Check all the masters classes
        for (PCClass mClass : mPC.getClassSet()) {
            final int mLev = mPC.getLevel(mClass) + aM.getAdjustment();
            final int compLev = cMod.getLevelApplied(mClass);
            if (compLev < 0) {
                continue;
            }
            // and for the correct level or lower
            if ((compLev <= mLev) || (compLev <= mTotalLevel)) {
                if (cMod.qualifies(this, cMod)) {
                    if (!oldCompanionMods.contains(cMod)) {
                        newCompanionMods.add(cMod);
                    }
                    companionModFacet.add(id, cMod);
                    addHD += cMod.getSafe(IntegerKey.HIT_DIE);
                }
            }
        }
        Map<String, Integer> varmap = cMod.getMapFor(MapKey.APPLIED_VARIABLE);
        for (String varName : varmap.keySet()) {
            final int mLev = mPC.getVariableValue(varName, Constants.EMPTY_STRING).intValue() + aM.getAdjustment();
            if (mLev >= cMod.getVariableApplied(varName)) {
                if (cMod.qualifies(this, cMod)) {
                    if (!oldCompanionMods.contains(cMod)) {
                        newCompanionMods.add(cMod);
                    }
                    companionModFacet.add(id, cMod);
                    addHD += cMod.getSafe(IntegerKey.HIT_DIE);
                }
            }
        }
    }
    // Add additional HD if required
    LevelCommandFactory lcf = getRace().get(ObjectKey.MONSTER_CLASS);
    final int usedHD = aM.getUsedHD();
    addHD -= usedHD;
    // if ((newClass != null) && (addHD != 0))
    if ((lcf != null) && (addHD != 0)) {
        // set the new HD (but only do it once!)
        incrementClassLevel(addHD, lcf.getPCClass(), true);
        aM.setUsedHD(addHD + usedHD);
        setDirty(true);
    }
    // If it's a familiar, we need to change it's Skills
    if (masterFacet.getUseMasterSkill(id)) {
        final Collection<Skill> mList = mPC.getSkillSet();
        final List<Skill> sKeyList = new ArrayList<>();
        // take the higher rank of each skill for the Familiar
        for (Skill fSkill : getSkillSet()) {
            for (Skill mSkill : mList) {
                // already has ranks in the skill
                if (mSkill.equals(fSkill)) {
                    // need higher rank of the two
                    Float totalMasterRank = SkillRankControl.getTotalRank(mPC, mSkill);
                    if (totalMasterRank.intValue() > this.getRank(fSkill).intValue()) {
                        // first zero current
                        SkillRankControl.setZeroRanks(lcf == null ? null : lcf.getPCClass(), this, fSkill);
                        // We don't pass in a class here so that the real
                        // skills can be distinguished from the ones from
                        // the master.
                        SkillRankControl.modRanks(totalMasterRank.doubleValue(), null, true, this, fSkill);
                    }
                }
                // Possesses, but the familiar does not
                if (!hasSkill(mSkill) && !sKeyList.contains(mSkill)) {
                    sKeyList.add(mSkill);
                }
            }
        }
        // now add all the skills only the master has
        for (Skill newSkill : sKeyList) {
            // familiar doesn't have skill,
            // but master does, so add it
            final double sr = SkillRankControl.getTotalRank(mPC, newSkill).doubleValue();
            // We don't pass in a class here so that the real skills can be
            // distinguished from the ones form the master.
            SkillRankControl.modRanks(sr, null, true, this, newSkill);
            if (ChooseActivation.hasNewChooseToken(newSkill)) {
                //TODO a bit reckless :P
                ChooseInformation<Language> chooseInfo = (ChooseInformation<Language>) newSkill.get(ObjectKey.CHOOSE_INFO);
                List<? extends Language> selected = chooseInfo.getChoiceActor().getCurrentlySelected(newSkill, mPC);
                ChoiceManagerList<Language> controller = ChooserUtilities.getConfiguredController(newSkill, this, null, new ArrayList<>());
                for (Language lang : selected) {
                    if (!controller.conditionallyApply(this, lang)) {
                        Logging.errorPrint("Failed to add master's language " + lang + " to companion.");
                    }
                }
            }
        }
    }
    oldCompanionMods.removeAll(companionModFacet.getSet(id));
    for (CompanionMod cMod : oldCompanionMods) {
        CDOMObjectUtilities.removeAdds(cMod, this);
        CDOMObjectUtilities.restoreRemovals(cMod, this);
    }
    for (CompanionMod cMod : newCompanionMods) {
        CDOMObjectUtilities.addAdds(cMod, this);
        CDOMObjectUtilities.checkRemovals(cMod, this);
        for (CDOMReference<PCTemplate> ref : cMod.getSafeListFor(ListKey.TEMPLATE)) {
            for (PCTemplate pct : ref.getContainedObjects()) {
                addTemplate(pct);
            }
        }
        for (CDOMReference<PCTemplate> ref : cMod.getSafeListFor(ListKey.REMOVE_TEMPLATES)) {
            for (PCTemplate pct : ref.getContainedObjects()) {
                removeTemplate(pct);
            }
        }
        for (TransitionChoice<Kit> kit : cMod.getSafeListFor(ListKey.KIT_CHOICE)) {
            kit.act(kit.driveChoice(this), cMod, this);
        }
    }
    calcActiveBonuses();
    setDirty(true);
}
Also used : ChooseInformation(pcgen.cdom.base.ChooseInformation) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) ArrayList(java.util.ArrayList) CompanionMod(pcgen.core.character.CompanionMod)

Example 3 with ChooseInformation

use of pcgen.cdom.base.ChooseInformation in project pcgen by PCGen.

the class AbilityTargetSelector method removeChoice.

@Override
public void removeChoice(ChooseDriver obj, T choice, PlayerCharacter pc) {
    Ability ab = ability.get();
    ChooseInformation ci = ab.get(ObjectKey.CHOOSE_INFO);
    detailedRemove(obj, ci, choice, pc);
}
Also used : Ability(pcgen.core.Ability) ChooseInformation(pcgen.cdom.base.ChooseInformation)

Example 4 with ChooseInformation

use of pcgen.cdom.base.ChooseInformation in project pcgen by PCGen.

the class LanguageChooserFacadeImpl method buildBonusLangList.

/**
	 * Build up the language lists for a choice of racial bonus languages.
	 */
private void buildBonusLangList() {
    CNAbility cna = theCharacter.getBonusLanguageAbility();
    Ability a = cna.getAbility();
    List<Language> availLangs = new ArrayList<>();
    ChooseInformation<Language> chooseInfo = (ChooseInformation<Language>) a.get(ObjectKey.CHOOSE_INFO);
    availLangs.addAll(chooseInfo.getSet(theCharacter));
    List<? extends Language> selLangs = chooseInfo.getChoiceActor().getCurrentlySelected(cna, theCharacter);
    if (selLangs == null) {
        selLangs = Collections.emptyList();
    }
    availLangs.removeAll(charDisplay.getLanguageSet());
    refreshLangListContents(availLangs, availableList);
    refreshLangListContents(selLangs, selectedList);
    refreshLangListContents(selLangs, originalSelectedList);
    boolean allowBonusLangAfterFirst = Globals.checkRule(RuleConstants.INTBONUSLANG);
    boolean atFirstLvl = theCharacter.getTotalLevels() <= 1;
    if (allowBonusLangAfterFirst || atFirstLvl) {
        int bonusLangMax = theCharacter.getBonusLanguageCount();
        numSelectionsRemain.set(bonusLangMax - selLangs.size());
    } else {
        numSelectionsRemain.set(0);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ChooseInformation(pcgen.cdom.base.ChooseInformation) Language(pcgen.core.Language) ArrayList(java.util.ArrayList)

Aggregations

ChooseInformation (pcgen.cdom.base.ChooseInformation)4 Ability (pcgen.core.Ability)3 ArrayList (java.util.ArrayList)2 CNAbility (pcgen.cdom.content.CNAbility)1 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)1 Language (pcgen.core.Language)1 CompanionMod (pcgen.core.character.CompanionMod)1