Search in sources :

Example 1 with AttackType

use of pcgen.util.enumeration.AttackType in project pcgen by PCGen.

the class PCClass method clone.

@Override
public PCClass clone() {
    PCClass aClass = null;
    try {
        aClass = (PCClass) super.clone();
        List<KnownSpellIdentifier> ksl = getListFor(ListKey.KNOWN_SPELLS);
        if (ksl != null) {
            aClass.removeListFor(ListKey.KNOWN_SPELLS);
            for (KnownSpellIdentifier ksi : ksl) {
                aClass.addToListFor(ListKey.KNOWN_SPELLS, ksi);
            }
        }
        Map<AttackType, Integer> acmap = getMapFor(MapKey.ATTACK_CYCLE);
        if (acmap != null && !acmap.isEmpty()) {
            aClass.removeMapFor(MapKey.ATTACK_CYCLE);
            for (Map.Entry<AttackType, Integer> me : acmap.entrySet()) {
                aClass.addToMapFor(MapKey.ATTACK_CYCLE, me.getKey(), me.getValue());
            }
        }
        aClass.levelMap = new TreeMap<>();
        for (Map.Entry<Integer, PCClassLevel> me : levelMap.entrySet()) {
            aClass.levelMap.put(me.getKey(), me.getValue().clone());
        }
    } catch (CloneNotSupportedException exc) {
        ShowMessageDelegate.showMessageDialog(exc.getMessage(), Constants.APPLICATION_NAME, MessageType.ERROR);
    }
    return aClass;
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) AttackType(pcgen.util.enumeration.AttackType) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 2 with AttackType

use of pcgen.util.enumeration.AttackType in project pcgen by PCGen.

the class AttackToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    String retString = "";
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    aTok.nextToken();
    if (aTok.hasMoreTokens()) {
        String attackTypeString = aTok.nextToken();
        String modifier = aTok.hasMoreTokens() ? aTok.nextToken() : "";
        String format = aTok.hasMoreTokens() ? aTok.nextToken() : "";
        AttackType attackType = AttackType.valueOf(attackTypeString);
        retString = AttackInfo.getAttackInfo(pc, attackType, modifier);
        // SHORT means we only return the first attack bonus
        if ("SHORT".equalsIgnoreCase(format)) {
            int sepPos = retString.indexOf('/');
            if (sepPos >= 0) {
                retString = retString.substring(0, sepPos);
            }
        }
    }
    return retString;
}
Also used : StringTokenizer(java.util.StringTokenizer) AttackType(pcgen.util.enumeration.AttackType)

Example 3 with AttackType

use of pcgen.util.enumeration.AttackType in project pcgen by PCGen.

the class AttackcycleToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
    if (aTok.countTokens() % 2 != 0) {
        return new ParseResult.Fail(getTokenName() + " must have an even number of arguments.", context);
    }
    while (aTok.hasMoreTokens()) {
        AttackType at = AttackType.getInstance(aTok.nextToken());
        if (AttackType.GRAPPLE.equals(at)) {
            return new ParseResult.Fail("Error: Cannot Set Attack Cycle " + "for GRAPPLE Attack Type", context);
        }
        String cycle = aTok.nextToken();
        try {
            Integer i = Integer.parseInt(cycle);
            if (i <= 0) {
                return new ParseResult.Fail("Invalid " + getTokenName() + ": " + value + " Cycle " + cycle + " must be a positive integer.", context);
            }
            context.getObjectContext().put(pcc, MapKey.ATTACK_CYCLE, at, i);
            /*
				 * This is a bit of a hack - it is designed to account for the
				 * fact that the BAB tag in ATTACKCYCLE actually impacts both
				 * ATTACK.MELEE and ATTACK.GRAPPLE ... therefore, one method of
				 * handing this (which is done here) is to actually allow the
				 * pcgen.core code to keep the 4 attack type view (MELEE,
				 * RANGED, UNARMED, GRAPPLE) by simply loading the attackCycle
				 * for MELEE into GRAPPLE. This is done in the hope that this is
				 * a more flexible solution for potential future requirements
				 * for other attack types (rather than treating GRAPPLE as a
				 * special case throughout the core code) - thpr Nov 1, 2006
				 */
            if (at.equals(AttackType.MELEE)) {
                context.getObjectContext().put(pcc, MapKey.ATTACK_CYCLE, AttackType.GRAPPLE, i);
            }
        } catch (NumberFormatException e) {
            return new ParseResult.Fail("Invalid " + getTokenName() + ": " + value + " Cycle " + cycle + " must be a (positive) integer.", context);
        }
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) AttackType(pcgen.util.enumeration.AttackType)

Example 4 with AttackType

use of pcgen.util.enumeration.AttackType in project pcgen by PCGen.

the class AttackcycleToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    MapChanges<AttackType, Integer> changes = context.getObjectContext().getMapChanges(pcc, MapKey.ATTACK_CYCLE);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    Set<String> set = new TreeSet<>();
    Integer grappleValue = null;
    Integer meleeValue = null;
    Map<AttackType, Integer> added = changes.getAdded();
    for (Map.Entry<AttackType, Integer> me : added.entrySet()) {
        AttackType attackType = me.getKey();
        Integer value = me.getValue();
        if (value != null) {
            if (value <= 0) {
                context.addWriteMessage("Invalid " + getTokenName() + ": " + value + " Cycle " + attackType + " must be a positive integer.");
                return null;
            }
            if (attackType.equals(AttackType.GRAPPLE)) {
                grappleValue = value;
            } else {
                if (attackType.equals(AttackType.MELEE)) {
                    meleeValue = value;
                }
                set.add(new StringBuilder().append(attackType.getIdentifier()).append(Constants.PIPE).append(value).toString());
            }
        }
    }
    if (grappleValue != null) {
        // Validate same as MELEE
        if (!grappleValue.equals(meleeValue)) {
            context.addWriteMessage("Grapple Attack Cycle (" + grappleValue + ") MUST be equal to " + "Melee Attack Cycle (" + meleeValue + ") because it is not stored");
            return null;
        }
    }
    if (set.isEmpty()) {
        //OK, someone set keys with no values
        return null;
    }
    return new String[] { StringUtil.join(set, Constants.PIPE) };
}
Also used : TreeSet(java.util.TreeSet) AttackType(pcgen.util.enumeration.AttackType) Map(java.util.Map)

Aggregations

AttackType (pcgen.util.enumeration.AttackType)4 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1