Example #1
0
 public static TeamOperation AssignToNewTeam(string newTeamName, Spectator existingSpectator)
 {
     return new TeamOperation
     {
         Type = ChoiceType.AssignToNewTeam,
         NewTeamName = newTeamName,
         ExistingSpectator = existingSpectator,
     };
 }
Example #2
0
 public override object GetStatsObject(Spectator spectator)
 {
     return new
     {
         Name = spectator.Name,
         LoginToken = spectator.GetStats().LoginToken,
         Connected = !spectator.IsDisconnected,
     };
 }
Example #3
0
 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);
     });
 }
Example #5
0
 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);
 }
Example #6
0
 public override string GetStatsString(Spectator spectator)
 {
     return spectator.GetStats().LoginToken;
 }
Example #7
0
 /// <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");
 }
Example #9
0
 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");
 }
Example #10
0
 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 });
 }
Example #11
0
 public virtual string GetStatsString(Spectator spectator)
 {
     return null;
 }
Example #12
0
 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 });
 }
Example #13
0
 public virtual object GetStatsObject(Spectator spectator)
 {
     return null;
 }
Example #14
0
 /// <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));
 }
Example #15
0
 public int RateLocally(Spectator spectator, IEnumerable<Spectator> allSpectators)
 {
     return new LocalRatingContext(CalculateScore, allSpectators).Rate(spectator);
 }
Example #16
0
 /// <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);
 }
Example #17
0
 /// <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);
 }
Example #18
0
 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 });
 }
Example #19
0
 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);
     });
 }
Example #20
0
 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);
 }
Example #21
0
 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);
     }
 }
Example #23
0
 public SpectatorStats(Spectator spectator)
 {
     Spectator = spectator;
     LoginToken = "";
 }
Example #24
0
 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;
 }
Example #26
0
 /// <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;
 }
Example #27
0
 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);
 }
Example #28
0
 /// <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;
 }
Example #29
0
 public static TeamOperation Remove(Spectator spectator)
 {
     return new TeamOperation
     {
         Type = ChoiceType.Remove,
         ExistingSpectator = spectator,
     };
 }