Declan Hopkins

software & game developer

[1] Starting To Implement Combat

06/15/2019, 05:12pm

I've been slowly starting to roll on the combat implementation. It's complex enough of a feature that other blocking issues in the codebase are starting to manifest. For example, my packet routing code (from the game world to the network) only allows entities to send packets to all connected clients. I need to make a small modification to allow targeted packets, so that the server can send combat text (in the form of chat messages) and other state info to individual clients when they attack or get attacked.

Players can now initiate combat with the giant rats in Antorum, and they will trade hits for 1 damage each. This is the first code going in here where two entities interact, so it's taking a bit of experimentation. I ended up finding shrev, a cool little event channel crate, particularly handy in this cross-entity interaction. When combat begins between entity A and B, an AttackEvent is sent to both of them, updating their combat state. I handle "turns" by simply pre-calculating the next "attack tick" when an attack should occur. When the CombatSystem sees that it is time for an attack, it performs the attack and adds a tick offset for the next attack tick. Since each tick is guaranteed to happen in sequence, I think this should work just fine.

Another new thing to consider, is that entities in combat need to make some attempt to stay within range of each other. If a player decides to run away from a monster, or gets ones attention, the monster should run after them. Right now the solution I have is a modification to the entity movement code so that I can specify a "target entity" that will be simply be followed (up to a specified minimum distance) instead of the usual method of moving to a set destination. This, in conjunction with the combat system doing range checks, should result in the simple persue effect I'm looking for.