Search in sources :

Example 6 with Skill

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

the class SkillListToCostFacet method dataAdded.

@Override
public void dataAdded(ScopeFacetChangeEvent<CharID, PCClass, ClassSkillList> dfce) {
    CharID id = dfce.getCharID();
    ClassSkillList skilllist = dfce.getCDOMObject();
    Collection<Skill> set = masterSkillFacet.getSet(id.getDatasetID(), skilllist);
    if (set != null) {
        PCClass pcc = dfce.getScope();
        for (Skill s : set) {
            add(id, pcc, SkillCost.CLASS, s, skilllist);
        }
    }
}
Also used : Skill(pcgen.core.Skill) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 7 with Skill

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

the class PCGVer2Parser method parseTempBonusLine.

/**
	 * ###############################################################
	 * Temporary Bonuses
	 * ###############################################################
	 * @param line
	 **/
private void parseTempBonusLine(final String line) {
    PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal TempBonus line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    String cTag = null;
    String tName = null;
    boolean active = true;
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_TEMPBONUS.equals(tag)) {
            cTag = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSTARGET.equals(tag)) {
            tName = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSACTIVE.equals(tag)) {
            active = element.getText().endsWith(IOConstants.VALUE_Y);
        }
    }
    if ((cTag == null) || (tName == null)) {
        warnings.add("Illegal TempBonus line ignored: " + line);
        return;
    }
    //$NON-NLS-1$
    final StringTokenizer aTok = new StringTokenizer(cTag, "=", false);
    if (aTok.countTokens() < 2) {
        return;
    }
    final String cType = aTok.nextToken();
    final String cKey = aTok.nextToken();
    Equipment aEq = null;
    if (!tName.equals(IOConstants.TAG_PC)) {
        // bonus is applied to an equipment item
        // so create a new one and add to PC
        final Equipment eq = thePC.getEquipmentNamed(tName);
        if (eq == null) {
            return;
        }
        aEq = eq.clone();
        //aEq.setWeight("0");
        aEq.resetTempBonusList();
    }
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        final String bonus;
        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            bonus = EntityEncoder.decode(element.getText());
        } else {
            continue;
        }
        if ((bonus == null) || (bonus.length() <= 0)) {
            continue;
        }
        BonusObj newB = null;
        Object creator = null;
        LoadContext context = Globals.getContext();
        // type of object to set as the creator
        if (cType.equals(IOConstants.TAG_FEAT)) {
            for (AbilityCategory aCat : SettingsHandler.getGame().getAllAbilityCategories()) {
                Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, aCat, cKey);
                if (a != null) {
                    newB = Bonus.newBonus(context, bonus);
                    creator = a;
                    break;
                }
            }
        } else if (cType.equals(IOConstants.TAG_EQUIPMENT)) {
            Equipment aEquip = thePC.getEquipmentNamed(cKey);
            if (aEquip == null) {
                aEquip = context.getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, cKey);
            }
            if (aEquip != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aEquip;
            }
        } else if (cType.equals(IOConstants.TAG_CLASS)) {
            final PCClass aClass = thePC.getClassKeyed(cKey);
            if (aClass == null) {
                continue;
            }
            int idx = bonus.indexOf('|');
            newB = Bonus.newBonus(context, bonus.substring(idx + 1));
            creator = aClass;
        } else if (cType.equals(IOConstants.TAG_TEMPLATE)) {
            PCTemplate aTemplate = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, cKey);
            if (aTemplate != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aTemplate;
            }
        } else if (cType.equals(IOConstants.TAG_SKILL)) {
            Skill aSkill = context.getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, cKey);
            if (aSkill != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSkill;
            }
        } else if (cType.equals(IOConstants.TAG_SPELL)) {
            final Spell aSpell = context.getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, cKey);
            if (aSpell != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSpell;
            }
        } else if (cType.equals(IOConstants.TAG_NAME)) {
            newB = Bonus.newBonus(context, bonus);
        //newB.setCreatorObject(thePC);
        }
        if (newB == null) {
            return;
        }
        TempBonusInfo tempBonusInfo;
        // Check to see if the target was the PC or an Item
        if (tName.equals(IOConstants.TAG_PC)) {
            thePC.setApplied(newB, true);
            tempBonusInfo = thePC.addTempBonus(newB, creator, thePC);
        } else {
            thePC.setApplied(newB, true);
            aEq.addTempBonus(newB);
            tempBonusInfo = thePC.addTempBonus(newB, creator, aEq);
        }
        if (!active) {
            String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
            thePC.setTempBonusFilter(bonusName);
        }
    }
    if (aEq != null) {
        aEq.setAppliedName(cKey);
        thePC.addTempBonusItemList(aEq);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) BonusObj(pcgen.core.bonus.BonusObj) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) Equipment(pcgen.core.Equipment) LoadContext(pcgen.rules.context.LoadContext) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory)

Example 8 with Skill

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

the class PCGVer2Parser method parseSkillLine.

/*
	 * ###############################################################
	 * Character Skills methods
	 * ###############################################################
	 */
private void parseSkillLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal Skill line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    Skill aSkill = null;
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the skill key name!!!
    String skillKey = "";
    if (it.hasNext()) {
        final PCGElement element = it.next();
        skillKey = EntityEncoder.decode(element.getText());
        aSkill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, skillKey);
    }
    while (it.hasNext()) {
        final PCGElement element = it.next();
        final String tag = element.getName();
        if (IOConstants.TAG_SYNERGY.equals(tag)) {
        // TODO
        // for now it's ok to ignore it!
        } else if (IOConstants.TAG_OUTPUTORDER.equals(tag)) {
            int outputindex = 0;
            try {
                outputindex = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
            // This is not critical.
            // Maybe warn the user?
            }
            if (aSkill != null) {
                thePC.setSkillOrder(aSkill, outputindex);
            }
        } else if (IOConstants.TAG_CLASSBOUGHT.equals(tag)) {
            PCGElement childClass = null;
            PCGElement childRanks = null;
            for (PCGElement child : element.getChildren()) {
                if (IOConstants.TAG_CLASS.equals(child.getName())) {
                    childClass = child;
                } else if (IOConstants.TAG_RANKS.equals(child.getName())) {
                    childRanks = child;
                }
            }
            if (childClass == null) {
                final String message = "Invalid class/ranks specification: " + line;
                warnings.add(message);
                continue;
            }
            if (childRanks == null) {
                final String message = "Invalid class/ranks specification: " + line;
                warnings.add(message);
                continue;
            }
            //None for a class is a special key word.  It is used when a familiar inherits a skill from its master
            PCClass aPCClass = null;
            if (//$NON-NLS-1$
            !childClass.getText().equals("None")) {
                final String childClassKey = EntityEncoder.decode(childClass.getText());
                aPCClass = thePC.getClassKeyed(childClassKey);
                if (aPCClass == null) {
                    final String message = "Could not find class: " + childClassKey;
                    warnings.add(message);
                    continue;
                }
            }
            if (aSkill == null) {
                // We only need to report this if the skill had ranks.
                final String message = "Could not add skill: " + skillKey;
                warnings.add(message);
                return;
            }
            try {
                double ranks = Double.parseDouble(childRanks.getText());
                SkillRankControl.modRanks(ranks, aPCClass, true, thePC, aSkill);
            } catch (NumberFormatException nfe) {
                final String message = "Invalid ranks specification: " + childRanks.getText();
                warnings.add(message);
                continue;
            }
        } else if (aSkill != null && IOConstants.TAG_ASSOCIATEDDATA.equals(tag)) {
            String key = EntityEncoder.decode(element.getText());
            ChoiceManagerList<Object> controller = ChooserUtilities.getConfiguredController(aSkill, thePC, null, new ArrayList<>());
            if (controller != null) {
                String[] assoc = key.split(Constants.COMMA, -1);
                for (String string : assoc) {
                    controller.restoreChoice(thePC, aSkill, string);
                }
            } else {
                warnings.add("Failed to find choose controller for skill " + aSkill);
            }
        } else if (aSkill != null && tag.equals(IOConstants.TAG_LEVELABILITY)) {
            parseLevelAbilityInfo(element, aSkill);
        } else if (aSkill != null && tag.equals(IOConstants.TAG_ADDTOKEN)) {
            parseAddTokenInfo(element, aSkill);
        }
    }
}
Also used : Skill(pcgen.core.Skill) ArrayList(java.util.ArrayList) ChoiceManagerList(pcgen.core.chooser.ChoiceManagerList) PCClass(pcgen.core.PCClass)

Example 9 with Skill

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

the class AbstractGlobalTargetedSaveRestoreTest method testAddAbilityNormalTarget.

@Test
public void testAddAbilityNormalTarget() {
    TokenRegistration.register(plugin.bonustokens.SkillRank.class);
    T target = create(getObjectClass(), "Target");
    Ability abil = context.getReferenceContext().constructCDOMObject(Ability.class, "GrantedAbility");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, abil);
    new plugin.lsttokens.add.AbilityToken().parseToken(context, target, "FEAT|NORMAL|GrantedAbility");
    Skill granted = create(Skill.class, "GrantedSkill");
    create(Skill.class, "IgnoredSkill");
    new plugin.lsttokens.choose.SkillToken().parseToken(context, abil, "GrantedSkill|IgnoredSkill");
    new plugin.lsttokens.BonusLst().parseToken(context, abil, "SKILLRANK|%LIST|1");
    abil.put(ObjectKey.MULTIPLE_ALLOWED, true);
    Object o = prepare(target);
    finishLoad();
    assertEquals(0.0f, SkillRankControl.getTotalRank(pc, granted));
    applyObject(target);
    pc.setDirty(true);
    assertEquals(1.0f, SkillRankControl.getTotalRank(pc, granted));
    runRoundRobin(getPreEqualityCleanup());
    assertEquals(1.0f, SkillRankControl.getTotalRank(pc, granted));
    assertEquals(1.0f, SkillRankControl.getTotalRank(reloadedPC, granted));
    remove(o);
    reloadedPC.setDirty(true);
//This fails (see CODE-2387)
//assertEquals(0.0f, SkillRankControl.getTotalRank(reloadedPC, granted));
}
Also used : Ability(pcgen.core.Ability) Skill(pcgen.core.Skill) SkillToken(plugin.lsttokens.choose.SkillToken) CDOMObject(pcgen.cdom.base.CDOMObject) Test(org.junit.Test)

Example 10 with Skill

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

the class AbstractGlobalTargetedSaveRestoreTest method testGlobalCSkillList.

@Test
public void testGlobalCSkillList() {
    PCClass monclass = create(PCClass.class, "MonClass");
    new HdToken().parseToken(context, monclass, "8");
    new TypeLst().parseToken(context, monclass, "Monster");
    Skill granted = create(Skill.class, "Granted");
    new ExclusiveToken().parseToken(context, granted, "Yes");
    T target = create(getObjectClass(), "Target");
    Skill skill = create(Skill.class, "MySkill");
    new ExclusiveToken().parseToken(context, skill, "Yes");
    new CskillLst().parseToken(context, target, "LIST");
    new SkillToken().parseToken(context, target, "Granted|MySkill");
    additionalChooseSet(target);
    Object o = prepare(target);
    finishLoad();
    pc.incrementClassLevel(1, monclass);
    pc.setHP(pc.getActiveClassLevel(monclass, 0), 3);
    assertEquals(SkillCost.EXCLUSIVE, pc.getSkillCostForClass(granted, monclass));
    applyObject(target);
    assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, monclass));
    final Runnable cleanup = getPreEqualityCleanup();
    Runnable fullcleanup = new Runnable() {

        public void run() {
            if (cleanup != null) {
                cleanup.run();
            }
            //TODO need this to create the spell support :/
            PCClass cl = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, "MonClass");
            reloadedPC.getSpellSupport(cl);
        }
    };
    runRoundRobin(fullcleanup);
    assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, monclass));
    assertEquals(SkillCost.CLASS, reloadedPC.getSkillCostForClass(granted, monclass));
    remove(o);
    reloadedPC.setDirty(true);
    if (isSymmetric()) {
        assertEquals(SkillCost.EXCLUSIVE, reloadedPC.getSkillCostForClass(granted, monclass));
    }
}
Also used : Skill(pcgen.core.Skill) CskillLst(plugin.lsttokens.CskillLst) HdToken(plugin.lsttokens.pcclass.HdToken) CDOMObject(pcgen.cdom.base.CDOMObject) PCClass(pcgen.core.PCClass) TypeLst(plugin.lsttokens.TypeLst) ExclusiveToken(plugin.lsttokens.skill.ExclusiveToken) SkillToken(plugin.lsttokens.choose.SkillToken) Test(org.junit.Test)

Aggregations

Skill (pcgen.core.Skill)165 Test (org.junit.Test)60 PCClass (pcgen.core.PCClass)55 ArrayList (java.util.ArrayList)29 CDOMReference (pcgen.cdom.base.CDOMReference)24 CharID (pcgen.cdom.enumeration.CharID)23 SkillCost (pcgen.cdom.enumeration.SkillCost)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 PlayerCharacter (pcgen.core.PlayerCharacter)14 ChoiceSet (pcgen.cdom.base.ChoiceSet)13 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)13 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)13 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)13 StringTokenizer (java.util.StringTokenizer)10 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)10 Ability (pcgen.core.Ability)10 LoadContext (pcgen.rules.context.LoadContext)9 ClassSkillList (pcgen.cdom.list.ClassSkillList)8 HashSet (java.util.HashSet)7 CNAbility (pcgen.cdom.content.CNAbility)7