private void Attack() { if (this.Target != null && !IsInVisualField(this.Target)) { this.Target = null; } if (this.Target == null) { this.Target = PetOwner.CombatManager.target; } if (this.Target != null) { if (DateTime.Now.Subtract(LastAttack).Seconds > 0) { LastAttack = DateTime.Now; Pet.CombatEngine.ProcessInteractionPacket(InteractPacket.Create(Pet.UID, Target.UID, Target.X, Target.Y, Enum.InteractAction.Attack, 0)); } if (this.Target.Alive == false) { Database.Domain.DbMagicType skill = Database.ServerDatabase.Context.MagicType.GetById(Pet.BaseMonster.SkillType); uint dmg = Pet.CalculateSkillDamage(this.Target, skill, false); var expGain = PetOwner.CalculateExperienceGain(this.Target, dmg); ((Player)PetOwner).GainExperience(expGain); this.Target = null; Console.WriteLine("EXP gained " + expGain); } } }
public void On_Entity_Timer() { if (Alive) { if (HasEffect(ClientEffect.Poison)) //Added poison damage { if (Common.Clock - LastPoisonDamage > Common.MS_PER_SECOND * 1) { SendToScreen(InteractPacket.Create(UID, UID, (ushort)Location.X, (ushort)Location.Y, InteractAction.Poison, ReceivePoisonDamage()), true); LastPoisonDamage = Common.Clock; } } } foreach (var effect in ClientEffects) { if (Common.Clock > effect.Value && effect.Value > 0) { RemoveEffect(effect.Key); } } foreach (var status in ClientStatuses) { if (Common.Clock > status.Value.Timeout && status.Value.Timeout > 0) { RemoveStatus(status.Key); } } }
public virtual void Kill(uint _dieType, uint _attacker) { if (!sentDeath) { sentDeath = true; SendToScreen(InteractPacket.Create(_attacker, UID, X, Y, InteractAction.Kill, _dieType), true); } Life = 0; }
public override void Kill(uint _dieType, uint _attacker) { SendToScreen(InteractPacket.Create(_attacker, UID, X, Y, InteractAction.Kill, _dieType), true); Life = 0; DiedAt = Common.Clock; SpawnPacket.StatusEffects = ClientEffect.Dead; AddEffect(ClientEffect.Fade, 0); PetOwner.Pet = null; Target = null; Map.Remove(this, false); }
public unsafe void JarUpdate(Player Killer, uint UID, int CurrentKills, InteractPacket Packet, bool reset = false) { if (!reset) { Killer.KOCount++; } if (Killer.KOCount % 10 == 0) { Database.ServerDatabase.Context.Tasks.UpdateTask(Killer.KOCount, UID, 1); } //Packet.MonsterType = AttackID.MonsterJar; Packet.dmg = 65536; Packet.Killed = Killer.KOCount; Killer.Send(Packet); Killer.SendToScreen(InteractPacket.Create(Killer.UID, Killer.UID, (ushort)Killer.Location.X, (ushort)Killer.Location.Y, InteractAction.Chop, 65536), true); }
public void Monster_Timer() { //Perform all monster logic here switch (Mode) { case MonsterMode.Attack: { var target = Map.Search <Entity>(TargetID); if (target == null || !target.Alive || target.HasEffect(ClientEffect.Fly)) { Mode = MonsterMode.Idle; return; } var dist = Calculations.GetDistance(Location, target.Location); if (dist > BaseMonster.ViewRange) { Mode = MonsterMode.Idle; } else if (dist > BaseMonster.AttackRange) { Mode = MonsterMode.Walk; } else if (Common.Clock - LastAttack > BaseMonster.AttackSpeed) { LastAttack = Common.Clock; CombatEngine.ProcessInteractionPacket(InteractPacket.Create(UID, TargetID, target.X, target.Y, InteractAction.Attack, 0)); } break; } case MonsterMode.Idle: { var d1 = BaseMonster.ViewRange; foreach (var t in Map.QueryScreen <Entity>(this)) { if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection)) { continue; } var d2 = Calculations.GetDistance(Location, t.Location); if (d2 < d1) { d1 = d2; TargetID = t.UID; if (d2 <= BaseMonster.AttackRange) { break; } } } var Target = Map.Search <Entity>(TargetID); /*if ((Life < MaximumLife) && (isSearching == false)) //Get the target that is range attacking * { * var searchRange = 30; * foreach (var t in Map.QueryScreen<Entity>(this)) * { * if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection)) * continue; * var d2 = Calculations.GetDistance(Location, t.Location); * if (d2 < searchRange) * { * searchRange = d2; * TargetID = t.UID; * } * } * Target = Map.Search<Entity>(TargetID); * Mode = MonsterMode.Search; * }*/ if (Life < isAttacked) { Mode = MonsterMode.Search; isAttacked = Life; foreach (var t in Map.QueryScreen <Entity>(this)) { if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection)) { continue; } var d2 = Calculations.GetDistance(Location, t.Location); if (d2 < 30) //Range of searching { TargetID = t.UID; if (d2 <= BaseMonster.AttackRange) { break; } } } } else { if (Target != null) { var dist = Calculations.GetDistance(Location, Target.Location); if (dist < BaseMonster.AttackRange) { Mode = MonsterMode.Attack; } else if (dist < BaseMonster.ViewRange) { Mode = MonsterMode.Walk; } } else if (BaseMonster.Mesh != 900 && Common.Clock - LastMove > BaseMonster.MoveSpeed * 4) { var dir = (byte)Common.Random.Next(9); Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]); if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster)) { //Send to screen new walk packet SendToScreen(WalkPacket.Create(UID, dir)); Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster); X = (ushort)tryMove.X; Y = (ushort)tryMove.Y; Direction = dir; Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster); LastMove = Common.Clock; UpdateSurroundings(); } } } break; } case MonsterMode.Walk: { var target = Map.Search <Entity>(TargetID); if (target == null || !target.Alive || (BaseMonster.Mesh != 900 && target.HasEffect(ClientEffect.Fly) || target.HasStatus(ClientStatus.ReviveProtection))) { Mode = MonsterMode.Idle; } else if (Common.Clock - LastMove > BaseMonster.MoveSpeed) { var dist = Calculations.GetDistance(Location, target.Location); if (dist > BaseMonster.ViewRange) { Mode = MonsterMode.Idle; } else if (dist > BaseMonster.AttackRange) { var dir = Calculations.GetDirection(Location, target.Location); Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]); if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster)) { //Send to screen new walk packet SendToScreen(WalkPacket.Create(UID, dir)); Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster); X = (ushort)tryMove.X; Y = (ushort)tryMove.Y; Direction = dir; Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster); LastMove = Common.Clock; } else if (Common.Clock - LastMove > BaseMonster.MoveSpeed * 5) { Mode = MonsterMode.Encircle; } } else { LastAttack = Common.Clock - AttackSpeed + 100; Mode = MonsterMode.Attack; } } break; } case MonsterMode.Encircle: { var Target = Map.Search <Entity>(TargetID); if (Target != null) { var dir = (byte)Common.Random.Next(9); //This should move to turn around an object. Now is random. for (int i = 0; i < Common.Random.Next(2, 5); i++) { Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]); if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster)) { //Send to screen new walk packet SendToScreen(WalkPacket.Create(UID, dir)); Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster); X = (ushort)tryMove.X; Y = (ushort)tryMove.Y; Direction = dir; Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster); LastMove = Common.Clock; //UpdateSurroundings(); } } } Mode = MonsterMode.Idle; break; } case MonsterMode.Search: { var target = Map.Search <Entity>(TargetID); if (target == null || !target.Alive || (BaseMonster.Mesh != 900 && target.HasEffect(ClientEffect.Fly) || target.HasStatus(ClientStatus.ReviveProtection))) { Mode = MonsterMode.Idle; } else if (Common.Clock - LastMove > BaseMonster.MoveSpeed) { var dist = Calculations.GetDistance(Location, target.Location); if (dist > 30) //Max range of search. { Mode = MonsterMode.Idle; } else if (dist > BaseMonster.AttackRange) { var dir = Calculations.GetDirection(Location, target.Location); Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]); if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster)) { //Send to screen new walk packet SendToScreen(WalkPacket.Create(UID, dir)); Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster); X = (ushort)tryMove.X; Y = (ushort)tryMove.Y; Direction = dir; Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster); LastMove = Common.Clock; } else if (Common.Clock - LastMove > BaseMonster.MoveSpeed * 5) { Mode = MonsterMode.Encircle; } } else { LastAttack = Common.Clock - AttackSpeed + 100; Mode = MonsterMode.Attack; } } break; } } }
public void Monster_Timer() { //Perform all monster logic here switch (Mode) { case MonsterMode.Attack: { var target = Map.Search <Entity>(TargetID); if (target == null || !target.Alive || target.HasEffect(ClientEffect.Fly)) { Mode = MonsterMode.Idle; return; } var dist = Calculations.GetDistance(Location, target.Location); if (dist > BaseMonster.ViewRange) { Mode = MonsterMode.Idle; } else if (dist > BaseMonster.AttackRange) { Mode = MonsterMode.Walk; } else if (Common.Clock - LastAttack > BaseMonster.AttackSpeed) { LastAttack = Common.Clock; CombatEngine.ProcessInteractionPacket(InteractPacket.Create(UID, TargetID, target.X, target.Y, InteractAction.Attack, 0)); } break; } case MonsterMode.Idle: { var d1 = BaseMonster.ViewRange; foreach (var t in Map.QueryScreen <Entity>(this)) { if (!CombatEngine.IsValidTarget(t) || (BaseMonster.Mesh != 900 && t.HasEffect(ClientEffect.Fly)) || t.HasStatus(ClientStatus.ReviveProtection)) { continue; } var d2 = Calculations.GetDistance(Location, t.Location); if (d2 < d1) { d1 = d2; TargetID = t.UID; if (d2 <= BaseMonster.AttackRange) { break; } } } var Target = Map.Search <Entity>(TargetID); if (Target == null) { return; } var dist = Calculations.GetDistance(Location, Target.Location); if (dist < BaseMonster.AttackRange) { Mode = MonsterMode.Attack; } else if (dist < BaseMonster.ViewRange) { Mode = MonsterMode.Walk; } else if (BaseMonster.Mesh != 900 && Common.Clock - LastMove > BaseMonster.MoveSpeed * 4) { var dir = (byte)Common.Random.Next(9); Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]); if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster)) { //Send to screen new walk packet SendToScreen(WalkPacket.Create(UID, dir)); Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster); X = (ushort)tryMove.X; Y = (ushort)tryMove.Y; Direction = dir; Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster); LastMove = Common.Clock; UpdateSurroundings(); } } break; } case MonsterMode.Walk: { var target = Map.Search <Entity>(TargetID); if (target == null || !target.Alive || (BaseMonster.Mesh != 900 && target.HasEffect(ClientEffect.Fly))) { Mode = MonsterMode.Idle; } else if (Common.Clock - LastMove > BaseMonster.MoveSpeed) { var dist = Calculations.GetDistance(Location, target.Location); if (dist > BaseMonster.ViewRange) { Mode = MonsterMode.Idle; } else if (dist > BaseMonster.AttackRange) { var dir = Calculations.GetDirection(Location, target.Location); Point tryMove = new Point(Location.X + Common.DeltaX[dir], Location.Y + Common.DeltaY[dir]); if (Common.MapService.Valid(MapID, (ushort)tryMove.X, (ushort)tryMove.Y) && !Common.MapService.HasFlag(MapID, (ushort)tryMove.X, (ushort)tryMove.Y, TinyMap.TileFlag.Monster)) { //Send to screen new walk packet SendToScreen(WalkPacket.Create(UID, dir)); Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster); X = (ushort)tryMove.X; Y = (ushort)tryMove.Y; Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster); LastMove = Common.Clock; } else if (Common.Clock - LastMove > BaseMonster.MoveSpeed * 5) { Mode = MonsterMode.Idle; } } else { LastAttack = Common.Clock; Mode = MonsterMode.Attack; } } break; } } }
public override void Kill(uint _dieType, uint _attacker) { if (PlayerManager.Players.ContainsKey(_attacker)) { var player = PlayerManager.Players[_attacker]; player.Xp++; player.KOCount++; if (player.HasEffect(ClientEffect.Cyclone) || player.HasEffect(ClientEffect.Superman)) { player.KOCount++; } } TargetID = 0; Mode = MonsterMode.Dormancy; DiedAt = Common.Clock; Monster x; Owner.AliveMembers.TryRemove(UID, out x); Owner.DyingMembers.TryAdd(UID, this); SpawnPacket.StatusEffects = ClientEffect.Dead; AddEffect(ClientEffect.Fade, 0); Map.Remove(this, false); GenerateDrops(_attacker); // TODO: use a better way to check if its a pet var killer = PlayerManager.GetUser(_attacker); if (killer != null && killer.Team != null) { foreach (var p in killer.Team.Members) { if (p == killer || !p.Alive || !p.VisibleObjects.ContainsKey(killer.UID)) { continue; } else { var bonusexp = (uint)(Redux.Common.MulDiv(BaseMonster.Life, 5, 100)); if (p.Spouse == killer.Spouse) { bonusexp *= 2; } p.GainExperience(bonusexp); p.SendMessage("Congratulations you have gained " + bonusexp * Constants.EXP_RATE + " team experience!", ChatType.System); } } } base.Kill(_dieType, _attacker); if (killer != null && killer.Team == null) { var Jar = killer.GetItemByID(750000); if (killer.HasItem(750000) && Jar.MaximumDurability == BaseMonster.ID /* && task.Count != Jar.Durability*/) { InteractPacket Packet = InteractPacket.Create(UID, TargetID, killer.X, killer.Y, InteractAction.Attack, 0); JarUpdate(killer, killer.UID, CurrentKills, Packet); killer.SendMessage("Nice"); } } }
public void Pet_Timer() { if (Remove == true) { return; } if (PetOwner != null) { if (Alive) { #region Movement if (Target == null || Space.Calculations.GetDistance(this, PetOwner) > 15 || Space.Calculations.GetDistance(this, Target) > BaseMonster.ViewRange) { int OwnerDistance = Space.Calculations.GetDistance(this, PetOwner); if (OwnerDistance > 15) { if (Map.IsValidMonsterLocation(PetOwner.Location)) { Point newloc = NextLocation(PetOwner); X = (ushort)newloc.X; Y = (ushort)newloc.Y; SendToScreen(this.SpawnPacket); UpdateSurroundings(); LastMove = Common.Clock; } } else if (OwnerDistance >= 8 && OwnerDistance <= 15 && Common.Clock > LastMove + 900) { if (Remove != true) { Jump(PetOwner); } } else if (OwnerDistance < 8 && OwnerDistance >= 3) { if (Common.Clock - LastMove > BaseMonster.MoveSpeed) { if (Remove != true) { Walk(PetOwner); } } } } #endregion else { #region Targeting if (!CombatEngine.IsValidTarget(Target) || !Target.Alive) { //Target = null; return; } int TargetDistance = Space.Calculations.GetDistance(this, Target); if (TargetDistance <= BaseMonster.AttackRange) { if (Common.Clock - LastAttack > BaseMonster.AttackSpeed) { if (BaseMonster.Mesh == 920) { LastAttack = Common.Clock; /*var skill = Database.ServerDatabase.Context.MagicType.GetById(BaseMonster.SkillType); * dmg = CalculateSkillDamage(Target, skill, skill.Percent < 100); * var packet = SkillEffectPacket.Create(UID, Target.UID, BaseMonster.SkillType, 0); * packet.AddTarget(Target.UID, dmg); * * SendToScreen(packet);*/ var pack = InteractPacket.Create(UID, Target.UID, Target.X, Target.Y, InteractAction.MagicAttack, 0); pack.MagicType = BaseMonster.SkillType; pack.MagicLevel = 0; pack.Target = Target.UID; CombatEngine.ProcessInteractionPacket(pack); } else if (!Target.HasEffect(ClientEffect.Fly)) { LastAttack = Common.Clock; //dmg = CalculatePhysicalDamage(Target, null, true); //SendToScreen(InteractPacket.Create(UID, Target.UID, (ushort)Target.Location.X, (ushort)Target.Location.Y, InteractAction.Attack, dmg)); CombatEngine.ProcessInteractionPacket(InteractPacket.Create(UID, Target.UID, Target.X, Target.Y, InteractAction.Attack, 0)); } /*if (dmg > 0) * { * Target.ReceiveDamage(dmg, UID); * * var expGain = CalculateExperienceGain(Target, dmg); * ((Player)PetOwner).GainExperience(expGain); * }*/ } } else if (TargetDistance > BaseMonster.AttackRange && TargetDistance <= BaseMonster.ViewRange) { if (TargetDistance - BaseMonster.AttackRange <= 4) { Walk(Target); } else { Jump(Target); } } } #endregion } } else { Map.Remove(this, false); } }