0
|
1 // Stats.cs
|
|
2 //
|
|
3 // Copyright (C) 2008 IBBoard
|
|
4 //
|
|
5 // This library is free software; you can redistribute it and/or
|
|
6 // modify it under the terms of the GNU Lesser General Public
|
|
7 // License version 2.1 of the License as published by the Free
|
|
8 // Software Foundation.
|
|
9 //
|
|
10 // This library is distributed in the hope that it will be useful,
|
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 // Lesser General Public License for more details.
|
|
14 //
|
|
15 // You should have received a copy of the GNU Lesser General Public
|
|
16 // License along with this library; if not, write to the Free Software
|
|
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 //
|
|
19 //
|
|
20
|
|
21 using System;
|
|
22 using System.Collections.Generic;
|
|
23 using IBBoard.Lang;
|
|
24
|
|
25 namespace IBBoard.WarFoundry.API.Objects
|
|
26 {
|
10
|
27 /// <summary>
|
|
28 /// 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.
|
|
29 /// </summary>
|
0
|
30 public class Stats
|
|
31 {
|
|
32 private Stat[] stats;
|
|
33 private List<string> statOrder;
|
|
34 private SystemStats sysStats;
|
|
35
|
|
36 public Stats(SystemStats systemStats)
|
|
37 {
|
|
38 sysStats = systemStats;
|
|
39 }
|
|
40
|
|
41 public Stat[] StatsArray
|
|
42 {
|
|
43 get { return (Stat[])stats.Clone(); }
|
|
44 }
|
|
45
|
|
46 protected internal void SetStats(List<Stat> statList)
|
|
47 {
|
|
48 stats = statList.ToArray();
|
|
49 statOrder = new List<string>();
|
|
50
|
|
51 foreach (Stat stat in statList)
|
|
52 {
|
|
53 statOrder.Add(stat.ParentSlot.Name);
|
|
54 }
|
|
55 }
|
|
56
|
|
57 public Stat this[string id]
|
|
58 {
|
|
59 get
|
|
60 {
|
|
61 Stat stat = null;
|
|
62 int pos = statOrder.IndexOf(id);
|
|
63
|
|
64 try
|
|
65 {
|
|
66 stat = this[pos];
|
|
67 }
|
|
68 catch (ArgumentException ex)
|
|
69 {
|
|
70 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic ID {0} for stats based on system stats set {1}", new object[]{id, sysStats.ID}), ex);
|
|
71 }
|
|
72
|
|
73 return stat;
|
|
74 }
|
|
75 }
|
|
76
|
|
77 public Stat this[int pos]
|
|
78 {
|
|
79 get
|
|
80 {
|
|
81 if (pos < stats.Length && pos >= 0)
|
|
82 {
|
|
83 return stats[pos];
|
|
84 }
|
|
85 else
|
|
86 {
|
|
87 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic position {0} for stats based on system stats set {1}", new object[]{pos, sysStats.ID}));
|
|
88 }
|
|
89 }
|
|
90 }
|
|
91
|
|
92 public int StatCount
|
|
93 {
|
|
94 get { return stats.Length; }
|
|
95 }
|
|
96 }
|
|
97 }
|