|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using System.IO; |
| 7 | +using System.Xml.Linq; |
| 8 | +using ESPSharp.Enums; |
| 9 | +using ESPSharp.Enums.Flags; |
| 10 | +using ESPSharp.Interfaces; |
| 11 | +using ESPSharp.Subrecords; |
| 12 | +using ESPSharp.SubrecordCollections; |
| 13 | +using ESPSharp.DataTypes; |
| 14 | + |
| 15 | +namespace ESPSharp.Records |
| 16 | +{ |
| 17 | + public partial class Quest : Record, IEditorID { |
| 18 | + public SimpleSubrecord<String> EditorID { get; set; } |
| 19 | + public RecordReference Script { get; set; } |
| 20 | + public SimpleSubrecord<String> Name { get; set; } |
| 21 | + public SimpleSubrecord<String> LargeIcon { get; set; } |
| 22 | + public SimpleSubrecord<String> SmallIcon { get; set; } |
| 23 | + public QuestData Data { get; set; } |
| 24 | + public List<Condition> Conditions { get; set; } |
| 25 | + public List<QuestStage> Stages { get; set; } |
| 26 | + public List<QuestObjective> Objectives { get; set; } |
| 27 | + |
| 28 | + public override void ReadData(ESPReader reader, long dataEnd) |
| 29 | + { |
| 30 | + while (reader.BaseStream.Position < dataEnd) |
| 31 | + { |
| 32 | + string subTag = reader.PeekTag(); |
| 33 | + |
| 34 | + switch (subTag) |
| 35 | + { |
| 36 | + case "EDID": |
| 37 | + if (EditorID == null) |
| 38 | + EditorID = new SimpleSubrecord<String>(); |
| 39 | + |
| 40 | + EditorID.ReadBinary(reader); |
| 41 | + break; |
| 42 | + case "SCRI": |
| 43 | + if (Script == null) |
| 44 | + Script = new RecordReference(); |
| 45 | + |
| 46 | + Script.ReadBinary(reader); |
| 47 | + break; |
| 48 | + case "FULL": |
| 49 | + if (Name == null) |
| 50 | + Name = new SimpleSubrecord<String>(); |
| 51 | + |
| 52 | + Name.ReadBinary(reader); |
| 53 | + break; |
| 54 | + case "ICON": |
| 55 | + if (LargeIcon == null) |
| 56 | + LargeIcon = new SimpleSubrecord<String>(); |
| 57 | + |
| 58 | + LargeIcon.ReadBinary(reader); |
| 59 | + break; |
| 60 | + case "MICO": |
| 61 | + if (SmallIcon == null) |
| 62 | + SmallIcon = new SimpleSubrecord<String>(); |
| 63 | + |
| 64 | + SmallIcon.ReadBinary(reader); |
| 65 | + break; |
| 66 | + case "DATA": |
| 67 | + if (Data == null) |
| 68 | + Data = new QuestData(); |
| 69 | + |
| 70 | + Data.ReadBinary(reader); |
| 71 | + break; |
| 72 | + case "CTDA": |
| 73 | + if (Conditions == null) |
| 74 | + Conditions = new List<Condition>(); |
| 75 | + |
| 76 | + Condition tempCTDA = new Condition(); |
| 77 | + tempCTDA.ReadBinary(reader); |
| 78 | + Conditions.Add(tempCTDA); |
| 79 | + break; |
| 80 | + case "INDX": |
| 81 | + if (Stages == null) |
| 82 | + Stages = new List<QuestStage>(); |
| 83 | + |
| 84 | + QuestStage tempINDX = new QuestStage(); |
| 85 | + tempINDX.ReadBinary(reader); |
| 86 | + Stages.Add(tempINDX); |
| 87 | + break; |
| 88 | + case "QOBJ": |
| 89 | + if (Objectives == null) |
| 90 | + Objectives = new List<QuestObjective>(); |
| 91 | + |
| 92 | + QuestObjective tempQOBJ = new QuestObjective(); |
| 93 | + tempQOBJ.ReadBinary(reader); |
| 94 | + Objectives.Add(tempQOBJ); |
| 95 | + break; |
| 96 | + default: |
| 97 | + throw new Exception(); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + public override void WriteData(ESPWriter writer) |
| 103 | + { |
| 104 | + if (EditorID != null) |
| 105 | + EditorID.WriteBinary(writer); |
| 106 | + if (Script != null) |
| 107 | + Script.WriteBinary(writer); |
| 108 | + if (Name != null) |
| 109 | + Name.WriteBinary(writer); |
| 110 | + if (LargeIcon != null) |
| 111 | + LargeIcon.WriteBinary(writer); |
| 112 | + if (SmallIcon != null) |
| 113 | + SmallIcon.WriteBinary(writer); |
| 114 | + if (Data != null) |
| 115 | + Data.WriteBinary(writer); |
| 116 | + if (Conditions != null) |
| 117 | + foreach (var item in Conditions) |
| 118 | + item.WriteBinary(writer); |
| 119 | + if (Stages != null) |
| 120 | + foreach (var item in Stages) |
| 121 | + item.WriteBinary(writer); |
| 122 | + if (Objectives != null) |
| 123 | + foreach (var item in Objectives) |
| 124 | + item.WriteBinary(writer); |
| 125 | + } |
| 126 | + |
| 127 | + public override void WriteDataXML(XElement ele, ElderScrollsPlugin master) |
| 128 | + { |
| 129 | + XElement subEle; |
| 130 | + if (EditorID != null) |
| 131 | + { |
| 132 | + ele.TryPathTo("EditorID", true, out subEle); |
| 133 | + EditorID.WriteXML(subEle, master); |
| 134 | + } |
| 135 | + if (Script != null) |
| 136 | + { |
| 137 | + ele.TryPathTo("Script", true, out subEle); |
| 138 | + Script.WriteXML(subEle, master); |
| 139 | + } |
| 140 | + if (Name != null) |
| 141 | + { |
| 142 | + ele.TryPathTo("Name", true, out subEle); |
| 143 | + Name.WriteXML(subEle, master); |
| 144 | + } |
| 145 | + if (LargeIcon != null) |
| 146 | + { |
| 147 | + ele.TryPathTo("Icon/Large", true, out subEle); |
| 148 | + LargeIcon.WriteXML(subEle, master); |
| 149 | + } |
| 150 | + if (SmallIcon != null) |
| 151 | + { |
| 152 | + ele.TryPathTo("Icon/Small", true, out subEle); |
| 153 | + SmallIcon.WriteXML(subEle, master); |
| 154 | + } |
| 155 | + if (Data != null) |
| 156 | + { |
| 157 | + ele.TryPathTo("Data", true, out subEle); |
| 158 | + Data.WriteXML(subEle, master); |
| 159 | + } |
| 160 | + if (Conditions != null) |
| 161 | + { |
| 162 | + ele.TryPathTo("Conditions", true, out subEle); |
| 163 | + List<string> xmlNames = new List<string>{"Condition"}; |
| 164 | + int i = 0; |
| 165 | + foreach (var entry in Conditions) |
| 166 | + { |
| 167 | + i = i % xmlNames.Count(); |
| 168 | + XElement newEle = new XElement(xmlNames[i]); |
| 169 | + entry.WriteXML(newEle, master); |
| 170 | + subEle.Add(newEle); |
| 171 | + i++; |
| 172 | + } |
| 173 | + } |
| 174 | + if (Stages != null) |
| 175 | + { |
| 176 | + ele.TryPathTo("Stages", true, out subEle); |
| 177 | + List<string> xmlNames = new List<string>{"Stage"}; |
| 178 | + int i = 0; |
| 179 | + foreach (var entry in Stages) |
| 180 | + { |
| 181 | + i = i % xmlNames.Count(); |
| 182 | + XElement newEle = new XElement(xmlNames[i]); |
| 183 | + entry.WriteXML(newEle, master); |
| 184 | + subEle.Add(newEle); |
| 185 | + i++; |
| 186 | + } |
| 187 | + } |
| 188 | + if (Objectives != null) |
| 189 | + { |
| 190 | + ele.TryPathTo("Objectives", true, out subEle); |
| 191 | + List<string> xmlNames = new List<string>{"Objective"}; |
| 192 | + int i = 0; |
| 193 | + foreach (var entry in Objectives) |
| 194 | + { |
| 195 | + i = i % xmlNames.Count(); |
| 196 | + XElement newEle = new XElement(xmlNames[i]); |
| 197 | + entry.WriteXML(newEle, master); |
| 198 | + subEle.Add(newEle); |
| 199 | + i++; |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + public override void ReadDataXML(XElement ele, ElderScrollsPlugin master) |
| 205 | + { |
| 206 | + XElement subEle; |
| 207 | + |
| 208 | + if (ele.TryPathTo("EditorID", false, out subEle)) |
| 209 | + { |
| 210 | + if (EditorID == null) |
| 211 | + EditorID = new SimpleSubrecord<String>(); |
| 212 | + |
| 213 | + EditorID.ReadXML(subEle, master); |
| 214 | + } |
| 215 | + if (ele.TryPathTo("Script", false, out subEle)) |
| 216 | + { |
| 217 | + if (Script == null) |
| 218 | + Script = new RecordReference(); |
| 219 | + |
| 220 | + Script.ReadXML(subEle, master); |
| 221 | + } |
| 222 | + if (ele.TryPathTo("Name", false, out subEle)) |
| 223 | + { |
| 224 | + if (Name == null) |
| 225 | + Name = new SimpleSubrecord<String>(); |
| 226 | + |
| 227 | + Name.ReadXML(subEle, master); |
| 228 | + } |
| 229 | + if (ele.TryPathTo("Icon/Large", false, out subEle)) |
| 230 | + { |
| 231 | + if (LargeIcon == null) |
| 232 | + LargeIcon = new SimpleSubrecord<String>(); |
| 233 | + |
| 234 | + LargeIcon.ReadXML(subEle, master); |
| 235 | + } |
| 236 | + if (ele.TryPathTo("Icon/Small", false, out subEle)) |
| 237 | + { |
| 238 | + if (SmallIcon == null) |
| 239 | + SmallIcon = new SimpleSubrecord<String>(); |
| 240 | + |
| 241 | + SmallIcon.ReadXML(subEle, master); |
| 242 | + } |
| 243 | + if (ele.TryPathTo("Data", false, out subEle)) |
| 244 | + { |
| 245 | + if (Data == null) |
| 246 | + Data = new QuestData(); |
| 247 | + |
| 248 | + Data.ReadXML(subEle, master); |
| 249 | + } |
| 250 | + if (ele.TryPathTo("Conditions", false, out subEle)) |
| 251 | + { |
| 252 | + if (Conditions == null) |
| 253 | + Conditions = new List<Condition>(); |
| 254 | + |
| 255 | + foreach (XElement e in subEle.Elements()) |
| 256 | + { |
| 257 | + Condition tempCTDA = new Condition(); |
| 258 | + tempCTDA.ReadXML(e, master); |
| 259 | + Conditions.Add(tempCTDA); |
| 260 | + } |
| 261 | + } |
| 262 | + if (ele.TryPathTo("Stages", false, out subEle)) |
| 263 | + { |
| 264 | + if (Stages == null) |
| 265 | + Stages = new List<QuestStage>(); |
| 266 | + |
| 267 | + foreach (XElement e in subEle.Elements()) |
| 268 | + { |
| 269 | + QuestStage tempINDX = new QuestStage(); |
| 270 | + tempINDX.ReadXML(e, master); |
| 271 | + Stages.Add(tempINDX); |
| 272 | + } |
| 273 | + } |
| 274 | + if (ele.TryPathTo("Objectives", false, out subEle)) |
| 275 | + { |
| 276 | + if (Objectives == null) |
| 277 | + Objectives = new List<QuestObjective>(); |
| 278 | + |
| 279 | + foreach (XElement e in subEle.Elements()) |
| 280 | + { |
| 281 | + QuestObjective tempQOBJ = new QuestObjective(); |
| 282 | + tempQOBJ.ReadXML(e, master); |
| 283 | + Objectives.Add(tempQOBJ); |
| 284 | + } |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + } |
| 289 | +} |
0 commit comments