public EnhancedBattleTestMissionSpawnHandler(
     IEnhancedBattleTestCombatant defenderParty,
     IEnhancedBattleTestCombatant attackerParty)
 {
     _defenderParty = defenderParty;
     _attackerParty = attackerParty;
 }
 public EnhancedBattleTestSiegeMissionSpawnHandler(
     IEnhancedBattleTestCombatant defenderBattleCombatant,
     IEnhancedBattleTestCombatant attackerBattleCombatant)
 {
     _battleCombatants = new IEnhancedBattleTestCombatant[2]
     {
         defenderBattleCombatant,
         attackerBattleCombatant
     };
 }
        public static Mission OpenMission(IEnhancedBattleTestCombatant playerParty,
                                          IEnhancedBattleTestCombatant enemyParty, BattleConfig config, string map)
        {
            if (config.PlayerTeamConfig.HasGeneral)
            {
                Game.Current.PlayerTroop = config.PlayerTeamConfig.General.CharacterObject;
            }
            if (config.BattleTypeConfig.BattleType == BattleType.Siege && config.PlayerTeamConfig.HasGeneral)
            {
                var attackerSiegeWeaponCount = GetSiegeWeaponCount(config.SiegeMachineConfig.AttackerMeleeMachines)
                                               .Union(GetSiegeWeaponCount(config.SiegeMachineConfig.AttackerRangedMachines))
                                               .ToDictionary(pair => pair.Key, pair => pair.Value);
                var defenderSiegeWeaponCount = GetSiegeWeaponCount(config.SiegeMachineConfig.DefenderMachines);

                int breachedWallCount   = config.MapConfig.BreachedWallCount;
                var hitPointPercentages = new float[2];

                switch (breachedWallCount)
                {
                case 0:
                    hitPointPercentages[0] = 1;
                    hitPointPercentages[1] = 1;
                    break;

                case 1:
                    int i = MBRandom.RandomInt(2);
                    hitPointPercentages[i]     = 0;
                    hitPointPercentages[1 - i] = 1;
                    break;

                default:
                    hitPointPercentages[0] = 0;
                    hitPointPercentages[1] = 0;
                    break;
                }

                return(OpenEnhancedBattleTestSiege(map, config, playerParty, enemyParty, hitPointPercentages,
                                                   attackerSiegeWeaponCount, defenderSiegeWeaponCount));
            }
            else if (config.BattleTypeConfig.BattleType == BattleType.Field || config.BattleTypeConfig.BattleType == BattleType.Village)
            {
                //var characterObject = (config.PlayerTeamConfig.General as SPCharacterConfig)?.ActualCharacterObject;
                //EnhancedBattleTestPartyController.PlayerParty.Party.Owner = characterObject.HeroObject;
                //foreach(BasicCharacterObject player in playerParty.Characters)
                //{
                //    if (player.IsPlayerCharacter)
                //    {
                //        playerchar = player;
                //        break;
                //    }
                //}
                return(OpenEnhancedBattleTestField(map, config, playerParty, enemyParty));
            }
            return(null);
        }
 private static IEnhancedBattleTestTroopSupplier CreateTroopSupplier(IEnhancedBattleTestCombatant combatant, bool isMultiplayer, bool _isPlayerSide)
 {
     if (isMultiplayer)
     {
         return(new MPTroopSupplier(combatant));
     }
     else
     {
         return(new SPTroopSupplier(combatant, _isPlayerSide));
     }
 }
Exemplo n.º 5
0
        public static Mission OpenMission(IEnhancedBattleTestCombatant playerParty,
                                          IEnhancedBattleTestCombatant enemyParty, BattleConfig config, string map)
        {
            if (config.BattleTypeConfig.BattleType == BattleType.Siege)
            {
                var attackerSiegeWeaponCount = GetSiegeWeaponCount(config.SiegeMachineConfig.AttackerMeleeMachines)
                                               .Union(GetSiegeWeaponCount(config.SiegeMachineConfig.AttackerRangedMachines))
                                               .ToDictionary(pair => pair.Key, pair => pair.Value);
                var defenderSiegeWeaponCount = GetSiegeWeaponCount(config.SiegeMachineConfig.DefenderMachines);

                int breachedWallCount   = config.MapConfig.BreachedWallCount;
                var hitPointPercentages = new float[2];

                switch (breachedWallCount)
                {
                case 0:
                    hitPointPercentages[0] = 1;
                    hitPointPercentages[1] = 1;
                    break;

                case 1:
                    int i = MBRandom.RandomInt(2);
                    hitPointPercentages[i]     = 0;
                    hitPointPercentages[1 - i] = 1;
                    break;

                default:
                    hitPointPercentages[0] = 0;
                    hitPointPercentages[1] = 0;
                    break;
                }

                return(OpenEnhancedBattleTestSiege(map, config, playerParty, enemyParty, hitPointPercentages,
                                                   attackerSiegeWeaponCount, defenderSiegeWeaponCount));
            }
            else
            {
                return(OpenEnhancedBattleTestField(map, config, playerParty, enemyParty));
            }
        }
Exemplo n.º 6
0
 public MPTroopSupplier(IEnhancedBattleTestCombatant combatant)
 {
     _combatant = combatant as MPCombatant;
     ArrangePriorities();
 }
        public static Mission OpenEnhancedBattleTestField(
            string scene,
            BattleConfig config,
            IEnhancedBattleTestCombatant playerParty,
            IEnhancedBattleTestCombatant enemyParty,
            float timeOfDay = 12f)
        {
            var playerSide = config.BattleTypeConfig.PlayerSide;
            var enemySide  = config.BattleTypeConfig.PlayerSide.GetOppositeSide();
            var player     = config.PlayerTeamConfig.General;

            if (player == null)
            {
                return(null);
            }

            bool hasPlayer = config.PlayerTeamConfig.HasGeneral;

            bool isPlayerAttacker = playerSide == BattleSideEnum.Attacker;

            IMissionTroopSupplier[] troopSuppliers = new IMissionTroopSupplier[2];
            bool isMultiplayer = EnhancedBattleTestSubModule.IsMultiplayer;

            troopSuppliers[(int)playerSide] = CreateTroopSupplier(playerParty, isMultiplayer, true);
            troopSuppliers[(int)enemySide]  = CreateTroopSupplier(enemyParty, isMultiplayer, false);
            bool isPlayerGeneral  = config.BattleTypeConfig.PlayerType == PlayerType.Commander;
            bool isPlayerSergeant = hasPlayer && config.BattleTypeConfig.PlayerType == PlayerType.Sergeant;

            List <CharacterObject> charactersInPlayerSideByPriority = null;
            List <CharacterObject> charactersInEnemySideByPriority  = null;
            string playerTeamGeneralName = null;
            string enemyTeamGeneralName  = null;

            if (!isMultiplayer)
            {
                var playerCharacter = player.CharacterObject as CharacterObject;
                if (playerCharacter == null)
                {
                    return(null);
                }
                charactersInPlayerSideByPriority = Utility.OrderHeroesByPriority(config.PlayerTeamConfig);
                var playerGeneral = hasPlayer && isPlayerGeneral
                    ? playerCharacter
                    : (hasPlayer && charactersInPlayerSideByPriority.First() == playerCharacter
                        ? charactersInPlayerSideByPriority.Skip(1).FirstOrDefault()
                        : charactersInPlayerSideByPriority.FirstOrDefault());
                if (playerGeneral != null)
                {
                    charactersInPlayerSideByPriority.Remove(playerGeneral);
                    playerTeamGeneralName = TextObject.ConvertToStringList(new List <TextObject>()
                    {
                        playerGeneral.Name
                    }).FirstOrDefault();
                }
                charactersInEnemySideByPriority = Utility.OrderHeroesByPriority(config.EnemyTeamConfig);
                var enemyGeneral = charactersInEnemySideByPriority.FirstOrDefault();
                if (enemyGeneral != null)
                {
                    charactersInEnemySideByPriority.Remove(enemyGeneral);
                    enemyTeamGeneralName = TextObject.ConvertToStringList(new List <TextObject>()
                    {
                        enemyGeneral.Name
                    }).FirstOrDefault();
                }
            }


            AtmosphereInfo atmosphereInfo = CreateAtmosphereInfoForMission(config.MapConfig.Season, timeOfDay);

            return(MissionState.OpenNew("EnhancedBattleTestFieldBattle", new MissionInitializerRecord(scene)
            {
                DoNotUseLoadingScreen = false,
                PlayingInCampaignMode = false,
                AtmosphereOnCampaign = atmosphereInfo,
                SceneLevels = "",
                TimeOfDay = timeOfDay
            }, mission =>
                                        new MissionBehaviour[]
            {
                new CommanderLogic(config),
                new MissionOptionsComponent(),
                new BattleEndLogic(),
                new MissionCombatantsLogic(null, playerParty,
                                           !isPlayerAttacker ? playerParty : enemyParty,
                                           isPlayerAttacker ? playerParty : enemyParty,
                                           Mission.MissionTeamAITypeEnum.FieldBattle, isPlayerSergeant),
                new BattleObserverMissionLogic(),
                new CustomBattleAgentLogic(),
                new MissionAgentSpawnLogic(troopSuppliers, playerSide),
                new EnhancedBattleTestMissionSpawnHandler(!isPlayerAttacker ? playerParty : enemyParty,
                                                          isPlayerAttacker ? playerParty : enemyParty),
                new AgentBattleAILogic(),
                new AgentVictoryLogic(),
                new MissionAgentPanicHandler(),
                new MissionHardBorderPlacer(),
                new MissionBoundaryPlacer(),
                new MissionBoundaryCrossingHandler(),
                new BattleMissionAgentInteractionLogic(),
                new FieldBattleController(),
                new AgentFadeOutLogic(),
                new AgentMoraleInteractionLogic(),
                new AssignPlayerRoleInTeamMissionController(isPlayerGeneral, isPlayerSergeant, isPlayerInArmy: false, isPlayerSergeant ? Enumerable.Repeat(config.PlayerTeamConfig.General.CharacterObject.StringId, 1).ToList() : new List <string>()),
                new CreateBodyguardMissionBehavior(
                    isPlayerAttacker ? playerTeamGeneralName : enemyTeamGeneralName,
                    !isPlayerAttacker ? playerTeamGeneralName : enemyTeamGeneralName,
                    null, null, true),
                new HighlightsController(),
                new BattleHighlightsController()
            }));
        }
        public static Mission OpenEnhancedBattleTestSiege(
            string scene,
            BattleConfig config,
            IEnhancedBattleTestCombatant playerParty,
            IEnhancedBattleTestCombatant enemyParty,
            float[] wallHitPointPercentages,
            Dictionary <SiegeEngineType, int> siegeWeaponsCountOfAttackers,
            Dictionary <SiegeEngineType, int> siegeWeaponsCountOfDefenders,
            bool isSallyOut          = false,
            bool isReliefForceAttack = false,
            float timeOfDay          = 6f)
        {
            bool hasAnySiegeTower = siegeWeaponsCountOfAttackers.ContainsKey(DefaultSiegeEngineTypes.SiegeTower);

            string levelString;

            switch (config.MapConfig.SceneLevel)
            {
            case 1:
                levelString = "level_1";
                break;

            case 2:
                levelString = "level_2";
                break;

            case 3:
                levelString = "level_3";
                break;

            default:
                levelString = "";
                break;
            }

            var sceneLevelString =
                !(isSallyOut | isReliefForceAttack) ? levelString + " siege" : levelString + " sally";
            var playerSide = config.BattleTypeConfig.PlayerSide;
            var enemySide  = config.BattleTypeConfig.PlayerSide.GetOppositeSide();


            var player = config.PlayerTeamConfig.General;

            if (player == null)
            {
                return(null);
            }
            bool hasPlayer        = config.PlayerTeamConfig.HasGeneral;
            bool isPlayerAttacker = playerSide == BattleSideEnum.Attacker;

            IMissionTroopSupplier[] troopSuppliers = new IMissionTroopSupplier[2];
            bool isMultiplayer = EnhancedBattleTestSubModule.IsMultiplayer;

            troopSuppliers[(int)playerSide] = CreateTroopSupplier(playerParty, isMultiplayer, true);
            troopSuppliers[(int)enemySide]  = CreateTroopSupplier(enemyParty, isMultiplayer, false);
            bool isPlayerGeneral  = config.BattleTypeConfig.PlayerType == PlayerType.Commander || !hasPlayer;
            bool isPlayerSergeant = hasPlayer && config.BattleTypeConfig.PlayerType == PlayerType.Sergeant;

            List <CharacterObject> charactersInPlayerSideByPriority = null;
            List <CharacterObject> charactersInEnemySideByPriority  = null;
            string playerTeamGeneralName = null;
            string enemyTeamGeneralName  = null;

            if (!isMultiplayer)
            {
                var playerCharacter = player.CharacterObject as CharacterObject;
                if (playerCharacter == null)
                {
                    return(null);
                }
                charactersInPlayerSideByPriority = Utility.OrderHeroesByPriority(config.PlayerTeamConfig);
                var playerGeneral = hasPlayer && isPlayerGeneral
                    ? playerCharacter
                    : (hasPlayer && charactersInPlayerSideByPriority.First() == playerCharacter
                        ? charactersInPlayerSideByPriority.Skip(1).FirstOrDefault()
                        : charactersInPlayerSideByPriority.FirstOrDefault());
                if (playerGeneral != null)
                {
                    charactersInPlayerSideByPriority.Remove(playerGeneral);
                    playerTeamGeneralName = TextObject.ConvertToStringList(new List <TextObject>()
                    {
                        playerGeneral.Name
                    }).FirstOrDefault();
                }
                charactersInEnemySideByPriority = Utility.OrderHeroesByPriority(config.EnemyTeamConfig);
                var enemyGeneral = charactersInEnemySideByPriority.FirstOrDefault();
                if (enemyGeneral != null)
                {
                    charactersInEnemySideByPriority.Remove(enemyGeneral);
                    enemyTeamGeneralName = TextObject.ConvertToStringList(new List <TextObject>()
                    {
                        enemyGeneral.Name
                    }).FirstOrDefault();
                }
            }

            AtmosphereInfo atmosphereInfo = CreateAtmosphereInfoForMission(config.MapConfig.Season, timeOfDay);

            var attackerSiegeWeapons =
                GetSiegeWeaponTypes(siegeWeaponsCountOfAttackers);
            var defenderSiegeWeapons =
                GetSiegeWeaponTypes(siegeWeaponsCountOfDefenders);

            return(MissionState.OpenNew("EnhancedBattleTestSiegeBattle", new MissionInitializerRecord(scene)
            {
                PlayingInCampaignMode = false,
                AtmosphereOnCampaign = atmosphereInfo,
                SceneLevels = sceneLevelString,
                TimeOfDay = timeOfDay
            }, mission =>
            {
                List <MissionBehaviour> missionBehaviourList = new List <MissionBehaviour>
                {
                    new CommanderLogic(config),
                    new BattleSpawnLogic(isSallyOut
                        ? "sally_out_set"
                        : (isReliefForceAttack ? "relief_force_attack_set" : "battle_set")),
                    new MissionOptionsComponent(),
                    new BattleEndLogic(),
                    new MissionCombatantsLogic(null, playerParty,
                                               !isPlayerAttacker ? playerParty : enemyParty,
                                               isPlayerAttacker ? playerParty : enemyParty,
                                               !isSallyOut ? Mission.MissionTeamAITypeEnum.Siege : Mission.MissionTeamAITypeEnum.SallyOut,
                                               isPlayerSergeant),
                    new SiegeMissionPreparationHandler(isSallyOut, isReliefForceAttack, wallHitPointPercentages,
                                                       hasAnySiegeTower),
                    new MissionAgentSpawnLogic(troopSuppliers, playerSide),
                    new BattleObserverMissionLogic(),
                    new CustomBattleAgentLogic(),
                    new AgentBattleAILogic(),
                    new AmmoSupplyLogic(new List <BattleSideEnum> {
                        BattleSideEnum.Defender
                    }),
                    new AgentVictoryLogic(),
                    new MissionAgentPanicHandler(),
                    new SiegeMissionController(
                        attackerSiegeWeapons,
                        defenderSiegeWeapons,
                        isPlayerAttacker, isSallyOut),
                    new SiegeDeploymentHandler(isPlayerAttacker,
                                               isPlayerAttacker ? attackerSiegeWeapons : defenderSiegeWeapons),
                    new MissionBoundaryPlacer(),
                    new MissionBoundaryCrossingHandler(),
                    new AgentMoraleInteractionLogic(),
                    new HighlightsController(),
                    new BattleHighlightsController(),
                    new AssignPlayerRoleInTeamMissionController(isPlayerGeneral, isPlayerSergeant, hasPlayer, charactersInPlayerSideByPriority?.Select(character => character.StringId).ToList()),
                    new CreateBodyguardMissionBehavior(
                        isPlayerAttacker ? playerTeamGeneralName : enemyTeamGeneralName,
                        !isPlayerAttacker ? playerTeamGeneralName : enemyTeamGeneralName,
                        null, null, false),
                };
                if (isSallyOut)
                {
                    missionBehaviourList.Add(new EnhancedBattleTestSiegeSallyOutMissionSpawnHandler(
                                                 isPlayerAttacker ? enemyParty : playerParty,
                                                 isPlayerAttacker ? playerParty : enemyParty));
                }
                else
                {
                    missionBehaviourList.Add(new EnhancedBattleTestSiegeMissionSpawnHandler(
                                                 isPlayerAttacker ? enemyParty : playerParty,
                                                 isPlayerAttacker ? playerParty : enemyParty));
                    missionBehaviourList.Add(new AgentFadeOutLogic());
                }
                return missionBehaviourList;
            }));
        }
 public SPTroopSupplier(IEnhancedBattleTestCombatant combatant, bool isPlayerSide)
 {
     _combatant    = combatant as SPCombatant;
     _isPlayerSide = isPlayerSide;
     ArrangePriorities();
 }