SaveData_VailWorldSim.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. using SOTF_Struct.Generic;
  2. using System.Text.Json.Serialization;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace SOTF_Struct.Data {
  6. public class SaveData_VailWorldSim {
  7. public class ActorInfo {
  8. private int _typeID;
  9. private int _count;
  10. private double _maxHealth;
  11. public ActorInfo(int TypeID) {
  12. this._typeID = TypeID;
  13. this._count = 0;
  14. this._maxHealth = 0;
  15. }
  16. public int TypeId {
  17. get => this._typeID;
  18. }
  19. public int Count { get => this._count; set => this._count = value; }
  20. public double MaxHealth { get => this._maxHealth; set => this._maxHealth = value; }
  21. }
  22. public string Version { get; set; }
  23. public List<Actor> Actors { get; set; }
  24. public List<SaveData_Spawner> Spawners { get; set; }
  25. [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
  26. public List<SaveData_EventMemory> EventMemory { get; set; }
  27. public List<InfluenceMemoryList> InfluenceMemory { get; set; }
  28. public List<SaveData_KillStat> KillStatsList { get; set; }
  29. public List<SaveData_WorldEvent> WorldEvents { get; set; }
  30. public SaveData_PlayerStats PlayerStats { get; set; }
  31. private Dictionary<int, ActorInfo?>? _actorCounter { get; set; } = null;
  32. public void RefreshActorCounter() {
  33. if (this._actorCounter == null)
  34. this._actorCounter = new Dictionary<int, ActorInfo>();
  35. else
  36. this._actorCounter.Clear();
  37. foreach(Actor a in this.Actors) {
  38. if (!this._actorCounter.ContainsKey(a.TypeId))
  39. this._actorCounter.Add(a.TypeId, new ActorInfo(a.TypeId));
  40. this._actorCounter[a.TypeId].Count++;
  41. if (this._actorCounter[a.TypeId].MaxHealth < a.Stats.Health)
  42. this._actorCounter[a.TypeId].MaxHealth = a.Stats.Health;
  43. }
  44. }
  45. [JsonIgnore(Condition = JsonIgnoreCondition.Always)]
  46. public Dictionary<int, ActorInfo?> ActorCounter {
  47. get {
  48. if (this._actorCounter == null)
  49. this.RefreshActorCounter();
  50. return this._actorCounter;
  51. }
  52. }
  53. public InfluenceMemoryList? GetInfluenceMemoryList(Actor a) {
  54. foreach (InfluenceMemoryList im in this.InfluenceMemory)
  55. if (im.UniqueId == a.UniqueId)
  56. return im;
  57. return null;
  58. }
  59. public InfluenceMemoryList? GetInfluenceMemoryList(int id) {
  60. foreach (InfluenceMemoryList im in this.InfluenceMemory)
  61. if (im.UniqueId == id)
  62. return im;
  63. return null;
  64. }
  65. public Influence? GetInfluenceMemory(Actor a, string Type) {
  66. foreach (InfluenceMemoryList im in this.InfluenceMemory)
  67. if (im.UniqueId == a.UniqueId)
  68. foreach (Influence i in im.Influences)
  69. if (i.TypeId.ToLower() == Type.ToLower())
  70. return i;
  71. return null;
  72. }
  73. public Influence? GetInfluenceMemory(int id, string Type) {
  74. foreach (InfluenceMemoryList im in this.InfluenceMemory)
  75. if (im.UniqueId == id)
  76. foreach(Influence i in im.Influences)
  77. if(i.TypeId.ToLower() == Type.ToLower())
  78. return i;
  79. return null;
  80. }
  81. public void RemoveInfluenceMemory(int actor, string Type) {
  82. for(int i=this.InfluenceMemory.Count-1; i>=0; i--)
  83. if (this.InfluenceMemory[i].UniqueId == actor)
  84. for(int j = this.InfluenceMemory[i].Influences.Count-1; j>=0;j--)
  85. if (this.InfluenceMemory[i].Influences[j].TypeId.ToLower() == Type.ToLower()) {
  86. this.InfluenceMemory[i].Influences.RemoveAt(j);
  87. return;
  88. }
  89. }
  90. public void RemoveInfluenceMemory(Actor actor, string Type) {
  91. for (int i = this.InfluenceMemory.Count - 1; i >= 0; i--)
  92. if (this.InfluenceMemory[i].UniqueId == actor.TypeId)
  93. for (int j = this.InfluenceMemory[i].Influences.Count - 1; j >= 0; j--)
  94. if (this.InfluenceMemory[i].Influences[j].TypeId.ToLower() == Type.ToLower()) {
  95. this.InfluenceMemory[i].Influences.RemoveAt(j);
  96. return;
  97. }
  98. }
  99. public void RemoveInfluenceMemory(Actor actor) {
  100. for (int i = this.InfluenceMemory.Count - 1; i >= 0; i--)
  101. if (this.InfluenceMemory[i].UniqueId == actor.TypeId) {
  102. this.InfluenceMemory.RemoveAt(i);
  103. return;
  104. }
  105. }
  106. public void RemoveInfluenceMemory(int actor) {
  107. for (int i = this.InfluenceMemory.Count - 1; i >= 0; i--)
  108. if (this.InfluenceMemory[i].UniqueId == actor) {
  109. this.InfluenceMemory.RemoveAt(i);
  110. return;
  111. }
  112. }
  113. public Actor? GetFirstActor(int TypeID) {
  114. foreach (Actor a in Actors)
  115. if (a.TypeId == TypeID)
  116. return a;
  117. return null;
  118. }
  119. public Actor[] GetActorsByType(int TypeID) {
  120. List<Actor> res = new List<Actor>();
  121. foreach (Actor a in Actors)
  122. if (a.TypeId == TypeID)
  123. res.Add(a);
  124. return res.ToArray();
  125. }
  126. public Actor[] GetActorsByFamily(int FamilyID) {
  127. List<Actor> res = new List<Actor>();
  128. foreach (Actor a in Actors)
  129. if (a.FamilyId == FamilyID)
  130. res.Add(a);
  131. return res.ToArray();
  132. }
  133. public Actor[] GetActorBySpawner(int ID) {
  134. List<Actor> res = new List<Actor>();
  135. foreach(Actor a in this.Actors) {
  136. if (a.SpawnerId == ID)
  137. res.Add(a);
  138. }
  139. return res.ToArray();
  140. }
  141. public Actor[] GetActorBySpawner(SaveData_Spawner spawner) {
  142. List<Actor> res = new List<Actor>();
  143. foreach (Actor a in this.Actors) {
  144. if (a.SpawnerId == spawner.UniqueId)
  145. res.Add(a);
  146. }
  147. return res.ToArray();
  148. }
  149. public int CreateActor(int TypeId) {
  150. Actor a = new Actor();
  151. a.Position = new Position();
  152. a.Rotation = new Rotation();
  153. a.Stats = new Actor.ActorStats();
  154. a.TypeId = TypeId;
  155. a.VariationId = -1;
  156. a.GraphMask = 1;
  157. a.EquippedItems = null;
  158. a.SpawnerId = 0;
  159. a.ActorSeed = 0;
  160. a.OutfitId = -1;
  161. a.NextGiftTime = 0.0f;
  162. a.LastVisitTime = -100.0f;
  163. // Stats
  164. a.Stats.Anger = 0.0f;
  165. a.Stats.Health = 0.0f;
  166. a.Stats.Fear = 0.0f;
  167. a.Stats.Affection = 0.0f;
  168. a.Stats.Anger = 0.0f;
  169. a.Stats.Energy = 0.0f;
  170. a.Stats.Hydration = 0.0f;
  171. a.Stats.Fullness = 0.0f;
  172. a.StateFlags = 0;
  173. // Position
  174. Position? pos = SOTF_Struct.LocationList.GetRandomPosition(a.GraphMask,eLocationList.Actor);
  175. if (pos != null)
  176. a.Position = pos;
  177. a.FamilyId = 0;
  178. a.UniqueId = this.GetUniqueID();
  179. int newID = this.Actors.Count();
  180. this.Actors.Add(a);
  181. return newID;
  182. }
  183. public int CreateActor(int TypeId, Position pos) {
  184. Actor a = new Actor();
  185. a.Position = new Position();
  186. a.Rotation = new Rotation();
  187. a.Stats = new Actor.ActorStats();
  188. a.TypeId = TypeId;
  189. a.VariationId = -1;
  190. a.GraphMask = 1;
  191. a.EquippedItems = null;
  192. a.SpawnerId = 0;
  193. a.ActorSeed = 0;
  194. a.OutfitId = -1;
  195. a.NextGiftTime = 0.0f;
  196. a.LastVisitTime = -100.0f;
  197. // Stats
  198. a.Stats.Anger = 0.0f;
  199. a.Stats.Health = 0.0f;
  200. a.Stats.Fear = 0.0f;
  201. a.Stats.Affection = 0.0f;
  202. a.Stats.Anger = 0.0f;
  203. a.Stats.Energy = 0.0f;
  204. a.Stats.Hydration = 0.0f;
  205. a.Stats.Fullness = 0.0f;
  206. a.StateFlags = 0;
  207. // Position
  208. a.Position = pos;
  209. a.FamilyId = 0;
  210. a.UniqueId = this.GetUniqueID();
  211. int newID = this.Actors.Count();
  212. this.Actors.Add(a);
  213. return newID;
  214. }
  215. public int GetUniqueID() {
  216. for(int i = 40000;i<60000;i++)
  217. foreach(Actor a in this.Actors) {
  218. if(a.UniqueId!=i) return i;
  219. }
  220. return -1;
  221. }
  222. }
  223. }