Example #1
0
 /// <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);
 }
Example #2
0
		/// <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);
			}
		}
Example #3
0
        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);
                    });
                }
            }
        }
Example #4
0
		/// <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);
		}
Example #5
0
		/// <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);
		}
Example #6
0
		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
		}
Example #7
0
		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);
					});
				}
			}
		}
Example #8
0
		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);
			}
		}