public static TeamOperation AssignToNewTeam(string newTeamName, Spectator existingSpectator) { return new TeamOperation { Type = ChoiceType.AssignToNewTeam, NewTeamName = newTeamName, ExistingSpectator = existingSpectator, }; }
public override object GetStatsObject(Spectator spectator) { return new { Name = spectator.Name, LoginToken = spectator.GetStats().LoginToken, Connected = !spectator.IsDisconnected, }; }
public static TeamOperation AssignToExistingTeam(Team existingTeam, Spectator existingSpectator) { return new TeamOperation { Type = ChoiceType.AssignToExistingTeam, ExistingTeam = existingTeam, ExistingSpectator = existingSpectator, }; }
private static void CreateDeathMessage(Spectator perpetrator, Vector2 Pos, string iconName) { Gob.CreateGob<ArenaMessage>(perpetrator.Game, (CanonicalString)"deathmessage", gob => { gob.ResetPos(Pos, Vector2.Zero, Gob.DEFAULT_ROTATION); gob.Message = perpetrator.Name; gob.IconName = iconName; gob.DrawColor = perpetrator.Color; perpetrator.Game.DataEngine.Arena.Gobs.Add(gob); }); }
public void UpdatePilotRanking(Spectator spectator) { if (spectator.GetStats().PilotId == null) return; var requestPath = string.Format("pilot/id/{0}/rankings", spectator.GetStats().PilotId); RequestFromStats(response => PilotDataRequestDone(response, spectator, "pilot ranking"), requestPath); }
public override string GetStatsString(Spectator spectator) { return spectator.GetStats().LoginToken; }
/// <summary> /// Steals minion ownership from the old spectator. Use this method on a game client /// when the spectator has reconnected. /// </summary> public virtual void ReconnectOnClient(Spectator oldSpectator) { }
private static void CreateTeamKillMessage(Spectator perpetrator, Vector2 pos) { CreateDeathMessage(perpetrator, pos, "b_icon_take_life"); }
public void RefuseRemoteSpectatorOnServer(Spectator newSpectator, Spectator oldSpectator) { var ipAddress = NetworkEngine.GetConnection(newSpectator.ConnectionID).RemoteTCPEndPoint.Address; Log.Write("Refusing spectator {0} from {1} because he's already logged in from {2}.", newSpectator.Name, ipAddress, (object)oldSpectator.IPAddress ?? "the local host"); }
private void SpectatorRemovedHandler(Spectator spectator) { if (NetworkMode != NetworkMode.Server) return; Stats.Send(new { RemovePlayer = spectator.GetStats().LoginToken, Name = spectator.Name }); UpdateGameServerInfoToManagementServer(); NetworkEngine.SendToGameClients(new SpectatorOrTeamDeletionMessage { SpectatorOrTeamID = spectator.ID }); }
public virtual string GetStatsString(Spectator spectator) { return null; }
public void AddRemoteSpectator(Spectator newSpectator) { Log.Write("Adding spectator {0}", newSpectator.Name); DataEngine.Spectators.Add(newSpectator); Stats.Send(new { AddPlayer = newSpectator.GetStats().LoginToken, Name = newSpectator.Name }); }
public virtual object GetStatsObject(Spectator spectator) { return null; }
/// <summary> /// Rates a spectator on a scale from <see cref="LocalRatingMin"/> to <see cref="LocalRatingMax"/>. /// The rating is based on the relative success of the spectator against others in the latest arena. /// </summary> public int Rate(Spectator spectator) { if (spectator.LatestArenaStatistics.IsEmpty || MinScore == MaxScore) return (int)Math.Round((LocalRatingMin + LocalRatingMax) / 2f); var relativeScore = (GetScore(spectator.LatestArenaStatistics) - MinScore) / (float)(MaxScore - MinScore); var localRating = ((relativeScore - 0.5f) * DampingFactor + 0.5f) * (LocalRatingMax - LocalRatingMin) + LocalRatingMin; return (int)Math.Round(MathHelper.Clamp(localRating, LocalRatingMin, LocalRatingMax)); }
public int RateLocally(Spectator spectator, IEnumerable<Spectator> allSpectators) { return new LocalRatingContext(CalculateScore, allSpectators).Rate(spectator); }
/// <summary> /// Chooses the team for a spectator. The team may be one of the given ones or a new one. /// </summary> public TeamOperation ChooseTeam(Spectator spectator, IEnumerable<Team> allTeams) { if (allTeams.Count() < 2) return TeamOperation.AssignToNewTeam(GetFreeTeamNames(allTeams).First(), spectator); var ratingContext = GetRatingContext(allTeams); return TeamOperation.AssignToExistingTeam(allTeams.OrderBy(ratingContext.Rate).First(), spectator); }
/// <summary> /// Updates <see cref="Members"/> according to <see cref="Spectator.Team"/>. /// To be called by the spectator itself after changing its team. /// </summary> public void UpdateAssignment(Spectator spectator) { var isMember = Members.Contains(spectator); if (spectator.Team == this && !isMember) _members.Add(spectator); else if (spectator.Team != this && isMember) _members.Remove(spectator); }
public void ReconnectRemoteSpectatorOnServer(Spectator newSpectator, Spectator oldSpectator) { Log.Write("Reconnecting spectator {0}", oldSpectator.Name); oldSpectator.ReconnectOnServer(newSpectator); Stats.Send(new { AddPlayer = oldSpectator.GetStats().LoginToken, Name = oldSpectator.Name }); }
private void PilotDataRequestDone(IAsyncResult result, Spectator spectator, string requestName) { RequestDone(result, requestName, responseString => { var response = JObject.Parse(responseString); if (response["error"] != null) Log.Write("Error in {0} query: {1}", requestName, response["error"]); spectator.GetStats().Update(response); }); }
private void SpectatorAddedHandler(Spectator spectator) { if (NetworkMode == NetworkMode.Server) UpdateGameServerInfoToManagementServer(); spectator.ArenaStatistics.Rating = () => spectator.GetStats().Rating; spectator.ResetForArena(); if (NetworkMode != NetworkMode.Server || spectator.IsLocal) return; var player = spectator as Player; if (player == null) return; player.IsAllowedToCreateShip = () => { if (!player.IsRemote) return false; var arenaID = NetworkEngine.GetGameClientConnection(player.ConnectionID).ConnectionStatus.IsRequestingSpawnForArenaID; if (!arenaID.HasValue || DataEngine.Arena == null) return false; return arenaID.Value == DataEngine.Arena.ID; }; player.Messages.NewChatMessage += mess => SendPlayerMessageToRemoteSpectator(mess, player); player.Messages.NewCombatLogMessage += mess => SendPlayerMessageToRemoteSpectator(mess, player); }
public void UpdatePilotData(Spectator spectator, string loginToken) { var requestPath = string.Format("pilot/token/{0}", loginToken); RequestFromStats(response => PilotDataRequestDone(response, spectator, "pilot data"), requestPath); }
public void WriteID(Spectator spectator) { checked { var id = spectator == null ? Spectator.UNINITIALIZED_ID : spectator.ID; Write((sbyte)id); } }
public SpectatorStats(Spectator spectator) { Spectator = spectator; LoginToken = ""; }
private static void CreateKillMessage(Spectator perpetrator, Vector2 pos) { CreateDeathMessage(perpetrator, pos, "b_icon_add_kill"); }
public static SubclassType GetSubclassType(Spectator spectator) { return spectator is Player ? SubclassType.Player : spectator is BotPlayer ? SubclassType.BotPlayer : SubclassType.Spectator; }
/// <summary> /// Returns true if the spectator is a friend, i.e. on the same side as this spectator. /// The friend relation is symmetric. /// </summary> public bool IsFriend(Spectator other) { return other != null && Team != null && other.Team == Team; }
public override void ReconnectOnClient(Spectator oldSpectator) { var oldPlayer = oldSpectator as Player; if (oldPlayer == null || oldPlayer.Ship == null) return; oldPlayer.Ship.Death -= oldPlayer.ShipDeathHandler; oldPlayer.Ship.Death -= MinionDeathHandler.OnMinionDeath; SeizeShip(oldPlayer.Ship); }
/// <summary> /// Copies connection information from a new instance. Use this method on a game server /// when a spectator on a game client reconnects. /// </summary> public void ReconnectOnServer(Spectator newSpectator) { ConnectionID = newSpectator.ConnectionID; ConnectionStatus = ConnectionStatusType.Remote; StatsData = newSpectator.StatsData; }
public static TeamOperation Remove(Spectator spectator) { return new TeamOperation { Type = ChoiceType.Remove, ExistingSpectator = spectator, }; }