コード例 #1
0
    public void SyncBotStat(string botName, int value, byte cmd)
    {
        BotsStats bs = BotsStatistics.Find(x => x.Name == botName);

        if (bs == null)
        {
            return;
        }
        if (cmd == 0)//add kill
        {
            bs.Kills++;
            bs.Score += bl_GameData.Instance.ScoreReward.ScorePerKill;
        }
        else if (cmd == 1)//death
        {
            bs.Deaths++;
        }
        else if (cmd == 2)//remove bot
        {
            bl_UIReferences.Instance.RemoveUIBot(bs.Name);
            BotsStatistics.Remove(bs);
            Debug.Log("bot remove");
        }
        else if (cmd == 3)//update view id
        {
            bs.ViewID = value;
            if (OnBotStatUpdate != null)
            {
                OnBotStatUpdate(bs);
            }
        }
    }
コード例 #2
0
 void SyncAllBotsStats(string stats)
 {
     BotsStatistics.Clear();
     string[] split = stats.Split("|"[0]);
     for (int i = 0; i < split.Length; i++)
     {
         if (string.IsNullOrEmpty(split[i]))
         {
             continue;
         }
         string[]  info = split[i].Split(","[0]);
         BotsStats bs   = new BotsStats();
         bs.Name   = info[0];
         bs.Kills  = int.Parse(info[1]);
         bs.Deaths = int.Parse(info[2]);
         bs.Score  = int.Parse(info[3]);
         bs.Team   = (Team)int.Parse(info[4]);
         bs.ViewID = int.Parse(info[5]);
         BotsStatistics.Add(bs);
     }
     Debug.Log("Received bot info count: " + BotsStatistics.Count);
     if (OnMaterStatsReceived != null)
     {
         OnMaterStatsReceived(BotsStatistics);
     }
     hasMasterInfo = true;
 }
コード例 #3
0
 void OnPlayerEnter(Player player)
 {
     //cause bots statistics are not sync by Hashtables as player data do we need sync it by RPC
     //so for sync it just one time (after will be update by the local client) we send it when a new player enter (only to the new player)
     if (PhotonNetwork.IsMasterClient && player.ActorNumber != PhotonNetwork.LocalPlayer.ActorNumber)
     {
         //so first we recollect all the stats from the master client and join it in a string line
         string line = string.Empty;
         for (int i = 0; i < BotsStatistics.Count; i++)
         {
             BotsStats b = BotsStatistics[i];
             line += string.Format("{0},{1},{2},{3},{4},{5}|", b.Name, b.Kills, b.Deaths, b.Score, (int)b.Team, b.ViewID);
         }
         //and send to the new player so him can have the data and update locally.
         photonView.RPC("SyncAllBotsStats", player, line);
     }
 }
コード例 #4
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);
    }