| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- using SOTF_Struct.Generic;
- using System.Text.Json.Serialization;
- using System;
- using System.Collections.Generic;
- namespace SOTF_Struct.Data {
- public class SaveData_VailWorldSim {
- public class ActorInfo {
- private int _typeID;
- private int _count;
- private double _maxHealth;
- public ActorInfo(int TypeID) {
- this._typeID = TypeID;
- this._count = 0;
- this._maxHealth = 0;
- }
- public int TypeId {
- get => this._typeID;
- }
- public int Count { get => this._count; set => this._count = value; }
- public double MaxHealth { get => this._maxHealth; set => this._maxHealth = value; }
- }
- public string Version { get; set; }
- public List<Actor> Actors { get; set; }
- public List<SaveData_Spawner> Spawners { get; set; }
- [JsonIgnore(Condition = JsonIgnoreCondition.Never)]
- public List<SaveData_EventMemory> EventMemory { get; set; }
- public List<InfluenceMemoryList> InfluenceMemory { get; set; }
- public List<SaveData_KillStat> KillStatsList { get; set; }
- public List<SaveData_WorldEvent> WorldEvents { get; set; }
- public SaveData_PlayerStats PlayerStats { get; set; }
- private Dictionary<int, ActorInfo?>? _actorCounter { get; set; } = null;
- public void RefreshActorCounter() {
- if (this._actorCounter == null)
- this._actorCounter = new Dictionary<int, ActorInfo>();
- else
- this._actorCounter.Clear();
- foreach(Actor a in this.Actors) {
- if (!this._actorCounter.ContainsKey(a.TypeId))
- this._actorCounter.Add(a.TypeId, new ActorInfo(a.TypeId));
- this._actorCounter[a.TypeId].Count++;
- if (this._actorCounter[a.TypeId].MaxHealth < a.Stats.Health)
- this._actorCounter[a.TypeId].MaxHealth = a.Stats.Health;
- }
- }
- [JsonIgnore(Condition = JsonIgnoreCondition.Always)]
- public Dictionary<int, ActorInfo?> ActorCounter {
- get {
- if (this._actorCounter == null)
- this.RefreshActorCounter();
- return this._actorCounter;
- }
- }
- public InfluenceMemoryList? GetInfluenceMemoryList(Actor a) {
- foreach (InfluenceMemoryList im in this.InfluenceMemory)
- if (im.UniqueId == a.UniqueId)
- return im;
- return null;
- }
- public InfluenceMemoryList? GetInfluenceMemoryList(int id) {
- foreach (InfluenceMemoryList im in this.InfluenceMemory)
- if (im.UniqueId == id)
- return im;
- return null;
- }
- public Influence? GetInfluenceMemory(Actor a, string Type) {
- foreach (InfluenceMemoryList im in this.InfluenceMemory)
- if (im.UniqueId == a.UniqueId)
- foreach (Influence i in im.Influences)
- if (i.TypeId.ToLower() == Type.ToLower())
- return i;
- return null;
- }
- public Influence? GetInfluenceMemory(int id, string Type) {
- foreach (InfluenceMemoryList im in this.InfluenceMemory)
- if (im.UniqueId == id)
- foreach(Influence i in im.Influences)
- if(i.TypeId.ToLower() == Type.ToLower())
- return i;
- return null;
- }
- public void RemoveInfluenceMemory(int actor, string Type) {
- for(int i=this.InfluenceMemory.Count-1; i>=0; i--)
- if (this.InfluenceMemory[i].UniqueId == actor)
- for(int j = this.InfluenceMemory[i].Influences.Count-1; j>=0;j--)
- if (this.InfluenceMemory[i].Influences[j].TypeId.ToLower() == Type.ToLower()) {
- this.InfluenceMemory[i].Influences.RemoveAt(j);
- return;
- }
- }
- public void RemoveInfluenceMemory(Actor actor, string Type) {
- for (int i = this.InfluenceMemory.Count - 1; i >= 0; i--)
- if (this.InfluenceMemory[i].UniqueId == actor.TypeId)
- for (int j = this.InfluenceMemory[i].Influences.Count - 1; j >= 0; j--)
- if (this.InfluenceMemory[i].Influences[j].TypeId.ToLower() == Type.ToLower()) {
- this.InfluenceMemory[i].Influences.RemoveAt(j);
- return;
- }
- }
- public void RemoveInfluenceMemory(Actor actor) {
- for (int i = this.InfluenceMemory.Count - 1; i >= 0; i--)
- if (this.InfluenceMemory[i].UniqueId == actor.TypeId) {
- this.InfluenceMemory.RemoveAt(i);
- return;
- }
- }
- public void RemoveInfluenceMemory(int actor) {
- for (int i = this.InfluenceMemory.Count - 1; i >= 0; i--)
- if (this.InfluenceMemory[i].UniqueId == actor) {
- this.InfluenceMemory.RemoveAt(i);
- return;
- }
- }
- public Actor? GetFirstActor(int TypeID) {
- foreach (Actor a in Actors)
- if (a.TypeId == TypeID)
- return a;
- return null;
- }
- public Actor[] GetActorsByType(int TypeID) {
- List<Actor> res = new List<Actor>();
- foreach (Actor a in Actors)
- if (a.TypeId == TypeID)
- res.Add(a);
- return res.ToArray();
- }
- public Actor[] GetActorsByFamily(int FamilyID) {
- List<Actor> res = new List<Actor>();
- foreach (Actor a in Actors)
- if (a.FamilyId == FamilyID)
- res.Add(a);
- return res.ToArray();
- }
- public Actor[] GetActorBySpawner(int ID) {
- List<Actor> res = new List<Actor>();
- foreach(Actor a in this.Actors) {
- if (a.SpawnerId == ID)
- res.Add(a);
- }
- return res.ToArray();
- }
- public Actor[] GetActorBySpawner(SaveData_Spawner spawner) {
- List<Actor> res = new List<Actor>();
- foreach (Actor a in this.Actors) {
- if (a.SpawnerId == spawner.UniqueId)
- res.Add(a);
- }
- return res.ToArray();
- }
- public int CreateActor(int TypeId) {
- Actor a = new Actor();
- a.Position = new Position();
- a.Rotation = new Rotation();
- a.Stats = new Actor.ActorStats();
- a.TypeId = TypeId;
- a.VariationId = -1;
- a.GraphMask = 1;
- a.EquippedItems = null;
- a.SpawnerId = 0;
- a.ActorSeed = 0;
- a.OutfitId = -1;
- a.NextGiftTime = 0.0f;
- a.LastVisitTime = -100.0f;
- // Stats
- a.Stats.Anger = 0.0f;
- a.Stats.Health = 0.0f;
- a.Stats.Fear = 0.0f;
- a.Stats.Affection = 0.0f;
- a.Stats.Anger = 0.0f;
- a.Stats.Energy = 0.0f;
- a.Stats.Hydration = 0.0f;
- a.Stats.Fullness = 0.0f;
- a.StateFlags = 0;
- // Position
- Position? pos = SOTF_Struct.LocationList.GetRandomPosition(a.GraphMask,eLocationList.Actor);
- if (pos != null)
- a.Position = pos;
- a.FamilyId = 0;
- a.UniqueId = this.GetUniqueID();
- int newID = this.Actors.Count();
- this.Actors.Add(a);
- return newID;
- }
- public int CreateActor(int TypeId, Position pos) {
- Actor a = new Actor();
- a.Position = new Position();
- a.Rotation = new Rotation();
- a.Stats = new Actor.ActorStats();
- a.TypeId = TypeId;
- a.VariationId = -1;
- a.GraphMask = 1;
- a.EquippedItems = null;
- a.SpawnerId = 0;
- a.ActorSeed = 0;
- a.OutfitId = -1;
- a.NextGiftTime = 0.0f;
- a.LastVisitTime = -100.0f;
- // Stats
- a.Stats.Anger = 0.0f;
- a.Stats.Health = 0.0f;
- a.Stats.Fear = 0.0f;
- a.Stats.Affection = 0.0f;
- a.Stats.Anger = 0.0f;
- a.Stats.Energy = 0.0f;
- a.Stats.Hydration = 0.0f;
- a.Stats.Fullness = 0.0f;
- a.StateFlags = 0;
- // Position
- a.Position = pos;
- a.FamilyId = 0;
- a.UniqueId = this.GetUniqueID();
- int newID = this.Actors.Count();
- this.Actors.Add(a);
- return newID;
- }
- public int GetUniqueID() {
- for(int i = 40000;i<60000;i++)
- foreach(Actor a in this.Actors) {
- if(a.UniqueId!=i) return i;
- }
- return -1;
- }
- }
- }
|