Class: PFM::Quests::Quest

Inherits:
Object show all
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

Instance Method Summary collapse

Constructor Details

#initialize(quest_id) ⇒ Quest

Create a new quest

Parameters:

  • quest_id (Integer)

    ID of the 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_idInteger (readonly)

Get the quest id

Returns:



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

Parameters:

  • path (Array<Symbol, Integer>)

    path used to obtain the data

  • default (Object)

    default value

Returns:



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

Parameters:

  • path (Array<Symbol, Integer>)

    path used to obtain the data

  • value (Object)


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

Returns:

  • (Boolean)


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

Parameters:

  • objective_method_name (Symbol)

    name of the method to call to validate the objective

  • args (Array)

    double check to ensure the arguments match the test

Returns:

  • (Boolean)


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

Parameters:

  • pkm (Hash, Integer)

    the criterions of the Pokemon

    The criterions are :

    nature: opt Integer # ID of the nature of the Pokemon
    type: opt Integer # One required type id
    min_level: opt Integer # The minimum level the Pokemon should have
    max_level: opt Integer # The maximum level the Pokemon should have
    level: opt Integer # The level the Pokemon must be
    
  • pokemon (PFM::Pokemon)

    the Pokemon that should be check with the criterions

Returns:

  • (Boolean)

    if the Pokemon pokemon check the criterions



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_listArray<Array(String, Boolean)>

Note:

Does not return text of hidden objectives

Get the list of objective texts with their validation state

Returns:

  • (Array<Array(String, Boolean)>)


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