Class: Demiurge::ActionItemInternal::ActionIntention Private
- Defined in:
- lib/demiurge/action_item.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An Intention for an ActionItem to perform one of its actions. This isn't an agent-specific intention which checks if the agent is busy and performs the action exclusively. Instead, it's an ActionItem performing this action as soon as the next tick happens
- more than one can occur, for instance.
Direct Known Subclasses
Demiurge::AgentInternal::AgentActionIntention, Demiurge::AgentInternal::WanderIntention
Instance Attribute Summary collapse
-
#action_args ⇒ Array
readonly
private
Additional arguments to pass to the argument's code block.
-
#action_name ⇒ String
readonly
private
The action name to perform.
Instance Method Summary collapse
-
#allowed? ⇒ Boolean
private
For now, ActionIntentions don't have a way to specify "allowed" blocks in their DSL, so they are always considered "allowed".
-
#apply ⇒ Object
private
Apply the ActionIntention's effects to the appropriate StateItems.
-
#apply_notification ⇒ void
private
Send out a notification to indicate this ActionIntention was applied.
-
#cancel_notification ⇒ void
private
Send out a notification to indicate this ActionIntention was cancelled.
-
#initialize(engine, name, action_name, *args) ⇒ void
constructor
private
Constructor.
-
#offer ⇒ Object
private
Make an offer of this ActionIntention and see if it is cancelled or modified.
Methods inherited from Intention
#cancel, #cancelled?, #try_apply
Constructor Details
#initialize(engine, name, action_name, *args) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Constructor. Pass in the engine, item name, action name and additional arguments.
447 448 449 450 451 452 453 454 455 |
# File 'lib/demiurge/action_item.rb', line 447 def initialize(engine, name, action_name, *args) @name = name @item = engine.item_by_name(name) raise Demiurge::Errors::NoSuchAgentError.new("Can't get agent's item for name #{name.inspect}!", execution_context: engine.execution_context) unless @item @action_name = action_name @action_args = args super(engine) nil end |
Instance Attribute Details
#action_args ⇒ Array (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Additional arguments to pass to the argument's code block
437 438 439 |
# File 'lib/demiurge/action_item.rb', line 437 def action_args @action_args end |
#action_name ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The action name to perform
433 434 435 |
# File 'lib/demiurge/action_item.rb', line 433 def action_name @action_name end |
Instance Method Details
#allowed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
For now, ActionIntentions don't have a way to specify "allowed" blocks in their DSL, so they are always considered "allowed".
return [void]
462 463 464 |
# File 'lib/demiurge/action_item.rb', line 462 def allowed? true end |
#apply ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Apply the ActionIntention's effects to the appropriate StateItems.
return [void]
484 485 486 |
# File 'lib/demiurge/action_item.rb', line 484 def apply @item.run_action(@action_name, *@action_args, current_intention: self) end |
#apply_notification ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Send out a notification to indicate this ActionIntention was applied.
516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/demiurge/action_item.rb', line 516 def apply_notification @engine.send_notification({ id: @intention_id, intention_type: self.class.to_s, }, type: Demiurge::Notifications::IntentionApplied, zone: @item.zone_name, location: @item.location_name, actor: @item.name, include_context: true) nil end |
#cancel_notification ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Send out a notification to indicate this ActionIntention was cancelled. If "silent" is set to true in the cancellation info, no notification will be sent.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/demiurge/action_item.rb', line 494 def cancel_notification return if @cancelled_info && @cancelled_info["silent"] @engine.send_notification({ reason: @cancelled_reason, by: @cancelled_by, id: @intention_id, intention_type: self.class.to_s, info: @cancelled_info, }, type: Demiurge::Notifications::IntentionCancelled, zone: @item.zone_name, location: @item.location_name, actor: @item.name, include_context: true) nil end |
#offer ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method changed signature in 0.2.0 to stop taking an intention ID.
Make an offer of this ActionIntention and see if it is cancelled or modified. By default, offers are coordinated through the item's location.
return [void]
473 474 475 476 477 478 |
# File 'lib/demiurge/action_item.rb', line 473 def offer loc = @item.location || @item.zone @engine.push_context("offered_action" => @action_name, "offered_location" => loc.name, "offering_item" => @item.name) do loc.receive_offer(@action_name, self) end end |