Search in sources :

Example 1 with Follower

use of pcgen.core.character.Follower in project pcgen by PCGen.

the class CompanionSupportFacadeImpl method removeCompanion.

@Override
public void removeCompanion(CompanionFacade companion) {
    if (!(companion instanceof CompanionFacadeDelegate)) {
        return;
    }
    File compFile = companion.getFileRef().get();
    for (Follower follower : charDisplay.getFollowerList()) {
        File followerFile = new File(follower.getFileName());
        if (followerFile.equals(compFile)) {
            theCharacter.delFollower(follower);
            break;
        }
    }
    companionList.removeElement((CompanionFacadeDelegate) companion);
    updateCompanionTodo(companion.getCompanionType());
}
Also used : Follower(pcgen.core.character.Follower) File(java.io.File)

Example 2 with Follower

use of pcgen.core.character.Follower in project pcgen by PCGen.

the class CompanionSupportFacadeImpl method initCompData.

/**
	 * Initialisation of the character's companion data.
	 * @param rebuildCompanionList Should the list of the character;s companions be rebuilt?
	 */
private void initCompData(boolean rebuildCompanionList) {
    List<CompanionStub> companions = new ArrayList<>();
    for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
        keyToCompanionListMap.put(compList.getKeyName(), compList);
        Map<FollowerOption, CDOMObject> fMap = charDisplay.getAvailableFollowers(compList.getKeyName(), null);
        for (FollowerOption followerOpt : fMap.keySet()) {
            if (followerOpt.getRace() != Globals.s_EMPTYRACE && followerOpt.qualifies(theCharacter, null)) {
                companions.add(new CompanionStub(followerOpt.getRace(), compList.getKeyName()));
            }
        }
        int maxVal = theCharacter.getMaxFollowers(compList);
        if (maxVal == 0) {
            maxCompanionsMap.removeKey(compList.toString());
        } else {
            maxCompanionsMap.putValue(compList.toString(), maxVal);
        }
    }
    availCompList.updateContents(companions);
    if (rebuildCompanionList) {
        for (Follower follower : charDisplay.getFollowerList()) {
            CompanionFacade comp = new CompanionNotLoaded(follower.getName(), new File(follower.getFileName()), follower.getRace(), follower.getType().toString());
            CompanionFacadeDelegate delegate = new CompanionFacadeDelegate();
            delegate.setCompanionFacade(comp);
            companionList.addElement(delegate);
        }
    }
    //Logging.debugPrint("Companion list " + companionList);
    for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
        updateCompanionTodo(compList.toString());
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) ArrayList(java.util.ArrayList) Follower(pcgen.core.character.Follower) CompanionFacade(pcgen.facade.core.CompanionFacade) CDOMObject(pcgen.cdom.base.CDOMObject) File(java.io.File)

Example 3 with Follower

use of pcgen.core.character.Follower in project pcgen by PCGen.

the class PCGVer2Parser method parseFollowerLine.

/*
	 * ###############################################################
	 * Character Follower methods
	 * ###############################################################
	 */
private void parseFollowerLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Warnings.PCGenParser.IllegalFollower", line, pcgpex.getMessage());
        warnings.add(msg);
        return;
    }
    final Follower aFollower = new Follower(Constants.EMPTY_STRING, Constants.EMPTY_STRING, null);
    for (final PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_FOLLOWER.equals(tag)) {
            aFollower.setName(EntityEncoder.decode(element.getText()));
        } else if (IOConstants.TAG_TYPE.equals(tag)) {
            String cType = EntityEncoder.decode(element.getText());
            CompanionList cList = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(CompanionList.class, cType);
            if (cList == null) {
                Logging.errorPrint("Cannot find CompanionList: " + cType);
            } else {
                aFollower.setType(cList);
            }
        } else if (IOConstants.TAG_RACE.equals(tag)) {
            String raceText = EntityEncoder.decode(element.getText());
            Race r = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, raceText);
            if (r == null) {
                Logging.errorPrint("Cannot find Race: " + raceText);
            } else {
                aFollower.setRace(r);
            }
        } else if (IOConstants.TAG_HITDICE.equals(tag)) {
            try {
                aFollower.setUsedHD(Integer.parseInt(element.getText()));
            } catch (NumberFormatException nfe) {
            // nothing we can do about it
            }
        } else if (IOConstants.TAG_FILE.equals(tag)) {
            String inputFileName = EntityEncoder.decode(element.getText());
            String masterFileName = makeFilenameAbsolute(inputFileName);
            if (masterFileName == null) {
                final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                "Warnings.PCGenParser.CantFindFollower", inputFileName);
                warnings.add(msg);
            } else {
                aFollower.setFileName(masterFileName);
            }
        }
    }
    if (!Constants.EMPTY_STRING.equals(aFollower.getFileName()) && !Constants.EMPTY_STRING.equals(aFollower.getName()) && aFollower.getType() != null && !Constants.EMPTY_STRING.equals(aFollower.getType().toString())) {
        thePC.addFollower(aFollower);
    }
}
Also used : CompanionList(pcgen.cdom.list.CompanionList) Race(pcgen.core.Race) Follower(pcgen.core.character.Follower)

Example 4 with Follower

use of pcgen.core.character.Follower in project pcgen by PCGen.

the class CharacterFacadeImpl method getMaster.

@Override
public CharacterStubFacade getMaster() {
    Follower master = charDisplay.getMaster();
    if (master == null) {
        return null;
    }
    CompanionNotLoaded stub = new CompanionNotLoaded(master.getName(), new File(master.getFileName()), master.getRace(), master.getType().getKeyName());
    CharacterFacade masterFacade = CharacterManager.getCharacterMatching(stub);
    if (masterFacade != null) {
        return masterFacade;
    }
    return stub;
}
Also used : Follower(pcgen.core.character.Follower) File(java.io.File) CharacterFacade(pcgen.facade.core.CharacterFacade)

Example 5 with Follower

use of pcgen.core.character.Follower in project pcgen by PCGen.

the class FollowerToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    /* FOLLOWER%.subtag stuff handled in here*/
    // New token syntax FOLLOWER.x instead of FOLLOWERx
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    // FOLLOWER
    String fString = aTok.nextToken();
    final int i;
    if ("FOLLOWER".equals(fString)) {
        i = Integer.parseInt(aTok.nextToken());
    } else {
        Logging.errorPrint("Old syntax FOLLOWERx will be replaced for FOLLOWER.x");
        i = Integer.parseInt(tokenSource.substring(8, tokenSource.indexOf('.')));
    }
    StringBuilder restString = new StringBuilder();
    while (aTok.hasMoreTokens()) {
        restString.append(".").append(aTok.nextToken());
    }
    if (restString.indexOf(".") == 0) {
        restString = restString.deleteCharAt(0);
    }
    String result = "";
    final List<Follower> followers = new ArrayList<>(pc.getDisplay().getFollowerList());
    if (i < followers.size()) {
        result = FollowerToken.getFollowerOutput(eh, restString.toString(), followers.get(i));
    }
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) Follower(pcgen.core.character.Follower)

Aggregations

Follower (pcgen.core.character.Follower)16 File (java.io.File)6 CompanionList (pcgen.cdom.list.CompanionList)6 PlayerCharacter (pcgen.core.PlayerCharacter)4 ArrayList (java.util.ArrayList)3 StringTokenizer (java.util.StringTokenizer)3 FollowerOption (pcgen.core.FollowerOption)3 CharacterDisplay (pcgen.core.display.CharacterDisplay)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 Race (pcgen.core.Race)2 Test (org.junit.Test)1 SourcedEquipmentFacet (pcgen.cdom.facet.SourcedEquipmentFacet)1 AbstractStorageFacet (pcgen.cdom.facet.base.AbstractStorageFacet)1 Equipment (pcgen.core.Equipment)1 PCClass (pcgen.core.PCClass)1 PCTemplate (pcgen.core.PCTemplate)1 CompanionMod (pcgen.core.character.CompanionMod)1 EquipSet (pcgen.core.character.EquipSet)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1 CharacterFacade (pcgen.facade.core.CharacterFacade)1