Пример #1
0
    internal void RecordFrag(TankController victim, TankController killer)
    {
        EventManager.destroyedEvent.Invoke(victim);

        victim.Deaths++;

        //don't reward points for same-team kills.
        if (ConfigValueStore.GetBoolValue("team_mode"))
        {
            if (OnSameTeam(victim.Name, killer.Name))
            {
                return;
            }
        }


        if (snitch != null)
        {
            if (snitch.GetComponent <SnitchBehaviour>().collector == victim)
            {
                killer.RewardSnitchPoints();
            }
        }

        killer.AddKillPoints();
        EventManager.killEvent.Invoke(killer);
    }
Пример #2
0
    internal GameObject CreatePlayer(PlayerCreate create)
    {
        //get a random point in the arena
        Vector3 potentialStartPoint = RandomArenaPosition();



        //already exists. Ignore.
        if (FindTankObject(create.Token) != null)
        {
            return(null);
        }


        GameObject t = null;

        //team game.
        if (ConfigValueStore.GetBoolValue("team_mode"))
        {
            if (create.Name.Contains(":"))
            {
                //get the team name.
                string teamName = GetTeamName(create.Name);

                //add the team to the list of teams if it isn't in there already.
                //Assign the team a tank type if this is the first time we've seen the team.
                if (!teams.Keys.Contains(teamName))
                {
                    teams.Add(teamName, new List <TankController>());
                    teamNameToModelMap.Add(teamName, currentModel);
                    currentModel += 2;
                }


                t = tankFactory.CreateTank(create.Color, create.Name, create.Token, potentialStartPoint, teamNameToModelMap[teamName]);
                teams[teamName].Add(t.GetComponent <TankController>());
            }
            else
            {
                //don't create player, this is a team game and they've not conformed to the naming needs (i.e. teamname:playername).
            }
        }
        else
        {
            t = tankFactory.CreateTank(create.Color, create.Name, create.Token, potentialStartPoint, -1);
        }



        //randomly rotate the tank
        t.GetComponent <TankController>().transform.Rotate(Vector3.up, UnityEngine.Random.Range(0, 360));

        t.GetComponent <TankController>().Sim = this;
        tankControllers.Add(t.GetComponent <TankController>());
        return(t);
    }
Пример #3
0
 internal void RewardSnitchPoints()
 {
     if (ConfigValueStore.GetBoolValue("kill_capture_mode"))
     {
         for (int i = 0; i < snitchKillPoints; i++)
         {
             AddKillPoints();
         }
     }
     else
     {
         Points += snitchKillPoints;
     }
 }
Пример #4
0
 public void AddKillPoints()
 {
     if (ConfigValueStore.GetBoolValue("kill_capture_mode"))
     {
         for (int i = 0; i < killPoints; i++)
         {
             UnbankedPoints++;
             var ob = GameObject.Instantiate(Resources.Load("Prefabs/UnbankedPoint") as GameObject);
             pointObjects.Add(ob);
         }
     }
     else
     {
         Points += killPoints;
     }
 }
Пример #5
0
    private void RefreshScores()
    {
        var scores = simulation.GetScores();


        StringBuilder sb = new StringBuilder();

        sb.Append("LEADERBOARD");

        sb.AppendLine();
        sb.AppendLine();

        if (!ConfigValueStore.GetBoolValue("team_mode"))
        {
            foreach (TankController t in scores)
            {
                sb.Append(t.Name + " - " + t.Points);
                sb.AppendLine();
            }
        }
        else
        {
            foreach (string team in simulation.teams.Keys)
            {
                int teamTotal = 0;
                foreach (TankController t in scores)
                {
                    if (GameSimulation.GetTeamName(t.Name) == team)
                    {
                        teamTotal += t.Points;
                    }
                }
                sb.Append(team + " - " + teamTotal);
                sb.AppendLine();
            }
        }

        scoreBoard.text = sb.ToString();

        scoreRefreshTime = DateTime.Now;
    }
Пример #6
0
    public void Update()
    {
        allObjects.Clear();


        HandlePickupLogic();

        foreach (TankController t in tanksToBeRemoved)
        {
            RemoveTank(t);
        }
        tanksToBeRemoved.Clear();

        while (enqueuedCommands.Count > 0)
        {
            GameCommand command = enqueuedCommands.Dequeue();
            HandleCommand(command);
        }

        lock (allObjects)
        {
            UpdateTankState();
        }

        lock (objectsInFieldOfView)
        {
            var tanks = UnityEngine.GameObject.FindObjectsOfType <TankController>();
            foreach (TankController t in tanks)
            {
                UpdateTankViewObjects(t);
            }
        }


        if (TrainingRoomMain.currentGameState == TrainingRoomMain.GameState.playing)
        {
            if (healthPickups.Count < healthPickupCount)
            {
                SpawnHealthPickup();
            }
            if (ammoPickups.Count < ammoPickupCount)
            {
                SpawnAmmoPickup();
            }

            if (TrainingRoomMain.timeLeft.TotalSeconds < ConfigValueStore.GetIntValue("snitch_spawn_threshold"))
            {
                if (!snitchSpawned && ConfigValueStore.GetBoolValue("snitch_enabled"))
                {
                    SpawnSnitch();
                }
            }
        }

        lock (tankDisconnects)
        {
            foreach (string s in tankDisconnects)
            {
                RemoveTank(FindTankObject(s));
            }
            tankDisconnects.Clear();
        }
    }