Class: PFM::Quests
- Defined in:
- scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb,
scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb
Overview
The quest management
The main object is stored in $quests and PFM.game_state.quests
Defined Under Namespace
Classes: Quest
Constant Summary collapse
- AUTO_CHECK_SIGNAL_ON_TEST =
Tell if the system should check the signal when we test finished?(id) or failed?(id)
true
- AUTO_CHECK_SIGNAL_ON_ALL_OBJECTIVE_VALIDATED =
Tell if the system should check the signal when we check the quest termination
false
Instance Attribute Summary collapse
-
#active_quests ⇒ Hash<Integer => Quest>
The list of active_quests.
-
#failed_quests ⇒ Hash<Integer => Quest>
The list of failed_quests.
-
#finished_quests ⇒ Hash<Integer => Quest>
The list of finished_quests.
-
#signal ⇒ Hash<start: Array<Integer>, finish: Array<Integer>, failed: Array<Integer>>
The signals that inform the game what quest started or has been finished.
Instance Method Summary collapse
-
#active_quest(quest_id) ⇒ Quest
Return an active quest by its id.
-
#add_item(item_id)
Inform the manager that an item has been added to the bag of the Player.
-
#beat_npc(quest_id, npc_name_index) ⇒ Boolean
Inform the manager that a NPC has been beaten.
-
#beat_pokemon(pokemon_id)
Inform the manager that a Pokemon has been beaten.
-
#catch_pokemon(pokemon)
Inform the manager that a Pokemon has been captured.
-
#check_quest(quest_id)
Check if a quest is done or not.
-
#check_up_signal
Check the signals and display them.
-
#earnings_got?(quest_id) ⇒ Boolean
Does the earning of a quest has been taken.
-
#egg_found
(also: #get_egg)
Inform the manager an egg has been found.
-
#failed?(quest_id) ⇒ Boolean
Is a quest failed ?.
-
#failed_quest(quest_id) ⇒ Quest
Return a failed quest by its id.
-
#finished?(quest_id) ⇒ Boolean
Is a quest finished ?.
-
#finished_quest(quest_id) ⇒ Quest
Return a finished quest by its id.
-
#get_earnings(quest_id) ⇒ Boolean
Get the earnings of a quest.
-
#get_goal_data_index(quest_id, goal_index) ⇒ Integer
Get the goal data index (if array like items / speak_to return the index of the goal in the array info from data/quest data).
-
#goal_shown?(quest_id, goal_index) ⇒ Boolean
Tell if a goal is shown or not.
-
#hatch_egg
Inform the manager an egg has hatched.
- #import_from_dot24
-
#initialize ⇒ Quests
constructor
Create a new Quest management object.
-
#see_pokemon(pokemon_id)
Inform the manager that a Pokemon has been seen.
-
#show_goal(quest_id, goal_index)
Show a goal of a quest.
-
#speak_to_npc(quest_id, npc_name_index) ⇒ Boolean
Inform the manager that a NPC has been spoken to.
-
#start(quest_id) ⇒ Boolean
Start a new quest if possible.
Constructor Details
#initialize ⇒ Quests
Create a new Quest management object
23 24 25 26 27 28 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 23 def initialize @active_quests = {} @finished_quests = {} @failed_quests = {} @signal = { start: [], finish: [], failed: [] } end |
Instance Attribute Details
#active_quests ⇒ Hash<Integer => Quest>
The list of active_quests
12 13 14 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 12 def active_quests @active_quests end |
#failed_quests ⇒ Hash<Integer => Quest>
The list of failed_quests
18 19 20 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 18 def failed_quests @failed_quests end |
Instance Method Details
#active_quest(quest_id) ⇒ Quest
Return an active quest by its id
46 47 48 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 46 def active_quest(quest_id) return @active_quests[quest_id] end |
#add_item(item_id)
Inform the manager that an item has been added to the bag of the Player
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 133 def add_item(item_id) item_db_symbol = data_item(item_id).db_symbol active_quests.each_value do |quest| if quest.objective?(:objective_obtain_item, item_db_symbol) old_count = quest.data_get(:obtained_items, item_db_symbol, 0) quest.data_set(:obtained_items, item_db_symbol, old_count + 1) check_quest(quest.quest_id) next end next unless quest.objective?(:objective_obtain_item, item_id) old_count = quest.data_get(:obtained_items, item_id, 0) quest.data_set(:obtained_items, item_id, old_count + 1) check_quest(quest.quest_id) end end |
#beat_npc(quest_id, npc_name_index) ⇒ Boolean
Inform the manager that a NPC has been beaten
108 109 110 111 112 113 114 115 116 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 108 def beat_npc(quest_id, npc_name_index) return false unless (quest = active_quest(quest_id)) return false unless quest.objective?(:objective_beat_npc, npc_name_index) old_count = quest.data_get(:npc_beaten, npc_name_index, 0) quest.data_set(:npc_beaten, npc_name_index, old_count + 1) check_quest(quest_id) return true end |
#beat_pokemon(pokemon_id)
Inform the manager that a Pokemon has been beaten
152 153 154 155 156 157 158 159 160 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 152 def beat_pokemon(pokemon_id) active_quests.each_value do |quest| next unless quest.objective?(:objective_beat_pokemon, pokemon_id) old_count = quest.data_get(:pokemon_beaten, pokemon_id, 0) quest.data_set(:pokemon_beaten, pokemon_id, old_count + 1) check_quest(quest.quest_id) end end |
#catch_pokemon(pokemon)
Inform the manager that a Pokemon has been captured
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 164 def catch_pokemon(pokemon) active_quests.each_value do |quest| next unless quest.objective?(:objective_catch_pokemon) quest_data = data_quest(quest.quest_id) quest_data.objectives.each do |objective| next unless objective.test_method_name == :objective_catch_pokemon pokemon_id = objective.test_method_args.first next unless quest.objective_catch_pokemon_test(pokemon_id, pokemon) old_count = quest.data_get(:pokemon_caught, pokemon_id, 0) quest.data_set(:pokemon_caught, pokemon_id, old_count + 1) check_quest(quest.quest_id) end end end |
#check_quest(quest_id)
Check if a quest is done or not
239 240 241 242 243 244 245 246 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 239 def check_quest(quest_id) return unless (quest = active_quest(quest_id)) return if @signal[:finish].include?(quest_id) return unless quest.finished? @signal[:finish] << quest_id check_up_signal if AUTO_CHECK_SIGNAL_ON_ALL_OBJECTIVE_VALIDATED end |
#check_up_signal
Check the signals and display them
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 217 def check_up_signal return unless $scene.is_a?(Scene_Map) if @signal[:start].any? start_names = @signal[:start].map { |quest_id| data_quest(quest_id).name } show_quest_inform(start_names, true) end if @signal[:finish].any? finish_names = @signal[:finish].collect { |quest_id| data_quest(quest_id).name } show_quest_inform(finish_names, false) # Switch the quests from stack to stack @signal[:finish].each do |quest_id| @finished_quests[quest_id] = @active_quests[quest_id] if @active_quests[quest_id] @active_quests.delete(quest_id) end end @signal[:start].clear @signal[:finish].clear end |
#earnings_got?(quest_id) ⇒ Boolean
Does the earning of a quest has been taken
277 278 279 280 281 282 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 277 def earnings_got?(quest_id) check_up_signal if AUTO_CHECK_SIGNAL_ON_TEST return false unless (quest = finished_quest(quest_id)) return quest.data_get(:earnings_distributed, false) end |
#egg_found Also known as: get_egg
Inform the manager an egg has been found
194 195 196 197 198 199 200 201 202 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 194 def egg_found active_quests.each_value do |quest| next unless quest.objective?(:objective_obtain_egg) old_count = quest.data_get(:obtained_eggs, 0) quest.data_set(:obtained_eggs, old_count + 1) check_quest(quest.quest_id) end end |
#failed?(quest_id) ⇒ Boolean
Is a quest failed ?
259 260 261 262 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 259 def failed?(quest_id) check_up_signal if AUTO_CHECK_SIGNAL_ON_TEST return !@failed_quests.fetch(quest_id, nil).nil? end |
#failed_quest(quest_id) ⇒ Quest
Return a failed quest by its id
60 61 62 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 60 def failed_quest(quest_id) return @failed_quests[quest_id] end |
#finished?(quest_id) ⇒ Boolean
Is a quest finished ?
251 252 253 254 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 251 def finished?(quest_id) check_up_signal if AUTO_CHECK_SIGNAL_ON_TEST return !@finished_quests.fetch(quest_id, nil).nil? end |
#finished_quest(quest_id) ⇒ Quest
Return a finished quest by its id
53 54 55 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 53 def finished_quest(quest_id) return @finished_quests[quest_id] end |
#get_earnings(quest_id) ⇒ Boolean
Get the earnings of a quest
267 268 269 270 271 272 273 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 267 def get_earnings(quest_id) return false unless (quest = finished_quest(quest_id)) return false if quest.data_get(:earnings_distributed, false) quest.distribute_earnings return true end |
#get_goal_data_index(quest_id, goal_index) ⇒ Integer
Get the goal data index (if array like items / speak_to return the index of the goal in the array info from data/quest data)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 88 def get_goal_data_index(quest_id, goal_index) raise ScriptError, 'This method should be removed!!!!' if (quest = @active_quests.fetch(quest_id, nil)).nil? if (quest = @finished_quests.fetch(quest_id, nil)).nil? return 0 if (quest = @failed_quests.fetch(quest_id, nil)).nil? end end goal_sym = quest[:order][goal_index] cnt = 0 quest[:order].each_with_index do |sym, i| break if i >= goal_index cnt += 1 if sym == goal_sym end return cnt end |
#goal_shown?(quest_id, goal_index) ⇒ Boolean
Tell if a goal is shown or not
77 78 79 80 81 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 77 def goal_shown?(quest_id, goal_index) return false unless (quest = active_quest(quest_id)) return quest.data_get(:goals_visibility, goal_index, false) end |
#hatch_egg
Inform the manager an egg has hatched
206 207 208 209 210 211 212 213 214 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 206 def hatch_egg active_quests.each_value do |quest| next unless quest.objective?(:objective_hatch_egg) old_count = quest.data_get(:hatched_eggs, nil, 0) quest.data_set(:hatched_eggs, nil, old_count + 1) check_quest(quest.quest_id) end end |
#import_from_dot24
284 285 286 287 288 289 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 284 def import_from_dot24 mapper = ->((id, quest)) { [id, convert_quest_from_dot24_to_dot25(id, quest)] } @active_quests = @active_quests.map(&mapper).to_h @finished_quests = @finished_quests.map(&mapper).to_h @failed_quests = @failed_quests.map(&mapper).to_h end |
#see_pokemon(pokemon_id)
Inform the manager that a Pokemon has been seen
184 185 186 187 188 189 190 191 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 184 def see_pokemon(pokemon_id) active_quests.each_value do |quest| next unless quest.objective?(:objective_see_pokemon, pokemon_id) quest.data_set(:pokemon_seen, pokemon_id, true) check_quest(quest.quest_id) end end |
#show_goal(quest_id, goal_index)
Show a goal of a quest
67 68 69 70 71 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 67 def show_goal(quest_id, goal_index) return unless (quest = active_quest(quest_id)) quest.data_set(:goals_visibility, goal_index, true) end |
#speak_to_npc(quest_id, npc_name_index) ⇒ Boolean
Inform the manager that a NPC has been spoken to
122 123 124 125 126 127 128 129 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 122 def speak_to_npc(quest_id, npc_name_index) return false unless (quest = active_quest(quest_id)) return false unless quest.objective?(:objective_speak_to, npc_name_index) quest.data_set(:spoken, npc_name_index, true) check_quest(quest_id) return true end |
#start(quest_id) ⇒ Boolean
Start a new quest if possible
33 34 35 36 37 38 39 40 41 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 33 def start(quest_id) return false if data_quest(quest_id).db_symbol == :__undef__ return false if finished?(quest_id) return false if @active_quests.fetch(quest_id, nil) @active_quests[quest_id] = Quest.new(quest_id) @signal[:start] << quest_id return true end |