Пример #1
0
        public static void Update(this SoldierEgg egg)
        {
            if (!egg.behaviour.gameObject.activeInHierarchy)
            {
                return;
            }

            var nearestLair = egg.GetNearestLair();

            if (Vector3.Distance(nearestLair.GetPosition(), egg.GetPosition()) < SoldierEggConstants.HATCH_MIN_DISTANCE_LAIR)
            {
                egg.hatchProgress += Time.deltaTime;

                if (egg.hatchProgress > SoldierEggConstants.HATCH_TIME)
                {
                    SoldierExtension.Instantiate(nearestLair.owner, egg.GetPosition());
                    egg.Destroy();
                }
            }
        }
Пример #2
0
        public static void Reset(this GameManager gameManager)
        {
            gameManager.players.Clear();
            gameManager.soldiers.Clear();
            gameManager.eggs.Clear();
            gameManager.lairs.Clear();
            gameManager.foodPiles.Clear();
            gameManager.foodUnits.Clear();

            var players   = Object.FindObjectsOfType(typeof(PlayerBehaviour)) as PlayerBehaviour[];
            var lairs     = Object.FindObjectsOfType(typeof(LairBehaviour)) as LairBehaviour[];
            var foodPiles = Object.FindObjectsOfType(typeof(FoodPileBehaviour)) as FoodPileBehaviour[];
            var ias       = 0;

            foreach (var player in players)
            {
                if (player.IsBot)
                {
                    ias++;
                }
            }

            Core.Log.Debug("Found: {0} Players ({1} Bots), {2} Lairs, {3} FoodPiles", players.Length, ias, lairs.Length, foodPiles.Length);

            foreach (var playerBehaviour in players)
            {
                var player = new Player();
                player.lastEggTime = Time.fixedTime;
                player.behaviour   = playerBehaviour;

                if (player.behaviour.IsBot)
                {
                    player.ia = Baka.Instantiate(player);
                }

                gameManager.players.Add(player);

                playerBehaviour.playerData = player;
            }

            foreach (var player in gameManager.players)
            {
                for (int i = 0; i < GameConstants.START_SOLDIER_COUNT; ++i)
                {
                    SoldierExtension.Instantiate(player, player.GetPosition());
                }

                foreach (var soldier in gameManager.soldiers)
                {
                    soldier.state = SoldierState.Protect;
                    soldier.behaviour.transform.position = soldier.GetPlayerProtectPosition();
                }
            }

            foreach (var lairBehaviour in lairs)
            {
                var lair = new Lair();
                lair.behaviour = lairBehaviour;
                lair.foodCount = LairConstants.START_FOOD_COUNT;

                foreach (var player in gameManager.players)
                {
                    if (player.behaviour == lairBehaviour.owner)
                    {
                        lair.owner = player;
                        break;
                    }
                }

                gameManager.lairs.Add(lair);

                lairBehaviour.lairData = lair;
            }

            foreach (var foodPileBehaviour in foodPiles)
            {
                var foodPile = new FoodPile();
                foodPile.behaviour = foodPileBehaviour;

                gameManager.foodPiles.Add(foodPile);

                foodPileBehaviour.foodPileData = foodPile;
            }
        }