| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using SOTF_Struct.Generic;
- namespace SOTF_Savegame_Editor {
- partial class frmMain {
- public class FamilyInfo {
- public FamilyInfo() {
- }
- public FamilyInfo(int FamilyID) {
- this.FamilyID = FamilyID;
- }
- private Influence Influence_Player_Total = new Influence();
- private Influence Influence_Cannibal_Total = new Influence();
- private Influence Influence_Creepy_Total = new Influence();
- private int Influence_Player_Count = 0;
- private int Influence_Cannibal_Count = 0;
- private int Influence_Creepy_Count = 0;
- public Influence Influence_Player = new Influence();
- public Influence Influence_Cannibal = new Influence();
- public Influence Influence_Creepy = new Influence();
- public int FamilyID = 0;
- public List<int> actorID = new List<int>();
- private int _creeps = 0;
- private int _animals = 0;
- private int _cannibals = 0;
- private int _females = 0;
- private int _males = 0;
- private int _diverse = 0;
- private int _npc = 0;
- public int Creeps { get => this._creeps; }
- public int Animals { get => this._animals; }
- public int Cannibals { get => this._cannibals; }
- public int Females { get => this._females; }
- public int Males { get => this._males; }
- public int NPC { get => this._npc; }
- public int InfluencedByPlayer {
- get => this.Influence_Player_Count;
- }
- public int InfluencedByCreep {
- get => this.Influence_Creepy_Count;
- }
- public int InfluencedByCannibal {
- get => this.Influence_Cannibal_Count;
- }
- public int ActorCount {
- get {
- return this._animals + this._cannibals + this._creeps + this._npc;
- }
- }
- public string _familyType = "";
- public string FamilyType {
- get {
- if (this._familyType == "")
- this.RefreshFamilyType();
- return this._familyType;
- }
- }
- private void RefreshFamilyType() {
- string prefix1 = "";
- string prefix2 = "";
- string name = "";
- string surfix = "";
- string gendre = "";
- if (this._males == 0 && this._diverse == 0 && this._females > 0)
- gendre = "female ";
- else if (this._males > 0 && this._diverse == 0 && this._females == 0)
- gendre = "male ";
- if (this.Influence_Player.Fear > 80)
- prefix1 = "scared ";
- else if (this.Influence_Player.Fear > 60)
- prefix1 = "fearing ";
- else if (this.Influence_Player.Fear > 40)
- prefix1 = "awed ";
- else if (this.Influence_Player.Fear > 40)
- prefix1 = "distrusted ";
- if (this.Influence_Player.Anger > 80 && this.Influence_Player.Sentiment < 10)
- prefix2 = "bloodlust ";
- else if (this.Influence_Player.Anger > 80 && this.Influence_Player.Sentiment < 60)
- prefix2 = "aggressive ";
- else if (this.Influence_Player.Anger > 60 && this.Influence_Player.Sentiment < 10)
- prefix2 = "angry ";
- else if (this.Influence_Player.Anger > 70 && this.Influence_Player.Sentiment < 20)
- prefix2 = "angry ";
- else if (this.Influence_Player.Anger > 50 && this.Influence_Player.Sentiment < 20)
- prefix2 = "wrathful ";
- else if (this.Influence_Player.Anger > 20 && this.Influence_Player.Sentiment < 20)
- prefix2 = "upset ";
- else if (this.Influence_Player.Anger < 60 && this.Influence_Player.Sentiment > 80)
- prefix2 = "lionized ";
- else if (this.Influence_Player.Anger < 10 && this.Influence_Player.Sentiment > 60)
- prefix2 = "loving ";
- else if (this.Influence_Player.Anger < 20 && this.Influence_Player.Sentiment > 70)
- prefix2 = "bundling ";
- else if (this.Influence_Player.Anger < 20 && this.Influence_Player.Sentiment > 50)
- prefix2 = "carring ";
- else if (this.Influence_Player.Anger < 20 && this.Influence_Player.Sentiment > 20)
- prefix2 = "liked ";
- if (this._animals >= 1 && this._cannibals == 0 && this._creeps == 0 && this._npc == 0)
- name = "Animals";
- else if (this._animals == 0 && this._cannibals >= 1 && this._creeps == 0 && this._npc == 0)
- name = "Canibals";
- else if (this._animals == 0 && this._cannibals == 0 && this._creeps >= 1 && this._npc == 0)
- name = "Creeps";
- else if (this._animals == 0 && this._cannibals == 0 && this._creeps == 0 && this._npc >= 1)
- name = "NPCs";
- else if (this._animals == 0 && this._cannibals >= 1 && this._creeps >= 1 && this._npc == 0)
- name = "Foes";
- else if (this._animals >= 1 && this._cannibals == 0 && this._creeps == 0 && this._npc >= 1)
- name = "Neutrals";
- else
- name = "Somethin";
- int mob = this._npc + this._animals + this._cannibals + this._creeps;
- if (mob > 50) surfix = " of the Gods";
- else if (mob > 30) surfix = " of the Army";
- else if (mob > 20) surfix = " of the Gang";
- else if (mob > 15) surfix = " of the Tribe";
- else if (mob > 10) surfix = " of the Family";
- string combined = prefix1 + prefix2 + gendre + name + surfix;
- combined = combined.Substring(0, 1).ToUpper() + combined.Substring(1);
- this._familyType = combined;
- }
- public void AddInfluence(Influence i) {
- if (i.TypeId.ToLower() == "player") {
- this.Influence_Player_Count++;
- this.Influence_Player_Total += i;
- this.Influence_Player = this.Influence_Player_Total / this.Influence_Player_Count;
- } else if (i.TypeId.ToLower() == "cannibal") {
- this.Influence_Cannibal_Count++;
- this.Influence_Cannibal_Total += i;
- this.Influence_Cannibal = this.Influence_Cannibal_Total / this.Influence_Cannibal_Count;
- } else if (i.TypeId.ToLower() == "creepy") {
- this.Influence_Creepy_Count++;
- this.Influence_Creepy_Total += i;
- this.Influence_Creepy = this.Influence_Creepy_Total / this.Influence_Creepy_Count;
- }
- }
- public void AddInfluence(Influence[] ins) {
- foreach (Influence i in ins) {
- if (i.TypeId.ToLower() == "player") {
- this.Influence_Player_Count++;
- this.Influence_Player_Total += i;
- } else if (i.TypeId.ToLower() == "cannibal") {
- this.Influence_Cannibal_Count++;
- this.Influence_Cannibal_Total += i;
- } else if (i.TypeId.ToLower() == "creepy") {
- this.Influence_Creepy_Count++;
- this.Influence_Creepy_Total += i;
- }
- }
- this.Influence_Player = this.Influence_Player_Total / this.Influence_Player_Count;
- this.Influence_Cannibal = this.Influence_Cannibal_Total / this.Influence_Cannibal_Count;
- this.Influence_Creepy = this.Influence_Creepy_Total / this.Influence_Creepy_Count;
- this._familyType = "";
- }
- public void AddInfluence(List<Influence> ins) {
- foreach (Influence i in ins) {
- if (i.TypeId.ToLower() == "player") {
- this.Influence_Player_Count++;
- this.Influence_Player_Total += i;
- } else if (i.TypeId.ToLower() == "cannibal") {
- this.Influence_Cannibal_Count++;
- this.Influence_Cannibal_Total += i;
- } else if (i.TypeId.ToLower() == "creepy") {
- this.Influence_Creepy_Count++;
- this.Influence_Creepy_Total += i;
- }
- }
- this.Influence_Player = this.Influence_Player_Total / this.Influence_Player_Count;
- this.Influence_Cannibal = this.Influence_Cannibal_Total / this.Influence_Cannibal_Count;
- this.Influence_Creepy = this.Influence_Creepy_Total / this.Influence_Creepy_Count;
- this._familyType = "";
- }
- public void AddActor(int index, Actor a) {
- if (!this.actorID.Contains(index))
- this.actorID.Add(index);
- if (a.TypeId <= 7) this._animals++;
- else if (a.TypeId <= 10) this._npc++;
- else if (a.TypeId == 11) this._creeps++;
- else if (a.TypeId <= 16) this._cannibals++;
- else if (a.TypeId == 17) this._animals++;
- else if (a.TypeId <= 21) this._creeps++;
- else if (a.TypeId <= 31) this._cannibals++;
- else if (a.TypeId <= 37) this._animals++;
- else if (a.TypeId == 38) this._cannibals++;
- else if (a.TypeId == 39) this._npc++;
- else if (a.TypeId <= 42) this._creeps++;
- else if (a.TypeId <= 44) this._cannibals++;
- else if (a.TypeId <= 47) this._creeps++;
- if (a.Gendre == 0) this._diverse++;
- else if (a.Gendre == 1) this._males++;
- else if (a.Gendre == 2) this._females++;
- this._familyType = "";
- }
- }
- private void UpdateFamilyList() {
- this.tvFamily.BeginUpdate();
- this.tvFamily.Nodes.Clear();
- Dictionary<int, FamilyInfo> familyList = new Dictionary<int, FamilyInfo>();
- for (int i = 0, c = this.saveData.VailWorldSim.Actors.Count; i < c; i++) {
- if (!familyList.ContainsKey(this.saveData.VailWorldSim.Actors[i].FamilyId))
- familyList.Add(this.saveData.VailWorldSim.Actors[i].FamilyId, new FamilyInfo(this.saveData.VailWorldSim.Actors[i].FamilyId));
- familyList[this.saveData.VailWorldSim.Actors[i].FamilyId].AddActor(i, this.saveData.VailWorldSim.Actors[i]);
- foreach (InfluenceMemoryList iL in this.saveData.VailWorldSim.InfluenceMemory) {
- if (iL.UniqueId == this.saveData.VailWorldSim.Actors[i].UniqueId)
- familyList[this.saveData.VailWorldSim.Actors[i].FamilyId].AddInfluence(iL.Influences);
- }
- }
- foreach (KeyValuePair<int, FamilyInfo> p in familyList) {
- string name = p.Value.FamilyType;
- TreeNode node = null;
- foreach (TreeNode n in this.tvFamily.Nodes)
- if (n.Text == name) {
- node = n;
- break;
- }
- if (node == null)
- node = tvFamily.Nodes.Add(name);
- node.Nodes.Add(new TreeNode() { Text = p.Key.ToString() + " [" + p.Value.ActorCount + "]", Tag = p.Value });
- }
- this.tvFamily.EndUpdate();
- }
- private void tvFamily_AfterSelect(object sender, TreeViewEventArgs e) {
- if (e.Node == null) {
- // No node selected
- this.ShowMiniMapItem(null);
- this.flowFamily.Controls.Clear();
- this.cbFamily_Anger.Enabled = false;
- this.cbFamily_Fear.Enabled = false;
- this.cbFamily_Sentiment.Enabled = false;
- this.lblFamily_Anger.Text = "-";
- this.lblFamily_Fear.Text = "-";
- this.lblFamily_Sentiment.Text = "-";
- this.lblFamilyName.Text = "-";
- this.cmdFamily_InfluencesRemove.Enabled = false;
- this.cmdFamily_InfluencesExisting.Enabled = false;
- this.cmdFamily_InfluencesAll.Enabled = false;
- } else if (e.Node.Tag == null) {
- this.ShowMiniMapItem(null);
- this.flowFamily.Controls.Clear();
- this.cbFamily_Anger.Enabled = false;
- this.cbFamily_Fear.Enabled = false;
- this.cbFamily_Sentiment.Enabled = false;
- this.lblFamily_Anger.Text = "-";
- this.lblFamily_Fear.Text = "-";
- this.lblFamily_Sentiment.Text = "-";
- this.lblFamilyName.Text = "-";
- this.cmdFamily_InfluencesRemove.Enabled = false;
- this.cmdFamily_InfluencesExisting.Enabled = false;
- this.cmdFamily_InfluencesAll.Enabled = false;
- } else if (e.Node.Tag.GetType() == typeof(FamilyInfo)) {
- FamilyInfo family = (FamilyInfo)e.Node.Tag;
- ShowFamilyInfo(family);
- }
- }
- private void ShowFamilyInfo(FamilyInfo family) {
- this.cbFamily_Anger.Enabled = true;
- this.cbFamily_Fear.Enabled = true;
- this.cbFamily_Sentiment.Enabled = true;
- this.cbFamily_Anger.Value = family.Influence_Player.Anger;
- this.cbFamily_Fear.Value = family.Influence_Player.Fear;
- this.cbFamily_Sentiment.Value = family.Influence_Player.Sentiment;
- this.lblFamily_Anger.Text = family.Influence_Player.Anger.ToString("0.00") + " %";
- this.lblFamily_Fear.Text = family.Influence_Player.Fear.ToString("0.00") + " %";
- this.lblFamily_Sentiment.Text = family.Influence_Player.Sentiment.ToString("0.00") + " %";
- this.cmdFamily_InfluencesRemove.Enabled = family.InfluencedByPlayer > 0;
- this.cmdFamily_InfluencesExisting.Enabled = family.InfluencedByPlayer > 0;
- this.cmdFamily_InfluencesAll.Enabled = true;
- this.lblFamilyName.Text = family.FamilyType;
- if (family.actorID.Count > 0) {
- this.ShowMiniMapItem(new MiniMapItem(
- family.actorID[0],
- this.saveData.VailWorldSim.Actors[family.actorID[0]].GetDisplayName(),
- eMiniMapType.Actor,
- this.saveData.VailWorldSim.Actors[family.actorID[0]].Position
- ));
- this.flowFamily.Controls.Clear();
- Font xfont = new Font(this.Font.FontFamily, 14, FontStyle.Bold);
- for (int i = 0; i < Math.Min(family.actorID.Count, 150); i++) {
- Actor a = this.saveData.VailWorldSim.Actors[family.actorID[i]];
- ActorProfile ap = new ActorProfile(
- a,
- this.saveData.VailWorldSim.GetInfluenceMemory(a, "player")
- ) {
- AutoSize = false,
- Width = 160,
- Height = 150,
- Font = xfont,
- BorderStyle = BorderStyle.FixedSingle,
- Padding = new Padding(10)
- };
- ap.MouseDown += Ap_MouseDown;
- this.flowFamily.Controls.Add(ap);
- }
- }
- }
- private void Ap_MouseDown(object? sender, MouseEventArgs e) {
- ActorProfile ap = (ActorProfile)sender;
- if (ap.Actor != null) {
- this.ShowMiniMapItem(new MiniMapItem(
- 0,
- ap.Actor.GetDisplayName(),
- eMiniMapType.Actor,
- ap.Actor.Position
- ));
- }
- }
- [Flags]
- public enum eInfluence {
- Anger = 1,
- Fear = 2,
- Sentiment = 4
- }
- bool bFamily_InfluenceOnlyOnExisting = true;
- private void SetFamilyInfluence(FamilyInfo family, bool OnlyOnExisting, eInfluence state, double value) {
- this.SetFamilyInfluence(family, "player", OnlyOnExisting, state, value);
- }
- private void SetFamilyInfluence(FamilyInfo family, string Type, bool OnlyOnExisting, eInfluence state, double value) {
- for (int i = 0, c = family.actorID.Count; i < c; i++) {
- int actorTypeId = this.saveData.VailWorldSim.Actors[family.actorID[i]].TypeId;
- // Ignore Virginia and Kelvin
- if (actorTypeId == 9 && actorTypeId == 10)
- continue;
- bool bFound = false;
- int uniqueID = this.saveData.VailWorldSim.Actors[family.actorID[i]].UniqueId;
- if (Type.ToLower() == "player") {
- if (state.HasFlag(eInfluence.Anger))
- this.saveData.VailWorldSim.Actors[family.actorID[i]].Stats.Anger = value;
- if (state.HasFlag(eInfluence.Fear))
- this.saveData.VailWorldSim.Actors[family.actorID[i]].Stats.Fear = value;
- if (state.HasFlag(eInfluence.Sentiment))
- this.saveData.VailWorldSim.Actors[family.actorID[i]].Stats.Affection = value;
- }
- for (int j = 0, c2 = this.saveData.VailWorldSim.InfluenceMemory.Count; j < c2; j++) {
- if (this.saveData.VailWorldSim.InfluenceMemory[j].UniqueId == uniqueID) {
- for (int k = 0, c3 = this.saveData.VailWorldSim.InfluenceMemory[j].Influences.Count; k < c3; k++)
- if (this.saveData.VailWorldSim.InfluenceMemory[j].Influences[k].TypeId.ToLower() == Type.ToLower()) {
- if (state.HasFlag(eInfluence.Anger))
- this.saveData.VailWorldSim.InfluenceMemory[j].Influences[k].Anger = value;
- else if (state.HasFlag(eInfluence.Fear))
- this.saveData.VailWorldSim.InfluenceMemory[j].Influences[k].Fear = value;
- else if (state.HasFlag(eInfluence.Sentiment))
- this.saveData.VailWorldSim.InfluenceMemory[j].Influences[k].Sentiment = value;
- bFound = true;
- break;
- }
- }
- }
- if (bFound == false && OnlyOnExisting == false) {
- Influence inf = new Influence() {
- TypeId = "Player",
- Anger = (state.HasFlag(eInfluence.Anger) ? value : 0.0d),
- Fear = (state.HasFlag(eInfluence.Fear) ? value : 0.0d),
- Sentiment = (state.HasFlag(eInfluence.Sentiment) ? value : 0.0d)
- };
- this.saveData.VailWorldSim.InfluenceMemory.Add(
- new InfluenceMemoryList() {
- UniqueId = uniqueID,
- Influences = new List<Influence>() { inf }
- }
- );
- family.AddInfluence(inf);
- }
- }
- }
- private void cmsFamilyInfluence_Click(object sender, EventArgs e) {
- System.Diagnostics.Debug.WriteLine("cmsFamilyInfluence_Click(\"" + sender.ToString() + "\")");
- if (this.tvFamily.SelectedNode != null && this.tvFamily.SelectedNode.Tag.GetType() == typeof(FamilyInfo)) {
- System.Diagnostics.Debug.WriteLine(" - Get Family");
- FamilyInfo family = (FamilyInfo)this.tvFamily.SelectedNode.Tag;
- if (sender == this.cmsFamilyInfluence_AngerLow)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Anger, -100.0);
- else if (sender == this.cmsFamilyInfluence_AngerNeutral)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Anger, 0.0);
- else if (sender == this.cmsFamilyInfluence_AngerHigh)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Anger, 100.0);
- else if (sender == this.cmsFamilyInfluence_FearLow)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Fear, -100.0);
- else if (sender == this.cmsFamilyInfluence_FearNeutral)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Fear, 0.0);
- else if (sender == this.cmsFamilyInfluence_FearHigh)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Fear, 100.0);
- else if (sender == this.cmsFamilyInfluence_SentimentLow)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Sentiment, -100.0);
- else if (sender == this.cmsFamilyInfluence_SentimentNeutral)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Sentiment, 0.0);
- else if (sender == this.cmsFamilyInfluence_SentimentHigh)
- this.SetFamilyInfluence(family, bFamily_InfluenceOnlyOnExisting, eInfluence.Sentiment, 100.0);
- else
- System.Diagnostics.Debug.WriteLine(" - Sender not found");
- this.ShowFamilyInfo(family);
- } else {
- System.Diagnostics.Debug.WriteLine(" - notFound: " + (this.tvFamily.SelectedNode == null ? "null" : this.tvFamily.SelectedNode.Text));
- }
- }
- private void RemoveInfluence(FamilyInfo family) {
- this.RemoveInfluence(family, "player");
- }
- private void RemoveInfluence(FamilyInfo family, string Type) {
- for (int i = 0, c = family.actorID.Count; i < c; i++) {
- bool bFound = false;
- int uniqueID = this.saveData.VailWorldSim.Actors[family.actorID[i]].UniqueId;
- for (int j = this.saveData.VailWorldSim.InfluenceMemory.Count - 1; j >= 0; j--) {
- if (this.saveData.VailWorldSim.InfluenceMemory[j].UniqueId == uniqueID) {
- for (int k = this.saveData.VailWorldSim.InfluenceMemory[j].Influences.Count - 1; k >= 0; k--)
- if (this.saveData.VailWorldSim.InfluenceMemory[j].Influences[k].TypeId.ToLower() == Type.ToLower()) {
- this.saveData.VailWorldSim.InfluenceMemory[j].Influences.RemoveAt(k);
- if (this.saveData.VailWorldSim.InfluenceMemory[j].Influences.Count == 0) {
- this.saveData.VailWorldSim.InfluenceMemory.RemoveAt(j);
- }
- }
- }
- }
- }
- this.ShowFamilyInfo(family);
- }
- private void cmdFamily_Influences_Click(object sender, EventArgs e) {
- this.bFamily_InfluenceOnlyOnExisting = sender == this.cmdFamily_InfluencesExisting;
- Button cmd = (Button)sender;
- this.cmsFamilyInfluence.Show(cmd, 0, cmd.Height);
- }
- private void cmdFamily_InfluencesRemove_Click(object sender, EventArgs e) {
- if (this.tvFamily.SelectedNode != null && this.tvFamily.SelectedNode.Tag.GetType() == typeof(FamilyInfo)) {
- FamilyInfo family = (FamilyInfo)this.tvFamily.SelectedNode.Tag;
- this.RemoveInfluence(family);
- }
- }
- }
- }
|