Module: Scheduler::EventTasks
- Defined in:
- scripts/00700 Ajout_PSDK/00101 EventTasks.rb
Overview
Module that aim to add task triggered by events actions
List of the event actions :
- begin_step
- begin_jump
-
- end_step
- end_jump
-
Events can be specified with the following criteria
- map_id / :any : ID of the map where the task can trigger
- event_id / :any : ID of the event that trigger the task (-1 = player, -2 its first follower, -3 its second, ...)
Parameter sent to the task :
- event : Game_Character object that triggered the task
- event_id : ID of the event that triggered the task (for :any tasks)
- map_id : ID of the map where the task was triggered (for :any tasks)
Important note : The system will detect the original id & map of the events (that's why the event object is sent & its id)
Class Method Summary collapse
-
.delete(task_type, description, event_id, map_id)
Remove a task.
-
.on(task_type, description, event_id = :any, map_id = :any, &task)
Add a new task.
-
.resolve_id(event) ⇒ Integer
Resolve the id of the event.
-
.resolve_map_id(event) ⇒ Integer
Resolve the id of the event.
-
.trigger(task_type, event)
Trigger a specific task.
Class Method Details
.delete(task_type, description, event_id, map_id)
Remove a task
100 101 102 103 104 105 |
# File 'scripts/00700 Ajout_PSDK/00101 EventTasks.rb', line 100 def delete(task_type, description, event_id, map_id) return unless (tasks = @tasks[task_type]) return unless (tasks = tasks[map_id]) return unless (tasks = tasks[event_id]) tasks.delete(description) end |
.on(task_type, description, event_id = :any, map_id = :any, &task)
Add a new task
34 35 36 37 38 39 |
# File 'scripts/00700 Ajout_PSDK/00101 EventTasks.rb', line 34 def on(task_type, description, event_id = :any, map_id = :any, &task) tasks = (@tasks[task_type] ||= {}) tasks = (tasks[map_id] ||= {}) tasks = (tasks[event_id] ||= {}) tasks[description] = task end |
.resolve_id(event) ⇒ Integer
Resolve the id of the event
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'scripts/00700 Ajout_PSDK/00101 EventTasks.rb', line 71 def resolve_id(event) if event.is_a?(Game_Event) return event.original_id elsif event == $game_player return -1 end # Follower resolution id = -1 follower = $game_player while (follower = follower.follower) id -= 1 return id if follower == event end return 0 end |
.resolve_map_id(event) ⇒ Integer
Resolve the id of the event
90 91 92 93 |
# File 'scripts/00700 Ajout_PSDK/00101 EventTasks.rb', line 90 def resolve_map_id(event) return event.original_map if event.is_a?(Game_Event) return $game_map.map_id end |
.trigger(task_type, event)
Trigger a specific task
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'scripts/00700 Ajout_PSDK/00101 EventTasks.rb', line 44 def trigger(task_type, event) return unless (tasks = @tasks[task_type]) event_id = resolve_id(event) map_id = resolve_map_id(event) # Tasks of the current map if (map_tasks = tasks[map_id]) if (event_tasks = map_tasks[event_id]) event_tasks.each_value { |task| task.call(event, event_id, map_id) } end if (event_tasks = map_tasks[:any]) event_tasks.each_value { |task| task.call(event, event_id, map_id) } end end # Tasks of all the map if (map_tasks = tasks[:any]) if (event_tasks = map_tasks[event_id]) event_tasks.each_value { |task| task.call(event, event_id, map_id) } end if (event_tasks = map_tasks[:any]) event_tasks.each_value { |task| task.call(event, event_id, map_id) } end end end |