class Demiurge::ActionItemInternal::ActionIntention
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.
@since 0.0.1
Attributes
@return [Array] Additional arguments to pass to the argument's code block @since 0.0.1
@return [String] The action name to perform @since 0.0.1
Public Class Methods
Constructor. Pass in the engine, item name, action name and additional arguments.
@param engine [Demiurge::Engine] The engine this Intention
operates within @param name [String] The item name of the ActionItem
acting @param action_name
[String] The action name to perform @param args [Array] Additional arguments to pass to the code block @return [void] @since 0.0.1
Demiurge::Intention::new
# 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
Public Instance Methods
For now, ActionIntentions don't have a way to specify “allowed” blocks in their DSL
, so they are always considered “allowed”.
return [void] @since 0.0.1
# File lib/demiurge/action_item.rb, line 462 def allowed? true end
Apply the ActionIntention's effects to the appropriate StateItems.
return [void] @since 0.0.1
# File lib/demiurge/action_item.rb, line 484 def apply @item.run_action(@action_name, *@action_args, current_intention: self) end
Send out a notification to indicate this ActionIntention
was applied.
@return [void] @since 0.2.0
# 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
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.
@return [void] @since 0.0.1
# 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
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] @since 0.0.1 @note This method changed signature in 0.2.0 to stop taking an intention ID.
# 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