Class: PFM::Quests::Quest
- Defined in:
- scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb
Overview
Class describing a running quest
Instance Attribute Summary collapse
-
#quest_id ⇒ Integer
readonly
Get the quest id.
Instance Method Summary collapse
-
#data_get(*path, default) ⇒ Object, default
Get a specific data information.
-
#data_set(*path, value)
Set a specific data information.
-
#distribute_earnings
Distribute the earning of the quest.
-
#finished? ⇒ Boolean
Tell if all the objective of the quest are finished.
-
#initialize(quest_id) ⇒ Quest
constructor
Create a new quest.
-
#objective?(objective_method_name, *args) ⇒ Boolean
Test if the quest has a specific kind of objective.
-
#objective_catch_pokemon_test(pkm, pokemon) ⇒ Boolean
Check the specific pokemon criterion in catch_pokemon.
-
#objective_text_list ⇒ Array<Array(String, Boolean)>
Get the list of objective texts with their validation state.
Constructor Details
#initialize(quest_id) ⇒ Quest
Create a new quest
11 12 13 14 15 16 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 11 def initialize(quest_id) @quest_id = quest_id @data = {} quest = data_quest(quest_id) data_set(:goals_visibility, quest.objectives.map { |objective| !objective.hidden_by_default }) end |
Instance Attribute Details
#quest_id ⇒ Integer (readonly)
Get the quest id
7 8 9 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 7 def quest_id @quest_id end |
Instance Method Details
#data_get(*path, default) ⇒ Object, default
Get a specific data information
22 23 24 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 22 def data_get(*path, default) return @data.dig(*path) || default end |
#data_set(*path, value)
Set a specific data information
29 30 31 32 33 34 35 36 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 29 def data_set(*path, value) data = @data last_part = path.pop path.each do |part| data = (data[part] ||= {}) end data[last_part] = value end |
#distribute_earnings
Distribute the earning of the quest
57 58 59 60 61 62 63 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 57 def distribute_earnings data = data_quest(@quest_id) data.earnings.each do |earning| send(earning.earning_method_name, *earning.earning_args) end data_set(:earnings_distributed, true) end |
#finished? ⇒ Boolean
Tell if all the objective of the quest are finished
67 68 69 70 71 72 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 67 def finished? data = data_quest(@quest_id) return data.objectives.all? do |objective| send(objective.objective_method_name, *objective.objective_method_args) end end |
#objective?(objective_method_name, *args) ⇒ Boolean
Test if the quest has a specific kind of objective
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 42 def objective?(objective_method_name, *args) quest = data_quest(quest_id) # @type [Array<Boolean>] objective_visibility = data_get(:goals_visibility, nil.to_a) quest.objectives.each_with_index do |objective, index| next if objective.hidden_by_default && !objective_visibility[index] next unless objective.objective_method_name == objective_method_name next unless args.each_with_index.all? { |arg, i| objective.objective_method_args[i] == arg } return true end return false end |
#objective_catch_pokemon_test(pkm, pokemon) ⇒ Boolean
Check the specific pokemon criterion in catch_pokemon
101 102 103 104 105 106 107 108 109 110 111 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 101 def objective_catch_pokemon_test(pkm, pokemon) return pokemon.id == pkm unless pkm.is_a?(Hash) return false if pkm[:id] && !(pokemon.id == pkm[:id] || pokemon.db_symbol == pkm[:id]) return false if pkm[:nature] && pokemon.nature_id != pkm[:nature] return false if pkm[:type] && pokemon.type1 != pkm[:type] && pokemon.type2 != pkm[:type] return false if pkm[:min_level] && pokemon.level <= pkm[:min_level] return false if pkm[:max_level] && pokemon.level >= pkm[:max_level] return false if pkm[:level] && pokemon.level != pkm[:level] return true end |
#objective_text_list ⇒ Array<Array(String, Boolean)>
Does not return text of hidden objectives
Get the list of objective texts with their validation state
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00002 PFM Quests Quest.rb', line 77 def objective_text_list # @type [Array<Boolean>] objective_visibility = data_get(:goals_visibility, nil.to_a) data = data_quest(@quest_id) visible_objectives = data.objectives.select.with_index { |_, index| objective_visibility[index] } return visible_objectives.map do |objective| [ send(objective.text_format_method_name, *objective.objective_method_args), send(objective.objective_method_name, *objective.objective_method_args) ] end end |