ScoutInstanceData.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using MaidStatus;
  4. using UnityEngine;
  5. namespace scoutmode
  6. {
  7. [Serializable]
  8. public class ScoutInstanceData : ISerializationCallbackReceiver, ICloneable
  9. {
  10. public void Apply(Maid maid)
  11. {
  12. if (this.enabled)
  13. {
  14. maid.status.relation = this.relation;
  15. maid.status.additionalRelation = this.additionalRelation;
  16. maid.status.likability = this.likability;
  17. maid.status.seikeiken = this.seikeiken;
  18. foreach (string flagName in maid.status.flags.GetKeyArray())
  19. {
  20. maid.status.RemoveFlag(flagName);
  21. }
  22. foreach (KeyValuePair<string, int> keyValuePair in this.maidFlags)
  23. {
  24. maid.status.AddFlag(keyValuePair.Key, keyValuePair.Value);
  25. }
  26. }
  27. }
  28. public void Create(Maid maid, string stageName, ScoutOptionData options)
  29. {
  30. if (maid == null || this.enabled)
  31. {
  32. return;
  33. }
  34. this.enabled = true;
  35. this.stageName = stageName;
  36. this.options = options;
  37. this.Update(maid);
  38. }
  39. public void Update(Maid maid)
  40. {
  41. if (maid == null)
  42. {
  43. return;
  44. }
  45. this.relation = maid.status.relation;
  46. this.additionalRelation = maid.status.additionalRelation;
  47. this.likability = maid.status.likability;
  48. this.seikeiken = maid.status.seikeiken;
  49. this.maidFlags = maid.status.flags.Copy();
  50. }
  51. public void Destroy()
  52. {
  53. this.enabled = false;
  54. }
  55. public void OnBeforeSerialize()
  56. {
  57. this.version = 1000;
  58. if (this.maidFlags == null)
  59. {
  60. this.maidFlags = new Dictionary<string, int>();
  61. }
  62. if (!this.enabled)
  63. {
  64. this.maidFlags.Clear();
  65. }
  66. this.maidFlags_Key = new string[this.maidFlags.Count];
  67. this.maidFlags_Value = new int[this.maidFlags.Count];
  68. int num = 0;
  69. foreach (KeyValuePair<string, int> keyValuePair in this.maidFlags)
  70. {
  71. this.maidFlags_Key[num] = keyValuePair.Key;
  72. this.maidFlags_Value[num] = keyValuePair.Value;
  73. num++;
  74. }
  75. }
  76. public void OnAfterDeserialize()
  77. {
  78. this.maidFlags = new Dictionary<string, int>();
  79. for (int i = 0; i < this.maidFlags_Key.Length; i++)
  80. {
  81. this.maidFlags.Add(this.maidFlags_Key[i], this.maidFlags_Value[i]);
  82. }
  83. }
  84. public object Clone()
  85. {
  86. ScoutInstanceData scoutInstanceData = (ScoutInstanceData)base.MemberwiseClone();
  87. return JsonUtility.FromJson<ScoutInstanceData>(JsonUtility.ToJson(this));
  88. }
  89. private const int FixVersion = 1000;
  90. public int version = 1000;
  91. public bool enabled;
  92. public Relation relation;
  93. public AdditionalRelation additionalRelation;
  94. public int likability;
  95. public string stageName;
  96. public Seikeiken seikeiken;
  97. public Dictionary<string, int> maidFlags = new Dictionary<string, int>();
  98. public ScoutOptionData options;
  99. [SerializeField]
  100. private string[] maidFlags_Key;
  101. [SerializeField]
  102. private int[] maidFlags_Value;
  103. }
  104. }