Пример #1
0
    void ToggleCombatDetails(GameObject attacker, GameObject defender, Vector3Int playerPos, Vector3Int enemyPos)
    {
        battle = new BattleSimulation(attacker, defender, playerPos, enemyPos);

        CharacterStats a = attacker.GetComponent <CharacterStats>();
        CharacterStats d = defender.GetComponent <CharacterStats>();

        if (attacker.tag == "Blue" || attacker.tag == "Green")
        {
            PLAYERINFO.GetComponent <CombatPanel>().InitializeInfo(attacker.name, a.GetMaxHealth(), a.GetHealth(),
                                                                   a.GetWeapon(), a.GetArmor(), battle.GetAttackerDamage().ToString(),
                                                                   battle.GetAttackerAccuracy().ToString(), battle.GetAttackerCritDamage().ToString(), battle.GetAttackerAttacks());
            ENEMYINFO.GetComponent <CombatPanel>().InitializeInfo(defender.name, d.GetMaxHealth(), d.GetHealth(),
                                                                  d.GetWeapon(), d.GetArmor(), battle.GetDefenderDamage().ToString(),
                                                                  battle.GetDefenderAccuracy().ToString(), battle.GetDefenderCritDamage().ToString(), battle.GetDefenderAttacks());
        }
        else
        {
            ENEMYINFO.GetComponent <CombatPanel>().InitializeInfo(attacker.name, a.GetMaxHealth(), a.GetHealth(),
                                                                  a.GetWeapon(), a.GetArmor(), battle.GetAttackerDamage().ToString(),
                                                                  battle.GetAttackerAccuracy().ToString(), battle.GetAttackerCritDamage().ToString(), battle.GetAttackerAttacks());
            PLAYERINFO.GetComponent <CombatPanel>().InitializeInfo(defender.name, d.GetMaxHealth(), d.GetHealth(),
                                                                   d.GetWeapon(), d.GetArmor(), battle.GetDefenderDamage().ToString(),
                                                                   battle.GetDefenderAccuracy().ToString(), battle.GetDefenderCritDamage().ToString(), battle.GetDefenderAttacks());
        }
    }
Пример #2
0
 void Start()
 {
     st = SelectState.SelectPlayer;
     bs = BattleSimulation.GetInstance;
     target.SetActive(true);
     SetIndicatorPosition(st == SelectState.SelectEnemy ? true : false);
 }
Пример #3
0
    void BattleWork(object threadParams)
    {
        ThreadParams param = threadParams as ThreadParams;

        try
        {
            foreach (Battleground battleground in terrainManager.battlegrounds)
            {
                for (int i = param.startIndex; i <= param.endIndex; i++)
                {
                    foreach (Creature creatureB in population)
                    {
                        if (population[i] != creatureB)
                        {
                            BattleStats stats = BattleSimulation.Battle(population[i], creatureB, battleground);
                            stats.winner.fitnessValue++;
                            battles++;
                            requiresUIUpdate = true;
                        }
                    }
                }
            }
        }
        finally
        {
            param.currentHandle.Set();
        }
    }
Пример #4
0
    float CalculateRating(BattleSimulation battle)
    {
        float damageDealt = (float)battle.GetAttackerDamage();
        float accuracy    = (float)battle.GetAttackerAccuracy();
        float attacks     = (float)battle.GetAttackerAttacks();

        return(attacks * damageDealt * accuracy * 0.01f);
    }
Пример #5
0
 public BattleSimulationDebugController(BattleSimulation simulation, BattleSimulationUI ui,
                                        AiContext context, PlayerContext playerContext,
                                        PlayerPresenterContext playerPresenterContext,
                                        RealtimeBattleSimulationController realtimeBattleSimulationController,
                                        BattleSimulationPresenter simulationPresenter)
 {
     this.simulation                         = simulation;
     this.ui                                 = ui;
     this.context                            = context;
     this.playerContext                      = playerContext;
     this.playerPresenterContext             = playerPresenterContext;
     this.realtimeBattleSimulationController = realtimeBattleSimulationController;
     this.simulationPresenter                = simulationPresenter;
 }
Пример #6
0
    EnemyDecision FindBestAttackAt(Vector3Int move)
    {
        UnitTracker       ut = GetComponent <UnitTracker>();
        List <Vector3Int> possibleAttacks = ut.PossibleAttacksAtTile(move);
        Vector3Int        bestAttack      = new Vector3Int(-1, -1, -1);
        float             bestRating      = 0;
        bool freeAttackFound = false;

        foreach (Vector3Int attack in possibleAttacks)
        {
            if (TileManager.instance.allUnits.ContainsKey(attack) && TileManager.instance.allUnits[attack].tag != tag)
            {
                GameObject       target = TileManager.instance.allUnits[attack];
                BattleSimulation battle = new BattleSimulation(gameObject, target, move, target.GetComponent <UnitTracker>().GetLocation());

                if (!freeAttackFound && battle.GetDefenderAttacks() == 0)
                {
                    freeAttackFound = true;
                    bestRating      = CalculateRating(battle);
                    bestAttack      = attack;
                }
                else if (!freeAttackFound && battle.GetDefenderAttacks() != 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestAttack = attack;
                    }
                }
                else if (battle.GetDefenderAttacks() == 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestAttack = attack;
                    }
                }
            }
        }

        return(new EnemyDecision(bestAttack));
    }
Пример #7
0
    Vector3Int WhereToAttack(List <Vector3Int> possibleAttackMoves, GameObject target)
    {
        Vector3Int bestMove        = new Vector3Int(-1, -1, -1);
        float      bestRating      = 0;
        bool       freeAttackFound = false;

        foreach (Vector3Int move in possibleAttackMoves)
        {
            BattleSimulation battle = new BattleSimulation(gameObject, target, move, target.GetComponent <UnitTracker>().GetLocation());
            if (!TileManager.instance.allUnits.ContainsKey(move))
            {
                if (!freeAttackFound && battle.GetDefenderAttacks() == 0)
                {
                    freeAttackFound = true;
                    bestRating      = CalculateRating(battle);
                    bestMove        = move;
                }
                else if (!freeAttackFound && battle.GetDefenderAttacks() != 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestMove   = move;
                    }
                }
                else if (battle.GetDefenderAttacks() == 0)
                {
                    float tempRating = CalculateRating(battle);
                    if (tempRating > bestRating)
                    {
                        bestRating = tempRating;
                        bestMove   = move;
                    }
                }
            }
        }

        return(bestMove);
    }
Пример #8
0
        IEnumerator Start()
        {
            #region Config

            log.Info("\n\nStart");
            var units                 = new UnitInfoLoader().Load();
            var saveDataLoader        = new SaveInfoLoader();
            var saves                 = saveDataLoader.Load();
            var decisionTreeLoader    = new DecisionTreeLoader();
            var decisionTreeComponent = decisionTreeLoader.Load();

            #endregion
            #region Infrastructure

            var tickController  = new TickController();
            var inputController = new InputController(tickController);
            //TODO: implement event bus that won't allocate(no delegates)
            var eventBus = new EventBus();            //TODO: stop using eventbus Ievent interface to remove reference on that library from model
            EventBus.Log     = m => log.Info($"{m}"); //TODO: remove that lmao
            EventBus.IsLogOn = () => DebugController.Info.IsDebugOn;

            #endregion
            #region View

            var mainCamera                  = Camera.main;
            var tileSpawner                 = new TilePresenter(TileStartPoints, new TileViewFactory(TileViewPrefab));
            var coordFinder                 = new CoordFinder(TileStartPoints);
            var unitViewFactory             = new UnitViewFactory(units, UnitViewPrefab, coordFinder, mainCamera);
            var unitViewCoordChangedHandler = new UnitViewCoordChangedHandler(coordFinder);
            var boardPresenter              = new BoardPresenter(unitViewCoordChangedHandler);

            var playerPresenterContext = new PlayerPresenterContext(
                new PlayerPresenter(unitViewFactory, unitViewCoordChangedHandler),
                new PlayerPresenter(unitViewFactory, unitViewCoordChangedHandler));

            #endregion
            #region Model
            var decisionTreeLookup = new DecisionTreeLookup();

            var decisionTreeCreatorVisitor = new DecisionTreeCreatorVisitor(eventBus,
                                                                            d => new LoggingDecorator(d, DebugController.Info), decisionTreeLookup);

            var unitFactory = new UnitFactory(units, new DecisionFactory(
                                                  decisionTreeCreatorVisitor, decisionTreeComponent));

            //TODO: replace board/bench dictionaries with array?
            var playerContext = new PlayerContext(new Player(unitFactory), new Player(unitFactory));
            var board         = new Board();
            var aiHeap        = new AiHeap();
            var aiContext     = new AiContext(board, aiHeap);

            #endregion
            #region Shared

            var worldContext = new PlayerSharedContext(playerContext, playerPresenterContext, BattleSetupUI);

            #endregion
            #region Controller

            var raycastController = new RaycastController(mainCamera,
                                                          LayerMask.GetMask("Terrain", "GlobalCollider"), LayerMask.GetMask("Unit"));

            var unitSelectionController = new UnitSelectionController(inputController,
                                                                      raycastController, coordFinder);

            var unitTooltipController = new UnitTooltipController(UnitTooltipUI,
                                                                  unitSelectionController);

            #endregion
            #region Unit drag

            var battleStateController = new BattleStateController(BattleSimulationUI);
            var unitDragController    = new UnitDragController(raycastController,
                                                               new CoordFinderBySelectedPlayer(coordFinder, BattleSetupUI),
                                                               inputController, unitSelectionController,
                                                               new CanStartDrag(battleStateController, BattleSetupUI));

            var tileHighlightController = new TileHighlighterController(tileSpawner,
                                                                        unitDragController);

            var unitMoveController = new UnitMoveController(worldContext, unitDragController);

            #endregion
            #region Battle simulation

            var movementController  = new MovementController(boardPresenter, coordFinder);
            var attackController    = new AttackController(boardPresenter, unitTooltipController);
            var animationController = new AnimationController(boardPresenter);
            eventBus.Register <StartMoveEvent>(movementController, animationController); //TODO: register implicitly?
            eventBus.Register <FinishMoveEvent>(movementController);
            eventBus.Register <RotateEvent>(movementController);
            eventBus.Register <UpdateHealthEvent>(attackController);
            eventBus.Register <DeathEvent>(attackController);
            eventBus.Register <IdleEvent>(animationController);
            eventBus.Register <StartAttackEvent>(animationController);

            var battleSimulationPresenter = new BattleSimulationPresenter(coordFinder,
                                                                          boardPresenter, movementController, movementController);

            var battleSimulation = new BattleSimulation(aiContext, board, aiHeap);

            var realtimeBattleSimulationController = new RealtimeBattleSimulationController(
                movementController, battleSimulation);

            #endregion
            #region Debug

            var battleSimulationDebugController = new BattleSimulationDebugController(
                battleSimulation, BattleSimulationUI,
                aiContext, playerContext, playerPresenterContext, realtimeBattleSimulationController,
                battleSimulationPresenter);

            var battleSaveController = new BattleSaveController(playerContext,
                                                                playerPresenterContext, BattleSaveUI, saveDataLoader, saves,
                                                                battleSimulationDebugController);

            var battleSetupController = new BattleSetupController(playerContext,
                                                                  playerPresenterContext, BattleSetupUI);

            var unitModelDebugController = new UnitModelDebugController(playerContext, board, ModelUI,
                                                                        DebugController.Info, unitSelectionController);

            var takenCoordDebugController = new TakenCoordDebugController(board, DebugController,
                                                                          tileSpawner);

            var targetDebugController = new TargetDebugController(
                board, coordFinder, DebugController.Info);

            var uiDebugController = new UIDebugController(
                BattleSetupUI, BattleSaveUI, BattleSimulationUI,
                unitModelDebugController);

            #endregion

            yield return(null);

            #region Infrastructure

            tickController.InitObservable(takenCoordDebugController, targetDebugController,
                                          uiDebugController, unitModelDebugController, realtimeBattleSimulationController,
                                          DebugController); //TODO: register implicitly?
            inputController.InitObservables();

            #endregion
            #region View

            BattleSetupUI.SetDropdownOptions(units.Keys.ToList());
            BattleSaveUI.SubToUI(saves.Keys.ToList());
            tileSpawner.SpawnTiles();

            #endregion
            decisionTreeCreatorVisitor.Init();
            #region Controller

            unitSelectionController.SubToInput(disposable);
            battleStateController.SubToUI();
            unitDragController.SubToUnitSelection(disposable);
            tileHighlightController.SubToDrag(disposable);
            unitMoveController.SubToDrag(disposable);
            unitTooltipController.SubToUnitSelection(disposable);

            #endregion
            #region Debug

            battleSaveController.SubToUI();
            battleSetupController.SubToUI();
            unitModelDebugController.SubToUnitSelection(disposable);
            battleSimulationDebugController.SubToUI();
            DebugController.Init(UnitTooltipUI);

            #endregion

            MonoBehaviourCallBackController.StartUpdating(tickController);
        }
Пример #9
0
    EnemyDecision FindBestMoveAttack(List <Vector3Int> possibleMoves)
    {
        UnitTracker ut = GetComponent <UnitTracker>();

        if (possibleMoves.Count == 0)
        {
            return(FindBestAttackAt(ut.GetLocation()));
        }

        Vector3Int bestMove        = new Vector3Int(-1, -1, -1);
        Vector3Int bestAttack      = new Vector3Int(-1, -1, -1);
        float      bestRating      = 0;
        bool       freeAttackFound = false;

        foreach (Vector3Int move in possibleMoves)                                                                         //Loop through every possible move a character can make
        {
            foreach (Vector3Int attack in ut.PossibleAttacksAtTile(move))                                                  //Loop through every possible attack at each move
            {
                if (TileManager.instance.allUnits.ContainsKey(attack) && TileManager.instance.allUnits[attack].tag != tag) //Check to see if there is an attackable unit
                {
                    GameObject       target = TileManager.instance.allUnits[attack];
                    BattleSimulation battle = new BattleSimulation(gameObject, target, move, target.GetComponent <UnitTracker>().GetLocation());
                    if (!TileManager.instance.allUnits.ContainsKey(move))
                    {
                        if (!freeAttackFound && battle.GetDefenderAttacks() == 0)
                        {
                            freeAttackFound = true;
                            bestRating      = CalculateRating(battle);
                            bestMove        = move;
                            bestAttack      = attack;
                        }
                        else if (!freeAttackFound && battle.GetDefenderAttacks() != 0)
                        {
                            float tempRating = CalculateRating(battle);
                            if (tempRating > bestRating)
                            {
                                bestRating = tempRating;
                                bestMove   = move;
                                bestAttack = attack;
                            }
                        }
                        else if (battle.GetDefenderAttacks() == 0)
                        {
                            float tempRating = CalculateRating(battle);
                            if (tempRating > bestRating)
                            {
                                bestRating = tempRating;
                                bestMove   = move;
                                bestAttack = attack;
                            }
                        }
                    }
                }
            }
        }

        if (bestMove.z == -1 && bestAttack.z == -1)
        {
            return(new EnemyDecision());
        }
        List <Vector3Int> path = ShortestPath.instance.FindPath(gameObject.GetComponent <UnitTracker>().GetLocation(), bestMove, "Red");

        return(new EnemyDecision(path, bestAttack));
    }
Пример #10
0
 void Awake()
 {
     Instance = this;
 }
Пример #11
0
 public BattleActionController(BattleSimulation battleSimulation)
 {
     this.Simulation = battleSimulation;
 }
Пример #12
0
 public BattleTargetingController(IWorldPositionningService worldPositionningService, IPathfindingService pathfindingService, BattleSimulation battleSimulation)
 {
     if (worldPositionningService == null)
     {
         throw new ArgumentNullException("worldPositionningService");
     }
     if (pathfindingService == null)
     {
         throw new ArgumentNullException("pathfindingService");
     }
     this.worldPositionningService         = worldPositionningService;
     this.pathfindingService               = pathfindingService;
     this.targettingAnimationCurveDatabase = Databases.GetDatabase <Amplitude.Unity.Framework.AnimationCurve>(false);
     if (this.targettingAnimationCurveDatabase == null)
     {
         Diagnostics.Assert("Can't retrieve the animationCurve database.", new object[0]);
     }
     this.battleTargetingUnitBehaviorWeightDatabase = Databases.GetDatabase <BattleTargetingUnitBehaviorWeight>(false);
     if (this.battleTargetingUnitBehaviorWeightDatabase == null)
     {
         Diagnostics.Assert("Can't retrieve the unit behavior weight database, please reimport BehaviorWeight/BattleTargetingUnitBehaviorWeight.xls.", new object[0]);
     }
     this.battleSimulation           = battleSimulation;
     this.paramsComputationDelegates = new Dictionary <StaticString, BattleTargetingController.ParamComputationDelegate>();
     this.paramsComputationDelegates.Add("TurnsToReachTargetWithCapacities", new BattleTargetingController.ParamComputationDelegate(this.GetNumberOfTurnToReachTargetWithCapacities));
     this.paramsComputationDelegates.Add("TurnsToReachTargetAsCrowFlies", new BattleTargetingController.ParamComputationDelegate(this.GetNumberOfTurnToReachTargetByAir));
     this.paramsComputationDelegates.Add("TargetHPRatio", new BattleTargetingController.ParamComputationDelegate(this.GetTargetHPRatio));
     this.paramsComputationDelegates.Add("DoesTargetHaveFullHP", new BattleTargetingController.ParamComputationDelegate(this.GetDoesTargetHaveFullHP));
     this.paramsComputationDelegates.Add("TargetLostHPRatio", new BattleTargetingController.ParamComputationDelegate(this.GetTargetLostHPRatio));
     this.paramsComputationDelegates.Add("TargetRatioOfOffensiveMilitaryPowerToBattleAverage", new BattleTargetingController.ParamComputationDelegate(this.GetTargetOffensiveMilitaryPowerRatio));
     this.paramsComputationDelegates.Add("TargetRatioOfDefensiveMilitaryPowerToBattleAverage", new BattleTargetingController.ParamComputationDelegate(this.GetTargetDefensiveMilitaryPowerRatio));
     this.paramsComputationDelegates.Add("TargetMorale", new BattleTargetingController.ParamComputationDelegate(this.GetTargetMorale));
     this.paramsComputationDelegates.Add("RatioOfTargetSpeedToBattleArea", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfTargetSpeedToBattleArea));
     this.paramsComputationDelegates.Add("WithinAttackRange", new BattleTargetingController.ParamComputationDelegate(this.GetWithinAttackRange));
     this.paramsComputationDelegates.Add("WithinMovementRange", new BattleTargetingController.ParamComputationDelegate(this.GetWithinMovementRange));
     this.paramsComputationDelegates.Add("WithinAttackAndMoveRange", new BattleTargetingController.ParamComputationDelegate(this.GetWithinAttackAndMoveRange));
     this.paramsComputationDelegates.Add("RatioDistanceToAttackAndMoveRange", new BattleTargetingController.ParamComputationDelegate(this.GetRatioDistanceToAttackAndMoveRange));
     this.paramsComputationDelegates.Add("NumberOfNegativeGroundEffectsAtTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetNumberOfNegativeGroundBattleActionsAtTargetPosition));
     this.paramsComputationDelegates.Add("NumberOfPositiveGroundEffectsAtTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetNumberOfPositiveGroundBattleActionsAtTargetPosition));
     this.paramsComputationDelegates.Add("IsMyBattleEffectAppliedOnTarget", new BattleTargetingController.ParamComputationDelegate(this.IsMyBattleEffectAppliedOnTarget));
     this.paramsComputationDelegates.Add("IsTargetUnitClassMelee", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassMelee));
     this.paramsComputationDelegates.Add("IsTargetUnitClassCavalry", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassCavalry));
     this.paramsComputationDelegates.Add("IsTargetUnitClassRanged", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassRanged));
     this.paramsComputationDelegates.Add("IsTargetUnitClassFlying", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassFlying));
     this.paramsComputationDelegates.Add("IsTargetUnitClassSupport", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassSupport));
     this.paramsComputationDelegates.Add("IsTargetUnitClassInterceptor", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassInterceptor));
     this.paramsComputationDelegates.Add("IsTargetUnitClassFrigate", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassFrigate));
     this.paramsComputationDelegates.Add("IsTargetUnitClassJuggernaut", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassJuggernaut));
     this.paramsComputationDelegates.Add("IsTargetUnitClassSubmersible", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetUnitClassSubmersible));
     this.paramsComputationDelegates.Add("IsTargetTransportShipUnit", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetTransportShipUnit));
     this.paramsComputationDelegates.Add("DoesTargetPlaysBeforeMe", new BattleTargetingController.ParamComputationDelegate(this.GetDoesTargetPlaysBeforeMe));
     this.paramsComputationDelegates.Add("RatioOfOpponentsAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfOpponentsAroundTargetPosition));
     this.paramsComputationDelegates.Add("RatioOfOpponentsAroundTargetPositionWhoPlayAfterMe", new BattleTargetingController.ParamComputationDelegate(this.RatioOfOpponentsAroundTargetPositionWhoPlayAfterMe));
     this.paramsComputationDelegates.Add("IsNoEnemyAroundTargetPositionWhoPlaysAfterMe", new BattleTargetingController.ParamComputationDelegate(this.IsNoEnemyAroundTargetPositionWhoPlaysAfterMe));
     this.paramsComputationDelegates.Add("RatioOfAlliesAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfAlliesAroundTargetPosition));
     this.paramsComputationDelegates.Add("IsTargetHigher", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetHigher));
     this.paramsComputationDelegates.Add("IsTargetLower", new BattleTargetingController.ParamComputationDelegate(this.GetIsTargetLower));
     this.paramsComputationDelegates.Add("RatioOfTargetAltitudeToMyAltitude", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfTargetAltitudeToMyAltitude));
     this.paramsComputationDelegates.Add("RatioMyAttackToTargetDefense", new BattleTargetingController.ParamComputationDelegate(this.GetRatioMyAttackToTargetDefense));
     this.paramsComputationDelegates.Add("RatioMyDefenseToTargetAttack", new BattleTargetingController.ParamComputationDelegate(this.GetRatioMyDefenseToTargetAttack));
     this.paramsComputationDelegates.Add("RatioOfHigherNeighboursAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfHigherNeighboursAroundTargetPosition));
     this.paramsComputationDelegates.Add("RatioOfLowerNeighboursAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfLowerNeighboursAroundTargetPosition));
     this.paramsComputationDelegates.Add("RatioOfWalkableNeighboursAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfWalkableNeighboursAroundTargetPosition));
     this.paramsComputationDelegates.Add("RatioOfImpassableNeighboursAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfImpassableNeighboursAroundTargetPosition));
     this.paramsComputationDelegates.Add("RatioOfAllyTargettedNeighboursAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfAllyTargettedNeighboursAroundTargetPosition));
     this.paramsComputationDelegates.Add("RatioOfEnemyTargettedNeighboursAroundTargetPosition", new BattleTargetingController.ParamComputationDelegate(this.GetRatioOfEnemyTargettedNeighboursAroundTargetPosition));
     this.paramsComputationDelegates.Add("TargetedByAlliesCount", new BattleTargetingController.ParamComputationDelegate(this.GetTargetedByAlliesCount));
     this.paramsComputationDelegates.Add("TargetedByAlliesWithMyBodyCount", new BattleTargetingController.ParamComputationDelegate(this.GetTargetedByAlliesWithMyBodyCount));
     this.paramsComputationDelegates.Add("NumberOfAliveOpponents", new BattleTargetingController.ParamComputationDelegate(this.GetNumberOfAliveOpponents));
     this.paramsComputationDelegates.Add("OpponentsDebufferRatio", new BattleTargetingController.ParamComputationDelegate(this.GetOpponentsDebufferRatio));
     this.paramsComputationDelegates.Add("RatioOfOpponentsToAllies", new BattleTargetingController.ParamComputationDelegate(this.RatioOfOpponentsToAllies));
     this.paramsComputationDelegates.Add("RatioOfAlliesToOpponents", new BattleTargetingController.ParamComputationDelegate(this.RatioOfAlliesToOpponents));
     this.filtersComputationDelegates = new Dictionary <StaticString, BattleTargetingController.FilterComputationDelegate>();
     this.filtersComputationDelegates.Add("CanAttackWithoutMoving", new BattleTargetingController.FilterComputationDelegate(this.CanAttackWithoutMoving));
     this.filtersComputationDelegates.Add("IsEnemy", new BattleTargetingController.FilterComputationDelegate(this.IsEnemy));
     this.filtersComputationDelegates.Add("IsAlly", new BattleTargetingController.FilterComputationDelegate(this.IsAlly));
     this.filtersComputationDelegates.Add("IsGroundUnit", new BattleTargetingController.FilterComputationDelegate(this.IsGroundUnit));
     this.filtersComputationDelegates.Add("IsFreePosition", new BattleTargetingController.FilterComputationDelegate(this.IsFreePosition));
     this.filtersComputationDelegates.Add("IsUnit", new BattleTargetingController.FilterComputationDelegate(this.IsUnit));
     this.filtersComputationDelegates.Add("IsNotMe", new BattleTargetingController.FilterComputationDelegate(this.IsNotMe));
     this.filtersComputationDelegates.Add("IAmCombatUnit", new BattleTargetingController.FilterComputationDelegate(this.IAmCombatUnit));
     this.filtersComputationDelegates.Add("IAmInLightForm", new BattleTargetingController.FilterComputationDelegate(this.IAmInLightForm));
     this.filtersComputationDelegates.Add("IAmInDarkForm", new BattleTargetingController.FilterComputationDelegate(this.IAmInDarkForm));
     this.filtersComputationDelegates.Add("AlliesArePresent", new BattleTargetingController.FilterComputationDelegate(this.AlliesArePresent));
     this.filtersComputationDelegates.Add("IsTargetWithinMovementRange", new BattleTargetingController.FilterComputationDelegate(this.IsTargetWithinMovementRange));
     this.filtersComputationDelegates.Add("CanTargetBeDebuffed", new BattleTargetingController.FilterComputationDelegate(this.CanTargetBeDebuffed));
     this.filtersComputationDelegates.Add("IsTargetNotMindControlled", new BattleTargetingController.FilterComputationDelegate(this.IsTargetNotMindControlled));
     this.filtersComputationDelegates.Add("AnyAliveOpponents", new BattleTargetingController.FilterComputationDelegate(this.AnyAliveOpponents));
     this.filtersComputationDelegates.Add("IAmTransportShip", new BattleTargetingController.FilterComputationDelegate(this.IAmTransportShip));
     this.filtersComputationDelegates.Add("IAmNotTransportShip", new BattleTargetingController.FilterComputationDelegate(this.IAmNotTransportShip));
 }
Пример #13
0
    public void ExecuteWaitingActions(BattleSimulation battleSimulation, RoundReport roundReport)
    {
        BattleSimulationUnit battleSimulationUnit = this.Units.FirstOrDefault((BattleSimulationUnit match) => match.Position.IsValid);

        if (battleSimulationUnit == null)
        {
            return;
        }
        List <IUnitReportInstruction> list = new List <IUnitReportInstruction>();

        for (int i = 0; i < this.WaitingArmyActions.Count; i++)
        {
            int num = BattleSimulation.UnitStateNextID++;
            BattleArmyAction           battleArmyAction           = this.WaitingArmyActions[i];
            ContenderActionInstruction contenderActionInstruction = battleArmyAction.BuildContenderActionInstruction(this.ContenderGUID, num, battleSimulationUnit.UnitGUID);
            WorldOrientation           orientation = this.Contender.WorldOrientation;
            if (contenderActionInstruction is ContenderActionSpellInstruction)
            {
                orientation = this.Contender.Deployment.DeploymentArea.Forward;
            }
            if (contenderActionInstruction != null)
            {
                contenderActionInstruction.AddEffectPosition(battleArmyAction.TargetPosition);
                BattleSimulationTarget[] currentTargets = new BattleSimulationTarget[]
                {
                    new BattleSimulationTarget(battleArmyAction.TargetPosition)
                };
                for (int j = 0; j < battleArmyAction.BattleActions.Count; j++)
                {
                    BattleAction battleAction = battleArmyAction.BattleActions[j];
                    for (int k = 0; k < battleAction.BattleEffects.Length; k++)
                    {
                        BattleEffects battleEffects = battleAction.BattleEffects[k];
                        if (battleEffects is BattleEffectsArea)
                        {
                            IPathfindingArea area = (battleEffects as BattleEffectsArea).GetArea(battleArmyAction.TargetPosition, orientation, null, battleSimulation.WorldParameters, battleSimulation.BattleZone, battleSimulationUnit);
                            if (area != null)
                            {
                                WorldPosition[] worldPositions = area.GetWorldPositions(battleSimulation.WorldParameters);
                                if (worldPositions != null)
                                {
                                    contenderActionInstruction.AddEffectArea(worldPositions);
                                }
                            }
                        }
                    }
                    WorldOrientation orientation2 = battleSimulationUnit.Orientation;
                    battleSimulationUnit.Orientation = orientation;
                    battleSimulation.BattleActionController.ExecuteBattleAction(battleAction, battleAction.BattleEffects, battleSimulationUnit, currentTargets, true, list);
                    battleSimulationUnit.Orientation = orientation2;
                    battleSimulation.CheckUnitsDeath(num);
                }
                for (int l = 0; l < list.Count; l++)
                {
                    contenderActionInstruction.AddReportInstruction(list[l]);
                }
                roundReport.ReportInstruction(this.ContenderGUID, contenderActionInstruction);
            }
        }
        this.ClearWaitingActions();
    }
Пример #14
0
 public RealtimeBattleSimulationController(ISimulationTick viewSimulation,
                                           BattleSimulation simulation)
 {
     this.viewSimulation = viewSimulation;
     this.simulation     = simulation;
 }