Class: Demiurge::ActionItemInternal::AgentBlockRunner Private

Inherits:
ActionItemBlockRunner 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.

This is a BlockRunner for an agent's actions - it will be used if "engine_code" isn't set and the item for the action is an agent.

Since:

  • 0.0.1

Instance Attribute Summary

Attributes inherited from ActionItemBlockRunner

#current_intention

Attributes inherited from BlockRunner

#engine, #item

Instance Method Summary collapse

Methods inherited from ActionItemBlockRunner

#action, #cancel_intention, #cancel_intention_if_present, #initialize, #notification, #position_to_location_and_tile_coords, #state

Methods inherited from BlockRunner

#initialize

Constructor Details

This class inherits a constructor from Demiurge::ActionItemInternal::ActionItemBlockRunner

Instance Method Details

#dump_state(filename = "statedump.json") ⇒ 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.

Dump the engine's state as JSON, as an admin-only action.

Parameters:

  • filename (String) (defaults to: "statedump.json")

    The filename to dump state to.

Since:

  • 0.0.1



409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/demiurge/action_item.rb', line 409

def dump_state(filename = "statedump.json")
  unless @item.state["admin"] # Admin-only command
    cancel_intention_if_present("The dump_state operation is admin-only!")
    return
  end

  ss = @item.engine.structured_state
  File.open(filename) do |f|
    f.print MultiJson.dump(ss, :pretty => true)
  end
  nil
end

#move_to_instant(position, options = {}) ⇒ 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.

Move the agent to a specific position immediately. Don't play a walking animation or anything. Just put it where it needs to be.

Parameters:

  • position (String)

    The position to move to

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

    A Hash of how the item moves there; this can be checked by your World Files or display library, though Demiurge won't use it directly.

Since:

  • 0.0.1



368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/demiurge/action_item.rb', line 368

def move_to_instant(position, options = {})
  # TODO: We don't have a great way to do this for non-agent entities. How does "accomodate" work for non-agents?
  # This may be app-specific.

  loc_name = TiledLocation.position_to_loc_coords(position)[0]
  location = @item.engine.item_by_name(loc_name)
  if !location
    cancel_intention_if_present "Location #{loc_name.inspect} doesn't exist.", "position" => position, "mover" => @item.name
  elsif location.can_accomodate_agent?(@item, position)
    @item.move_to_position(position)
  else
    cancel_intention_if_present "That position is blocked.", "position" => position, "message" => "position blocked", "mover" => @item.name
  end
end

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

Queue an action for this agent, to be performed during the next tick.

Parameters:

  • action_name (String)

    The action name to queue up

  • args (Array)

    Additional arguments to pass to the action block

Since:

  • 0.0.1



390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/demiurge/action_item.rb', line 390

def queue_action(action_name, *args)
  unless @item.is_a?(::Demiurge::Agent)
    @engine.admin_warning("Trying to queue an action #{action_name.inspect} for an item #{@item.name.inspect} that isn't an agent! Skipping.")
    return
  end
  act = @item.get_action(action_name)
  unless act
    raise Demiurge::Errors::NoSuchActionError.new("Trying to queue an action #{action_name.inspect} for an item #{@item.name.inspect} that doesn't have it!",
                                                  "item" => @item.name, "action" => action_name, execution_context: @item.engine.execution_context)
    return
  end
  @item.queue_action(action_name, args)
end