Posted June 17, 2021 by Coke and Code
I thought it'd had been a fairly quiet week, my day job got busier and my kids have been loud and fun. That was until I looked back at my commit log and tried to rationalise what's changed this week. Here we go, there's quite a few - so if theres anything you'd like more detail about please let me know.
Krishna was good enough to produce one of his Patreon updates, pop-culture renditions of his mini-fantasy character. These came along with some new random hair styles which I immediately put in as options to the character creator. Prizes for those that can guess where they each of the new three came from:
Of course, because there were new hair styles at this level I had to add new hairstyles in the portrait images. For one of the few bits of art I've done myself in this project I'm pretty pleased with how they came out.
One of the less interesting but essential parts I'm finding about writing a multiplayer online game is the need to be able to monitor and update the server and the players connected. My admin console is a fairly simple affair, plain old Javascript and HTML, but it does a fine job.
This week I added a bunch of things I found I needed while play testing with some very helpful folks:
This one was particularly interesting, I'd run a poll on Twitter to find out what people thought about chat in online games. A very resounding vocal response of "no, don't do it, it's bad". I took the advice and left it out altogether. However, as soon as a few people started playing it became obvious that they needed some level of chat to allow them to explore together and most of all to have fun.
I didn't want to turn the game server into a glorified chat server so I've limited chat a little:
It's worked out quite well so far. As you can imagine given it was a multiplayer game already adding chat wasn't too much trouble, just passing text through the existing transport layer. The other thing to consider was the swear filter on the chat text which went in before I released it to the main server.
The inventory dialog that was put in last week has been working ok but as more content was added it was clear it wouldn't scale. When loot was first added the inventory rapidly got filled with blue shirts (the first loot item I tested). Monster configuration - the subject of another devlog maybe - defines what any given monster type should drop. However, the inventory dialog could show a maximum of 16 slots which quickly got filled.
I had a lot of blue shirts! Loot was great but it was causing me a few problems, so the first thing I did was to add paging into my inventory - the little green arrows let you go back and forward through the pages of items in your inventory. I'm not sure whether to limit the inventory at all or not - but right now I don't have to worry.
Finally having lots of particular items is a bit of pain to organise. With items like shirts it doesn't matter too much, since you're unlikely to want to keep more than one or two (unless you really love your fashion). On the other hand, in the case of health potions the player will often want to keep a lot so they need to be stackable - that is one item might represent a lot of them like so:
Whether an item can be equipped, whether it's stackable and all the other associated information is driven through data files so it's reasonably easy to add new items.
Next up this week I wanted to get to the point where my NPCs could have dialogue trees and perform actions. In the past I've implemented this a few ways but the best I've found is:
Here's a quick example of how that looks in the case of my single NPC, Alia the healer:
Dissecting the above you can see the dialogue has two pages, a welcome page with options "Thanks" and "Heal" - and a second page after healing has been completed. In the options the "exec" field contains javascript that is run inside the game with a controlled scope that exposes only the operations scripts are allowed to call - closing the dialog, changing the page and because of this NPC a heal function.
Right now this is just proof of concept stuff but the framework feels like its the right level to be expanded on while maintaining a very rapid rate of world development.
The final big thing this week was something that I've been wanting to do for a while. When the player (or any actor, monster, npc) moves in the world the path they follow is generated from an A* path search across a tile based map from the obstacles and objects placed in the world. This has been working well but does leave the player wondering why their character moves so stiffly between locations.
To remedy this I've added path smooth, this is where the tile based path is simplified to straight lines where possible, as shown below.
On the left we have the path that was generated by the tile map based A* algorithm. It's a perfectly acceptable path but does feel a bit awkward to the player. After path smooth the path has been simplified down to a single long move that's still completely valid.
The algorithm I used to do this was roughly:
It's not super efficient but it does work out! So far no huge performance impact but the actor path following code did need a fair bit of rework to follow paths that weren't a unit long.
Wow, did you really read all of that? Thank you :)
If there's something here you feel it's worth me writing more about or something else in the game, let me know in the comments.