public override void Step(StateMachine stateMachine, float dt)
 {
     _game.HideSelector = true;
     if (HasMoveBeenConfirmed())
     {
         var destination = _game.GetSelectorCoord(DestinationSelectorDelta);
         _action.TriggerAction(destination);
         stateMachine.SetState(new IdleState());
     }
     else
     {
         MoveDestinationSelector();
     }
 }
Exemple #2
0
 public override void Step(StateMachine stateMachine, float dt)
 {
     _game.HideSelector = false;
     if (HasMoveBeenConfirmed())
     {
         var destination = _game.GetSelectorCoord(DestinationSelectorDelta);
         if (destination != LocationOfItemToMove)
         {
             var sourceIndex      = _driver.Game.TileMap.ToIndex(LocationOfItemToMove); // :(
             var destinationIndex = _driver.Game.TileMap.ToIndex(destination);
             Locator.Get <ConnectionToGridiaServerHandler>().MoveItem(0, 0, sourceIndex, destinationIndex);
         }
         _game.HideSelector = true;
         stateMachine.SetState(new IdleState());
     }
     else
     {
         MoveDestinationSelector();
     }
 }
Exemple #3
0
        public override void Step(StateMachine stateMachine, float dt)
        {
            var numKeyPressed = GetNumberKeyPressed();

            if (numKeyPressed != -1)
            {
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    _driver.TabbedGui.ToggleVisiblity(numKeyPressed - 1);
                }
                else
                {
                    var actionIndex = numKeyPressed == 0 ? 9 : numKeyPressed - 1;
                    _driver.ActionWindow.TriggerAction(actionIndex);
                }
            }

            if (Input.GetKeyUp(KeyCode.T))
            {
                End(stateMachine, dt, new TargetSelectState());
                return;
            }

            if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.LeftAlt))
            {
                End(stateMachine, dt, new ItemMovementState(_game.GetSelectorCoord()));
                return;
            }

            if (Input.GetKeyUp(KeyCode.Tab))
            {
                _driver.MoveSelectedContainerToNext();
            }

            var wasdKeysUp = InputManager.Get4DirectionalWasdInputUp();
            var wasdKeys   = InputManager.Get4DirectionalWasdInput();

            if (wasdKeysUp != Vector3.zero)
            {
                var destinationUp = Locator.Get <GridiaGame>().View.Focus.Position + wasdKeysUp;
                if (Locator.Get <TileMap>().GetCreatureAt(destinationUp) != null || Locator.Get <TileMap>().GetTile(destinationUp).Floor == 0)
                {
                    Locator.Get <ConnectionToGridiaServerHandler>().Hit(destinationUp);
                }
                else if (Locator.Get <TileMap>().GetTile(destinationUp).Item.Item.Class == Item.ItemClass.Container)
                {
                    Locator.Get <ConnectionToGridiaServerHandler>().ContainerRequest(destinationUp);
                }
            }
            else if (wasdKeys != Vector3.zero)
            {
                var destination = _game.View.Focus.Position + wasdKeys;
                if (Locator.Get <TileMap>().Walkable(destination) && !_game.View.Focus.HasAFuturePosition())
                {
                    Locator.Get <GridiaDriver>().RemoveAllOpenContainers();
                    End(stateMachine, dt, new PlayerMovementState(wasdKeys));
                    return;
                }
            }

            var arrowKeysUp = InputManager.Get4DirectionalArrowKeysInputUp();

            if (arrowKeysUp != Vector3.zero)
            {
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    _driver.InvGui.SlotSelectedX += (int)arrowKeysUp.x;
                    _driver.InvGui.SlotSelectedY += (int)-arrowKeysUp.y;
                    _driver.InvGui.SetWindowNameToCurrentSelection();
                }
                else if (_driver.SelectedContainer != null)
                {
                    _driver.SelectedContainer.SlotSelectedX += (int)arrowKeysUp.x;
                    _driver.SelectedContainer.SlotSelectedY -= (int)arrowKeysUp.y;
                }
                else
                {
                    _game.SelectorDelta += arrowKeysUp;
                    _game.HideSelector   = false;
                }
            }

            if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                _game.PickUpItemAtSelection();
            }
            else if (Input.GetKeyUp(KeyCode.Space))
            {
                if (_driver.SelectedCreature == null)
                {
                    _game.UseItemAtSelection(_driver.InvGui.SlotSelected);
                    return;
                }
            }
            else if (Input.GetKeyUp(KeyCode.LeftAlt))
            {
                _game.UseItemAtSelection(-1);
                return;
            }
            else if (Input.GetKeyUp(KeyCode.Q))
            {
                _game.DropItemAtSelection();
            }
            else if (Input.GetKeyUp(KeyCode.E))
            {
                _driver.InvGui.EquipItemAtCurrentSelection();
            }

            // if (Input.GetMouseButtonDown(0))
            // {
            //     var openContainerWithMouseDown = Main.Instance.MouseDownContainer;
            //     if (openContainerWithMouseDown != null)
            //     {
            //         _mouseDownLocation = openContainerWithMouseDown.ContainerId;
            //         _sourceIndex = Main.Instance.MouseDownIndex;
            //         _driver.MouseDownItem = openContainerWithMouseDown.Items[_sourceIndex];
            //     }
            //     else if (!_driver.IsMouseOverGui())
            //     {
            //         _mouseDownLocation = 0;
            //         var downCoord = _driver.GetTileLocationOfMouse();
            //         _driver.MouseDownItem = _driver.Game.TileMap.GetTile((int)downCoord.x, (int)downCoord.y, (int)downCoord.z).Item;
            //         _sourceIndex = _driver.Game.TileMap.ToIndex(downCoord);
            //     }
            // }
            // else if (Input.GetMouseButtonUp(0) && _mouseDownLocation != -1)
            // {
            //     int dest, destIndex;

            //     var openContainerWithMouseUp = Main.Instance.MouseUpContainer;
            //     if (openContainerWithMouseUp != null)
            //     {
            //         dest = openContainerWithMouseUp.ContainerId;
            //         destIndex = Main.Instance.MouseUpIndex;
            //     }
            //     else
            //     {
            //         var tileLocUp = _driver.GetTileLocationOfMouse();
            //         if (tileLocUp == _driver.Game.TileMap.Wrap(_driver.Game.View.Focus.Position))
            //         {
            //             dest = GameState.Instance.InventoryContainerId;
            //             destIndex = -1;
            //         }
            //         else
            //         {
            //             dest = 0;
            //             destIndex = _driver.Game.TileMap.ToIndex(tileLocUp);
            //         }
            //     }

            //     Locator.Get<ConnectionToGridiaServerHandler>().MoveItem(_mouseDownLocation, dest, _sourceIndex, destIndex);

            //     _driver.MouseDownItem =  null;
            //     _mouseDownLocation = -1;
            // }
        }