Class: Game_Event

Inherits:
Game_Character show all
Defined in:
Game_Event.rb

Overview

** Game_Event


This class handles events. Functions include event page switching via

condition determinants and running parallel process events. Used within the Game_Map class.

Constant Summary

Constant Summary

Constants inherited from Game_Character

Game_Character::ROUTE_CHANGE_BLENDING, Game_Character::ROUTE_CHANGE_FREQ, Game_Character::ROUTE_CHANGE_GRAPHIC, Game_Character::ROUTE_CHANGE_OPACITY, Game_Character::ROUTE_CHANGE_SPEED, Game_Character::ROUTE_DIR_FIX_OFF, Game_Character::ROUTE_DIR_FIX_ON, Game_Character::ROUTE_END, Game_Character::ROUTE_JUMP, Game_Character::ROUTE_MOVE_AWAY, Game_Character::ROUTE_MOVE_BACKWARD, Game_Character::ROUTE_MOVE_DOWN, Game_Character::ROUTE_MOVE_FORWARD, Game_Character::ROUTE_MOVE_LEFT, Game_Character::ROUTE_MOVE_LOWER_L, Game_Character::ROUTE_MOVE_LOWER_R, Game_Character::ROUTE_MOVE_RANDOM, Game_Character::ROUTE_MOVE_RIGHT, Game_Character::ROUTE_MOVE_TOWARD, Game_Character::ROUTE_MOVE_UP, Game_Character::ROUTE_MOVE_UPPER_L, Game_Character::ROUTE_MOVE_UPPER_R, Game_Character::ROUTE_PLAY_SE, Game_Character::ROUTE_SCRIPT, Game_Character::ROUTE_STEP_ANIME_OFF, Game_Character::ROUTE_STEP_ANIME_ON, Game_Character::ROUTE_SWITCH_OFF, Game_Character::ROUTE_SWITCH_ON, Game_Character::ROUTE_THROUGH_OFF, Game_Character::ROUTE_THROUGH_ON, Game_Character::ROUTE_TRANSPARENT_OFF, Game_Character::ROUTE_TRANSPARENT_ON, Game_Character::ROUTE_TURN_180D, Game_Character::ROUTE_TURN_90D_L, Game_Character::ROUTE_TURN_90D_R, Game_Character::ROUTE_TURN_90D_R_L, Game_Character::ROUTE_TURN_AWAY, Game_Character::ROUTE_TURN_DOWN, Game_Character::ROUTE_TURN_LEFT, Game_Character::ROUTE_TURN_RANDOM, Game_Character::ROUTE_TURN_RIGHT, Game_Character::ROUTE_TURN_TOWARD, Game_Character::ROUTE_TURN_UP, Game_Character::ROUTE_WAIT, Game_Character::ROUTE_WALK_ANIME_OFF, Game_Character::ROUTE_WALK_ANIME_ON

Instance Attribute Summary (collapse)

Attributes inherited from Game_Character

#move_route_forcing

Attributes inherited from Game_CharacterBase

#animation_id, #balloon_id, #blend_type, #bush_depth, #character_index, #character_name, #direction, #direction_fix, #id, #move_frequency, #move_speed, #opacity, #pattern, #priority_type, #real_x, #real_y, #step_anime, #through, #tile_id, #transparent, #walk_anime, #x, #y

Instance Method Summary (collapse)

Methods inherited from Game_Character

#advance_move_route_index, #distance_x_from, #distance_y_from, #force_move_route, #jump, #memorize_move_route, #move_away_from_character, #move_away_from_player, #move_backward, #move_forward, #move_random, #move_toward_character, #move_toward_player, #process_move_command, #process_route_end, #restore_move_route, #swap, #turn_180, #turn_away_from_character, #turn_away_from_player, #turn_left_90, #turn_random, #turn_right_90, #turn_right_or_left_90, #turn_toward_character, #turn_toward_player, #update_routine_move

Methods inherited from Game_CharacterBase

#bush?, #check_event_trigger_touch_front, #collide_with_events?, #collide_with_vehicles?, #dash?, #debug_through?, #diagonal_passable?, #distance_per_frame, #increase_steps, #jump_height, #jumping?, #ladder?, #map_passable?, #move_diagonal, #move_straight, #moveto, #moving?, #normal_priority?, #object_character?, #passable?, #pos?, #pos_nt?, #real_move_speed, #region_id, #reverse_dir, #screen_x, #screen_y, #screen_z, #set_direction, #set_graphic, #shift_y, #stopping?, #straighten, #terrain_tag, #tile?, #update_animation, #update_anime_count, #update_anime_pattern, #update_bush_depth, #update_jump, #update_move

Constructor Details

- (Game_Event) initialize(map_id, event)


  • Object Initialization

    event:  RPG::Event



20
21
22
23
24
25
26
27
# File 'Game_Event.rb', line 20

def initialize(map_id, event)
  super()
  @map_id = map_id
  @event = event
  @id = @event.id
  moveto(@event.x, @event.y)
  refresh
end

Instance Attribute Details

- (Object) list (readonly)

list of event commands



14
15
16
# File 'Game_Event.rb', line 14

def list
  @list
end

- (Object) starting (readonly)

starting flag



15
16
17
# File 'Game_Event.rb', line 15

def starting
  @starting
end

- (Object) trigger (readonly)


  • Public Instance Variables




13
14
15
# File 'Game_Event.rb', line 13

def trigger
  @trigger
end

Instance Method Details

- (Object) check_event_trigger_auto


  • Determine if Autorun Event is Triggered




295
296
297
# File 'Game_Event.rb', line 295

def check_event_trigger_auto
  start if @trigger == 3
end

- (Object) check_event_trigger_touch(x, y)


  • Determine if Touch Event is Triggered




286
287
288
289
290
291
# File 'Game_Event.rb', line 286

def check_event_trigger_touch(x, y)
  return if $game_map.interpreter.running?
  if @trigger == 2 && $game_player.pos?(x, y)
    start if !jumping? && normal_priority?
  end
end

- (Object) clear_page_settings


  • Clear Event Page Settings




242
243
244
245
246
247
248
249
250
251
# File 'Game_Event.rb', line 242

def clear_page_settings
  @tile_id          = 0
  @character_name   = ""
  @character_index  = 0
  @move_type        = 0
  @through          = true
  @trigger          = nil
  @list             = nil
  @interpreter      = nil
end

- (Object) clear_starting_flag


  • Clear Starting Flag




153
154
155
# File 'Game_Event.rb', line 153

def clear_starting_flag
  @starting = false
end

- (Boolean) collide_with_characters?(x, y)


  • Detect Collision with Character


Returns:

  • (Boolean)


49
50
51
# File 'Game_Event.rb', line 49

def collide_with_characters?(x, y)
  super || collide_with_player_characters?(x, y)
end

- (Boolean) collide_with_player_characters?(x, y)


  • Detect Collision with Player (Including Followers)


Returns:

  • (Boolean)


55
56
57
# File 'Game_Event.rb', line 55

def collide_with_player_characters?(x, y)
  normal_priority? && $game_player.collide?(x, y)
end

- (Boolean) conditions_met?(page)


  • Determine if Event Page Conditions Are Met


Returns:

  • (Boolean)


200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'Game_Event.rb', line 200

def conditions_met?(page)
  c = page.condition
  if c.switch1_valid
    return false unless $game_switches[c.switch1_id]
  end
  if c.switch2_valid
    return false unless $game_switches[c.switch2_id]
  end
  if c.variable_valid
    return false if $game_variables[c.variable_id] < c.variable_value
  end
  if c.self_switch_valid
    key = [@map_id, @event.id, c.self_switch_ch]
    return false if $game_self_switches[key] != true
  end
  if c.item_valid
    item = $data_items[c.item_id]
    return false unless $game_party.has_item?(item)
  end
  if c.actor_valid
    actor = $game_actors[c.actor_id]
    return false unless $game_party.members.include?(actor)
  end
  return true
end

- (Boolean) empty?


  • Determine if Contents Are Empty


Returns:

  • (Boolean)


159
160
161
# File 'Game_Event.rb', line 159

def empty?
  !@list || @list.size <= 1
end

- (Object) erase


  • Temporarily Erase




180
181
182
183
# File 'Game_Event.rb', line 180

def erase
  @erased = true
  refresh
end

- (Object) find_proper_page


  • Find Event Page Meeting Conditions




194
195
196
# File 'Game_Event.rb', line 194

def find_proper_page
  @event.pages.reverse.find {|page| conditions_met?(page) }
end

- (Object) init_private_members


  • Initialize Private Member Variables




40
41
42
43
44
45
# File 'Game_Event.rb', line 40

def init_private_members
  super
  @move_type = 0                        # Movement type
  @erased = false                       # Temporary erase flag
  @page = nil                           # Event page
end

- (Object) init_public_members


  • Initialize Public Member Variables




31
32
33
34
35
36
# File 'Game_Event.rb', line 31

def init_public_members
  super
  @trigger = 0
  @list = nil
  @starting = false
end

- (Object) lock


  • Lock (Processing in Which Executing Events Stop)




61
62
63
64
65
66
67
# File 'Game_Event.rb', line 61

def lock
  unless @locked
    @prelock_direction = @direction
    turn_toward_player
    @locked = true
  end
end

- (Object) move_type_custom


  • Move Type : Custom




147
148
149
# File 'Game_Event.rb', line 147

def move_type_custom
  update_routine_move
end

- (Object) move_type_random


  • Move Type : Random




115
116
117
118
119
120
121
# File 'Game_Event.rb', line 115

def move_type_random
  case rand(6)
  when 0..1;  move_random
  when 2..4;  move_forward
  when 5;     @stop_count = 0
  end
end

- (Object) move_type_toward_player


  • Move Type : Approach




125
126
127
128
129
130
131
132
133
134
135
# File 'Game_Event.rb', line 125

def move_type_toward_player
  if near_the_player?
    case rand(6)
    when 0..3;  move_toward_player
    when 4;     move_random
    when 5;     move_forward
    end
  else
    move_random
  end
end

- (Boolean) near_the_player?


  • Determine if Near Player


Returns:

  • (Boolean)


139
140
141
142
143
# File 'Game_Event.rb', line 139

def near_the_player?
  sx = distance_x_from($game_player.x).abs
  sy = distance_y_from($game_player.y).abs
  sx + sy < 20
end

- (Boolean) near_the_screen?(dx = 12, dy = 8)


  • Determine if Near Visible Area of Screen

    dx:  A certain number of tiles left/right of screen's center
    dy:  A certain number of tiles above/below screen's center

Returns:

  • (Boolean)


101
102
103
104
105
# File 'Game_Event.rb', line 101

def near_the_screen?(dx = 12, dy = 8)
  ax = $game_map.adjust_x(@real_x) - Graphics.width / 2 / 32
  ay = $game_map.adjust_y(@real_y) - Graphics.height / 2 / 32
  ax >= -dx && ax <= dx && ay >= -dy && ay <= dy
end

- (Object) refresh


  • Refresh




187
188
189
190
# File 'Game_Event.rb', line 187

def refresh
  new_page = @erased ? nil : find_proper_page
  setup_page(new_page) if !new_page || new_page != @page
end

- (Object) setup_page(new_page)


  • Event Page Setup




228
229
230
231
232
233
234
235
236
237
238
# File 'Game_Event.rb', line 228

def setup_page(new_page)
  @page = new_page
  if @page
    setup_page_settings
  else
    clear_page_settings
  end
  update_bush_depth
  clear_starting_flag
  check_event_trigger_auto
end

- (Object) setup_page_settings


  • Set Up Event Page Settings




255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'Game_Event.rb', line 255

def setup_page_settings
  @tile_id          = @page.graphic.tile_id
  @character_name   = @page.graphic.character_name
  @character_index  = @page.graphic.character_index
  if @original_direction != @page.graphic.direction
    @direction          = @page.graphic.direction
    @original_direction = @direction
    @prelock_direction  = 0
  end
  if @original_pattern != @page.graphic.pattern
    @pattern            = @page.graphic.pattern
    @original_pattern   = @pattern
  end
  @move_type          = @page.move_type
  @move_speed         = @page.move_speed
  @move_frequency     = @page.move_frequency
  @move_route         = @page.move_route
  @move_route_index   = 0
  @move_route_forcing = false
  @walk_anime         = @page.walk_anime
  @step_anime         = @page.step_anime
  @direction_fix      = @page.direction_fix
  @through            = @page.through
  @priority_type      = @page.priority_type
  @trigger            = @page.trigger
  @list               = @page.list
  @interpreter = @trigger == 4 ? Game_Interpreter.new : nil
end

- (Object) start


  • Start Event




172
173
174
175
176
# File 'Game_Event.rb', line 172

def start
  return if empty?
  @starting = true
  lock if trigger_in?([0,1,2])
end

- (Object) stop_count_threshold


  • Calculate Threshold of Counter for Stopping Autonomous Movement Startup




109
110
111
# File 'Game_Event.rb', line 109

def stop_count_threshold
  30 * (5 - @move_frequency)
end

- (Boolean) trigger_in?(triggers)


  • Determine if One of Specified Triggers

    triggers : Trigger array

Returns:

  • (Boolean)


166
167
168
# File 'Game_Event.rb', line 166

def trigger_in?(triggers)
  triggers.include?(@trigger)
end

- (Object) unlock


  • Unlock




71
72
73
74
75
76
# File 'Game_Event.rb', line 71

def unlock
  if @locked
    @locked = false
    set_direction(@prelock_direction)
  end
end

- (Object) update


  • Frame Update




301
302
303
304
305
306
307
# File 'Game_Event.rb', line 301

def update
  super
  check_event_trigger_auto
  return unless @interpreter
  @interpreter.setup(@list, @event.id) unless @interpreter.running?
  @interpreter.update
end

- (Object) update_self_movement


  • Update During Autonomous Movement




87
88
89
90
91
92
93
94
95
# File 'Game_Event.rb', line 87

def update_self_movement
  if near_the_screen? && @stop_count > stop_count_threshold
    case @move_type
    when 1;  move_type_random
    when 2;  move_type_toward_player
    when 3;  move_type_custom
    end
  end
end

- (Object) update_stop


  • Update While Stopped




80
81
82
83
# File 'Game_Event.rb', line 80

def update_stop
  super
  update_self_movement unless @move_route_forcing
end