Browse Source

Add requirements list and implement method to expand

master
Chris Smith 15 years ago
parent
commit
3968dd1d3e

+ 2
- 1
src/uk/co/md87/evetool/api/wrappers/CertificateTree.java View File

@@ -31,6 +31,7 @@ import uk.co.md87.evetool.api.parser.ApiElement;
31 31
 import uk.co.md87.evetool.api.wrappers.data.CertCategory;
32 32
 import uk.co.md87.evetool.api.wrappers.data.CertClass;
33 33
 import uk.co.md87.evetool.api.wrappers.data.CertInfo;
34
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
34 35
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
35 36
 
36 37
 /**
@@ -84,7 +85,7 @@ public class CertificateTree extends ArrayList<CertCategory> {
84 85
         final int grade = row.getNumericAttribute("grade");
85 86
         final int corp = row.getNumericAttribute("corporationID");
86 87
         final String desc = row.getStringAttribute("description");
87
-        final List<SkillRequirement> skillReqs = new ArrayList<SkillRequirement>();
88
+        final RequirementsList skillReqs = new RequirementsList();
88 89
         final List<Integer> certReqs = new ArrayList<Integer>();
89 90
 
90 91
         for (ApiElement srow : row.getRowset("requiredSkills")) {

+ 8
- 3
src/uk/co/md87/evetool/api/wrappers/CharacterSheet.java View File

@@ -34,6 +34,7 @@ import uk.co.md87.evetool.api.wrappers.data.BasicCharInfo;
34 34
 import uk.co.md87.evetool.api.wrappers.data.BasicCloneInfo;
35 35
 import uk.co.md87.evetool.api.wrappers.data.BasicCorpInfo;
36 36
 import uk.co.md87.evetool.api.wrappers.data.Implant;
37
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
37 38
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
38 39
 import uk.co.md87.evetool.api.wrappers.data.TrainedSkillInfo;
39 40
 
@@ -244,10 +245,14 @@ public class CharacterSheet {
244 245
         return skills;
245 246
     }
246 247
 
247
-    public boolean hasSkills(final List<SkillRequirement> reqs) {
248
+    public boolean hasSkill(final SkillRequirement req) {
249
+        return skills.containsKey(req.getSkillId()) ||
250
+                skills.get(req.getSkillId()).getLevel() < req.getRequiredLevel();
251
+    }
252
+
253
+    public boolean hasSkills(final RequirementsList reqs) {
248 254
         for (SkillRequirement req : reqs) {
249
-            if (!skills.containsKey(req.getSkillId()) ||
250
-                    skills.get(req.getSkillId()).getLevel() < req.getRequiredLevel()) {
255
+            if (!hasSkill(req)) {
251 256
                 return false;
252 257
             }
253 258
         }

+ 2
- 3
src/uk/co/md87/evetool/api/wrappers/ShipList.java View File

@@ -22,14 +22,13 @@
22 22
 
23 23
 package uk.co.md87.evetool.api.wrappers;
24 24
 
25
-import java.util.ArrayList;
26 25
 import java.util.HashMap;
27
-import java.util.List;
28 26
 import java.util.Map;
29 27
 
30 28
 import uk.co.md87.evetool.api.parser.ApiElement;
31 29
 import uk.co.md87.evetool.api.wrappers.data.BasicRaceInfo;
32 30
 import uk.co.md87.evetool.api.wrappers.data.BasicShipInfo;
31
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
33 32
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
34 33
 import uk.co.md87.evetool.api.wrappers.data.TypeGroup;
35 34
 
@@ -56,7 +55,7 @@ public class ShipList {
56 55
                 final String typeName = ship.getStringAttribute("typeName");
57 56
                 final int graphicID = ship.getNumericAttribute("graphicID");
58 57
                 final int raceID = ship.getNumericAttribute("raceID");
59
-                final List<SkillRequirement> reqs = new ArrayList<SkillRequirement>();
58
+                final RequirementsList reqs = new RequirementsList();
60 59
                 
61 60
                 final int[][] values = new int[ship.getRowset("attributes").size() / 2][2];
62 61
                 for (ApiElement req : ship.getRowset("attributes")) {

+ 4
- 3
src/uk/co/md87/evetool/api/wrappers/SkillList.java View File

@@ -29,6 +29,7 @@ import java.util.Map;
29 29
 
30 30
 import uk.co.md87.evetool.api.parser.ApiElement;
31 31
 import uk.co.md87.evetool.api.wrappers.data.Attribute;
32
+import uk.co.md87.evetool.api.wrappers.data.RequirementsList;
32 33
 import uk.co.md87.evetool.api.wrappers.data.SkillGroup;
33 34
 import uk.co.md87.evetool.api.wrappers.data.SkillInfo;
34 35
 import uk.co.md87.evetool.api.wrappers.data.SkillRequirement;
@@ -79,7 +80,7 @@ public class SkillList extends ArrayList<SkillGroup> {
79 80
         final int typeId = row.getNumericAttribute("typeID");
80 81
         final String desc = row.getChildContent("description");
81 82
         final int rank = row.getNumericChildContent("rank");
82
-        final List<SkillRequirement> reqs = getReqs(row.getRowset("requiredSkills"));
83
+        final RequirementsList reqs = getReqs(row.getRowset("requiredSkills"));
83 84
         final Attribute primaryAttribute = Attribute.valueOf(row.getChild("requiredAttributes")
84 85
                 .getChildContent("primaryAttribute").toUpperCase());
85 86
         final Attribute secondaryAttribute = Attribute.valueOf(row.getChild("requiredAttributes")
@@ -90,8 +91,8 @@ public class SkillList extends ArrayList<SkillGroup> {
90 91
                 secondaryAttribute, bonuses);
91 92
     }
92 93
 
93
-    protected List<SkillRequirement> getReqs(final List<ApiElement> rowset) {
94
-        final List<SkillRequirement> reqs = new ArrayList<SkillRequirement>();
94
+    protected RequirementsList getReqs(final List<ApiElement> rowset) {
95
+        final RequirementsList reqs = new RequirementsList();
95 96
 
96 97
         for (ApiElement row : rowset) {
97 98
             reqs.add(new SkillRequirement(row.getNumericAttribute("typeID"),

+ 3
- 5
src/uk/co/md87/evetool/api/wrappers/data/BasicShipInfo.java View File

@@ -22,8 +22,6 @@
22 22
 
23 23
 package uk.co.md87.evetool.api.wrappers.data;
24 24
 
25
-import java.util.List;
26
-
27 25
 /**
28 26
  *
29 27
  * TODO: Document BasicShipInfo
@@ -32,11 +30,11 @@ import java.util.List;
32 30
 public class BasicShipInfo extends BasicType {
33 31
 
34 32
     private final int graphicID;
35
-    private final List<SkillRequirement> requirements;
33
+    private final RequirementsList requirements;
36 34
 
37 35
     public BasicShipInfo(final int id, final String name, final BasicRaceInfo race,
38 36
             final TypeGroup group, final int graphicID,
39
-            final List<SkillRequirement> requirements) {
37
+            final RequirementsList requirements) {
40 38
         super(id, name, race, group);
41 39
 
42 40
         this.graphicID = graphicID;
@@ -48,7 +46,7 @@ public class BasicShipInfo extends BasicType {
48 46
     }
49 47
 
50 48
 
51
-    public List<SkillRequirement> getRequirements() {
49
+    public RequirementsList getRequirements() {
52 50
         return requirements;
53 51
     }
54 52
 

+ 4
- 3
src/uk/co/md87/evetool/api/wrappers/data/CertInfo.java View File

@@ -23,6 +23,7 @@
23 23
 package uk.co.md87.evetool.api.wrappers.data;
24 24
 
25 25
 import java.util.List;
26
+
26 27
 import uk.co.md87.evetool.ui.listable.Retrievable;
27 28
 
28 29
 /**
@@ -36,11 +37,11 @@ public class CertInfo {
36 37
     private final int grade;
37 38
     private final int corp;
38 39
     private final String desc;
39
-    private final List<SkillRequirement> skillReqs;
40
+    private final RequirementsList skillReqs;
40 41
     private final List<Integer> certReqs;
41 42
 
42 43
     public CertInfo(final int id, final int grade, final int corp,
43
-            final String desc, final List<SkillRequirement> skillReqs,
44
+            final String desc, final RequirementsList skillReqs,
44 45
             final List<Integer> certReqs) {
45 46
         this.id = id;
46 47
         this.grade = grade;
@@ -74,7 +75,7 @@ public class CertInfo {
74 75
         return id;
75 76
     }
76 77
 
77
-    public List<SkillRequirement> getSkillReqs() {
78
+    public RequirementsList getSkillReqs() {
78 79
         return skillReqs;
79 80
     }
80 81
 

+ 74
- 0
src/uk/co/md87/evetool/api/wrappers/data/RequirementsList.java View File

@@ -0,0 +1,74 @@
1
+/*
2
+ * Copyright (c) 2009 Chris Smith
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.co.md87.evetool.api.wrappers.data;
24
+
25
+import java.util.ArrayList;
26
+import java.util.HashMap;
27
+import java.util.List;
28
+import java.util.Map;
29
+
30
+import uk.co.md87.evetool.api.wrappers.SkillList;
31
+import uk.co.md87.evetool.ui.listable.Retrievable;
32
+
33
+/**
34
+ *
35
+ * TODO: Document RequirementsList
36
+ * @author chris
37
+ */
38
+public class RequirementsList extends ArrayList<SkillRequirement> {
39
+
40
+    /**
41
+     * A version number for this class. It should be changed whenever the class
42
+     * structure is changed (or anything else that would prevent serialized
43
+     * objects being unserialized with the new class).
44
+     */
45
+    private static final long serialVersionUID = 10;
46
+
47
+    public void expandRequirements(final SkillList skillList) {
48
+        final List<SkillRequirement> unprocessed = new ArrayList<SkillRequirement>();
49
+        final Map<Integer, Integer> needed = new HashMap<Integer, Integer>();
50
+        unprocessed.addAll(this);
51
+
52
+        while (!unprocessed.isEmpty()) {
53
+            final SkillRequirement target = unprocessed.remove(0);
54
+
55
+            unprocessed.addAll(skillList.getSkillById(target.getSkillId()).getRequirements());
56
+
57
+            final int level =  Math.max(needed.containsKey(target.getSkillId())
58
+                    ? needed.get(target.getSkillId()) : 0, target.getRequiredLevel());
59
+            needed.put(target.getSkillId(), level);
60
+        }
61
+
62
+        clear();
63
+
64
+        for (Map.Entry<Integer, Integer> entry : needed.entrySet()) {
65
+            add(new SkillRequirement(entry.getKey(), entry.getValue()));
66
+        }
67
+    }
68
+
69
+    @Retrievable(name="total number")
70
+    public int getNumSkills() {
71
+        return size();
72
+    }
73
+
74
+}

+ 8
- 3
src/uk/co/md87/evetool/api/wrappers/data/SkillInfo.java View File

@@ -22,8 +22,8 @@
22 22
 
23 23
 package uk.co.md87.evetool.api.wrappers.data;
24 24
 
25
-import java.util.List;
26 25
 import java.util.Map;
26
+
27 27
 import uk.co.md87.evetool.ui.listable.Retrievable;
28 28
 import uk.co.md87.evetool.ui.listable.formatters.NumberFormatter;
29 29
 
@@ -39,14 +39,14 @@ public class SkillInfo {
39 39
     protected final int id;
40 40
     protected final String description;
41 41
     protected final int rank;
42
-    protected final List<SkillRequirement> requirements;
42
+    protected final RequirementsList requirements;
43 43
     protected final Attribute primaryAttribute;
44 44
     protected final Attribute secondaryAttribute;
45 45
     protected final Map<String, String> bonuses;
46 46
 
47 47
     public SkillInfo(final SkillGroup group, final String name, final int id,
48 48
             final String description, final int rank,
49
-            final List<SkillRequirement> requirements,
49
+            final RequirementsList requirements,
50 50
             final Attribute primaryAttribute, final Attribute secondaryAttribute,
51 51
             final Map<String, String> bonuses) {
52 52
         this.group = group;
@@ -97,6 +97,11 @@ public class SkillInfo {
97 97
         return group;
98 98
     }
99 99
 
100
+    @Retrievable(deferred=true,name="Requirements:")
101
+    public RequirementsList getRequirements() {
102
+        return requirements;
103
+    }
104
+
100 105
     @Override
101 106
     public String toString() {
102 107
         return "[" + name + " (" + id + ") | " + bonuses + "]";

Loading…
Cancel
Save