Tuesday, April 6, 2010

Combat AI in Elderlands

Target Acquisition
In my previous works (Dransik) I had a very simplistic AI system. Attacking mobs looked for a target that was closest to them and went after it. Whenever they were attacked back and the attacker was closer than their current target they would switch to that target. This allowed for the ping ponging of a mob.

What Elderlands does for combat AI and agro management is a bit more complex. Each entity has a list of other entities that it is upset with and a list of entities that are upset with it. Now the list of entities that we are upset with is called the threat list or agro list. Players typically ignore this list but active npcs use this to determine which npc is the most viable target.

Whenever an entity is attacked the attacker adds agro to the list. The amount of agro is determined by the form of attack. For example a melee attack generates threat near equal to the amount of damage. When a ‘heal’ spell or any helpful spell is cast upon the any entity in our threat list will be added at 2x the value of the healed amount. This makes life a bit dangerous for support players in a battle.

Every second the agro list is sorted by the amount of agro recorded for each entity in the list. If the new top level entity contains X% more agro than the current target then we switch targets. When an entity dies, gets too far away, or meets a few other conditions they are then removed from the list.

For npcs when the list is empty they are out of combat and enter ‘homing’ mode. I have yet to refine the rules for players to determine when they are out of combat. This is important since health regeneration and some item cooldowns will be linked directly to the combat mode flag.

Maintaining Agro
Mobs stay in combat as long as they have entities on their agro list. So how do we lost agro? A mob should understand that if it was not attacked after some time it would drop that target or at least reduce the agro value for the target.

Npcs will also drop entities from the agro list when they meet certain criteria,  such as distance, death, certain protection spells, etc. When the npc’s agro list is empty they go into a ‘homing’ state where they attempt to return to their place of origin.

A big question is what to do while in this homing state. Do we allow players to attack a retreating npc? In World of Warcraft evading npcs are immune to all attacks until they return to their origin. This is something I’m going to spend some time in testing before I settle for a final solution. The goal is to prevent players from exploiting npcs and using this as a way to farm XP without subjecting themselves to danger. Another precaution taken against npcs is to have them regenerate their health once they reach home. The reason for this is a player could continue to resurrect and re-attack a mob until it finally does go down. This prevents us as developers from creating difficult mobs that require players of certain levels or a certain number of players in order to default.

3 comments:

  1. Glad to know this will end the days of dragging mobs to clear valleys :)

    ReplyDelete
  2. *On topic*
    Yay for improvements!


    *Off topic*
    wtf with the amount of source code on this tiny page?

    ReplyDelete
  3. You can do so many more interesting things by increasing a system's complexity juuust a little.

    Glad you're able to do some of this type of work these days: it'll make Elderlands a unique experience for sure. Keep up the great work, Loth!

    ReplyDelete