Difference between revisions of "NPC Perception Design"

From PSwiki
Jump to navigation Jump to search
m (Reverted edits by Luca (Talk) to last revision by Ethryn)
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
See [[Behaviors_and_Reactions]] for most up to date description of perceptions.
See [[Behaviors_and_Reactions]] for User details about how to use Perceptions in the behavior.xml file.


----
----
This embodies any perception an NPC might have, or any game event of interest.  Reaction objects below will subscribe to these events, and the networking system will publish them.  Examples would be "attacked", "collided", "talked to", "hear cry".
This embodies any perception an NPC might have, or any game event of interest.  Reaction objects below will subscribe to these events, and the networking system will publish them.  Examples would be "attacked", "collided", "talked to", "hear cry".


== NPC Perceptions ==
=== Class Hierarchy ===
The Perception class is used for simple perception and as the Base Class for a number of special perceptions.
<uml>
class Perception {
  #csString name
  #csString type
  +bool ShouldReact()
  +void ExecutePerception()
  +gemNPCObject GetTarget()
  +csString ToString()
}
Perception <|-- SpecialPerception
class SpecialPerception {
  +bool ShouldReact()
  +void ExecutePerception()
  +gemNPCObject GetTarget()
  +csString ToString()
}
</uml>
Special Perceptions:
* TimePerception
* FactionPerception
* ItemPerception
* LocationPerception
* PositionPerception
* AttackPerception
* GroupAttackPerception
* DamagePerception
* SpellPerception
* DeathPerception
* InventoryPerception
* OwnerCmdPerception
* OwnerActionPerception
* NPCCmdPerception


== Sequences ==
=== Personal NPC Perceptions Sequence ===


Show the typical sequence for a Perception fired for a NPC, might be perceptions like Damage Perception.


== NPC Perceptions ==
<uml>
-> NPC : TriggerEvent
activate NPC
NPC -> NPCType : FirePerception
activate NPCType
loop "For all Reactions"
  NPCType -> Reaction : React
  activate Reaction
  Reaction -> Perception : ShouldReact
  activate Perception
  Reaction <-- Perception
  deactivate Perception
  Reaction -> Reaction : CheckDeath
  Reaction -> Reaction : Check DoNotInterrupt
  Reaction -> Reaction : Check OnlyInterrupt
  loop "For all Affected"
    Reaction -> Reaction : Check only active affected
    Reaction -> Reaction : Check only inactive affected
    Reaction -> Reaction : Adjust Needs
    Reaction -> Perception : ExecutePerception
    activate Perception
    Reaction <-- Perception
    deactivate Perception
  end
  NPC <- Reaction : SetLastPerception
  NPCType <-- Reaction
  deactivate Reaction
end
NPC <-- NPCType
deactivate NPCType
<-- NPC
deactivate NPC
</uml>
 
=== Broadcast NPC Perceptions Sequence ===


=== RangePerception ===
Show the typical sequence for a broadcasted Perception. Examples of broadcasted perceptions is the SpellPerception.


=== TimePerception ===
<uml>
The Game Server sends a Time perception once per game hour to all
-> psNPCClient : TriggerEvent
superclients, with a number from 0 to 23 indicating the hour. If a superclient needs more fine-grained time reactions, the superclient can generate time perceptions of its own in between and react accordingly.
activate psNPCClient
loop
  psNPCClient -> NPC : TriggerEvent
  activate NPC
  NPC -> NPCType : FirePerception
  activate NPCType
  loop
    note over NPCType : See Personal NPC\nPerception Sequence\nfor details.
  end
  NPC <-- NPCType
  deactivate NPCType
  psNPCClient <-- NPC
  deactivate NPC
end
<-- psNPCClient
deactivate psNPCClient
</uml>


This perception allows npcs to change behaviors or state depending on the time of day. For example, you could have nocturnal hunting creatures who sleep during the day, or npc city merchants who are in their shops during the day and at home at night.
== Special cases ==


=== Perceptions used from locate operation ===
The [[Behavior_Operations#Locate_Operation|Locate Operation]] can locate objects of type perception. This only make sense for perceptions that has an actual position. Either a physical position that can be provided through the GetLocate or an target that the default implementation of the GetLocate could use to get the position of the target. In this case the perception need to implement the GetTarget.


Example:
<uml>
  <react event="time" value="8,0,,,"  behavior="go_other_sector1" delta="20" />
participant LocateOperation
participant NPC
participant Perception


=== FactionPerception ===
== During Perception Handling ==
=== ItemPerception ===
Whenever an NPC is close to an item, this perception is passed to the npc.


=== LocationPerception ===
[-> NPC : SetLastPerception
Whenever an NPC is close to an location, this perception is passed to the npc.
activate NPC
[<-- NPC
deactivate NPC


=== AttackPerception ===
== During Script Execution ==
Whenever an NPC is attacked by a player, this perception is passed to the attacked npc.  The npc should use this to build an initial hate list for the player and his group (if any). If the designer wants to cheat, he can start attacking back on this event instead of on first damage, and save a few seconds in response time.


Example:
[-> LocateOperation : Run
  <react event="attack"  behavior="fight" delta="150" />
Activate LocateOperation


=== GroupAttackPerception ===
LocateOperation -> NPC : GetLastPerception
Whenever an NPC is attacked by a grouop, this perception is passed to the attacked npc.  The npc should use this to build an initial hate list for the player group. If the designer wants to cheat, he can start attacking back on this event instead of on first damage, and save a few seconds in response time.
Activate NPC


=== DamagePerception ===
LocateOperation <-- NPC
Whenever an NPC is hit for damage by a melee hit or a spell, this perception is passed to the damaged npc.  Right now, it affects his/her hate list according to the weight supplied.
Deactivate NPC


=== SpellPerception ===
alt Perception == NULL
Whenever a player casts a spell on himself, another player, or any npc, this perception is passed to npc's in the vicinity. We cannot only use targeted NPCs because an npc in combat may want to react to a player healing his group mate, which helps his team and hurts the NPC indirectly.  Right now, reactions are allowed by type of spell, and depending on the severity, it affects his/her hate list according to the weight supplied.
  [<-- LocateOperation : OPERATION_FAILED
else Perception <> NULL
  LocateOperation -> Perception : GetLocation
  Activate Perception


=== DeathPerception ===
  Perception -> Perception : GetTarget
The network layer is notified of any deaths from players or NPCs on the server.  This perception is passed to all NPCs so they can react, by removing the player from hate lists, stopping their combat or whatever.
  note right: Default behavior get location from target if there is one.
  activate Perception
  deactivate Perception
  Perception --> LocateOperation
  Deactivate Perception


=== InventoryPerception ===
  LocateOperation -> NPC : SetLocate
This perception is used when a item is added or removed from inventory.
  Activate NPC
  LocateOperation <-- NPC
  Deactivate NPC


=== OwnerCmdPerception ===
  alt destination == "Active"
Whenever an NPCPet is told by it's owner to stay, this perception is passed to the NPCPet.  Right now, it changes the current behavior of the NPCPet.
    LocateOperation -> NPC : SetTarget
    Activate NPC
    LocateOperation <-- NPC
    Deactivate NPC
  end
end


=== OwnerActionPerception ===
[<-- LocateOperation : OPERATION_COMPLETED
Whenever an NPCPet is told by it's owner to stay, this perception is passed to the NPCPet.  Right now, it changes the current behavior of the NPCPet.
Deactivate LocateOperation


=== NPCCmdPerception ===
</uml>
Whenever an NPC Cmd is received this perception is fired. This is most typicaly from a response script like: <npccmd cmd="test_cmd"/>




[[Category:Engine documents]]
[[Category:Engine documents]] [[Category:NPCClient Design]]

Latest revision as of 14:30, 7 April 2013

See Behaviors_and_Reactions for User details about how to use Perceptions in the behavior.xml file.


This embodies any perception an NPC might have, or any game event of interest. Reaction objects below will subscribe to these events, and the networking system will publish them. Examples would be "attacked", "collided", "talked to", "hear cry".

NPC Perceptions

Class Hierarchy

The Perception class is used for simple perception and as the Base Class for a number of special perceptions.

Adobe SVG Viewer plugin (for Internet Explorer) or use Firefox, Opera or Safari instead.

Special Perceptions:

  • TimePerception
  • FactionPerception
  • ItemPerception
  • LocationPerception
  • PositionPerception
  • AttackPerception
  • GroupAttackPerception
  • DamagePerception
  • SpellPerception
  • DeathPerception
  • InventoryPerception
  • OwnerCmdPerception
  • OwnerActionPerception
  • NPCCmdPerception

Sequences

Personal NPC Perceptions Sequence

Show the typical sequence for a Perception fired for a NPC, might be perceptions like Damage Perception.

Adobe SVG Viewer plugin (for Internet Explorer) or use Firefox, Opera or Safari instead.

Broadcast NPC Perceptions Sequence

Show the typical sequence for a broadcasted Perception. Examples of broadcasted perceptions is the SpellPerception.

Adobe SVG Viewer plugin (for Internet Explorer) or use Firefox, Opera or Safari instead.

Special cases

Perceptions used from locate operation

The Locate Operation can locate objects of type perception. This only make sense for perceptions that has an actual position. Either a physical position that can be provided through the GetLocate or an target that the default implementation of the GetLocate could use to get the position of the target. In this case the perception need to implement the GetTarget.

Adobe SVG Viewer plugin (for Internet Explorer) or use Firefox, Opera or Safari instead.