Class: Demiurge::ActionItemInternal::ActionIntention Private

Inherits:
Intention
  • Object
show all
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.

Since:

  • 0.0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • engine (Demiurge::Engine)

    The engine this Intention operates within

  • name (String)

    The item name of the ActionItem acting

  • action_name (String)

    The action name to perform

  • args (Array)

    Additional arguments to pass to the code block

Raises:

Since:

  • 0.0.1



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_argsArray (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

Returns:

  • (Array)

    Additional arguments to pass to the argument's code block

Since:

  • 0.0.1



437
438
439
# File 'lib/demiurge/action_item.rb', line 437

def action_args
  @action_args
end

#action_nameString (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

Returns:

  • (String)

    The action name to perform

Since:

  • 0.0.1



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]

Returns:

  • (Boolean)

Since:

  • 0.0.1



462
463
464
# File 'lib/demiurge/action_item.rb', line 462

def allowed?
  true
end

#applyObject

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]

Since:

  • 0.0.1



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_notificationvoid

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.

Since:

  • 0.2.0



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_notificationvoid

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.

Since:

  • 0.0.1



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

#offerObject

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.

Note:

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]

Since:

  • 0.0.1



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