public HashSet <int> GetTeamIDs() { if (OwnerID == null) { return(new HashSet <int>()); } else { return(_playerLocator.GetPlayerAsync(OwnerID).Result.GetTeamIDs()); } }
/// <summary> /// Returns the ship's current player, or null if no player is assigned. /// </summary> /// <returns></returns> public Player GetPlayer() { if (_playerLocator == null) { throw new Exception("Error: Ship.GetPlayer() called on IShip with ID " + Id.ToString() + " but _playerLocator service reference is null."); } if (_model.PlayerID != null) { return(_playerLocator.GetPlayerAsync((int)_model.PlayerID).Result); } else { return(null); } }
public Dictionary <int, Player> GetOnlinePlayers() { lock (PLAYERLOCK) { try { Dictionary <int, Player> players; if (_isPlayerCacheReady) { players = new Dictionary <int, Player>(_onlinePlayerCache); } else { players = new Dictionary <int, Player>(_onlinePlayerIDs.Count); foreach (int?id in _onlinePlayerIDs) { Player p = _playerLocator.GetPlayerAsync(id).Result; if (p != null) { players.Add(p.Id, p); } } } return(players); } catch (Exception e) { ConsoleManager.WriteLine(e.Message); ConsoleManager.WriteLine(e.StackTrace); return(new Dictionary <int, Player>(_onlinePlayerCache)); } } }
public override StructureData GetNetworkData() { StructureData data = new StructureData(); data.XPos = PosX; data.YPos = PosY; data.CurrentHealth = CurrentHealth; data.Id = Id; data.StructureType = StructureType; data.OwnerTeamIDs = _playerLocator.GetPlayerAsync(OwnerID).Result.GetTeamIDs(); return(data); }
public IShip KillShip(IShip s, ICanFire killingObject) { if (s.IsDead) { ConsoleManager.WriteLine("Killing a ship which was already dead.", ConsoleMessageType.Warning); return(s); } s.IsDead = true; s.KillTimeStamp = TimeKeeper.MsSinceInitialization; s.RespawnTimeDelay = 3000;//TODO: This will be a problem later, if a IShip warps into a new system where a dead IShip is waiting to respawn, the warping IShip will see a live ship. Needs to be fully implemented. s.CurrentHealth = 0; if (s.GetPlayer().IsTrading) { _tradeTerminator.TerminateTrade(s.Id, true); } var currentArea = s.GetArea(); if (currentArea.NumOnlinePlayers > 0) { MessageRemoveKillRevive msgData = new MessageRemoveKillRevive(); msgData.ActionType = ActionType.Kill; msgData.ObjectType = RemovableObjectTypes.Ship; msgData.ObjectIDs.Add(s.Id); currentArea.BroadcastMessage(new NetworkMessageContainer(msgData, MessageTypes.RemoveKillRevive)); // Send chat messages if (killingObject is IShip) { ((IShip)killingObject).GetPlayer().PlayersKilled++; var killingPlayer = ((IShip)killingObject).GetPlayer(); killingPlayer.PlayersKilled++; var killText = string.Format("{0} was shot down by {1}!", s.GetPlayer().Username, killingPlayer.Username); _chatManager.BroadcastSimpleChat(s.GetArea(), "", killText, ChatTypes.None); } else if (killingObject is Turret) { _playerLocator.GetPlayerAsync(((Turret)killingObject).OwnerID).Result.PlayersKilled++; var killedPlayer = s.GetPlayer(); var defensesOwner = _playerLocator.GetPlayerAsync(((Turret)killingObject).OwnerID).Result.Username; var killText = string.Format("{0} was shot down by defenses of {1}!", killedPlayer.Username, defensesOwner); _chatManager.BroadcastSimpleChat(s.GetArea(), "", killText, ChatTypes.None); } } #region Modules //For now, just make the ship drop one mod to space. Later we'll figure out how many to destroy/keep with the ship var moduleToRemove = s.Cargo.GetAnyStatefulCargo(StatefulCargoTypes.Module); if (moduleToRemove != null) { var ct = new TransactionRemoveStatefulCargo(s, StatefulCargoTypes.Module, moduleToRemove.Id); ct.OnCompletion += s.CargoRemoved; ct.OnCompletion += _messageManager.NotifyCargoRemoved; ct.OnCompletion += _addCargoToArea; var mod = moduleToRemove as Module; mod.PosX = s.PosX; mod.PosY = s.PosY; mod.Rotation = s.Rotation; mod.NextAreaID = (int)s.CurrentAreaId; _cargoSynchronizer.RequestTransaction(ct); } #endregion s.CurrentHealth = s.ShipStats.MaxHealth; //s.IsDead = false; float tempx = 0; float tempy = 0; SpatialOperations.GetRandomPointInRadius(ref tempx, ref tempy, 10, 20); s.PosX = tempx; s.PosY = tempy; return(s); }
public void _handleGameStateJoinRequest() { //Recieved request to allow a player on another server to join var shipProps = _shipFactory.CreateShip(GetDefaultShipProperties(5, 5, _model.SpawnSystemId), _playerLocator.GetPlayerAsync(j) }
/// <summary> /// Dissolves the team with the given team number /// I kind of half assed this function, needs testing /// </summary> /// <param name="teamNumber"></param> /// <returns></returns> public void dissolveTeam(Team team) { var areas = new HashSet <IArea>(); //Keeps track of all areas which need to recieve notification HashSet <int> playerIDs = team.PlayerIDs; HashSet <int> nonlocalPlayerIDs = new HashSet <int>(); foreach (int i in team.PlayerIDs) { Player p = _playerLocator.GetPlayerAsync(i).Result; if (p == null) { nonlocalPlayerIDs.Add(i); } else { p.RemoveTeam(team.Id); areas.Add(p.GetArea()); } } if (nonlocalPlayerIDs.Count != 0) { NetworkMessageContainer msgc = new NetworkMessageContainer(); msgc.MessageData = new PlayerRemoveTeam(nonlocalPlayerIDs, team.Id); _redisServer.PublishObject(MessageTypes.Redis_PlayerRemoveTeam, msgc); } //Send removeships message to areas in which this team exists foreach (var a in areas) { if (a.NumOnlinePlayers == 0) { continue; } var data = new MessageAddRemoveShipsTeam(); data.AddOrRemove = false; data.TeamID = team.Id; foreach (var s in a.GetShips()) { if (team.PlayerIDs.Contains(s.Value.Id)) { data.IDs.Add(s.Value.Id); } } a.BroadcastMessage(new NetworkMessageContainer(data, MessageTypes.AddRemoveShipsTeam)); } _databaseManager.DeleteTeam(team.Id); _teamIDSupplier.PushFreeID(team.Id); }