Exemple #1
0
        /// <summary>
        ///     For the specified player, check the single objects and spawn or destroy
        ///     any objects in range of the player.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="obj"></param>
        public void CheckIfShouldCreateDestroyObject(Player.Player player, SimObject obj)
        {
            // Ignore the player's own ship or an uninitialised ship
            if (player.Ship.Objid == obj.Objid || player.Ship.Objid == 0)
            {
                return;
            }

            if (obj is Object.Solar.Solar)
            {
                return;
            }

            var shouldMonitor = true;

            if (obj is Ship.Ship && (obj as Ship.Ship).Basedata != null)
            {
                shouldMonitor = false;
            }
            else if (player.Ship.Basedata != null)
            {
                shouldMonitor = false;
            }
            // TODO: use bucket?
            else if (!player.Ship.ScanBucket.Contains(obj))
            {
                shouldMonitor = false;
            }

            if (shouldMonitor)
            {
                if (player.MonitoredObjs.ContainsKey(obj.Objid))
                {
                    return;
                }

                player.MonitoredObjs[obj.Objid] = obj;
                if (obj is Ship.Ship)
                {
                    player.SendMsgToClient(BuildCreateShip(obj as Ship.Ship));
                    player.SendSetReputation(obj as Ship.Ship);
                }
                else if (obj is Missile)
                {
                    player.SendMsgToClient(BuildCreateMissile(obj as Missile));
                }
                else if (obj is CounterMeasure)
                {
                    player.SendMsgToClient(BuildCreateCounterMeasure(obj as CounterMeasure));
                }
                else if (obj is Loot)
                {
                    player.SendCreateLoot(player.Ship, obj as Loot);
                }
            }
            else
            {
                if (!player.MonitoredObjs.ContainsKey(obj.Objid))
                {
                    return;
                }
                player.MonitoredObjs.Remove(obj.Objid);
                player.SendMsgToClient(BuildDestroyObj(obj, true));
            }
        }