コード例 #1
0
ファイル: InputSystem.cs プロジェクト: Fymir27/RoguelikeECS
        // This function tries to do the following things in order:
        // tries to use an item if inventory is open
        // tries to interact with terrain under player
        // tries to pick up Item
        private void HandleSpacePressed()
        {
            if (UI.InventoryOpen)
            {
                //Console.WriteLine("Space trigger item use!");
                //Console.WriteLine("UsedItemEvent null? " + UsedItemEvent == null);
                UsedItemEvent?.Invoke(Util.PlayerID, EntityManager.GetComponent <InventoryComponent>(Util.PlayerID).Items[UI.InventoryCursorPosition - 1], ItemUsage.Consume);
                return;
            }

            var playerPos = EntityManager.GetComponent <TransformComponent>(Util.PlayerID).Position;

            int terrain = Util.CurrentFloor.GetTerrain(playerPos);

            if (terrain != 0) // is there special terrain?
            {
                var terrainInteraction = EntityManager.GetComponent <InteractableComponent>(terrain);

                if (terrainInteraction != null) // is it interactable?
                {
                    InteractionEvent?.Invoke(Util.PlayerID, terrain);
                    return;
                }
            }

            bool itemsOnFloor = Util.CurrentFloor.GetItems(playerPos).Count() > 0; // are there items here?

            if (!itemsOnFloor)
            {
                UISystem.Message("No items here to be picked up!");
                return;
            }

            PickupItemEvent?.Invoke(Util.PlayerID);
        }
コード例 #2
0
ファイル: PlayerEvents.cs プロジェクト: SynapseSL/SynapseOld
        internal static void InvokePickupItemEvent(Player player, Pickup pickup, ref bool allow)
        {
            if (PickupItemEvent == null)
            {
                return;
            }

            var ev = new PickupItemEvent
            {
                Allow  = allow,
                Pickup = pickup,
                Player = player
            };

            PickupItemEvent.Invoke(ev);

            allow = ev.Allow;
        }
コード例 #3
0
        private void Interact()
        {
            var tile = Util.CurrentFloor.GetTile(Util.GetPlayerPos());

            if (tile.Items != null && tile.Items.Count > 0)
            {
                PickupItemEvent?.Invoke(ControlledEntity);
                return;
            }

            if (tile.Structure != 0)
            {
                var interactableStructure = EntityManager.GetComponent <InteractableComponent>(tile.Structure);

                if (interactableStructure != null)
                {
                    InteractionEvent?.Invoke(Util.PlayerID, tile.Structure);
                    return;
                }
            }
        }