Search in sources :

Example 6 with FollowerOption

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

the class CompanionListLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<FollowerOption> changes = context.getObjectContext().getListChanges(obj, ListKey.COMPANIONLIST);
    Collection<FollowerOption> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
        context.addWriteMessage(getTokenName() + " does not support .CLEAR");
        return null;
    }
    Collection<FollowerOption> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token (and no global clear, so nothing to do)
        return null;
    }
    TripleKeyMapToList<Set<Prerequisite>, CDOMReference<? extends CDOMList<?>>, Integer, CDOMReference<Race>> m = new TripleKeyMapToList<>();
    for (FollowerOption fo : added) {
        m.addToListFor(new HashSet<>(fo.getPrerequisiteList()), fo.getListRef(), fo.getAdjustment(), fo.getRaceRef());
    }
    Set<String> set = new TreeSet<>();
    StringBuilder sb = new StringBuilder();
    for (Set<Prerequisite> prereqs : m.getKeySet()) {
        String prereqString = null;
        if (prereqs != null && !prereqs.isEmpty()) {
            prereqString = getPrerequisiteString(context, prereqs);
        }
        for (CDOMReference<? extends CDOMList<?>> cl : m.getSecondaryKeySet(prereqs)) {
            for (Integer fa : m.getTertiaryKeySet(prereqs, cl)) {
                sb.setLength(0);
                sb.append(cl.getLSTformat(false));
                sb.append(Constants.PIPE);
                Set<CDOMReference<Race>> raceSet = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
                raceSet.addAll(m.getListFor(prereqs, cl, fa));
                sb.append(ReferenceUtilities.joinLstFormat(raceSet, Constants.COMMA, true));
                if (fa != null && fa != 0) {
                    sb.append(Constants.PIPE);
                    sb.append("FOLLOWERADJUSTMENT:");
                    sb.append(fa);
                }
                if (prereqString != null) {
                    sb.append(Constants.PIPE);
                    sb.append(prereqString);
                }
                set.add(sb.toString());
            }
        }
    }
    return set.toArray(new String[set.size()]);
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) FollowerOption(pcgen.core.FollowerOption) TreeSet(java.util.TreeSet) TripleKeyMapToList(pcgen.base.util.TripleKeyMapToList) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 7 with FollowerOption

use of pcgen.core.FollowerOption 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 8 with FollowerOption

use of pcgen.core.FollowerOption 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)

Example 9 with FollowerOption

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

the class CompanionSupportFacadeImpl method getFollowerOpt.

private FollowerOption getFollowerOpt(CompanionList compList, Race compRace) {
    FollowerOption followerOpt = null;
    Map<FollowerOption, CDOMObject> fMap = charDisplay.getAvailableFollowers(compList.getKeyName(), null);
    for (FollowerOption fOpt : fMap.keySet()) {
        if (compRace == fOpt.getRace()) {
            followerOpt = fOpt;
            break;
        }
    }
    return followerOpt;
}
Also used : FollowerOption(pcgen.core.FollowerOption) CDOMObject(pcgen.cdom.base.CDOMObject)

Example 10 with FollowerOption

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

the class FollowerOptionFacet method dataAdded.

/**
	 * Adds the FollowerOption objects granted by CDOMObjects added to the
	 * Player Character to this FollowerLimitFacet.
	 * 
	 * Triggered when one of the Facets to which FollowerOptionFacet listens
	 * fires a DataFacetChangeEvent to indicate a FollowerOption 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) {
    CDOMObject cdo = dfce.getCDOMObject();
    List<FollowerOption> lists = cdo.getListFor(ListKey.COMPANIONLIST);
    if (lists != null) {
        addAll(dfce.getCharID(), lists, cdo);
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CDOMObject(pcgen.cdom.base.CDOMObject)

Aggregations

FollowerOption (pcgen.core.FollowerOption)10 CompanionList (pcgen.cdom.list.CompanionList)6 CDOMObject (pcgen.cdom.base.CDOMObject)5 Race (pcgen.core.Race)4 File (java.io.File)3 Follower (pcgen.core.character.Follower)3 Set (java.util.Set)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 CaseInsensitiveMap (pcgen.base.util.CaseInsensitiveMap)1 TripleKeyMapToList (pcgen.base.util.TripleKeyMapToList)1 WrappedMapSet (pcgen.base.util.WrappedMapSet)1 CDOMList (pcgen.cdom.base.CDOMList)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 CDOMDirectSingleRef (pcgen.cdom.reference.CDOMDirectSingleRef)1 CDOMSimpleSingleRef (pcgen.cdom.reference.CDOMSimpleSingleRef)1