| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using Server.MirDatabase;
- using Server.MirEnvir;
- using S = ServerPackets;
- namespace Server.MirObjects.Monsters
- {
- public class SpittingToad : MonsterObject
- {
- public bool Summoned;
- public long AliveTime;
- public long deadTime;
- protected internal SpittingToad(MonsterInfo info) : base(info)
- {
- ActionTime = Envir.Time + 1000;
- }
- public override string Name
- {
- get { return Master == null ? Info.GameName : (Dead ? Info.GameName : string.Format("{0}({1})", Info.GameName, Master.Name)); }
- set { throw new NotSupportedException(); }
- }
- public override void Process()
- {
- if (!Dead && Summoned)
- {
- if (Master != null)
- {
- bool selfDestruct = false;
- if (FindObject(Master.ObjectID, 15) == null) selfDestruct = true;
- if (Summoned && Envir.Time > AliveTime) selfDestruct = true;
- if (selfDestruct && Master != null) Die();
- }
- }
- base.Process();
- }
- public override void Process(DelayedAction action)
- {
- switch (action.Type)
- {
- case DelayedType.Damage:
- CompleteAttack(action.Params);
- break;
- case DelayedType.RangeDamage:
- CompleteRangeAttack(action.Params);
- break;
- case DelayedType.Recall:
- PetRecall((MapObject)action.Params[0]);
- break;
- }
- }
- public void PetRecall(MapObject target)
- {
- if (target == null) return;
- if (Master == null) return;
- Teleport(Master.CurrentMap, target.CurrentLocation);
- }
- protected override void ProcessAI()
- {
- //ProcessSearch
- if (Envir.Time < SearchTime) return;
- SearchTime = Envir.Time + SearchDelay;
- if (Target == null) FindTarget();
- //ProcessTarget
- if (Target == null || !CanAttack) return;
- if (InAttackRange())
- {
- Attack();
- if (Target.Dead) FindTarget();
- return;
- }
- else FindTarget();//Target out of range find new
- if (Envir.Time < ShockTime)
- {
- Target = null;
- return;
- }
- }
- protected override bool InAttackRange()
- {
- if (Target.CurrentMap != CurrentMap) return false;
- if (Target.CurrentLocation == CurrentLocation) return false;
- int x = Math.Abs(Target.CurrentLocation.X - CurrentLocation.X);
- int y = Math.Abs(Target.CurrentLocation.Y - CurrentLocation.Y);
- if (x > 12 || y > 12) return false;
- return (x <= 12 && y <= 12) || (x == y || x % 2 == y % 2);
- }
- protected override void Attack()
- {
- if (!Target.IsAttackTarget(this))
- {
- Target = null;
- return;
- }
- ShockTime = 0;
- ActionTime = Envir.Time + 300;
- AttackTime = Envir.Time + AttackSpeed;
- int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
- Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
- Turn(Direction);
- Broadcast(new S.ObjectRangeAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, TargetID = Target.ObjectID });
- AttackTime = Envir.Time + AttackSpeed + 500;
- if (damage == 0) return;
- int delay = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation) * 50 + 500; //50 MS per Step
- DelayedAction action = new DelayedAction(DelayedType.RangeDamage, Envir.Time + delay, Target, damage, DefenceType.MAC);
- ActionList.Add(action);
- }
- public override void Spawned()
- {
- base.Spawned();
- Summoned = true;
- }
- public override Packet GetInfo()
- {
- var packet = (S.ObjectMonster)base.GetInfo();
- packet.Image = Monster.SpittingToad;
- packet.Extra = Summoned;
- return packet;
- }
- }
- }
|