Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Objects/Stats.cs @ 184:cedf8bba1d52
Re #198: Add equipment slots
* Alter handling of setting one limit and other limit matching by checking on Get instead of Set
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 27 Oct 2009 20:09:40 +0000 |
parents | 8c6f55d289b0 |
children | ece26f6a62f3 |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
1 // This file (Stats.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
0 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
0 | 4 |
5 using System; | |
6 using System.Collections.Generic; | |
7 using IBBoard.Lang; | |
8 | |
9 namespace IBBoard.WarFoundry.API.Objects | |
10 { | |
10 | 11 /// <summary> |
12 /// Stats defines the statistic/attribute values for an entity (for example a unit or any of their equipment that has a stat line) paired against a <see cref=" SystemStats"/> stat line definition. | |
13 /// </summary> | |
0 | 14 public class Stats |
15 { | |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
16 private List<Stat> stats; |
0 | 17 private SystemStats sysStats; |
18 | |
19 public Stats(SystemStats systemStats) | |
20 { | |
21 sysStats = systemStats; | |
68
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
22 int statCount = sysStats.SlotCount; |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
23 stats = new List<Stat>(statCount); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
24 |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
25 for (int i = 0; i < statCount; i++) |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
26 { |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
27 stats.Add(null); |
10d14a7051d5
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
28 } |
0 | 29 } |
30 | |
31 public Stat[] StatsArray | |
32 { | |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
33 get { return stats.ToArray(); } |
0 | 34 } |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
35 |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
36 public void SetStatValue(string statName, string statValue) |
0 | 37 { |
181
8c6f55d289b0
Fixes #200: Stats names should be case-insensitive
IBBoard <dev@ibboard.co.uk>
parents:
131
diff
changeset
|
38 StatSlot slot = sysStats[statName.ToLower()]; |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
39 |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
40 if (slot!=null) |
0 | 41 { |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
42 int pos = sysStats.GetStatSlotPosition(slot); |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
43 |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
44 if (pos > -1) |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
45 { |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
46 stats[pos] = new Stat(slot, statValue); |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
47 } |
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
48 } |
0 | 49 } |
50 | |
51 public Stat this[string id] | |
52 { | |
53 get | |
54 { | |
181
8c6f55d289b0
Fixes #200: Stats names should be case-insensitive
IBBoard <dev@ibboard.co.uk>
parents:
131
diff
changeset
|
55 StatSlot slot = sysStats[id.ToLower()]; |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
56 int pos = sysStats.GetStatSlotPosition(slot); |
0 | 57 Stat stat = null; |
58 | |
59 try | |
60 { | |
61 stat = this[pos]; | |
62 } | |
63 catch (ArgumentException ex) | |
64 { | |
65 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic ID {0} for stats based on system stats set {1}", new object[]{id, sysStats.ID}), ex); | |
66 } | |
67 | |
68 return stat; | |
69 } | |
70 } | |
71 | |
72 public Stat this[int pos] | |
73 { | |
74 get | |
75 { | |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
76 if (pos < stats.Count && pos >= 0) |
0 | 77 { |
78 return stats[pos]; | |
79 } | |
80 else | |
81 { | |
82 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic position {0} for stats based on system stats set {1}", new object[]{pos, sysStats.ID})); | |
83 } | |
84 } | |
85 } | |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
86 |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
87 public string GetStatValue(string id) |
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
88 { |
181
8c6f55d289b0
Fixes #200: Stats names should be case-insensitive
IBBoard <dev@ibboard.co.uk>
parents:
131
diff
changeset
|
89 return this[id.ToLower()].SlotValueString; |
81
032b174fc17a
Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
90 } |
0 | 91 |
92 public int StatCount | |
93 { | |
67
e6200220ece3
Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
94 get { return stats.Count; } |
0 | 95 } |
131
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
96 |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
97 public string StatsID |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
98 { |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
99 get |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
100 { |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
101 return sysStats.ID; |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
102 } |
5145b7c61ae0
Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
103 } |
0 | 104 } |
105 } |