Advertisement
XConquer

ScREEN

Jul 2nd, 2015
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 137.64 KB | None | 0 0
  1. using CM.Arg.Client;
  2. using CM.Arg.Interfaces;
  3. using CM.Arg.Network.GamePackets;
  4. using System;
  5. using System.Collections.Concurrent;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading;
  10. using System.Threading.Generic;
  11.  
  12. namespace CM.Arg.Game
  13. {
  14.     public class Screen
  15.     {
  16.         private static TimerRule<GameState> MonsterBuffers, Guards, AliveMonsters, Items, MatrixMobs;
  17.         public static void CreateTimerFactories()
  18.         {
  19.             MonsterBuffers = new TimerRule<GameState>(monsterBuffersCallback, 500);
  20.             Guards = new TimerRule<GameState>(guardsCallback, 700);
  21.             MatrixMobs = new TimerRule<GameState>(MatrixMobsCallback, 700);
  22.             AliveMonsters = new TimerRule<GameState>(aliveMonstersCallback, 500);
  23.             Items = new TimerRule<GameState>(FloorSpellsCallBack, 1000);
  24.  
  25.         }
  26.  
  27.         private static void monsterBuffersCallback(GameState client, int time)
  28.         {
  29.             if (!client.Socket.Alive)
  30.             {
  31.                 client.Screen.DisposeTimers();
  32.                 return;
  33.             }
  34.             if (client.Entity == null)
  35.                 return;
  36.             if (client.Map == null)
  37.                 return;
  38.             if (client.Map.FreezeMonsters)
  39.                 return;
  40.             #region EpicWater/Fire
  41.             if (Database.DataHolder.IsTaoist(client.Entity.Class))
  42.             {
  43.                 //water 4
  44.                 //Fire 7
  45.                 var Date = DateTime.Now;
  46.                 if (client.Entity.LastGetEnergy.AddSeconds(1) <= Date)
  47.                 {
  48.                     if (client.Entity.EpicTaoist())
  49.                     {
  50.                         if (client.Entity.Class >= 130 && client.Entity.Class <= 135)
  51.                         {
  52.                             if (220 > client.Entity.Energy)
  53.                             {
  54.                                 client.Entity.Energy += 20;
  55.                             }
  56.                         }
  57.                         else
  58.                         {
  59.                             if (client.Entity.Energy < 330)
  60.                             {
  61.                                 client.Entity.Energy += 70;
  62.                             }
  63.                         }
  64.                         client.Entity.LastGetEnergy = Date;
  65.                     }
  66.                     else
  67.                     {
  68.                         if (client.Entity.ContainsFlag3((ulong)Update.Flags3.AuroraLotus))
  69.                         {
  70.                             client.Entity.RemoveFlag3((ulong)Update.Flags3.AuroraLotus);
  71.                         }
  72.                         if (client.Entity.ContainsFlag3((ulong)Update.Flags3.FlameLotus))
  73.                         {
  74.                             client.Entity.RemoveFlag3((ulong)Update.Flags3.FlameLotus);
  75.                         }
  76.                         if (client.Entity.Energy > 0)
  77.                         {
  78.                             client.Entity.Energy = 0;
  79.                         }
  80.                     }
  81.                 }
  82.             }
  83.             #endregion
  84.             #region Stamina
  85.             if (client.Entity.StaminaStamp.Next(500, time: time))
  86.             {
  87.                 if (client.Vigor < client.Entity.ExtraVigor)
  88.                 {
  89.                     client.Vigor += (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
  90.  
  91.                     {
  92.                         Vigor vigor = new Vigor(true);
  93.                         vigor.Amount = client.Vigor;
  94.                         vigor.Send(client);
  95.                     }
  96.                 }
  97.                 if (!client.Entity.ContainsFlag(Update.Flags.Ride) && !client.Entity.ContainsFlag(Update.Flags.Fly) || client.Equipment.TryGetItem(18) != null)
  98.                 {
  99.                     int limit = 0;
  100.                     if (client.Entity.HeavenBlessing > 0)
  101.                         limit = 50;
  102.                     if (client.Entity.Stamina != 100 + limit)
  103.                     {
  104.                         if (client.Entity.Action == Enums.ConquerAction.Sit)
  105.                         {
  106.                             if (client.Entity.Stamina <= 93 + limit)
  107.                             {
  108.                                 client.Entity.Stamina += 7;
  109.                             }
  110.                             else
  111.                             {
  112.                                 if (client.Entity.Stamina != 100 + limit)
  113.                                     client.Entity.Stamina = (byte)(100 + limit);
  114.                             }
  115.                         }
  116.                         else
  117.                         {
  118.                             if (client.Entity.Stamina <= 97 + limit)
  119.                             {
  120.                                 client.Entity.Stamina += 3;
  121.                             }
  122.                             else
  123.                             {
  124.                                 if (client.Entity.Stamina != 100 + limit)
  125.                                     client.Entity.Stamina = (byte)(100 + limit);
  126.                             }
  127.                         }
  128.                     }
  129.                     client.Entity.StaminaStamp = new Time32(time);
  130.                 }
  131.             }
  132.             #endregion
  133.             if (client.Map.ID == 8880 || client.Map.ID == 8881 || client.Map.ID == 1002)
  134.             {
  135.                 SafeDictionary<uint, PokerTable> ToRem = new SafeDictionary<uint, PokerTable>(40);
  136.                 foreach (PokerTable T in PokerTables.Values)
  137.                 {
  138.                     if (client.Map.ID == T.Map)
  139.                         if (Kernel.GetDistance(T.X, T.Y, client.Entity.X, client.Entity.Y) > Constants.nScreenDistance)
  140.                             ToRem.Add(T.Id, T);
  141.                 }
  142.                 foreach (PokerTable T in ToRem.Values)
  143.                     if (PokerTables.ContainsKey(T.Id))
  144.                         PokerTables.Remove(T.Id);
  145.             }
  146.             foreach (IMapObject obj in client.Screen.Objects)
  147.             {
  148.                 if (obj != null)
  149.                 {
  150.                     if (obj.MapObjType == MapObjectType.Monster)
  151.                     {
  152.                         Entity monster = obj as Entity;
  153.                         if (monster == null) continue;
  154.  
  155.                         if (monster.ContainsFlag(Network.GamePackets.Update.Flags.Stigma))
  156.                         {
  157.                             if (monster.StigmaStamp.AddSeconds(monster.StigmaTime).Next(time: time) || monster.Dead)
  158.                             {
  159.                                 monster.StigmaTime = 0;
  160.                                 monster.StigmaIncrease = 0;
  161.                                 monster.RemoveFlag(Update.Flags.Stigma);
  162.                             }
  163.                         }
  164.                         if (monster.ContainsFlag(Update.Flags.Dodge))
  165.                         {
  166.                             if (monster.DodgeStamp.AddSeconds(monster.DodgeTime).Next(time: time) || monster.Dead)
  167.                             {
  168.                                 monster.DodgeTime = 0;
  169.                                 monster.DodgeIncrease = 0;
  170.                                 monster.RemoveFlag(Network.GamePackets.Update.Flags.Dodge);
  171.                             }
  172.                         }
  173.                         if (monster.ContainsFlag(Update.Flags.Invisibility))
  174.                         {
  175.                             if (monster.InvisibilityStamp.AddSeconds(monster.InvisibilityTime).Next(time: time) || monster.Dead)
  176.                             {
  177.                                 monster.RemoveFlag(Update.Flags.Invisibility);
  178.                             }
  179.                         }
  180.                         if (monster.ContainsFlag(Update.Flags.StarOfAccuracy))
  181.                         {
  182.                             if (monster.StarOfAccuracyTime != 0)
  183.                             {
  184.                                 if (monster.StarOfAccuracyStamp.AddSeconds(monster.StarOfAccuracyTime).Next(time: time) || monster.Dead)
  185.                                 {
  186.                                     monster.RemoveFlag(Update.Flags.StarOfAccuracy);
  187.                                 }
  188.                             }
  189.                             else
  190.                             {
  191.                                 if (monster.AccuracyStamp.AddSeconds(monster.AccuracyTime).Next(time: time) || monster.Dead)
  192.                                 {
  193.                                     monster.RemoveFlag(Update.Flags.StarOfAccuracy);
  194.                                 }
  195.                             }
  196.                         }
  197.                         if (monster.ContainsFlag(Update.Flags.MagicShield))
  198.                         {
  199.                             if (monster.MagicShieldTime != 0)
  200.                             {
  201.                                 if (monster.MagicShieldStamp.AddSeconds(monster.MagicShieldTime).Next(time: time) || monster.Dead)
  202.                                 {
  203.                                     monster.MagicShieldIncrease = 0;
  204.                                     monster.MagicShieldTime = 0;
  205.                                     monster.RemoveFlag(Update.Flags.MagicShield);
  206.                                 }
  207.                             }
  208.                             else
  209.                             {
  210.                                 if (monster.ShieldStamp.AddSeconds(monster.ShieldTime).Next(time: time) || monster.Dead)
  211.                                 {
  212.                                     monster.ShieldIncrease = 0;
  213.                                     monster.ShieldTime = 0;
  214.                                     monster.RemoveFlag(Update.Flags.MagicShield);
  215.                                 }
  216.                             }
  217.                         }
  218.                         if (monster.Dead || monster.Killed)
  219.                         {
  220.                             if (!monster.ContainsFlag(Update.Flags.Ghost) || monster.Killed)
  221.                             {
  222.                                 monster.Killed = false;
  223.                                 monster.MonsterInfo.InSight = 0;
  224.                                 monster.AddFlag(Network.GamePackets.Update.Flags.Ghost);
  225.                                 monster.AddFlag(Network.GamePackets.Update.Flags.Dead);
  226.                                 monster.AddFlag(Network.GamePackets.Update.Flags.FadeAway);
  227.                                 Network.GamePackets.Attack attack = new Network.GamePackets.Attack(true);
  228.                                 attack.Attacker = monster.Killer.UID;
  229.                                 attack.Attacked = monster.UID;
  230.                                 attack.AttackType = Network.GamePackets.Attack.Kill;
  231.                                 attack.X = monster.X;
  232.                                 attack.Y = monster.Y;
  233.                                 client.Map.Floor[monster.X, monster.Y, MapObjectType.Monster, monster] = true;
  234.                                 attack.KOCount = ++monster.Killer.KOCount;
  235.                                 if (monster.Killer.EntityFlag == EntityFlag.Player)
  236.                                 {
  237.                                     monster.MonsterInfo.ExcludeFromSend = monster.Killer.UID;
  238.                                     monster.Killer.Owner.Send(attack);
  239.                                 }
  240.                                 monster.MonsterInfo.SendScreen(attack);
  241.                                 monster.MonsterInfo.ExcludeFromSend = 0;
  242.                             }
  243.                             if (monster.DeathStamp.AddSeconds(4).Next(time: time))
  244.                             {
  245.                                 Data data = new Data(true);
  246.                                 data.UID = monster.UID;
  247.                                 data.ID = Network.GamePackets.Data.RemoveEntity;
  248.                                 monster.MonsterInfo.SendScreen(data);
  249.                             }
  250.                         }
  251.                     }
  252.                 }
  253.             }
  254.         }
  255.         private static void FloorSpellsCallBack(GameState client, int time)
  256.         {
  257.             if (!client.Socket.Alive)
  258.             {
  259.                 client.Screen.DisposeTimers();
  260.                 return;
  261.             }
  262.             if (client.Entity == null) return;
  263.             if (client.Map == null) return;
  264.             Time32 Now = new Time32(time);
  265.             if (client.Entity.FloorSpells.Count != 0)
  266.             {
  267.                 foreach (var ID in client.Entity.FloorSpells)
  268.                 {
  269.                     switch (ID.Key)
  270.                     {
  271.  
  272.                         #region Habilidad AuroraLotus
  273.                         case 12370://AuroraLouts:
  274.                             {
  275.                                 var spellclient = ID.Value;
  276.                                 Queue<Game.Attacking.FloorSpell> RemoveSpells = new Queue<Game.Attacking.FloorSpell>();
  277.                                 foreach (var spell in spellclient.Spells)
  278.                                 {
  279.                                     if (spellclient.CheckInvocke(Now, spell))
  280.                                     {
  281.                                         RemoveSpells.Enqueue(spell);
  282.                                         spellclient.CreateMsgSpell(100);
  283.                                         var attack = new Attack(true);
  284.                                         attack.Attacker = client.Entity.UID;
  285.                                         attack.AttackType = Attack.Melee;
  286.                                         foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  287.                                         {
  288.                                             if (_obj == null) continue;
  289.                                             if (_obj.MapObjType == MapObjectType.Player)
  290.                                             {
  291.                                                 var attacked = _obj as Entity;
  292.                                                 if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) <= 15)
  293.                                                 {
  294.                                                     attacked.BringToLifeLotus();
  295.                                                 }
  296.                                             }
  297.                                         }
  298.                                         spellclient.SendView(client);
  299.  
  300.                                         spell.FloorPacket.Type = FloorItem.RemoveEffect;
  301.                                         client.SendScreen(spell.FloorPacket, true);
  302.                                     }
  303.                                 }
  304.                                 while (RemoveSpells.Count > 0)
  305.                                     spellclient.RemoveItem(RemoveSpells.Dequeue());
  306.                                 if (spellclient.Spells.Count == 0)
  307.                                 {
  308.                                     Game.Attacking.FloorSpell.ClientFloorSpells FloorSpell;
  309.                                     client.Entity.FloorSpells.TryRemove(spellclient.DBSkill.ID, out FloorSpell);
  310.                                 }
  311.                                 break;
  312.                             }
  313.                         #endregion
  314.  
  315.                         #region Habilidad FlameLotus
  316.                         case 12380://FlameLouts:
  317.                             {
  318.                                 var spellclient = ID.Value;
  319.                                 Queue<Game.Attacking.FloorSpell> RemoveSpells = new Queue<Game.Attacking.FloorSpell>();
  320.                                 foreach (var spell in spellclient.Spells)
  321.                                 {
  322.                                     if (spellclient.CheckInvocke(Now, spell))
  323.                                     {
  324.                                         RemoveSpells.Enqueue(spell);
  325.                                         spellclient.CreateMsgSpell(100);
  326.                                         var attack = new Attack(true);
  327.                                         attack.Attacker = client.Entity.UID;
  328.                                         attack.AttackType = Attack.Melee;
  329.                                         foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  330.                                         {
  331.                                             if (_obj == null) continue;
  332.                                             if (_obj.MapObjType == MapObjectType.Monster)
  333.                                             {
  334.                                                 var attacked = _obj as Entity;
  335.                                                 if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) <= 15)
  336.                                                 {
  337.                                                     if (!Game.Attacking.Handle.CanAttack(client.Entity, attacked, spell.DBSkill, false)) continue;
  338.                                                     attack.Effect1 = Attack.AttackEffects1.Penetration;
  339.                                                     uint damage = Game.Attacking.Calculate.Magic(client.Entity, attacked, spell.DBSkill, ref attack) * 10;
  340.                                                    
  341.                                                     spellclient.SpellPacket.Effect1 = attack.Effect1;
  342.                                                     attack.Damage = damage * 2;
  343.                                                     Game.Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell.DBSkill);
  344.                                                     spellclient.SpellPacket.AddTarget1(attacked, damage, attack);
  345.                                                 }
  346.                                             }
  347.                                             if (_obj.MapObjType == MapObjectType.Player)
  348.                                             {
  349.                                                 var attacked = _obj as Entity;
  350.                                                 if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) <= 15)
  351.                                                 {
  352.                                                     if (!Game.Attacking.Handle.CanAttack(client.Entity, attacked, spell.DBSkill, false)) continue;
  353.                                                     attack.Effect1 = Attack.AttackEffects1.None;
  354.                                                     uint damage = Game.Attacking.Calculate.Magic(client.Entity, attacked, spell.DBSkill, ref attack) * 10;
  355.                                                     spellclient.SpellPacket.Effect1 = attack.Effect1;
  356.                                                     attack.Damage = damage;
  357.                                                     Game.Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell.DBSkill);
  358.                                                     spellclient.SpellPacket.AddTarget1(attacked, damage, attack);
  359.                                                 }
  360.                                             }
  361.                                         }
  362.                                         spellclient.SendView(client);
  363.  
  364.                                         spell.FloorPacket.Type = FloorItem.RemoveEffect;
  365.                                         client.SendScreen(spell.FloorPacket, true);
  366.                                     }
  367.                                 }
  368.                                 while (RemoveSpells.Count > 0)
  369.                                     spellclient.RemoveItem(RemoveSpells.Dequeue());
  370.                                 if (spellclient.Spells.Count == 0)
  371.                                 {
  372.                                     Game.Attacking.FloorSpell.ClientFloorSpells FloorSpell;
  373.                                     client.Entity.FloorSpells.TryRemove(spellclient.DBSkill.ID, out FloorSpell);
  374.                                 }
  375.                                 break;
  376.                             }
  377.                         #endregion
  378.  
  379.                         #region Habilidad TwilightDance
  380.                         case 12070://TwilightDance:
  381.                             {
  382.                                 var spellclient = ID.Value;
  383.                                 Queue<Game.Attacking.FloorSpell> RemoveSpells = new Queue<Game.Attacking.FloorSpell>();
  384.                                 foreach (var spell in spellclient.Spells)
  385.                                 {
  386.                                     if (spellclient.CheckInvocke(Now, spell))
  387.                                     {
  388.                                         RemoveSpells.Enqueue(spell);
  389.                                         spellclient.CreateMsgSpell(100);
  390.                                         var attack = new Attack(true);
  391.                                         attack.Attacker = client.Entity.UID;
  392.                                         attack.AttackType = Attack.Melee;
  393.                                         foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  394.                                         {
  395.                                             if (_obj == null) continue;
  396.                                             if (_obj.MapObjType == MapObjectType.Monster || _obj.MapObjType == MapObjectType.Player)
  397.                                             {
  398.                                                 var attacked = _obj as Entity;
  399.                                                 if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attacked.X, attacked.Y) < 3)
  400.                                                 {
  401.                                                     if (!Game.Attacking.Handle.CanAttack(client.Entity, attacked, spell.DBSkill, false)) continue;
  402.                                                     attack.Effect1 = Attack.AttackEffects1.None;
  403.                                                     uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell.DBSkill, ref attack);
  404.                                                     damage += (uint)((damage) / 2);
  405.                                                     spellclient.SpellPacket.Effect1 = attack.Effect1;
  406.                                                     attack.Damage = damage;
  407.                                                     Game.Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell.DBSkill);
  408.                                                     spellclient.SpellPacket.AddTarget1(attacked, damage, attack);
  409.                                                 }
  410.                                             }
  411.                                             else if (_obj.MapObjType == MapObjectType.SobNpc)
  412.                                             {
  413.                                                 var attackedsob = _obj as SobNpcSpawn;
  414.  
  415.                                                 if (Kernel.GetDistance(spell.FloorPacket.X, spell.FloorPacket.Y, attackedsob.X, attackedsob.Y) < 3)
  416.                                                 {
  417.                                                     if (!Game.Attacking.Handle.CanAttack(client.Entity, attackedsob, spell.DBSkill)) continue;
  418.                                                     attack.Effect1 = Attack.AttackEffects1.None;
  419.                                                     uint damage = Game.Attacking.Calculate.Melee(client.Entity, attackedsob, ref attack);
  420.                                                     attack.Damage = damage;
  421.                                                     Game.Attacking.Handle.ReceiveAttack(client.Entity, attackedsob, attack, damage, spell.DBSkill);
  422.                                                     spellclient.SpellPacket.AddTarget1(attackedsob, damage, attack);
  423.                                                 }
  424.                                             }
  425.                                         }
  426.                                         spellclient.SendView(client);
  427.                                         Data datap = new Data(true);
  428.                                         datap.UID = spell.FloorPacket.UID;
  429.                                         datap.dwParam = (uint)((spell.FloorPacket.Y << 16) | spell.FloorPacket.X);
  430.                                         datap.wParam2 = (ushort)(spell.FloorPacket.Y - 2);
  431.                                         datap.wParam1 = (ushort)(spell.FloorPacket.X - 3);
  432.                                         datap.ID = Data.RemoveTrap;
  433.                                         client.SendScreen(datap, true);
  434.                                         spell.FloorPacket.Type = FloorItem.RemoveEffect;
  435.                                         client.SendScreen(spell.FloorPacket, true);
  436.                                     }
  437.                                 }
  438.                                 while (RemoveSpells.Count > 0)
  439.                                     spellclient.RemoveItem(RemoveSpells.Dequeue());
  440.                                 if (spellclient.Spells.Count == 0)
  441.                                 {
  442.                                     Game.Attacking.FloorSpell.ClientFloorSpells FloorSpell;
  443.                                     client.Entity.FloorSpells.TryRemove(spellclient.DBSkill.ID, out FloorSpell);
  444.                                 }
  445.                                 break;
  446.                             }
  447.                         #endregion
  448.  
  449.                     }
  450.                 }
  451.             }
  452.         }
  453.  
  454.         private static void guardsCallback(GameState client, int time)
  455.         {
  456.             if (!client.Socket.Alive)
  457.             {
  458.                 client.Screen.DisposeTimers();
  459.                 return;
  460.             }
  461.             if (client.Entity == null)
  462.                 return;
  463.             if (client.Map == null)
  464.                 return;
  465.             if (client.Map.FreezeMonsters)
  466.                 return;
  467.  
  468.             Time32 Now = new Time32(time);
  469.             foreach (IMapObject obj in client.Screen.Objects)
  470.             {
  471.                 if (obj != null)
  472.                 {
  473.                     if (obj.MapObjType == MapObjectType.Monster)
  474.                     {
  475.                         Entity monster = obj as Entity;
  476.                         if (monster.Companion) continue;
  477.                         if (monster.Boss == 1 || monster.MonsterInfo.Boss) continue;
  478.                         if (monster.Dead || monster.Killed) continue;
  479.  
  480.                         if (monster.MonsterInfo.Guard)
  481.                         {
  482.                             if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  483.                             {
  484.                                 if (monster.MonsterInfo.InSight == 0)
  485.                                 {
  486.                                     ushort xx = (ushort)Kernel.Random.Next(monster.X - 2, monster.X + 2);
  487.                                     ushort yy = (ushort)Kernel.Random.Next(monster.Y - 2, monster.Y + 2);
  488.                                     if (monster.X != monster.MonsterInfo.BoundX || monster.Y != monster.MonsterInfo.BoundY)
  489.                                     {
  490.                                         monster.X = monster.MonsterInfo.BoundX;
  491.                                         monster.Y = monster.MonsterInfo.BoundY;
  492.                                         TwoMovements jump = new TwoMovements();
  493.                                         jump.X = monster.MonsterInfo.BoundX;
  494.                                         jump.Y = monster.MonsterInfo.BoundY;
  495.                                         jump.EntityCount = 1;
  496.                                         jump.FirstEntity = monster.UID;
  497.                                         jump.MovementType = TwoMovements.Jump;
  498.                                         client.SendScreen(jump, true);
  499.                                     }
  500.  
  501.                                     if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  502.                                         monster.MonsterInfo.InSight = client.Entity.UID;
  503.                                 }
  504.                                 else
  505.                                 {
  506.                                     if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  507.                                     {
  508.                                         if (monster.MonsterInfo.InSight == client.Entity.UID)
  509.                                         {
  510.                                             if (!client.Entity.Dead)
  511.                                             {
  512.                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  513.                                                 {
  514.                                                     short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  515.  
  516.                                                     if (distance <= monster.MonsterInfo.AttackRange)
  517.                                                     {
  518.                                                         monster.MonsterInfo.LastMove = Time32.Now;
  519.                                                         new Game.Attacking.Handle(null, monster, client.Entity);
  520.                                                     }
  521.                                                     else
  522.                                                     {
  523.                                                         if (distance <= monster.MonsterInfo.ViewRange)
  524.                                                         {
  525.                                                             TwoMovements jump = new TwoMovements();
  526.                                                             jump.X = client.Entity.X;
  527.                                                             jump.Y = client.Entity.Y;
  528.                                                             monster.X = client.Entity.X;
  529.                                                             monster.Y = client.Entity.Y;
  530.                                                             jump.EntityCount = 1;
  531.                                                             jump.FirstEntity = monster.UID;
  532.                                                             jump.MovementType = TwoMovements.Jump;
  533.                                                             client.SendScreen(jump, true);
  534.                                                         }
  535.                                                     }
  536.                                                 }
  537.                                             }
  538.                                         }
  539.                                     }
  540.                                     else
  541.                                     {
  542.                                         if (monster.MonsterInfo.InSight == client.Entity.UID)
  543.                                         {
  544.                                             monster.MonsterInfo.InSight = 0;
  545.                                         }
  546.                                     }
  547.                                 }
  548.  
  549.                                 foreach (IMapObject obj2 in client.Screen.Objects)
  550.                                 {
  551.                                     if (obj2 == null) continue;
  552.                                     //if (obj2.MapObjType == MapObjectType.Item)
  553.                                     //{
  554.                                     //    FloorItem flooritem = obj2 as FloorItem;
  555.                                     //    if (flooritem == null) continue;
  556.                                     //    if (flooritem.ValueType == FloorItem.FloorValueType.Money)
  557.                                     //    {
  558.                                     //        short distance = Kernel.GetDistance(monster.X, monster.Y, flooritem.X, flooritem.Y);
  559.                                     //        if (distance <= 15)
  560.                                     //        {
  561.                                     //            FloorItem item = new FloorItem(true);
  562.                                     //            item.Type = 3;
  563.                                     //            item.UID = client.Entity.UID;
  564.                                     //            item.X = client.Entity.X;
  565.                                     //            item.Y = client.Entity.Y;
  566.                                     //            //  client.Send(Constants.PickupGold(floorItem.Value));
  567.                                     //            monster.MonsterInfo.SendScreen(item);
  568.                                     //            flooritem.Type = 2;
  569.                                     //            client.RemoveScreenSpawn(flooritem, true);
  570.  
  571.                                     //        }
  572.                                     //    }
  573.                                     //}
  574.                                     if (obj2.MapObjType == MapObjectType.Monster)
  575.                                     {
  576.                                         Entity monster2 = obj2 as Entity;
  577.  
  578.                                         if (monster2 == null) continue;
  579.                                         if (monster2.Dead) continue;
  580.  
  581.                                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  582.                                         {
  583.                                             if (!monster2.MonsterInfo.Guard && (!monster2.Companion || monster2.Owner.Entity.ContainsFlag(Update.Flags.FlashingName)))
  584.                                             {
  585.                                                 short distance = Kernel.GetDistance(monster.X, monster.Y, monster2.X, monster2.Y);
  586.  
  587.                                                 if (distance <= monster.MonsterInfo.AttackRange)
  588.                                                 {
  589.                                                     monster.MonsterInfo.LastMove = Time32.Now;
  590.                                                     new Game.Attacking.Handle(null, monster, monster2);
  591.                                                 }
  592.                                             }
  593.                                         }
  594.                                     }
  595.                                 }
  596.                             }
  597.                         }
  598.                     }
  599.                 }
  600.             }
  601.         }
  602.         private static void aliveMonstersCallback(GameState client, int time)
  603.         {
  604.             if (!client.Socket.Alive)
  605.             {
  606.                 client.Screen.DisposeTimers();
  607.                 return;
  608.             }
  609.             if (client.Entity == null)
  610.                 return;
  611.             if (client.Map == null)
  612.                 return;
  613.             if (client.Map.FreezeMonsters)
  614.                 return;
  615.  
  616.             Time32 Now = new Time32(time);
  617.             foreach (IMapObject obj in client.Screen.Objects)
  618.             {
  619.                 if (obj != null)
  620.                 {
  621.                     if (obj.MapObjType == MapObjectType.Monster)
  622.                     {
  623.                         Entity monster = obj as Entity;
  624.                         if (monster == null) continue;
  625.                         if (monster.MonsterInfo.Guard || monster.Companion || monster.Dead) continue;
  626.                         if (monster.MonsterInfo.Reviver)
  627.                         {
  628.                             if (client.Entity.Dead && Now > client.Entity.DeathStamp.AddSeconds(5))
  629.                             {
  630.                                 client.Entity.BringToLife();
  631.                                 SpellUse use = new SpellUse(true);
  632.                                 use.Attacker = monster.UID;
  633.                                 use.X = client.Entity.X;
  634.                                 use.Y = client.Entity.Y;
  635.                                 use.SpellID = 1100;
  636.                                 use.AddTarget(client.Entity, 0, null);
  637.                                 Kernel.SendWorldMessage(use, Program.Values, monster.MapID);
  638.                             }
  639.                             return;
  640.                         }
  641.                         short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  642.                         if (distance > Constants.pScreenDistance)
  643.                         {
  644.                             client.Screen.Remove(obj);
  645.                             continue;
  646.                         }
  647.                         if (monster.MonsterInfo.InSight != 0 && monster.MonsterInfo.InSight != client.Entity.UID)
  648.                         {
  649.                             if (monster.MonsterInfo.InSight > 1000000)
  650.                             {
  651.                                 GameState cl;
  652.                                 if (Kernel.GamePool.TryGetValue(monster.MonsterInfo.InSight, out cl) || CrossServer.CrossPool.TryGetValue(monster.MonsterInfo.InSight, out cl))
  653.                                 {
  654.                                     short dst = Kernel.GetDistance(monster.X, monster.Y, cl.Entity.X, cl.Entity.Y);
  655.                                     if (dst > Constants.pScreenDistance)
  656.                                         monster.MonsterInfo.InSight = 0;
  657.                                 }
  658.                                 else
  659.                                     monster.MonsterInfo.InSight = 0;
  660.                             }
  661.                             //else
  662.                             //{
  663.                             //    Entity companion = client.Map.Companions[monster.MonsterInfo.InSight];
  664.                             //    if (companion != null)
  665.                             //    {
  666.                             //        short dst = Kernel.GetDistance(monster.X, monster.Y, companion.X, companion.Y);
  667.                             //        if (dst > Constants.pScreenDistance)
  668.                             //            monster.MonsterInfo.InSight = 0;
  669.                             //    }
  670.                             //    else
  671.                             //        monster.MonsterInfo.InSight = 0;
  672.                             //}
  673.                         }
  674.                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  675.                         {
  676.                             if (distance <= Constants.pScreenDistance)
  677.                             {
  678.                                 #region Companions
  679.                                 if (client.Pet != null)
  680.                                 {
  681.                                     if (client.Pet.Pets != null)
  682.                                     {
  683.                                         foreach (var pet in client.Pet.Pets.Values)
  684.                                         {
  685.                                             if (pet != null)
  686.                                             {
  687.                                                 #region Pets
  688.                                                 if (pet.Entity.Companion && !pet.Entity.Dead)
  689.                                                 {
  690.                                                     short distance2 = Kernel.GetDistance(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  691.                                                     if (distance > distance2 || client.Entity.ContainsFlag(Update.Flags.Invisibility) || client.Entity.ContainsFlag(Update.Flags.Fly))
  692.                                                     {
  693.                                                         if (monster.MonsterInfo.InSight == 0)
  694.                                                         {
  695.                                                             monster.MonsterInfo.InSight = pet.Entity.UID;
  696.                                                         }
  697.                                                         else
  698.                                                         {
  699.                                                             if (monster.MonsterInfo.InSight == pet.Entity.UID)
  700.                                                             {
  701.                                                                 if (distance2 > Constants.pScreenDistance)
  702.                                                                 {
  703.                                                                     monster.MonsterInfo.InSight = 0;
  704.                                                                 }
  705.                                                                 else
  706.                                                                 {
  707.                                                                     if (distance2 <= monster.MonsterInfo.AttackRange)
  708.                                                                     {
  709.                                                                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  710.                                                                         {
  711.                                                                             monster.MonsterInfo.LastMove = Time32.Now;
  712.                                                                             new Game.Attacking.Handle(null, monster, pet.Entity);
  713.                                                                             if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  714.                                                                             {
  715.                                                                                 monster.MonsterInfo.Lastpop = Time32.Now;
  716.  
  717.                                                                                 continue;
  718.                                                                             }
  719.                                                                         }
  720.                                                                     }
  721.                                                                     else
  722.                                                                     {
  723.                                                                         if (distance2 > monster.MonsterInfo.ViewRange / 2)
  724.                                                                         {
  725.                                                                             if (distance2 < Constants.pScreenDistance)
  726.                                                                             {
  727.                                                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  728.                                                                                 {
  729.                                                                                     monster.MonsterInfo.LastMove = Time32.Now;
  730.  
  731.                                                                                     Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  732.                                                                                     if (!monster.Move(facing))
  733.                                                                                     {
  734.                                                                                         facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  735.                                                                                         if (monster.Move(facing))
  736.                                                                                         {
  737.                                                                                             monster.Facing = facing;
  738.                                                                                             GroundMovement move = new GroundMovement(true);
  739.                                                                                             move.Direction = facing;
  740.                                                                                             move.UID = monster.UID;
  741.                                                                                             move.GroundMovementType = GroundMovement.Run;
  742.                                                                                             monster.MonsterInfo.SendScreen(move);
  743.                                                                                             continue;
  744.                                                                                         }
  745.                                                                                     }
  746.                                                                                     else
  747.                                                                                     {
  748.                                                                                         monster.Facing = facing;
  749.                                                                                         GroundMovement move = new GroundMovement(true);
  750.                                                                                         move.Direction = facing;
  751.                                                                                         move.UID = monster.UID;
  752.                                                                                         move.GroundMovementType = GroundMovement.Run;
  753.                                                                                         monster.MonsterInfo.SendScreen(move);
  754.                                                                                         continue;
  755.                                                                                     }
  756.                                                                                 }
  757.                                                                             }
  758.                                                                             else
  759.                                                                             {
  760.                                                                                 monster.MonsterInfo.InSight = 0;
  761.                                                                             }
  762.                                                                         }
  763.                                                                         else
  764.                                                                         {
  765.                                                                             if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  766.                                                                             {
  767.                                                                                 monster.MonsterInfo.LastMove = Time32.Now;
  768.                                                                                 Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  769.                                                                                 if (!monster.Move(facing))
  770.                                                                                 {
  771.                                                                                     facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  772.                                                                                     if (monster.Move(facing))
  773.                                                                                     {
  774.                                                                                         monster.Facing = facing;
  775.                                                                                         GroundMovement move = new GroundMovement(true);
  776.                                                                                         move.Direction = facing;
  777.                                                                                         move.UID = monster.UID;
  778.                                                                                         monster.MonsterInfo.SendScreen(move);
  779.                                                                                         continue;
  780.                                                                                     }
  781.                                                                                 }
  782.                                                                                 else
  783.                                                                                 {
  784.                                                                                     monster.Facing = facing;
  785.                                                                                     GroundMovement move = new GroundMovement(true);
  786.                                                                                     move.Direction = facing;
  787.                                                                                     move.UID = monster.UID;
  788.                                                                                     monster.MonsterInfo.SendScreen(move);
  789.                                                                                     continue;
  790.                                                                                 }
  791.                                                                             }
  792.                                                                         }
  793.                                                                     }
  794.                                                                 }
  795.                                                             }
  796.                                                         }
  797.                                                     }
  798.                                                 }
  799.                                                 #endregion
  800.                                             }
  801.  
  802.                                         }
  803.                                     }
  804.                                 }
  805.                                 #endregion
  806.                                 #region Player
  807.                                 if (monster.MonsterInfo.InSight == 0)
  808.                                 {
  809.                                     if (distance <= monster.MonsterInfo.ViewRange)
  810.                                     {
  811.                                         if (!client.Entity.ContainsFlag(Update.Flags.Invisibility))
  812.                                         {
  813.                                             if (monster.MonsterInfo.SpellID != 0 || !client.Entity.ContainsFlag(Update.Flags.Fly))
  814.                                             {
  815.                                                 monster.MonsterInfo.InSight = client.Entity.UID;
  816.                                             }
  817.                                         }
  818.                                     }
  819.                                 }
  820.                                 else
  821.                                 {
  822.                                     if (monster.MonsterInfo.InSight == client.Entity.UID)
  823.                                     {
  824.                                         if (monster.MonsterInfo.SpellID == 0 && client.Entity.ContainsFlag(Update.Flags.Fly))
  825.                                         {
  826.                                             monster.MonsterInfo.InSight = 0;
  827.                                             return;
  828.                                         }
  829.  
  830.                                         if (client.Entity.Dead)
  831.                                         {
  832.                                             monster.MonsterInfo.InSight = 0;
  833.                                             return;
  834.                                         }
  835.                                         if (distance > Constants.pScreenDistance)
  836.                                         {
  837.                                             monster.MonsterInfo.InSight = 0;
  838.                                         }
  839.                                         else
  840.                                         {
  841.                                             if (distance <= monster.MonsterInfo.AttackRange)
  842.                                             {
  843.                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  844.                                                 {
  845.                                                     monster.MonsterInfo.LastMove = Time32.Now;
  846.                                                     new Game.Attacking.Handle(null, monster, client.Entity);
  847.                                                     if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  848.                                                     {
  849.                                                         monster.MonsterInfo.Lastpop = Time32.Now;
  850.                                                     }
  851.                                                 }
  852.                                             }
  853.                                             else
  854.                                             {
  855.                                                 if (distance > monster.MonsterInfo.ViewRange / 2)
  856.                                                 {
  857.                                                     if (distance < Constants.pScreenDistance)
  858.                                                     {
  859.                                                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  860.                                                         {
  861.                                                             monster.MonsterInfo.LastMove = Time32.Now;
  862.  
  863.                                                             Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  864.                                                             if (!monster.Move(facing))
  865.                                                             {
  866.                                                                 facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  867.                                                                 if (monster.Move(facing))
  868.                                                                 {
  869.                                                                     monster.Facing = facing;
  870.                                                                     GroundMovement move = new GroundMovement(true);
  871.                                                                     move.Direction = facing;
  872.                                                                     move.UID = monster.UID;
  873.                                                                     move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  874.                                                                     monster.MonsterInfo.SendScreen(move);
  875.                                                                 }
  876.                                                             }
  877.                                                             else
  878.                                                             {
  879.                                                                 monster.Facing = facing;
  880.                                                                 GroundMovement move = new GroundMovement(true);
  881.                                                                 move.Direction = facing;
  882.                                                                 move.UID = monster.UID;
  883.                                                                 move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  884.                                                                 monster.MonsterInfo.SendScreen(move);
  885.                                                             }
  886.                                                         }
  887.                                                     }
  888.                                                     else
  889.                                                     {
  890.                                                         monster.MonsterInfo.InSight = 0;
  891.                                                     }
  892.                                                 }
  893.                                                 else
  894.                                                 {
  895.                                                     if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  896.                                                     {
  897.                                                         monster.MonsterInfo.LastMove = Time32.Now;
  898.                                                         Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  899.                                                         if (!monster.Move(facing))
  900.                                                         {
  901.                                                             facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  902.                                                             if (monster.Move(facing))
  903.                                                             {
  904.                                                                 monster.Facing = facing;
  905.                                                                 GroundMovement move = new GroundMovement(true);
  906.                                                                 move.Direction = facing;
  907.                                                                 move.UID = monster.UID;
  908.                                                                 monster.MonsterInfo.SendScreen(move);
  909.                                                             }
  910.                                                         }
  911.                                                         else
  912.                                                         {
  913.                                                             monster.Facing = facing;
  914.                                                             GroundMovement move = new GroundMovement(true);
  915.                                                             move.Direction = facing;
  916.                                                             move.UID = monster.UID;
  917.                                                             monster.MonsterInfo.SendScreen(move);
  918.                                                         }
  919.                                                     }
  920.                                                 }
  921.                                             }
  922.                                         }
  923.                                     }
  924.                                 }
  925.                                 #endregion
  926.                             }
  927.                         }
  928.                     }
  929.                     else if (obj.MapObjType == MapObjectType.Item)
  930.                     {
  931.                         FloorItem item = obj as FloorItem;
  932.                         if (item == null) continue;
  933.                         if (item.Type == FloorItem.Effect)
  934.                         {
  935.                             if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce)
  936.                             {
  937.                                 if (item.Owner == client)
  938.                                 {
  939.                                     if (Time32.Now > item.UseTime.AddSeconds(1))
  940.                                     {
  941.                                         item.UseTime = Time32.Now;
  942.                                         var spell = Database.SpellTable.GetSpell(11600, client);
  943.  
  944.                                         var attack = new Attack(true);
  945.                                         attack.Attacker = item.Owner.Entity.UID;
  946.                                         attack.AttackType = Attack.Melee;
  947.  
  948.                                         foreach (var obj1 in client.Screen.Objects)
  949.                                         {
  950.                                             if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  951.                                             {
  952.                                                 if (obj1.MapObjType == MapObjectType.Monster || obj1.MapObjType == MapObjectType.Player)
  953.                                                 {
  954.                                                     var attacked = obj1 as Entity;
  955.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  956.                                                     {
  957.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  958.                                                         damage = (damage * 2) / 30;
  959.                                                         attack.Damage = damage;
  960.                                                         attack.Attacked = attacked.UID;
  961.                                                         attack.X = attacked.X;
  962.                                                         attack.Y = attacked.Y;
  963.  
  964.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  965.                                                     }
  966.                                                 }
  967.                                                 else if (obj1.MapObjType == MapObjectType.SobNpc)
  968.                                                 {
  969.                                                     var attacked = obj1 as SobNpcSpawn;
  970.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell))
  971.                                                     {
  972.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, ref attack);
  973.                                                         damage = (damage * 2) / 30;
  974.  
  975.                                                         attack.Damage = damage;
  976.                                                         attack.Attacked = attacked.UID;
  977.                                                         attack.X = attacked.X;
  978.                                                         attack.Y = attacked.Y;
  979.  
  980.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell);
  981.                                                     }
  982.                                                 }
  983.                                             }
  984.                                         }
  985.                                     }
  986.                                 }
  987.                             }
  988.                             if (item.ItemID == FloorItem.FlameLotus)
  989.                             {
  990.                                 if (item.Owner == client)
  991.                                 {
  992.                                     if (item.OnFloor.AddSeconds(8).Next(time: time))
  993.                                     {
  994.                                         item.UseTime = Time32.Now;
  995.                                         var spell = Database.SpellTable.GetSpell(12380, client);
  996.  
  997.                                         var attack = new Attack(true);
  998.                                         attack.Attacker = item.Owner.Entity.UID;
  999.                                         attack.AttackType = Attack.Melee;
  1000.  
  1001.                                         foreach (var obj1 in client.Screen.Objects)
  1002.                                         {
  1003.                                             if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  1004.                                             {
  1005.                                                 if (obj1.MapObjType == MapObjectType.Player)
  1006.                                                 {
  1007.                                                     var attacked = obj1 as Entity;
  1008.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  1009.                                                     {
  1010.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  1011.                                                         damage = (damage * 100000000) / 100;
  1012.                                                         attack.Damage = damage;
  1013.                                                         attack.Attacked = attacked.UID;
  1014.                                                         attack.X = attacked.X;
  1015.                                                         attack.Y = attacked.Y;
  1016.  
  1017.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  1018.                                                     }
  1019.                                                 }
  1020.                                                 if (obj1.MapObjType == MapObjectType.Monster)
  1021.                                                 {
  1022.                                                     var attacked = obj1 as Entity;
  1023.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  1024.                                                     {
  1025.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  1026.                                                         damage = (damage * 100000000) / 100;
  1027.                                                         attack.Damage = damage;
  1028.                                                         attack.Attacked = attacked.UID;
  1029.                                                         attack.X = attacked.X;
  1030.                                                         attack.Y = attacked.Y;
  1031.  
  1032.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  1033.                                                     }
  1034.                                                 }
  1035.                                             }
  1036.                                         }
  1037.                                     }
  1038.                                 }
  1039.                             }
  1040.                         }
  1041.                     }
  1042.                 }
  1043.             }
  1044.         }
  1045.  
  1046.     /*    private static void itemsCallback(GameState client, int time)
  1047.         {
  1048.             if (!client.Socket.Alive)
  1049.             {
  1050.                 client.Screen.DisposeTimers(); return;
  1051.             }
  1052.             if (client.Entity == null) return;
  1053.             if (client.Map == null) return;
  1054.             if (client.Map.FreezeMonsters) return;
  1055.             Time32 Now = new Time32(time);
  1056.             foreach (IMapObject obj in client.Screen.Objects)
  1057.             {
  1058.                 if (obj != null)
  1059.                 {
  1060.                     if (obj.MapObjType == MapObjectType.Item)
  1061.                     {
  1062.                         FloorItem item = obj as FloorItem;
  1063.                         if (item == null) continue;
  1064.                         if (item.Type == FloorItem.Effect)
  1065.                         {
  1066.                             if (item.ItemID == FloorItem.FlameLotus ||
  1067.                             item.ItemID == FloorItem.AuroraLotus)
  1068.                             {
  1069.                                 if (item.OnFloor.AddSeconds(8).Next(time: time))
  1070.                                 {
  1071.                                     IEnumerable<Client.GameState> array = null;
  1072.                                     Database.SpellInformation Spell = null;
  1073.                                     if (item.ItemID == FloorItem.FlameLotus)
  1074.                                     {
  1075.                                         Spell = Database.SpellTable.GetSpell(12380, 6);
  1076.                                         if (item.Owner.Team != null)
  1077.                                         {
  1078.                                             array = Kernel.GamePool.Values.Where
  1079.                                             (x =>
  1080.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1081.                                             x.Entity.Dead == true &&
  1082.                                             item.Owner.Team.IsTeammate(x.Entity.UID)
  1083.                                             );
  1084.                                         }
  1085.                                         else if (item.Owner.Guild != null)
  1086.                                         {
  1087.                                             array = Kernel.GamePool.Values.Where
  1088.                                             (x =>
  1089.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1090.                                             x.Entity.Dead == true && x.Entity.GuildID == item.Owner.Entity.GuildID
  1091.                                             );
  1092.                                         }
  1093.                                         else if (item.Owner.Entity.GetClan != null)
  1094.                                         {
  1095.                                             array = Kernel.GamePool.Values.Where
  1096.                                             (x =>
  1097.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1098.                                             x.Entity.Dead == true && x.Entity.ClanId == item.Owner.Entity.ClanId
  1099.                                             );
  1100.                                         }
  1101.                                         else
  1102.                                         {
  1103.                                             array = Kernel.GamePool.Values.Where
  1104.                                             (x =>
  1105.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1106.                                             x.Entity.Dead == true
  1107.                                             );
  1108.                                         }
  1109.                                     }
  1110.                                     foreach (GameState pClient in array)
  1111.                                     {
  1112.                                         if (pClient == null) return;
  1113.                                         if (pClient.Entity == null) return;
  1114.                                         if (pClient.Entity.UID != item.Owner.Entity.UID)
  1115.                                         {
  1116.                                             if (Spell.ID == 12380)
  1117.                                             {
  1118.                                                 SpellUse suse = new SpellUse(true);
  1119.                                                 suse.Attacker = item.Owner.Entity.UID;
  1120.                                                 suse.SpellID = 12380;
  1121.                                                 suse.SpellLevel = 0;
  1122.                                                 suse.X = pClient.Entity.X;
  1123.                                                 suse.Y = pClient.Entity.Y;
  1124.                                             }
  1125.                                             item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1126.                                             client.Map.RemoveFloorItem(item);
  1127.                                             client.RemoveScreenSpawn(item, true);
  1128.                                         }
  1129.                                     }
  1130.                                     if (item.ItemID == FloorItem.AuroraLotus)
  1131.                                     {
  1132.                                         Spell = Database.SpellTable.GetSpell(12370, 6);
  1133.                                         if (item.Owner.Team != null)
  1134.                                         {
  1135.                                             array = Kernel.GamePool.Values.Where
  1136.                                             (x =>
  1137.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1138.                                             x.Entity.Dead == true &&
  1139.                                             item.Owner.Team.IsTeammate(x.Entity.UID)
  1140.                                             );
  1141.                                         }
  1142.                                         else if (item.Owner.Guild != null)
  1143.                                         {
  1144.                                             array = Kernel.GamePool.Values.Where
  1145.                                             (x =>
  1146.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1147.                                             x.Entity.Dead == true && x.Entity.GuildID == item.Owner.Entity.GuildID
  1148.                                             );
  1149.                                         }
  1150.                                         else if (item.Owner.Entity.GetClan != null)
  1151.                                         {
  1152.                                             array = Kernel.GamePool.Values.Where
  1153.                                             (x =>
  1154.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1155.                                             x.Entity.Dead == true && x.Entity.ClanId == item.Owner.Entity.ClanId
  1156.                                             );
  1157.                                         }
  1158.                                         else
  1159.                                         {
  1160.                                             array = Kernel.GamePool.Values.Where
  1161.                                             (x =>
  1162.                                             Kernel.GetDistance(x.Entity.X, x.Entity.Y, item.X, item.Y) <= Spell.Range &&
  1163.                                             x.Entity.Dead == true
  1164.                                             );
  1165.                                         }
  1166.                                     }
  1167.                                     foreach (GameState pClient in array)
  1168.                                     {
  1169.                                         Database.SpellInformation spell = null;
  1170.                                         if (pClient == null) return;
  1171.                                         if (pClient.Entity == null) return;
  1172.                                         if (pClient.Entity.UID != item.Owner.Entity.UID)
  1173.                                         {
  1174.                                             if (Spell.ID == 12370)
  1175.                                             {
  1176.                                                 SpellUse suse = new SpellUse(true);
  1177.                                                 suse.Attacker = item.Owner.Entity.UID;
  1178.                                                 suse.SpellID = 1100;
  1179.                                                 suse.SpellLevel = 0;
  1180.                                                 suse.X = pClient.Entity.X;
  1181.                                                 suse.Y = pClient.Entity.Y;
  1182.                                                 //   suse.AddTarget(, 0, null);
  1183.                                                 pClient.Entity.Action =
  1184.                                                 CM.Arg.Game.Enums.ConquerAction.None;
  1185.                                                 pClient.ReviveStamp = Time32.Now;
  1186.                                                 pClient.Attackable = false;
  1187.                                                 pClient.Entity.TransformationID = 0;
  1188.                                                 pClient.Entity.RemoveFlag((ulong)Update.Flags.Dead);
  1189.                                                 pClient.Entity.RemoveFlag((ulong)Update.Flags.Ghost);
  1190.                                                 pClient.Entity.Hitpoints = pClient.Entity.MaxHitpoints;
  1191.                                                 pClient.Entity.Ressurect();
  1192.                                                 pClient.SendScreen(suse, true);
  1193.                                                 pClient.Entity.AddFlag((ulong)Update.Flags.Stigma);
  1194.                                                 pClient.Entity.AddFlag((ulong)Update.Flags.MagicShield);
  1195.                                                 pClient.Entity.AddFlag((ulong)Update.Flags.StarOfAccuracy);
  1196.                                                 pClient.Entity.StigmaStamp = Time32.Now;
  1197.                                                 pClient.Entity.StarOfAccuracyTime = 45;
  1198.                                                 pClient.Entity.StigmaTime = 45;
  1199.                                                 pClient.Entity.MagicShieldTime = 45;
  1200.                                                 pClient.Entity.StigmaIncrease = 15;
  1201.                                                 pClient.Entity.MagicShieldIncrease = 15;
  1202.                                                 pClient.Entity.ShieldTime = 0;
  1203.                                                 pClient.Entity.ShieldTime = 0;
  1204.                                                 pClient.Entity.AccuracyTime = 0;
  1205.                                                 pClient.Entity.AccuracyStamp = Time32.Now;
  1206.                                                 pClient.Entity.StarOfAccuracyStamp = Time32.Now;
  1207.                                                 pClient.Entity.ShieldStamp = Time32.Now;
  1208.                                                 pClient.Entity.MagicShieldStamp = Time32.Now;
  1209.                                                 if (pClient.Entity.EntityFlag == EntityFlag.Player)
  1210.                                                     pClient.Entity.Owner.Send(Constants.Shield(spell.PowerPercent, spell.Duration));
  1211.                                                 pClient.Entity.Owner.Send(Constants.Accuracy(spell.Duration));
  1212.                                                 pClient.Entity.Owner.Send(Constants.Stigma(spell.PowerPercent, spell.Duration));
  1213.                                             }
  1214.                                         }
  1215.                                     }
  1216.                                     item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1217.                                     client.Map.RemoveFloorItem(item);
  1218.                                     client.RemoveScreenSpawn(item, true);
  1219.                                 }
  1220.                             }
  1221.                             else
  1222.                                 if (item.ItemID == FloorItem.AuroraLotus || item.ItemID == FloorItem.FlameLotus) return;
  1223.                             if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce || item.ItemID == 31)
  1224.                             {
  1225.                                 if (item.OnFloor.AddSeconds(4).Next(time: time))
  1226.                                 {
  1227.                                     item.Type = FloorItem.RemoveEffect;
  1228.                                     //client.SendScreen(item, true);
  1229.                                     client.Map.RemoveFloorItem(item);
  1230.                                     client.RemoveScreenSpawn(item, true);
  1231.                                 }
  1232.                             }
  1233.                         }
  1234.                         else
  1235.                         {
  1236.                             if (item.OnFloor.AddSeconds(Constants.FloorItemSeconds).Next(time: time))
  1237.                             {
  1238.                                 item.Type = FloorItem.Remove;
  1239.                                 foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  1240.                                     if (_obj != null)
  1241.                                         if (_obj.MapObjType == MapObjectType.Player)
  1242.                                             (_obj as Entity).Owner.Send(item);
  1243.                                 client.Map.RemoveFloorItem(item);
  1244.                                 client.Screen.Remove(item);
  1245.                             }
  1246.                         }
  1247.                     }
  1248.                 }
  1249.             }
  1250.         }*/
  1251.         private static void MatrixMobsCallback(GameState client, int time)
  1252.         {
  1253.             if (!client.Socket.Alive)
  1254.             {
  1255.                 client.Screen.DisposeTimers();
  1256.                 return;
  1257.             }
  1258.             if (client.Entity == null)
  1259.                 return;
  1260.             if (client.Map == null)
  1261.                 return;
  1262.             if (client.Map.FreezeMonsters)
  1263.                 return;
  1264.  
  1265.             Time32 Now = new Time32(time);
  1266.             foreach (IMapObject obj in client.Screen.Objects)
  1267.             {
  1268.                 if (obj != null)
  1269.                 {
  1270.                     if (obj.MapObjType == MapObjectType.Monster)
  1271.                     {
  1272.                         Entity monster = obj as Entity;
  1273.                         if (monster.Companion) continue;
  1274.                         if (monster.Dead || monster.Killed) continue;
  1275.  
  1276.                         if (monster.MonsterInfo.Type == 2 || monster.Mesh == 482)
  1277.                         {
  1278.                             if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  1279.                             {
  1280.                                 if (monster.MonsterInfo.InSight == 0)
  1281.                                 {
  1282.                                     ushort xx = (ushort)Kernel.Random.Next(monster.X - 10, monster.X + 10);
  1283.                                     ushort yy = (ushort)Kernel.Random.Next(monster.Y - 10, monster.Y + 10);
  1284.                                     if (monster.X != xx || monster.Y != yy)
  1285.                                     {
  1286.                                         monster.X = xx;
  1287.                                         monster.Y = yy;
  1288.                                         TwoMovements jump = new TwoMovements();
  1289.                                         jump.X = xx;
  1290.                                         jump.Y = yy;
  1291.                                         jump.EntityCount = 1;
  1292.                                         jump.FirstEntity = monster.UID;
  1293.                                         jump.MovementType = TwoMovements.Jump;
  1294.                                         client.SendScreen(jump, true);
  1295.                                     }
  1296.                                     // if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1297.                                     //    monster.MonsterInfo.InSight = client.Entity.UID;
  1298.                                 }
  1299.                                 else
  1300.                                 {
  1301.                                     //  if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1302.                                     {
  1303.                                         if (monster.MonsterInfo.InSight == client.Entity.UID)
  1304.                                         {
  1305.                                             if (!client.Entity.Dead)
  1306.                                             {
  1307.                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  1308.                                                 {
  1309.                                                     short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  1310.  
  1311.                                                     if (distance <= monster.MonsterInfo.AttackRange)
  1312.                                                     {
  1313.                                                         monster.MonsterInfo.LastMove = Time32.Now;
  1314.                                                         new Game.Attacking.Handle(null, monster, client.Entity);
  1315.                                                         if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  1316.                                                         {
  1317.                                                             monster.MonsterInfo.Lastpop = Time32.Now;
  1318.  
  1319.                                                         }
  1320.                                                     }
  1321.                                                     else
  1322.                                                     {
  1323.                                                         if (distance <= monster.MonsterInfo.ViewRange)
  1324.                                                         {
  1325.                                                             TwoMovements jump = new TwoMovements();
  1326.                                                             jump.X = client.Entity.X;
  1327.                                                             jump.Y = client.Entity.Y;
  1328.                                                             monster.X = client.Entity.X;
  1329.                                                             monster.Y = client.Entity.Y;
  1330.                                                             jump.EntityCount = 1;
  1331.                                                             jump.FirstEntity = monster.UID;
  1332.                                                             jump.MovementType = TwoMovements.Jump;
  1333.                                                             client.SendScreen(jump, true);
  1334.                                                         }
  1335.                                                     }
  1336.                                                 }
  1337.                                             }
  1338.                                         }
  1339.                                     }
  1340.                                 }
  1341.                             }
  1342.                         }
  1343.                     }
  1344.                 }
  1345.             }
  1346.         }
  1347.  
  1348.         private IDisposable[] TimerSubscriptions;
  1349.         private object DisposalSyncRoot;
  1350.  
  1351.         private Interfaces.IMapObject[] _objects;
  1352.         private static ConcurrentDictionary<uint, PokerTable> PokerTables;
  1353.         public Interfaces.IMapObject[] Objects { get { return _objects; } }
  1354.  
  1355.         private ConcurrentDictionary<uint, Interfaces.IMapObject> _objectDictionary;
  1356.         public ConcurrentDictionary<uint, Game.Statue> Statue = new ConcurrentDictionary<uint, Statue>();
  1357.  
  1358.         public Client.GameState Owner;
  1359.  
  1360.         public Screen(Client.GameState client)
  1361.         {
  1362.             Owner = client;
  1363.             _objects = new Interfaces.IMapObject[0];
  1364.             PokerTables = new ConcurrentDictionary<uint, PokerTable>();
  1365.             _objectDictionary = new ConcurrentDictionary<uint, IMapObject>();
  1366.  
  1367.             TimerSubscriptions = new IDisposable[]
  1368.                 {
  1369.                     MonsterBuffers.Add(client),
  1370.                     Guards.Add(client),
  1371.                     AliveMonsters.Add(client),
  1372.                     Items.Add(client),
  1373.                     MatrixMobs.Add(client)
  1374.                 };
  1375.             DisposalSyncRoot = new object();
  1376.  
  1377.         }
  1378.         ~Screen()
  1379.         {
  1380.             DisposeTimers();
  1381.             Clear();
  1382.             _objects = null;
  1383.             _objectDictionary = null;
  1384.             Owner = null;
  1385.         }
  1386.  
  1387.         public void DisposeTimers()
  1388.         {
  1389.             lock (DisposalSyncRoot)
  1390.             {
  1391.                 if (TimerSubscriptions == null) return;
  1392.                 for (int i = 0; i < TimerSubscriptions.Length; i++)
  1393.                 {
  1394.                     if (TimerSubscriptions[i] != null)
  1395.                     {
  1396.                         TimerSubscriptions[i].Dispose();
  1397.                         TimerSubscriptions[i] = null;
  1398.                     }
  1399.                 }
  1400.             }
  1401.         }
  1402.  
  1403.         private void updateBase()
  1404.         {
  1405.             _objects = _objectDictionary.Values.ToArray();
  1406.         }
  1407.  
  1408.         public bool Add(Interfaces.IMapObject _object)
  1409.         {
  1410.             if (_object == null) return false;
  1411.  
  1412.             if (_objectDictionary.ContainsKey(_object.UID))
  1413.                 if (_objectDictionary[_object.UID] == null) // should never happen
  1414.                     _objectDictionary.Remove(_object.UID);
  1415.  
  1416.             if (!_objectDictionary.ContainsKey(_object.UID))
  1417.             {
  1418.                 if (Kernel.GetDistance(_object.X, _object.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.pScreenDistance)
  1419.                 {
  1420.                     _objectDictionary[_object.UID] = _object;
  1421.                     updateBase();
  1422.                     return true;
  1423.                 }
  1424.             }
  1425.             return false;
  1426.         }
  1427.         public bool Remove(Interfaces.IMapObject _object)
  1428.         {
  1429.             if (_object == null) return false;
  1430.  
  1431.             if (_objectDictionary.Remove(_object.UID))
  1432.             {
  1433.                 updateBase();
  1434.                 if (_object.MapObjType == MapObjectType.Item)
  1435.                 {
  1436.                     FloorItem item = _object as FloorItem;
  1437.                     if (item.Type >= FloorItem.Effect)
  1438.                     {
  1439.                         item.Type = FloorItem.RemoveEffect;
  1440.                         Owner.Send(item);
  1441.                     }
  1442.                     else
  1443.                     {
  1444.                         item.Type = FloorItem.Remove;
  1445.                         Owner.Send(item);
  1446.                         item.Type = FloorItem.Drop;
  1447.                     }
  1448.                 }
  1449.                 else if (_object.MapObjType == MapObjectType.Player)
  1450.                 {
  1451.                     Owner.Send(new Data(true)
  1452.                     {
  1453.                         UID = _object.UID,
  1454.                         ID = Network.GamePackets.Data.RemoveEntity
  1455.                     });
  1456.                 }
  1457.                 else if (_object.MapObjType == MapObjectType.StaticEntity)
  1458.                 {
  1459.                     Owner.Send(new Data(true)
  1460.                     {
  1461.                         UID = _object.UID,
  1462.                         ID = Network.GamePackets.Data.RemoveEntity
  1463.                     });
  1464.                 }
  1465.                 return true;
  1466.             }
  1467.             return false;
  1468.         }
  1469.  
  1470.         public bool TryGetValue(uint uid, out Entity entity)
  1471.         {
  1472.             entity = null;
  1473.             Interfaces.IMapObject imo = null;
  1474.             if (_objectDictionary.TryGetValue(uid, out imo))
  1475.             {
  1476.                 if (imo == null)
  1477.                 {
  1478.                     _objectDictionary.Remove(uid);
  1479.                     updateBase();
  1480.                     return false;
  1481.                 }
  1482.                 if (imo is Entity)
  1483.                 {
  1484.                     entity = imo as Entity;
  1485.                     return true;
  1486.                 }
  1487.             }
  1488.             return false;
  1489.         }
  1490.         public bool GetRaceObject(Func<IMapObject, bool> predicate, out StaticEntity entity)
  1491.         {
  1492.             entity = null;
  1493.             foreach (var obj in Objects)
  1494.                 if (obj is StaticEntity)
  1495.                     if (predicate(obj))
  1496.                         entity = obj as StaticEntity;
  1497.             return entity != null;
  1498.         }
  1499.         public bool TryGetSob(uint uid, out SobNpcSpawn sob)
  1500.         {
  1501.             sob = null;
  1502.             Interfaces.IMapObject imo = null;
  1503.             if (_objectDictionary.TryGetValue(uid, out imo))
  1504.             {
  1505.                 if (imo == null)
  1506.                 {
  1507.                     _objectDictionary.Remove(uid);
  1508.                     updateBase();
  1509.                     return false;
  1510.                 }
  1511.                 if (imo is SobNpcSpawn)
  1512.                 {
  1513.                     sob = imo as SobNpcSpawn;
  1514.                     return true;
  1515.                 }
  1516.             }
  1517.             return false;
  1518.         }
  1519.         public bool TryGetFloorItem(uint uid, out FloorItem item)
  1520.         {
  1521.             item = null;
  1522.             Interfaces.IMapObject imo = null;
  1523.             if (_objectDictionary.TryGetValue(uid, out imo))
  1524.             {
  1525.                 if (imo == null)
  1526.                 {
  1527.                     _objectDictionary.Remove(uid);
  1528.                     updateBase();
  1529.                     return false;
  1530.                 }
  1531.                 if (imo is FloorItem)
  1532.                 {
  1533.                     item = imo as FloorItem;
  1534.                     return true;
  1535.                 }
  1536.             }
  1537.             return false;
  1538.         }
  1539.  
  1540.  
  1541.         public IEnumerable<T> Select<T>(MapObjectType type) where T : class
  1542.         {
  1543.             foreach (var obj in Objects)
  1544.                 if (obj != null)
  1545.                     if (obj.MapObjType == type)
  1546.                         yield return obj as T;
  1547.         }
  1548.         public IEnumerable<T> Where<T>(Func<IMapObject, bool> predicate) where T : class
  1549.         {
  1550.             foreach (var obj in Objects)
  1551.                 if (obj != null)
  1552.                     if (predicate(obj))
  1553.                         yield return obj as T;
  1554.         }
  1555.         public IEnumerable<T> SelectWhere<T>(MapObjectType type, Func<T, bool> predicate) where T : class
  1556.         {
  1557.             foreach (var obj in Objects)
  1558.                 if (obj != null)
  1559.                     if (obj.MapObjType == type)
  1560.                         if (predicate(obj as T))
  1561.                             yield return obj as T;
  1562.         }
  1563.  
  1564.  
  1565.         public bool Contains(Interfaces.IMapObject _object)
  1566.         {
  1567.             if (_object == null) return false;
  1568.             return _objectDictionary.ContainsKey(_object.UID);
  1569.         }
  1570.         public bool Contains(uint uid)
  1571.         {
  1572.             return _objectDictionary.ContainsKey(uid);
  1573.         }
  1574.  
  1575.         public void CleanUp(Interfaces.IPacket spawnWith)
  1576.         {
  1577.             bool remove;
  1578.             try
  1579.             {
  1580.                 foreach (IMapObject Base in Objects)
  1581.                 {
  1582.                     if (Base == null) continue;
  1583.                     remove = false;
  1584.                     if (Base.MapObjType == MapObjectType.Monster)
  1585.                     {
  1586.                         if ((Base as Entity).Dead)
  1587.                         {
  1588.                             if (Time32.Now > (Base as Entity).DeathStamp.AddSeconds(8))
  1589.                                 remove = true;
  1590.                             else
  1591.                                 remove = false;
  1592.                         }
  1593.                         if (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance)
  1594.                             remove = true;
  1595.                         if (remove)
  1596.                         {
  1597.                             if ((Base as Entity).MonsterInfo.InSight == Owner.Entity.UID)
  1598.                                 (Base as Entity).MonsterInfo.InSight = 0;
  1599.                         }
  1600.                     }
  1601.                     else if (Base.MapObjType == MapObjectType.Player)
  1602.                     {
  1603.                         if (remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.pScreenDistance))
  1604.                         {
  1605.                             GameState pPlayer = Base.Owner as GameState;
  1606.                             pPlayer.Screen.Remove(Owner.Entity);
  1607.                         }
  1608.                     }
  1609.                     else if (Base.MapObjType == MapObjectType.Item)
  1610.                     {
  1611.                         remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= 22);
  1612.  
  1613.                     }
  1614.                     else
  1615.                     {
  1616.                         remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance);
  1617.                     }
  1618.                     if (Base.MapID != Owner.Map.ID)
  1619.                         remove = true;
  1620.                     if (remove)
  1621.                     {
  1622.                         Remove(Base);
  1623.                     }
  1624.                 }
  1625.             }
  1626.             catch (Exception e) { Program.SaveException(e); }
  1627.         }
  1628.         public void FullWipe()
  1629.         {
  1630.             foreach (IMapObject Base in Objects)
  1631.             {
  1632.                 if (Base == null) continue;
  1633.  
  1634.                 Data data = new Data(true);
  1635.                 data.UID = Base.UID;
  1636.                 data.ID = Network.GamePackets.Data.RemoveEntity;
  1637.                 Owner.Send(data);
  1638.  
  1639.                 if (Base.MapObjType == Game.MapObjectType.Player)
  1640.                 {
  1641.                     GameState pPlayer = Base.Owner as GameState;
  1642.                     pPlayer.Screen.Remove(Owner.Entity);
  1643.                 }
  1644.             }
  1645.             Clear();
  1646.         }
  1647.         public void Clear()
  1648.         {
  1649.             _objectDictionary.Clear();
  1650.             _objects = new IMapObject[0];
  1651.         }
  1652.         public void Reload(Interfaces.IPacket spawnWith = null)
  1653.         {
  1654.             CleanUp(spawnWith);
  1655.             if (Owner.Entity.MapID == 1002)
  1656.             {
  1657.                 foreach (var statue in Game.Statue.Statues.Values)
  1658.                 {
  1659.                     if (statue > Owner)
  1660.                     {
  1661.                         Statue.TryAdd(statue.UID, statue);
  1662.                     }
  1663.                     else if (statue < Owner)
  1664.                     {
  1665.                         Game.Statue astatue;
  1666.                         Statue.TryRemove(statue.UID, out astatue);
  1667.                     }
  1668.                 }
  1669.             }
  1670.             else
  1671.             {
  1672.                 if (Statue.Count > 0)
  1673.                     Statue.Clear();
  1674.             }
  1675.             try
  1676.             {
  1677.                 foreach (GameState pClient in CrossServer.CrossPool.Values)
  1678.                 {
  1679.                     if (pClient == null) return;
  1680.                     if (pClient.Entity == null) return;
  1681.                     if (Owner == null) return;
  1682.                     if (Owner.Entity == null) return;
  1683.                     if (pClient.Entity.UID != Owner.Entity.UID)
  1684.                     {
  1685.                         if (pClient.Map.ID == Owner.Map.ID)
  1686.                         {
  1687.                             short dist = Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, Owner.Entity.X, Owner.Entity.Y);
  1688.                             if (dist <= Constants.pScreenDistance && !Contains(pClient.Entity))
  1689.                             {
  1690.                                 if (pClient.Guild != null)
  1691.                                     pClient.Guild.SendName(Owner);
  1692.  
  1693.  
  1694.                                 if (Owner.Guild != null)
  1695.                                     Owner.Guild.SendName(pClient);
  1696.                                 if (pClient.Entity.InteractionInProgress && pClient.Entity.InteractionWith != Owner.Entity.UID && pClient.Entity.InteractionSet)
  1697.                                 {
  1698.                                     if (pClient.Entity.Body == 1003 || pClient.Entity.Body == 1004)
  1699.                                     {
  1700.                                         if (pClient.Entity.InteractionX == pClient.Entity.X && pClient.Entity.Y == pClient.Entity.InteractionY)
  1701.                                         {
  1702.                                             Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  1703.                                             atak.Attacker = pClient.Entity.UID;
  1704.                                             atak.Attacked = pClient.Entity.InteractionWith;
  1705.                                             atak.X = pClient.Entity.X;
  1706.                                             atak.Y = pClient.Entity.Y;
  1707.                                             atak.AttackType = 49;
  1708.                                             atak.Damage = pClient.Entity.InteractionType;
  1709.                                             Owner.Send(atak);
  1710.                                         }
  1711.                                     }
  1712.                                     else
  1713.                                     {
  1714.                                         if (CM.Arg.Kernel.GamePool.ContainsKey(pClient.Entity.InteractionWith))
  1715.                                         {
  1716.                                             Client.GameState Cs = CM.Arg.Kernel.GamePool[pClient.Entity.InteractionWith] as Client.GameState;
  1717.                                             if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  1718.                                             {
  1719.                                                 Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  1720.                                                 atak.Attacker = pClient.Entity.UID;
  1721.                                                 atak.Attacked = pClient.Entity.InteractionWith;
  1722.                                                 atak.X = pClient.Entity.X;
  1723.                                                 atak.Y = pClient.Entity.Y;
  1724.                                                 atak.AttackType = 49;
  1725.                                                 atak.Damage = pClient.Entity.InteractionType;
  1726.                                                 Owner.Send(atak);
  1727.                                             }
  1728.                                         }
  1729.                                         if (CM.Arg.CrossServer.CrossPool.ContainsKey(pClient.Entity.InteractionWith))
  1730.                                         {
  1731.                                             Client.GameState Cs = CM.Arg.CrossServer.CrossPool[pClient.Entity.InteractionWith] as Client.GameState;
  1732.                                             if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  1733.                                             {
  1734.                                                 Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  1735.                                                 atak.Attacker = pClient.Entity.UID;
  1736.                                                 atak.Attacked = pClient.Entity.InteractionWith;
  1737.                                                 atak.X = pClient.Entity.X;
  1738.                                                 atak.Y = pClient.Entity.Y;
  1739.                                                 atak.AttackType = 49;
  1740.                                                 atak.Damage = pClient.Entity.InteractionType;
  1741.                                                 Owner.Send(atak);
  1742.                                             }
  1743.                                         }
  1744.                                     }
  1745.                                 }
  1746.                                 if (pClient.Map.BaseID == 700)
  1747.                                 {
  1748.                                     if (Owner.InQualifier())
  1749.                                     {
  1750.                                         if (pClient.InQualifier())
  1751.                                         {
  1752.                                             Owner.Entity.SendSpawn(pClient);
  1753.                                             pClient.Entity.SendSpawn(Owner);
  1754.                                             if (pClient.Guild != null)
  1755.                                                 Owner.Entity.SendSpawn(pClient, false);
  1756.                                             if (Owner.Guild != null)
  1757.                                                 pClient.Entity.SendSpawn(Owner, false);
  1758.                                             if (spawnWith != null)
  1759.                                                 pClient.Send(spawnWith);
  1760.                                         }
  1761.                                         else
  1762.                                         {
  1763.                                             Owner.Entity.SendSpawn(pClient);
  1764.  
  1765.                                             if (pClient.Guild != null)
  1766.                                                 Owner.Entity.SendSpawn(pClient, false);
  1767.                                             Add(pClient.Entity);
  1768.                                             if (spawnWith != null)
  1769.                                                 pClient.Send(spawnWith);
  1770.                                         }
  1771.                                     }
  1772.                                     else
  1773.                                     {
  1774.                                         if (pClient.InQualifier())
  1775.                                         {
  1776.                                             pClient.Entity.SendSpawn(Owner);
  1777.                                             if (Owner.Guild != null)
  1778.                                                 pClient.Entity.SendSpawn(Owner, false);
  1779.                                             pClient.Screen.Add(Owner.Entity);
  1780.                                             if (spawnWith != null)
  1781.                                                 Owner.Send(spawnWith);
  1782.                                         }
  1783.                                         else
  1784.                                         {
  1785.                                             Owner.Entity.SendSpawn(pClient);
  1786.                                             pClient.Entity.SendSpawn(Owner);
  1787.  
  1788.                                             if (pClient.Guild != null)
  1789.                                                 Owner.Entity.SendSpawn(pClient, false);
  1790.                                             if (Owner.Guild != null)
  1791.                                                 pClient.Entity.SendSpawn(Owner, false);
  1792.  
  1793.                                             if (spawnWith != null)
  1794.                                                 pClient.Send(spawnWith);
  1795.                                         }
  1796.                                     }
  1797.                                 }
  1798.                                 else
  1799.                                 {
  1800.                                     Owner.Entity.SendSpawn(pClient);
  1801.                                     pClient.Entity.SendSpawn(Owner);
  1802.  
  1803.                                     if (pClient.Guild != null)
  1804.                                         Owner.Entity.SendSpawn(pClient, false);
  1805.                                     if (Owner.Guild != null)
  1806.                                         pClient.Entity.SendSpawn(Owner, false);
  1807.  
  1808.                                     if (spawnWith != null)
  1809.                                         pClient.Send(spawnWith);
  1810.                                 }
  1811.  
  1812.                                 #region Otras Mascotas y Clones
  1813.                                 if (pClient.Entity.MyClones.Count > 0)
  1814.                                 {
  1815.                                     foreach (var clone in pClient.Entity.MyClones.Values)
  1816.                                     {
  1817.                                         if (clone == null) continue;
  1818.                                         if (Kernel.GetDistance(clone.X, clone.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(clone.UID))
  1819.                                         {
  1820.                                             if (!clone.Dead)
  1821.                                                 clone.SendSpawn(Owner);
  1822.                                         }
  1823.                                     }
  1824.                                 }
  1825.                                 if (pClient.Pet.Pets.Count > 0)
  1826.                                 {
  1827.                                     foreach (var pet in pClient.Pet.Pets.Values)
  1828.                                     {
  1829.                                         if (pet == null) continue;
  1830.                                         if (pet.Entity == null) continue;
  1831.                                         if (Kernel.GetDistance(pet.Entity.X, pet.Entity.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(pet.Entity.UID))
  1832.                                         {
  1833.                                             if (!pet.Entity.Dead)
  1834.                                                 pet.Entity.SendSpawn(Owner);
  1835.                                         }
  1836.                                     }
  1837.                                 }
  1838.                                 #endregion
  1839.                             }
  1840.                         }
  1841.                     }
  1842.                 }
  1843.                 foreach (GameState pClient in CrossServer.CrossPool.Values)
  1844.                 {
  1845.                     if (pClient == null) return;
  1846.                     if (pClient.Entity == null) return;
  1847.                     if (Owner == null) return;
  1848.                     if (Owner.Entity == null) return;
  1849.                     if (pClient.Entity.UID != Owner.Entity.UID)
  1850.                     {
  1851.                         if (pClient.Map.ID == Owner.Map.ID)
  1852.                         {
  1853.                             short dist = Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, Owner.Entity.X, Owner.Entity.Y);
  1854.                             if (dist <= Constants.pScreenDistance && !Contains(pClient.Entity))
  1855.                             {
  1856.                                 if (pClient.Guild != null)
  1857.                                     pClient.Guild.SendName(Owner);
  1858.  
  1859.  
  1860.                                 if (Owner.Guild != null)
  1861.                                     Owner.Guild.SendName(pClient);
  1862.                                 if (pClient.Entity.InteractionInProgress && pClient.Entity.InteractionWith != Owner.Entity.UID && pClient.Entity.InteractionSet)
  1863.                                 {
  1864.                                     if (pClient.Entity.Body == 1003 || pClient.Entity.Body == 1004)
  1865.                                     {
  1866.                                         if (pClient.Entity.InteractionX == pClient.Entity.X && pClient.Entity.Y == pClient.Entity.InteractionY)
  1867.                                         {
  1868.                                             Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  1869.                                             atak.Attacker = pClient.Entity.UID;
  1870.                                             atak.Attacked = pClient.Entity.InteractionWith;
  1871.                                             atak.X = pClient.Entity.X;
  1872.                                             atak.Y = pClient.Entity.Y;
  1873.                                             atak.AttackType = 49;
  1874.                                             atak.Damage = pClient.Entity.InteractionType;
  1875.                                             Owner.Send(atak);
  1876.                                         }
  1877.                                     }
  1878.                                     else
  1879.                                     {
  1880.                                         if (CM.Arg.Kernel.GamePool.ContainsKey(pClient.Entity.InteractionWith))
  1881.                                         {
  1882.                                             Client.GameState Cs = CM.Arg.Kernel.GamePool[pClient.Entity.InteractionWith] as Client.GameState;
  1883.                                             if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  1884.                                             {
  1885.                                                 Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  1886.                                                 atak.Attacker = pClient.Entity.UID;
  1887.                                                 atak.Attacked = pClient.Entity.InteractionWith;
  1888.                                                 atak.X = pClient.Entity.X;
  1889.                                                 atak.Y = pClient.Entity.Y;
  1890.                                                 atak.AttackType = 49;
  1891.                                                 atak.Damage = pClient.Entity.InteractionType;
  1892.                                                 Owner.Send(atak);
  1893.                                             }
  1894.                                         }
  1895.                                         if (CM.Arg.CrossServer.CrossPool.ContainsKey(pClient.Entity.InteractionWith))
  1896.                                         {
  1897.                                             Client.GameState Cs = CM.Arg.CrossServer.CrossPool[pClient.Entity.InteractionWith] as Client.GameState;
  1898.                                             if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  1899.                                             {
  1900.                                                 Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  1901.                                                 atak.Attacker = pClient.Entity.UID;
  1902.                                                 atak.Attacked = pClient.Entity.InteractionWith;
  1903.                                                 atak.X = pClient.Entity.X;
  1904.                                                 atak.Y = pClient.Entity.Y;
  1905.                                                 atak.AttackType = 49;
  1906.                                                 atak.Damage = pClient.Entity.InteractionType;
  1907.                                                 Owner.Send(atak);
  1908.                                             }
  1909.                                         }
  1910.                                     }
  1911.                                 }
  1912.                                 if (pClient.Map.BaseID == 700)
  1913.                                 {
  1914.                                     if (Owner.InQualifier())
  1915.                                     {
  1916.                                         if (pClient.InQualifier())
  1917.                                         {
  1918.                                             Owner.Entity.SendSpawn(pClient);
  1919.                                             pClient.Entity.SendSpawn(Owner);
  1920.                                             if (pClient.Guild != null)
  1921.                                                 Owner.Entity.SendSpawn(pClient, false);
  1922.                                             if (Owner.Guild != null)
  1923.                                                 pClient.Entity.SendSpawn(Owner, false);
  1924.                                             if (spawnWith != null)
  1925.                                                 pClient.Send(spawnWith);
  1926.                                         }
  1927.                                         else
  1928.                                         {
  1929.                                             Owner.Entity.SendSpawn(pClient);
  1930.  
  1931.                                             if (pClient.Guild != null)
  1932.                                                 Owner.Entity.SendSpawn(pClient, false);
  1933.                                             Add(pClient.Entity);
  1934.                                             if (spawnWith != null)
  1935.                                                 pClient.Send(spawnWith);
  1936.                                         }
  1937.                                     }
  1938.                                     else
  1939.                                     {
  1940.                                         if (pClient.InQualifier())
  1941.                                         {
  1942.                                             pClient.Entity.SendSpawn(Owner);
  1943.                                             if (Owner.Guild != null)
  1944.                                                 pClient.Entity.SendSpawn(Owner, false);
  1945.                                             pClient.Screen.Add(Owner.Entity);
  1946.                                             if (spawnWith != null)
  1947.                                                 Owner.Send(spawnWith);
  1948.                                         }
  1949.                                         else
  1950.                                         {
  1951.                                             Owner.Entity.SendSpawn(pClient);
  1952.                                             pClient.Entity.SendSpawn(Owner);
  1953.  
  1954.                                             if (pClient.Guild != null)
  1955.                                                 Owner.Entity.SendSpawn(pClient, false);
  1956.                                             if (Owner.Guild != null)
  1957.                                                 pClient.Entity.SendSpawn(Owner, false);
  1958.  
  1959.                                             if (spawnWith != null)
  1960.                                                 pClient.Send(spawnWith);
  1961.                                         }
  1962.                                     }
  1963.                                 }
  1964.                                 else
  1965.                                 {
  1966.                                     Owner.Entity.SendSpawn(pClient);
  1967.                                     pClient.Entity.SendSpawn(Owner);
  1968.  
  1969.                                     if (pClient.Guild != null)
  1970.                                         Owner.Entity.SendSpawn(pClient, false);
  1971.                                     if (Owner.Guild != null)
  1972.                                         pClient.Entity.SendSpawn(Owner, false);
  1973.  
  1974.                                     if (spawnWith != null)
  1975.                                         pClient.Send(spawnWith);
  1976.                                 }
  1977.  
  1978.                                 #region Other Pet & Clones
  1979.                                 if (pClient.Entity.MyClones.Count > 0)
  1980.                                 {
  1981.                                     foreach (var clone in pClient.Entity.MyClones.Values)
  1982.                                     {
  1983.                                         if (clone == null) continue;
  1984.                                         if (Kernel.GetDistance(clone.X, clone.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(clone.UID))
  1985.                                         {
  1986.                                             if (!clone.Dead)
  1987.                                                 clone.SendSpawn(Owner);
  1988.                                         }
  1989.                                     }
  1990.                                 }
  1991.                                 if (pClient.Pet.Pets.Count > 0)
  1992.                                 {
  1993.                                     foreach (var pet in pClient.Pet.Pets.Values)
  1994.                                     {
  1995.                                         if (pet == null) continue;
  1996.                                         if (pet.Entity == null) continue;
  1997.                                         if (Kernel.GetDistance(pet.Entity.X, pet.Entity.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(pet.Entity.UID))
  1998.                                         {
  1999.                                             if (!pet.Entity.Dead)
  2000.                                                 pet.Entity.SendSpawn(Owner);
  2001.                                         }
  2002.                                     }
  2003.                                 }
  2004.                                 #endregion
  2005.                             }
  2006.                         }
  2007.                     }
  2008.                 }
  2009.                 foreach (GameState pClient in Kernel.GamePool.Values)
  2010.                 {
  2011.                     if (pClient == null) return;
  2012.                     if (pClient.Entity == null) return;
  2013.                     if (Owner == null) return;
  2014.                     if (Owner.Entity == null) return;
  2015.                     if (pClient.Entity.UID != Owner.Entity.UID)
  2016.                     {
  2017.                         if (pClient.Map.ID == Owner.Map.ID)
  2018.                         {
  2019.                             short dist = Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, Owner.Entity.X, Owner.Entity.Y);
  2020.                             if (dist <= Constants.pScreenDistance && !Contains(pClient.Entity))
  2021.                             {
  2022.                                 if (pClient.Guild != null)
  2023.                                     pClient.Guild.SendName(Owner);
  2024.  
  2025.  
  2026.                                 if (Owner.Guild != null)
  2027.                                     Owner.Guild.SendName(pClient);
  2028.                                 if (pClient.Entity.InteractionInProgress && pClient.Entity.InteractionWith != Owner.Entity.UID && pClient.Entity.InteractionSet)
  2029.                                 {
  2030.                                     if (pClient.Entity.Body == 1003 || pClient.Entity.Body == 1004)
  2031.                                     {
  2032.                                         if (pClient.Entity.InteractionX == pClient.Entity.X && pClient.Entity.Y == pClient.Entity.InteractionY)
  2033.                                         {
  2034.                                             Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  2035.                                             atak.Attacker = pClient.Entity.UID;
  2036.                                             atak.Attacked = pClient.Entity.InteractionWith;
  2037.                                             atak.X = pClient.Entity.X;
  2038.                                             atak.Y = pClient.Entity.Y;
  2039.                                             atak.AttackType = 49;
  2040.                                             atak.Damage = pClient.Entity.InteractionType;
  2041.                                             Owner.Send(atak);
  2042.                                         }
  2043.                                     }
  2044.                                     else
  2045.                                     {
  2046.                                         if (CM.Arg.Kernel.GamePool.ContainsKey(pClient.Entity.InteractionWith))
  2047.                                         {
  2048.                                             Client.GameState Cs = CM.Arg.Kernel.GamePool[pClient.Entity.InteractionWith] as Client.GameState;
  2049.                                             if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  2050.                                             {
  2051.                                                 Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  2052.                                                 atak.Attacker = pClient.Entity.UID;
  2053.                                                 atak.Attacked = pClient.Entity.InteractionWith;
  2054.                                                 atak.X = pClient.Entity.X;
  2055.                                                 atak.Y = pClient.Entity.Y;
  2056.                                                 atak.AttackType = 49;
  2057.                                                 atak.Damage = pClient.Entity.InteractionType;
  2058.                                                 Owner.Send(atak);
  2059.                                             }
  2060.                                         }
  2061.                                         if (CM.Arg.CrossServer.CrossPool.ContainsKey(pClient.Entity.InteractionWith))
  2062.                                         {
  2063.                                             Client.GameState Cs = CM.Arg.CrossServer.CrossPool[pClient.Entity.InteractionWith] as Client.GameState;
  2064.                                             if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  2065.                                             {
  2066.                                                 Network.GamePackets.Attack atak = new CM.Arg.Network.GamePackets.Attack(true);
  2067.                                                 atak.Attacker = pClient.Entity.UID;
  2068.                                                 atak.Attacked = pClient.Entity.InteractionWith;
  2069.                                                 atak.X = pClient.Entity.X;
  2070.                                                 atak.Y = pClient.Entity.Y;
  2071.                                                 atak.AttackType = 49;
  2072.                                                 atak.Damage = pClient.Entity.InteractionType;
  2073.                                                 Owner.Send(atak);
  2074.                                             }
  2075.                                         }
  2076.                                     }
  2077.                                 }
  2078.                                 if (pClient.Map.BaseID == 700)
  2079.                                 {
  2080.                                     if (Owner.InQualifier())
  2081.                                     {
  2082.                                         if (pClient.InQualifier())
  2083.                                         {
  2084.                                             Owner.Entity.SendSpawn(pClient);
  2085.                                             pClient.Entity.SendSpawn(Owner);
  2086.                                             if (pClient.Guild != null)
  2087.                                                 Owner.Entity.SendSpawn(pClient, false);
  2088.                                             if (Owner.Guild != null)
  2089.                                                 pClient.Entity.SendSpawn(Owner, false);
  2090.                                             if (spawnWith != null)
  2091.                                                 pClient.Send(spawnWith);
  2092.                                         }
  2093.                                         else
  2094.                                         {
  2095.                                             Owner.Entity.SendSpawn(pClient);
  2096.  
  2097.                                             if (pClient.Guild != null)
  2098.                                                 Owner.Entity.SendSpawn(pClient, false);
  2099.                                             Add(pClient.Entity);
  2100.                                             if (spawnWith != null)
  2101.                                                 pClient.Send(spawnWith);
  2102.                                         }
  2103.                                     }
  2104.                                     else
  2105.                                     {
  2106.                                         if (pClient.InQualifier())
  2107.                                         {
  2108.                                             pClient.Entity.SendSpawn(Owner);
  2109.                                             if (Owner.Guild != null)
  2110.                                                 pClient.Entity.SendSpawn(Owner, false);
  2111.                                             pClient.Screen.Add(Owner.Entity);
  2112.                                             if (spawnWith != null)
  2113.                                                 Owner.Send(spawnWith);
  2114.                                         }
  2115.                                         else
  2116.                                         {
  2117.                                             Owner.Entity.SendSpawn(pClient);
  2118.                                             pClient.Entity.SendSpawn(Owner);
  2119.  
  2120.                                             if (pClient.Guild != null)
  2121.                                                 Owner.Entity.SendSpawn(pClient, false);
  2122.                                             if (Owner.Guild != null)
  2123.                                                 pClient.Entity.SendSpawn(Owner, false);
  2124.  
  2125.                                             if (spawnWith != null)
  2126.                                                 pClient.Send(spawnWith);
  2127.                                         }
  2128.                                     }
  2129.                                 }
  2130.                                 else
  2131.                                 {
  2132.                                     Owner.Entity.SendSpawn(pClient);
  2133.                                     pClient.Entity.SendSpawn(Owner);
  2134.  
  2135.                                     if (pClient.Guild != null)
  2136.                                         Owner.Entity.SendSpawn(pClient, false);
  2137.                                     if (Owner.Guild != null)
  2138.                                         pClient.Entity.SendSpawn(Owner, false);
  2139.  
  2140.                                     if (spawnWith != null)
  2141.                                         pClient.Send(spawnWith);
  2142.                                 }
  2143.  
  2144.                                 #region Other Pet & Clones
  2145.                                 if (pClient.Entity.MyClones.Count > 0)
  2146.                                 {
  2147.                                     foreach (var clone in pClient.Entity.MyClones.Values)
  2148.                                     {
  2149.                                         if (clone == null) continue;
  2150.                                         if (Kernel.GetDistance(clone.X, clone.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(clone.UID))
  2151.                                         {
  2152.                                             if (!clone.Dead)
  2153.                                                 clone.SendSpawn(Owner);
  2154.                                         }
  2155.                                     }
  2156.                                 }
  2157.                                 if (pClient.Pet.Pets.Count > 0)
  2158.                                 {
  2159.                                     foreach (var pet in pClient.Pet.Pets.Values)
  2160.                                     {
  2161.                                         if (pet == null) continue;
  2162.                                         if (pet.Entity == null) continue;
  2163.                                         if (Kernel.GetDistance(pet.Entity.X, pet.Entity.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(pet.Entity.UID))
  2164.                                         {
  2165.                                             if (!pet.Entity.Dead)
  2166.                                                 pet.Entity.SendSpawn(Owner);
  2167.                                         }
  2168.                                     }
  2169.                                 }
  2170.                                 #endregion
  2171.                             }
  2172.                         }
  2173.                     }
  2174.                 }
  2175.                 #region My Pet & Clones
  2176.                 if (Owner.Entity.MyClones.Count > 0)
  2177.                 {
  2178.                     foreach (var clone in Owner.Entity.MyClones.Values)
  2179.                     {
  2180.                         if (clone == null) continue;
  2181.                         if (Kernel.GetDistance(clone.X, clone.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(clone.UID))
  2182.                         {
  2183.                             if (!clone.Dead)
  2184.                                 clone.SendSpawn(Owner);
  2185.                         }
  2186.                     }
  2187.                 }
  2188.                 if (Owner.Pet.Pets.Count > 0)
  2189.                 {
  2190.                     foreach (var pet in Owner.Pet.Pets.Values)
  2191.                     {
  2192.                         if (pet == null) continue;
  2193.                         if (pet.Entity == null) continue;
  2194.                         if (Kernel.GetDistance(pet.Entity.X, pet.Entity.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(pet.Entity.UID))
  2195.                         {
  2196.                             if (!pet.Entity.Dead)
  2197.                                 pet.Entity.SendSpawn(Owner);
  2198.                         }
  2199.                     }
  2200.                 }
  2201.                 #endregion
  2202.                 var Map = Owner.Map;
  2203.                 #region House
  2204.                 var spouse = MaTrix.House.SpouseHouse(Owner.Entity.Spouse);
  2205.                 if (Owner.Map.ID == (ushort)Owner.Entity.UID)
  2206.                 {
  2207.                     if (MaTrix.House.Houses.ContainsKey(Owner.Entity.UID))
  2208.                     {
  2209.                         var info = MaTrix.House.Houses[Owner.Entity.UID];
  2210.                         foreach (var fur in info.Furnitures.Values)
  2211.                         {
  2212.                             if (fur == null) continue;
  2213.                             if (Kernel.GetDistance(fur.X, fur.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2214.                             if (Contains(fur.UID)) continue;
  2215.                             fur.SendSpawn(Owner, false);
  2216.                         }
  2217.                     }
  2218.                 }
  2219.                 else if (spouse != null)
  2220.                 {
  2221.                     if (Owner.Map.ID == spouse.ID)
  2222.                     {
  2223.                         foreach (var fur in spouse.Furnitures.Values)
  2224.                         {
  2225.                             if (fur == null) continue;
  2226.                             if (Kernel.GetDistance(fur.X, fur.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2227.                             if (Contains(fur.UID)) continue;
  2228.                             fur.SendSpawn(Owner, false);
  2229.                         }
  2230.                     }
  2231.                 }
  2232.                 #endregion
  2233.                 #region Npcs
  2234.                 foreach (Interfaces.INpc npc in Map.Npcs.Values)
  2235.                 {
  2236.                     if (npc == null) continue;
  2237.                     if (Kernel.GetDistance(npc.X, npc.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2238.                     if (Contains(npc.UID)) continue;
  2239.                     npc.SendSpawn(Owner, false);
  2240.                 }
  2241.                 foreach (var npc in Database.GuildCondutors.GuildConductors.Values)
  2242.                 {
  2243.                     if (npc == null) continue;
  2244.                     if (npc.npc.MapID == Owner.Entity.MapID)
  2245.                     {
  2246.                         if (Kernel.GetDistance(npc.npc.X, npc.npc.Y, Owner.Entity.X, Owner.Entity.Y) > 16)
  2247.                             continue;
  2248.                         if (Contains(npc.npc.UID))
  2249.                             continue;
  2250.                         npc.npc.SendSpawn(Owner, false);
  2251.                     }
  2252.                 }
  2253.                 #endregion
  2254.                 #region Items + map effects
  2255.                 foreach (var item in Map.FloorItems.Values)
  2256.                 {
  2257.                     if (item == null) continue;
  2258.                     if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2259.                     if (Contains(item.UID)) continue;
  2260.                     if (item.Type == FloorItem.Effect)
  2261.                     {
  2262.  
  2263.                         if (item.ItemID == FloorItem.AuroraLotus || item.ItemID == FloorItem.FlameLotus) return;
  2264.                         if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce)
  2265.                         {
  2266.                             if (item.OnFloor.AddSeconds(4).Next(time: Time32.Now.AllMilliseconds()))
  2267.                             {
  2268.                                 item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  2269.                                 foreach (Interfaces.IMapObject _obj in Objects)
  2270.                                     if (_obj != null)
  2271.                                         if (_obj.MapObjType == MapObjectType.Player)
  2272.                                             (_obj as Entity).Owner.Send(item);
  2273.                                 Map.RemoveFloorItem(item);
  2274.                             }
  2275.                             else
  2276.                                 item.SendSpawn(Owner, false);
  2277.                         }
  2278.                         else
  2279.                             item.SendSpawn(Owner, false);
  2280.                     }
  2281.                     else
  2282.                     {
  2283.                         if ((Time32.Now > item.OnFloor.AddSeconds(Constants.FloorItemSeconds)) || item.PickedUpAlready)
  2284.                         {
  2285.                             item.Type = Network.GamePackets.FloorItem.Remove;
  2286.                             Map.RemoveFloorItem(item);
  2287.                         }
  2288.                     }
  2289.                     item.SendSpawn(Owner);
  2290.                     if (item.ItemID == FloorItem.FlameLotus || item.ItemID == FloorItem.AuroraLotus)
  2291.                     {
  2292.                         if (item.OnFloor.AddSeconds(8).Next(time: Time32.Now.AllMilliseconds()))
  2293.                         {
  2294.                             item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  2295.                             foreach (Interfaces.IMapObject _obj in Objects)
  2296.                                 if (_obj != null)
  2297.                                     if (_obj.MapObjType == MapObjectType.Player)
  2298.                                         (_obj as Entity).Owner.Send(item);
  2299.                             Map.RemoveFloorItem(item);
  2300.                         }
  2301.                         else
  2302.                             item.SendSpawn(Owner, false);
  2303.                     }
  2304.                 }
  2305.                 #endregion
  2306.  
  2307.                 MaTrix.AI.CheckScreen(Owner, spawnWith);
  2308.  
  2309.                 foreach (Game.Entity monster in Map.Entities.Values)
  2310.                 {
  2311.                     if (monster == null) continue;
  2312.                     if (Kernel.GetDistance(monster.X, monster.Y, Owner.Entity.X, Owner.Entity.Y) <= 16 && !Contains(monster.UID))
  2313.                     {
  2314.                         if (!monster.Dead)
  2315.                         {
  2316.                             monster.SendSpawn(Owner, false);
  2317.                             if (monster.MaxHitpoints > 65535)
  2318.                             {
  2319.                                 Update upd = new Update(true) { UID = monster.UID };
  2320.                                 // upd.Append(Update.MaxHitpoints, monster.MaxHitpoints);
  2321.                                 upd.Append(Update.Hitpoints, monster.Hitpoints);
  2322.                                 Owner.Send(upd);
  2323.                             }
  2324.                         }
  2325.                     }
  2326.                 }
  2327.                 if (Owner.Map.ID == MaTrix.Roulette.Database.Roulettes.RouletteTable.MapID)
  2328.                 {
  2329.                     foreach (var R in MaTrix.Roulette.Database.Roulettes.RoulettesPoll.Values)
  2330.                     {
  2331.                         if (Kernel.GetDistance(R.SpawnPacket.X, R.SpawnPacket.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.nScreenDistance && !Contains(R.SpawnPacket.UID))
  2332.                         {
  2333.                             Owner.Send(R.SpawnPacket);
  2334.                         }
  2335.                     }
  2336.                 }
  2337.                 #region RaceItems
  2338.                 if (Owner.Map.StaticEntities.Count != 0)
  2339.                 {
  2340.                     foreach (var item in Owner.Map.StaticEntities.Values)
  2341.                     {
  2342.                         if (item == null) continue;
  2343.                         if (!item.Viable) continue;
  2344.                         if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  2345.                         if (Contains(item.UID)) continue;
  2346.                         item.SendSpawn(Owner);
  2347.                     }
  2348.                 }
  2349.                 #endregion
  2350.                 if (Owner.Map.ID == 8880 || Owner.Map.ID == 8881 || Owner.Map.ID == 1002)
  2351.                 {
  2352.                     foreach (Game.PokerTable T in Kernel.PokerTables.Values)
  2353.                     {
  2354.                         if (T.Map == Owner.Map.ID)
  2355.                         {
  2356.                             if (Kernel.GetDistance(T.X, T.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.nScreenDistance && !PokerTables.ContainsKey(T.Id))
  2357.                             {
  2358.                                 Owner.Send(Game.PokerPackets.PokerTable(T));
  2359.                                 PokerTables.Add(T.Id, T);
  2360.                             }
  2361.                         }
  2362.                     }
  2363.                 }
  2364.             }
  2365.             catch (Exception e) { Program.SaveException(e); }
  2366.         }
  2367.  
  2368.         public void SendScreen(Interfaces.IPacket buffer, bool self)
  2369.         {
  2370.             foreach (Interfaces.IMapObject _obj in Objects)
  2371.             {
  2372.                 if (_obj != null)
  2373.                 {
  2374.                     if (_obj.UID != Owner.Entity.UID)
  2375.                     {
  2376.                         if (_obj.MapObjType == Game.MapObjectType.Player)
  2377.                         {
  2378.                             GameState client = _obj.Owner as GameState;
  2379.                             if (Owner.WatchingGroup != null && client.WatchingGroup == null)
  2380.                                 continue;
  2381.                             if (Owner.TeamWatchingGroup != null && client.TeamWatchingGroup == null)
  2382.                                 continue;
  2383.                             client.Send(buffer);
  2384.                         }
  2385.                     }
  2386.                 }
  2387.             }
  2388.  
  2389.             if (self)
  2390.                 Owner.Send(buffer);
  2391.         }
  2392.  
  2393.         public bool TryGetNpc(uint uid, out INpc sob)
  2394.         {
  2395.             sob = null;
  2396.             Interfaces.IMapObject imo = null;
  2397.             if (_objectDictionary.TryGetValue(uid, out imo))
  2398.             {
  2399.                 if (imo == null)
  2400.                 {
  2401.                     _objectDictionary.Remove(uid);
  2402.                     updateBase();
  2403.                     return false;
  2404.                 }
  2405.                 if (imo is NpcSpawn)
  2406.                 {
  2407.                     sob = imo as NpcSpawn;
  2408.                     return true;
  2409.                 }
  2410.             }
  2411.             return false;
  2412.         }
  2413.     }
  2414. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement