Ejemplo n.º 1
0
    public override UnitState HandleInput(Controller controller)
    {
        var swappedAbility = SwapActiveAbility(controller);

        if (swappedAbility != null)
        {
            BoardVisuals.RemoveTilesFromHighlightsByUnit(Owner);
            CleanIndicator();
            return(swappedAbility);
        }

        List <PathfindingData> tilesInRange = GetTilesInRange();

        // handling a special case where the targetting is programmatic.
        // will ecentually need to accomodate for this in a more robust way using OOP
        if (abilityComponent.CurrentAbility.AutoTargets)
        {
            PathfindingData autoTarget = tilesInRange.FirstOrDefault(
                element => element.tile.IsOccupied() && element.tile.OccupiedBy.GetComponent <Monster> ()
                );

            if (autoTarget == null)
            {
                AudioComponent.PlaySound(Sounds.ERROR);
                onAbilityCanceled();
                return(new PlayerIdleState(Owner));
            }

            if (Owner.EnergyComponent.AdjustEnergy(-abilityComponent.CurrentAbility.EnergyCost) &&
                abilityComponent.PrepAbility(tilesInRange, autoTarget))
            {
                onAbilityCommited(Owner, abilityComponent.IndexOfCurrentAbility());
                return(new PlayerActingState(Owner, tilesInRange, autoTarget));
            }
        }

        Point mousePosition = BoardUtility.mousePosFromScreenPoint();

        HighlightTiles(tilesInRange, mousePosition);

        // user clicks on a walkable tile which is in range....
        if (controller.DetectInputFor(ControlTypes.CONFIRM))
        {
            PathfindingData selectedTarget = tilesInRange.Find(
                element => element.tile.Position == mousePosition
                );

            // transition to acting state if it's a valid selection
            // and we successfully prep our ability for use
            bool targetIsValid = selectedTarget != null && selectedTarget.tile.isWalkable;
            if (targetIsValid && Owner.EnergyComponent.AdjustEnergy(-abilityComponent.CurrentAbility.EnergyCost) &&
                abilityComponent.PrepAbility(tilesInRange, selectedTarget))
            {
                onAbilityCommited(Owner, abilityComponent.IndexOfCurrentAbility());
                return(new PlayerActingState(Owner, tilesInRange, selectedTarget));
            }
        }

        return(null);
    }
Ejemplo n.º 2
0
 private bool NoValidActionsAreAvailable(PlanOfAction plan)
 {
     return(plan == null ||
            !abilityComponent.CurrentAbility ||
            !Owner.EnergyComponent.AdjustEnergy(-abilityComponent.CurrentAbility.EnergyCost) ||
            !abilityComponent.PrepAbility(plan.tilesInRange, plan.targetLocation));
 }