Hopson97 / open-builder

Open "Minecraft-like" game with multiplayer support and Lua scripting support for the both client and server
https://github.com/Hopson97/open-builder/projects/3
GNU General Public License v3.0
700 stars 80 forks source link

Item support #137

Open Hopson97 opened 4 years ago

Hopson97 commented 4 years ago

Describe your suggestion

Adds support for items in the game, as in things the player is able to store in their inventory and hold.

This is a pretty huge thing covering a lot of areas

As far as I can work out, there are 6 item types (Anyone think of anymore?)

  1. Voxel items - Things that are able to placed in the world
  2. Tool items - Things that have some kind ability
  3. Materials - Things that have no ability, and cannot be placed, but can be used as a crafting recipe
  4. Consumables - Things the player is able to consume, (potions, food etc)
  5. Ammo - Things that are used by tools somehow

However, some items would have some overlap in these categories (Eg a "wood" block is both a material and a voxel), so would need some way to deal with this.

On top of this, every time would need to have some kind of "GUI" representation as well, so the player is able to see it in their inventory.

Some item types would be able to be automatically created from other things, for example adding a new voxel type to the game would add a corresponding item.

Implementations ideas [optional]

Create/ Register item types in Lua, somehow automatically does the rest behind the scenes? Not sure

grant-rez commented 4 years ago

I have been thinking about how to represent items for a little bit, and I think I have a pretty good idea for an item/inventory system that will be both flexible and powerful. If things about this design aren't clear please let me know and I can work on clarifying and possibly draw out a diagram that outlines the main classes and their interactions. I am working on my Technical Communications skills in general, so I would appreciate any feedback either way. Anyways, onto my actual idea ...

Overview

Synchronizing Data

Since Open-Builder is a networked, multiplayer game, I made sure to think about how we can serialize the both the items that a server is using as well as the inventory of a player.

The following schemas are json-like objects that are meant to show the structure of how we could send the data.

Inventory Schema:

[
   {
      ItemId: id,
      ItemCount: numItems,
      AttributesData:
      [
         {
            AttributeType: type,
            ConstructorArg1: arg1 (These args are dependent on the AttributeType),
            ConstructorArg2: arg2,
            ...
            ConstructorArgN: argN,
         }
      ]
   },
   {
      ItemId: id,
      ItemCount: numItems,
      AttributesData:
      [
         {
            AttributeType: type,
            ConstructorArg1: arg1 (These args are dependent on the AttributeType),
            ConstructorArg2: arg2,
            ...
            ConstructorArgN: argN,
         }
      ]
   },
   {
      ItemId: 0 (Means that there is no item in this slot)
   }
]

Item Schema

{
   ItemName: “name”,
   ItemId: id,
   ItemTexture: ??? (not quite sure how we want to do this)
   Attributes:
   [
      {
         AtrributeType: type (Probably just a number (enum) that uniquely identifies which derived Attribute this is),
         ConstructorArg1: arg1,
         ConstructorArg2: arg2,
         ...
         ConstructorArgN: argN
      },
      {
         AtrributeType: type (Probably just a number (enum) that uniquely identifies which derived Attribute this is),
         ConstructorArg1: arg1,
         ConstructorArg2: arg2,
         ...
         ConstructorArgN: argN
      }
   ]
}
Hopson97 commented 4 years ago

In terms of a technical post, I think this is really well and neatly laid out, so that's all good :)

For the ideas posted, it's really good. Love the idea of having items keeping a list of attributes, like as you said that would be very scalable. Also like how you thought about ways the sort of "base data" is separated from the individual item data.

Only thing I can really think of is if there is a way to define attributes in the Lua code itself, but that might be complicating things a bit too much so the current ideas are perfectly fine.

So as far as I can tell this is what we have so far in terms of data, using all caps to show the different struct/schema more clear

ITEM - defines the data associated with a type of item, as well as a list of ITEM ATTRIBUTE

ITEM STACK - Contains an Id for an ITEM, the amount in this stack, and a list of ITEM ATTRIBUTE DATA, corresponding to the ITEM ATTRIBUTE list of the ITEM

INVENTORY - Managed list of ITEM STACK, could also be used to store things like the items in chest, etc

ITEM ATTRIBUTE - Contains info about a property of the item, such as it has durability etc

ITEM ATTRIBUTE DATA - Metadata about an attribute of an invidvial ITEMSTACK, such as how much durability is left in it, etc

Have a flight to catch soon so not sure if managed to list everything, please let me know if I did, but the ideas you have posted are looking great so far :)

Thanks!

grant-rez commented 4 years ago

It seems like you summarized what I said pretty well!

I don't have a lot of experience with Lua, but my initial thought is that there would be a specific script that is run when the server starts up that defines the items. I am not too familiar with Lua, but I would think the script to define the items would look something like this (written in Python syntax because I am more familiar with Python):

def defineItems():
    items = ItemList()
    sword = Item("texture_file.png")
    sword.addAttribute("DamageModifier", 10) # add a DamageModifier Attribute with the value 10
    items.addItem(sword)
    return items

Defining all of these things in Lua could get overly verbose, so we could also define them in some file in a standardized format then have Lua read the input from the file. The addAttribute function should basically just call a factory function that returns an Attribute/Component pointer.