示例#1
0
        private static void PopulatePlayerFactionLane(int dungeonLevel, EncounterState state, Random seededRand,
                                                      DeploymentInfo deploymentInfo, CommanderAIComponent commanderAI, Lane lane)
        {
            var numLines = seededRand.Next(3) + 1;
            // var numLines = 2;

            Unit hastatusUnit = null;

            if (numLines > 0)
            {
                var numHastati = seededRand.Next(80, 120);
                Func <int, Unit, Entity> hastatusFn = (formationNum, unit) => EntityBuilder.CreateHastatusEntity(state.CurrentTick, formationNum, unit, FactionName.PLAYER);
                if (lane.LaneIdx == deploymentInfo.NumLanes / 2)
                {
                    hastatusFn = WrapWithPlayerFn(state, hastatusFn, numHastati - 3);
                    // hastatusFn = WrapWithPlayerFn(state, hastatusFn, 9);
                }
                hastatusUnit = CreateAndDeployUnit(seededRand, state, FactionName.PLAYER,
                                                   lane, 1, UnitOrder.REFORM, FormationType.MANIPULE_CLOSED,
                                                   deploymentInfo.PlayerFacing,
                                                   numHastati,
                                                   hastatusFn, commanderAI);
                commanderAI.RegisterDeploymentOrder(20, new Order(hastatusUnit.UnitId, OrderType.OPEN_MANIPULE));
                commanderAI.RegisterDeploymentOrder(ADVANCE_AT_TURN, new Order(hastatusUnit.UnitId, OrderType.ADVANCE));
                RegisterRoutAtPercentage(commanderAI, hastatusUnit, .80f);
            }
            Unit princepsUnit = null;

            if (numLines > 1)
            {
                Func <int, Unit, Entity> princepsFn = (formationNum, unit) => EntityBuilder.CreatePrincepsEntity(state.CurrentTick, formationNum, unit, FactionName.PLAYER);
                princepsUnit = CreateAndDeployUnit(seededRand, state, FactionName.PLAYER,
                                                   lane, 2, UnitOrder.REFORM, FormationType.MANIPULE_CLOSED,
                                                   deploymentInfo.PlayerFacing,
                                                   seededRand.Next(80, 120),
                                                   // 20,
                                                   princepsFn, commanderAI);
                commanderAI.RegisterDeploymentOrder(30, new Order(princepsUnit.UnitId, OrderType.OPEN_MANIPULE));
                commanderAI.RegisterTriggeredOrder(TriggeredOrder.AdvanceIfUnitRetreatsRoutsOrWithdraws(hastatusUnit, princepsUnit));
                RegisterRoutAtPercentage(commanderAI, princepsUnit, .60f);
            }
            Unit triariusUnit = null;

            if (numLines > 2)
            {
                Func <int, Unit, Entity> triariusFn = (formationNum, unit) => EntityBuilder.CreateTriariusEntity(state.CurrentTick, formationNum, unit, FactionName.PLAYER);
                triariusUnit = CreateAndDeployUnit(seededRand, state, FactionName.PLAYER,
                                                   lane, 3, UnitOrder.REFORM, FormationType.MANIPULE_CLOSED,
                                                   deploymentInfo.PlayerFacing, seededRand.Next(40, 60), triariusFn, commanderAI);
                commanderAI.RegisterDeploymentOrder(40, new Order(triariusUnit.UnitId, OrderType.OPEN_MANIPULE));
                commanderAI.RegisterTriggeredOrder(TriggeredOrder.AdvanceIfUnitRetreatsRoutsOrWithdraws(princepsUnit, triariusUnit));
                RegisterRoutAtPercentage(commanderAI, triariusUnit, .40f);
            }
        }
示例#2
0
        public static DeploymentInfo Create(int width, int height, Random seededRand, int numLanes)
        {
            var info = new DeploymentInfo();

            if (seededRand.Next(2) == 0)
            {
                info.Attacker = FactionName.PLAYER;
                info.Defender = FactionName.ENEMY;
            }
            else
            {
                info.Attacker = FactionName.ENEMY;
                info.Defender = FactionName.PLAYER;
            }
            info.AttackerFacing = (FormationFacing)seededRand.Next(4);
            info.DefenderFacing = info.AttackerFacing.Opposite();
            GD.Print("Attacking faction is: ", info.Attacker);

            if (info.Attacker == FactionName.PLAYER)
            {
                info.PlayerFacing = info.AttackerFacing;
                info.EnemyFacing  = info.DefenderFacing;
            }
            else
            {
                info.PlayerFacing = info.DefenderFacing;
                info.EnemyFacing  = info.AttackerFacing;
            }

            var interval = 20;

            info.CenterPos = new EncounterPosition(width / 2, height / 2);
            info.NumLanes  = numLanes;
            info.Lanes     = new List <Lane>();
            var leftX = -(Mathf.FloorToInt(info.NumLanes / 2) * interval);

            if (numLanes % 2 == 0)
            {
                leftX = -(info.NumLanes / 2 * interval) + interval / 2;
            }
            for (int i = 0; i < info.NumLanes; i++)
            {
                var laneX = leftX + i * interval;
                // Lanes are laid out from the perspective of the attacker
                var laneCenterPos = AIUtils.RotateAndProject(info.CenterPos, laneX, 0, info.AttackerFacing);
                info.Lanes.Add(new Lane(i, laneCenterPos));
            }
            return(info);
        }
示例#3
0
        private static void PopulateEnemyFactionLane(int dungeonLevel, EncounterState state, Random seededRand,
                                                     DeploymentInfo deploymentInfo, CommanderAIComponent commanderAI, Lane lane)
        {
            var numLines = seededRand.Next(3) + 1;
            // var numLines = 1;

            Unit firstRankUnit = null;

            if (numLines > 0)
            {
                var enemyFn = FirstLineEnemyFn(state, seededRand);
                firstRankUnit = CreateAndDeployUnit(seededRand, state, FactionName.ENEMY,
                                                    lane, 1, UnitOrder.REFORM, FormationType.LINE_20,
                                                    deploymentInfo.EnemyFacing,
                                                    seededRand.Next(80, 120),
                                                    // 20,
                                                    enemyFn, commanderAI);
                commanderAI.RegisterDeploymentOrder(ADVANCE_AT_TURN - 5, new Order(firstRankUnit.UnitId, OrderType.ADVANCE));
                RegisterRoutAtPercentage(commanderAI, firstRankUnit, .80f);
            }
            Unit secondRankUnit = null;

            if (numLines > 1)
            {
                var enemyFn = SecondLineEnemyFn(state, seededRand);
                secondRankUnit = CreateAndDeployUnit(seededRand, state, FactionName.ENEMY,
                                                     lane, 2, UnitOrder.REFORM, FormationType.LINE_20,
                                                     deploymentInfo.EnemyFacing,
                                                     seededRand.Next(80, 120),
                                                     // 20,
                                                     enemyFn, commanderAI);
                commanderAI.RegisterTriggeredOrder(TriggeredOrder.AdvanceIfUnitRetreatsRoutsOrWithdraws(firstRankUnit, secondRankUnit));
                RegisterRoutAtPercentage(commanderAI, secondRankUnit, .60f);
            }
            Unit thirdRankUnit = null;

            if (numLines > 2)
            {
                var enemyFn = ThirdLineEnemyFn(state, seededRand);
                thirdRankUnit = CreateAndDeployUnit(seededRand, state, FactionName.ENEMY,
                                                    lane, 3, UnitOrder.REFORM, FormationType.LINE_20,
                                                    deploymentInfo.EnemyFacing, seededRand.Next(40, 60), enemyFn, commanderAI);
                commanderAI.RegisterTriggeredOrder(TriggeredOrder.AdvanceIfUnitRetreatsRoutsOrWithdraws(secondRankUnit, thirdRankUnit));
                RegisterRoutAtPercentage(commanderAI, thirdRankUnit, .40f);
            }
        }
示例#4
0
        public static void PopulateStateForLevel(Entity player, int dungeonLevel, EncounterState state, Random seededRand,
                                                 int width = 300, int height = 300, int maxZoneGenAttempts = 100)
        {
            InitializeMap(state, width, height);

            // Reset player's start
            // Heal the player
            player.GetComponent <PlayerComponent>().StartOfLevel = true;
            player.GetComponent <DefenderComponent>().RestoreHP(9999);

            var commanderAI = CreateAndPlaceCommander(state);

            var numLanes       = seededRand.Next(4) + 1;
            var deploymentInfo = DeploymentInfo.Create(width, height, seededRand, numLanes);

            state.DeploymentInfo = deploymentInfo;

            foreach (var lane in deploymentInfo.Lanes)
            {
                PopulatePlayerFactionLane(dungeonLevel, state, seededRand, deploymentInfo, commanderAI, lane);
                PopulateEnemyFactionLane(dungeonLevel, state, seededRand, deploymentInfo, commanderAI, lane);
            }
        }