Esempio n. 1
0
    public int Update(PlayStateContext context, out bool willSpendTime)
    {
        willSpendTime = false;

        RangeSelectStateContext ctxt = context as RangeSelectStateContext;

        if (ctxt.Input.MoveDir != MoveDirection.None)
        {
            ctxt.RefreshTargetView(ctxt.Input.MoveDir);
        }

        if (ctxt.Input.ActionConfirm || ctxt.Input.RangeStart)
        {
            ctxt.ClearTargetView();
            willSpendTime = ctxt.EntityController.Player.BattleTrait.TryAttackCoords(ctxt.Target);
            return(GameController.PlayStates.Action);
        }

        if (ctxt.Input.ActionCancel)
        {
            ctxt.ClearTargetView();
            return(GameController.PlayStates.Action);
        }

        return(GameController.PlayStates.RangePrepare);
    }
Esempio n. 2
0
    public int Update(PlayStateContext context, out bool willSpendTime)
    {
        willSpendTime = false;

        GameOverStateContext ctxt = context as GameOverStateContext;

        ctxt.Elapsed += Time.deltaTime;

        if (ctxt.Elapsed < ctxt.Delay)
        {
            return(GameController.PlayStates.GameOver);
        }

        if (ctxt.Input.Any)
        {
            ctxt.Controller.Restart();
        }

        return(GameController.PlayStates.GameOver);
    }
Esempio n. 3
0
    public int Update(PlayStateContext contextData, out bool timeWillPass)
    {
        if (Input.GetKeyDown(KeyCode.F4))
        {
            SceneManager.LoadScene(0);
        }
        PlayerActionStateContext actionData       = contextData as PlayerActionStateContext;
        BaseInputController      input            = actionData.Input;
        IMapController           map              = actionData.Map;
        IEntityController        entityController = actionData.EntityController;
        Player player = entityController.Player;

        int nextPlayState = GameController.PlayStates.Action;

        timeWillPass = false;

        if (input.IdleTurn)
        {
            timeWillPass = true;
            actionData.Events.Player.SendIdleTurn();
            return(GameController.PlayStates.Action);
        }

        if (input.RangeStart && player.BattleTrait.RangedAttack)
        {
            timeWillPass = false;
            return(GameController.PlayStates.RangePrepare);
        }

        Vector2Int playerCoords = map.CoordsFromWorld(player.transform.position);


        // GAME SPECIFIC
        if (HandleExtendedActions(actionData, out timeWillPass, out nextPlayState))
        {
            return(nextPlayState);
        }

        Vector2Int offset = map.CalculateMoveOffset(input.MoveDir, playerCoords);

        if (offset != Vector2Int.zero)
        {
            var newPlayerCoords = playerCoords + offset;

            if (!player.ValidMapCoords(newPlayerCoords))
            {
                timeWillPass = actionData.BumpingWallsWillSpendTurn;
            }
            else
            {
                timeWillPass = true;

                // Check interactions
                bool canMove = true;

                // Blockers:
                var blocker = FindBlockingEntityAt(entityController, newPlayerCoords);
                if (blocker != null)
                {
                    if (blocker.BlockingTrait.TryUnlock(player))
                    {
                        player.Coords = newPlayerCoords;
                    }
                    return(nextPlayState);
                }

                bool exit = HandleAdditionalMoveInteractions(actionData, newPlayerCoords, ref nextPlayState, ref canMove);
                if (exit)
                {
                    if (canMove)
                    {
                        player.Coords = newPlayerCoords;
                    }
                    return(nextPlayState);
                }

                if (player.SeesHostilesAtCoords(newPlayerCoords))
                {
                    bool allDefeated = player.AttackCoords(newPlayerCoords);
                    canMove = allDefeated;
                }

                if (canMove)
                {
                    player.Coords = newPlayerCoords;
                }
            }
        }

        // Quick Inventory actions:
        int inventoryIdx = System.Array.FindIndex(input.NumbersPressed, x => x);

        if (inventoryIdx != -1)
        {
            bool dropModifier = input.ShiftPressed;
        }

        return(GameController.PlayStates.Action);
    }
Esempio n. 4
0
 public virtual void Exit(PlayStateContext context)
 {
 }
Esempio n. 5
0
 public virtual void Enter(PlayStateContext context)
 {
 }
Esempio n. 6
0
    public void Exit(PlayStateContext context)
    {
        RangeSelectStateContext rangeContext = ((RangeSelectStateContext)context);

        rangeContext.ClearTargetView();
    }
Esempio n. 7
0
    public void Enter(PlayStateContext context)
    {
        RangeSelectStateContext rangeContext = ((RangeSelectStateContext)context);

        rangeContext.SetupTargetView();
    }