/// <summary> /// A player/NPC has docked or left the server. Update and remove the /// ship from any players monitoring it and remove it from the object list. /// </summary> public void DelSimObject(SimObject obj) { foreach (var player in Players.Values) { if (!player.MonitoredObjs.ContainsKey(obj.Objid)) { continue; } player.MonitoredObjs.Remove(obj.Objid); player.SendMsg(Packets.DestroyObj(obj.Objid, true)); } obj.System.AffObjects.Remove(obj.Objid); obj.System.Objects.Remove(obj.Objid); obj.Objid = 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 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; } 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) { 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.SendMsg(Packets.CreateLoot(player.Ship, obj as Loot)); } } else { if (!player.MonitoredObjs.ContainsKey(obj.Objid)) { return; } player.MonitoredObjs.Remove(obj.Objid); player.SendMsg(Packets.DestroyObj(obj.Objid, true)); } }