GeneralMeowMeow.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using S = ServerPackets;
  4. namespace Server.MirObjects.Monsters
  5. {
  6. /// <summary>
  7. /// Attack1 - Basic melee attack
  8. /// Attack2 - Slam Attack (DC * 3)
  9. /// AttackRange1 - Lightning Group Attack (find all targets within 1 range of target and hit)
  10. /// Special Action - Gains a Lightning Magic Shield at various stages of HP (80-70% / 50-40% / 20-0%)
  11. /// Special Action 2 - Hits EVERYONE in range with a thunderbolt periodically (this is only when Energy Shield is up)
  12. /// Summons Slaves periodically
  13. /// </summary>
  14. public class GeneralMeowMeow : MonsterObject
  15. {
  16. public long SlaveSpawnTime;
  17. public int ShieldUpDuration;
  18. public long ThunderAttackTime;
  19. protected virtual byte AttackRange
  20. {
  21. get
  22. {
  23. return 12;
  24. }
  25. }
  26. protected internal GeneralMeowMeow(MonsterInfo info)
  27. : base(info)
  28. {
  29. ShieldUpDuration = Settings.Second * 30;
  30. }
  31. protected override bool InAttackRange()
  32. {
  33. return CurrentMap == Target.CurrentMap && Functions.InRange(CurrentLocation, Target.CurrentLocation, AttackRange);
  34. }
  35. protected override void Attack()
  36. {
  37. if (!Target.IsAttackTarget(this))
  38. {
  39. Target = null;
  40. return;
  41. }
  42. ShockTime = 0;
  43. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  44. bool ranged = CurrentLocation == Target.CurrentLocation || !Functions.InRange(CurrentLocation, Target.CurrentLocation, 2);
  45. ActionTime = Envir.Time + 300;
  46. AttackTime = Envir.Time + AttackSpeed;
  47. /* Energy Shield Logic:
  48. When mob gets to certain health percentages (i.e. 80% / 60% / 40% / 20%) active Energy Shield.
  49. Whilst Energy Shield is active the following happen:
  50. - This monsters damage taken is reduced (50% reduction?)
  51. - Every 'x' amount of seconds all players in range are attacked with a thunderbolt
  52. */
  53. var hpPercent = (HP * 100) / Stats[Stat.HP];
  54. bool stage1Bubble = hpPercent >= 70 && hpPercent <= 80;//HP < Stats[Stat.HP] / 10 * 8 && this.HP > Stats[Stat.HP] / 10 * 7;
  55. bool stage2Bubble = hpPercent >= 40 && hpPercent <= 50;//HP < Stats[Stat.HP] / 10 * 5 && this.HP > Stats[Stat.HP] / 10 * 4;
  56. bool stage3Bubble = hpPercent <= 20; //this.HP < Stats[Stat.HP] / 10 * 2 && this.HP > 1;
  57. if (stage1Bubble == true || stage2Bubble == true || stage3Bubble == true)
  58. {
  59. if (Target != null)
  60. {
  61. var stats = new Stats
  62. {
  63. [Stat.MaxAC] = 100,
  64. [Stat.MinAC] = 100
  65. };
  66. AddBuff(BuffType.GeneralMeowMeowShield, this, ShieldUpDuration, stats);
  67. if (Envir.Time > ThunderAttackTime)
  68. {
  69. MassThunderAttack();
  70. }
  71. OperateTime = 0;
  72. }
  73. }
  74. if (!ranged)
  75. {
  76. if (Envir.Random.Next(9) != 0)
  77. {
  78. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 0 });
  79. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
  80. if (damage == 0) return;
  81. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.ACAgility, false);
  82. ActionList.Add(action);
  83. }
  84. else
  85. {
  86. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  87. int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]) * 3;
  88. if (damage == 0) return;
  89. DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 500, Target, damage, DefenceType.AC, true);
  90. ActionList.Add(action);
  91. }
  92. }
  93. else
  94. {
  95. Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID, Type = 0 });
  96. int damage = GetAttackPower(Stats[Stat.MinMC], Stats[Stat.MaxMC]);
  97. if (damage == 0) return;
  98. DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + 500, Target, damage, DefenceType.MACAgility);
  99. ActionList.Add(action);
  100. }
  101. }
  102. protected override void ProcessAI()
  103. {
  104. if (Dead) return;
  105. // After first 60 seconds: spawn mobs, then every 60 seconds after, spawn more mobs.
  106. if (Target != null && Envir.Time > SlaveSpawnTime)
  107. {
  108. SpawnSlaves();
  109. SlaveSpawnTime = Envir.Time + (Settings.Second * 60);
  110. }
  111. base.ProcessAI();
  112. }
  113. public void MassThunderAttack()
  114. {
  115. // Whilst Energy Shield is up, attack all players every few seconds.
  116. if (Envir.Time > ThunderAttackTime)
  117. {
  118. List<MapObject> targets = FindAllTargets(AttackRange, Target.CurrentLocation);
  119. if (targets.Count == 0) return;
  120. for (int i = 0; i < targets.Count; i++)
  121. {
  122. if (targets[i].IsAttackTarget(this))
  123. {
  124. var spellObj = new SpellObject
  125. {
  126. Spell = Spell.GeneralMeowMeowThunder,
  127. Value = Envir.Random.Next(Stats[Stat.MinMC], Stats[Stat.MaxMC]),
  128. ExpireTime = Envir.Time + 1000,
  129. TickSpeed = 500,
  130. Caster = this,
  131. CurrentLocation = targets[i].CurrentLocation,
  132. CurrentMap = CurrentMap,
  133. Direction = MirDirection.Up
  134. };
  135. DelayedAction action = new DelayedAction(DelayedType.Spawn, Envir.Time + 2000, spellObj);
  136. CurrentMap.ActionList.Add(action);
  137. }
  138. }
  139. }
  140. ThunderAttackTime = Envir.Time + Math.Max(Envir.Random.Next(2000), Envir.Random.Next(4000));
  141. }
  142. public override void Spawned()
  143. {
  144. // Begin countdown timer
  145. SlaveSpawnTime = Envir.Time + (Settings.Second * 60);
  146. base.Spawned();
  147. }
  148. protected override void CompleteAttack(IList<object> data)
  149. {
  150. MapObject target = (MapObject)data[0];
  151. int damage = (int)data[1];
  152. DefenceType defence = (DefenceType)data[2];
  153. bool slamDamage = (bool)data[3];
  154. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  155. target.Attacked(this, damage, defence);
  156. }
  157. protected override void CompleteRangeAttack(IList<object> data)
  158. {
  159. MapObject target = (MapObject)data[0];
  160. int damage = (int)data[1];
  161. DefenceType defence = (DefenceType)data[2];
  162. if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
  163. List<MapObject> targets = FindAllTargets(2, target.CurrentLocation);
  164. if (targets.Count == 0) return;
  165. for (int i = 0; i < targets.Count; i++)
  166. {
  167. targets[i].Attacked(this, damage, defence);
  168. }
  169. }
  170. private void SpawnSlaves()
  171. {
  172. int count = Math.Min(3, 6 - SlaveList.Count);
  173. for (int i = 0; i < count; i++)
  174. {
  175. MonsterObject mob = null;
  176. switch (Envir.Random.Next(4))
  177. {
  178. case 0:
  179. mob = GetMonster(Envir.GetMonsterInfo(Settings.GeneralMeowMeowMob1));
  180. break;
  181. case 1:
  182. mob = GetMonster(Envir.GetMonsterInfo(Settings.GeneralMeowMeowMob2));
  183. break;
  184. case 2:
  185. mob = GetMonster(Envir.GetMonsterInfo(Settings.GeneralMeowMeowMob3));
  186. break;
  187. case 3:
  188. mob = GetMonster(Envir.GetMonsterInfo(Settings.GeneralMeowMeowMob4));
  189. break;
  190. }
  191. if (mob == null) continue;
  192. if (!mob.Spawn(CurrentMap, Front))
  193. {
  194. mob.Spawn(CurrentMap, CurrentLocation);
  195. }
  196. mob.Target = Target;
  197. mob.ActionTime = Envir.Time + 2000;
  198. SlaveList.Add(mob);
  199. }
  200. }
  201. protected override void ProcessTarget()
  202. {
  203. if (CurrentMap.Players.Count == 0) return;
  204. if (Target == null) return;
  205. if (InAttackRange() && CanAttack)
  206. {
  207. Attack();
  208. return;
  209. }
  210. if (Envir.Time < ShockTime)
  211. {
  212. Target = null;
  213. return;
  214. }
  215. MoveTo(Target.CurrentLocation);
  216. }
  217. }
  218. }