Beispiel #1
0
        public void ExecuteAbility(IGameUnit user, IAbility ability, MapPoint targetPoint)
        {
            var targetPoints = ability.AreaPoints.Select(x => x.ApplyOffset(targetPoint.X, targetPoint.Y));

            var foundTargets = _gameMap.FindAllMapObjectsInBounds(out var targets, targetPoints);
            var validTargets = AbilityTargetCalculator.FilterTargets(user, ability, targets);

            // Get a queue of abilities and their execution
            _executionQueue = CreateAbiltyQueue(user, ability, validTargets, targetPoint, _gameMap);

            // Now execute each entry in our queue
            while (_executionQueue.Any())
            {
                var executionParams  = _executionQueue.Dequeue();
                var executionResults = new List <AbilityResultContainer>();

                // If the params doesn't have a target assigned we'll create dupes and populate the targets
                if (executionParams.Target == null)
                {
                    var newParams        = executionParams.AllTargets.Select(x => new AbilityExecuteParameters(executionParams.UnitExecuting, executionParams.AbilityExecuting, x, executionParams.AllTargets, executionParams.TargetPoint, executionParams.GameMap));
                    var newParamsResults = newParams.SelectMany(x => ExecuteAbilityParameters(x)).ToList();
                    executionResults.AddRange(newParamsResults);
                }
                // Otherwise we'll just execute the ability
                else
                {
                    var paramsResults = ExecuteAbilityParameters(executionParams);
                    executionResults.AddRange(paramsResults);
                }

                // DO SOME ANIMATION HERE?

                // ALSO IF A COUNTER HAS A COST IT ISN"T DEDUCTED EVER
            }

            // Now that we executed the ability we need to consume the cost of the ability
            ConsumeAbilityForUnit(user, ability);

            // Check for defeated units
            validTargets.OfType <IGameUnit>().Where(x => x.IsDead()).ForEach(x => RemoveUnit(x));
            if (user.IsDead())
            {
                RemoveUnit(user);
            }
        }
        public void UpdateState()
        {
            // Back button hit: Undo this state
            if (Input.GetMouseButtonDown(1))
            {
                _gameBattle.ClearTopInputState();
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                // Get the current cursor position
                var cursorPoint = _gameMap.GetCursorPosition();
                // Then check if it lines up with the current abilty ranges
                if (_abilityRange.Points.Any(x => x.SameOrigin(cursorPoint)))
                {
                    // We have a cursor and our target offsets, convert the offsets to actual map points
                    var targetPoints = _abilityTargeting.AreaPoints.Select(x => x.ApplyOffset(cursorPoint.X, cursorPoint.Y));
                    // Then see if there's any valid targets
                    var foundTargets = _gameMap.FindAllMapObjectsInBounds(out var targets, targetPoints);
                    var validTarget  = AbilityTargetCalculator.CheckForValidTargets(_unitCasting, _abilityTargeting, targets);
                    if (validTarget)
                    {
                        _gameBattle.AddInputState(_inputStateFactory.ResolveExecuteAbilityState(_unitCasting, _abilityTargeting, cursorPoint.X, cursorPoint.Y));
                        //Debug.Log("Valid target found");
                    }
                    else
                    {
                        Debug.Log("No valid targets found");
                    }
                }
                else
                {
                    Debug.Log("Clicked out of bounds!");
                }
            }
        }