Exemplo n.º 1
0
        public void TestGenerate()
        {
            var generator = new RandomSpawnGenerator(20f, 200f, 200f);
            // two
            var spawnPoints = generator.Generate(2);

            // Debug.Log(String.Format("spawn points -> {0}",
            //     String.Join(",", spawnPoints.Select(v=>v.ToString()).ToArray())));
            Assert.AreEqual(2, spawnPoints.Length);
            // twelve
            spawnPoints = generator.Generate(12);
            // Debug.Log(String.Format("spawn points -> {0}",
            //     String.Join(",", spawnPoints.Select(v=>v.ToString()).ToArray())));
            Assert.AreEqual(12, spawnPoints.Length);
        }
Exemplo n.º 2
0
    // ------------------------------------------------------
    // STATE ENGINES
    /// <summary>
    /// This is the main server loop
    /// </summary>
    IEnumerator ServerLoop()
    {
        // Debug.Log("starting ServerLoop");
        // wait for players to join
        yield return(StartCoroutine(ListenForTanks()));

        // create spawn points
        ISpawnGenerator spawnGenerator;

        if (useRandomSpawn)
        {
            var maxX    = 200f;
            var maxZ    = 200f;
            var terrain = Terrain.activeTerrain;
            if (terrain != null)
            {
                maxX = terrain.terrainData.size.x;
                maxZ = terrain.terrainData.size.z;
            }
            spawnGenerator = new RandomSpawnGenerator(minPlayerSpacing, maxX, maxZ);
        }
        else
        {
            spawnGenerator = new FixedSpawnGenerator();
        }
        // add two extra spawn points to break up the map into more chunks (if player count is low)
        var numToSpawn  = (tankRegistry.Count <= 4) ? tankRegistry.Count + 2 : tankRegistry.Count;
        var spawnPoints = spawnGenerator.Generate(numToSpawn);

        // register spawn points over network
        foreach (var spawnPoint in spawnPoints)
        {
            RpcAddSpawn(spawnPoint);
        }

        // build world
        yield return(StartCoroutine(BuildWorld()));

        // place tanks
        foreach (var tankId in tankRegistry.Keys)
        {
            var spawnPoint = spawnPoints[tankId - 1];
            var tank       = tankRegistry[tankId];
            PlaceTank(tank, spawnPoint);
            // add spawn exclusion
            if (LootSpawnController.singleton != null)
            {
                LootSpawnController.singleton.AddExclusion(spawnPoint, 10f);
            }
            tank.ServerActivate();
        }
        yield return(null);

        // spawn initial lootboxes
        StartCoroutine(DelayLootSpawn());

        // re-enable groundZero terrain
        groundZero.enabled = true;

        // adjust camera
        //RpcViewLocalTank();

        // start the game on client
        RpcStart();

        // start the game
        yield return(StartCoroutine(PlayRound()));

        // FIXME: need to rework game win/loss logic

        if (nukeActive)
        {
            StartCoroutine(NukeSequence());
            ServerNukeGameOver();
        }
        else
        {
            ServerGameOver();
        }
        // Debug.Log("finishing ServerLoop");
    }