Class: Demiurge::ActionItemInternal::AgentBlockRunner Private
- Inherits:
-
ActionItemBlockRunner
- Object
- BlockRunner
- ActionItemBlockRunner
- Demiurge::ActionItemInternal::AgentBlockRunner
- 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.
Instance Attribute Summary
Attributes inherited from ActionItemBlockRunner
Attributes inherited from BlockRunner
Instance Method Summary collapse
-
#dump_state(filename = "statedump.json") ⇒ void
private
Dump the engine's state as JSON, as an admin-only action.
-
#move_to_instant(position, options = {}) ⇒ void
private
Move the agent to a specific position immediately.
-
#queue_action(action_name, *args) ⇒ void
private
Queue an action for this agent, to be performed during the next tick.
Methods inherited from ActionItemBlockRunner
#action, #cancel_intention, #cancel_intention_if_present, #initialize, #notification, #position_to_location_and_tile_coords, #state
Methods inherited from BlockRunner
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.
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.
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, = {}) # 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.
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 |