Search in sources :

Example 1 with PersistentTransitionChoice

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

the class PCGVer2Parser method parseWeaponProficienciesLine.

/*
	 * ###############################################################
	 * Character Weapon proficiencies methods
	 * ###############################################################
	 */
private void parseWeaponProficienciesLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal Weapon proficiencies line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    CDOMObject source = null;
    boolean hadSource = false;
    for (PCGElement element : tokens.getElements()) {
        if (IOConstants.TAG_SOURCE.equals(element.getName())) {
            hadSource = true;
            String type = Constants.EMPTY_STRING;
            String key = Constants.EMPTY_STRING;
            for (final PCGElement child : element.getChildren()) {
                final String tag = child.getName();
                if (IOConstants.TAG_TYPE.equals(tag)) {
                    type = child.getText().toUpperCase();
                } else if (IOConstants.TAG_NAME.equals(tag)) {
                    key = child.getText();
                }
            }
            if (Constants.EMPTY_STRING.equals(type) || Constants.EMPTY_STRING.equals(key)) {
                final String message = "Illegal Weapon proficiencies line ignored: " + line;
                warnings.add(message);
                return;
            }
            if (IOConstants.TAG_RACE.equals(type)) {
                source = thePC.getRace();
            } else if (TAG_PCTEMPLATE.equals(type)) {
                PCTemplate template = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, key);
                if (thePC.hasTemplate(template)) {
                    source = template;
                } else {
                    warnings.add("PC does not have Template: " + key);
                }
            } else if (IOConstants.TAG_PCCLASS.equals(type)) {
                source = thePC.getClassKeyed(key);
            }
            if (source == null) {
                final String message = "Invalid source specification: " + line;
                warnings.add(message);
            }
            break;
        }
    }
    final PCGElement element = tokens.getElements().get(0);
    boolean processed = false;
    if (source != null) {
        List<PersistentTransitionChoice<?>> adds = source.getListFor(ListKey.ADD);
        if (adds != null) {
            for (PersistentTransitionChoice<?> ptc : adds) {
                if (ptc.getChoiceClass().equals(WeaponProf.class)) {
                    for (PCGElement child : element.getChildren()) {
                        WeaponProf wp = getWeaponProf(child.getText());
                        Set c = Collections.singleton(wp);
                        ptc.act(c, source, thePC);
                    }
                    processed = true;
                    break;
                }
            }
        }
    }
    if (hadSource && !processed) {
        final String message = "Unable to apply WeaponProfs: " + line;
        warnings.add(message);
    }
}
Also used : EquipSet(pcgen.core.character.EquipSet) Set(java.util.Set) SelectableSet(pcgen.cdom.base.SelectableSet) HashSet(java.util.HashSet) CDOMObject(pcgen.cdom.base.CDOMObject) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) WeaponProf(pcgen.core.WeaponProf) PCTemplate(pcgen.core.PCTemplate)

Example 2 with PersistentTransitionChoice

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

the class KitLevelAbility method doApplication.

private boolean doApplication(PlayerCharacter aPC) {
    PCClass theClass = theClassName.get();
    PCClass classKeyed = aPC.getClassKeyed(theClass.getKeyName());
    if (classKeyed == null) {
    //Error?
    }
    //Look for ADD in class
    List<PersistentTransitionChoice<?>> adds = theClass.getListFor(ListKey.ADD);
    if (adds == null) {
    //Error?
    }
    for (PersistentTransitionChoice<?> ch : adds) {
        if (add.equals(ch)) {
            process(aPC, classKeyed, ch);
            return true;
        }
    }
    return false;
}
Also used : PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) PCClass(pcgen.core.PCClass)

Example 3 with PersistentTransitionChoice

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

the class TemplateToken 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 (PCTEMPLATE_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;
            }
            StringBuilder sb = new StringBuilder();
            if (!FormulaFactory.ONE.equals(f)) {
                sb.append(f).append(Constants.PIPE);
            }
            sb.append(cs.getLSTformat());
            addStrings.add(sb.toString());
        // assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
        }
    }
    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)

Example 4 with PersistentTransitionChoice

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

the class LanguageToken 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 (cs.getName().equals(getTokenName()) && LANGUAGE_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());
            addStrings.add(sb.toString());
        // assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
        }
    }
    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)

Example 5 with PersistentTransitionChoice

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

the class AddClassSkillsTest method testGetChoicesListWithParens.

/**
	 * Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
	 */
@Test
public void testGetChoicesListWithParens() {
    PCClass po = new PCClass();
    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());
    assertEquals(2, choice.getCount().resolve(getCharacter(), ""));
    List<String> choiceStrings = new ArrayList<>();
    for (Object o : choiceSet) {
        choiceStrings.add(o.toString());
    }
    assertTrue(choiceStrings.contains("Bluff"));
    assertTrue(choiceStrings.contains("Listen"));
    assertTrue(choiceStrings.contains("Knowledge (Arcana)"));
}
Also used : PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) Test(org.junit.Test)

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