Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void AliveMonstersCallback(GameState client, int time)
- {
- if (!client.Socket.IsAlive)
- {
- client.Screen.DisposeTimers();
- return;
- }
- if (client.Player == null)
- return;
- if (client.Map == null)
- return;
- if (client.Map.FreezeMonsters)
- return;
- Time32 Now = new Time32(time);
- foreach (IMapObject obj in client.Screen.Objects)
- {
- if (obj != null)
- {
- if (obj.MapObjType == MapObjectType.Monster)
- {
- Entity monster = obj as Entity;
- if (monster == null) continue;
- if (monster.Name == "CasprGuard" && !monster.Dead)
- {
- if (client.Player.Dead && !client.Player.ContainsFlag2(Update.Flags2.SoulShackle))
- {
- if (MyMath.Success(50.0))
- {
- client.Player.BringToLife();
- SpellUse use = new SpellUse(true);
- use.Attacker = monster.UID;
- use.X = client.Player.X;
- use.Y = client.Player.Y;
- use.SpellID = 1100;
- use.AddTarget(client.Player, 0, null);
- Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
- if (MyMath.Success(50.0))
- {
- use = new SpellUse(true);
- use.Attacker = monster.UID;
- use.X = client.Player.X;
- use.Y = client.Player.Y;
- use.SpellID = 30000;
- use.AddTarget(client.Player, 0, null);
- Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
- client.Player.AzureShieldDefence = (ushort)(3000 * 4);
- client.Player.AzureShieldLevel = 4;
- client.Player.MagicShieldStamp = Time32.Now;
- client.Player.AzureShieldStamp = DateTime.Now;
- client.Player.AddFlag2(Update.Flags2.AzureShield);
- client.Player.MagicShieldTime = 60;
- client.Player.AzureShieldPacket();
- if (client.Player.EntityFlag == EntityFlag.Entity)
- client.Send(Constants.Shield(12000, client.Player.MagicShieldTime));
- }
- else
- {
- use = new SpellUse(true);
- use.Attacker = monster.UID;
- use.X = client.Player.X;
- use.Y = client.Player.Y;
- use.SpellID = 6002;
- use.AddTarget(client.Player, 0, null);
- Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
- client.Player.AddFlag2(Update.Flags2.EffectBall);
- client.Player.NoDrugsStamp = Time32.Now;
- client.Player.NoDrugsTime = (short)60;
- if (client.Player.EntityFlag == EntityFlag.Entity)
- client.Send(Constants.NoDrugs(60));
- }
- }
- else
- {
- SpellUse use = new SpellUse(true);
- use.Attacker = monster.UID;
- use.X = client.Player.X;
- use.Y = client.Player.Y;
- use.SpellID = 10405;
- use.AddTarget(client.Player, 0, null);
- Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
- if (!client.Player.ContainsFlag2(Update.Flags2.SoulShackle))
- {
- client.Player.AddFlag2(Update.Flags2.SoulShackle);//Give them shackeld effect
- client.Player.ShackleStamp = Time32.Now;//Set stamp so source can remove the flag after X seconds
- client.Player.ShackleTime = 35;//(short)(30 + 15 * spell.Level);//double checking here. Could be db has this wrong.
- Network.GamePackets.Update upgrade = new Network.GamePackets.Update(true);
- upgrade.UID = client.Player.UID;
- upgrade.Append(Network.GamePackets.Update.SoulShackle
- , 111
- , 35, 0, 4);
- client.Player.Owner.Send(upgrade.ToArray());
- if (client.Player.EntityFlag == EntityFlag.Entity)
- client.Send(Constants.Shackled(client.Player.ShackleTime));
- }
- }
- }
- }
- if (monster.MonsterInfo.Guard || monster.Companion || monster.Dead) continue;
- if (monster.MonsterInfo.Reviver)
- {
- if (client.Player.Dead && Now > client.Player.DeathStamp.AddSeconds(5))
- {
- client.Player.BringToLife();
- SpellUse use = new SpellUse(true);
- use.Attacker = monster.UID;
- use.X = client.Player.X;
- use.Y = client.Player.Y;
- use.SpellID = 1100;
- use.AddTarget(client.Player, 0, null);
- Kernel.SendWorldMessage(use, Program.GamePool, monster.MapID);
- }
- return;
- }
- short distance = Kernel.GetDistance(monster.X, monster.Y, client.Player.X, client.Player.Y);
- if (distance > Constants.pScreenDistance)
- {
- client.Screen.Remove(obj);
- continue;
- }
- if (monster.MonsterInfo.InSight != 0 && monster.MonsterInfo.InSight != client.Player.UID)
- {
- if (monster.MonsterInfo.InSight > 1000000)
- {
- GameState cl;
- if (Kernel.GamePool.TryGetValue(monster.MonsterInfo.InSight, out cl))
- {
- short dst = Kernel.GetDistance(monster.X, monster.Y, cl.Player.X, cl.Player.Y);
- if (dst > Constants.pScreenDistance)
- monster.MonsterInfo.InSight = 0;
- }
- else
- monster.MonsterInfo.InSight = 0;
- }
- //else
- //{
- // Entity companion = client.Map.Companions[monster.MonsterInfo.InSight];
- // if (companion != null)
- // {
- // short dst = Kernel.GetDistance(monster.X, monster.Y, companion.X, companion.Y);
- // if (dst > Constants.pScreenDistance)
- // monster.MonsterInfo.InSight = 0;
- // }
- // else
- // monster.MonsterInfo.InSight = 0;
- //}
- }
- if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
- {
- if (distance <= Constants.pScreenDistance)
- {
- #region Companions
- foreach (var pet in client.Pet.Pets.Values)
- {
- if (pet != null)
- {
- #region Pets
- if (pet.Entity.Companion && !pet.Entity.Dead)
- {
- short distance2 = Kernel.GetDistance(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
- if (distance > distance2 || client.Player.ContainsFlag(Update.Flags.Invisibility) || client.Player.ContainsFlag(Update.Flags.Fly))
- {
- if (monster.MonsterInfo.InSight == 0)
- {
- monster.MonsterInfo.InSight = pet.Entity.UID;
- }
- else
- {
- if (monster.MonsterInfo.InSight == pet.Entity.UID)
- {
- if (distance2 > Constants.pScreenDistance)
- {
- monster.MonsterInfo.InSight = 0;
- }
- else
- {
- if (distance2 <= monster.MonsterInfo.AttackRange)
- {
- if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
- {
- monster.MonsterInfo.LastMove = Time32.Now;
- new Game.Attacking.Handle(null, monster, pet.Entity);
- if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
- {
- monster.MonsterInfo.Lastpop = Time32.Now;
- continue;
- }
- }
- }
- else
- {
- if (distance2 > monster.MonsterInfo.ViewRange / 2)
- {
- if (distance2 < Constants.pScreenDistance)
- {
- if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
- {
- monster.MonsterInfo.LastMove = Time32.Now;
- Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
- if (!monster.Move(facing))
- {
- facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
- if (monster.Move(facing))
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- move.GroundMovementType = GroundMovement.Run;
- monster.MonsterInfo.SendScreen(move);
- continue;
- }
- }
- else
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- move.GroundMovementType = GroundMovement.Run;
- monster.MonsterInfo.SendScreen(move);
- continue;
- }
- }
- }
- else
- {
- monster.MonsterInfo.InSight = 0;
- }
- }
- else
- {
- if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
- {
- monster.MonsterInfo.LastMove = Time32.Now;
- Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
- if (!monster.Move(facing))
- {
- facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
- if (monster.Move(facing))
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- monster.MonsterInfo.SendScreen(move);
- continue;
- }
- }
- else
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- monster.MonsterInfo.SendScreen(move);
- continue;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- #endregion
- }
- }
- #endregion
- #region Entity
- if (monster.MonsterInfo.InSight == 0)
- {
- if (distance <= monster.MonsterInfo.ViewRange)
- {
- if (!client.Player.ContainsFlag(Update.Flags.Invisibility))
- {
- if (monster.MonsterInfo.SpellID != 0 || !client.Player.ContainsFlag(Update.Flags.Fly))
- {
- monster.MonsterInfo.InSight = client.Player.UID;
- }
- }
- }
- }
- else
- {
- if (monster.MonsterInfo.InSight == client.Player.UID)
- {
- if (monster.MonsterInfo.SpellID == 0 && client.Player.ContainsFlag(Update.Flags.Fly))
- {
- monster.MonsterInfo.InSight = 0;
- return;
- }
- if (client.Player.Dead)
- {
- monster.MonsterInfo.InSight = 0;
- return;
- }
- if (distance > Constants.pScreenDistance)
- {
- monster.MonsterInfo.InSight = 0;
- }
- else
- {
- if (distance <= monster.MonsterInfo.AttackRange)
- {
- if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
- {
- monster.MonsterInfo.LastMove = Time32.Now;
- new Game.Attacking.Handle(null, monster, client.Player);
- if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
- {
- monster.MonsterInfo.Lastpop = Time32.Now;
- }
- }
- }
- else
- {
- if (distance > monster.MonsterInfo.ViewRange / 2)
- {
- if (distance < Constants.pScreenDistance)
- {
- if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
- {
- monster.MonsterInfo.LastMove = Time32.Now;
- Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Player.X, client.Player.Y);
- if (!monster.Move(facing))
- {
- facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
- if (monster.Move(facing))
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
- monster.MonsterInfo.SendScreen(move);
- }
- }
- else
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
- monster.MonsterInfo.SendScreen(move);
- }
- }
- }
- else
- {
- monster.MonsterInfo.InSight = 0;
- }
- }
- else
- {
- if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
- {
- monster.MonsterInfo.LastMove = Time32.Now;
- Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Player.X, client.Player.Y);
- if (!monster.Move(facing))
- {
- facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
- if (monster.Move(facing))
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- monster.MonsterInfo.SendScreen(move);
- }
- }
- else
- {
- monster.Facing = facing;
- GroundMovement move = new GroundMovement(true);
- move.Direction = facing;
- move.UID = monster.UID;
- monster.MonsterInfo.SendScreen(move);
- }
- }
- }
- }
- }
- }
- }
- #endregion
- }
- }
- }
- else if (obj.MapObjType == MapObjectType.Item)
- {
- FloorItem item = obj as FloorItem;
- if (item == null) continue;
- //if (item.ItemID == FloorItem.InfernalEcho)
- //{
- // if (item.Owner == client)
- // {
- // if (item.OnFloor.AddSeconds(4).Next(time: time))
- // {
- // item.UseTime = Time32.Now;
- // var spell = Database.SpellTable.GetSpell(12550, client);
- // var attack = new Attack(true);
- // attack.Attacker = item.Owner.Player.UID;
- // attack.AttackType = Attack.Melee;
- // foreach (var obj1 in client.Screen.Objects)
- // {
- // if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 10)
- // {
- // if (obj1.MapObjType == MapObjectType.Entity && client.Player.PKMode != Enums.PKMode.Capture)
- // {
- // var attacked = obj1 as Entity;
- // if (Attacking.Handle.CanAttack(client.Player, attacked, spell, false))
- // {
- // uint damage = Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack);
- // damage = (uint)(damage * 1.4);
- // attack.Damage = damage;
- // attack.Attacked = attacked.UID;
- // attack.X = attacked.X;
- // attack.Y = attacked.Y;
- // attacked.Update(_String.Effect, "twz_xldy_gj", true);
- // Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
- // }
- // }
- // if (obj1.MapObjType == MapObjectType.Monster)
- // {
- // var attacked = obj1 as Entity;
- // if (Attacking.Handle.CanAttack(client.Player, attacked, spell, false))
- // {
- // uint damage = Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack);
- // damage = (damage * 200) / 100;
- // attack.Damage = damage;
- // attack.Attacked = attacked.UID;
- // attack.X = attacked.X;
- // attack.Y = attacked.Y;
- // attacked.Update(_String.Effect, "twz_xldy_gj", true);
- // Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
- // }
- // }
- // }
- // }
- // }
- // }
- //}
- if (item.Type == FloorItem.Effect)
- {
- if (item.ItemID == FloorItem.RageOfWarTrap)
- {
- if (item.Owner == client)
- {
- if (item.OnFloor.AddSeconds(2).Next(time: time))
- {
- var spell = Database.SpellTable.GetSpell(12930, client);
- if (spell == null) return;
- var attack = new Attack(true);
- attack.Attacker = client.Player.UID;
- attack.AttackType = Attack.Melee;
- foreach (var obj1 in client.Screen.Objects)
- {
- if (obj1 == null)
- continue;
- var attacked = obj1 as Entity;
- if (attacked == null) continue;
- if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
- {
- if (Attacking.Handle.CanAttack(client.Player, attacked, spell, attack.AttackType == Attack.Melee))
- {
- uint damage = (uint)(Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack) * (spell.SecondDamage - 30000) / 100);
- attack.Effect1 = Attack.AttackEffects1.None;
- attack.Damage = damage;
- attack.Attacked = attacked.UID;
- attack.X = attacked.X;
- attack.Y = attacked.Y;
- attack.Effect1 = Attack.AttackEffects1.None;
- Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
- }
- }
- }
- }
- }
- }
- if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce)
- {
- if (item.Owner == client)
- {
- if (Time32.Now > item.UseTime.AddSeconds(1))
- {
- item.UseTime = Time32.Now;
- var spell = Database.SpellTable.GetSpell(11600, client);
- var attack = new Attack(true);
- attack.Attacker = item.Owner.Player.UID;
- attack.AttackType = Attack.Melee;
- foreach (var obj1 in client.Screen.Objects)
- {
- if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
- {
- if (obj1.MapObjType == MapObjectType.Monster || obj1.MapObjType == MapObjectType.Entity)
- {
- var attacked = obj1 as Entity;
- if (Attacking.Handle.CanAttack(client.Player, attacked, spell, false))
- {
- uint damage = Game.Attacking.Calculate.AttackingSpell(client.Player, attacked, spell, ref attack);
- attack.Damage = damage;
- attack.Attacked = attacked.UID;
- attack.X = attacked.X;
- attack.Y = attacked.Y;
- Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, ref damage, spell);
- }
- }
- else if (obj1.MapObjType == MapObjectType.SobNpc)
- {
- var attacked = obj1 as SobNpcSpawn;
- if (Attacking.Handle.CanAttack(client.Player, attacked, spell))
- {
- uint damage = Game.Attacking.Calculate.Melee(client.Player, attacked, ref attack);
- attack.Damage = damage;
- attack.Attacked = attacked.UID;
- attack.X = attacked.X;
- attack.Y = attacked.Y;
- Attacking.Handle.ReceiveAttack(client.Player, attacked, attack, damage, spell);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- =======================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement