BuffInfo.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. using Server.MirEnvir;
  2. using Server.MirObjects;
  3. namespace Server.MirDatabase
  4. {
  5. public class BuffInfo
  6. {
  7. public BuffType Type { get; set; }
  8. public BuffStackType StackType { get; set; }
  9. public BuffProperty Properties { get; set; }
  10. public int Icon { get; set; }
  11. public bool Visible { get; set; }
  12. public static List<BuffInfo> Load()
  13. {
  14. List<BuffInfo> info = new List<BuffInfo>
  15. {
  16. //Magics
  17. new BuffInfo { Type = BuffType.TemporalFlux, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  18. new BuffInfo { Type = BuffType.Hiding, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  19. new BuffInfo { Type = BuffType.Haste, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  20. new BuffInfo { Type = BuffType.SwiftFeet, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  21. new BuffInfo { Type = BuffType.Fury, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  22. new BuffInfo { Type = BuffType.SoulShield, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  23. new BuffInfo { Type = BuffType.BlessedArmour, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  24. new BuffInfo { Type = BuffType.LightBody, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  25. new BuffInfo { Type = BuffType.UltimateEnhancer, Properties = BuffProperty.None, StackType = BuffStackType.ResetStatAndDuration },
  26. new BuffInfo { Type = BuffType.ProtectionField, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  27. new BuffInfo { Type = BuffType.Rage, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  28. new BuffInfo { Type = BuffType.Curse, Properties = BuffProperty.RemoveOnDeath | BuffProperty.Debuff, StackType = BuffStackType.ResetDuration },
  29. new BuffInfo { Type = BuffType.MoonLight, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  30. new BuffInfo { Type = BuffType.DarkBody, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  31. new BuffInfo { Type = BuffType.Concentration, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  32. new BuffInfo { Type = BuffType.VampireShot, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  33. new BuffInfo { Type = BuffType.PoisonShot, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  34. new BuffInfo { Type = BuffType.CounterAttack, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  35. new BuffInfo { Type = BuffType.MentalState, Properties = BuffProperty.None, StackType = BuffStackType.Infinite },
  36. new BuffInfo { Type = BuffType.EnergyShield, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  37. new BuffInfo { Type = BuffType.MagicBooster, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  38. new BuffInfo { Type = BuffType.PetEnhancer, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  39. new BuffInfo { Type = BuffType.ImmortalSkin, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  40. new BuffInfo { Type = BuffType.MagicShield, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  41. new BuffInfo { Type = BuffType.ElementalBarrier, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  42. //Monsters
  43. new BuffInfo { Type = BuffType.HornedArcherBuff, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  44. new BuffInfo { Type = BuffType.ColdArcherBuff, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  45. new BuffInfo { Type = BuffType.GeneralMeowMeowShield, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  46. new BuffInfo { Type = BuffType.RhinoPriestDebuff, Properties = BuffProperty.Debuff, StackType = BuffStackType.ResetDuration },
  47. new BuffInfo { Type = BuffType.PowerBeadBuff, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  48. new BuffInfo { Type = BuffType.HornedWarriorShield, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  49. new BuffInfo { Type = BuffType.HornedCommanderShield, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration, Visible = true },
  50. new BuffInfo { Type = BuffType.Blindness, Properties = BuffProperty.RemoveOnDeath | BuffProperty.Debuff, StackType = BuffStackType.ResetDuration },
  51. //Special
  52. new BuffInfo { Type = BuffType.GameMaster, Properties = BuffProperty.None, StackType = BuffStackType.Infinite, Visible = Settings.GameMasterEffect },
  53. new BuffInfo { Type = BuffType.Mentee, Properties = BuffProperty.None, StackType = BuffStackType.Infinite },
  54. new BuffInfo { Type = BuffType.Mentor, Properties = BuffProperty.None, StackType = BuffStackType.Infinite },
  55. new BuffInfo { Type = BuffType.Guild, Properties = BuffProperty.None, StackType = BuffStackType.Infinite },
  56. new BuffInfo { Type = BuffType.Skill, Properties = BuffProperty.None, StackType = BuffStackType.Infinite },
  57. new BuffInfo { Type = BuffType.ClearRing, Properties = BuffProperty.None, StackType = BuffStackType.Infinite },
  58. new BuffInfo { Type = BuffType.Transform, Properties = BuffProperty.None, StackType = BuffStackType.None },
  59. new BuffInfo { Type = BuffType.Lover, Properties = BuffProperty.RemoveOnExit, StackType = BuffStackType.Infinite },
  60. new BuffInfo { Type = BuffType.Rested, Properties = BuffProperty.None, StackType = BuffStackType.ResetDuration },
  61. new BuffInfo { Type = BuffType.Prison, Properties = BuffProperty.None, StackType = BuffStackType.None }, //???
  62. new BuffInfo { Type = BuffType.General, Properties = BuffProperty.None, StackType = BuffStackType.None }, //???
  63. new BuffInfo { Type = BuffType.Newbie, Properties = BuffProperty.RemoveOnExit, StackType = BuffStackType.Infinite }, //???
  64. //Stats
  65. new BuffInfo { Type = BuffType.Exp, Properties = BuffProperty.PauseInSafeZone, StackType = BuffStackType.StackDuration },
  66. new BuffInfo { Type = BuffType.Drop, Properties = BuffProperty.PauseInSafeZone, StackType = BuffStackType.StackDuration },
  67. new BuffInfo { Type = BuffType.Gold, Properties = BuffProperty.PauseInSafeZone, StackType = BuffStackType.StackDuration },
  68. new BuffInfo { Type = BuffType.BagWeight, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  69. new BuffInfo { Type = BuffType.Impact, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  70. new BuffInfo { Type = BuffType.Magic, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  71. new BuffInfo { Type = BuffType.Taoist, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  72. new BuffInfo { Type = BuffType.Storm, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  73. new BuffInfo { Type = BuffType.HealthAid, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  74. new BuffInfo { Type = BuffType.ManaAid, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  75. new BuffInfo { Type = BuffType.Defence, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  76. new BuffInfo { Type = BuffType.MagicDefence, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  77. new BuffInfo { Type = BuffType.WonderDrug, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration },
  78. new BuffInfo { Type = BuffType.Knapsack, Properties = BuffProperty.None, StackType = BuffStackType.StackDuration }
  79. };
  80. return info;
  81. }
  82. }
  83. public class Buff
  84. {
  85. protected static Envir Envir
  86. {
  87. get { return Envir.Main; }
  88. }
  89. private Dictionary<string, object> Data { get; set; } = new Dictionary<string, object>();
  90. public BuffInfo Info;
  91. public MapObject Caster;
  92. public uint ObjectID;
  93. public long ExpireTime;
  94. public long LastTime, NextTime;
  95. public Stats Stats;
  96. public int[] Values;
  97. public bool FlagForRemoval;
  98. public bool Paused;
  99. public BuffType Type
  100. {
  101. get { return Info.Type; }
  102. }
  103. public BuffStackType StackType
  104. {
  105. get { return Info.StackType; }
  106. }
  107. public BuffProperty Properties
  108. {
  109. get { return Info.Properties; }
  110. }
  111. public Buff(BuffType type)
  112. {
  113. Info = Envir.GetBuffInfo(type);
  114. Stats = new Stats();
  115. Data = new Dictionary<string, object>();
  116. }
  117. public Buff(BinaryReader reader, int version, int customVersion)
  118. {
  119. var type = (BuffType)reader.ReadByte();
  120. Info = Envir.GetBuffInfo(type);
  121. Caster = null;
  122. if (version < 88)
  123. {
  124. var visible = reader.ReadBoolean();
  125. }
  126. ObjectID = reader.ReadUInt32();
  127. ExpireTime = reader.ReadInt64();
  128. if (version <= 84)
  129. {
  130. Values = new int[reader.ReadInt32()];
  131. for (int i = 0; i < Values.Length; i++)
  132. {
  133. Values[i] = reader.ReadInt32();
  134. }
  135. if (version < 88)
  136. {
  137. var infinite = reader.ReadBoolean();
  138. }
  139. Stats = new Stats();
  140. Data = new Dictionary<string, object>();
  141. }
  142. else
  143. {
  144. if (version < 88)
  145. {
  146. var stackable = reader.ReadBoolean();
  147. }
  148. Values = new int[0];
  149. Stats = new Stats(reader, version, customVersion);
  150. Data = new Dictionary<string, object>();
  151. int count = reader.ReadInt32();
  152. for (int i = 0; i < count; i++)
  153. {
  154. var key = reader.ReadString();
  155. var length = reader.ReadInt32();
  156. var array = new byte[length];
  157. for (int j = 0; j < array.Length; j++)
  158. {
  159. array[j] = reader.ReadByte();
  160. }
  161. Data[key] = Functions.DeserializeFromBytes(array);
  162. }
  163. if (version > 86)
  164. {
  165. count = reader.ReadInt32();
  166. Values = new int[count];
  167. for (int i = 0; i < count; i++)
  168. {
  169. Values[i] = reader.ReadInt32();
  170. }
  171. }
  172. }
  173. }
  174. public void Save(BinaryWriter writer)
  175. {
  176. writer.Write((byte)Type);
  177. writer.Write(ObjectID);
  178. writer.Write(ExpireTime);
  179. Stats.Save(writer);
  180. writer.Write(Data.Count);
  181. foreach (KeyValuePair<string, object> pair in Data)
  182. {
  183. var bytes = Functions.SerializeToBytes(pair.Value);
  184. writer.Write(pair.Key);
  185. writer.Write(bytes.Length);
  186. for (int i = 0; i < bytes.Length; i++)
  187. {
  188. writer.Write(bytes[i]);
  189. }
  190. }
  191. writer.Write(Values.Length);
  192. for (int i = 0; i < Values.Length; i++)
  193. {
  194. writer.Write(Values[i]);
  195. }
  196. }
  197. public T Get<T>(string key)
  198. {
  199. if (!Data.TryGetValue(key, out object result))
  200. {
  201. return default;
  202. }
  203. return (T)result;
  204. }
  205. public void Set(string key, object val)
  206. {
  207. Data[key] = val;
  208. }
  209. public ClientBuff ToClientBuff()
  210. {
  211. return new ClientBuff
  212. {
  213. Type = Type,
  214. Caster = Caster?.Name ?? "",
  215. ObjectID = ObjectID,
  216. Visible = Info.Visible,
  217. Infinite = StackType == BuffStackType.Infinite,
  218. Paused = Paused,
  219. ExpireTime = ExpireTime,
  220. Stats = new Stats(Stats),
  221. Values = Values
  222. };
  223. }
  224. }
  225. }