Class: PFM::Nuzlocke

Inherits:
Object show all
Defined in:
scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb

Overview

Class responsive of managing Nuzlocke information and helping to implement the nuzlocke logic

Author:

  • Logically anime and ralandel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_state = PFM.game_state) ⇒ Nuzlocke

Create a new Nuzlocke object

Parameters:

  • game_state (PFM::GameState) (defaults to: PFM.game_state)

    variable responsive of containing the whole game state for easier access



17
18
19
20
21
22
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 17

def initialize(game_state = PFM.game_state)
  @catch_locked_zones = []
  @no_lock_on_duplicate = false
  @graveyard = []
  @game_state = game_state
end

Instance Attribute Details

#game_statePFM::GameState

Get the game state responsive of the whole game state

Returns:



13
14
15
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 13

def game_state
  @game_state
end

#graveyardArray<PFM::Pokemon>

Storage of dead Pokemon to re-use later in other systems

Returns:



10
11
12
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 10

def graveyard
  @graveyard
end

#no_lock_on_duplicateBoolean

If we prevent Duplicate from locking catch

Returns:

  • (Boolean)


7
8
9
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 7

def no_lock_on_duplicate
  @no_lock_on_duplicate
end

Instance Method Details

#catching_locked?(id) ⇒ Boolean

Tell if catching is locked in the given zone

Parameters:

Returns:

  • (Boolean)


52
53
54
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 52

def catching_locked?(id)
  @catch_locked_zones.include?(id)
end

#catching_locked_here?Boolean

Tell if catching is locked in the current zone

Returns:

  • (Boolean)


58
59
60
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 58

def catching_locked_here?
  catching_locked?(@game_state.env.master_zone)
end

#clear_dead_pokemon Also known as: dead

Function that clears the dead Pokemon from the party and put their item back in the bag



26
27
28
29
30
31
32
33
34
35
36
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 26

def clear_dead_pokemon
  dead_condition = proc { |pokemon| pokemon.hp <= 0 }
  # List all the items from dead Pokemon
  item_ids = @game_state.actors.select(&dead_condition).map(&:item_hold)
  # Add items back to the bag
  item_ids.each { |item_id| @game_state.bag.add_item(item_id, 1) if item_id >= 0 }
  # Storing Pokemon that are dead
  graveyard.concat(@game_state.actors.select(&dead_condition))
  # Remove Pokemon from the party
  @game_state.actors.delete_if(&dead_condition)
end

#disable

Disable the Nuzlocke



80
81
82
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 80

def disable
  switch(false)
end

#enable

Enable the Nuzlocke



75
76
77
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 75

def enable
  switch(true)
end

#enabled?Boolean

Tell if the Nuzlocke is enabled

Returns:

  • (Boolean)


70
71
72
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 70

def enabled?
  @game_state.game_switches[Yuki::Sw::Nuzlocke_ENA]
end

#lock_catch_in_current_zone(pokemon_id)

Note:

This method checks if that's possible to lock before locking

Lock the current zone (prevent Pokemon from being able to be caught here)

Parameters:

  • pokemon_id (Integer)

    ID of the Pokemon that was seen before locking



42
43
44
45
46
47
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 42

def lock_catch_in_current_zone(pokemon_id)
  return if catching_locked_here? || @game_state.game_temp.trainer_battle
  return if no_lock_on_duplicate && @game_state.pokedex.creature_caught?(pokemon_id) && !@game_state.game_switches[Yuki::Sw::BT_Catch]

  @catch_locked_zones.push(@game_state.env.master_zone)
end

#switch(bool)

Switch the enable state of the Nuzlocke

Parameters:

  • bool (Boolean)


64
65
66
# File 'scripts/01450 Systems/00204 Nuzlocke/00001 PFM/01600 Nuzlocke.rb', line 64

def switch(bool)
  @game_state.game_switches[Yuki::Sw::Nuzlocke_ENA] = bool
end