Search in sources :

Example 6 with PObject

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

the class OpposedCheckDialog method initializeLists.

/**
	 *
	 * <p>
	 * Iniitializes the list of skills, and the main data models for the tables,
	 * based on the rolling and available groups.
	 * </p>
	 *
	 * @param rollingGroup   A list comprising the main (rolling) group of combatants
	 * @param availableGroup A list comprising the other combatants
	 */
private void initializeLists(List<InitHolder> rollingGroup, List<InitHolder> availableGroup) {
    skillNames.addAll(Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Skill.class).stream().map(PObject::toString).collect(Collectors.toList()));
    ivjAvailableModel = new OpposedSkillTypeModel(availableGroup);
    ivjRollingSkillModel = new OpposedSkillModel(rollingGroup);
    ivjOpposedSkillModel = new OpposedSkillModel();
}
Also used : OpposedSkillTypeModel(plugin.initiative.OpposedSkillTypeModel) PObject(pcgen.core.PObject) OpposedSkillModel(plugin.initiative.OpposedSkillModel)

Example 7 with PObject

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

the class SpellMemToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter aPC, ExportHandler eh) {
    StringBuilder retValue = new StringBuilder();
    // New Token syntax - SPELLMEM.x instead of SPELLMEMx
    final StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    aTok.nextToken();
    final int classNum;
    classNum = Integer.parseInt(aTok.nextToken());
    final int bookNum = Integer.parseInt(aTok.nextToken());
    final int spellLevel = Integer.parseInt(aTok.nextToken());
    final int spellNumber = Integer.parseInt(aTok.nextToken());
    boolean found = false;
    String aLabel = "NAME";
    if (aTok.hasMoreTokens()) {
        aLabel = aTok.nextToken();
    }
    String altLabel = "";
    if (aTok.hasMoreTokens()) {
        altLabel = aTok.nextToken();
    }
    final PObject aObject = aPC.getSpellClassAtIndex(classNum);
    if ((aObject == null) && eh != null && eh.getExistsOnly() && (classNum != -1)) {
        eh.setNoMoreItems(true);
    }
    String bookName = Globals.getDefaultSpellBook();
    if (bookNum > 0) {
        bookName = aPC.getDisplay().getSpellBookNames().get(bookNum);
    }
    if ((aObject != null) || (classNum == -1)) {
        if (classNum == -1) {
            bookName = Globals.getDefaultSpellBook();
        }
        CharacterSpell selectedCSpell = null;
        if (!"".equals(bookName)) {
            Spell aSpell = null;
            if (classNum == -1) {
                // List of all the character's spells (including SLAs)
                final List<CharacterSpell> charSpellList = new ArrayList<>();
                // For each class
                for (PCClass pcClass : aPC.getDisplay().getClassSet()) {
                    // Get the spells provided by the class
                    List<CharacterSpell> aList = aPC.getCharacterSpells(pcClass, null, bookName, spellLevel);
                    for (CharacterSpell cs : aList) {
                        // Add to the list if they are not there already
                        if (!charSpellList.contains(cs)) {
                            charSpellList.add(cs);
                        }
                    }
                }
                // Sort the list
                Collections.sort(charSpellList);
                // Set cs to the spell asked for
                if (spellNumber < charSpellList.size()) {
                    selectedCSpell = charSpellList.get(spellNumber);
                    aSpell = selectedCSpell.getSpell();
                    found = true;
                }
            } else if (aObject != null) {
                // List of spells provided by this PObject
                final List<CharacterSpell> charSpells = aPC.getCharacterSpells(aObject, null, bookName, spellLevel);
                if (spellNumber < charSpells.size()) {
                    selectedCSpell = charSpells.get(spellNumber);
                    aSpell = selectedCSpell.getSpell();
                    found = true;
                }
            } else if (eh != null && eh.getInLabel() && eh.getCheckBefore()) {
                eh.setCanWrite(false);
            }
            // We never found the requested spell
            if (selectedCSpell == null) {
                if (eh != null && eh.getExistsOnly()) {
                    eh.setNoMoreItems(true);
                }
                return retValue.toString();
            }
            // Get the SpellInfo for the selected spell
            final SpellInfo si = selectedCSpell.getSpellInfoFor(bookName, spellLevel);
            if (found && (aSpell != null) && (si != null)) {
                if ("NAME".equals(aLabel) || "OUTPUTNAME".equals(aLabel)) {
                    retValue.append(OutputNameFormatting.getOutputName(aSpell) + si.toString());
                } else if ("BASENAME".equals(aLabel)) {
                    retValue.append(OutputNameFormatting.getOutputName(aSpell));
                } else if ("APPLIEDNAME".equals(aLabel)) {
                    retValue.append(getAppliedName(si));
                } else if ("PPCOST".equals(aLabel)) {
                    if (si.getActualPPCost() != -1) {
                        retValue.append(si.getActualPPCost());
                    }
                } else if ("TIMES".equals(aLabel)) {
                    if (si.getTimes() == SpellInfo.TIMES_AT_WILL) {
                        retValue.append("At Will");
                    } else {
                        retValue.append(String.valueOf(si.getTimes()));
                    }
                } else if ("TIMEUNIT".equals(aLabel)) {
                    retValue.append(String.valueOf(si.getTimeUnit()));
                } else // if (aSpell != null) can't be null
                {
                    if ("RANGE".equals(aLabel)) {
                        retValue.append(aPC.getSpellRange(selectedCSpell, si));
                    } else if ("CASTERLEVEL".equals(aLabel)) {
                        retValue.append(aPC.getCasterLevelForSpell(selectedCSpell));
                    } else if ("CASTINGTIME".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.CASTTIME));
                    } else if ("COMPONENTS".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.COMPONENTS));
                    } else if ("CONCENTRATION".equals(aLabel)) {
                        if (SettingsHandler.getGame().getSpellBaseConcentration() != "") {
                            int concentration = aPC.getConcentration(aSpell, selectedCSpell, si);
                            retValue.append(Delta.toString(concentration));
                        }
                    } else if ("COST".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(ObjectKey.COST).toString());
                    } else if ("DC".equals(aLabel)) {
                        String SaveInfo = aSpell.getListAsString(ListKey.SAVE_INFO);
                        if (!"".equals(SaveInfo) && !"None".equals(SaveInfo) && !"No".equals(SaveInfo)) {
                            int dc = aPC.getDC(aSpell, selectedCSpell, si);
                            retValue.append(String.valueOf(dc));
                        }
                    } else if ("DURATION".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aSpell.getListAsString(ListKey.DURATION));
                        retValue.append(mString);
                    } else if ("DESC".equals(aLabel) || "EFFECT".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aPC.getDescription(aSpell));
                        retValue.append(mString);
                    } else if ("TARGET".equals(aLabel) || "EFFECTYPE".equals(aLabel)) {
                        String mString = aPC.parseSpellString(selectedCSpell, aSpell.getSafe(StringKey.TARGET_AREA));
                        retValue.append(mString);
                    } else if ("SAVEINFO".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SAVE_INFO));
                    } else if ("SCHOOL".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_SCHOOL));
                    } else if ("SOURCELEVEL".equals(aLabel)) {
                        retValue.append(replaceTokenSpellMemSourceLevel(aSpell, aPC));
                    } else if ("SOURCE".equals(aLabel)) {
                        retValue.append(SourceFormat.getFormattedString(aSpell, Globals.getSourceDisplay(), true));
                    } else if ("SOURCESHORT".equals(aLabel)) {
                        retValue.append(SourceFormat.formatShort(aSpell, 8));
                    } else if ("SOURCEPAGE".equals(aLabel)) {
                        retValue.append(aSpell.get(StringKey.SOURCE_PAGE));
                    } else if ("SOURCEWEB".equals(aLabel)) {
                        String aTemp = aSpell.get(StringKey.SOURCE_WEB);
                        if (aTemp != null && !aTemp.isEmpty()) {
                            retValue.append(aTemp);
                        }
                    } else if ("SOURCELINK".equals(aLabel)) {
                        String aTemp = aSpell.get(StringKey.SOURCE_LINK);
                        if (aTemp != null && !aTemp.isEmpty()) {
                            retValue.append(aTemp);
                        }
                    } else if ("SUBSCHOOL".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL));
                    } else if ("DESCRIPTOR".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR));
                    } else if ("FULLSCHOOL".equals(aLabel)) {
                        String aTemp = aSpell.getListAsString(ListKey.SPELL_SCHOOL);
                        if ((!aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL).isEmpty()) && (!"NONE".equalsIgnoreCase(aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL).trim()))) {
                            aTemp += (" (" + aSpell.getListAsString(ListKey.SPELL_SUBSCHOOL) + ')');
                        }
                        if (!aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR).isEmpty()) {
                            aTemp += (" [" + aSpell.getListAsString(ListKey.SPELL_DESCRIPTOR) + ']');
                        }
                        retValue.append(aTemp);
                    } else if ("SR".equals(aLabel)) {
                        retValue.append(aSpell.getListAsString(ListKey.SPELL_RESISTANCE));
                    } else if ("SRSHORT".equals(aLabel)) {
                        if ("No".equals(aSpell.getListAsString(ListKey.SPELL_RESISTANCE))) {
                            retValue.append('N');
                        } else {
                            retValue.append('Y');
                        }
                    } else if ("CLASS".equals(aLabel)) {
                        retValue.append(OutputNameFormatting.getOutputName(aObject));
                    } else if ("DCSTAT".equals(aLabel)) {
                        if (aObject instanceof PCClass) {
                            PCClass aClass = (PCClass) aObject;
                            retValue.append(aClass.getSpellBaseStat());
                        }
                    } else if ("TYPE".equals(aLabel)) {
                        PCClass aClass = null;
                        if (aObject instanceof PCClass) {
                            aClass = (PCClass) aObject;
                        }
                        if (aClass != null) {
                            retValue.append(aClass.getSpellType());
                        }
                    } else if (aLabel.startsWith("DESCRIPTION")) {
                        final String sString = getItemDescription("SPELL", aSpell.getKeyName(), aPC.getDescription(aSpell), aPC);
                        if (!altLabel.isEmpty()) {
                            retValue.append(sString.replaceAll("\r?\n", altLabel));
                        } else {
                            retValue.append(sString);
                        }
                    } else if (aLabel.startsWith("BONUSSPELL")) {
                        String sString = "*";
                        if (aLabel.length() > 10) {
                            sString = aLabel.substring(10);
                        }
                        retValue.append(getBonusSpellValue(aPC, spellLevel, sString, altLabel, aObject, bookName, selectedCSpell, aSpell));
                    } else if ("XPCOST".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(IntegerKey.XP_COST));
                    } else if ("CT".equals(aLabel)) {
                        retValue.append(aSpell.getSafe(IntegerKey.CASTING_THRESHOLD));
                    }
                }
            } else if (eh != null && eh.getExistsOnly()) {
                eh.setNoMoreItems(true);
            }
        } else if (eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
    }
    return retValue.toString();
}
Also used : ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) StringTokenizer(java.util.StringTokenizer) PObject(pcgen.core.PObject) ArrayList(java.util.ArrayList) HashMapToList(pcgen.base.util.HashMapToList) CDOMList(pcgen.cdom.base.CDOMList) List(java.util.List) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 8 with PObject

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

the class OutputNameFormattingTest method setUp.

/**
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    testObj = new PObject();
    testObj.setName(NAME);
    super.setUp();
}
Also used : PObject(pcgen.core.PObject)

Example 9 with PObject

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

the class EquipmentBuilderFacadeImpl method getSpellChoiceForEqMod.

private boolean getSpellChoiceForEqMod(EquipmentModifier eqMod) {
    String choiceValue = eqMod.getSafe(StringKey.CHOICE_STRING).substring(15);
    SpellBuilderFacadeImpl spellBuilderFI = new SpellBuilderFacadeImpl(choiceValue, character, equip);
    if (!delegate.showCustomSpellDialog(spellBuilderFI)) {
        return false;
    }
    InfoFacade castingClass = spellBuilderFI.getClassRef().get();
    Spell theSpell = (Spell) spellBuilderFI.getSpellRef().get();
    String variant = spellBuilderFI.getVariantRef().get();
    if (variant == null) {
        variant = "";
    }
    String spellType = spellBuilderFI.getSpellTypeRef().get();
    int baseSpellLevel = spellBuilderFI.getSpellLevelRef().get();
    int casterLevel = spellBuilderFI.getCasterLevelRef().get();
    ListFacade<AbilityFacade> metamagicFeatsList = spellBuilderFI.getSelectedMetamagicFeats();
    Object[] metamagicFeats = new Object[metamagicFeatsList.getSize()];
    for (int i = 0; i < metamagicFeats.length; i++) {
        metamagicFeats[i] = metamagicFeatsList.getElementAt(i);
    }
    int charges = getNumCharges(eqMod);
    EquipmentModifier existingEqMod = equip.getEqModifierKeyed(eqMod.getKeyName(), true);
    if (existingEqMod == null) {
        equip.addEqModifier(eqMod, true, character);
    }
    existingEqMod = equip.getEqModifierKeyed(eqMod.getKeyName(), true);
    EqModSpellInfo.setSpellInfo(equip, existingEqMod, (PObject) castingClass, theSpell, variant, spellType, baseSpellLevel, casterLevel, metamagicFeats, charges);
    return true;
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) InfoFacade(pcgen.facade.core.InfoFacade) AbilityFacade(pcgen.facade.core.AbilityFacade) PObject(pcgen.core.PObject) Spell(pcgen.core.spell.Spell)

Example 10 with PObject

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

the class PCCountSpellTimesTermEvaluator method resolve.

@Override
public Float resolve(PlayerCharacter pc) {
    String bookName = (classNum == -1) ? Globals.getDefaultSpellBook() : (bookNum > 0) ? pc.getDisplay().getSpellBookNames().get(bookNum) : Globals.getDefaultSpellBook();
    if (!"".equals(bookName)) {
        List<CharacterSpell> csList = new ArrayList<>();
        if (classNum == -1) {
            csList = new ArrayList<>();
            for (PObject cl : pc.getDisplay().getClassSet()) {
                for (CharacterSpell cs : pc.getCharacterSpells(cl, bookName)) {
                    if (!csList.contains(cs)) {
                        csList.add(cs);
                    }
                }
            }
            Collections.sort(csList);
        } else {
            final PObject pcClass = pc.getSpellClassAtIndex(classNum);
            if (pcClass != null) {
                csList = pc.getCharacterSpells(pcClass, null, bookName, spellLevel);
            }
        }
        boolean found = false;
        SpellInfo si = null;
        if (spellNumber < csList.size()) {
            final CharacterSpell cs = csList.get(spellNumber);
            si = cs.getSpellInfoFor(bookName, spellLevel);
            found = true;
        }
        if (found && (si != null)) {
            return (float) si.getTimes();
        }
    }
    return 0.0f;
}
Also used : PObject(pcgen.core.PObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Aggregations

PObject (pcgen.core.PObject)15 CharacterSpell (pcgen.core.character.CharacterSpell)7 ArrayList (java.util.ArrayList)6 Spell (pcgen.core.spell.Spell)5 PCClass (pcgen.core.PCClass)4 Ability (pcgen.core.Ability)3 Domain (pcgen.core.Domain)3 SpellInfo (pcgen.core.character.SpellInfo)3 StringTokenizer (java.util.StringTokenizer)2 SpellBook (pcgen.core.character.SpellBook)2 InfoFacade (pcgen.facade.core.InfoFacade)2 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 HashMapToList (pcgen.base.util.HashMapToList)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMList (pcgen.cdom.base.CDOMList)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 TransitionChoice (pcgen.cdom.base.TransitionChoice)1 CNAbility (pcgen.cdom.content.CNAbility)1 AvailableSpell (pcgen.cdom.helper.AvailableSpell)1