Module: Yuki::FollowMe

Defined in:
scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb,
scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb

Overview

The Player Follower Manager

Author:

  • Nuri Yuri

Class Method Summary collapse

Class Method Details

.clear

Clears the follower (and dispose them)



160
161
162
163
164
165
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 160

def clear
  return unless @followers

  @followers.each { |i| i&.dispose }
  @followers.clear
end

.dispose

Dispose the follower and release resources.



252
253
254
255
256
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 252

def dispose
  @followers&.each { |i| i.dispose if i && !i.disposed? }
  @followers = nil
  @viewport = nil
end

.each_follower(&block)

yield a block on each Followers

Examples:

Turn each follower down

Yuki::FollowMe.each_follower { |c| c.turn_down }

Parameters:

  • block (Proc)

    the block to call



181
182
183
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 181

def each_follower(&block)
  @followers&.collect(&:character)&.each(&block)
end

.enabledBoolean

Tell if the system is enabled or not

Returns:

  • (Boolean)


7
8
9
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 7

def enabled
  $game_switches[Sw::FM_Enabled]
end

.enabled=(state)

Enable or disabled the system

Parameters:

  • state (Boolean)

    new enabled state



13
14
15
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 13

def enabled=(state)
  $game_switches[Sw::FM_Enabled] = state
end

.follower_entitiesArray<#character_name>

Get the follower entities (those giving information about character_name)

Returns:

  • (Array<#character_name>)


61
62
63
64
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 61

def follower_entities
  player_pokemon = in_lets_go_mode? ? player_pokemon_lets_go_entity : player_pokemon_entities
  return human_entities.concat(player_pokemon).concat(other_pokemon_entities)
end

.get_follower(i) ⇒ Game_Character

Retrieve a follower

Parameters:

  • i (Integer)

    index of the follower in the @followers Array

Returns:



170
171
172
173
174
175
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 170

def get_follower(i)
  if @followers && @followers[i]
    return @followers[i].character
  end
  return $game_player
end

.human_countInteger

Get the number of human following the player (Heroes from 2 to n+1)

Returns:



31
32
33
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 31

def human_count
  $game_variables[Var::FM_N_Human]
end

.human_count=(count)

Set the number of human following the player

Parameters:

  • count (Integer)

    number of human



37
38
39
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 37

def human_count=(count)
  $game_variables[Var::FM_N_Human] = count
end

.human_entitiesArray<#character_name>

Get the human follower entities

Returns:

  • (Array<#character_name>)


68
69
70
71
72
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 68

def human_entities
  human = (0...human_count).map { |i| $game_actors[i + 2] }
  human.compact!
  return human
end

.in_lets_go_mode?Boolean

Is the FollowMe in Let's Go Mode

Returns:

  • (Boolean)


67
68
69
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 67

def in_lets_go_mode?
  $game_switches[Sw::FollowMe_LetsGoMode]
end

.init(viewport)

Init the FollowMe on a new viewport. Previous Follower are disposed.

Parameters:

  • viewport (Viewport)

    the new viewport



15
16
17
18
19
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 15

def init(viewport)
  dispose if @followers
  @viewport = viewport
  @followers = []
end

.is_player_follower?(character) ⇒ Boolean

Test if a character is a Follower of the player

Parameters:

Returns:

  • (Boolean)


234
235
236
237
238
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 234

def is_player_follower?(character)
  return false unless @followers

  return @followers.any? { |follower_sprite| follower_sprite.character == character }
end

.lets_go_mode=(mode)

Set the FollowMe Let's Go Mode state

Parameters:

  • mode (Boolean)

    true if in lets go mode



73
74
75
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 73

def lets_go_mode=(mode)
  $game_switches[Sw::FollowMe_LetsGoMode] = mode
end

.other_pokemon_countInteger

Get the number of Pokemon from “other_party” following the player

Returns:



55
56
57
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 55

def other_pokemon_count
  $game_variables[Var::FM_N_Friend]
end

.other_pokemon_count=(count)

Set the number of Pokemon from “other_party” following the player

Parameters:



61
62
63
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 61

def other_pokemon_count=(count)
  $game_variables[Var::FM_N_Friend] = count
end

.other_pokemon_entitiesArray<#character_name>

Get the friend's pokemon follower entities

Returns:

  • (Array<#character_name>)


94
95
96
97
98
99
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 94

def other_pokemon_entities
  other_mon = (0...other_pokemon_count).map { |i| $storage.other_party[i] }
  other_mon.compact!
  other_mon.reject!(&:dead?)
  return other_mon
end

.particle_push

Push particle of each character if the Follower Manager was in Battle mode.



246
247
248
249
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 246

def particle_push
  each_follower(&:particle_push) if @was_fighting
  @was_fighting = false
end

.player_pokemon_entitiesArray<#character_name>

Get the player's pokemon follower entities

Returns:

  • (Array<#character_name>)


76
77
78
79
80
81
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 76

def player_pokemon_entities
  player_mon = (0...pokemon_count).map { |i| $actors[i] }
  player_mon.compact!
  player_mon.reject!(&:dead?)
  return player_mon
end

.player_pokemon_lets_go_entityArray<#character_name>

Get the player's pokemon follower entity if the FollowMe mode is Let's Go

Returns:

  • (Array<#character_name>)


85
86
87
88
89
90
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 85

def player_pokemon_lets_go_entity
  follower = $storage.lets_go_follower
  return [] unless follower && !follower.dead? && $actors.include?(follower)

  return [follower]
end

.pokemon_countInteger

Get the number of pokemon following the player

Returns:



43
44
45
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 43

def pokemon_count
  $game_variables[Var::FM_N_Pokem]
end

.pokemon_count=(count)

Set the number of pokemon following the player

Parameters:



49
50
51
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 49

def pokemon_count=(count)
  $game_variables[Var::FM_N_Pokem] = count
end

.position_character(c, i)

Sets the default position of a follower

Parameters:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 131

def position_character(c,i)
  return if $game_variables[Yuki::Var::FM_Sel_Foll] > 0
  c1 = (i == 0 ? $game_player : @followers[i - 1].character)
  x = c1.x
  y = c1.y
  if $game_switches[Sw::Env_CanFly] || $game_switches[Sw::FM_NoReset]
    case c1.direction
    when 2
      y -= 1
    when 4
      x += 1
    when 6
      x -= 1
    else
      y += 1
    end
  end
  c.through = false
  if c.passable?(x, y, 0) # c1.direction)) #$game_map
    c.moveto(x, y)
  else
    c.moveto(c1.x, c1.y)
  end
  c.through = true
  c.direction = $game_player.direction
  c.update
end

.reset_position

Reset position of each follower to the player (entering in a building)



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 204

def reset_position
  return unless @followers
  $game_player.reset_follower_move
  @followers.size.times do |i|
    v = @followers[i]
    c = v.character
    x,y = $game_player.x, $game_player.y
    case $game_player.direction
    when 2
      y -= 1
    when 8
      y += 1
    when 4
      x += 1
    when 6
      x -= 1
    end
    x,y = $game_player.x, $game_player.y if !$game_map.passable?(x,y,$game_player.direction)
    c.moveto(x,y)
    c.direction = $game_player.direction
    c.instance_variable_set(:@memorized_move, nil)
    c.instance_variable_set(:@memorized_move_arg, nil)
    c.update
    v.update
    v.z -= 1
  end
end

.selected_followerInteger

Get the current selected follower (to move using player moveroutes)

Returns:

  • (Integer)

    0 = no follower selected



19
20
21
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 19

def selected_follower
  $game_variables[Var::FM_Sel_Foll]
end

.selected_follower=(index1)

Set the selected follower

Parameters:

  • index1 (Integer)

    index of the follower in the follower stack starting at index 1



25
26
27
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00001 Config.rb', line 25

def selected_follower=(index1)
  $game_variables[Var::FM_Sel_Foll] = index1.clamp(0, @followers.size)
end

.set_battle_entry(v = true)

Set the Follower Manager in Battle mode. When getting out of battle every character will get its particle pushed.



241
242
243
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 241

def set_battle_entry(v = true)
  @was_fighting = v
end

.set_player_follower_particles(value)

Enable / Disable the particles for the player followers



274
275
276
277
278
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 274

def set_player_follower_particles(value)
  each_follower do |follower|
    follower.particles_disabled = !value
  end
end

.set_positions(*args)

Sets the position of each follower (Warp)

Parameters:



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 187

def set_positions(*args)
  x = y = 0
  (args.size / 3).times do |i|
    next unless (v = @followers[i])

    c = v.character
    x = args[i * 3]
    y = args[i * 3 + 1]
    c.moveto(x, y)
    c.direction = args[i * 3 + 2]
    c.update
    c.particle_push
    v.update
  end
end

.smart_disable

Smart disable the following system (keep it active when smart_enable is called)



259
260
261
262
263
264
265
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 259

def smart_disable
  return unless $game_switches[Sw::FM_Enabled]
  $game_player.set_follower(nil, true)
  set_player_follower_particles(false)
  $game_switches[Sw::FM_WasEnabled] = $game_switches[Sw::FM_Enabled]
  $game_switches[Sw::FM_Enabled] = false
end

.smart_enable

Smart disable the following system (keep it active when smart_enable is called)



268
269
270
271
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 268

def smart_enable
  set_player_follower_particles(true)
  $game_switches[Sw::FM_Enabled] = $game_switches[Sw::FM_WasEnabled]
end

.update

Update of the Follower Management. Their graphics are updated here.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 22

def update
  entities = follower_entities
  return clear unless enabled

  last_follower = $game_player
  follower_event = @followers.find { |follower| follower.character.follower.is_a?(Game_Event) }&.character&.follower
  follower_event ||= last_follower.follower if last_follower.follower.is_a?(Game_Event)
  chara_update = selected_follower == 0

  # Reset following state
  last_follower.set_follower(nil, true)
  @followers.each { |follower| follower.character.set_follower(nil) }

  # Update each follower
  entities.each_with_index do |entity, index|
    last_follower = update_follower(last_follower, index, entity, chara_update)
  end

  # Remove the remaining followers
  @followers.pop&.dispose while @followers.size > entities.size

  # Update the last follower's follower
  update_follower_event(last_follower, follower_event)
end

.update_follower(last_follower, i, entity, chara_update) ⇒ Game_Character

Update of a single follower

Parameters:

  • last_follower (Game_Character)

    the last follower (in case of Follower creation)

  • i (Integer)

    index in the @followers Array

  • entity (PFM::Pokemon, Game_Actor)

    the entity that is shown as a follower

  • chara_update (Boolean)

    if the character graphics and informations needs to be updated

Returns:

  • (Game_Character)

    the character that will become the last_follower



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 107

def update_follower(last_follower, i, entity, chara_update)
  follower = @followers[i]
  unless follower
    @followers[i] = follower = Sprite_Character.new(@viewport, Game_Character.new)
    position_character(follower.character, i)
    follower.character.z = $game_player.z
  end
  character = follower.character
  last_follower.set_follower(character)
  if chara_update
    character.character_name = entity.character_name
    character.is_pokemon = character.step_anime = entity.class == PFM::Pokemon
  end
  character.move_speed = $game_player.original_move_speed
  character.through = true
  character.update
  follower.update
  follower.z -= 1 if character.x == $game_player.x && character.y == $game_player.y
  return (@followers[i] = follower).character
end

.update_follower_event(last_follower, follower_event)

Function that attempts to set the event as last follower

Parameters:



50
51
52
53
54
55
56
57
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00200 FollowMe/00300 Core.rb', line 50

def update_follower_event(last_follower, follower_event)
  last_follower_event = follower_event
  while last_follower_event&.follower
    last_follower_event.set_follower(nil) unless last_follower_event.follower.is_a?(Game_Event)
    last_follower_event = last_follower_event.follower
  end
  last_follower.set_follower(follower_event) if last_follower.follower != follower_event
end