1: using System.Drawing;
2: using System.Collections.Generic;
3: using System.Xml;
4: using System.IO;
5:
6: public class Weapon
7: {
8: public static List<Weapon> g_GlobalWeaponList = new List<Weapon>();
9:
10: private int m_WeaponDamage;
11: private int m_WeaponDamagePlusMinus;
12: private bool m_RotateOnOverlap;
13: private bool m_RotateOnIdleToMatchHands;
14:
15: //Name of the Weapon
16: private string m_WeaponName;
17: private string m_WeaponDescription;
18: //Not necessarily how much item weighs
19: private int m_Encumberance;
20: //Number of gold pieces the item is worth
21: private int m_Value;
22: private string m_EquipFx;
23:
24: //Ranged weapon or not?
25: private bool m_Ranged;
26: //"hands" count as 0 hands
27: private int m_NumberOfHands;
28:
29: private int m_WeaponImagePosX;
30: private int m_WeaponImagePosY;
31:
32: private bool m_IsConsumable;
33: private int m_RangedSpeedModifier;
34: private List<string> m_HitFx;
35: // Equipped Image Locations:
36: public Point m_EquippedImageLoc;
37: public Point m_EquippedWeaponImageHotSpot;
38:
39: // Default Constructor:
40: public Weapon()
41: {
42: this.m_WeaponDamage = 2;
43: this.m_WeaponDamagePlusMinus = 1;
44: this.m_WeaponImagePosX = 0;
45: this.m_WeaponImagePosY = 0;
46: this.m_WeaponName = "Hands";
47: this.m_WeaponDescription = "Your mitts";
48: this.m_Ranged = false;
49: this.m_NumberOfHands = 0;
50: this.m_IsConsumable = false;
51: this.m_RangedSpeedModifier = 0;
52: this.m_EquipFx = null;
53: this.m_EquippedImageLoc = new Point();
54: this.m_EquippedWeaponImageHotSpot = new Point(32,32);
55: this.m_HitFx = new List<string>();
56: this.m_RotateOnOverlap = false;
57: this.m_RotateOnIdleToMatchHands = false;
58: }
59: // Properties:
60: #region
61: public int p_WeaponImagePosX { set { m_WeaponImagePosX = value; } get { return m_WeaponImagePosX; } }
62: public int p_WeaponImagePosY { set { m_WeaponImagePosY = value; } get { return m_WeaponImagePosY; } }
63: public string p_WeaponName { set { m_WeaponName = value; } get { return m_WeaponName; } }
64: public string p_EquipFx { set { m_EquipFx = value; } get { return m_EquipFx; } }
65: public int p_Encumberance { set { m_Encumberance = value; } get { return m_Encumberance; } }
66: public int p_Value { set { m_Value = value; } get { return m_Value; } }
67: public bool p_Ranged { set { m_Ranged = value; } get { return m_Ranged; } }
68: public bool p_RotateOnOverlap { set { m_RotateOnOverlap = value; } get { return m_RotateOnOverlap; } }
69: public bool p_RotateOnIdleToMatchHands { set { m_RotateOnIdleToMatchHands = value; }
70: get { return m_RotateOnIdleToMatchHands; } }
71: public int p_NumberOfHands { set { m_NumberOfHands = value; } get { return m_NumberOfHands; } }
72: public string p_WeaponDescription { set { m_WeaponDescription = value; } get { return m_WeaponDescription; } }
73: public int p_WeaponDamage { set { m_WeaponDamage = value; } get { return m_WeaponDamage; } }
74: public int p_WeaponDamagePlusMinus { set { m_WeaponDamagePlusMinus = value; }
75: get { return m_WeaponDamagePlusMinus; } }
76: public bool p_IsConsumable { set { m_IsConsumable = value; } get { return m_IsConsumable; } }
77: public int p_RangedSpeedModifier { set { m_RangedSpeedModifier = value; }
78: get { return m_RangedSpeedModifier; } }
79: public List<string> p_HitFx { set { m_HitFx = value; } get { return m_HitFx; } }
80: #endregion
81: public Weapon Clone()
82: {
83: Weapon weaponClone = new Weapon();
84: weaponClone.m_WeaponDamage = this.m_WeaponDamage;
85: weaponClone.m_WeaponDamagePlusMinus = this.m_WeaponDamagePlusMinus;
86: weaponClone.m_WeaponImagePosX = this.m_WeaponImagePosX;
87: weaponClone.m_WeaponImagePosY = this.m_WeaponImagePosY;
88: weaponClone.m_WeaponName = this.m_WeaponName;
89: weaponClone.m_WeaponDescription = this.m_WeaponDescription;
90: weaponClone.m_Encumberance = this.m_Encumberance;
91: weaponClone.m_Value = this.m_Value;
92: weaponClone.m_Ranged = this.m_Ranged;
93: weaponClone.m_NumberOfHands = this.m_NumberOfHands;
94: weaponClone.m_IsConsumable = this.m_IsConsumable;
95: weaponClone.m_RangedSpeedModifier = this.m_RangedSpeedModifier;
96: weaponClone.m_EquipFx = this.m_EquipFx;
97: weaponClone.m_HitFx = new List<string>(this.m_HitFx);
98: weaponClone.m_EquippedWeaponImageHotSpot = this.m_EquippedWeaponImageHotSpot;
99: weaponClone.m_EquippedImageLoc = this.m_EquippedImageLoc;
100: return weaponClone;
101: }
102: public static int LoadIntoMemoryAllWeaponsXML(ref List<Weapon> tempWeaponList)
103: {
104: tempWeaponList.Clear();
105: XmlDocument xmlDoc = new XmlDocument();
106: System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetAssembly(typeof(TerraAegrus));
107: Stream myStream = myAssembly.GetManifestResourceStream("Data.Weapons.xml");
108: xmlDoc.Load(myStream);
109:
110: XmlNodeList elemList = xmlDoc.GetElementsByTagName("Weapon");
111:
112: for (int i = 0; i < elemList.Count; i++)
113: {
114: Weapon tempWeapon = new Weapon();
115: tempWeaponList.Add(tempWeapon);
116:
117: XmlNodeList list = elemList[i].ChildNodes;
118: for (int x = 0; x < list.Count; x++)
119: {
120: string attr = list[x].Name;
121: string attrValue = list[x].InnerText;
122: char[] delimiter = ",".ToCharArray();;
123: string[] values;
124: switch (attr)
125: {
126: case "NumberOfHands":
127: tempWeaponList[i].p_NumberOfHands = int.Parse(attrValue);
128: break;
129: case "Ranged":
130: tempWeaponList[i].p_Ranged = bool.Parse(attrValue);
131: break;
132: case "Name":
133: tempWeaponList[i].p_WeaponName = attrValue;
134: break;
135: case "PlusMinus":
136: tempWeaponList[i].p_WeaponDamagePlusMinus = int.Parse(attrValue);
137: break;
138: case "Damage":
139: tempWeaponList[i].p_WeaponDamage = int.Parse(attrValue);
140: break;
141: case "Encumbrance":
142: tempWeaponList[i].p_Encumberance = int.Parse(attrValue);
143: break;
144: case "Value":
145: tempWeaponList[i].p_Value = int.Parse(attrValue);
146: break;
147: case "ImagePosX":
148: tempWeaponList[i].p_WeaponImagePosX = int.Parse(attrValue);
149: break;
150: case "ImagePosY":
151: tempWeaponList[i].p_WeaponImagePosY = int.Parse(attrValue);
152: break;
153: case "Description":
154: tempWeaponList[i].p_WeaponDescription = attrValue;
155: break;
156: case "IsConsumable":
157: tempWeaponList[i].p_IsConsumable = bool.Parse(attrValue); ;
158: break;
159: case "RotateOnOverlap":
160: tempWeaponList[i].p_RotateOnOverlap = bool.Parse(attrValue); ;
161: break;
162: case "RotateOnIdleToMatchHands":
163: tempWeaponList[i].p_RotateOnIdleToMatchHands = bool.Parse(attrValue); ;
164: break;
165: case "RangedModifier":
166: tempWeaponList[i].m_RangedSpeedModifier = int.Parse(attrValue);
167: break;
168: case "EquipFx":
169: tempWeaponList[i].p_EquipFx = attrValue;
170: break;
171: case "HitFx":
172: values = attrValue.Split(delimiter);
173: tempWeaponList[i].m_HitFx = new List<string>(values.Length);
174: tempWeaponList[i].m_HitFx.AddRange(values);
175: break;
176: case "EquippedImageLoc":
177: values = attrValue.Split(delimiter);
178: tempWeaponList[i].m_EquippedImageLoc.X = int.Parse(values[0]);
179: tempWeaponList[i].m_EquippedImageLoc.Y = int.Parse(values[1]);
180: break;
181: case "EquippedImageHotSpot":
182: values = attrValue.Split(delimiter);
183: tempWeaponList[i].m_EquippedWeaponImageHotSpot.X = int.Parse(values[0]);
184: tempWeaponList[i].m_EquippedWeaponImageHotSpot.Y = int.Parse(values[1]);
185: break;
186: default:
187: Log.WriteToLog("***Error: LoadIntoMemoryAllWeapons: " + attr);
188: break;
189: }
190: }
191: }
192: return 0;
193: }
194: public static Weapon ReturnWeaponFromString(string sWeaponName)
195: {
196: // Returns a Weapon object depending on what string name was passed to it.
197: foreach (Weapon el in g_GlobalWeaponList)
198: {
199: if (el.p_WeaponName.Equals(sWeaponName))
200: {
201: return el;
202: }
203: }
204: Log.WriteToLog("***Error: in ReturnWeaponFromString: Unknown weapon: " + sWeaponName);
205: return new Weapon();
206: }
207: public string ReturnPrettyDescription()
208: {
209: return this.p_WeaponDescription + "\n" + this.ReturnStats();
210: }
211: public string ReturnStats()
212: {
213: char plusMinus = (char)177;
214: if (this.m_IsConsumable)
215: {
216: return "Restores: ~" +
217: this.p_WeaponDamage.ToString() + plusMinus + this.p_WeaponDamagePlusMinus.ToString() + "~";
218: }
219: else
220: {
221: return "Damage: ~" +
222: this.p_WeaponDamage.ToString() + plusMinus + this.p_WeaponDamagePlusMinus.ToString() + "~";
223: }
224: }
225: public static bool IsWeapon(string sWeaponName)
226: {
227: foreach (Weapon el in g_GlobalWeaponList)
228: {
229: if (el.p_WeaponName.Equals(sWeaponName))
230: {
231: return true;
232: }
233: }
234: // This is not a weapon:
235: return false;
236: }
237: public static int ReturnValue(string sWeaponName)
238: {
239: Weapon w = Weapon.ReturnWeaponFromString(sWeaponName);
240: int value = w.p_Value;
241: if (w.p_Value == 0)
242: {
243: value = w.p_WeaponDamage * 10 + w.p_WeaponDamagePlusMinus * 5;
244: }
245: return value;
246: }
247:
248: }