Saturday, June 9, 2012

Monster strategy

I thought about how I could implement monster strategy. On one hand, I want monsters to have many different behavior patterns to give players a varying game experience. This screams like an application for the Strategy pattern. But I also want to keep my Controller pattern where monsters are controlled from the outside. That's because I want some monsters to act as teams and be aware of what other monsters around them are doing. So I decided that every spawn area shall have its own MonsterController, which in turn gets four different strategies assigned to it:
  • SpawnStrategy: When and where it spawns mobs  
  • TargetStrategy: How it decides which monsters attack which players
  • RoamingStrategy: Behavior of monsters without an attack target
  • AttackStrategy: Behavior of monsters which have an attack target

Here are some example strategies for each category:

SpawnReplaceSingleRespawns dead mobs until the population reached a certain value
ReplaceTeamWhen all mobs have died, respawn them all.
AmbushLike ReplaceTeam, but only spawn them when a player is in a specific area.
Targetnullnever choose an attack target
ClosestChooses the target closest to the monster
ClosestTeamChooses the target closest to any controlled monster
LastAttackerChooses the last combatant who attacked the monster
LastAttackerTeamChooses the last combatant who attacked any monster of the team
BestAttackerChooses the combatant who did most damage to monster
BestAttackerTeamChooses the combatant who did most damage to all monsters of the team
Roamingnulldo not move when not in combat
GuardReturn to spawn position when not in combat
MapMove randomly around the whole map
AreaMove randomly around the spawn area
TeamMove randomly to positions around the center of the team
PatrolMove along a predefined set of waypoints
PatrolTeamMove along a predefined set of waypoints, wait until everyone has reached the waypoint
Attacknullnever attack, never move when in combat
StationaryUse a random attack which is in range
PursuitChoose random attack. When in range, use it. When not in range, move into range.
StalkChoose random attack, move close to maximum range, use it.
FleeDon't attack. Try to hold a minimum distance to target.

Every monster type has a default strategy for each category. But spawn areas can manually override them. So you can have, for example, a demon castle where some demons patrol the surrounding, two demons guard the front gate, a group which ambushs any players who gets past the guards and some which roam the interior.

No comments:

Post a Comment