class Demiurge::ActionItemInternal::AgentBlockRunner

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

Public Instance Methods

dump_state(filename = "statedump.json") click to toggle source

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

@param filename [String] The filename to dump state to. @return [void] @since 0.0.1

# 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 = {}) click to toggle source

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

@param position [String] The position to move to @param options [Hash] 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. @return [void] @since 0.0.1

# 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, next_x, next_y = TiledLocation.position_to_loc_coords(position)
  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) click to toggle source

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

@param action_name [String] The action name to queue up @param args [Array] Additional arguments to pass to the action block @return [void] @since 0.0.1

# 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