protected override void Awake()
 {
     base.Awake();
     m_animator = GetComponent <Animator>();
     AI         = transform.parent.GetComponent <bl_AIShooterAgent>();
     SetKinecmatic();
 }
Esempio n. 2
0
    public List <Transform> GetOtherBots(Transform bot, Team _team)
    {
        List <Transform> all = new List <Transform>();

        if (isOneTeamMode)
        {
            all.AddRange(AllBotsTransforms);
            for (int i = 0; i < all.Count; i++)
            {
                if (all[i].transform.root.name.Contains("die") || all[i].transform.root == bot.root)
                {
                    all.RemoveAt(i);
                }
            }
        }
        else //if TDM game mode
        {
            for (int i = 0; i < AllBotsTransforms.Count; i++)
            {
                Transform         t   = AllBotsTransforms[i].root;
                bl_AIShooterAgent asa = t.GetComponent <bl_AIShooterAgent>();
                if (asa.AITeam != _team && asa.AITeam != Team.None && !t.name.Contains("die") && t != bot.root)
                {
                    all.Add(AllBotsTransforms[i]);
                }
            }
        }
        if (all.Contains(bot))
        {
            all.Remove(bot);
        }
        return(all);
    }
Esempio n. 3
0
    /// <summary>
    ///
    /// </summary>
    private void Awake()
    {
        AI      = GetComponent <bl_AIShooterAgent>();
        Anim    = GetComponentInChildren <Animator>();
        Pooling = bl_ObjectPooling.Instance;
        bl_PhotonCallbacks.PlayerEnteredRoom += OnPhotonPlayerConnected;
#if UMM
        miniMapItem = GetComponent <bl_MiniMapItem>();
#endif
    }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 bool CheckPlayerSlot(bl_AIShooterAgent agent, Team team)
 {
     if (!isOneTeamMode)
     {
         if (team == Team.Recon)
         {
             bool already = Team2PlayersSlots.Exists(x => x.Bot == agent.AIName);
             if (already)
             {
                 return(true);
             }
             else
             {
                 if (hasSpaceInTeamForBot(Team.Recon))
                 {
                     int index = Team2PlayersSlots.FindIndex(x => x.Player == string.Empty && x.Bot == string.Empty);
                     Team2PlayersSlots[index].Bot = agent.AIName;
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
         else if (team == Team.Delta)
         {
             bool already = Team1PlayersSlots.Exists(x => x.Bot == agent.AIName);
             if (already)
             {
                 return(true);
             }
             else
             {
                 if (hasSpaceInTeamForBot(Team.Delta))
                 {
                     int index = Team1PlayersSlots.FindIndex(x => x.Player == string.Empty && x.Bot == string.Empty);
                     Team1PlayersSlots[index].Bot = agent.AIName;
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Esempio n. 5
0
    public void OnBotDeath(bl_AIShooterAgent agent, bl_AIShooterAgent killer)
    {
        if (!PhotonNetwork.IsMasterClient)
        {
            return;
        }

        AllBots.Remove(agent);
        AllBotsTransforms.Remove(agent.AimTarget);
        for (int i = 0; i < AllBots.Count; i++)
        {
            AllBots[i].CheckTargets();
        }

        SpawningBots.Add(agent);
        Invoke("SpawnPendingBot", bl_GameData.Instance.PlayerRespawnTime);
    }
    /// <summary>
    ///
    /// </summary>
    void SearchPlayers()
    {
        GameMode gm = GetGameMode;

        for (int i = 0; i < PlayersInRoom.Count; i++)
        {
            Transform enemy = PlayersInRoom[i];
            if (enemy != null)
            {
                float Distance = bl_UtilityHelper.Distance(enemy.position, m_Transform.localPosition);//if a player in range, get this
                if (gm == GameMode.FFA)
                {
                    if (Distance < LookRange && !enemy.root.name.Contains("(die)")) //if in range
                    {
                        GetTarget(PlayersInRoom[i]);                                //get this player
                    }
                }
                else
                {
                    bl_AIShooterAgent aisa = enemy.root.GetComponent <bl_AIShooterAgent>();
                    if (aisa != null)
                    {
                        if (Distance < LookRange && !enemy.root.name.Contains("(die)") && enemy.root.GetComponent <bl_AIShooterAgent>().AITeam != AITeam) //if in range
                        {
                            GetTarget(PlayersInRoom[i]);                                                                                                  //get this player
                        }
                    }
                }
            }
        }

        if (PhotonNetwork.IsMasterClient && !randomOnStartTake && PlayersInRoom.Count > 0)
        {
            if (GetRandomTargetOnStart)
            {
                Target            = PlayersInRoom[Random.Range(0, PlayersInRoom.Count)];
                randomOnStartTake = true;
            }
        }
    }
    void RpcDoDamage(int damage, string wn, Vector3 direction, int viewID, bool fromBot, bool ishead)
    {
        if (Agent.death)
        {
            return;
        }

        Health -= damage;
        if (LastActorEnemy != viewID)
        {
            Agent.personal = false;
        }
        LastActorEnemy = viewID;

        if (PhotonNetwork.IsMasterClient)
        {
            Agent.OnGetHit(direction);
        }
        if (viewID == bl_GameManager.m_view)//if was me that make damage
        {
            bl_UCrosshair.Instance.OnHit();
        }

        if (Health > 0)
        {
            Transform t = bl_GameManager.Instance.FindActor(viewID);
            if (t != null)
            {
                if (Agent.Target == null)
                {
                    Agent.personal = true;
                    Agent.Target   = t;
                }
                else
                {
                    if (t != Agent.Target)
                    {
                        float cd = bl_UtilityHelper.Distance(transform.position, Agent.Target.position);
                        float od = bl_UtilityHelper.Distance(transform.position, t.position);
                        if (od < cd && (cd - od) > 7)
                        {
                            Agent.personal = true;
                            Agent.Target   = t;
                        }
                    }
                }
            }
            AIAnim.OnGetHit();
        }
        else
        {
            Agent.death           = true;
            Agent.enabled         = false;
            Agent.Agent.isStopped = true;
            GetComponent <bl_DrawName>().enabled = false;

            bl_AIShooterAgent killerBot = null;
            if (viewID == bl_GameManager.m_view && !fromBot)//if was me that kill AI
            {
                bl_EventHandler.KillEvent(base.LocalName, Agent.AIName, wn, PhotonNetwork.LocalPlayer.GetPlayerTeam().ToString(), 5, 20);
                //Add a new kill and update information
                PhotonNetwork.LocalPlayer.PostKill(1);//Send a new kill

                int score;
                //If heat shot will give you double experience
                if (ishead)
                {
                    bl_GameManager.Instance.Headshots++;
                    score = bl_GameData.Instance.ScoreReward.ScorePerKill + bl_GameData.Instance.ScoreReward.ScorePerHeadShot;
#if KILL_STREAK
                    bl_KillNotifierManager kn = bl_KillNotifierUtils.GetManager;
                    if (kn != null)
                    {
                        kn.NewKill(true);
                    }
                    else
                    {
                        Debug.LogWarning("Kill streak notifier is enabled but not integrate in this scene.");
                    }
#endif
                }
                else
                {
                    score = bl_GameData.Instance.ScoreReward.ScorePerKill;
#if KILL_STREAK
                    bl_KillNotifierManager kn = bl_KillNotifierUtils.GetManager;
                    if (kn != null)
                    {
                        kn.NewKill();
                    }
                    else
                    {
                        Debug.LogWarning("Kill streak notifier is enabled but not integrate in this scene.");
                    }
#endif
                }

                bl_KillFeed.LocalKillInfo localKillInfo = new bl_KillFeed.LocalKillInfo();
                localKillInfo.Killed   = Agent.AIName;
                localKillInfo.HeadShot = ishead;
                localKillInfo.Weapon   = wn;
                bl_EventHandler.OnKillEvent(localKillInfo);

                //Send to update score to player
                PhotonNetwork.LocalPlayer.PostScore(score);
            }
            else if (fromBot)
            {
                if (PhotonNetwork.IsMasterClient)
                {
                    PhotonView p      = PhotonView.Find(viewID);
                    string     killer = "Unknown";
                    if (p != null)
                    {
                        killer = p.gameObject.name;
                        //update bot stats
                        AIManager.SetBotKill(killer);
                    }
                    bl_EventHandler.KillEvent(killer, Agent.AIName, wn, Agent.AITeam.ToString(), 5, 20);

                    bl_AIShooterAgent bot = p.GetComponent <bl_AIShooterAgent>();
                    if (bot != null)
                    {
                        bot.KillTheTarget(transform);
                        killerBot = bot;
                    }
                    else
                    {
                        Debug.Log("Bot can't be found");
                    }
                }
            }
            AIManager.SetBotDeath(Agent.AIName);
            gameObject.name += " (die)";
            if (PhotonNetwork.IsMasterClient)
            {
                if (GetGameMode == GameMode.TDM)
                {
                    string t     = (Agent.AITeam == Team.Recon) ? PropertiesKeys.Team1Score : PropertiesKeys.Team2Score;
                    int    score = (int)PhotonNetwork.CurrentRoom.CustomProperties[t];
                    score++;
                    ExitGames.Client.Photon.Hashtable table = new ExitGames.Client.Photon.Hashtable();
                    table.Add(t, score);
                    PhotonNetwork.CurrentRoom.SetCustomProperties(table);
                    if (Agent.AITeam == PhotonNetwork.LocalPlayer.GetPlayerTeam())
                    {
                        GameObject di = bl_ObjectPooling.Instance.Instantiate("deathicon", transform.position, transform.rotation);
                        di.GetComponent <bl_ClampIcon>().SetTempIcon(DeathIcon, 5, 20);
                    }
                }
                AIManager.OnBotDeath(Agent, killerBot);
            }
            this.photonView.RPC("DestroyRpc", RpcTarget.AllBuffered, direction);
        }
    }
 /// <summary>
 ///
 /// </summary>
 void Awake()
 {
     Agent     = GetComponent <bl_AIShooterAgent>();
     AIManager = FindObjectOfType <bl_AIMananger>();
     AIAnim    = GetComponentInChildren <bl_AIAnimation>();
 }
Esempio n. 9
0
    public void SpawnBot(bl_AIShooterAgent agent = null, Team _team = Team.None)
    {
        Transform t      = GameManager.GetAnSpawnPoint;
        string    AiName = bl_GameData.Instance.BotTeam1.name;

        if (agent != null)//if is a already instanced bot
        {
            AiName = (agent.AITeam == Team.Recon) ? bl_GameData.Instance.BotTeam2.name : bl_GameData.Instance.BotTeam1.name;
            if (!isOneTeamMode)//if team mode, spawn bots in the respective team spawn points.
            {
                if (agent.AITeam == Team.None)
                {
                    Debug.LogError("This bot has not team");
                }

                if (CheckPlayerSlot(agent, agent.AITeam))
                {
                    t = GameManager.GetAnTeamSpawnPoint(agent.AITeam, true);
                }
                else
                {
                    int ind = BotsStatistics.FindIndex(x => x.Name == agent.AIName);
                    if (ind != -1 && ind <= BotsStatistics.Count - 1)
                    {
                        BotsStatistics.RemoveAt(ind);
                    }
                    return;
                }
            }
        }
        else
        {
            AiName = (_team == Team.Recon) ? bl_GameData.Instance.BotTeam2.name : bl_GameData.Instance.BotTeam1.name;
            if (!isOneTeamMode)//if team mode, spawn bots in the respective team spawn points.
            {
                t = GameManager.GetAnTeamSpawnPoint(_team, true);
            }
        }
        GameObject        bot      = PhotonNetwork.Instantiate(AiName, t.position, t.rotation, 0);
        bl_AIShooterAgent newAgent = bot.GetComponent <bl_AIShooterAgent>();

        if (agent != null)
        {
            newAgent.AIName = agent.AIName;
            newAgent.AITeam = agent.AITeam;
            photonView.RPC("SyncBotStat", RpcTarget.Others, agent.AIName, bot.GetComponent <PhotonView>().ViewID, (byte)3);
        }
        else
        {
            int rbn = Random.Range(0, BotsNames.Count);
            newAgent.AIName = "BOT " + BotsNames[rbn];
            newAgent.AITeam = _team;
            BotsNames.RemoveAt(rbn);
            //insert bot stats
            BotsStats bs = new BotsStats();
            bs.Name   = newAgent.AIName;
            bs.Team   = _team;
            bs.ViewID = bot.GetComponent <PhotonView>().ViewID;
            BotsStatistics.Add(bs);
            CheckPlayerSlot(newAgent, _team);
        }
        newAgent.Init();
        bl_EventHandler.OnRemoteActorChange(newAgent.transform, true, false);
        AllBots.Add(newAgent);
        AllBotsTransforms.Add(newAgent.AimTarget);
    }