After watching a lot of Youtube videos, I finally decided what I want to do next for Milestone 0.3.0 release coming in about a month.
The main focus will be to implement items that can be picked up and moved into an inventory slot, and then hopefully equip it and use it if I have enough time.
The first part is to create items that can be grabbed by the player.
At this point, you walk up to an item, a message is printed in the debug log to know that you properly have focus on it, and then press the “E” key.
For now the item only destroys itself, but I’ll extend it in the future.
Again, as with other components, I’m using the ability system for the interaction, and the enhanced input system for mapping keys to input actions (in the case, “E” is mapped to IA_Interact)
When the key is pressed, the
Interact function is called on the
Interact System, which in turn creates an event to send to the character. This event has all of the details for the ability system to execute the interaction.
It’s a little extra work to do it this way, but the advantage is in the future I’ll be able to apply animations and other effects to it, as well has have blocking abilities and cooldowns without any additional code (it’s all handled via data properties).
For example, for a blocking ability, I will be able to make it so that while a player is reloading a weapon then he won’t be able to do anything else requiring hands, so I can use
GA_HandsInUse as an ability that is applied while reloading, and then use that ability as a blocker to prevent the player from also grabbing an item while the reload is in progress.
From there, the
GA_Interact ability verifies that the player can interact with the item, and then calls the item’s
Interact function. If successful then the ability is committed, otherwise it’s cancelled.
The advantage of this is that anything done before the cancel can be undone simply by calling the
Verify portion is required in order to prevent cheating. The first part of the
Interact System is primarily executed on the client, but the
Ability is executed on both the client and server. If the server finds out that the player cannot actually interact with the item they’re trying to interact with (possibly some condition exists that hadn’t yet replicated to the client, such as another player picking up the item first), then the server cancels the ability and the client knows that it got cancelled and doesn’t apply the changes made by the ability.