comparison api/Objects/Stats.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 607c3232d689
comparison
equal deleted inserted replaced
-1:000000000000 0:520818033bb6
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 {
27 public class Stats
28 {
29 private Stat[] stats;
30 private List<string> statOrder;
31 private SystemStats sysStats;
32
33 public Stats(SystemStats systemStats)
34 {
35 sysStats = systemStats;
36 }
37
38 public Stat[] StatsArray
39 {
40 get { return (Stat[])stats.Clone(); }
41 }
42
43 protected internal void SetStats(List<Stat> statList)
44 {
45 stats = statList.ToArray();
46 statOrder = new List<string>();
47
48 foreach (Stat stat in statList)
49 {
50 statOrder.Add(stat.ParentSlot.Name);
51 }
52 }
53
54 public Stat this[string id]
55 {
56 get
57 {
58 Stat stat = null;
59 int pos = statOrder.IndexOf(id);
60
61 try
62 {
63 stat = this[pos];
64 }
65 catch (ArgumentException ex)
66 {
67 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic ID {0} for stats based on system stats set {1}", new object[]{id, sysStats.ID}), ex);
68 }
69
70 return stat;
71 }
72 }
73
74 public Stat this[int pos]
75 {
76 get
77 {
78 if (pos < stats.Length && pos >= 0)
79 {
80 return stats[pos];
81 }
82 else
83 {
84 throw new ArgumentException(Translation.GetTranslation("InvalidStatPos", "Invalid statistic position {0} for stats based on system stats set {1}", new object[]{pos, sysStats.ID}));
85 }
86 }
87 }
88
89 public int StatCount
90 {
91 get { return stats.Length; }
92 }
93 }
94 }