Class: Demiurge::ActionItemInternal::ActionItemBlockRunner Private

Inherits:
BlockRunner
  • 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.

The ActionItemBlockRunner is a good, general-purpose block runner that supplies more context and more "gentle" object accessors to the block code. The methods of this class are generally intended to be used in the block code.

Since:

  • 0.0.1

Direct Known Subclasses

AgentBlockRunner

Instance Attribute Summary collapse

Attributes inherited from BlockRunner

#engine, #item

Instance Method Summary collapse

Constructor Details

#initialize(item, current_intention:) ⇒ ActionItemBlockRunner

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.

The constructor

Parameters:

  • item

    The item receiving the block and (usually) taking action

  • current_intention

    The current intention, if any; used for canceling

Since:

  • 0.0.1



263
264
265
266
# File 'lib/demiurge/action_item.rb', line 263

def initialize(item, current_intention:)
  super(item)
  @current_intention = current_intention
end

Instance Attribute Details

#current_intentionDemiurge::Intention? (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 current intention, if any

Returns:

Since:

  • 0.0.1



256
257
258
# File 'lib/demiurge/action_item.rb', line 256

def current_intention
  @current_intention
end

Instance Method Details

#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.

This method returns an undefined value.

Create an action to be executed immediately. This doesn't go through an agent's action queue or make anybody busy. It just happens during the current tick, but it uses the normal allow/offer/execute/notify cycle.

Parameters:

  • name (String)

    The action name

  • args (Array)

    Additional arguments to send to the action

Since:

  • 0.0.1



316
317
318
319
320
# File 'lib/demiurge/action_item.rb', line 316

def action(name, *args)
  intention = ActionItemInternal::ActionIntention.new(engine, @item.name, name, *args)
  @item.engine.queue_intention(intention)
  nil
end

#cancel_intention(reason, extra_info = {}) ⇒ 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.

Cancel the current intention. Raise a NoCurrentIntentionError if there isn't one.

Parameters:

  • reason (String)

    The reason to cancel

  • extra_info (Hash) (defaults to: {})

    Additional cancellation info, if any

Raises:

Since:

  • 0.0.1



338
339
340
341
342
343
# File 'lib/demiurge/action_item.rb', line 338

def cancel_intention(reason, extra_info = {})
  raise ::Demiurge::Errors::NoCurrentIntentionError.new("No current intention in action of item #{@item.name}!", { "script_item": @item.name },
                                                        execution_context: @item.engine.execution_context) unless @current_intention
  @current_intention.cancel(reason, extra_info)
  nil
end

#cancel_intention_if_present(reason, extra_info = {}) ⇒ 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.

Cancel the current intention. Do nothing if there isn't one.

Parameters:

  • reason (String)

    The reason to cancel

  • extra_info (Hash) (defaults to: {})

    Additional cancellation info, if any

Since:

  • 0.0.1



351
352
353
# File 'lib/demiurge/action_item.rb', line 351

def cancel_intention_if_present(reason, extra_info = {})
  @current_intention.cancel(reason, extra_info) if @current_intention
end

#notification(data) ⇒ 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 a notification, starting from the location of the ActionItem. Any fields other than the special "type", "zone", "location" and "actor" fields will be sent as additional notification fields.

Parameters:

  • data (Hash)

    The fields for the notification to send

Options Hash (data):

  • type (String)

    The notification type to send

  • zone (String)

    The zone name to send the notification in; defaults to ActionItem's zone

  • location (String)

    The location name to send the notification in; defaults to ActionItem's location

  • actor (String)

    The acting item's name; defaults to this ActionItem

Since:

  • 0.0.1



298
299
300
301
302
303
304
305
# File 'lib/demiurge/action_item.rb', line 298

def notification(data)
  type = data.delete("type") || data.delete(:type) || data.delete("type") || data.delete(:type)
  zone = to_demiurge_name(data.delete("zone") || data.delete(:zone) || @item.zone)
  location = to_demiurge_name(data.delete("location") || data.delete(:location) || @item.location)
  actor = to_demiurge_name(data.delete("actor") || data.delete(:actor) || @item)
  @item.engine.send_notification(data, type: type.to_s, zone: zone, location: location, actor: actor, include_context: true)
  nil
end

#position_to_location_and_tile_coords(position) ⇒ String, Integer

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 tiled maps, cut the position string apart into a location and X and Y tile coordinates within that location.

Parameters:

  • position (String)

    The position string

Returns:

  • (String, Integer, Integer)

    The location string, the X coordinate and the Y coordinate

Since:

  • 0.0.1



328
329
330
# File 'lib/demiurge/action_item.rb', line 328

def position_to_location_and_tile_coords(position)
  ::Demiurge::TiledLocation.position_to_loc_coords(position)
end

#stateDemiurge::ActionItemInternal::ActionItemStateWrapper

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.

Access the item's state via a state wrapper. This only allows setting new fields or reading fields that already exist.

Returns:

Since:

  • 0.0.1



273
274
275
# File 'lib/demiurge/action_item.rb', line 273

def state
  @state_wrapper ||= ActionItemInternal::ActionItemStateWrapper.new(@item)
end