Difference between revisions of "NPCs"

From LugdunonWiki
Jump to: navigation, search
(BaseBehavior)
(Behavior Overview)
Line 7: Line 7:
  
  
 +
Behaviors are what define the actions of an NPC. They are discrete chunks of logic that inhabit a priority queue. Behaviors towards the front of this queue are deemed ‘more important’ to the NPC and will be evaluated before those behaviors further down the queue. Another factor that drives decision making is the NPCs behavior state. These state values are defined in '''''etc/behaviorStates.json'''''. At runtime, these state values are sorted and then an '''''int''''' value is assigned to each one. To discover the integer value of a given state, use the '''''State.instance().getWorld().getBehaviorState(String state)''''' method. Individual behaviors, or in some cases outside factors, may set that state and thus change the response of a particular behavior. One final piece is the presence of certain properties in the NPC’s behavior context. The existence of this context allows different behaviors to persist and share state.
  
 +
 +
The properties within the NPC’s behavior context can be accessed using the following convenience methods on the '''''net.lugdunon.state.character.NonPlayerCharacter''''' class:
  
  
 
<syntaxhighlight lang="javascript" line start="100" highlight="5" enclose="div">
 
<syntaxhighlight lang="javascript" line start="100" highlight="5" enclose="div">
 +
public Object getBehaviorContextVariable(String id)
  
 +
public void setBehaviorContextVariable(String id, Object value)
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 18:13, 13 October 2013

Contents

Introduction

Non-Player Characters (NPCs) share a large part of their code with player characters (PCs). The only real exceptions are the account related and locational awareness (for client-side rendering) properties of PCs and parent definition, spawner id, and behavior related properties of NPCs. This document will focus mainly on the configuration and definition of behaviors, as that is currently the core concept for modifying an NPC.

Behavior Overview

Behaviors are what define the actions of an NPC. They are discrete chunks of logic that inhabit a priority queue. Behaviors towards the front of this queue are deemed ‘more important’ to the NPC and will be evaluated before those behaviors further down the queue. Another factor that drives decision making is the NPCs behavior state. These state values are defined in etc/behaviorStates.json. At runtime, these state values are sorted and then an int value is assigned to each one. To discover the integer value of a given state, use the State.instance().getWorld().getBehaviorState(String state) method. Individual behaviors, or in some cases outside factors, may set that state and thus change the response of a particular behavior. One final piece is the presence of certain properties in the NPC’s behavior context. The existence of this context allows different behaviors to persist and share state.


The properties within the NPC’s behavior context can be accessed using the following convenience methods on the net.lugdunon.state.character.NonPlayerCharacter class:


  1. public Object getBehaviorContextVariable(String id)
  2.  
  3. public void setBehaviorContextVariable(String id, Object value)

BaseBehavior

  1.  




  1.  

IdleBehavior

PathBehavior

AggroBehavior