Published on

Devlog #9 - Combat & Loot

Started off the week getting clicking on sprites working. Used that to send a fight request to the server. Now I'm having the player and the mob's ActorFighters determine if they can fight or not. ActorFighters have a target and a tagged property. Target is what it's fighting and tagged is who started fighting it first. Tagged is mostly so people can't come and steal kills whenever they feel like it. They have to be alone or in a group! So I'm sending the request and it seems things are tagging each other and are ready to do some damage.

Actually first lets deal with the fight request response to the client. The clients in the area will know that two actors got in a fight so we need to show that with a beautiful red line and have the actors look at each other.

Oh god that's too many lines and they're white ahhh.

Ah, that's better, hello red line, old friend.

Now we need to stop fighting if we click the mob again and change targets if we start a new fight. Then it's time to do some damage. But first I decided to have actors move close enough to fight automatically just like in FO. And there they go walking into combat.

Now that we're close enough to fight, let's do some damage. Damage is calculated from attributes that are mostly set in stone for mobs right now. Here's the sneaky calculation for both players and mobs:

(int)(minDmg + random.nextFloat() * (maxDmg - minDmg));

Oh my gosh it's scandalous! The way minDmg and maxDmg are calculated are the real special sauce. And now we can actually do damage. So in the actor update thread we check for in a fight, not moving, target not moving, is it time to attack, and are we close enough to attack. If all those check out then we calculate damage and dole it out. You can see the damage messages coming into the debug console in Chrome in the screenshot below.

Now it's on to checking for death on the server and then letting all the clients know something is dead. We need numbers over head to show damage now but I'm not sure what the best way to do it is so I asked https://forum.babylonjs.com/t/best-way-to-place-gui-objects-on-top-of-a-sprite/39653/1.

Actually, let's make the dead crab tip over so we know he's really dead. Then we'll move on to calculating drops and looting. It rotates but it's not pretty yet. I have to ask another question https://forum.babylonjs.com/t/is-there-a-way-to-set-the-pivot-point-of-a-sprite/39654. And it turns out I have to do pivot points myself.

Now that the crabs are dieing, it's time to add loot. Loot will be calculated when a player clicks on a corpse and that player is allowed to loot the corpse. First we need to go back to the MobDefinitionSpawns table in MySQL and add a new table MobDefinitionSpawnDrops. It will have the MobDefinitionSpawn id, item id, and chance to drop percentage. This way each spawn can have different drops. If I wanted to sneak in a secret low drop rate item, I could make it even more rare by assigning it to only one mob spawn.

I've now added the crab's loot table to MySQL and it's also being loaded into the server. That's great. Now I added code in the MobSpawn to calculate drops from the MobSpawnDefinitionSpawner. I'm laying the groundwork for groups all over the place but will not implement groups until later.

After you kill a mob and it tips over, the first time you click on a mob corpse is when the drops are calculated. At that moment, coins dropped are determined as well and given to the looter automatically. Then we send the loot list to the client to display the loot window.

And that's it for this week. In the upcoming week we will finish looting, add lots of mobs, add lots of spawns, add lots of loot to Noob Island, do some ex p and leveling work, and lots of little bits and pieces here and there.

See you next Friday!

Have Fun & Keep Gaming!

P.S. - We've started discussing a possible Bestiary and how it would work here:
https://discord.com/channels/1076004705773310084/1093786162939838494

As more cool ideas get approved we'll be discussing them in the "approved-ideas" forum on the discord server.