Advertisement
Guest User

سيسي

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