/// <summary> /// Fills a message for the players already in a game to indicate that a new player joined the game. /// </summary> static void FillNewRemotePlayerMessage(NetBuffer msg, ServerClient client) { FillChampionInfo(msg, client.Champion, client.ChampStats); }
/// <summary> /// Creates a message indicating that he has joined the game and that /// the client should create a new drawable champion associated to it. /// </summary> static void FillJoinedGameMessage(NetBuffer msg, ServerClient champion, List<ServerClient> remoteChampions) { double time = Server.Instance.GetTime().TotalSeconds; remoteChampions.Insert(0, champion); // add our champion to the beginning // and send all the champions together foreach (ServerClient champ in remoteChampions) { FillChampionInfo(msg, champ.Champion, champ.ChampStats); } }
void UpdateChampionHealth(ServerClient client) { // check to respawn after being dead for long enough if (!client.ChampStats.Alive && client.ChampStats.ShouldRespawn()) { Respawn(client); } if (client.ChampStats.GetHealthChangedAndClearFlag()) { AddRemarkableEvent(ServerCommand.StatsChanged, (msg) => { msg.Write(client.Champion.ID); msg.Write(client.ChampStats.Health); }); if (!client.ChampStats.Alive) // the player died! { client.ChampStats.RevivalTime = Server.Instance.GetTime().TotalSeconds + GetRespawnTime().TotalSeconds; uint kills = 0; ++client.ChampStats.Deaths; if (client.ChampStats.Killer.HasValue) { ServerClient killer = null; foreach (ServerClient c in Clients.Values) { if (c.Champion.ID == client.ChampStats.Killer.Value) { killer = c; } } if (killer != null) { ++killer.ChampStats.Kills; if (killer.Champion.Team == Teams.Left) { ++LeftKills; } else if (killer.Champion.Team == Teams.Right) { ++RightKills; } kills = killer.ChampStats.Kills; } } AddRemarkableEvent(ServerCommand.ChampionDied, (msg) => { msg.Write(client.Champion.ID); msg.Write(client.ChampStats.Killer ?? IDGenerator.NO_ID); msg.Write(kills); msg.Write(client.ChampStats.Deaths); msg.Write(LeftKills); msg.Write(RightKills); msg.Write((ushort)GetRespawnTime().TotalSeconds); }); } } }
/// <summary> /// Adds the client to the current game. /// </summary> public void AddClient(NetConnection connection, ChampionTypes champ) { ILogger.Log("New player added to the game.", LogPriority.High); ServerChampion champion = CreateChampion(champ); ServerClient client = new ServerClient(connection, champion); // Send to the client that asked to join, along with the info of the current players List<ServerClient> remoteClients = new List<ServerClient>(); foreach (ServerClient remote in Clients.Values) { remoteClients.Add(remote); } SendCommand(connection, ServerCommand.JoinedGame, NetDeliveryMethod.ReliableUnordered, (msg) => FillJoinedGameMessage(msg, client, remoteClients)); // Send the new player event to other players foreach (NetConnection clientConn in Clients.Keys) { if (clientConn != connection) { SendCommand(clientConn, ServerCommand.NewRemotePlayer, NetDeliveryMethod.ReliableUnordered, (msg) => FillNewRemotePlayerMessage(msg, client)); } } // Apply the changes to our game state Clients.Add(connection, client); Match.CurrentState.AddEntity(champion); }
void Respawn(ServerClient client) { client.ChampStats.SetHealth(client.ChampStats.MaxHealth); // heal back to max health client.Champion.Position = GetSpawnPosition(client.Champion.Team); client.ChampStats.RevivalTime = double.MaxValue; client.Champion.FacingLeft = client.Champion.Team == Teams.Right; // face the opposite team }
void UpdateChampionHealth(ServerClient client) { // check to respawn after being dead for long enough if (!client.ChampStats.Alive && client.ChampStats.ShouldRespawn()) { Respawn(client); } if (client.ChampStats.GetHealthChangedAndClearFlag()) { AddRemarkableEvent(ServerCommand.StatsChanged, (msg) => { msg.Write(client.Champion.ID); msg.Write(client.ChampStats.Health); }); if (!client.ChampStats.Alive) { // the player died! client.ChampStats.RevivalTime = Server.Instance.GetTime().TotalSeconds + GetRespawnTime().TotalSeconds; uint kills = 0; ++client.ChampStats.Deaths; if (client.ChampStats.Killer.HasValue) { ServerClient killer = null; foreach (ServerClient c in Clients.Values) { if (c.Champion.ID == client.ChampStats.Killer.Value) { killer = c; } } if (killer != null) { ++killer.ChampStats.Kills; if (killer.Champion.Team == Teams.Left) ++LeftKills; else if (killer.Champion.Team == Teams.Right) ++RightKills; kills = killer.ChampStats.Kills; } } AddRemarkableEvent(ServerCommand.ChampionDied, (msg) => { msg.Write(client.Champion.ID); msg.Write(client.ChampStats.Killer ?? IDGenerator.NO_ID); msg.Write(kills); msg.Write(client.ChampStats.Deaths); msg.Write(LeftKills); msg.Write(RightKills); msg.Write((ushort)GetRespawnTime().TotalSeconds); }); } } }
void HandleAction(ServerClient client, PlayerAction action) { if (ActionTypeHelper.IsSpell(action.Type)) { var spell = ChampionTypesHelper.GetSpellFromAction(client.Champion.Type, action.Type); if (client.ChampStats.Alive && !client.ChampStats.IsOnCooldown(spell)) { // we're not dead and the spell is not on cooldown CastChampionSpell(client.Champion, action); client.ChampStats.UsedSpell(spell); } } else if (action.Type != PlayerActionType.Idle) { ILogger.Log("Unknown player action type: " + action.Type); } }