IntelligentCreatureInfo.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using Server.MirEnvir;
  2. namespace Server.MirDatabase
  3. {
  4. public class IntelligentCreatureInfo
  5. {
  6. protected static Envir Envir
  7. {
  8. get { return Envir.Main; }
  9. }
  10. public static List<IntelligentCreatureInfo> Creatures = new List<IntelligentCreatureInfo>();
  11. public IntelligentCreatureType PetType;
  12. public int Icon;
  13. public int MinimalFullness = 1000;
  14. public bool MousePickupEnabled = false;
  15. public int MousePickupRange = 0;
  16. public bool AutoPickupEnabled = false;
  17. public int AutoPickupRange = 0;
  18. public bool SemiAutoPickupEnabled = false;
  19. public int SemiAutoPickupRange = 0;
  20. public bool CanProduceBlackStone = false;
  21. static IntelligentCreatureInfo()
  22. {
  23. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.BabyPig, Icon = 500, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 3, MinimalFullness = 4000 };
  24. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.Chick, Icon = 501, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 7, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 7, CanProduceBlackStone = true };
  25. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.Kitten, Icon = 502, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 3, MinimalFullness = 6000 };
  26. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.BabySkeleton, Icon = 503, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 7, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 7, CanProduceBlackStone = true };
  27. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.Baekdon, Icon = 504, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 7, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 7, CanProduceBlackStone = true };
  28. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.Wimaen, Icon = 505, MousePickupEnabled = true, MousePickupRange = 7, AutoPickupEnabled = true, AutoPickupRange = 5, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 5, MinimalFullness = 5000 };
  29. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.BlackKitten, Icon = 506, MousePickupEnabled = true, MousePickupRange = 7, AutoPickupEnabled = true, AutoPickupRange = 5, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 5, MinimalFullness = 5000 };
  30. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.BabyDragon, Icon = 507, MousePickupEnabled = true, MousePickupRange = 7, AutoPickupEnabled = true, AutoPickupRange = 5, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 5, MinimalFullness = 7000 };
  31. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.OlympicFlame, Icon = 508, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 11, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 11, CanProduceBlackStone = true };
  32. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.BabySnowMan, Icon = 509, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 11, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 11, CanProduceBlackStone = true };
  33. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.Frog, Icon = 510, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 11, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 11, CanProduceBlackStone = true };
  34. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.BabyMonkey, Icon = 511, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 11, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 11, CanProduceBlackStone = true };
  35. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.AngryBird, Icon = 512, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 11, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 11, CanProduceBlackStone = true };
  36. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.Foxey, Icon = 513, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 11, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 11, CanProduceBlackStone = true };
  37. new IntelligentCreatureInfo { PetType = IntelligentCreatureType.MedicalRat, Icon = 514, MousePickupEnabled = true, MousePickupRange = 11, AutoPickupEnabled = true, AutoPickupRange = 11, SemiAutoPickupEnabled = true, SemiAutoPickupRange = 11, CanProduceBlackStone = true };
  38. }
  39. public IntelligentCreatureInfo()
  40. {
  41. Creatures.Add(this);
  42. }
  43. public static IntelligentCreatureInfo GetCreatureInfo(IntelligentCreatureType petType)
  44. {
  45. for (int i = 0; i < Creatures.Count; i++)
  46. {
  47. IntelligentCreatureInfo info = Creatures[i];
  48. if (info.PetType != petType) continue;
  49. return info;
  50. }
  51. return null;
  52. }
  53. }
  54. public class UserIntelligentCreature
  55. {
  56. protected static Envir Envir
  57. {
  58. get { return Envir.Main; }
  59. }
  60. public IntelligentCreatureType PetType;
  61. public IntelligentCreatureInfo Info;
  62. public IntelligentCreatureItemFilter Filter;
  63. public IntelligentCreaturePickupMode petMode = IntelligentCreaturePickupMode.SemiAutomatic;
  64. public string CustomName;
  65. public int Fullness;
  66. public int SlotIndex;
  67. public DateTime Expire;
  68. public long BlackstoneTime = 0;
  69. public long MaintainFoodTime = 0;
  70. public UserIntelligentCreature(IntelligentCreatureType creatureType, int slot, byte effect = 0)
  71. {
  72. PetType = creatureType;
  73. Info = IntelligentCreatureInfo.GetCreatureInfo(PetType);
  74. CustomName = Envir.Main.GetMonsterInfo(64, (byte)PetType)?.Name ?? PetType.ToString();
  75. Fullness = 7500;//starts at 75% food
  76. SlotIndex = slot;
  77. if (effect > 0) Expire = Envir.Now.AddDays(effect);//effect holds the amount in days
  78. else Expire = DateTime.MinValue;//permanent
  79. BlackstoneTime = 0;
  80. MaintainFoodTime = 0;
  81. Filter = new IntelligentCreatureItemFilter();
  82. }
  83. public UserIntelligentCreature(BinaryReader reader, int version, int customVersion)
  84. {
  85. PetType = (IntelligentCreatureType)reader.ReadByte();
  86. Info = IntelligentCreatureInfo.GetCreatureInfo(PetType);
  87. CustomName = reader.ReadString();
  88. Fullness = reader.ReadInt32();
  89. SlotIndex = reader.ReadInt32();
  90. var expireTime = reader.ReadInt64();
  91. if (expireTime == -9999)
  92. {
  93. Expire = DateTime.MinValue;
  94. }
  95. else
  96. {
  97. Expire = Envir.Now.AddSeconds(expireTime);
  98. }
  99. BlackstoneTime = reader.ReadInt64();
  100. petMode = (IntelligentCreaturePickupMode)reader.ReadByte();
  101. Filter = new IntelligentCreatureItemFilter(reader);
  102. if (version > 48)
  103. {
  104. Filter.PickupGrade = (ItemGrade)reader.ReadByte();
  105. MaintainFoodTime = reader.ReadInt64();//maintain food buff
  106. }
  107. }
  108. public void Save(BinaryWriter writer)
  109. {
  110. writer.Write((byte)PetType);
  111. writer.Write(CustomName);
  112. writer.Write(Fullness);
  113. writer.Write(SlotIndex);
  114. if (Expire == DateTime.MinValue)
  115. {
  116. writer.Write((long)-9999);
  117. }
  118. else
  119. {
  120. writer.Write((long)(Expire - Envir.Now).TotalSeconds);
  121. }
  122. writer.Write(BlackstoneTime);
  123. writer.Write((byte)petMode);
  124. Filter.Save(writer);
  125. writer.Write((byte)Filter.PickupGrade);//since Envir.Version 49
  126. writer.Write(MaintainFoodTime);//maintain food buff
  127. }
  128. public Packet GetInfo()
  129. {
  130. return new ServerPackets.NewIntelligentCreature
  131. {
  132. Creature = CreateClientIntelligentCreature()
  133. };
  134. }
  135. public ClientIntelligentCreature CreateClientIntelligentCreature()
  136. {
  137. return new ClientIntelligentCreature
  138. {
  139. PetType = PetType,
  140. Icon = Info.Icon,
  141. CustomName = CustomName,
  142. Fullness = Fullness,
  143. SlotIndex = SlotIndex,
  144. Expire = Expire,
  145. BlackstoneTime = BlackstoneTime,
  146. MaintainFoodTime = MaintainFoodTime,
  147. petMode = petMode,
  148. CreatureRules = new IntelligentCreatureRules
  149. {
  150. MinimalFullness = Info.MinimalFullness,
  151. MousePickupEnabled = Info.MousePickupEnabled,
  152. MousePickupRange = Info.MousePickupRange,
  153. AutoPickupEnabled = Info.AutoPickupEnabled,
  154. AutoPickupRange = Info.AutoPickupRange,
  155. SemiAutoPickupEnabled = Info.SemiAutoPickupEnabled,
  156. SemiAutoPickupRange = Info.SemiAutoPickupRange,
  157. CanProduceBlackStone = Info.CanProduceBlackStone
  158. },
  159. Filter = Filter
  160. };
  161. }
  162. }
  163. }