Class: Battle::Logic::ExpHandler

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/02000 ExpHandler.rb

Overview

Class responsive of calculating experience & EV of Pokemon when a Pokemon faints

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

#exec_hooks, #force_return, included, register, remove, remove_without_name

Constructor Details

#initialize(logic) ⇒ ExpHandler

Create the exp handler

Parameters:



12
13
14
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/02000 ExpHandler.rb', line 12

def initialize(logic)
  @logic = logic
end

Instance Attribute Details

#logicBattle::Logic (readonly)

Get the logic object

Returns:



8
9
10
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/02000 ExpHandler.rb', line 8

def logic
  @logic
end

Class Method Details

.register_power_ev_bonus(reason) {|receiver, enemy, handler| ... }

Register a hook allowing a pokemon to receive a power_ev bonus

Parameters:

  • reason (String)

    reason of the power_ev_bonus call

Yield Parameters:



186
187
188
189
190
191
192
193
194
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/02000 ExpHandler.rb', line 186

def register_power_ev_bonus(reason)
  Hooks.register(ExpHandler, :power_ev_bonus, reason) do |hook_binding|
    yield(
      hook_binding.local_variable_get(:receiver),
      hook_binding.local_variable_get(:enemy),
      self
    )
  end
end

Instance Method Details

#distribute_exp_for(enemy) ⇒ Hash{ PFM::PokemonBattler => Integer }

Distribute the experience for a single pokemon

Parameters:

Returns:



35
36
37
38
39
40
41
42
43
44
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/02000 ExpHandler.rb', line 35

def distribute_exp_for(enemy)
  evable = evable_pokemon(enemy)
  expable = expable_pokemon(enemy)
  return {} if logic.battle_info.disallow_exp?

  distribute_ev_to(evable, enemy)
  exp_data = global_multi_exp_factor? ? distribute_global_exp_for(enemy, expable) : distribute_separate_exp_for(enemy, expable)
  enemy.exp_distributed = true
  return exp_data.to_h
end

#distribute_exp_grouped(enemies) ⇒ Hash{ PFM::PokemonBattler => Integer }

Distribute the experience for several pokemon and merge them

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Handlers/02000 ExpHandler.rb', line 19

def distribute_exp_grouped(enemies)
  exp_distributions = {}
  # Distribute exp and add all enemy that are dead to switch request
  enemies.each do |enemy|
    next if enemy.exp_distributed

    exp_distributions.merge!(distribute_exp_for(enemy)) do |_, old_val, new_val|
      old_val + new_val
    end
  end
  return exp_distributions
end