Search in sources :

Example 6 with CompanionList

use of pcgen.cdom.list.CompanionList in project pcgen by PCGen.

the class FollowersLst method parseToken.

@Override
public ParseResult parseToken(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 ((value == null) || value.isEmpty()) {
        return new ParseResult.Fail("Argument in " + getTokenName() + " cannot be empty", context);
    }
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String followerType = sep.next();
    if (followerType.isEmpty()) {
        return new ParseResult.Fail("Follower Type in " + getTokenName() + " cannot be empty", context);
    }
    if (!sep.hasNext()) {
        return new ParseResult.Fail(getTokenName() + " has no PIPE character: " + "Must be of the form <follower type>|<formula>", context);
    }
    String followerNumber = sep.next();
    if (sep.hasNext()) {
        return new ParseResult.Fail(getTokenName() + " has too many PIPE characters: " + "Must be of the form <follower type>|<formula", context);
    }
    if (followerNumber.isEmpty()) {
        return new ParseResult.Fail("Follower Count in " + getTokenName() + " cannot be empty", context);
    }
    CDOMSingleRef<CompanionList> cl = context.getReferenceContext().getCDOMReference(CompanionList.class, followerType);
    Formula num = FormulaFactory.getFormulaFor(followerNumber);
    if (!num.isValid()) {
        return new ParseResult.Fail("Number of Followers in " + getTokenName() + " was not valid: " + num.toString(), context);
    }
    context.getObjectContext().addToList(obj, ListKey.FOLLOWERS, new FollowerLimit(cl, num));
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) CompanionList(pcgen.cdom.list.CompanionList) FollowerLimit(pcgen.cdom.helper.FollowerLimit) Ungranted(pcgen.cdom.base.Ungranted)

Example 7 with CompanionList

use of pcgen.cdom.list.CompanionList in project pcgen by PCGen.

the class CompanionListLst method finish.

private void finish(LoadContext context, CDOMObject obj, String companionType, Set<CDOMReference<Race>> races, Integer followerAdjustment, List<Prerequisite> prereqs) {
    context.getReferenceContext().constructIfNecessary(CompanionList.class, companionType);
    CDOMSingleRef<CompanionList> ref = context.getReferenceContext().getCDOMReference(CompanionList.class, companionType);
    for (CDOMReference<Race> race : races) {
        final FollowerOption option = new FollowerOption(race, ref);
        if (prereqs != null && !prereqs.isEmpty()) {
            option.addAllPrerequisites(prereqs);
        }
        if (followerAdjustment != null && followerAdjustment != 0) {
            option.setAdjustment(followerAdjustment.intValue());
        }
        context.getObjectContext().addToList(obj, ListKey.COMPANIONLIST, option);
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) Race(pcgen.core.Race)

Example 8 with CompanionList

use of pcgen.cdom.list.CompanionList 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);
            }
        }
    }
}
Also used : CompanionList(pcgen.cdom.list.CompanionList) Follower(pcgen.core.character.Follower) CompanionMod(pcgen.core.character.CompanionMod)

Example 9 with CompanionList

use of pcgen.cdom.list.CompanionList in project pcgen by PCGen.

the class CompanionSupportFacadeImpl method linkCompanion.

/**
	 * Adds a newly opened character into the existing
	 * companion framework. This character will replace
	 * the dummy CompanionFacade that has the same
	 * file name. This should typically be called
	 * when a character is opened from one of the follower stubs
	 * @param character the character to link
	 */
private void linkCompanion(CharacterFacade character) {
    for (CompanionFacadeDelegate delegate : companionList) {
        File file = delegate.getFileRef().get();
        String name = delegate.getNameRef().get();
        RaceFacade race = delegate.getRaceRef().get();
        if (file.equals(character.getFileRef().get()) && name.equals(character.getNameRef().get()) && (race == null || race.equals(character.getRaceRef().get()))) {
            String companionType = delegate.getCompanionType();
            delegate.setCompanionFacade(character);
            // Note: When creating a companion we leave the linking to the create code.  
            if (character.getMaster() == null && character.getRaceRef().get() != null && !Constants.NONESELECTED.equals(character.getRaceRef().get().getKeyName())) {
                CompanionList compList = keyToCompanionListMap.get(companionType);
                final Follower newMaster = new Follower(charDisplay.getFileName(), charDisplay.getName(), compList);
                FollowerOption followerOpt = getFollowerOpt(compList, (Race) character.getRaceRef().get());
                if (followerOpt != null) {
                    newMaster.setAdjustment(followerOpt.getAdjustment());
                } else {
                    Logging.log(Logging.WARNING, "Failed to find FollowerOption for complist " + compList + " and race " + character.getRaceRef().get());
                }
                ((CharacterFacadeImpl) character).getTheCharacter().setMaster(newMaster);
            }
            return;
        }
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) Follower(pcgen.core.character.Follower) File(java.io.File) RaceFacade(pcgen.facade.core.RaceFacade)

Example 10 with CompanionList

use of pcgen.cdom.list.CompanionList in project pcgen by PCGen.

the class CompanionSupportFacadeImpl method addCompanion.

@Override
public void addCompanion(CharacterFacade companion, String companionType) {
    if (companion == null || !(companion instanceof CharacterFacadeImpl)) {
        return;
    }
    CharacterFacadeImpl compFacadeImpl = (CharacterFacadeImpl) companion;
    CompanionList compList = keyToCompanionListMap.get(companionType);
    Race compRace = (Race) compFacadeImpl.getRaceRef().get();
    FollowerOption followerOpt = getFollowerOpt(compList, compRace);
    if (followerOpt == null) {
        Logging.errorPrint(//$NON-NLS-1$
        "Unable to find follower option for companion " + companion + " of race " + //$NON-NLS-1$
        compRace);
        return;
    }
    if (!followerOpt.qualifies(theCharacter, null)) {
        Logging.errorPrint(//$NON-NLS-1$
        "Not qualified to take companion " + companion + " of race " + //$NON-NLS-1$
        compRace);
        return;
    }
    // Update the companion with the master details
    Logging.log(Logging.INFO, //$NON-NLS-1$
    "Setting master to " + charDisplay.getName() + " for character " + //$NON-NLS-1$
    compFacadeImpl);
    final Follower newMaster = new Follower(charDisplay.getFileName(), charDisplay.getName(), compList);
    newMaster.setAdjustment(followerOpt.getAdjustment());
    compFacadeImpl.getTheCharacter().setMaster(newMaster);
    compFacadeImpl.refreshClassLevelModel();
    compFacadeImpl.postLevellingUpdates();
    // Update the master with the new companion
    File compFile = compFacadeImpl.getFileRef().get();
    String compFilename = StringUtils.isEmpty(compFile.getPath()) ? "" : compFile.getAbsolutePath();
    Follower follower = new Follower(compFilename, compFacadeImpl.getNameRef().get(), compList);
    follower.setRace(compRace);
    theCharacter.addFollower(follower);
    theCharacter.setCalcFollowerBonus();
    theCharacter.calcActiveBonuses();
    pcFacade.postLevellingUpdates();
    CompanionFacadeDelegate delegate = new CompanionFacadeDelegate();
    delegate.setCompanionFacade(companion);
    companionList.addElement(delegate);
    // Watch companion file name and character name to update follower record
    companion.getFileRef().addReferenceListener(new DelegateFileListener(follower));
    companion.getNameRef().addReferenceListener(new DelegateNameListener(follower));
    updateCompanionTodo(companionType);
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) Race(pcgen.core.Race) Follower(pcgen.core.character.Follower) File(java.io.File)

Aggregations

CompanionList (pcgen.cdom.list.CompanionList)12 Follower (pcgen.core.character.Follower)6 FollowerOption (pcgen.core.FollowerOption)5 Race (pcgen.core.Race)4 File (java.io.File)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 FollowerLimit (pcgen.cdom.helper.FollowerLimit)3 IdentityHashMap (java.util.IdentityHashMap)2 Set (java.util.Set)2 WrappedMapSet (pcgen.base.util.WrappedMapSet)2 CDOMDirectSingleRef (pcgen.cdom.reference.CDOMDirectSingleRef)2 CDOMSimpleSingleRef (pcgen.cdom.reference.CDOMSimpleSingleRef)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Formula (pcgen.base.formula.Formula)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 Ungranted (pcgen.cdom.base.Ungranted)1 DataSet (pcgen.core.DataSet)1 CompanionMod (pcgen.core.character.CompanionMod)1