use of pcgen.core.character.CompanionMod in project pcgen by PCGen.
the class TypeToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CompanionMod mod, String value) {
//TODO Check for "." and warn?
Type type = Type.getConstant(value);
context.getObjectContext().addToList(mod, ListKey.TYPE, type);
final Category<CompanionMod> cat = context.getReferenceContext().constructNowIfNecessary(COMPANIONLIST_CLASS, value);
if (cat == null) {
return new ParseResult.Fail("Cannot find Companion List: " + value, context);
}
context.getReferenceContext().reassociateCategory(cat, mod);
return ParseResult.SUCCESS;
}
use of pcgen.core.character.CompanionMod in project pcgen by PCGen.
the class AbstractContentTokenTest method testFromCompanionMod.
@Test
public void testFromCompanionMod() throws PersistenceLayerException {
CompanionMod source = create(CompanionMod.class, "Source");
processToken(source);
assertEquals(baseCount(), targetFacetCount());
companionModFacet.add(id, source);
assertTrue(containsExpected());
assertEquals(baseCount() + 1, targetFacetCount());
companionModFacet.remove(id, source);
assertEquals(baseCount(), targetFacetCount());
}
use of pcgen.core.character.CompanionMod 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);
}
use of pcgen.core.character.CompanionMod in project pcgen by PCGen.
the class PlayerCharacter method setCalcFollowerBonus.
/**
* Apply the bonus from a follower to the master pc.
*/
public void setCalcFollowerBonus() {
setDirty(true);
for (Follower aF : getFollowerList()) {
final CompanionList cList = aF.getType();
final String rType = cList.getKeyName();
final Race fRace = aF.getRace();
for (CompanionMod cm : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, cList).getAllObjects()) {
final String aType = cm.getType();
if (aType.equalsIgnoreCase(rType) && cm.appliesToRace(fRace)) {
// Found race and type of follower
// so add bonus to the master
companionModFacet.add(id, cm);
}
}
}
}
use of pcgen.core.character.CompanionMod in project pcgen by PCGen.
the class CompanionModFacetTest method getObject.
@Override
protected CompanionMod getObject() {
CompanionMod t = new CompanionMod();
t.put(IntegerKey.LEVEL, n);
t.setName("CompanionMod" + n++);
return t;
}
Aggregations