Combat And Npcs!
Combat took way longer than I expected.
I quickly began to run into issues with the way I was handling combat positioning. I thought I could rely on the character follow functionality that I talked about in the last post, but it was far too unreliable. Sometimes characters would dance around each other, unable to agree on stationary positions for themselves, because their target (the other character) was also doing the same, just delayed by 1 tick. This behavior was also seen in Runescape, when two players followed each other. In hindsight, since I'm modeling the character movement in a similar style, I should have anticipated it.
I pivoted into a new solution that seems to work well. When two characters begin combat, I create a lightweight combat handler entity. Every tick, it processes combat messages between the combatants and also determines where each one should be standing. Now that the combat positions are calculated on the same tick, the "follow dancing" problem is fixed. You will also notice that I also added a few more prototype cubes and NPCs to spice up combat testing.
There isn't much to say about NPCs yet. They can die and respawn (so can players now, too). The most interesting addition is a refactor I did to allow entities to be defined externally, in a .toml file:
[entity] name = "Giant Rat" model_id = 2 [transform] [npc] [movement] [health] max_hp = 6 [combat] [skills] combat = 1 strength = 1 dexterity = 1 endurance = 1
As you can see from the above entity file, entities can now have skills. There are four skills, and they are combat related: Combat - Determines your hit chance. Strength - Determines the maximum damage your attacks can deal. Dexterity - Determines your dodge chance. Endurance - Determines your block chance and block amount. These are probably all going to change. I just needed some basic skills so I could work on stuff like dodging, blocking, and critical hits.