MCPcopy Create free account
hub / github.com/PCGen/pcgen / PreArmorTypeTester

Class PreArmorTypeTester

code/src/java/plugin/pretokens/test/PreArmorTypeTester.java:34–128  ·  view source on GitHub ↗

Prerequisite test the type of a piece of armour.

Source from the content-addressed store, hash-verified

32 * Prerequisite test the type of a piece of armour.
33 */
34public class PreArmorTypeTester extends AbstractDisplayPrereqTest implements PrerequisiteTest
35{
36
37 // TODO All the equipment related PRE tag code should be refactored into a
38 // common base class.
39 @Override
40 public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source)
41 {
42 int runningTotal = 0;
43
44 if (display.hasEquipment())
45 {
46 final String desiredType = prereq.getKey();
47 for (Equipment eq : display.getEquippedEquipmentSet())
48 {
49 if (!eq.isArmor())
50 {
51 continue;
52 }
53
54 // Match against a TYPE of armour
55 if (desiredType.startsWith(Constants.LST_TYPE_EQUAL) || desiredType.startsWith(Constants.LST_TYPE_DOT))
56 {
57
58 String stripped = desiredType.substring(Constants.SUBSTRING_LENGTH_FIVE);
59 StringTokenizer tok = new StringTokenizer(stripped.toUpperCase(), ".");
60
61 boolean match = false;
62 if (tok.hasMoreTokens())
63 {
64 match = true;
65 }
66 //
67 // Must match all listed types to qualify
68 //
69 while (tok.hasMoreTokens())
70 {
71 final String type = tok.nextToken();
72 if (!eq.isType(type))
73 {
74 match = false;
75 break;
76 }
77 }
78 if (match)
79 {
80 runningTotal++;
81 break;
82 }
83 }
84 else
85 { //not a TYPE string
86 final String eqName = eq.getName().toUpperCase();
87 final int percentPos = desiredType.indexOf('%');
88 if (percentPos >= 0)
89 {
90 //handle wildcards (always assume they
91 // end the line)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected