Search in sources :

Example 31 with WeaponProf

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

the class DeityWeaponProfFacetTest method getObject.

@Override
protected WeaponProf getObject() {
    WeaponProf wp = new WeaponProf();
    wp.setName("WP" + n++);
    return wp;
}
Also used : WeaponProf(pcgen.core.WeaponProf)

Example 32 with WeaponProf

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

the class DeityWeaponProfFacetTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Deity cdo1 = new Deity();
    cdo1.setName("Deity1");
    Deity cdo2 = new Deity();
    cdo2.setName("Deity2");
    WeaponProf st1 = new WeaponProf();
    st1.setName("Prof1");
    WeaponProf st2 = new WeaponProf();
    st1.setName("Prof2");
    cdo1.addToListFor(ListKey.DEITYWEAPON, CDOMDirectSingleRef.getRef(st1));
    cdo2.addToListFor(ListKey.DEITYWEAPON, CDOMDirectSingleRef.getRef(st2));
    source = new Deity[] { cdo1, cdo2 };
    target = new WeaponProf[] { st1, st2 };
}
Also used : Deity(pcgen.core.Deity) WeaponProf(pcgen.core.WeaponProf)

Example 33 with WeaponProf

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

the class TypeTokenTest method setUp.

@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    TokenRegistration.register(TYPE_TOKEN);
    Type med = Type.getConstant("Medium");
    WeaponProf pls = primaryContext.getReferenceContext().constructCDOMObject(WeaponProf.class, "Longsword");
    pls.addToListFor(ListKey.TYPE, med);
    WeaponProf sls = secondaryContext.getReferenceContext().constructCDOMObject(WeaponProf.class, "Longsword");
    sls.addToListFor(ListKey.TYPE, med);
}
Also used : Type(pcgen.cdom.enumeration.Type) WeaponProf(pcgen.core.WeaponProf)

Example 34 with WeaponProf

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

the class ChangeprofLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<ChangeProf> changes = context.getObjectContext().getListChanges(obj, ListKey.CHANGEPROF);
    Collection<ChangeProf> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    HashMapToList<CDOMGroupRef<WeaponProf>, CDOMReference<WeaponProf>> m = new HashMapToList<>();
    for (ChangeProf cp : added) {
        CDOMReference<WeaponProf> source = cp.getSource();
        CDOMGroupRef<WeaponProf> result = cp.getResult();
        m.addToListFor(result, source);
    }
    SortedSet<CDOMReference<WeaponProf>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
    Set<String> returnSet = new TreeSet<>();
    for (CDOMGroupRef<WeaponProf> result : m.getKeySet()) {
        StringBuilder sb = new StringBuilder();
        boolean needComma = false;
        set.clear();
        set.addAll(m.getListFor(result));
        for (CDOMReference<WeaponProf> source : set) {
            if (needComma) {
                sb.append(Constants.COMMA);
            }
            needComma = true;
            String sourceLst = source.getLSTformat(false);
            if (sourceLst.startsWith(Constants.LST_TYPE_EQUAL)) {
                sb.append(Constants.LST_TYPE_DOT);
                sb.append(sourceLst.substring(5));
            } else {
                sb.append(sourceLst);
            }
        }
        sb.append(Constants.EQUALS).append(result.getLSTformat(false).substring(5));
        returnSet.add(sb.toString());
    }
    return new String[] { StringUtil.join(returnSet, Constants.PIPE) };
}
Also used : WeaponProf(pcgen.core.WeaponProf) HashMapToList(pcgen.base.util.HashMapToList) ChangeProf(pcgen.cdom.content.ChangeProf) CDOMGroupRef(pcgen.cdom.reference.CDOMGroupRef) TreeSet(java.util.TreeSet) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 35 with WeaponProf

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

the class ChangeprofLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    // value should be of the format:
    // Name1,TYPE.type1,Name3=Prof1|Name4,Name5=Prof2
    //
    // e.g.: TYPE.Hammer,Hand Axe=Simple|Urgosh,Waraxe=Martial
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    List<ChangeProf> list = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        int equalLoc = tokText.indexOf('=');
        if (equalLoc < 0) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": No = found. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        } else if (equalLoc != tokText.lastIndexOf('=')) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Two = found.  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        String newType = tokText.substring(equalLoc + 1);
        if (newType.isEmpty()) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Result Type.  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        if (newType.indexOf(Constants.DOT) != -1) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Invalid (Compound) Result Type: cannot contain a period (.)  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        String[] val = { newType };
        CDOMGroupRef<WeaponProf> newTypeProf = context.getReferenceContext().getCDOMTypeReference(WEAPONPROF_CLASS, val);
        String profs = tokText.substring(0, equalLoc);
        if (profs.isEmpty()) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Source Prof.  " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
            cpr.addErrorMessage("  Token was: " + tokText);
            cpr.addErrorMessage("  Tag was: " + value);
            return cpr;
        }
        StringTokenizer pTok = new StringTokenizer(profs, Constants.COMMA);
        while (pTok.hasMoreTokens()) {
            CDOMReference<WeaponProf> wp = TokenUtilities.getTypeOrPrimitive(context, WEAPONPROF_CLASS, pTok.nextToken());
            list.add(new ChangeProf(wp, newTypeProf));
        }
    }
    for (ChangeProf cp : list) {
        context.getObjectContext().addToList(obj, ListKey.CHANGEPROF, cp);
    }
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) WeaponProf(pcgen.core.WeaponProf) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Ungranted(pcgen.cdom.base.Ungranted) StringTokenizer(java.util.StringTokenizer) ChangeProf(pcgen.cdom.content.ChangeProf)

Aggregations

WeaponProf (pcgen.core.WeaponProf)56 StringTokenizer (java.util.StringTokenizer)10 Test (org.junit.Test)10 Equipment (pcgen.core.Equipment)10 CDOMReference (pcgen.cdom.base.CDOMReference)6 ArrayList (java.util.ArrayList)5 CDOMObject (pcgen.cdom.base.CDOMObject)5 Deity (pcgen.core.Deity)5 ArmorProf (pcgen.core.ArmorProf)4 PCTemplate (pcgen.core.PCTemplate)4 ShieldProf (pcgen.core.ShieldProf)4 HashSet (java.util.HashSet)3 ChangeProf (pcgen.cdom.content.ChangeProf)3 WeaponProfProvider (pcgen.cdom.helper.WeaponProfProvider)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 PCClass (pcgen.core.PCClass)3 Race (pcgen.core.Race)3 Type (pcgen.cdom.enumeration.Type)2 EquipmentHead (pcgen.cdom.inst.EquipmentHead)2 CDOMGroupRef (pcgen.cdom.reference.CDOMGroupRef)2