User Tools

Site Tools


mr:ai_behavior_mechanic

AI Behavior Mechanic - Code References

Java Classes

  • AI State Interface: AiState.java - Base interface for all AI states
  • AI State Manager: MobAi.java - Manages AI state transitions and state registration
  • Mob Base Class: Mob.java - Contains AI state management logic
  • Char Base Class: Char.java - Base character class with AI state field

AI State Implementations

JSON Configuration

AI states can be specified in mob JSON descriptors with the “aiState” parameter:

  • Mob Descriptors: Located in RemixedDungeon/src/main/assets/mobsDesc/ directory
  • Example:
    {"aiState": "Sleeping"}

String Resources

<!-- AI Status Strings -->
<string name="Mob_StaWanderingStatus">%s is wandering</string>
<string name="Mob_StaHuntingStatus">%s is hunting</string>
<string name="Mob_StaHuntingStatus2">%s is hunting %s</string>
<string name="Mob_StaSleepingStatus">%s is sleeping</string>
<string name="Mob_StaPassiveStatus">%s is passive</string>
<string name="Mob_StaFleeingStatus">%s is fleeing</string>
<string name="Mob_StaFleeingStatus2">%s is fleeing from %s</string>
<string name="Mob_StaAmokStatus">This %1$s is running amok</string>
<string name="Mob_StaTerrorStatus">This %1$s is horrified</string>
<string name="Mob_StaTerrorStatus2">This %1$s is horrified by %2$s</string>
<string name="Mob_StaControlledStatus">This %s is under unholy possession</string>

Lua Scripts

AI states can be manipulated via Lua scripts for custom mob behaviors:

  • Script Location: RemixedDungeon/src/main/assets/scripts/mobs/
  • AI Control: Lua scripts can call Mob.setState() to change AI behavior

AI State Transitions

  • Damage Trigger: When mob takes damage → typically transitions to Hunting AI
  • Sight Trigger: When mob sees enemy while Sleeping/Wandering → transitions to Hunting AI
  • Health Trigger: When mob's health is low → may transition to Fleeing AI
  • Scripted Trigger: Lua scripts can force AI state changes

AiState Interface Methods

public interface AiState {
    void act(@NotNull Char me);                    // Called each turn to execute AI behavior
    String status(Char me);                         // Returns status string for display
    String getTag();                                // Returns AI state identifier
    void gotDamage(Char me, NamedEntityKind src, int dmg);  // Called when mob takes damage
    void onDie(@NotNull Char me);                   // Called when mob dies
}

Entity Kind

  • Interface: com.nyrds.pixeldungeon.ai.AiState
  • Package: com.nyrds.pixeldungeon.ai
  • Pattern: State Pattern for AI behavior management
mr/ai_behavior_mechanic.txt · Last modified: by 127.0.0.1