Search in sources :

Example 6 with PersistentTransitionChoice

use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.

the class AddClassSkillsTest method testGetChoicesListWithClassSkill.

/**
	 * Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
	 */
@Test
public void testGetChoicesListWithClassSkill() {
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    String classPCCText = "CLASS:Cleric	HD:8		TYPE:Base.PC	ABB:Clr\n" + "CLASS:Cleric	STARTSKILLPTS:2	CSKILL:KEY_Knowledge (Dungeoneering)";
    PCClass po;
    try {
        po = parsePCClassText(classPCCText, source);
    } catch (PersistenceLayerException e) {
        throw new UnreachableError(e);
    }
    getCharacter().incrementClassLevel(1, po, false);
    PCTemplate pct = new PCTemplate();
    Skill bluff = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, "KEY_Bluff");
    pct.addToListFor(ListKey.CSKILL, CDOMDirectSingleRef.getRef(bluff));
    getCharacter().addTemplate(pct);
    Globals.getContext().unconditionallyProcess(po, "ADD", "CLASSSKILLS|2|KEY_Bluff,KEY_Listen,KEY_Knowledge (Arcana)");
    assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
    List<PersistentTransitionChoice<?>> choiceList = po.getListFor(ListKey.ADD);
    assertEquals(1, choiceList.size());
    TransitionChoice<?> choice = choiceList.get(0);
    Collection<?> choiceSet = choice.getChoices().getSet(getCharacter());
    assertEquals(3, choiceSet.size());
    Set<Object> limitedSet = new HashSet<>();
    ClassSkillChoiceActor csca = new ClassSkillChoiceActor(po, 0);
    for (Object sc : choiceSet) {
        if (csca.allow((Skill) sc, getCharacter(), true)) {
            limitedSet.add(sc);
        }
    }
    assertEquals(2, limitedSet.size());
    assertEquals(2, choice.getCount().resolve(getCharacter(), ""));
    List<String> choiceStrings = new ArrayList<>();
    for (Object o : limitedSet) {
        choiceStrings.add(o.toString());
    }
    assertTrue(choiceStrings.contains("Listen"));
    assertTrue(choiceStrings.contains("Knowledge (Arcana)"));
}
Also used : PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCClass(pcgen.core.PCClass) URI(java.net.URI) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) Campaign(pcgen.core.Campaign) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) PCTemplate(pcgen.core.PCTemplate) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with PersistentTransitionChoice

use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.

the class AddClassSkillsTest method testBasicChoicesList.

/**
	 * Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
	 */
@Test
public void testBasicChoicesList() {
    PCClass po = new PCClass();
    PlayerCharacter pc = getCharacter();
    Globals.getContext().unconditionallyProcess(po, "ADD", "CLASSSKILLS|2|KEY_Bluff,KEY_Listen,KEY_Move Silently");
    assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
    List<PersistentTransitionChoice<?>> choiceList = po.getListFor(ListKey.ADD);
    assertEquals(1, choiceList.size());
    TransitionChoice<?> choice = choiceList.get(0);
    Collection<?> choiceSet = choice.getChoices().getSet(pc);
    assertEquals(3, choiceSet.size());
    assertEquals(2, choice.getCount().resolve(pc, ""));
    List<String> choiceStrings = new ArrayList<>();
    for (Object o : choiceSet) {
        choiceStrings.add(o.toString());
    }
    assertTrue(choiceStrings.contains("Bluff"));
    assertTrue(choiceStrings.contains("Listen"));
    assertTrue(choiceStrings.contains("Move Silently"));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) Test(org.junit.Test)

Example 8 with PersistentTransitionChoice

use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.

the class AbilityToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
    Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
    if (addedItems == null || addedItems.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    List<String> addStrings = new ArrayList<>();
    for (TransitionChoice<?> container : addedItems) {
        SelectableSet<?> cs = container.getChoices();
        if (getTokenName().equals(cs.getName()) && CAT_ABILITY_SELECTION_CLASS.equals(cs.getChoiceClass())) {
            AbilityChoiceSet ascs = (AbilityChoiceSet) cs;
            Formula f = container.getCount();
            if (f == null) {
                context.addWriteMessage("Unable to find " + getFullName() + " Count");
                return null;
            }
            if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
                context.addWriteMessage("Count in " + getFullName() + " must be > 0");
                return null;
            }
            if (!cs.getGroupingState().isValid()) {
                context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + cs.getLSTformat());
                return null;
            }
            StringBuilder sb = new StringBuilder();
            if (!FormulaFactory.ONE.equals(f)) {
                sb.append(f).append(Constants.PIPE);
            }
            sb.append(ascs.getCategory().getLSTformat(false));
            sb.append(Constants.PIPE);
            sb.append(ascs.getNature());
            sb.append(Constants.PIPE);
            if (container.allowsStacking()) {
                sb.append("STACKS");
                Integer stackLimit = container.getStackLimit();
                if (stackLimit != null) {
                    if (stackLimit.intValue() <= 0) {
                        context.addWriteMessage("Stack Limit in " + getFullName() + " must be > 0");
                        return null;
                    }
                    sb.append(Constants.EQUALS);
                    sb.append(stackLimit.intValue());
                }
                sb.append(Constants.COMMA);
            }
            sb.append(cs.getLSTformat());
            addStrings.add(sb.toString());
        }
    }
    return addStrings.toArray(new String[addStrings.size()]);
}
Also used : Formula(pcgen.base.formula.Formula) AbilityChoiceSet(pcgen.cdom.base.ChoiceSet.AbilityChoiceSet) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList)

Example 9 with PersistentTransitionChoice

use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.

the class ClassSkillsLevelToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClassLevel obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
    Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
    if (addedItems == null || addedItems.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    List<String> addStrings = new ArrayList<>();
    for (TransitionChoice<?> container : addedItems) {
        SelectableSet<?> cs = container.getChoices();
        if (getTokenName().equals(cs.getName()) && SKILL_CLASS.equals(cs.getChoiceClass())) {
            Formula f = container.getCount();
            if (f == null) {
                context.addWriteMessage("Unable to find " + getFullName() + " Count");
                return null;
            }
            if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
                context.addWriteMessage("Count in " + getFullName() + " must be > 0");
                return null;
            }
            if (!cs.getGroupingState().isValid()) {
                context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + cs.getLSTformat());
                return null;
            }
            StringBuilder sb = new StringBuilder();
            if (!FormulaFactory.ONE.equals(f)) {
                sb.append(f).append(Constants.PIPE);
            }
            sb.append(cs.getLSTformat());
            ClassSkillChoiceActor actor = (ClassSkillChoiceActor) container.getChoiceActor();
            Integer rank = actor.getApplyRank();
            if (rank != null) {
                sb.append(Constants.COMMA).append("AUTORANK=" + rank);
            }
            addStrings.add(sb.toString());
        }
    }
    return addStrings.toArray(new String[addStrings.size()]);
}
Also used : Formula(pcgen.base.formula.Formula) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor)

Example 10 with PersistentTransitionChoice

use of pcgen.cdom.base.PersistentTransitionChoice in project pcgen by PCGen.

the class ClassSkillsToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
    Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
    if (addedItems == null || addedItems.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    List<String> addStrings = new ArrayList<>();
    for (TransitionChoice<?> container : addedItems) {
        SelectableSet<?> cs = container.getChoices();
        if (getTokenName().equals(cs.getName()) && SKILL_CLASS.equals(cs.getChoiceClass())) {
            Formula f = container.getCount();
            if (f == null) {
                context.addWriteMessage("Unable to find " + getFullName() + " Count");
                return null;
            }
            if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
                context.addWriteMessage("Count in " + getFullName() + " must be > 0");
                return null;
            }
            if (!cs.getGroupingState().isValid()) {
                context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + cs.getLSTformat());
                return null;
            }
            StringBuilder sb = new StringBuilder();
            if (!FormulaFactory.ONE.equals(f)) {
                sb.append(f).append(Constants.PIPE);
            }
            sb.append(cs.getLSTformat());
            ClassSkillChoiceActor actor = (ClassSkillChoiceActor) container.getChoiceActor();
            Integer rank = actor.getApplyRank();
            if (rank != null) {
                sb.append(Constants.COMMA).append("AUTORANK=" + rank);
            }
            addStrings.add(sb.toString());
        }
    }
    return addStrings.toArray(new String[addStrings.size()]);
}
Also used : Formula(pcgen.base.formula.Formula) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor)

Aggregations

PersistentTransitionChoice (pcgen.cdom.base.PersistentTransitionChoice)16 ArrayList (java.util.ArrayList)12 Formula (pcgen.base.formula.Formula)9 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)9 PCClass (pcgen.core.PCClass)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)3 PCTemplate (pcgen.core.PCTemplate)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 IdentityHashMap (java.util.IdentityHashMap)1 Set (java.util.Set)1 UnreachableError (pcgen.base.lang.UnreachableError)1 HashMapToList (pcgen.base.util.HashMapToList)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 AbilityChoiceSet (pcgen.cdom.base.ChoiceSet.AbilityChoiceSet)1