The MMO Project Part 17: Iten plz

The MMO Project Part 17: Iten plz

Today I hope to finish up the inventory system, at least as far as I can for now. Some things require other features to be implemented first. I also had some ideas about how the skill tree system will work. Got me a page written up with the details sitting in the mound.

I guess I should pick up where I left off yesterday with implementing the items on the server and then work out the client side of it. Then I will finish implementing the Inventory UI.

So the way I am thinking of handling Items in the server is have an Item DB node that loads all items on startup and can pull information from the DB (When I add that) also will have an Item_Rehash() function so I can reload the item info from the DB without a reboot. This Item DB node will have a dict that has the item id as the key and load a script for the item as the value. Which(in theory) will allow me to access the items with ItemId.item_name and stuff like that. I have not yet tried this and I don't know if GDscript will allow it but it is the first idea. It seems to work. Nice.

var item_database = {
	#item ID: load(item)
	"479867df-39dc-4a25-8a79-0d60fd724cfb": preload("res://Items/").new()

This should be good then. I am pretty sure it uses hashing under the hood for dicts so it should be fairly quick to do look-ups like this? I could be wrong. Anyway, I will continue with this for now as it works and there is much to implement before the end of today if I want to get the inventory in and hopefully the board shows up and I could get started working on the maps tomorrow.

First I will write a couple utility functions for the Items node on the server and next I need to make the items on the client.  Functions like Item_Search() to get items by name and return their ID. Stuff that I might need later, you know?

Anyway I need the client to have a sprite for the item and a button that uses the sprite as a texture. The button must also have an overlaid label. If the item is in one of the usable categories, it should be used on click, firing the Use_Item(item_user) code on the server.

So we need the item as a button and the item as a floor object. The floor object comes in later, once the maps are in but I should still do it now so I can create a workflow around item creation. Currently it looks like: Web admin(Create Item and copy ID) -> Server, create script for item, add any functions or properties required, add script to server item DB under Item ID copied from web admin -> Client, Create floor item and item button using same ID. The floor item in the client will go in the Loot folder whereas the Button will be in the Items folder.

What I could maybe do is have one dummy button and instance it for each item in the inventory. Rather than having to create a new button node for each Inventory item. I probably could do the same for the loot node.

Here's the Item button setup with data for Apple. It loads it's texture based on the item_name, can set it's amount label and has a function to update it's count.

This should be created based on the inventory of the player, then added as a child to the inventory slot. Basically the player should load in to the map and then the inventory will be populated by the server with buttons for each item. The buttons themselves are responsible for setting up their tool-tips, amounts and textures.

We just need to loop through the data from the inventory we get from the server, create a button for each, pull the information for each item from the server to set up the buttons and add them as children to the inventory slots.

Of course, the inventory itself will decide where each item goes in it, for now that will be the next open slot. All the client needs to know is the item's name, description and the amount in the inventory. The server will handle the actual inventory management. If the user tried to use an item not in their inventory server-side it would do nothing.

Time for lunch. Then I need to start working out the inventory communications.

Right, fed myself. On to the inventory setup.

So the Character Data should hold the inventory as it is a property of the character. This also gives me a centralized point where all the inventory stuff can be dealt with. The UI will be in charge of only it's display of course. The Character Data will have functions to update the inventory but only based on what the server tells it. All it is responsible for is holding the data and updating it from the server.

There is a ItemInfo singleton that is responsible for querying the server for information on items as the player encounters them each session. This will cache them so they are not constantly being updated needlessly as well as allow me to change items on the server and rehash the item db, then have the player get the updated information next login without needing a patch.

The singleton will add an item ID to a dict as a key, then send an RPC off to the server, which will respond with a dict of it's own containing the name, description and type of item. This will be sent to another function on the ItemInfo singleton that will add the dict to the key of the ID.

Alright, we can now retrieve the inventory from the server, now we just need to use it to populate the inventory UI.

Never underestimate the power of print.

Alright, there was some silly buggers type stuff due to the asynchronous nature of multi-threading but I got over that with a delayed setup call for the initial inventory setup on login.

I got some apples.

Banana loves him some apples.

Now items can be used. They call their own particular Use function and deplete by one, then the database is updated with the new item inventory. Once all items in the stack are used, the inventory clears the button so it can be replaced by a new item.

Found a bug where the inventory is populated with a button for an item that has an amount of 0. I know why this is happening, better fix it. There we go, now if there are 0 in the stack it no longer shows up in the inventory.

Ate all my apples.

I have successfully depleted Cakeman and Banana's apple supplies. Now they have to eat eachother.

Now I need a way to add an item to the inventory. Kromdibular will be used for this. (Cutting it close. It's 4pm)

That went smoother than expected.

Woo, apples! I'm filthy rich!

With that I have completed the goal for today. I went and added some inputs to toggle the inventory window (tab, b, i) and removed the test enemies on the client that were mainly there because I forgot to clean them up a while ago.

I'll push all my changes to the repositories and go relax for a while. This was probably the most complex system so far. The next goal is to implement the server side maps... ohhhhh boy. I wont be able to do that so easily without the whiteboard so hopefully it shows up early tomorrow, if not I will do some work on mantilogs if I have any feature requests. Maybe make it a lazy-ass half day. Play some video games. I do really need to relax more.