Exemple #1
0
        public static Lair GetNearestLair(this SoldierEgg egg)
        {
            Lair nearestLair = null;

            foreach (var lair in Core.Get <GameManager>().lairs)
            {
                if (nearestLair == null || Vector3.Distance(lair.GetPosition(), egg.GetPosition()) < Vector3.Distance(nearestLair.GetPosition(), egg.GetPosition()))
                {
                    nearestLair = lair;
                }
            }

            return(nearestLair);
        }
Exemple #2
0
        public static Lair GetPlayerLair(this GameManager gameManager, Player player)
        {
            Lair playerLair = null;

            foreach (var lair in gameManager.lairs)
            {
                if (lair.owner == player)
                {
                    playerLair = lair;
                    break;
                }
            }

            return(playerLair);
        }
Exemple #3
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;
            }
        }
Exemple #4
0
 public static Vector3 GetPosition(this Lair lair)
 {
     return(lair.behaviour.transform.position);
 }