class Rsrb::World::Task
A Task
executed in the context of the game
task = Rsrb::World::Task.new
(3, 3, @player) do |task, player|
player.inventory.remove(Rsrb::Item[995], 50000) player.inventory.add(Rsrb::Item[4151], 1)
end
WORLD.schedule_player_task(task) #=> in 3 ticks, the world will remove 50000 gp from the player's inventory and add 1 abbyssal whip 3 times
Constants
- Properties
A struct for holding property data. @param delay [Integer] the delay in ticks before the task should be executed. @param block [Proc] the block to execute during the task.
Attributes
@return [Integer] The delay in ticks before the task will execute.
@return [Integer] The ID for the task.
@return [Array] Operations the task will perform.
@return [Struct] Properties
for the task.
Public Class Methods
Create a task with a specified delay. @param props [Hash] properties for this task. @param block [Proc] the code to execute during the task.
properties include:
-
delay [Integer] delay in ticks before operations should start executing.
-
exec_count [Integer] the number of times the block should execute
-
label [String, Symbol, Integer] the symbol for the task
Rsrb::Internal::Types::Routine::new
# File lib/rsrb/world/task.rb, line 43 def initialize(props = { delay: 0, count: 1, params: [self] }, &block) init_loggers return unless block_given? @id = props[:id] || object_id @delay = props[:delay] @operations = [] @observer = WORLD update(props[:delay], props[:count], block) super(props[:params]) end
Public Instance Methods
Shorthand retrieval of properties.
# File lib/rsrb/world/task.rb, line 74 def [](key) @properties[key] end
Attempts to stop the task.
# File lib/rsrb/world/task.rb, line 66 def cancel return unless @execution @execution.running? ? @execution.shutdown : @execution.cancel end
Updates the task's execution block.
# File lib/rsrb/world/task.rb, line 57 def update(delay, exec_count, block) log!("Updating task: [#{@label}]:(#{@id})}") if WORLD.settings[:task_debug] @delay = delay exec_count.times { @operations << -> { block.call(@assets) } } log("Operations View: #{@operations}") if WORLD.settings[:task_debug] end
Private Instance Methods
the execution function for the task.
# File lib/rsrb/world/task.rb, line 81 def execute Concurrent::ScheduledTask.execute(@delay * 0.600) do |task| @execution = task @operations.each(&:call) end.add_observer(@observer) end
the callback function for the task. currently is used to add the bound world as the observer.
# File lib/rsrb/world/task.rb, line 90 def successful; end
the errback function for the task.
# File lib/rsrb/world/task.rb, line 93 def unsuccessful cancel end