Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Objects/Stats.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
336:3631c1493c7f | 337:3c4a6403a88c |
---|---|
1 // This file (Stats.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. | |
2 // | |
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. | |
4 | |
5 using System; | |
6 using System.Collections.Generic; | |
7 | |
8 namespace IBBoard.WarFoundry.API.Objects | |
9 { | |
10 /// <summary> | |
11 /// 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. | |
12 /// </summary> | |
13 public class Stats | |
14 { | |
15 private List<Stat> stats; | |
16 private SystemStats sysStats; | |
17 | |
18 public Stats(SystemStats systemStats) | |
19 { | |
20 sysStats = systemStats; | |
21 int statCount = sysStats.SlotCount; | |
22 stats = new List<Stat>(statCount); | |
23 | |
24 foreach (StatSlot slot in sysStats.StatSlots) | |
25 { | |
26 stats.Add(new Stat(slot, "")); | |
27 } | |
28 } | |
29 | |
30 public Stat[] StatsArray | |
31 { | |
32 get { return stats.ToArray(); } | |
33 } | |
34 | |
35 public void SetStatValue(string statName, string statValue) | |
36 { | |
37 StatSlot slot = sysStats[statName.ToLower()]; | |
38 | |
39 if (slot!=null) | |
40 { | |
41 int pos = sysStats.GetStatSlotPosition(slot); | |
42 | |
43 if (pos > -1) | |
44 { | |
45 stats[pos] = new Stat(slot, statValue); | |
46 } | |
47 } | |
48 } | |
49 | |
50 public Stat this[string id] | |
51 { | |
52 get | |
53 { | |
54 StatSlot slot = sysStats[id.ToLower()]; | |
55 int pos = sysStats.GetStatSlotPosition(slot); | |
56 Stat stat = null; | |
57 | |
58 try | |
59 { | |
60 stat = this[pos]; | |
61 } | |
62 catch (ArgumentException ex) | |
63 { | |
64 throw new ArgumentException(String.Format("Invalid statistic ID {0} for stats based on system stats set {1}", new object[]{id, sysStats.ID}), ex); | |
65 } | |
66 | |
67 return stat; | |
68 } | |
69 } | |
70 | |
71 public Stat this[int pos] | |
72 { | |
73 get | |
74 { | |
75 if (pos < stats.Count && pos >= 0) | |
76 { | |
77 return stats[pos]; | |
78 } | |
79 else | |
80 { | |
81 throw new ArgumentException(String.Format("Invalid statistic position {0} for stats based on system stats set {1}", new object[]{pos, sysStats.ID})); | |
82 } | |
83 } | |
84 } | |
85 | |
86 public string GetStatValue(string id) | |
87 { | |
88 return this[id.ToLower()].SlotValueString; | |
89 } | |
90 | |
91 public int StatCount | |
92 { | |
93 get { return stats.Count; } | |
94 } | |
95 | |
96 public string StatsID | |
97 { | |
98 get | |
99 { | |
100 return sysStats.ID; | |
101 } | |
102 } | |
103 } | |
104 } |