15
|
1 // This file (Stats.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
|
0
|
2 //
|
15
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL 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 {
|
|
16 private Stat[] stats;
|
|
17 private List<string> statOrder;
|
|
18 private SystemStats sysStats;
|
|
19
|
|
20 public Stats(SystemStats systemStats)
|
|
21 {
|
|
22 sysStats = systemStats;
|
|
23 }
|
|
24
|
|
25 public Stat[] StatsArray
|
|
26 {
|
|
27 get { return (Stat[])stats.Clone(); }
|
|
28 }
|
|
29
|
|
30 protected internal void SetStats(List<Stat> statList)
|
|
31 {
|
|
32 stats = statList.ToArray();
|
|
33 statOrder = new List<string>();
|
|
34
|
|
35 foreach (Stat stat in statList)
|
|
36 {
|
|
37 statOrder.Add(stat.ParentSlot.Name);
|
|
38 }
|
|
39 }
|
|
40
|
|
41 public Stat this[string id]
|
|
42 {
|
|
43 get
|
|
44 {
|
|
45 Stat stat = null;
|
|
46 int pos = statOrder.IndexOf(id);
|
|
47
|
|
48 try
|
|
49 {
|
|
50 stat = this[pos];
|
|
51 }
|
|
52 catch (ArgumentException ex)
|
|
53 {
|
|
54 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic ID {0} for stats based on system stats set {1}", new object[]{id, sysStats.ID}), ex);
|
|
55 }
|
|
56
|
|
57 return stat;
|
|
58 }
|
|
59 }
|
|
60
|
|
61 public Stat this[int pos]
|
|
62 {
|
|
63 get
|
|
64 {
|
|
65 if (pos < stats.Length && pos >= 0)
|
|
66 {
|
|
67 return stats[pos];
|
|
68 }
|
|
69 else
|
|
70 {
|
|
71 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic position {0} for stats based on system stats set {1}", new object[]{pos, sysStats.ID}));
|
|
72 }
|
|
73 }
|
|
74 }
|
|
75
|
|
76 public int StatCount
|
|
77 {
|
|
78 get { return stats.Length; }
|
|
79 }
|
|
80 }
|
|
81 }
|