source: OniSplit/Objects/Neutral.cs@ 1119

Last change on this file since 1119 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 5.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using Oni.Metadata;
5
6namespace Oni.Objects
7{
8 internal class Neutral : ObjectBase
9 {
10 public string Name;
11 public int Id;
12 public NeutralFlags Flags;
13 public float TriggerRange;
14 public float TalkRange;
15 public float FollowRange;
16 public float AbortEnemyRange;
17 public string TriggerSpeech;
18 public string AbortSpeech;
19 public string EnemySpeech;
20 public string EndScript;
21 public string WeaponClass;
22 public int AmmoAmount;
23 public int CellAmount;
24 public int HypoAmount;
25 public NeutralItems OtherItems;
26 public NeutralDialogLine[] Lines;
27
28 public Neutral()
29 {
30 TypeId = ObjectType.Neutral;
31 }
32
33 protected override void WriteOsd(BinaryWriter writer)
34 {
35 writer.Write(Name, 32);
36 writer.WriteUInt16(Id);
37 writer.WriteUInt16(Lines.Length);
38 writer.Write((int)Flags);
39 writer.Write(TriggerRange);
40 writer.Write(TalkRange);
41 writer.Write(FollowRange);
42 writer.Write(AbortEnemyRange);
43 writer.Write(TriggerSpeech, 32);
44 writer.Write(AbortSpeech, 32);
45 writer.Write(EnemySpeech, 32);
46 writer.Write(EndScript, 32);
47 writer.Write(WeaponClass, 32);
48 writer.WriteByte(AmmoAmount);
49 writer.WriteByte(CellAmount);
50 writer.WriteByte(HypoAmount);
51 writer.WriteByte((byte)OtherItems);
52
53 foreach (var line in Lines)
54 {
55 writer.Write((int)line.Flags);
56 writer.WriteUInt16((ushort)line.AnimType);
57 writer.WriteUInt16((ushort)line.OtherAnimationType);
58 writer.Write(line.Speech, 32);
59 }
60 }
61
62 protected override void ReadOsd(BinaryReader reader)
63 {
64 Name = reader.ReadString(32);
65 Id = reader.ReadInt16();
66 Lines = new NeutralDialogLine[reader.ReadInt16()];
67 Flags = (NeutralFlags)reader.ReadInt32();
68 TriggerRange = reader.ReadSingle();
69 TalkRange = reader.ReadSingle();
70 FollowRange = reader.ReadSingle();
71 AbortEnemyRange = reader.ReadSingle();
72 TriggerSpeech = reader.ReadString(32);
73 AbortSpeech = reader.ReadString(32);
74 EnemySpeech = reader.ReadString(32);
75 EndScript = reader.ReadString(32);
76 WeaponClass = reader.ReadString(32);
77 AmmoAmount = reader.ReadByte();
78 CellAmount = reader.ReadByte();
79 HypoAmount = reader.ReadByte();
80 OtherItems = (NeutralItems)reader.ReadByte();
81
82 for (int i = 0; i < Lines.Length; i++)
83 {
84 Lines[i] = new NeutralDialogLine
85 {
86 Flags = (NeutralDialogLineFlags)reader.ReadInt32(),
87 AnimType = (Totoro.AnimationType)reader.ReadUInt16(),
88 OtherAnimationType = (Totoro.AnimationType)reader.ReadUInt16(),
89 Speech = reader.ReadString(32)
90 };
91 }
92 }
93
94 protected override void ReadOsd(XmlReader xml, ObjectLoadContext context)
95 {
96 Name = xml.ReadElementContentAsString("Name", "");
97 Id = xml.ReadElementContentAsInt("NeutralId", "");
98 Flags = xml.ReadElementContentAsEnum<NeutralFlags>("Flags");
99 xml.ReadStartElement("Ranges");
100 TriggerRange = xml.ReadElementContentAsFloat("Trigger", "");
101 TalkRange = xml.ReadElementContentAsFloat("Talk", "");
102 FollowRange = xml.ReadElementContentAsFloat("Follow", "");
103 AbortEnemyRange = xml.ReadElementContentAsFloat("Enemy", "");
104 xml.ReadEndElement();
105 xml.ReadStartElement("Speech");
106 TriggerSpeech = xml.ReadElementContentAsString("Trigger", "");
107 AbortSpeech = xml.ReadElementContentAsString("Abort", "");
108 EnemySpeech = xml.ReadElementContentAsString("Enemy", "");
109 xml.ReadEndElement();
110 xml.ReadStartElement("Script");
111 EndScript = xml.ReadElementContentAsString("AfterTalk", "");
112 xml.ReadEndElement();
113 xml.ReadStartElement("Rewards");
114 WeaponClass = xml.ReadElementContentAsString("WeaponClass", "");
115 AmmoAmount = xml.ReadElementContentAsInt("Ammo", "");
116 CellAmount = xml.ReadElementContentAsInt("EnergyCell", "");
117 HypoAmount = xml.ReadElementContentAsInt("Hypo", "");
118 OtherItems = xml.ReadElementContentAsEnum<NeutralItems>("Other");
119 xml.ReadEndElement();
120 xml.ReadStartElement("DialogLines");
121
122 var lineList = new List<NeutralDialogLine>();
123
124 while (xml.IsStartElement())
125 {
126 xml.ReadStartElement("DialogLine");
127
128 lineList.Add(new NeutralDialogLine
129 {
130 Flags = xml.ReadElementContentAsEnum<NeutralDialogLineFlags>("Flags"),
131 AnimType = xml.ReadElementContentAsEnum<Totoro.AnimationType>("Anim"),
132 OtherAnimationType = xml.ReadElementContentAsEnum<Totoro.AnimationType>("OtherAnim"),
133 Speech = xml.ReadElementContentAsString("SpeechName", "")
134 });
135
136 xml.ReadEndElement();
137 }
138
139 Lines = lineList.ToArray();
140
141 xml.ReadEndElement();
142 }
143
144 protected override void WriteOsd(XmlWriter xml)
145 {
146 throw new NotImplementedException();
147 }
148 }
149}
Note: See TracBrowser for help on using the repository browser.