Class: PFM::Trainer

Inherits:
Object show all
Defined in:
scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb

Overview

The actor trainer data informations

Main object stored in $trainer and PFM.game_state.trainer

Author:

  • Nuri Yuri

Constant Summary collapse

TIME_FORMAT =

Time format

'%02d:%02d'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_state = PFM.game_state) ⇒ Trainer

Create a new Trainer

Parameters:

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

    variable responsive of containing the whole game state for easier access



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 48

def initialize(game_state = PFM.game_state)
  @name_boy = default_male_name
  @name_girl = default_female_name
  @game_state = game_state
  game_state.game_switches[Yuki::Sw::Gender] = @playing_girl = false
  game_state.game_variables[Yuki::Var::Player_ID] = @id_boy = rand(0x3FFFFFFF)
  @id_girl = (@id_boy ^ 0x28F4AB4C)
  @start_time = Time.new.to_i
  @play_time = 0
  @badges = Array.new(6 * 8, false)
  @region = 0
  @game_version = Configs.infos.game_version
  @current_version = PSDK_Version rescue 0
  @time_counter = 0
  load_time
end

Instance Attribute Details

#badgesArray<Boolean>

The badges this trainer object has collected

Returns:

  • (Array<Boolean>)


32
33
34
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 32

def badges
  @badges
end

#current_versionInteger

The current version de PSDK (update management). It's saved like game_version

Returns:



41
42
43
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 41

def current_version
  @current_version
end

#game_statePFM::GameState

Get the game state responsive of the whole game state

Returns:



44
45
46
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 44

def game_state
  @game_state
end

#game_versionInteger

The game version in which this object has been saved or created

Returns:



38
39
40
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 38

def game_version
  @game_version
end

#id_boyInteger

The internal ID of the trainer as a boy

Returns:



20
21
22
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 20

def id_boy
  @id_boy
end

#id_girlInteger

The internal ID of the trainer as a girl. It's equal to id_boy ^ 0x28F4AB4C

Returns:



23
24
25
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 23

def id_girl
  @id_girl
end

#name_boyString

Name of the trainer as a boy (Default to Palbolsky)

Returns:



11
12
13
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 11

def name_boy
  @name_boy
end

#name_girlString

Name of the trainer as a girl (Default to Yuri)

Returns:



14
15
16
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 14

def name_girl
  @name_girl
end

#play_timeInteger

The time the player has played as this Trainer object

Returns:



29
30
31
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 29

def play_time
  @play_time
end

#playing_girlBoolean

If the player is playing the girl trainer

Returns:

  • (Boolean)


17
18
19
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 17

def playing_girl
  @playing_girl
end

#regionInteger

The ID of the current region in which the trainer is

Returns:



35
36
37
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 35

def region
  @region
end

#start_timeInteger

The time in second when the Trainer object has been created (computer time)

Returns:



26
27
28
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 26

def start_time
  @start_time
end

Instance Method Details

#badge_counterInteger

Return the number of badges the trainer got

Returns:



117
118
119
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 117

def badge_counter
  @badges.count { |badge| badge == true }
end

#badge_obtained?(badge_num, region = 1) ⇒ Boolean Also known as: has_badge?

Has the player got the badge ?

Parameters:

  • badge_num (1, 2, 3, 4, 5, 6, 7, 8)

    the badge

  • region (Integer) (defaults to: 1)

    the region id (starting by 1)

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
149
150
151
152
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 141

def badge_obtained?(badge_num, region = 1)
  region -= 1
  badge_num -= 1
  if (region * 8) >= @badges.size
    log_error('Le jeu ne prévoit pas de badge pour cette région. PSDK_ERR n°000_006')
  elsif badge_num < 0 || badge_num > 7
    log_error('Le numéro de badge indiqué est invalide, il doit être entre 1 et 8. PSDK_ERR n°000_007')
  else
    return @badges[(region * 8) + badge_num]
  end
  return false
end

#define_gender(playing_girl) Also known as: set_gender

Set the gender of the trainer

Parameters:

  • playing_girl (Boolean)

    if the trainer will be a girl



157
158
159
160
161
162
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 157

def define_gender(playing_girl)
  @playing_girl = playing_girl
  game_state.game_switches[Yuki::Sw::Gender] = playing_girl
  game_state.game_variables[Yuki::Var::Player_ID] = id
  game_state.game_actors[1].name = name
end

#idInteger

Return the id of the trainer

Returns:



84
85
86
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 84

def id
  return @playing_girl ? @id_girl : @id_boy
end

#load_time

Load the time counter with the current time



96
97
98
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 96

def load_time
  @time_counter = Time.new.to_i
end

#nameString

Return the name of the trainer

Returns:



67
68
69
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 67

def name
  return @playing_girl ? @name_girl : @name_boy
end

#name=(value)

Change the name of the trainer

Parameters:

  • value (String)

    the new value of the trainer name



73
74
75
76
77
78
79
80
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 73

def name=(value)
  if @playing_girl
    @name_girl = value
  else
    @name_boy = value
  end
  game_state.game_actors[1].name = value
end

#play_time_textString

Return the play time text (without updating it)

Returns:



167
168
169
170
171
172
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 167

def play_time_text
  time = @play_time
  hours = time / 3600
  minutes = (time - 3600 * hours) / 60
  return format(TIME_FORMAT, hours, minutes)
end

#redefine_var

Redefine some variable RMXP uses with the right values



89
90
91
92
93
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 89

def redefine_var
  game_state.game_variables[Yuki::Var::Player_ID] = id
  game_state.game_actors[1].name = name
  # redefinir les badges
end

#set_badge(badge_num, region = 1, value = true)

Set the got state of a badge

Parameters:

  • badge_num (1, 2, 3, 4, 5, 6, 7, 8)

    the badge

  • region (Integer) (defaults to: 1)

    the region id (starting by 1)

  • value (Boolean) (defaults to: true)

    the got state of the badge



125
126
127
128
129
130
131
132
133
134
135
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 125

def set_badge(badge_num, region = 1, value = true)
  region -= 1
  badge_num -= 1
  if (region * 8) >= @badges.size
    log_error('Le jeu ne prévoit pas de badge pour cette région. PSDK_ERR n°000_006')
  elsif badge_num < 0 || badge_num > 7
    log_error('Le numéro de badge indiqué est invalide, il doit être entre 1 et 8. PSDK_ERR n°000_007')
  else
    @badges[(region * 8) + badge_num] = value
  end
end

#time_counterInteger

Return the time counter (current time - time counter)

Returns:



102
103
104
105
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 102

def time_counter
  counter = Time.new.to_i - @time_counter
  return counter < 0 ? 0 : counter
end

#update_play_timeInteger

Update the play time and reload the time counter

Returns:



109
110
111
112
113
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 109

def update_play_time
  @play_time += time_counter
  load_time
  return @play_time
end