[14] Equipment

01/02/2020, 10:41pm

Equipment was a pain. The inventory was already a complex piece of state, and equipment just added more stuff to keep track of. I also had to rework the UI on the client to accomodate this. Now there's a little tabbed menu, with 3 pages: Character, Gear, and Settings. I haven't gotten to make many new models or textures for the equipment yet.

Item Types & Attributes

Item resources now support an an item type, and slot (if the item is equippable). You can also specify a simple attributes table, which allows items to have configurable attributes such as damage, armor, and a healing amount (for consumables). Here's what the item file for the rusty axe looks like:

rusty-axe.toml id = 8 [item] name = "Rusty Axe" description = "Dull, but will chop stuff." type = "weapon" slot = "mainhand" model_id = 0 is_stackable = false [attributes] damage = 1

Most of the code was tiny refactors and packet additions, so here's a changelist to sum it up quickly.

  • Server: Updated item database schema
  • Server: Added weapon and armor item types
  • Server: Added 'slot' field to item definitions (for weapons and armor)
  • Server: Added item attribute table to item definitions
  • Server: Added EntityState::Inventory
  • Server: Updated combat to take equipment damage and armor into account
  • Server: Updated block mechanic to only work if you have a shield equipped
  • Client: Added button to equip items in inventory
  • Client: Added tab menu UI, with character, gear, and settings tab
  • Common: Added a few new items including a shield
  • Common: Updated InventoryPacket to include equipment stats
  • Common: Added InventoryUseRequestPacket, InventoryEquipPacket, InventoryUnequipRequestPacket, InventoryUnequipPacket

New Packets

Client - 0x19 (25) - Inventory Use Request bag_slot: u8 (1 byte) Server - 0x19 (25) - Inventory Equip bag_slot: u8 (1 byte) dest_equipment_slot: u8 (1 byte) new_damage: u32 (4 bytes) new_armor: u32 (4 bytes) Client - 0x1A (26) - Inventory Unequip Request equipment_slot: u8 (1 byte) Server - 0x1A (26) - Inventory Unequip equipment_slot: u8 (1 byte) dest_bag_slot: u8 (1 byte) new_damage: u32 (4 bytes) new_armor: u32 (4 bytes)

Having a full gear set makes it pretty easy to take on the King Chonkrat, the main threat in this test world. Although, I did hack in a better weapon for extra damage. I need to add some more NPCs that drop loot.

Was having fun with the world editor and made this little island. I want to get back to the terrain code soon and start making the world much larger.