Advertisement
AhmedEl5WaGa

Untitled

Jan 21st, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3. using Naruto.Client;
  4. using System.Threading;
  5. using System.Diagnostics;
  6. using Naruto.Interfaces;
  7. using System.Threading.Generic;
  8. using System.Collections.Generic;
  9. using Naruto.Network.GamePackets;
  10. using System.Collections.Concurrent;
  11.  
  12. namespace Naruto.Game
  13. {
  14.     public unsafe class Screen
  15.     {
  16.         private static TimerRule<GameState> MonsterBuffers, Guards, AliveMonsters, Items, FloorSpells, MatrixMobs;
  17.         public ConcurrentDictionary<uint, Game.EntityAdd> ConcurrentDictionaryPlayers = new ConcurrentDictionary<uint, EntityAdd>();
  18.         public static void CreateTimerFactories()
  19.         {
  20.             MonsterBuffers = new TimerRule<GameState>(monsterBuffersCallback, 500);
  21.             Guards = new TimerRule<GameState>(guardsCallback, 700);
  22.             MatrixMobs = new TimerRule<GameState>(MatrixMobsCallback, 700);
  23.             AliveMonsters = new TimerRule<GameState>(aliveMonstersCallback, 500);
  24.             Items = new TimerRule<GameState>(itemsCallback, 1000);
  25.             FloorSpells = new TimerRule<GameState>(FloorSpellsCallBack, 100);
  26.         }
  27.         private static void FloorSpellsCallBack(GameState client, int time)
  28.         {
  29.             if (!client.Socket.Alive)
  30.             {
  31.                 client.Screen.DisposeTimers();
  32.                 return;
  33.             }
  34.             if (client.Entity == null) return;
  35.             if (client.Map == null) return;
  36.             Time32 Now = new Time32(time);
  37.             if (client.Entity.FloorSpells.Count != 0)
  38.             {
  39.                 foreach (var ID in client.Entity.FloorSpells)
  40.                 {
  41.                     switch (ID.Key)
  42.                     {
  43.                     }
  44.                 }
  45.             }
  46.         }
  47.         private static void monsterBuffersCallback(GameState client, int time)
  48.         {
  49.             if (!client.Socket.Alive)
  50.             {
  51.                 client.Screen.DisposeTimers(); return;
  52.             }
  53.             if (client.Entity == null) return;
  54.             if (client.Map == null) return;
  55.             if (client.Map.FreezeMonsters) return;
  56.             #region Stamina
  57.             //if (client.Entity.StaminaStamp.Next(500, time: time))
  58.             //{
  59.             //    if (client.Vigor < client.MaxVigor)
  60.             //    {
  61.             //        ushort amount = (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
  62.             //        if (client.Vigor + amount > client.MaxVigor)
  63.             //        {
  64.             //            amount = client.MaxVigor;
  65.             //            client.Vigor = amount;
  66.             //        }
  67.             //        else
  68.             //        {
  69.             //            client.Vigor += amount;
  70.             //        }
  71.             //        Vigor vigor = new Vigor(true);
  72.             //        vigor.Amount = client.Vigor;
  73.             //        vigor.Send(client);
  74.             //    }
  75.             //    if (!client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Ride) && !client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly) || client.Equipment.TryGetItem(18) != null)
  76.             //    {
  77.             //        int limit = 0;
  78.             //        if (client.Entity.HeavenBlessing > 0)
  79.             //            limit = 50;
  80.             //        if (client.Spells != null)
  81.             //        {
  82.             //            if (client.Spells.ContainsKey(12560))
  83.             //            {
  84.             //                var spelll = client.Spells[12560];
  85.             //                var skilll = Database.SpellTable.SpellInformations[12560][spelll.Level];
  86.             //                limit += (int)skilll.Power;
  87.             //            }
  88.             //        }
  89.             //        if (client.Entity.Stamina != 100 + limit)
  90.             //        {
  91.             //            if (client.Entity.Action == Enums.ConquerAction.Sit)
  92.             //            {
  93.             //                if (client.Entity.Stamina <= 90 + limit)
  94.             //                {
  95.             //                    client.Entity.Stamina += 10;
  96.             //                }
  97.             //                else
  98.             //                {
  99.             //                    if (client.Entity.Stamina != 100 + limit)
  100.             //                        client.Entity.Stamina = (byte)(100 + limit);
  101.             //                }
  102.             //            }
  103.             //            else
  104.             //            {
  105.             //                if (client.Entity.Stamina <= 95 + limit)
  106.             //                {
  107.             //                    client.Entity.Stamina += 5;
  108.             //                }
  109.             //                else
  110.             //                {
  111.             //                    if (client.Entity.Stamina != 100 + limit)
  112.             //                        client.Entity.Stamina = (byte)(100 + limit);
  113.             //                }
  114.             //            }
  115.             //        }
  116.             //        client.Entity.StaminaStamp = new Time32(time);
  117.             //    }
  118.             //}
  119.             #endregion
  120.             #region Stamina
  121.             if (client.Entity.StaminaStamp.Next(500, time: time))
  122.             {
  123.                 if (client.Vigor < client.Entity.ExtraVigor)
  124.                 {
  125.                     client.Vigor += (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
  126.                     {
  127.                         Vigor vigor = new Vigor(true);
  128.                         vigor.Amount = client.Vigor;
  129.                         vigor.Send(client);
  130.                     }
  131.                 }
  132.                 if (!client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Ride) && !client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly) || client.Equipment.TryGetItem(18) != null)
  133.                 {
  134.                     int limit = 0;
  135.                     if (client.Entity.HeavenBlessing > 0)
  136.                         limit = 50;
  137.                     if (client.Spells != null)
  138.                     {
  139.                         if (client.Spells.ContainsKey(12560))
  140.                         {
  141.                             var spell = client.Spells[12560];
  142.                             var skill = Database.SpellTable.SpellInformations[12560][spell.Level];
  143.                             limit += (int)skill.Power;
  144.                         }
  145.                     }
  146.                     if (client.Entity.Stamina != 100 + limit)
  147.                     {
  148.                         if (client.Entity.Action == Enums.ConquerAction.Sit)
  149.                         {
  150.                             if (client.Entity.Stamina <= 93 + limit)
  151.                             {
  152.                                 client.Entity.Stamina += 7;
  153.                             }
  154.                             else
  155.                             {
  156.                                 if (client.Entity.Stamina != 100 + limit)
  157.                                     client.Entity.Stamina = (byte)(100 + limit);
  158.                             }
  159.                         }
  160.                         else
  161.                         {
  162.                             if (client.Entity.Stamina <= 97 + limit)
  163.                             {
  164.                                 client.Entity.Stamina += 3;
  165.                             }
  166.                             else
  167.                             {
  168.                                 if (client.Entity.Stamina != 100 + limit)
  169.                                     client.Entity.Stamina = (byte)(100 + limit);
  170.                             }
  171.                         }
  172.                     }
  173.                     client.Entity.StaminaStamp = new Time32(time);
  174.                 }
  175.             }
  176.             #endregion
  177.             #region Energia Aurora Lotus / Flame Lotus
  178.             if (!client.Entity.Dead)
  179.             {
  180.                 if (client.Entity.LotusEnergyStamp.Next(1000, time: time))
  181.                 {
  182.                     if (client.Entity.Class >= 130 && client.Entity.Class <= 135)
  183.                     {
  184.                         if (client.Entity.ContainsFlag3((ulong)FlagsUpdate.Flags3.AuroraLotus))
  185.                         {
  186.                             if (client.Entity.AuroraLotusEnergy < 220)
  187.                                 client.Entity.AuroraLotusEnergy = (uint)Math.Min(220, client.Entity.AuroraLotusEnergy + 2);
  188.                             client.Entity.Lotus(client.Entity.AuroraLotusEnergy, FlagsUpdate.AuroraLotus);
  189.                         }
  190.                     }
  191.                     if (client.Entity.Class >= 140 && client.Entity.Class <= 145)
  192.                     {
  193.                         if (client.Entity.ContainsFlag3((ulong)FlagsUpdate.Flags3.FlameLotus))
  194.                         {
  195.                             if (client.Entity.FlameLotusEnergy < 330)
  196.                                 client.Entity.FlameLotusEnergy = (uint)Math.Min(330, client.Entity.FlameLotusEnergy + 3);
  197.                             client.Entity.Lotus(client.Entity.FlameLotusEnergy, FlagsUpdate.FlameLotus);
  198.  
  199.                         }
  200.                     }
  201.                     client.Entity.LotusEnergyStamp = new Time32(time);
  202.                 }
  203.             }
  204.             #endregion
  205.             if (client.Map.ID == 8880 || client.Map.ID == 8881)
  206.             {
  207.                 SafeDictionary<uint, PokerTable> ToRem = new SafeDictionary<uint, PokerTable>(40);
  208.                 foreach (PokerTable T in PokerTables.Values)
  209.                 {
  210.                     if (client.Map.ID == T.Map)
  211.                         if (Kernel.GetDistance(T.X, T.Y, client.Entity.X, client.Entity.Y) > Constants.nScreenDistance)
  212.                             ToRem.Add(T.Id, T);
  213.                 }
  214.                 foreach (PokerTable T in ToRem.Values)
  215.                     if (PokerTables.ContainsKey(T.Id))
  216.                         PokerTables.Remove(T.Id);
  217.             }
  218.             foreach (IMapObject obj in client.Screen.Objects)
  219.             {
  220.                 if (obj != null)
  221.                 {
  222.                     if (obj.MapObjType == MapObjectType.Monster)
  223.                     {
  224.                         Entity monster = obj as Entity;
  225.                         if (monster == null) continue;
  226.  
  227.                         if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.Stigma))
  228.                         {
  229.                             if (monster.StigmaStamp.AddSeconds(monster.StigmaTime).Next(time: time) || monster.Dead)
  230.                             {
  231.                                 monster.StigmaTime = 0;
  232.                                 monster.StigmaIncrease = 0;
  233.                                 monster.RemoveFlag((ulong)FlagsUpdate.Flags.Stigma);
  234.                             }
  235.                         }
  236.                         if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.Dodge))
  237.                         {
  238.                             if (monster.DodgeStamp.AddSeconds(monster.DodgeTime).Next(time: time) || monster.Dead)
  239.                             {
  240.                                 monster.DodgeTime = 0;
  241.                                 monster.DodgeIncrease = 0;
  242.                                 monster.RemoveFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.Dodge);
  243.                             }
  244.                         }
  245.                         if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.Invisibility))
  246.                         {
  247.                             if (monster.InvisibilityStamp.AddSeconds(monster.InvisibilityTime).Next(time: time) || monster.Dead)
  248.                             {
  249.                                 monster.RemoveFlag((ulong)FlagsUpdate.Flags.Invisibility);
  250.                             }
  251.                         }
  252.                         if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.StarOfAccuracy))
  253.                         {
  254.                             if (monster.StarOfAccuracyTime != 0)
  255.                             {
  256.                                 if (monster.StarOfAccuracyStamp.AddSeconds(monster.StarOfAccuracyTime).Next(time: time) || monster.Dead)
  257.                                 {
  258.                                     monster.RemoveFlag((ulong)FlagsUpdate.Flags.StarOfAccuracy);
  259.                                 }
  260.                             }
  261.                             else
  262.                             {
  263.                                 if (monster.AccuracyStamp.AddSeconds(monster.AccuracyTime).Next(time: time) || monster.Dead)
  264.                                 {
  265.                                     monster.RemoveFlag((ulong)FlagsUpdate.Flags.StarOfAccuracy);
  266.                                 }
  267.                             }
  268.                         }
  269.                         if (monster.ContainsFlag((ulong)FlagsUpdate.Flags.MagicShield))
  270.                         {
  271.                             if (monster.MagicShieldTime != 0)
  272.                             {
  273.                                 if (monster.MagicShieldStamp.AddSeconds(monster.MagicShieldTime).Next(time: time) || monster.Dead)
  274.                                 {
  275.                                     monster.MagicShieldIncrease = 0;
  276.                                     monster.MagicShieldTime = 0;
  277.                                     monster.RemoveFlag((ulong)FlagsUpdate.Flags.MagicShield);
  278.                                 }
  279.                             }
  280.                             else
  281.                             {
  282.                                 if (monster.ShieldStamp.AddSeconds(monster.ShieldTime).Next(time: time) || monster.Dead)
  283.                                 {
  284.                                     monster.ShieldIncrease = 0;
  285.                                     monster.ShieldTime = 0;
  286.                                     monster.RemoveFlag((ulong)FlagsUpdate.Flags.MagicShield);
  287.                                 }
  288.                             }
  289.                         }
  290.                         if (monster.Dead || monster.Killed)
  291.                         {
  292.                             if (!monster.ContainsFlag((ulong)FlagsUpdate.Flags.Ghost) || monster.Killed)
  293.                             {
  294.                                 monster.Killed = false;
  295.                                 monster.MonsterInfo.InSight = 0;
  296.                                 monster.AddFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.Ghost);
  297.                                 monster.AddFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.Dead);
  298.                                 monster.AddFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.FadeAway);
  299.                                 Network.GamePackets.Attack attack = new Network.GamePackets.Attack(true);
  300.                                 attack.Attacker = monster.Killer.UID;
  301.                                 attack.Attacked = monster.UID;
  302.                                 attack.AttackType = Network.GamePackets.Attack.Kill;
  303.                                 attack.X = monster.X;
  304.                                 attack.Y = monster.Y;
  305.                                 client.Map.Floor[monster.X, monster.Y, MapObjectType.Monster, monster] = true;
  306.                                 attack.KOCount = ++monster.Killer.KOCount;
  307.                                 if (monster.Killer.EntityFlag == EntityFlag.Player)
  308.                                 {
  309.                                     monster.MonsterInfo.ExcludeFromSend = monster.Killer.UID;
  310.                                     monster.Killer.Owner.Send(attack);
  311.                                 }
  312.                                 monster.MonsterInfo.SendScreen(attack);
  313.                                 monster.MonsterInfo.ExcludeFromSend = 0;
  314.                             }
  315.                             if (monster.DeathStamp.AddSeconds(4).Next(time: time))
  316.                             {
  317.                                 Data data = new Data(true);
  318.                                 data.UID = monster.UID;
  319.                                 data.ID = Network.GamePackets.Data.RemoveEntity;
  320.                                 monster.MonsterInfo.SendScreen(data);
  321.                             }
  322.                         }
  323.                     }
  324.                 }
  325.             }
  326.         }
  327.         private static void guardsCallback(GameState client, int time)
  328.         {
  329.             if (!client.Socket.Alive)
  330.             {
  331.                 client.Screen.DisposeTimers(); return;
  332.             }
  333.             if (client.Entity == null) return;
  334.             if (client.Map == null) return;
  335.             if (client.Map.FreezeMonsters) return;
  336.             Time32 Now = new Time32(time);
  337.             foreach (IMapObject obj in client.Screen.Objects)
  338.             {
  339.                 if (obj != null)
  340.                 {
  341.                     if (obj.MapObjType == MapObjectType.Monster)
  342.                     {
  343.                         Entity monster = obj as Entity;
  344.                         if (!monster.Companion && !monster.Dead && !monster.Killed && monster.MonsterInfo.Guard && !monster.MonsterInfo.Boss && monster.Name != "NemesisTyrant" && monster.Name != "SwordMaster" && monster.Name != "ThrillingSpook" && monster.Name != "LavaBeast" && monster.Name != "SnowBanshee" && monster.Name != "PurpleBanshee" && monster.Name != "SnowBansheeSoul" && monster.Name != "TeratoDragon" && Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  345.                         {
  346.                             if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  347.                             {
  348.                                 if (monster.MonsterInfo.InSight == 0)
  349.                                 {
  350.                                     if (monster.X != monster.MonsterInfo.BoundX || monster.Y != monster.MonsterInfo.BoundY)
  351.                                     {
  352.                                         monster.X = monster.MonsterInfo.BoundX;
  353.                                         monster.Y = monster.MonsterInfo.BoundY;
  354.                                         TwoMovements jump = new TwoMovements();
  355.                                         jump.X = monster.MonsterInfo.BoundX;
  356.                                         jump.Y = monster.MonsterInfo.BoundY;
  357.                                         jump.EntityCount = 1;
  358.                                         jump.FirstEntity = monster.UID;
  359.                                         jump.MovementType = TwoMovements.Jump;
  360.                                         client.SendScreen(jump, true);
  361.                                     }
  362.                                     /*
  363.                                     if (monster.MonsterInfo.Type != 1)  
  364.                                        client.Send(new Network.GamePackets.Message("WelCoMe In "+ Constants.ServerName +"#38", client.Entity.Name, monster.MonsterInfo.Name, System.Drawing.Color.White, Message.Talk));
  365.                                        client.Send(new Network.GamePackets.Message("WelCoMe In " + Constants.ServerName + "#00", client.Entity.Name, monster.Name, System.Drawing.Color.White, Message.Talk));
  366.                                     */
  367.                                     if (client.Entity.ContainsFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.FlashingName))
  368.                                         monster.MonsterInfo.InSight = client.Entity.UID;
  369.                                 }
  370.                                 else
  371.                                 {
  372.                                     if (client.Entity.ContainsFlag((ulong)Network.GamePackets.FlagsUpdate.Flags.FlashingName))
  373.                                     {
  374.                                         if (monster.MonsterInfo.InSight == client.Entity.UID)
  375.                                         {
  376.                                             if (!client.Entity.Dead)
  377.                                             {
  378.                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  379.                                                 {
  380.                                                     short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  381.  
  382.                                                     if (distance <= monster.MonsterInfo.AttackRange)
  383.                                                     {
  384.                                                         monster.MonsterInfo.LastMove = Time32.Now;
  385.                                                         new Game.Attacking.Handle(null, monster, client.Entity);
  386.                                                     }
  387.                                                     else
  388.                                                     {
  389.                                                         if (distance <= monster.MonsterInfo.ViewRange)
  390.                                                         {
  391.                                                             TwoMovements jump = new TwoMovements();
  392.                                                             jump.X = client.Entity.X;
  393.                                                             jump.Y = client.Entity.Y;
  394.                                                             monster.X = client.Entity.X;
  395.                                                             monster.Y = client.Entity.Y;
  396.                                                             jump.EntityCount = 1;
  397.                                                             jump.FirstEntity = monster.UID;
  398.                                                             jump.MovementType = TwoMovements.Jump;
  399.                                                             client.SendScreen(jump, true);
  400.                                                         }
  401.                                                     }
  402.                                                 }
  403.                                             }
  404.                                         }
  405.                                     }
  406.                                     else
  407.                                     {
  408.                                         if (monster.MonsterInfo.InSight == client.Entity.UID)
  409.                                         {
  410.                                             monster.MonsterInfo.InSight = 0;
  411.                                         }
  412.                                     }
  413.                                 }
  414.                                 foreach (IMapObject obj2 in client.Screen.Objects)
  415.                                 {
  416.                                     if (obj2 == null) continue;
  417.                                     if (obj2.MapObjType == MapObjectType.Monster)
  418.                                     {
  419.                                         Entity monster2 = obj2 as Entity;
  420.  
  421.                                         if (monster2 == null) continue;
  422.                                         if (monster2.Dead) continue;
  423.  
  424.                                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  425.                                         {
  426.                                             if (!monster2.MonsterInfo.Guard && (!monster2.Companion || monster2.Owner.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.FlashingName)))
  427.                                             {
  428.                                                 short distance = Kernel.GetDistance(monster.X, monster.Y, monster2.X, monster2.Y);
  429.  
  430.                                                 if (distance <= monster.MonsterInfo.AttackRange)
  431.                                                 {
  432.                                                     monster.MonsterInfo.LastMove = Time32.Now;
  433.                                                     new Game.Attacking.Handle(null, monster, monster2);
  434.                                                 }
  435.                                             }
  436.                                         }
  437.                                     }
  438.                                 }
  439.                             }
  440.                         }
  441.                     }
  442.                 }
  443.             }
  444.         }
  445.         private static void aliveMonstersCallback(GameState client, int time)
  446.         {
  447.             if (!client.Socket.Alive)
  448.             {
  449.                 client.Screen.DisposeTimers();
  450.                 return;
  451.             }
  452.             if (client.Entity == null) return;
  453.             if (client.Map == null) return;
  454.             if (client.Map.FreezeMonsters) return;
  455.             Time32 Now = new Time32(time);
  456.             foreach (IMapObject obj in client.Screen.Objects)
  457.             {
  458.                 if (obj != null)
  459.                 {
  460.                     if (obj.MapObjType == MapObjectType.Monster)
  461.                     {
  462.                         Entity monster = obj as Entity;
  463.                        
  464.                         if (monster == null) continue;
  465.                         if (monster.MonsterInfo.Guard || monster.Companion || monster.Dead) continue;
  466.                         if (monster.MonsterInfo.Reviver)
  467.                         {
  468.                             if (client.Entity.Dead && Now > client.Entity.DeathStamp.AddSeconds(5))
  469.                             {
  470.                                 client.Entity.BringToLife();
  471.                                 SpellUse use = new SpellUse(true);
  472.                                 use.Attacker = monster.UID;
  473.                                 use.X = client.Entity.X;
  474.                                 use.Y = client.Entity.Y;
  475.                                 use.SpellID = 1100;
  476.                                 use.AddTarget(client.Entity.UID, 0, null);
  477.                                 Kernel.SendWorldMessage(use, Server.GamePool, monster.MapID);
  478.                             }
  479.                             return;
  480.                         }
  481.                         short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  482.                         if (distance > Constants.pScreenDistance)
  483.                         {
  484.                             client.Screen.Remove(obj);
  485.                             continue;
  486.                         }
  487.                         if (monster.MonsterInfo.InSight != 0 && monster.MonsterInfo.InSight != client.Entity.UID)
  488.                         {
  489.                             if (monster.MonsterInfo.InSight > 1000000)
  490.                             {
  491.                                 GameState cl;
  492.                                 if (Kernel.GamePool.TryGetValue(monster.MonsterInfo.InSight, out cl))
  493.                                 {
  494.                                     short dst = Kernel.GetDistance(monster.X, monster.Y, cl.Entity.X, cl.Entity.Y);
  495.                                     if (dst > Constants.pScreenDistance)
  496.                                         monster.MonsterInfo.InSight = 0;
  497.                                 }
  498.                                 else
  499.                                     monster.MonsterInfo.InSight = 0;
  500.                             }
  501.                             else
  502.                             {
  503.                                 Entity companion = client.Map.Companions[monster.MonsterInfo.InSight];
  504.                                 if (companion != null)
  505.                                 {
  506.                                     short dst = Kernel.GetDistance(monster.X, monster.Y, companion.X, companion.Y);
  507.                                     if (dst > Constants.pScreenDistance)
  508.                                         monster.MonsterInfo.InSight = 0;
  509.                                 }
  510.                                 else
  511.                                     monster.MonsterInfo.InSight = 0;
  512.                             }
  513.                         }
  514.                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  515.                         {
  516.                             if (distance <= Constants.pScreenDistance)
  517.                             {
  518.                                 #region Companions
  519.                                 if (client.Pet != null)
  520.                                 {
  521.                                     if (client.Pet.Pets != null)
  522.                                     {
  523.                                         foreach (var pet in client.Pet.Pets.Values)
  524.                                         {
  525.                                             if (pet != null)
  526.                                             {
  527.                                                 #region Pets
  528.                                                 if (pet.Entity.Companion && !pet.Entity.Dead)
  529.                                                 {
  530.                                                     short distance2 = Kernel.GetDistance(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  531.                                                     if (distance > distance2 || client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Invisibility) || client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly))
  532.                                                     {
  533.                                                         if (monster.MonsterInfo.InSight == 0)
  534.                                                         {
  535.                                                             monster.MonsterInfo.InSight = pet.Entity.UID;
  536.                                                         }
  537.                                                         else
  538.                                                         {
  539.                                                             if (monster.MonsterInfo.InSight == pet.Entity.UID)
  540.                                                             {
  541.                                                                 if (distance2 > Constants.pScreenDistance)
  542.                                                                 {
  543.                                                                     monster.MonsterInfo.InSight = 0;
  544.                                                                 }
  545.                                                                 else
  546.                                                                 {
  547.                                                                     if (distance2 <= monster.MonsterInfo.AttackRange)
  548.                                                                     {
  549.                                                                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  550.                                                                         {
  551.                                                                             monster.MonsterInfo.LastMove = Time32.Now;
  552.                                                                             new Game.Attacking.Handle(null, monster, pet.Entity);
  553.                                                                             if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  554.                                                                             {
  555.                                                                                 monster.MonsterInfo.Lastpop = Time32.Now;
  556.                                                                                 continue;
  557.                                                                             }
  558.                                                                         }
  559.                                                                     }
  560.                                                                     else
  561.                                                                     {
  562.                                                                         if (distance2 > monster.MonsterInfo.ViewRange / 2)
  563.                                                                         {
  564.                                                                             if (distance2 < Constants.pScreenDistance)
  565.                                                                             {
  566.                                                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  567.                                                                                 {
  568.                                                                                     monster.MonsterInfo.LastMove = Time32.Now;
  569.                                                                                     Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  570.                                                                                     if (!monster.Move(facing))
  571.                                                                                     {
  572.                                                                                         facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  573.                                                                                         if (monster.Move(facing))
  574.                                                                                         {
  575.                                                                                             monster.Facing = facing;
  576.                                                                                             GroundMovement move = new GroundMovement(true);
  577.                                                                                             move.Direction = facing;
  578.                                                                                             move.UID = monster.UID;
  579.                                                                                             move.GroundMovementType = GroundMovement.Run;
  580.                                                                                             monster.MonsterInfo.SendScreen(move);
  581.                                                                                             continue;
  582.                                                                                         }
  583.                                                                                     }
  584.                                                                                     else
  585.                                                                                     {
  586.                                                                                         monster.Facing = facing;
  587.                                                                                         GroundMovement move = new GroundMovement(true);
  588.                                                                                         move.Direction = facing;
  589.                                                                                         move.UID = monster.UID;
  590.                                                                                         move.GroundMovementType = GroundMovement.Run;
  591.                                                                                         monster.MonsterInfo.SendScreen(move);
  592.                                                                                         continue;
  593.                                                                                     }
  594.                                                                                 }
  595.                                                                             }
  596.                                                                             else
  597.                                                                             {
  598.                                                                                 monster.MonsterInfo.InSight = 0;
  599.                                                                             }
  600.                                                                         }
  601.                                                                         else
  602.                                                                         {
  603.                                                                             if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  604.                                                                             {
  605.                                                                                 monster.MonsterInfo.LastMove = Time32.Now;
  606.                                                                                 Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, pet.Entity.X, pet.Entity.Y);
  607.                                                                                 if (!monster.Move(facing))
  608.                                                                                 {
  609.                                                                                     facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  610.                                                                                     if (monster.Move(facing))
  611.                                                                                     {
  612.                                                                                         monster.Facing = facing;
  613.                                                                                         GroundMovement move = new GroundMovement(true);
  614.                                                                                         move.Direction = facing;
  615.                                                                                         move.UID = monster.UID;
  616.                                                                                         monster.MonsterInfo.SendScreen(move);
  617.                                                                                         continue;
  618.                                                                                     }
  619.                                                                                 }
  620.                                                                                 else
  621.                                                                                 {
  622.                                                                                     monster.Facing = facing;
  623.                                                                                     GroundMovement move = new GroundMovement(true);
  624.                                                                                     move.Direction = facing;
  625.                                                                                     move.UID = monster.UID;
  626.                                                                                     monster.MonsterInfo.SendScreen(move);
  627.                                                                                     continue;
  628.                                                                                 }
  629.                                                                             }
  630.                                                                         }
  631.                                                                     }
  632.                                                                 }
  633.                                                             }
  634.                                                         }
  635.                                                     }
  636.                                                 }
  637.                                                 #endregion
  638.                                             }
  639.  
  640.                                         }
  641.                                     }
  642.                                 }
  643.                                 #endregion
  644.                                 #region Player
  645.                                 if (monster.MonsterInfo.InSight == 0)
  646.                                 {
  647.                                     if (distance <= monster.MonsterInfo.ViewRange)
  648.                                     {
  649.                                         if (!client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Invisibility))
  650.                                         {
  651.                                             if (monster.MonsterInfo.SpellID != 0 || !client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly))
  652.                                             {
  653.                                                 monster.MonsterInfo.InSight = client.Entity.UID;
  654.                                             }
  655.                                         }
  656.                                     }
  657.                                 }
  658.                                 else
  659.                                 {
  660.                                     if (monster.MonsterInfo.InSight == client.Entity.UID)
  661.                                     {
  662.                                         if (monster.MonsterInfo.SpellID == 0 && client.Entity.ContainsFlag((ulong)FlagsUpdate.Flags.Fly))
  663.                                         {
  664.                                             monster.MonsterInfo.InSight = 0;
  665.                                             return;
  666.                                         }
  667.                                         if (client.Entity.Dead)
  668.                                         {
  669.                                             monster.MonsterInfo.InSight = 0;
  670.                                             return;
  671.                                         }
  672.                                         if (distance > Constants.pScreenDistance)
  673.                                         {
  674.                                             monster.MonsterInfo.InSight = 0;
  675.                                         }
  676.                                         else
  677.                                         {
  678.                                             if (distance <= monster.MonsterInfo.AttackRange)
  679.                                             {
  680.                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  681.                                                 {
  682.                                                     monster.MonsterInfo.LastMove = Time32.Now;
  683.                                                     new Game.Attacking.Handle(null, monster, client.Entity);
  684.                                                 }
  685.                                             }
  686.                                             else
  687.                                             {
  688.                                                 if (distance > monster.MonsterInfo.ViewRange / 2)
  689.                                                 {
  690.                                                     if (distance < Constants.pScreenDistance)
  691.                                                     {
  692.                                                         if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.RunSpeed))
  693.                                                         {
  694.                                                             monster.MonsterInfo.LastMove = Time32.Now;
  695.                                                             Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  696.                                                             if (!monster.Move(facing))
  697.                                                             {
  698.                                                                 facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  699.                                                                 if (monster.Move(facing))
  700.                                                                 {
  701.                                                                     monster.Facing = facing;
  702.                                                                     GroundMovement move = new GroundMovement(true);
  703.                                                                     move.Direction = facing;
  704.                                                                     move.UID = monster.UID;
  705.                                                                     move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  706.                                                                     monster.MonsterInfo.SendScreen(move);
  707.                                                                 }
  708.                                                             }
  709.                                                             else
  710.                                                             {
  711.                                                                 monster.Facing = facing;
  712.                                                                 GroundMovement move = new GroundMovement(true);
  713.                                                                 move.Direction = facing;
  714.                                                                 move.UID = monster.UID;
  715.                                                                 move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
  716.                                                                 monster.MonsterInfo.SendScreen(move);
  717.                                                             }
  718.                                                         }
  719.                                                     }
  720.                                                     else
  721.                                                     {
  722.                                                         monster.MonsterInfo.InSight = 0;
  723.                                                     }
  724.                                                 }
  725.                                                 else
  726.                                                 {
  727.                                                     if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MoveSpeed))
  728.                                                     {
  729.                                                         monster.MonsterInfo.LastMove = Time32.Now;
  730.                                                         Enums.ConquerAngle facing = Kernel.GetAngle(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  731.                                                         if (!monster.Move(facing))
  732.                                                         {
  733.                                                             facing = (Enums.ConquerAngle)Kernel.Random.Next(7);
  734.                                                             if (monster.Move(facing))
  735.                                                             {
  736.                                                                 monster.Facing = facing;
  737.                                                                 GroundMovement move = new GroundMovement(true);
  738.                                                                 move.Direction = facing;
  739.                                                                 move.UID = monster.UID;
  740.                                                                 monster.MonsterInfo.SendScreen(move);
  741.                                                             }
  742.                                                         }
  743.                                                         else
  744.                                                         {
  745.                                                             monster.Facing = facing;
  746.                                                             GroundMovement move = new GroundMovement(true);
  747.                                                             move.Direction = facing;
  748.                                                             move.UID = monster.UID;
  749.                                                             monster.MonsterInfo.SendScreen(move);
  750.                                                         }
  751.                                                     }
  752.                                                 }
  753.                                             }
  754.                                         }
  755.                                     }
  756.                                 }
  757.                                 #endregion
  758.                             }
  759.                         }
  760.                     }
  761.                     else if (obj.MapObjType == MapObjectType.Item)
  762.                     {
  763.                         FloorItem item = obj as FloorItem;
  764.                         if (item == null) continue;
  765.  
  766.                         if (item.Type == FloorItem.Effect)
  767.                         {
  768.                             if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce || item.ItemID == 31)
  769.                             {
  770.                                 if (item.Owner == client)
  771.                                 {
  772.                                     if (Time32.Now > item.UseTime.AddSeconds(1))
  773.                                     {
  774.                                         item.UseTime = Time32.Now;
  775.                                         var spell = Database.SpellTable.GetSpell(11600, client);
  776.                                         var attack = new Attack(true);
  777.                                         attack.Attacker = item.Owner.Entity.UID;
  778.                                         attack.AttackType = Attack.Melee;
  779.                                         foreach (var obj1 in client.Screen.Objects)
  780.                                         {
  781.                                             if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  782.                                             {
  783.                                                 if (obj1.MapObjType == MapObjectType.Monster || obj1.MapObjType == MapObjectType.Player)
  784.                                                 {
  785.                                                     var attacked = obj1 as Entity;
  786.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  787.                                                     {
  788.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  789.                                                         damage = (uint)((damage) / 12);
  790.                                                         attack.Damage = damage;
  791.                                                         attack.Attacked = attacked.UID;
  792.                                                         attack.X = attacked.X;
  793.                                                         attack.Y = attacked.Y;
  794.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  795.                                                     }
  796.                                                 }
  797.                                                 else if (obj1.MapObjType == MapObjectType.SobNpc)
  798.                                                 {
  799.                                                     var attacked = obj1 as SobNpcSpawn;
  800.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell))
  801.                                                     {
  802.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, ref attack);
  803.                                                         damage = (uint)(damage * spell.PowerPercent);
  804.                                                         attack.Damage = damage;
  805.                                                         attack.Attacked = attacked.UID;
  806.                                                         attack.X = attacked.X;
  807.                                                         attack.Y = attacked.Y;
  808.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, damage, spell);
  809.                                                     }
  810.                                                 }
  811.                                             }
  812.                                         }
  813.                                     }
  814.                                 }
  815.                             }
  816.                             if (item.ItemID == 1397)
  817.                             {
  818.                                 if (item.Owner == client)
  819.                                 {
  820.                                     if (item.OnFloor.AddSeconds(3).Next(time: time))
  821.                                     {
  822.                                         item.UseTime = Time32.Now;
  823.                                         var spell = Database.SpellTable.GetSpell(12550, client);
  824.                                         var attack = new Attack(true);
  825.                                         attack.Attacker = item.Owner.Entity.UID;
  826.                                         attack.AttackType = Attack.Melee;
  827.                                         foreach (var obj1 in client.Screen.Objects)
  828.                                         {
  829.                                             if (Kernel.GetDistance(obj1.X, obj1.Y, obj.X, obj.Y) <= 3)
  830.                                             {
  831.                                                 if (obj1.MapObjType == MapObjectType.Player)
  832.                                                 {
  833.                                                     var attacked = obj1 as Entity;
  834.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  835.                                                     {
  836.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  837.                                                         // damage = (uint)(damage * 3);
  838.                                                         // damage = damage * 10;
  839.                                                         attack.Damage = damage;
  840.                                                         attack.Attacked = attacked.UID;
  841.                                                         attack.X = attacked.X;
  842.                                                         attack.Y = attacked.Y;
  843.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  844.                                                     }
  845.                                                 }
  846.                                                 else if (obj1.MapObjType == MapObjectType.Monster)
  847.                                                 {
  848.                                                     var attacked = obj1 as Entity;
  849.                                                     if (Attacking.Handle.CanAttack(client.Entity, attacked, spell, false))
  850.                                                     {
  851.                                                         uint damage = Game.Attacking.Calculate.Melee(client.Entity, attacked, spell, ref attack);
  852.                                                         //  damage = (uint)(damage * 3);
  853.                                                         //  damage = damage * 10;
  854.                                                         attack.Damage = damage;
  855.                                                         attack.Attacked = attacked.UID;
  856.                                                         attack.X = attacked.X;
  857.                                                         attack.Y = attacked.Y;
  858.                                                         Attacking.Handle.ReceiveAttack(client.Entity, attacked, attack, ref damage, spell);
  859.                                                     }
  860.                                                 }
  861.                                             }
  862.                                         }
  863.                                     }
  864.                                 }
  865.                             }
  866.                         }
  867.                     }
  868.                 }
  869.             }
  870.         }
  871.           private static void itemsCallback(GameState client, int time)
  872.         {
  873.             if (!client.Socket.Alive)
  874.             {
  875.                 client.Screen.DisposeTimers(); return;
  876.             }
  877.             if (client.Entity == null) return;
  878.             if (client.Map == null) return;
  879.             if (client.Map.FreezeMonsters) return;
  880.             if (!client.Entity.FullyLoaded) return;
  881.             Time32 Now = new Time32(time);
  882.             foreach (IMapObject obj in client.Screen.Objects)
  883.             {
  884.                 if (obj != null)
  885.                 {
  886.                     if (obj.MapObjType == MapObjectType.Item)
  887.                     {
  888.                         FloorItem item = obj as FloorItem;
  889.                         if (item == null) continue;
  890.                         if (item.Type == FloorItem.Effect)
  891.                         {
  892.                             if (item.ItemID == 1397)
  893.                             {
  894.                                 if (item.OnFloor.AddSeconds(3).Next(time: time))
  895.                                 {
  896.                                     Attacking.Handle.InfroEcho(item);
  897.                                     item.Type = FloorItem.RemoveEffect;
  898.                                     client.Map.RemoveFloorItem(item);
  899.                                     client.RemoveScreenSpawn(item, true);
  900.                                 }
  901.                             }
  902.                             if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce || item.ItemID == 31)
  903.                             {
  904.                                 if (item.OnFloor.AddSeconds(4).Next(time: time))
  905.                                 {
  906.                                     item.Type = FloorItem.RemoveEffect;
  907.                                     client.Map.RemoveFloorItem(item);
  908.                                     client.RemoveScreenSpawn(item, true);
  909.                                 }
  910.                             }
  911.                             if (item.ItemID == FloorItem.AuroraLotus)
  912.                             {
  913.                                 if (item.OnFloor.AddSeconds(7).Next(time: time))
  914.                                 {
  915.                                     item.Type = FloorItem.RemoveEffect;
  916.                                     client.Map.RemoveFloorItem(item);
  917.                                     client.RemoveScreenSpawn(item, true);
  918.                                     Attacking.Handle.AuroraLotus(item);
  919.                                 }
  920.                             }
  921.                             if (item.ItemID == FloorItem.FlameLotus)
  922.                             {
  923.                                 if (item.OnFloor.AddSeconds(7).Next(time: time))
  924.                                 {
  925.                                     item.Type = FloorItem.RemoveEffect;
  926.                                     client.Map.RemoveFloorItem(item);
  927.                                     client.RemoveScreenSpawn(item, true);
  928.                                     Attacking.Handle.FlameLotus(item);
  929.                                 }
  930.                             }
  931.                             if (item.ItemID == FloorItem.TwilightDance)
  932.                             {
  933.                                 if (item.OnFloor.AddMilliseconds(500).Next(time: time))
  934.                                 {
  935.                                     item.Type = FloorItem.RemoveEffect;
  936.                                     client.Map.RemoveFloorItem(item);
  937.                                     client.RemoveScreenSpawn(item, true);
  938.                                 }
  939.                             }
  940.                         }
  941.                         else
  942.                         {
  943.                             if (item.OnFloor.AddSeconds(Constants.FloorItemSeconds).Next(time: time))
  944.                             {
  945.                                 item.Type = FloorItem.Remove;
  946.                                 foreach (Interfaces.IMapObject _obj in client.Screen.Objects)
  947.                                     if (_obj != null)
  948.                                         if (_obj.MapObjType == MapObjectType.Player)
  949.                                             (_obj as Entity).Owner.Send(item);
  950.                                 client.Map.RemoveFloorItem(item);
  951.                                 client.Screen.Remove(item);
  952.                             }
  953.                         }
  954.  
  955.                     }
  956.                 }
  957.             }
  958.         }
  959.         private static void MatrixMobsCallback(GameState client, int time)
  960.         {
  961.             if (!client.Socket.Alive)
  962.             {
  963.                 client.Screen.DisposeTimers();
  964.                 return;
  965.             }
  966.             if (client.Entity == null)
  967.                 return;
  968.             if (client.Map == null)
  969.                 return;
  970.             if (client.Map.FreezeMonsters)
  971.                 return;
  972.  
  973.             Time32 Now = new Time32(time);
  974.             foreach (IMapObject obj in client.Screen.Objects)
  975.             {
  976.                 if (obj != null)
  977.                 {
  978.                     if (obj.MapObjType == MapObjectType.Monster)
  979.                     {
  980.                         Entity monster = obj as Entity;
  981.                         if (monster.Companion) continue;
  982.                         if (monster.Dead || monster.Killed) continue;
  983.  
  984.                         if (monster.MonsterInfo.Type == 2 || monster.Mesh == 482)
  985.                         {
  986.                             if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.MinimumSpeed))
  987.                             {
  988.                                 if (monster.MonsterInfo.InSight == 0)
  989.                                 {
  990.                                     ushort xx = (ushort)Kernel.Random.Next(monster.X - 10, monster.X + 10);
  991.                                     ushort yy = (ushort)Kernel.Random.Next(monster.Y - 10, monster.Y + 10);
  992.                                     if (monster.X != xx || monster.Y != yy)
  993.                                     {
  994.                                         monster.X = xx;
  995.                                         monster.Y = yy;
  996.                                         TwoMovements jump = new TwoMovements();
  997.                                         jump.X = xx;
  998.                                         jump.Y = yy;
  999.                                         jump.EntityCount = 1;
  1000.                                         jump.FirstEntity = monster.UID;
  1001.                                         jump.MovementType = TwoMovements.Jump;
  1002.                                         client.SendScreen(jump, true);
  1003.                                     }
  1004.                                     // if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1005.                                     //    monster.MonsterInfo.InSight = client.Entity.UID;
  1006.                                 }
  1007.                                 else
  1008.                                 {
  1009.                                     //  if (client.Entity.ContainsFlag(Update.Flags.FlashingName))
  1010.                                     {
  1011.                                         if (monster.MonsterInfo.InSight == client.Entity.UID)
  1012.                                         {
  1013.                                             if (!client.Entity.Dead)
  1014.                                             {
  1015.                                                 if (Now >= monster.MonsterInfo.LastMove.AddMilliseconds(monster.MonsterInfo.AttackSpeed))
  1016.                                                 {
  1017.                                                     short distance = Kernel.GetDistance(monster.X, monster.Y, client.Entity.X, client.Entity.Y);
  1018.  
  1019.                                                     if (distance <= monster.MonsterInfo.AttackRange)
  1020.                                                     {
  1021.                                                         monster.MonsterInfo.LastMove = Time32.Now;
  1022.                                                         new Game.Attacking.Handle(null, monster, client.Entity);
  1023.                                                         if (Time32.Now >= monster.MonsterInfo.Lastpop.AddSeconds(30))
  1024.                                                         {
  1025.                                                             monster.MonsterInfo.Lastpop = Time32.Now;
  1026.  
  1027.                                                         }
  1028.                                                     }
  1029.                                                     else
  1030.                                                     {
  1031.                                                         if (distance <= monster.MonsterInfo.ViewRange)
  1032.                                                         {
  1033.                                                             TwoMovements jump = new TwoMovements();
  1034.                                                             jump.X = client.Entity.X;
  1035.                                                             jump.Y = client.Entity.Y;
  1036.                                                             monster.X = client.Entity.X;
  1037.                                                             monster.Y = client.Entity.Y;
  1038.                                                             jump.EntityCount = 1;
  1039.                                                             jump.FirstEntity = monster.UID;
  1040.                                                             jump.MovementType = TwoMovements.Jump;
  1041.                                                             client.SendScreen(jump, true);
  1042.                                                         }
  1043.                                                     }
  1044.                                                 }
  1045.                                             }
  1046.                                         }
  1047.                                     }
  1048.                                 }
  1049.                             }
  1050.                         }
  1051.                     }
  1052.                 }
  1053.             }
  1054.         }
  1055.         private IDisposable[] TimerSubscriptions;
  1056.         private object DisposalSyncRoot;
  1057.         public ConcurrentDictionary<uint, Game.Statue> Statue = new ConcurrentDictionary<uint, Statue>();
  1058.         private Interfaces.IMapObject[] _objects;
  1059.         private static ConcurrentDictionary<uint, PokerTable> PokerTables;
  1060.         public Interfaces.IMapObject[] Objects
  1061.         {
  1062.             get { return _objects; }
  1063.         }
  1064.         private ConcurrentDictionary<uint, Interfaces.IMapObject> _objectDictionary;
  1065.         public Client.GameState Owner;
  1066.         public Screen(Client.GameState client)
  1067.         {
  1068.             Owner = client;
  1069.             _objects = new Interfaces.IMapObject[0];
  1070.             PokerTables = new ConcurrentDictionary<uint, PokerTable>();
  1071.             _objectDictionary = new ConcurrentDictionary<uint, IMapObject>();
  1072.             TimerSubscriptions = new IDisposable[]
  1073.             {
  1074.                 MonsterBuffers.Add(client),
  1075.                 Guards.Add(client),
  1076.                 AliveMonsters.Add(client),
  1077.                 Items.Add(client),
  1078.                 FloorSpells.Add(client),
  1079.                 MatrixMobs.Add(client)
  1080.             };
  1081.             DisposalSyncRoot = new object();
  1082.         }
  1083.         ~Screen()
  1084.         {
  1085.             DisposeTimers();
  1086.             Clear();
  1087.             _objects = null;
  1088.             _objectDictionary = null;
  1089.             Owner = null;
  1090.         }
  1091.         public void DisposeTimers()
  1092.         {
  1093.             lock (DisposalSyncRoot)
  1094.             {
  1095.                 if (TimerSubscriptions == null) return;
  1096.                 for (int i = 0; i < TimerSubscriptions.Length; i++)
  1097.                 {
  1098.                     if (TimerSubscriptions[i] != null)
  1099.                     {
  1100.                         TimerSubscriptions[i].Dispose();
  1101.                         TimerSubscriptions[i] = null;
  1102.                     }
  1103.                 }
  1104.             }
  1105.         }
  1106.         private void updateBase()
  1107.         {
  1108.             _objects = _objectDictionary.Values.ToArray();
  1109.         }
  1110.         public bool Add(Interfaces.IMapObject _object)
  1111.         {
  1112.             if (_object == null) return false;
  1113.             if (_objectDictionary.ContainsKey(_object.UID))
  1114.                 if (_objectDictionary[_object.UID] == null)
  1115.                     _objectDictionary.Remove(_object.UID);
  1116.             if (!_objectDictionary.ContainsKey(_object.UID))
  1117.             {
  1118.                 if (Kernel.GetDistance(_object.X, _object.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.pScreenDistance)
  1119.                 {
  1120.                     _objectDictionary[_object.UID] = _object;
  1121.                     updateBase();
  1122.                     return true;
  1123.                 }
  1124.             }
  1125.             return false;
  1126.         }
  1127.         public bool Remove(Interfaces.IMapObject _object)
  1128.         {
  1129.             if (_object == null) return false;
  1130.             if (_objectDictionary.Remove(_object.UID))
  1131.             {
  1132.                 updateBase();
  1133.                 if (_object.MapObjType == MapObjectType.Item)
  1134.                 {
  1135.                     FloorItem item = _object as FloorItem;
  1136.                     if (item.Type >= FloorItem.Effect)
  1137.                     {
  1138.                         item.Type = FloorItem.RemoveEffect;
  1139.                         Owner.Send(item);
  1140.                     }
  1141.                     else
  1142.                     {
  1143.                         item.Type = FloorItem.Remove;
  1144.                         Owner.Send(item);
  1145.                         item.Type = FloorItem.Drop;
  1146.                     }
  1147.                 }
  1148.                 else if (_object.MapObjType == MapObjectType.Player)
  1149.                 {
  1150.                     Owner.Send(new Data(true)
  1151.                     {
  1152.                         UID = _object.UID,
  1153.                         ID = Network.GamePackets.Data.RemoveEntity
  1154.                     });
  1155.                 }
  1156.                 else if (_object.MapObjType == MapObjectType.StaticEntity)
  1157.                 {
  1158.                     Owner.Send(new Data(true)
  1159.                     {
  1160.                         UID = _object.UID,
  1161.                         ID = Network.GamePackets.Data.RemoveEntity
  1162.                     });
  1163.                 }
  1164.                 return true;
  1165.             }
  1166.             return false;
  1167.         }
  1168.         public bool TryGetValue(uint uid, out Entity entity)
  1169.         {
  1170.             entity = null;
  1171.             Interfaces.IMapObject imo = null;
  1172.             if (_objectDictionary.TryGetValue(uid, out imo))
  1173.             {
  1174.                 if (imo == null)
  1175.                 {
  1176.                     _objectDictionary.Remove(uid);
  1177.                     updateBase();
  1178.                     return false;
  1179.                 }
  1180.                 if (imo is Entity)
  1181.                 {
  1182.                     entity = imo as Entity;
  1183.                     return true;
  1184.                 }
  1185.             }
  1186.             return false;
  1187.         }
  1188.         public bool GetRaceObject(Func<IMapObject, bool> predicate, out StaticEntity entity)
  1189.         {
  1190.             entity = null;
  1191.             foreach (var obj in Objects)
  1192.                 if (obj is StaticEntity)
  1193.                     if (predicate(obj))
  1194.                         entity = obj as StaticEntity;
  1195.             return entity != null;
  1196.         }
  1197.         public bool TryGetSob(uint uid, out SobNpcSpawn sob)
  1198.         {
  1199.             sob = null;
  1200.             Interfaces.IMapObject imo = null;
  1201.             if (_objectDictionary.TryGetValue(uid, out imo))
  1202.             {
  1203.                 if (imo == null)
  1204.                 {
  1205.                     _objectDictionary.Remove(uid);
  1206.                     updateBase();
  1207.                     return false;
  1208.                 }
  1209.                 if (imo is SobNpcSpawn)
  1210.                 {
  1211.                     sob = imo as SobNpcSpawn;
  1212.                     return true;
  1213.                 }
  1214.             }
  1215.             return false;
  1216.         }
  1217.         public bool TryGetFloorItem(uint uid, out FloorItem item)
  1218.         {
  1219.             item = null;
  1220.             Interfaces.IMapObject imo = null;
  1221.             if (_objectDictionary.TryGetValue(uid, out imo))
  1222.             {
  1223.                 if (imo == null)
  1224.                 {
  1225.                     _objectDictionary.Remove(uid);
  1226.                     updateBase();
  1227.                     return false;
  1228.                 }
  1229.                 if (imo is FloorItem)
  1230.                 {
  1231.                     item = imo as FloorItem;
  1232.                     return true;
  1233.                 }
  1234.             }
  1235.             return false;
  1236.         }
  1237.         public IEnumerable<T> Select<T>(MapObjectType type) where T : class
  1238.         {
  1239.             foreach (var obj in Objects)
  1240.                 if (obj != null)
  1241.                     if (obj.MapObjType == type)
  1242.                         yield return obj as T;
  1243.         }
  1244.         public IEnumerable<T> Where<T>(Func<IMapObject, bool> predicate) where T : class
  1245.         {
  1246.             foreach (var obj in Objects)
  1247.                 if (obj != null)
  1248.                     if (predicate(obj))
  1249.                         yield return obj as T;
  1250.         }
  1251.         public IEnumerable<T> SelectWhere<T>(MapObjectType type, Func<T, bool> predicate) where T : class
  1252.         {
  1253.             foreach (var obj in Objects)
  1254.                 if (obj != null)
  1255.                     if (obj.MapObjType == type)
  1256.                         if (predicate(obj as T))
  1257.                             yield return obj as T;
  1258.         }
  1259.         public bool Contains(Interfaces.IMapObject _object)
  1260.         {
  1261.             if (_object == null) return false;
  1262.             return _objectDictionary.ContainsKey(_object.UID);
  1263.         }
  1264.         public bool Contains(uint uid)
  1265.         {
  1266.             return _objectDictionary.ContainsKey(uid);
  1267.         }
  1268.         public void FullWipe()
  1269.         {
  1270.             foreach (IMapObject Base in Objects)
  1271.             {
  1272.                 if (Base == null) continue;
  1273.                 Data data = new Data(true);
  1274.                 data.UID = Base.UID;
  1275.                 data.ID = Data.RemoveEntity;
  1276.                 Owner.Send(data);
  1277.                 if (Base.MapObjType == Game.MapObjectType.Player)
  1278.                 {
  1279.                     GameState pPlayer = Base.Owner as GameState;
  1280.                     pPlayer.Screen.Remove(Owner.Entity);
  1281.                 }
  1282.             }
  1283.             Clear();
  1284.         }
  1285.         public void Clear()
  1286.         {
  1287.             _objectDictionary.Clear();
  1288.             _objects = new IMapObject[0];
  1289.         }
  1290.         public ConcurrentDictionary<uint, Game.BotShop> BOTSTALL = new ConcurrentDictionary<uint, BotShop>();
  1291.         public void Reload(Interfaces.IPacket spawnWith = null)
  1292.         {
  1293.             CleanUp(spawnWith);
  1294.             if (Owner.Entity.MapID == 1002)
  1295.             {
  1296.                 foreach (var statue in Game.Statue.Statues.Values)
  1297.                 {
  1298.                     if (statue > Owner)
  1299.                     {
  1300.                         Statue.TryAdd(statue.UID, statue);
  1301.                     }
  1302.                     else if (statue < Owner)
  1303.                     {
  1304.                         Game.Statue astatue;
  1305.                         Statue.TryRemove(statue.UID, out astatue);
  1306.                     }
  1307.                 }
  1308.             }
  1309.             else
  1310.             {
  1311.                 if (Statue.Count > 0)
  1312.                     Statue.Clear();
  1313.             }
  1314.             try
  1315.             {
  1316.                 foreach (GameState pClient in Kernel.GamePool.Values)
  1317.                 {
  1318.                     if (pClient == null) return;
  1319.                     if (pClient.Entity == null) return;
  1320.                     if (Owner == null) return;
  1321.                     if (Owner.Entity == null) return;
  1322.                     if (pClient.Entity.UID != Owner.Entity.UID)
  1323.                     {
  1324.                         if (pClient.Map.ID == Owner.Map.ID)
  1325.                         {
  1326.                             short dist = Kernel.GetDistance(pClient.Entity.X, pClient.Entity.Y, Owner.Entity.X, Owner.Entity.Y);
  1327.                             if (dist <= Constants.pScreenDistance && !Contains(pClient.Entity))
  1328.                             {
  1329.                                 if (pClient.Guild != null)
  1330.                                     pClient.Guild.SendName(Owner);
  1331.                                 if (Owner.Guild != null)
  1332.                                     Owner.Guild.SendName(pClient);
  1333.                                 if (pClient.Entity.InteractionInProgress && pClient.Entity.InteractionWith != Owner.Entity.UID && pClient.Entity.InteractionSet)
  1334.                                 {
  1335.                                     if (pClient.Entity.Body == 1003 || pClient.Entity.Body == 1004)
  1336.                                     {
  1337.                                         if (pClient.Entity.InteractionX == pClient.Entity.X && pClient.Entity.Y == pClient.Entity.InteractionY)
  1338.                                         {
  1339.                                             Attack atak = new Attack(true);
  1340.                                             atak.Attacker = pClient.Entity.UID;
  1341.                                             atak.Attacked = pClient.Entity.InteractionWith;
  1342.                                             atak.X = pClient.Entity.X;
  1343.                                             atak.Y = pClient.Entity.Y;
  1344.                                             atak.AttackType = 49;
  1345.                                             atak.Damage = pClient.Entity.InteractionType;
  1346.                                             Owner.Send(atak);
  1347.                                         }
  1348.                                     }
  1349.                                     else
  1350.                                     {
  1351.                                         if (Kernel.GamePool.ContainsKey(pClient.Entity.InteractionWith))
  1352.                                         {
  1353.                                             Client.GameState Cs = Kernel.GamePool[pClient.Entity.InteractionWith] as Client.GameState;
  1354.                                             if (Cs.Entity.X == pClient.Entity.InteractionX && pClient.Entity.Y == pClient.Entity.InteractionY)
  1355.                                             {
  1356.                                                 Attack atak = new Attack(true);
  1357.                                                 atak.Attacker = pClient.Entity.UID;
  1358.                                                 atak.Attacked = pClient.Entity.InteractionWith;
  1359.                                                 atak.X = pClient.Entity.X;
  1360.                                                 atak.Y = pClient.Entity.Y;
  1361.                                                 atak.AttackType = 49;
  1362.                                                 atak.Damage = pClient.Entity.InteractionType;
  1363.                                                 Owner.Send(atak);
  1364.                                             }
  1365.                                         }
  1366.                                     }
  1367.                                 }
  1368.                                 if (pClient.Entity.MyClones.Count > 0)
  1369.                                 {
  1370.                                     foreach (var clone in pClient.Entity.MyClones.Values)
  1371.                                     {
  1372.                                         if (clone == null) continue;
  1373.                                         if (Kernel.GetDistance(clone.X, clone.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(clone.UID))
  1374.                                         {
  1375.                                             if (!clone.Dead)
  1376.                                                 clone.SendSpawn(Owner);
  1377.                                         }
  1378.                                     }
  1379.                                 }
  1380.                                 if (pClient.Pet.Pets.Count > 0)
  1381.                                 {
  1382.                                     foreach (var pet in pClient.Pet.Pets.Values)
  1383.                                     {
  1384.                                         if (pet == null) continue;
  1385.                                         if (pet.Entity == null) continue;
  1386.                                         if (Kernel.GetDistance(pet.Entity.X, pet.Entity.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(pet.Entity.UID))
  1387.                                         {
  1388.                                             if (!pet.Entity.Dead)
  1389.                                                 pet.Entity.SendSpawn(Owner);
  1390.                                         }
  1391.                                     }
  1392.                                 }
  1393.                                 if (pClient.Map.BaseID == 700)
  1394.                                 {
  1395.                                     if (Owner.InQualifier())
  1396.                                     {
  1397.                                         if (pClient.InQualifier())
  1398.                                         {
  1399.                                             Owner.Entity.SendSpawn(pClient);
  1400.                                             pClient.Entity.SendSpawn(Owner);
  1401.                                             if (pClient.Guild != null)
  1402.                                                 Owner.Entity.SendSpawn(pClient, false);
  1403.                                             if (Owner.Guild != null)
  1404.                                                 pClient.Entity.SendSpawn(Owner, false);
  1405.                                             if (spawnWith != null)
  1406.                                                 pClient.Send(spawnWith);
  1407.                                         }
  1408.                                         else
  1409.                                         {
  1410.                                             Owner.Entity.SendSpawn(pClient);
  1411.                                             if (pClient.Guild != null)
  1412.                                                 Owner.Entity.SendSpawn(pClient, false);
  1413.                                             Add(pClient.Entity);
  1414.                                             if (spawnWith != null)
  1415.                                                 pClient.Send(spawnWith);
  1416.                                         }
  1417.                                     }
  1418.                                     else
  1419.                                     {
  1420.                                         if (pClient.InQualifier())
  1421.                                         {
  1422.                                             pClient.Entity.SendSpawn(Owner);
  1423.                                             if (Owner.Guild != null)
  1424.                                                 pClient.Entity.SendSpawn(Owner, false);
  1425.                                             pClient.Screen.Add(Owner.Entity);
  1426.                                             if (spawnWith != null)
  1427.                                                 Owner.Send(spawnWith);
  1428.                                         }
  1429.                                         else
  1430.                                         {
  1431.                                             Owner.Entity.SendSpawn(pClient);
  1432.                                             pClient.Entity.SendSpawn(Owner);
  1433.                                             if (pClient.Guild != null)
  1434.                                                 Owner.Entity.SendSpawn(pClient, false);
  1435.                                             if (Owner.Guild != null)
  1436.                                                 pClient.Entity.SendSpawn(Owner, false);
  1437.                                             if (spawnWith != null)
  1438.                                                 pClient.Send(spawnWith);
  1439.                                         }
  1440.                                     }
  1441.                                 }
  1442.                                 else
  1443.                                 {
  1444.                                     Owner.Entity.SendSpawn(pClient);
  1445.                                     pClient.Entity.SendSpawn(Owner);
  1446.                                     if (pClient.Guild != null)
  1447.                                         Owner.Entity.SendSpawn(pClient, false);
  1448.                                     if (Owner.Guild != null)
  1449.                                         pClient.Entity.SendSpawn(Owner, false);
  1450.                                     if (spawnWith != null)
  1451.                                         pClient.Send(spawnWith);
  1452.                                 }
  1453.                             }
  1454.                         }
  1455.                     }
  1456.                 }
  1457.                 var Map = Owner.Map;
  1458.                 #region Npcs
  1459.                 foreach (Interfaces.INpc npc in Map.Npcs.Values)
  1460.                 {
  1461.                     if (npc == null) continue;
  1462.                     if (Kernel.GetDistance(npc.X, npc.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  1463.                     if (Contains(npc.UID)) continue;
  1464.                     npc.SendSpawn(Owner, false);
  1465.                 }
  1466.                 #endregion
  1467.                 #region PlayersAdd
  1468.                 foreach (var p in Game.EntityAdd.DictionaryPlayers.Values)
  1469.                 {
  1470.                     if (p > Owner)
  1471.                     {
  1472.                         ConcurrentDictionaryPlayers.TryAdd(p.UID, p);
  1473.                     }
  1474.                     else if (p < Owner)
  1475.                     {
  1476.                         Game.EntityAdd outbot;
  1477.                         ConcurrentDictionaryPlayers.TryRemove(p.UID, out outbot);
  1478.                     }
  1479.                 }
  1480.                 #endregion
  1481.                 #region Items + map effects
  1482.                 foreach (var item in Map.FloorItems.Values)
  1483.                 {
  1484.                     if (item == null) continue;
  1485.                     if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  1486.                     if (Contains(item.UID)) continue;
  1487.                     if (item.Type == FloorItem.Effect)
  1488.                     {
  1489.                         if (item.ItemID == FloorItem.DaggerStorm || item.ItemID == FloorItem.FuryofEgg || item.ItemID == FloorItem.ShacklingIce || item.ItemID == 31 || item.ItemID == 1397)
  1490.                         {
  1491.                             if (item.OnFloor.AddSeconds(4).Next(time: Time32.Now.AllMilliseconds()))
  1492.                             {
  1493.                                 item.Type = FloorItem.RemoveEffect;
  1494.                                 foreach (Interfaces.IMapObject _obj in Objects)
  1495.                                     if (_obj != null)
  1496.                                         if (_obj.MapObjType == MapObjectType.Player)
  1497.                                             (_obj as Entity).Owner.Send(item);
  1498.                                 Map.RemoveFloorItem(item);
  1499.                             }
  1500.                             else
  1501.                                 item.SendSpawn(Owner, false);
  1502.                         }
  1503.                         else
  1504.                             item.SendSpawn(Owner, false);
  1505.                     }
  1506.                     else
  1507.                     {
  1508.                         if ((Time32.Now > item.OnFloor.AddSeconds(Constants.FloorItemSeconds)) || item.PickedUpAlready)
  1509.                         {
  1510.                             item.Type = Network.GamePackets.FloorItem.Remove;
  1511.                             Map.RemoveFloorItem(item);
  1512.                         }
  1513.                     }
  1514.                     item.SendSpawn(Owner);
  1515.                     if (item.ItemID == FloorItem.AuroraLotus)
  1516.                     {
  1517.                         if (item.OnFloor.AddSeconds(7).Next(time: Time32.Now.AllMilliseconds()))
  1518.                         {
  1519.                             item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1520.                             foreach (Interfaces.IMapObject _obj in Objects)
  1521.                                 if (_obj != null)
  1522.                                     if (_obj.MapObjType == MapObjectType.Player)
  1523.                                         (_obj as Entity).Owner.Send(item);
  1524.                             Map.RemoveFloorItem(item);
  1525.                             Attacking.Handle.AuroraLotus(item);
  1526.                         }
  1527.                         else
  1528.                             item.SendSpawn(Owner, false);
  1529.                     }
  1530.                     else if (item.ItemID == FloorItem.FlameLotus)
  1531.                     {
  1532.                         if (item.OnFloor.AddSeconds(7).Next(time: Time32.Now.AllMilliseconds()))
  1533.                         {
  1534.                             item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1535.                             foreach (Interfaces.IMapObject _obj in Objects)
  1536.                                 if (_obj != null)
  1537.                                     if (_obj.MapObjType == MapObjectType.Player)
  1538.                                         (_obj as Entity).Owner.Send(item);
  1539.                             Map.RemoveFloorItem(item);
  1540.                             Attacking.Handle.FlameLotus(item);
  1541.                         }
  1542.                         else
  1543.                             item.SendSpawn(Owner, false);
  1544.                     }
  1545.                     else if (item.ItemID == FloorItem.TwilightDance)
  1546.                     {
  1547.                         if (item.OnFloor.AddSeconds(1).Next(time: Time32.Now.AllMilliseconds()))
  1548.                         {
  1549.                             item.Type = Network.GamePackets.FloorItem.RemoveEffect;
  1550.                             foreach (Interfaces.IMapObject _obj in Objects)
  1551.                                 if (_obj != null)
  1552.                                     if (_obj.MapObjType == MapObjectType.Player)
  1553.                                         (_obj as Entity).Owner.Send(item);
  1554.                             Map.RemoveFloorItem(item);
  1555.                         }
  1556.                         else
  1557.                             item.SendSpawn(Owner, false);
  1558.                     }
  1559.                 }
  1560.                 #endregion
  1561.                 foreach (Game.Entity monster in Map.Entities.Values)
  1562.                 {
  1563.                     if (monster == null) continue;
  1564.                     if (Kernel.GetDistance(monster.X, monster.Y, Owner.Entity.X, Owner.Entity.Y) <= 16 && !Contains(monster.UID))
  1565.                     {
  1566.                         if (!monster.Dead)
  1567.                         {
  1568.                             monster.SendSpawn(Owner, false);
  1569.                             if (monster.MaxHitpoints > 65535)
  1570.                             {
  1571.                                 FlagsUpdate upd = new FlagsUpdate(true)
  1572.                                 {
  1573.                                     UID = monster.UID
  1574.                                 };
  1575.                                 upd.Append((byte)FlagsUpdate.DataType.Hitpoints, monster.Hitpoints);
  1576.                                 Owner.Send(upd);
  1577.                             }
  1578.                         }
  1579.                     }
  1580.                 }
  1581.                 #region RaceItems
  1582.                 if (Owner.Map.StaticEntities.Count != 0)
  1583.                 {
  1584.                     foreach (var item in Owner.Map.StaticEntities.Values)
  1585.                     {
  1586.                         if (item == null) continue;
  1587.                         if (!item.Viable) continue;
  1588.                         if (Kernel.GetDistance(item.X, item.Y, Owner.Entity.X, Owner.Entity.Y) > 16) continue;
  1589.                         if (Contains(item.UID)) continue;
  1590.                         item.SendSpawn(Owner);
  1591.                     }
  1592.                 }
  1593.                 #endregion
  1594.                 #region Flooritems
  1595.                 foreach (var f in Database.FloorItemTable.FloorItems)
  1596.                 {
  1597.                     if (f == null) continue;
  1598.                     if (Kernel.GetDistance(f.X, f.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.pScreenDistance)
  1599.                     {
  1600.                         if (f.MapID == Owner.Entity.MapID && !Owner.Entity.FloorItems.ContainsKey(f.UID))
  1601.                         {
  1602.                             Owner.Entity.FloorItems.Add(f.UID, f);
  1603.                             f.SendSpawn(Owner);
  1604.                         }
  1605.                     }
  1606.                     else
  1607.                     {
  1608.                         if (Owner.Entity.FloorItems.ContainsKey(f.UID))
  1609.                         {
  1610.                             Owner.Entity.FloorItems.Remove(f.UID);
  1611.                             Remove(f);
  1612.                         }
  1613.                     }
  1614.                     if (Owner.Entity.MapID != f.MapID && Owner.Entity.FloorItems.ContainsKey(f.UID))
  1615.                     {
  1616.                         Owner.Entity.FloorItems.Remove(f.UID);
  1617.                     }
  1618.                 }
  1619.                 #endregion
  1620.                 foreach (Game.Entity monster in Map.Companions.Values)
  1621.                 {
  1622.                     if (monster == null) continue;
  1623.                     if (Kernel.GetDistance(monster.X, monster.Y, Owner.Entity.X, Owner.Entity.Y) <= 18 && !Contains(monster.UID))
  1624.                     {
  1625.                         if (!monster.Dead)
  1626.                         {
  1627.                             monster.SendSpawn(Owner);
  1628.                         }
  1629.                     }
  1630.                 }
  1631.                 foreach (var bot in Game.BotShop.STATICSTALLS.Values)
  1632.                 {
  1633.                     if (bot > Owner)
  1634.                     {
  1635.                         BOTSTALL.TryAdd(bot.UID, bot);
  1636.                     }
  1637.                     else if (bot < Owner)
  1638.                     {
  1639.                         Game.BotShop outbot;
  1640.                         BOTSTALL.TryRemove(bot.UID, out outbot);
  1641.                     }
  1642.                 }
  1643.                 if (Owner.Map.ID == 8880 || Owner.Map.ID == 8881 || Owner.Map.ID == 1002)
  1644.                 {
  1645.                     foreach (Game.PokerTable T in Kernel.PokerTables.Values)
  1646.                     {
  1647.                         if (T.Map == Owner.Map.ID)
  1648.                         {
  1649.                             if (Kernel.GetDistance(T.X, T.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.nScreenDistance && !PokerTables.ContainsKey(T.Id))
  1650.                             {
  1651.                                 Owner.Send(Game.PokerPackets.PokerTable(T));
  1652.                                 PokerTables.Add(T.Id, T);
  1653.                             }
  1654.                         }
  1655.                     }
  1656.                 }      
  1657.                 if (Owner.Map.ID == Roulette.Database.Roulettes.RouletteTable.MapID)
  1658.                 {
  1659.                     foreach (var R in Roulette.Database.Roulettes.RoulettesPoll.Values)
  1660.                     {
  1661.                         if (Kernel.GetDistance(R.SpawnPacket.X, R.SpawnPacket.Y, Owner.Entity.X, Owner.Entity.Y) <= Constants.nScreenDistance && !PokerTables.ContainsKey(R.SpawnPacket.UID))
  1662.                         {
  1663.                             Owner.Send(R.SpawnPacket);
  1664.                         }
  1665.                     }
  1666.                 }
  1667.             }
  1668.             catch (Exception e)
  1669.             {
  1670.                 Server.SaveException(e);
  1671.             }
  1672.         }
  1673.         public void CleanUp(Interfaces.IPacket spawnWith)
  1674.         {
  1675.             bool remove;
  1676.             try
  1677.             {
  1678.                 foreach (IMapObject Base in Objects)
  1679.                 {
  1680.                     if (Base == null) continue;
  1681.                     remove = false;
  1682.                     if (Base.MapObjType == MapObjectType.Monster)
  1683.                     {
  1684.                         if ((Base as Entity).Dead)
  1685.                         {
  1686.                             if (Time32.Now > (Base as Entity).DeathStamp.AddSeconds(8))
  1687.                                 remove = true;
  1688.                             else remove = false;
  1689.                         }
  1690.                         if (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance)
  1691.                             remove = true;
  1692.                         if (remove)
  1693.                         {
  1694.                             if ((Base as Entity).MonsterInfo.InSight == Owner.Entity.UID)
  1695.                                 (Base as Entity).MonsterInfo.InSight = 0;
  1696.                         }
  1697.                     }
  1698.                     else if (Base.MapObjType == MapObjectType.Player)
  1699.                     {
  1700.                         if (remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.pScreenDistance))
  1701.                         {
  1702.                             GameState pPlayer = Base.Owner as GameState;
  1703.                             pPlayer.Screen.Remove(Owner.Entity);
  1704.                         }
  1705.                     }
  1706.                     else if (Base.MapObjType == MapObjectType.Item)
  1707.                     {
  1708.                         remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= 22);
  1709.                     }
  1710.                     else
  1711.                     {
  1712.                         remove = (Kernel.GetDistance(Owner.Entity.X, Owner.Entity.Y, Base.X, Base.Y) >= Constants.remScreenDistance);
  1713.                     }
  1714.                     if (Base.MapID != Owner.Map.ID)
  1715.                         remove = true;
  1716.                     if (remove)
  1717.                     {
  1718.                         Remove(Base);
  1719.                     }
  1720.                 }
  1721.             }
  1722.             catch (Exception e)
  1723.             {
  1724.                 Server.SaveException(e);
  1725.             }
  1726.         }
  1727.     }
  1728. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement