Difference between revisions of "NPC Perception Design"
(19 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
See [[Behaviors_and_Reactions]] for | 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 === | |||
Show the typical sequence for a broadcasted Perception. Examples of broadcasted perceptions is the SpellPerception. | |||
<uml> | |||
-> psNPCClient : TriggerEvent | |||
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> | |||
== 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. | |||
<uml> | |||
participant LocateOperation | |||
participant NPC | |||
participant Perception | |||
=== | == During Perception Handling == | ||
[-> NPC : SetLastPerception | |||
activate NPC | |||
[<-- NPC | |||
deactivate NPC | |||
=== | == During Script Execution == | ||
[-> LocateOperation : Run | |||
Activate LocateOperation | |||
LocateOperation -> NPC : GetLastPerception | |||
Activate NPC | |||
LocateOperation <-- NPC | |||
Deactivate NPC | |||
== | alt Perception == NULL | ||
[<-- LocateOperation : OPERATION_FAILED | |||
else Perception <> NULL | |||
LocateOperation -> Perception : GetLocation | |||
Activate Perception | |||
Perception -> Perception : GetTarget | |||
note right: Default behavior get location from target if there is one. | |||
activate Perception | |||
deactivate Perception | |||
Perception --> LocateOperation | |||
Deactivate Perception | |||
LocateOperation -> NPC : SetLocate | |||
Activate NPC | |||
LocateOperation <-- NPC | |||
Deactivate NPC | |||
== | alt destination == "Active" | ||
LocateOperation -> NPC : SetTarget | |||
Activate NPC | |||
LocateOperation <-- NPC | |||
Deactivate NPC | |||
end | |||
end | |||
[<-- LocateOperation : OPERATION_COMPLETED | |||
Deactivate LocateOperation | |||
</uml> | |||
[[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.
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.
Broadcast NPC Perceptions Sequence
Show the typical sequence for a broadcasted Perception. Examples of broadcasted perceptions is the SpellPerception.
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.