| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- using Server.MirDatabase;
- using Server.MirEnvir;
- using S = ServerPackets;
- namespace Server.MirObjects.Monsters
- {
- public class CharmedSnake : MonsterObject
- {
- public bool Summoned;
- public long AliveTime;
- public MapObject MasterTotem;
- protected internal CharmedSnake(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)
- {
- bool selfDestruct = false;
- if (Master != null)
- {
- 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;
- }
- }
- // protected override void ProcessAI()
- // {
- // ProcessSearch();
- // ProcessRoam();
- // ProcessTarget();
- //}
- protected override void ProcessAI()
- {
- if (Dead) return;
- ProcessSearch();
- //todo ProcessRoaming(); needs no master follow just target roaming
- ProcessTarget();
- }
- protected override void ProcessSearch()
- {
- if (Envir.Time < SearchTime) return;
- SearchTime = Envir.Time + SearchDelay;
- //Stacking or Infront of master - Move
- bool stacking = false;
- Cell cell = CurrentMap.GetCell(CurrentLocation);
- if (cell.Objects != null)
- for (int i = 0; i < cell.Objects.Count; i++)
- {
- MapObject ob = cell.Objects[i];
- if (ob == this || !ob.Blocking) continue;
- stacking = true;
- break;
- }
- if (CanMove && ((MasterTotem != null && MasterTotem.Front == CurrentLocation) || stacking))
- {
- //Walk Randomly
- if (!Walk(Direction))
- {
- MirDirection dir = Direction;
- switch (Envir.Random.Next(3)) // favour Clockwise
- {
- case 0:
- for (int i = 0; i < 7; i++)
- {
- dir = Functions.NextDir(dir);
- if (Walk(dir))
- break;
- }
- break;
- default:
- for (int i = 0; i < 7; i++)
- {
- dir = Functions.PreviousDir(dir);
- if (Walk(dir))
- break;
- }
- break;
- }
- }
- }
- if (Target == null || Envir.Random.Next(3) == 0) FindTarget();
- }
- protected override void ProcessRoam()
- {
- if (Target != null || Envir.Time < RoamTime) return;
- if (ProcessRoute()) return;
- if (MasterTotem != null)
- {
- MoveTo(MasterTotem.Back);
- return;
- }
- RoamTime = Envir.Time + RoamDelay;
- if (Envir.Random.Next(10) != 0) return;
- switch (Envir.Random.Next(3)) //Face Walk
- {
- case 0:
- Turn((MirDirection)Envir.Random.Next(8));
- break;
- default:
- Walk(Direction);
- break;
- }
- }
- protected override void ProcessTarget()
- {
- if (Target == null || !CanAttack) return;
- if (InAttackRange())
- {
- Attack();
- if (Target.Dead)
- FindTarget();
- return;
- }
- if (Envir.Time < ShockTime)
- {
- Target = null;
- return;
- }
- MoveTo(Target.CurrentLocation);
- }
- protected override void Attack()
- {
- if (!Target.IsAttackTarget(this))
- {
- Target = null;
- return;
- }
- Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
- Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
- int damage = GetAttackPower(Stats[Stat.MinDC], Stats[Stat.MaxDC]);
- if (damage > 0)
- {
- DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + 300, Target, damage, DefenceType.MAC);
- ActionList.Add(action);
- }
- ActionTime = Envir.Time + 300;
- AttackTime = Envir.Time + AttackSpeed;
- ShockTime = 0;
- }
- protected override void CompleteAttack(IList<object> data)
- {
- MapObject target = (MapObject)data[0];
- int damage = (int)data[1];
- DefenceType defence = (DefenceType)data[2];
- if (target == null || !target.IsAttackTarget(this) || target.CurrentMap != CurrentMap || target.Node == null) return;
- if (target.Attacked(this, damage, defence) <= 0) return;
- PoisonTarget(target, 10 - PetLevel, 4 + PetLevel, PoisonType.Paralysis, 1000);
- }
- public override void Die()
- {
- base.Die();
- //Explosion
- for (int y = CurrentLocation.Y - 1; y <= CurrentLocation.Y + 1; y++)
- {
- if (y < 0) continue;
- if (y >= CurrentMap.Height) break;
- for (int x = CurrentLocation.X - 1; x <= CurrentLocation.X + 1; x++)
- {
- if (x < 0) continue;
- if (x >= CurrentMap.Width) break;
- Cell cell = CurrentMap.GetCell(x, y);
- if (!cell.Valid || cell.Objects == null) continue;
- for (int i = 0; i < cell.Objects.Count; i++)
- {
- MapObject target = cell.Objects[i];
- switch (target.Race)
- {
- case ObjectType.Monster:
- case ObjectType.Player:
- //Only targets
- if (!target.IsAttackTarget(this) || target.Dead) break;
- target.Attacked(this, 10 * PetLevel, DefenceType.MACAgility);
- break;
- }
- }
- }
- }
- }
- public override void Spawned()
- {
- base.Spawned();
- Summoned = true;
- }
- public override Packet GetInfo()
- {
- var packet = (S.ObjectMonster)base.GetInfo();
- packet.Image = Monster.CharmedSnake;
- packet.Extra = Summoned;
- return packet;
- }
- }
- }
|