/// <summary>
    /// Ties to add a player a given new team. However the player might not join it
    /// </summary>
    /// <param name="p">The ntwork player who wants to join/change a team</param>
    /// <param name="newTeam">The team the players want to join/change to</param>
    /// <returns>The team the player is now part of, might be the same as before if we could not switch</returns>
    public ETeams TryToAddPlayerToTeam(NetworkPlayer p, ETeams newTeam)
    {
        //Can we even sitch (aks is team we are trying to join full)
        if (CanSwitchToTeam(newTeam))
        {
            //Remove the player form the team, we are doing it in both list just in case its in two at the same time
            m_crazyPeopleTeam.Remove(p);
            m_fireFigthersTeam.Remove(p);
            //Join the apropiate team
            switch (newTeam)
            {
            case ETeams.CrazyPeople:
                m_crazyPeopleTeam.Add(p);
                break;

            case ETeams.FireFighters:
                m_fireFigthersTeam.Add(p);
                break;
            }
            //Invoke that a team changed
            if (TeamsChanged != null)
            {
                TeamsChanged.Invoke();
            }
            //Return the team it joined
            return(newTeam);
        }
        else
        {
            //Just return the team it already is part of
            return(p.Player_Team);
        }
    }
 /// <summary>
 /// Checks if a player can switch to a different team
 /// </summary>
 /// <param name="newTeam">The new team the players want to join</param>
 /// <returns>bool - If possible or not to switch</returns>
 public bool CanSwitchToTeam(ETeams newTeam)
 {
     if (newTeam == ETeams.CrazyPeople)
     {
         return(CrazyTeamSize < 4);
     }
     return(FirefightersTeamSize < 2);
 }
 public async Task <IHttpActionResult> GetByTeam(int matchId, ETeams teamId)
 {
     return(await TryCatchAsync(async() =>
     {
         var players = await _playersServices.GetAllByTeam(matchId, teamId);
         return Ok(players);
     }));
 }
    /// <summary>
    /// Sets the team list of players to the given list of players. It will ovewrite the current team list
    /// </summary>
    /// <param name="playersIDs">The list of players is</param>
    /// <param name="team">The team this players are part of</param>
    public void SetTeamFromIds(int[] playersIDs, ETeams team)
    {
        //Based on the team we do different things
        switch (team)
        {
        case ETeams.CrazyPeople:
        {
            //Clear the player list
            m_crazyPeopleTeam.Clear();
            //Convert the array to list, this is to use functions like contains instead of nesting for loops myself
            List <int> playersIDsList = new List <int>();
            playersIDsList.AddRange(playersIDs);
            //Find the NetworkPlayer object with the given ids and add them to the team list
            foreach (NetworkPlayer p in MainNetworkManager._instance.PlayersConnected)
            {
                if (playersIDsList.Contains(p.Player_ID))
                {
                    m_crazyPeopleTeam.Add(p);
                }
            }
        }
        break;

        case ETeams.FireFighters:
        {
            //Clear the player list
            m_fireFigthersTeam.Clear();
            //Convert the array to list, this is to use functions like contains instead of nesting for loops myself
            List <int> playersIDsList = new List <int>();
            playersIDsList.AddRange(playersIDs);
            //Find the NetworkPlayer object with the given ids and add them to the team list
            foreach (NetworkPlayer p in MainNetworkManager._instance.PlayersConnected)
            {
                if (playersIDsList.Contains(p.Player_ID))
                {
                    m_fireFigthersTeam.Add(p);
                }
            }
        }
        break;
        }
        //Invoke that a team changed
        if (TeamsChanged != null)
        {
            TeamsChanged.Invoke();
        }
    }
    public void CmdSwitchTeam()
    {
        //Update the team of the player if possible
        switch (m_team)
        {
        case ETeams.CrazyPeople:
            m_team = MatchSettings._instance.TryToAddPlayerToTeam(this, ETeams.FireFighters);
            break;

        case ETeams.FireFighters:
            m_team = MatchSettings._instance.TryToAddPlayerToTeam(this, ETeams.CrazyPeople);
            break;
        }
        //Send the new data to all clients
        RpcTaemSizesUpdate(MatchSettings._instance.GetTeamMembersId(ETeams.CrazyPeople), MatchSettings._instance.GetTeamMembersId(ETeams.FireFighters));
        //Reset ready status for everyone
        MainNetworkManager._instance.ClearAllPlayersReadyStatus();
    }
    private void CmdSetUpPlayer(string name)
    {
        //Get the name from all the other players
        List <string> usedNames = new List <string>();

        foreach (NetworkPlayer p in MainNetworkManager._instance.PlayersConnected)
        {
            if (p != this)
            {
                usedNames.Add(p.Player_Name);
            }
        }
        //Generate new names until we got a unique one
        while (usedNames.Contains(name))
        {
            name = RandomNameGenerator.GetRanomName();
        }
        //Set all the data and initialize it
        m_Name        = name;
        m_team        = MatchSettings._instance.TryToAddPlayerToTeam(this, MatchSettings._instance.GetNewPlayerStartingTeam());
        m_Initialized = true;
    }
 /// <summary>
 /// Gets a list of all players id from a team
 /// </summary>
 /// <param name="team">The team we want to get the ids from</param>
 /// <returns>Arrays of ints (int[]) with all the players id</returns>
 public int[] GetTeamMembersId(ETeams team)
 {
     //Check for wicht team we want the data to be returned
     if (team == ETeams.CrazyPeople)
     {
         //Create the array based on the size of the team
         int[] returnValue = new int[CrazyTeamSize];
         //Get the ids
         for (int i = 0; i < CrazyTeamSize; i++)
         {
             returnValue[i] = m_crazyPeopleTeam[i].Player_ID;
         }
         return(returnValue);
     }
     //Create the array based on the size of the team
     int[] firefightersIDS = new int[FirefightersTeamSize];
     //Get the ids
     for (int i = 0; i < FirefightersTeamSize; i++)
     {
         firefightersIDS[i] = m_fireFigthersTeam[i].Player_ID;
     }
     return(firefightersIDS);
 }
 private void OnTeamChanged(ETeams newTeam)
 {
     m_team = newTeam;
     OnNetworkPlayerDataUpdated();
 }
Beispiel #9
0
        public async Task <IEnumerable <PlayerOutputDto> > GetAllByTeam(int matchId, ETeams teamId)
        {
            var players = await _playersRepository.GetAllAsync(w => w.MatchId == matchId && w.TeamId == teamId);

            return(MappingConfig.Mapper().Map <List <PlayerOutputDto> >(players));
        }