Search in sources :

Example 1 with WeaponProf

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

the class ChangeProfFacet method getWeaponProfsInTarget.

/**
	 * For a given type of WeaponProf, returns a List of WeaponProf objects
	 * active for a Player Character after they are modified by the ChangeProf
	 * objects active on the Player Character.
	 * 
	 * This method is value-semantic in that ownership of the returned List is
	 * transferred to the class calling this method. Modification of the
	 * returned List will not modify this ChangeProfFacet and modification of
	 * this ChangeProfFacet will not modify the returned List. Modifications to
	 * the returned List will also not modify any future or previous objects
	 * returned by this (or other) methods on ChangeProfFacet. If you wish to
	 * modify the information stored in this ChangeProfFacet, you must use the
	 * add*() and remove*() methods of ChangeProfFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the List
	 *            of WeaponProf objects will be returned
	 * @param master
	 *            The original group of WeaponProf objects to be modified by any
	 *            ChangeProf objects active on the Player Character.
	 * @return A List of WeaponProf objects active for a Player Character, after
	 *         they are modified by the ChangeProf objects active on the Player
	 *         Character
	 */
public List<WeaponProf> getWeaponProfsInTarget(CharID id, CDOMGroupRef<WeaponProf> master) {
    String type = master.getLSTformat(false);
    if (!type.startsWith("TYPE=")) {
        throw new IllegalArgumentException("Cannot get targets for: " + type);
    }
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    List<WeaponProf> aList = new ArrayList<>();
    // Can't use master because late called references may not have been
    // initialized, see 2001287
    Collection<WeaponProf> weaponProfsOfType = Globals.getPObjectsOfType(ref.getConstructedCDOMObjects(WeaponProf.class), type);
    for (ChangeProf cp : getSet(id)) {
        if (cp.getResult().equals(master)) {
            aList.addAll(cp.getSource().getContainedObjects());
        } else if (weaponProfsOfType != null) {
            weaponProfsOfType.removeAll(cp.getSource().getContainedObjects());
        }
    }
    aList.addAll(weaponProfsOfType);
    return aList;
}
Also used : ChangeProf(pcgen.cdom.content.ChangeProf) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) ArrayList(java.util.ArrayList) WeaponProf(pcgen.core.WeaponProf)

Example 2 with WeaponProf

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

the class NaturalWeaponProfFacet method dataAdded.

/**
	 * Adds the implied (by NATURALATTACKS: token) weapon proficiencies to a
	 * Player Character when a CDOMObject which grants natural attacks is added
	 * to a Player Character.
	 * 
	 * Triggered when one of the Facets to which NaturalWeaponProfFacet listens
	 * fires a DataFacetChangeEvent to indicate a CDOMObject was added to a
	 * Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    // Natural Weapon Proficiencies
    List<CDOMSingleRef<WeaponProf>> iwp = cdo.getListFor(ListKey.IMPLIED_WEAPONPROF);
    if (iwp != null) {
        CharID id = dfce.getCharID();
        for (CDOMSingleRef<WeaponProf> ref : iwp) {
            add(id, ref.get(), cdo);
        }
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) WeaponProf(pcgen.core.WeaponProf) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) CharID(pcgen.cdom.enumeration.CharID)

Example 3 with WeaponProf

use of pcgen.core.WeaponProf 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 4 with WeaponProf

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

the class PCGVer2Creator method appendWeaponProficiencyLines.

/*
	 * ###############################################################
	 * Character Weapon proficiencies methods
	 * ###############################################################
	 */
private void appendWeaponProficiencyLines(StringBuilder buffer) {
    final int size = charDisplay.getWeaponProfSet().size();
    if (size > 0) {
        /*
			 * since aPC.getWeaponProfList() returns a TreeSet,
			 * we have to put them into an array first.
			 * we do not use TreeSet's toArray()-method since it
			 * makes no guarantees on element order.
			 *
			 * author: Thomas Behr 08-09-02
			 */
        final String[] weaponProficiencies = new String[size];
        int j = 0;
        for (WeaponProf wp : charDisplay.getSortedWeaponProfs()) {
            weaponProficiencies[j++] = wp.getKeyName();
        }
        // as per Mynex's request do not write more than 10 weapons per line
        final int step = 10;
        final int times = (size / step) + (((size % step) > 0) ? 1 : 0);
        for (int k = 0; k < times; ++k) {
            buffer.append(IOConstants.TAG_WEAPONPROF).append(':');
            buffer.append('[');
            String del = Constants.EMPTY_STRING;
            int stop = Math.min(size, (k * step) + 10);
            for (int i = k * step; i < stop; ++i) {
                buffer.append(del);
                buffer.append(IOConstants.TAG_WEAPON).append(':');
                buffer.append(EntityEncoder.encode(weaponProficiencies[i]));
                //$NON-NLS-1$
                del = "|";
            }
            buffer.append(']');
            buffer.append(IOConstants.LINE_SEP);
        }
    }
    //
    // Save any selected racial bonus weapons
    //
    appendWeaponProficiencyLines(buffer, charDisplay.getRace());
    //
    for (PCTemplate pct : charDisplay.getTemplateSet()) {
        appendWeaponProficiencyLines(buffer, pct);
    }
    //
    for (final PCClass pcClass : charDisplay.getClassSet()) {
        appendWeaponProficiencyLines(buffer, pcClass);
    }
}
Also used : WeaponProf(pcgen.core.WeaponProf) PCTemplate(pcgen.core.PCTemplate) PCClass(pcgen.core.PCClass)

Example 5 with WeaponProf

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

the class AbstractGlobalTargetedSaveRestoreTest method testAutoWeaponProf.

@Test
public void testAutoWeaponProf() {
    WeaponProf granted = create(WeaponProf.class, "Granted");
    create(WeaponProf.class, "Ignored");
    T target = create(getObjectClass(), "Target");
    new WeaponProfToken().parseToken(context, target, "Granted");
    Object o = prepare(target);
    finishLoad();
    assertFalse(pc.hasWeaponProf(granted));
    applyObject(target);
    assertTrue(pc.hasWeaponProf(granted));
    runRoundRobin(getPreEqualityCleanup());
    assertTrue(pc.hasWeaponProf(granted));
    assertTrue(reloadedPC.hasWeaponProf(granted));
    remove(o);
    reloadedPC.setDirty(true);
    assertFalse(reloadedPC.hasWeaponProf(granted));
}
Also used : WeaponProfToken(plugin.lsttokens.auto.WeaponProfToken) WeaponProf(pcgen.core.WeaponProf) CDOMObject(pcgen.cdom.base.CDOMObject) Test(org.junit.Test)

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