annotate api/Objects/Stats.cs @ 309:7e1b27843b0d

Fixes #99: Define "points" values in GameSystem * Implement fall-back in case only one value has been set
author IBBoard <dev@ibboard.co.uk>
date Sun, 20 Feb 2011 16:00:11 +0000
parents cdda78975be1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 namespace IBBoard.WarFoundry.API.Objects
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 {
10
607c3232d689 Re #11 - Documentation
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
10 /// <summary>
607c3232d689 Re #11 - Documentation
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
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.
607c3232d689 Re #11 - Documentation
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
12 /// </summary>
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 public class Stats
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
15 private List<Stat> stats;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 private SystemStats sysStats;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 public Stats(SystemStats systemStats)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 sysStats = systemStats;
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
21 int statCount = sysStats.SlotCount;
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
22 stats = new List<Stat>(statCount);
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
23
252
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
24 foreach (StatSlot slot in sysStats.StatSlots)
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
25 {
252
a54da5a8b5bb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 228
diff changeset
26 stats.Add(new Stat(slot, ""));
68
10d14a7051d5 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 67
diff changeset
27 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 public Stat[] StatsArray
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 {
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
32 get { return stats.ToArray(); }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 }
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
34
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
35 public void SetStatValue(string statName, string statValue)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 {
181
8c6f55d289b0 Fixes #200: Stats names should be case-insensitive
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
37 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
38
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
39 if (slot!=null)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 {
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
41 int pos = sysStats.GetStatSlotPosition(slot);
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
42
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
43 if (pos > -1)
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
44 {
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
45 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
46 }
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
47 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 public Stat this[string id]
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 get
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 {
181
8c6f55d289b0 Fixes #200: Stats names should be case-insensitive
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
54 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
55 int pos = sysStats.GetStatSlotPosition(slot);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 Stat stat = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 stat = this[pos];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 catch (ArgumentException ex)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 {
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 181
diff changeset
64 throw new ArgumentException(String.Format("Invalid statistic ID {0} for stats based on system stats set {1}", new object[]{id, sysStats.ID}), ex);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 return stat;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 public Stat this[int pos]
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 get
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 {
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
75 if (pos < stats.Count && pos >= 0)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 return stats[pos];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 {
228
ece26f6a62f3 Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents: 181
diff changeset
81 throw new ArgumentException(String.Format("Invalid statistic position {0} for stats based on system stats set {1}", new object[]{pos, sysStats.ID}));
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 }
81
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
85
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
86 public string GetStatValue(string id)
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
87 {
181
8c6f55d289b0 Fixes #200: Stats names should be case-insensitive
IBBoard <dev@ibboard.co.uk>
parents: 131
diff changeset
88 return this[id.ToLower()].SlotValueString;
81
032b174fc17a Re #10 - Refactoring for readability
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
89 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 public int StatCount
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 {
67
e6200220ece3 Re #50 - Complete core loading of WarFoundry XML files
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
93 get { return stats.Count; }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 }
131
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
95
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
96 public string StatsID
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
97 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
98 get
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
99 {
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
100 return sysStats.ID;
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
101 }
5145b7c61ae0 Re #68: Add "export army list" function
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
102 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 }