Search in sources :

Example 6 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 7 with Follower

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

the class FollowerOfToken method getFollowerOfToken.

/**
	 * Get FOLLOWEROF Token
	 *
	 * @param pc
	 * @return Token
	 */
public static String getFollowerOfToken(PlayerCharacter pc) {
    String retString = "";
    PlayerCharacter masterPC = pc.getMasterPC();
    if (masterPC != null) {
        CharacterDisplay masterDisplay = masterPC.getDisplay();
        for (Follower aFollower : masterDisplay.getFollowerList()) {
            if (aFollower.getFileName().equals(pc.getDisplay().getFileName())) {
                retString = aFollower.getType() + " of " + masterDisplay.getName();
            }
        }
    }
    return retString;
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CharacterDisplay(pcgen.core.display.CharacterDisplay) Follower(pcgen.core.character.Follower)

Example 8 with Follower

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

the class CompanionSupportFacadeImplTest method testAddCompanion.

/**
	 * Test method for {@link pcgen.gui2.facade.CompanionSupportFacadeImpl#addCompanion(pcgen.core.facade.CharacterFacade, java.lang.String)}.
	 */
@Test
public void testAddCompanion() {
    PlayerCharacter master = getCharacter();
    master.setRace(masterRace);
    master.setFileName("Master.pcg");
    master.setName("Master1");
    CompanionSupportFacadeImpl masterCsfi = new CompanionSupportFacadeImpl(master, todoManager, new DefaultReferenceFacade<>(), new DefaultReferenceFacade<>(), new CharacterFacadeImpl(master, uiDelegate, dataSetFacade));
    PlayerCharacter companion = new PlayerCharacter();
    companion.setRace(companionRace);
    companion.setFileName("Companion.pcg");
    companion.setName("Companion1");
    CharacterFacadeImpl compFacade = new CharacterFacadeImpl(companion, uiDelegate, dataSetFacade);
    assertNull("No companion type should be set yet.", compFacade.getCompanionType());
    assertTrue("Master should have no companions", master.getFollowerList().isEmpty());
    masterCsfi.addCompanion(compFacade, "Familiar");
    Follower follower = master.getFollowerList().iterator().next();
    assertEquals("Companion should be the first follower", companion.getName(), follower.getName());
    assertEquals("Master should have one companion", 1, master.getFollowerList().size());
    assertNotNull("Companion should have a master now", companion.getDisplay().getMaster());
    assertEquals("Companion's master", master.getName(), companion.getDisplay().getMaster().getName());
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Follower(pcgen.core.character.Follower) Test(org.junit.Test)

Example 9 with Follower

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

the class ExportHandler method dealWithFilteredTokens.

/**
	 * Helper method for replaceToken, deals with the filter tokens e.g. %DOMAIN, basically 
	 * returns 0 if we should not be writing something out, e.g. It's filtered out
	 * 
	 * @param aString
	 * @param aPC
	 * @return 0 If we should not be writing something out 
	 */
private int dealWithFilteredTokens(String aString, PlayerCharacter aPC) {
    // Start by stating that we are allowed to write
    canWrite = true;
    // Get the merge strategy for equipment for later use
    int merge = getEquipmentMergingStrategy(aString);
    // Filter out on GAMEMODE
    if (aString.substring(1).startsWith("GAMEMODE:")) {
        if (aString.substring(10).endsWith(GameModeToken.getGameModeToken())) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out REGION
    CharacterDisplay display = aPC.getDisplay();
    if ("REGION".equals(aString.substring(1))) {
        if (display.getRegionString().equals(Constants.NONE)) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out NOTES
    if ("NOTES".equals(aString.substring(1))) {
        if (aPC.getDisplay().getNotesCount() <= 0) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out SKILLPOINTS
    if ("SKILLPOINTS".equals(aString.substring(1))) {
        if (SkillpointsToken.getUnusedSkillPoints(aPC) == 0) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out TEMPLATE
    if (aString.substring(1).startsWith("TEMPLATE")) {
        // New token syntax |%TEMPLATE.x| instead of |%TEMPLATEx|
        final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
        final List<PCTemplate> tList = new ArrayList<>(aPC.getTemplateSet());
        String fString = aTok.nextToken();
        final int index;
        if (aTok.hasMoreTokens()) {
            index = Integer.parseInt(aTok.nextToken());
        } else {
            // When removing old syntax, remove the else and leave the if
            if ("TEMPLATE".equals(fString)) {
                if (tList.isEmpty()) {
                    canWrite = false;
                }
                return 0;
            }
            Logging.errorPrint("Old syntax %TEMPLATEx will be replaced for %TEMPLATE.x");
            index = Integer.parseInt(aString.substring(9));
        }
        if (index >= tList.size()) {
            canWrite = false;
            return 0;
        }
        final PCTemplate template = tList.get(index);
        if (!template.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_EXPORT)) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out FOLLOWER
    if ("FOLLOWER".equals(aString.substring(1))) {
        if (!aPC.hasFollowers()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out FOLLOWEROF
    if ("FOLLOWEROF".equals(aString.substring(1))) {
        if (aPC.getMasterPC() == null) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out FOLLOWERTYPE.
    if (aString.substring(1).startsWith("FOLLOWERTYPE.")) {
        List<Follower> aList = new ArrayList<>();
        for (Follower follower : aPC.getFollowerList()) {
            // Otherwise the stats a zero
            for (PlayerCharacter pc : Globals.getPCList()) {
                if (pc.getFileName().equals(follower.getFileName())) {
                    aList.add(follower);
                }
            }
        }
        StringTokenizer aTok = new StringTokenizer(aString, ".");
        // FOLLOWERTYPE
        aTok.nextToken();
        String typeString = aTok.nextToken();
        for (int i = aList.size() - 1; i >= 0; --i) {
            final Follower fol = aList.get(i);
            if (!fol.getType().getKeyName().equalsIgnoreCase(typeString)) {
                aList.remove(i);
            }
        }
        if (aList.isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out PROHIBITEDLIST
    if ("PROHIBITEDLIST".equals(aString.substring(1))) {
        for (PCClass pcClass : aPC.getClassSet()) {
            if (aPC.getLevel(pcClass) > 0) {
                if (pcClass.containsListFor(ListKey.PROHIBITED_SPELLS) || aPC.containsProhibitedSchools(pcClass)) {
                    return 0;
                }
            }
        }
        canWrite = false;
        return 0;
    }
    // Filter out CATCHPHRASE
    if ("CATCHPHRASE".equals(aString.substring(1))) {
        String catchPhrase = display.getCatchPhrase();
        if (catchPhrase.equals(Constants.NONE)) {
            canWrite = false;
        } else if (catchPhrase.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out LOCATION
    if ("LOCATION".equals(aString.substring(1))) {
        String location = display.getLocation();
        if (location.equals(Constants.NONE)) {
            canWrite = false;
        } else if (location.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out RESIDENCE
    if ("RESIDENCE".equals(aString.substring(1))) {
        String residence = aPC.getSafeStringFor(PCStringKey.RESIDENCE);
        if (residence.equals(Constants.NONE)) {
            canWrite = false;
        } else if (residence.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out PHOBIAS
    if ("PHOBIAS".equals(aString.substring(1))) {
        String phobias = display.getSafeStringFor(PCStringKey.PHOBIAS);
        ;
        if (phobias.equals(Constants.NONE)) {
            canWrite = false;
        } else if (phobias.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out INTERESTS
    if ("INTERESTS".equals(aString.substring(1))) {
        String interests = display.getInterests();
        if (interests.equals(Constants.NONE)) {
            canWrite = false;
        } else if (interests.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out SPEECHTENDENCY
    if ("SPEECHTENDENCY".equals(aString.substring(1))) {
        String speechTendency = display.getSpeechTendency();
        if (speechTendency.equals(Constants.NONE)) {
            canWrite = false;
        } else if (speechTendency.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out PERSONALITY1
    if ("PERSONALITY1".equals(aString.substring(1))) {
        String trait1 = display.getTrait1();
        if (trait1.equals(Constants.NONE)) {
            canWrite = false;
        } else if (trait1.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out PERSONALITY2
    if ("PERSONALITY2".equals(aString.substring(1))) {
        String trait2 = display.getTrait2();
        if (trait2.equals(Constants.NONE)) {
            canWrite = false;
        } else if (trait2.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out MISC.FUNDS
    if ("MISC.FUNDS".equals(aString.substring(1))) {
        if (aPC.getSafeStringFor(PCStringKey.ASSETS).equals(Constants.NONE)) {
            canWrite = false;
        } else if ((aPC.getSafeStringFor(PCStringKey.ASSETS)).trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out MISC.COMPANIONS and COMPANIONS
    if ("COMPANIONS".equals(aString.substring(1)) || "MISC.COMPANIONS".equals(aString.substring(1))) {
        if (aPC.getSafeStringFor(PCStringKey.COMPANIONS).equals(Constants.NONE)) {
            canWrite = false;
        } else if (aPC.getSafeStringFor(PCStringKey.COMPANIONS).trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out MISC.MAGIC
    if ("MISC.MAGIC".equals(aString.substring(1))) {
        if (aPC.getSafeStringFor(PCStringKey.MAGIC).equals(Constants.NONE)) {
            canWrite = false;
        } else if (aPC.getSafeStringFor(PCStringKey.MAGIC).trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out DESC
    if ("DESC".equals(aString.substring(1))) {
        String description = display.getSafeStringFor(PCStringKey.DESCRIPTION);
        if (description.equals(Constants.NONE)) {
            canWrite = false;
        } else if (description.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out BIO
    if ("BIO".equals(aString.substring(1))) {
        String bio = display.getBio();
        if (bio.equals(Constants.NONE)) {
            canWrite = false;
        } else if (bio.trim().isEmpty()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out SUBREGION
    if ("SUBREGION".equals(aString.substring(1))) {
        if (display.getSubRegion().equals(Constants.NONE)) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out TEMPBONUS.
    if (aString.substring(1).startsWith("TEMPBONUS.")) {
        StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
        // discard first one
        aTok.nextToken();
        int index = -1;
        if (aTok.hasMoreTokens()) {
            index = Integer.parseInt(aTok.nextToken());
        }
        if (index > aPC.getNamedTempBonusList().size()) {
            canWrite = false;
            return 0;
        }
        if (aPC.getUseTempMods()) {
            canWrite = true;
            return 1;
        }
    }
    // Filter out ARMOR.ITEM
    if (aString.substring(1).startsWith("ARMOR.ITEM")) {
        // New token syntax |%ARMOR.ITEM.x| instead of |%ARMOR.ITEMx|
        final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
        // ARMOR
        aTok.nextToken();
        String fString = aTok.nextToken();
        final Collection<Equipment> aArrayList = new ArrayList<>();
        for (Equipment eq : aPC.getEquipmentListInOutputOrder()) {
            if (eq.altersAC(aPC) && (!eq.isArmor() && !eq.isShield())) {
                aArrayList.add(eq);
            }
        }
        // When removing old syntax, remove the else and leave the if
        final int count;
        if (aTok.hasMoreTokens()) {
            count = Integer.parseInt(aTok.nextToken());
        } else {
            Logging.errorPrint("Old syntax %ARMOR.ITEMx will be replaced for %ARMOR.ITEM.x");
            count = Integer.parseInt(fString.substring(fString.length() - 1));
        }
        if (count > aArrayList.size()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out ARMOR.SHIELD
    if (aString.substring(1).startsWith("ARMOR.SHIELD")) {
        // New token syntax |%ARMOR.SHIELD.x| instead of |%ARMOR.SHIELDx|
        final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
        // ARMOR
        aTok.nextToken();
        String fString = aTok.nextToken();
        final int count;
        final List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("SHIELD", 3);
        // When removing old syntax, remove the else and leave the if
        if (aTok.hasMoreTokens()) {
            count = Integer.parseInt(aTok.nextToken());
        } else {
            Logging.errorPrint("Old syntax %ARMOR.SHIELDx will be replaced for %ARMOR.SHIELD.x");
            count = Integer.parseInt(fString.substring(fString.length() - 1));
        }
        if (count > aArrayList.size()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out ARMOR
    if (aString.substring(1).startsWith("ARMOR")) {
        // New token syntax |%ARMOR.x| instead of |%ARMORx|
        final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
        String fString = aTok.nextToken();
        List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("ARMOR", 3);
        //Get list of shields.  Remove any from list of armor
        //Since shields are included in the armor list they will appear twice and they really shouldn't be in the list of armor
        List<Equipment> shieldList = aPC.getEquipmentOfTypeInOutputOrder("SHIELD", 3);
        int z = 0;
        while (z < shieldList.size()) {
            aArrayList.remove(shieldList.get(z));
            z++;
        }
        // When removing old syntax, remove the else and leave the if
        final int count;
        if (aTok.hasMoreTokens()) {
            count = Integer.parseInt(aTok.nextToken());
        } else {
            Logging.errorPrint("Old syntax %ARMORx will be replaced for %ARMOR.x");
            count = Integer.parseInt(fString.substring(fString.length() - 1));
        }
        if (count > aArrayList.size()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out WEAPONPROF
    if ("WEAPONPROF".equals(aString.substring(1))) {
        if (!SettingsHandler.getWeaponProfPrintout()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out WEAPON
    if (aString.substring(1).startsWith("WEAPON")) {
        // New token syntax |%WEAPON.x| instead of |%WEAPONx|
        final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
        String fString = aTok.nextToken();
        final List<Equipment> aArrayList = aPC.getExpandedWeapons(merge);
        int count;
        // When removing old syntax, remove the else and leave the if
        if (aTok.hasMoreTokens()) {
            count = Integer.parseInt(aTok.nextToken());
        } else {
            Logging.errorPrint("Old syntax %WEAPONx will be replaced for %WEAPON.x");
            count = Integer.parseInt(fString.substring(fString.length() - 1));
        }
        if (count >= aArrayList.size()) {
            canWrite = false;
        }
        return 0;
    }
    // Filter out DOMAIN
    if (aString.substring(1).startsWith("DOMAIN")) {
        // New token syntax |%DOMAIN.x| instead of |%DOMAINx|
        final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ".");
        String fString = aTok.nextToken();
        final int index;
        // When removing old syntax, remove the else and leave the if
        if (aTok.hasMoreTokens()) {
            index = Integer.parseInt(aTok.nextToken());
        } else {
            Logging.errorPrint("Old syntax %DOMAINx will be replaced for %DOMAIN.x");
            index = Integer.parseInt(fString.substring(6));
        }
        canWrite = (index <= display.getDomainCount());
        return 0;
    }
    // Filter out SPELLLISTBOOK
    if (aString.substring(1).startsWith("SPELLLISTBOOK")) {
        if (SettingsHandler.getPrintSpellsWithPC()) {
            // New token syntax |%SPELLLISTBOOK.x| instead of |%SPELLLISTBOOKx|
            // To remove old syntax, replace i with 15
            int i;
            if (aString.charAt(14) == '.') {
                i = 15;
            } else {
                i = 14;
            }
            return replaceTokenSpellListBook(aString.substring(i), aPC);
        }
        canWrite = false;
        return 0;
    }
    // Filter out VAR.
    if (aString.substring(1).startsWith("VAR.")) {
        replaceTokenVar(aString, aPC);
        return 0;
    }
    // Filter out COUNT[
    if (aString.substring(1).startsWith("COUNT[")) {
        if (getVarValue(aString.substring(1), aPC) > 0) {
            canWrite = true;
            return 1;
        }
        canWrite = false;
        return 0;
    }
    // finally, check for classes
    final StringTokenizer aTok = new StringTokenizer(aString.substring(1), ",", false);
    boolean found = false;
    while (aTok.hasMoreTokens()) {
        String cString = aTok.nextToken();
        StringTokenizer bTok = new StringTokenizer(cString, "=", false);
        String bString = bTok.nextToken();
        int i = 0;
        if (bTok.hasMoreTokens()) {
            i = Integer.parseInt(bTok.nextToken());
        }
        PCClass aClass = aPC.getClassKeyed(bString);
        found = aClass != null;
        if (aClass == null) {
            canWrite = false;
        } else {
            canWrite = (aPC.getLevel(aClass) >= i);
        }
        // Filter out SPELLLISTCLASS			
        if (bString.startsWith("SPELLLISTCLASS")) {
            // To remove old syntax, keep the if and remove the else
            if (bString.charAt(14) == '.') {
                bString = bString.substring(15);
            } else {
                bString = bString.substring(14);
            }
            found = true;
            CDOMObject aObject = aPC.getSpellClassAtIndex(Integer.parseInt(bString));
            canWrite = (aObject != null);
        }
    }
    if (found) {
        inLabel = true;
        return 0;
    }
    canWrite = false;
    inLabel = true;
    Logging.debugPrint("Return 0 (don't write/no replacement) for an undetermined filter token.");
    return 0;
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList) Follower(pcgen.core.character.Follower) PCClass(pcgen.core.PCClass) StringTokenizer(java.util.StringTokenizer) PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) PCTemplate(pcgen.core.PCTemplate)

Example 10 with Follower

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

the class FollowerListToken method getFollowerListToken.

/**
	 * Get FOLLOWERLIST Token
	 *
	 * @param display The character to be queried
	 * @return The list of followers.
	 */
public static String getFollowerListToken(CharacterDisplay display) {
    StringBuilder buf = new StringBuilder();
    boolean needComma = false;
    for (Follower aF : display.getFollowerList()) {
        for (PlayerCharacter nPC : Globals.getPCList()) {
            CharacterDisplay nDisplay = nPC.getDisplay();
            if (aF.getFileName().equals(nDisplay.getFileName())) {
                if (needComma) {
                    buf.append(", ");
                }
                buf.append(FileAccess.filterString(nDisplay.getName()));
                needComma = true;
            }
        }
    }
    return buf.toString();
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CharacterDisplay(pcgen.core.display.CharacterDisplay) 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