예제 #1
0
    /////////////////////////////////////////////////////////////////////////////
    /// Function:               SpawnPowerUp
    /////////////////////////////////////////////////////////////////////////////
    public static void SpawnPowerUp(CPowerUp.EItemType eType)
    {
        foreach (GameObject goObject in m_liSpawnPoints)
        {
            CSpawner cSpawner = goObject.GetComponent <CSpawner>();

            if (cSpawner.SpawnerType != ESpawnerType.TYPE_POWERUPS)
            {
                continue;
            }

            if (cSpawner.Team == IAIBase.ETeam.TEAM_NONE && true == cSpawner.CanSpawn)
            {
                List <GameObject> liPowerUps = ItemsResource.Items;
                foreach (GameObject goPowerUp in liPowerUps)
                {
                    CPowerUp cPowerUp = goPowerUp.GetComponent <CPowerUp>();
                    if (cPowerUp.ItemType == eType)
                    {
                        cSpawner.Spawn(goPowerUp);
                    }
                }
            }
        }
    }
예제 #2
0
    /////////////////////////////////////////////////////////////////////////////
    /// Function:               Die
    /////////////////////////////////////////////////////////////////////////////
    protected void Die(bool bInstantiateFlag = true)
    {
        string strFunction = "IAIBase::Die()";

        switch (m_eTeam)
        {
        case ETeam.TEAM_BLUE:

            m_liActiveBlues.Remove(gameObject);

            break;

        case ETeam.TEAM_RED:

            m_liActiveReds.Remove(gameObject);

            break;

        default:

            // Unassigned NPC detected, report the issue.
            Debug.LogError(string.Format("{0} {1}: {2}", strFunction, ErrorStrings.ERROR_UNASSIGNED_NPC, transform.position));

            return;
        }

        // We need to drop the flag if we're holding it.
        if (true == m_bHasFlag && true == bInstantiateFlag)
        {
            GameObject goFlag = (GameObject)Network.Instantiate(m_goFlagPrefab, transform.position, Quaternion.identity, 0);
            goFlag.name    = Names.NAME_FLAG;
            m_goFlagHolder = null;
        }

        // We only want to send the death message to the server if the attacker object has been defined.
        //  The Die function is called on several occasions, one of them being when the drone has lost
        //  its path and doesn't know how to go back, this means that the attacker may be undefined.
        if (null != m_Attacker)
        {
            // Inform the server who killed this AI character.
            ServerManager cServer = RoleManager.roleManager as ServerManager;
            cServer.SendGameMessage(new MsgPlayerDied()
            {
                PlayerName = gameObject.name,
                KillerName = m_Attacker.AttackerName,
                PlayerTeam = m_eTeam,
                KillerTeam = m_Attacker.Team
            });
        }

        if (gameObject)
        {
            Network.Instantiate(m_goExplosionParticles, transform.position, Quaternion.identity, 0);
            Network.Destroy(gameObject);
        }

        CSpawner.SpawnNPC(m_eTeam, m_eNPCType);
    }
예제 #3
0
    /////////////////////////////////////////////////////////////////////////////
    /// Function:               CollidedWithBase
    /////////////////////////////////////////////////////////////////////////////
    protected void CollidedWithBase()
    {
        m_fHealth += 0.5f;

        if (true == m_bHasFlag)
        {
            // Inform the server that we delivered the flag to the base.
            ServerManager cServer = RoleManager.roleManager as ServerManager;
            cServer.SendGameMessage(new MsgFlagDelivered()
            {
                PlayerName = gameObject.name, PlayerTeam = m_eTeam
            });

            Die(false);
            CSpawner.SpawnFlag();
        }
    }
예제 #4
0
    /////////////////////////////////////////////////////////////////////////////
    /// Function:               SpawnNPC
    /////////////////////////////////////////////////////////////////////////////
    public static void SpawnNPC(IAIBase.ETeam eTeam, IAIBase.ENPCType eType)
    {
        foreach (GameObject goObject in m_liSpawnPoints)
        {
            CSpawner cSpawner = goObject.GetComponent <CSpawner>();

            if (cSpawner.SpawnerType != ESpawnerType.TYPE_NPC)
            {
                continue;
            }

            if (cSpawner.Team == eTeam && true == cSpawner.CanSpawn)
            {
                cSpawner.Spawn(NPCResource.GetObjectByType(eTeam, eType));
                break;
            }
        }
    }
예제 #5
0
    /////////////////////////////////////////////////////////////////////////////
    /// Function:               SpawnFlag
    /////////////////////////////////////////////////////////////////////////////
    public static void SpawnFlag()
    {
        List <GameObject> liSpawnLocations = new List <GameObject>();

        foreach (GameObject goObject in m_liSpawnPoints)
        {
            CSpawner cSpawner = goObject.GetComponent <CSpawner>();

            if (cSpawner.SpawnerType != ESpawnerType.TYPE_FLAG)
            {
                continue;
            }

            liSpawnLocations.Add(goObject);
        }

        CSpawner cSpawn = liSpawnLocations[Random.Range(0, liSpawnLocations.Count - 1)].GetComponent <CSpawner>();

        cSpawn.Spawn(m_goFlagPrefab);
    }
        public void GamePlayStarted()
        {
            networkView.RPC("RPCGamePlayStarted", RPCMode.Others);
            // Spawn the flag.
            CSpawner.SpawnFlag();

            // Get the number of required red AI characters.
            int iNumberOfRequiredNPCs = Constants.GAME_MAX_PLAYERS_PER_TEAM - RedTeam.TeamDisplayNames.Length;

            for (int i = 0; i < iNumberOfRequiredNPCs; ++i)
            {
                CSpawner.SpawnNPC(IAIBase.ETeam.TEAM_RED, IAIBase.ENPCType.TYPE_DRONE);
            }

            // Get the number of required blue AI characters.
            iNumberOfRequiredNPCs = Constants.GAME_MAX_PLAYERS_PER_TEAM - BlueTeam.TeamDisplayNames.Length;
            for (int i = 0; i < iNumberOfRequiredNPCs; ++i)
            {
                CSpawner.SpawnNPC(IAIBase.ETeam.TEAM_BLUE, IAIBase.ENPCType.TYPE_DRONE);
            }
        }
예제 #7
0
        private void CollidedWithBase(ClientDataOnServer client)
        {
            if (Network.isServer)
            {
                ServerManager cServer = RoleManager.roleManager as ServerManager;

                if (HasFlag == true)
                {
                    // Inform the server that we delivered the flag to the base.
                    cServer.SendGameMessage(new MsgFlagDelivered()
                    {
                        PlayerName = client.Profile.DisplayName, PlayerTeam = client.ClientTeam
                    });
                    HasFlag = false;
                    CSpawner.SpawnFlag();
                }

                cServer.SendGameMessage(new PlayerHealed()
                {
                    Heal = 1
                });
            }
        }
        public override void OnGameMessage(GameMessage message)
        {
            // Please not that the messages have been segmented intentionally as both
            //  clients and AI characters are sending messages and the serverManager
            //  does not differentiate between messages sent by AI or clients.
            //
            //  For example, score should always be updated when an AI character has scored
            //  a point, but as the AI has no ClientDataOnServer object there's no point
            //  in updating client stats.
            //
            //  Additionally, sometimes we may not want to forward certain messages to the clients,
            //  therefore message forwarding is a separate RPC.
            MatchExpired expired = message as MatchExpired;

            if (expired != null)
            {
                if (serverManager.OnMatchEnded != null)
                {
                    serverManager.OnMatchEnded();
                }
                serverManager.ChangeState(serverManager.ServerGameEndState, new MsgScoreUpdate()
                {
                    RedScore = m_iRedScore, BlueScore = m_iBlueScore
                });
                return;
            }

            //MsgDamageClient msgDamageClient = message as MsgDamageClient;
            //if ( null != msgDamageClient )
            //{
            //    // A client has been hit, we want to damage the client which the
            //    //  message specifies.
            //    foreach ( ClientDataOnServer clientData in serverManager.RegisteredClients )
            //    {
            //        if ( clientData.Profile.DisplayName == msgDamageClient.UserName )
            //        {
            //            clientData.CurrentHealth -= msgDamageClient.Damage;

            //            serverManager.networkManager.UpdateClientStats( clientData );

            //            break;
            //        }
            //    }
            //}

            MsgFlagPickedUp msgFlagPickedUp = message as MsgFlagPickedUp;

            if (null != msgFlagPickedUp)
            {
                // Forward this message to the clients so they log the event.
                serverManager.networkManager.ForwardFlagPickedUp(msgFlagPickedUp);
                ClientDataOnServer client = serverManager.RegisteredClients.FirstOrDefault(c => c.Profile.DisplayName == msgFlagPickedUp.PlayerName);
                if (client != null)
                {
                    client.HasFlag = true;
                }
            }

            PlayerTakenDamage playerDamage = message as PlayerTakenDamage;

            if (playerDamage != null)
            {
                ClientDataOnServer clientData = serverManager.RegisteredClients.First(c => c.NetworkPlayer == playerDamage.Player);
                clientData.CurrentHealth -= playerDamage.Damage;

                // If client is dead
                if (clientData.CurrentHealth <= 0)
                {
                    CAudioControl.CreateAndPlayAudio(playerDamage.PlayerPosition, Audio.AUDIO_EFFECT_EXPLOSION, false, true, false, 2f);
                    Network.Instantiate(PrefabResource.ExplosionPrefab, playerDamage.PlayerPosition, Quaternion.identity, 0);
                    serverManager.CountdownToPlayerRespawn(clientData.NetworkPlayer);
                    serverManager.SendGameMessage(new MsgPlayerDied()
                    {
                        PlayerName = clientData.Profile.DisplayName, PlayerTeam = clientData.ClientTeam, KillerName = playerDamage.Attacker, KillerTeam = playerDamage.AttackerTeam
                    });
                }
                else // otherwise just send the updated stats
                {
                    serverManager.networkManager.UpdateClientStats(clientData);
                }
            }

            PlayerHealed playerHeal = message as PlayerHealed;

            if (playerHeal != null)
            {
                ClientDataOnServer clientData = serverManager.RegisteredClients.FirstOrDefault(c => c.NetworkPlayer == playerDamage.Player);
                if (clientData != null)
                {
                    clientData.CurrentHealth = Mathf.Min(clientData.CurrentHealth + playerHeal.Heal, Constants.DEFAULT_HEALTH_DRONE);

                    serverManager.networkManager.UpdateClientStats(clientData);
                }

                return;
            }

            MsgPlayerDied msgPlayerDied = message as MsgPlayerDied;

            if (null != msgPlayerDied)
            {
                // Try to find the client data object for the scoring player and update his stats.
                foreach (ClientDataOnServer clientData in serverManager.RegisteredClients)
                {
                    if (clientData.Profile.DisplayName == msgPlayerDied.PlayerName)
                    {
                        clientData.DeathCount   += 1;
                        clientData.CurrentHealth = 0;
                        serverManager.networkManager.UpdateClientStats(clientData);

                        if (clientData.HasFlag == true)
                        {
                            clientData.HasFlag = false;
                            CSpawner.SpawnFlag();
                        }
                    }

                    if (clientData.Profile.DisplayName == msgPlayerDied.KillerName)
                    {
                        clientData.KillCount += 1;
                        clientData.EXP       += Constants.POINTS_ON_KILL;
                        serverManager.networkManager.UpdateClientStats(clientData);
                    }
                }

                // Forward this message to the clients so they log the event.
                serverManager.networkManager.ForwardCharacterDied(msgPlayerDied);
            }

            PlayerRespawn playerRespawn = message as PlayerRespawn;

            if (playerRespawn != null)
            {
                ClientDataOnServer client = serverManager.RegisteredClients.FirstOrDefault(c => c.NetworkPlayer == playerRespawn.Player);
                if (client != null)
                {
                    client.CurrentHealth = Constants.DEFAULT_HEALTH_DRONE;
                    serverManager.networkManager.RespawnPlayer(playerRespawn.Player);
                }
            }

            MsgFlagDelivered msgFlagDelivered = message as MsgFlagDelivered;

            if (null != msgFlagDelivered)
            {
                // Increase score depending on the player's team.
                switch (msgFlagDelivered.PlayerTeam)
                {
                case IAIBase.ETeam.TEAM_BLUE:

                    m_iBlueScore += 1;

                    break;

                case IAIBase.ETeam.TEAM_RED:

                    m_iRedScore += 1;

                    break;
                }

                // Update the score on the network.
                serverManager.networkManager.UpdateScore(m_iRedScore, m_iBlueScore);

                // Try to find the client data object for the scoring player and update his stats.
                foreach (ClientDataOnServer clientData in serverManager.RegisteredClients)
                {
                    if (clientData.Profile.DisplayName == msgFlagDelivered.PlayerName)
                    {
                        clientData.CaptureCount += 1;
                        clientData.EXP          += Constants.POINTS_ON_CAPTURE;

                        serverManager.networkManager.UpdateClientStats(clientData);

                        break;
                    }
                }

                // Forward this message to the clients so they log the event.
                serverManager.networkManager.ForwardFlagCaptured(msgFlagDelivered);
            }

            base.OnGameMessage(message);
        }