feat: define authoritative action effects
This commit is contained in:
@@ -2,33 +2,38 @@ class_name ActionCommand
|
||||
extends RefCounted
|
||||
|
||||
var _command_id: StringName
|
||||
var _actor_id: StringName
|
||||
var _actor: WorldEntityRef
|
||||
var _action_id: StringName
|
||||
var _target: WorldTargetHandle
|
||||
var _parameters: Dictionary
|
||||
var _expected_state_revision: int
|
||||
|
||||
|
||||
func _init(
|
||||
command_id: StringName = &"",
|
||||
actor_id: StringName = &"",
|
||||
actor: Variant = null,
|
||||
action_id: StringName = &"",
|
||||
target: WorldTargetHandle = null,
|
||||
parameters: Dictionary = {}
|
||||
parameters: Dictionary = {},
|
||||
expected_state_revision: int = -1
|
||||
) -> void:
|
||||
_command_id = command_id
|
||||
_actor_id = actor_id
|
||||
_actor = _normalize_actor(actor)
|
||||
_action_id = action_id
|
||||
_target = target
|
||||
_parameters = parameters.duplicate(true)
|
||||
_expected_state_revision = expected_state_revision
|
||||
|
||||
|
||||
func is_valid() -> bool:
|
||||
return (
|
||||
not _command_id.is_empty()
|
||||
and not _actor_id.is_empty()
|
||||
and _actor != null
|
||||
and _actor.is_valid()
|
||||
and not _action_id.is_empty()
|
||||
and _target != null
|
||||
and _target.is_well_formed()
|
||||
and _expected_state_revision >= -1
|
||||
and not WorldTargetCapability._contains_object(_parameters)
|
||||
)
|
||||
|
||||
@@ -38,7 +43,11 @@ func get_command_id() -> StringName:
|
||||
|
||||
|
||||
func get_actor_id() -> StringName:
|
||||
return _actor_id
|
||||
return _actor.get_entity_id() if _actor != null else &""
|
||||
|
||||
|
||||
func get_actor() -> WorldEntityRef:
|
||||
return _actor.duplicate_ref() if _actor != null else null
|
||||
|
||||
|
||||
func get_action_id() -> StringName:
|
||||
@@ -51,3 +60,15 @@ func get_target() -> WorldTargetHandle:
|
||||
|
||||
func get_parameters() -> Dictionary:
|
||||
return _parameters.duplicate(true)
|
||||
|
||||
|
||||
func get_expected_state_revision() -> int:
|
||||
return _expected_state_revision
|
||||
|
||||
|
||||
static func _normalize_actor(actor: Variant) -> WorldEntityRef:
|
||||
if actor is WorldEntityRef:
|
||||
return (actor as WorldEntityRef).duplicate_ref()
|
||||
if actor is StringName or actor is String:
|
||||
return WorldEntityRef.create(SimulationIds.ENTITY_PERSON, StringName(actor))
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user