Slowly but surely chipping away at the combat system. Today I wrote the ‘backup’ and ‘restore’ functions for combat (so that even if the player closes their browser, when they log back in everything will be as it was), and wrote quite a nice little function that takes the action probabilities of each pre-action (stored like 9/30-7/10-8/60, to be read like ’30% chance of action_id 9, 10% chance of action_id 7 etc.) and explodes them out into an array, then rolls a hundred sided die then checks it against each probability to get the monster’s action for that combat round–it’s the reverse of how I’d normally do this, but because the number of possible actions is not set (ie there could be two, three, four or more possible actions for a given pre-action), it’s the best I came up with. One flaw is that if the action probabilities don’t add up to 100 then the possibility of an infinite loop is created. I could put some error-checking in for that, but it’s easier to just make sure my numbers are correct to begin with.
In any case, it’s working pretty much exactly as I want it to–the player is presented with the monster’s ‘pre-action’, and from that can try to predict what it’s going to do. I’ve worked hard to make behaviour consistent–each monster has ‘tells’ that telegraph certain attacks. Some of them are quite basic (aggressive pre-actions usually come before attacks), some more subtle (for certain monsters it’s the absence of a certain behaviour that telegraphs a particular action, for example). All in all I think it’s a good, fun system and I’m quite proud of it–it kind of replicates the sort of combat system I enjoy the most in real-time action games (observe and react).