#============================================================================== # ** rmxp standard development kit (sdk) #-----------------------------------------------------------------------------# build date - 2005-11-22 # version 1.0 - near fantastica - 2005-11-22 # version 1.1 - sephirothspawn - 2005-12-18 - (near fantastica) # version 1.2 - near fantastica - 2005-12-18 # version 1.3 - wachunga - 2005-12-19 # version 1.4 - prexus - 2006-03-02 # version 1.5 - jimme reashu - 2006-03-25 - (near fantastica) #-----------------------------------------------------------------------------=begin 1.0 - outline the standard development kit (sdk) aims to increase compatibility between rgss scripts by: a) defining a set of scripting standards (see section 3) b) restructuring often-used default classes and methods (see section 4) c) providing a scripting tools module (see section 5) #-----------------------------------------------------------------------------2.0 - modifications to the rmxp standard development kit since edits to the sdk may cause massive capability errors, any and all modifications must first be approved by a member of the rmxp sdk team. the author of any modifications must be sure to update all relevant documentation. this also includes the header, where the author is to put the next version number with his or her name and the name of the approval member (from the sdk team) under the latest version in the following format. version # - name - date - (approval member name) #-----------------------------------------------------------------------------3.0 - coding standards to be compliant with the sdk, a script must compy with the following coding standards: 3.1 - commenting 3.2 - classes 3.3 - variables 3.4 - aliases 3.5 - strings 3.6 - line length 3.7 - white space 3.8 - constants 3.9 - parentheses #-----------------------------------------------------------------------------3.1 - commenting scripts must begin with the following header: #============================================================================== # ** script name #-----------------------------------------------------------------------------# your name # version # date
#============================================================================== all classes and methods must have a comment describing the process or what was added. all code added to methods that can not be aliased must be formatted as follows: #-----------------------------------------------------------------------------# begin script name edit #-----------------------------------------------------------------------------[code] #-----------------------------------------------------------------------------# end script name edit #-----------------------------------------------------------------------------single line comments should precede the described block of code and should be indented at the same level. code that is not self-documenting should be commented. however, very short comments can appear on the same line as the described code, but should be shifted far enough to separate them from the statements. if more than one short comment appears in a chunk of code, they should all be indented to the same tab setting. attribute declarations should always have a trailing comment. #-----------------------------------------------------------------------------3.2 - classes all classes must be named consistently with the default code, namely: data - any class that holds data game - any class that processes data sprite - any class that defines a sprite spriteset - any class that defines multiple sprites window - any class that defines a window arrow - any class that defines an arrow scene - any class that defines a scene #-----------------------------------------------------------------------------3.3 - variables all variable names must be reasonably descriptive. use of class and global variables should be limited. any variable used by the default system can not have its use changed. #-----------------------------------------------------------------------------3.4 - aliases aliasing a method is preferable to overriding it; an alias should be used whenever possible to increase compatibility with other scripts. all alias names must have the following format: yourname_scriptname_classname_methodname #-----------------------------------------------------------------------------3.5 � strings strings should normally be defined with single quotes ('example'); this decreases the processing time of the engine. double quotes are useful when using the following features: a) substitutions, i.e. sequences that start with a backslash character (e.g. \n for the newline character) b) expression interpolation, i.e. #{ expression } is replaced by the value
of expression #-----------------------------------------------------------------------------3.6 - line length lines should not cause the the viewer to have to scroll sideways to view them in the script editor. when the line needs to be broken, it should follow the following guidelines, in preferential order: break after a comma. break before an operator. prefer higher-level breaks to lower-level breaks. align the new line with the beginning of the expression at the same level on the previous line. if the above rules lead to confusing code or to code that�s squished up against the right margin, just indent 4 spaces instead. #-----------------------------------------------------------------------------3.7 - white space a blank line(s) should be used in the following places: between sections of a source file between class and module definitions between attributes and the class definition between methods between the local variables in a method and its first statement before a block or single-line comment between logical sections inside a method to improve readability blank spaces should be used in the following places: a keyword followed by a parenthesis, e.g. if (some_boolean_statements) after commas in argument lists, e.g. def method (arg1, arg2, ...) all binary operators except '.', e.g. a + b; c = 1 #-----------------------------------------------------------------------------3.8 - constants new numerical values should not be "hard-coded", except for -1, 0, and 1, which can appear in for loops as counter values. instead, these numerical values should be made into constant variables and these used instead. #-----------------------------------------------------------------------------3.9 - parentheses it is generally a good idea to use parentheses liberally in expressions involving mixed operators to avoid operator precedence problems. even if the operator precedence seems clear to you, it might not be to others -� you shouldn�t assume that other programmers know precedence as well as you do. #-----------------------------------------------------------------------------4.0 - engine updates the following is a list of classes and methods that have been updated by the sdk to help improve compatibility: game_map - setup game_map - update game_character - update game_event - refresh game_player - update
sprite_battler - update spriteset_map - initialize spriteset_map - update scene_tile - main scene_map - main scene_map - update scene_save - write_save_data scene_load - read_save_data scene_menu - initialize scene_menu - main scene_menu - update & command input scene_battle - main scene_battle - update scene_battle - update_phase3_basic_command scene_battle - make_basic_action_result #-----------------------------------------------------------------------------5.0 - sdk tools the following tools are included in the sdk to help improve the development process: 5.1 - logging scripts 5.2 - enabling/disabling scripts 5.3 - script dependencies 5.4 - standard text box input 5.5 - standard event comment input #-----------------------------------------------------------------------------5.1 � logging scripts all sdk-compliant scripts should be logged. this is done by calling the sdk.log(script, name, ver, date) method, where script = script name name = your name ver = version date = date last updated #-----------------------------------------------------------------------------5.2 � enabling/disabling scripts when a script is logged it is also enabled. a script can be enabled and disabled using the following calls: sdk.enable('script name') sdk.disable('script name') all non-default scripts (and code added to default scripts) must be enclosed in an if statement that checks whether or not they have been enabled, as follows: #-------------------------------------------------------------------------# begin sdk enabled check #-------------------------------------------------------------------------if sdk.state('script name') == true [script or code] end #-------------------------------------------------------------------------# end sdk enabled test #--------------------------------------------------------------------------
keep in mind that this if statement can not continue on to other pages and every page needs its own if statement testing the state of the script. as well every script should have its own test. #-----------------------------------------------------------------------------5.3 � script dependencies any script that requires (i.e. has a dependency on) another script can check if that dependency is met provided that the required script is set up before the script in question. this would be done in the following way: p 'script name not found' if sdk.state('script name') != true #-----------------------------------------------------------------------------5.4 � standard text box input any script that requires input from a database text field should use the following: sdk.text_box_input(element, index) where: element = an object of the text field index = the index in which your script call falls the text field should be formatted in the following way: "default value | script call | script call" #-----------------------------------------------------------------------------5.5 � standard event comment input any script that requires input from an event comment should use the following: sdk.event_comment_input(event, elements, trigger) where: event = an object of the event elements = the number of elements the method is to process trigger = the text value triggering the script to start processing or sdk.event_comment_input(page, elements, trigger) where: page = an object of the event.page elements = the number of elements the method is to process trigger = the text value triggering the script to start processing the method returns nil if the trigger can not be found; otherwise, it returns a list of the parameters from the event. #============================================================================== =end module sdk @list = {} @enabled = {} #--------------------------------------------------------------------------
# * logs a custom script #-------------------------------------------------------------------------def self.log(script, name, ver, date) @list[script] = [name,ver,date] @enabled[script] = true end #-------------------------------------------------------------------------# * returns a list of custom scripts #-------------------------------------------------------------------------def self.print(script = '') if script == '' return @list else return @list[script] end end #-------------------------------------------------------------------------# * writes a list of the custom scripts to a file #-------------------------------------------------------------------------def self.write file = file.open('scripts list.txt', 'wb') for key in @list.keys file.write("#{@list[key][0]} : #{key} version #{@list[key][1]}\n") end file.close end #-------------------------------------------------------------------------# * returns the state of the passed script #-------------------------------------------------------------------------def self.state(script) return @enabled[script] end #-------------------------------------------------------------------------# * enables the passed script #-------------------------------------------------------------------------def self.enable(script) @enabled[script] = true end #-------------------------------------------------------------------------# * disables the passed script #-------------------------------------------------------------------------def self.disable(script) @enabled[script] = false end #-------------------------------------------------------------------------# * evals text from an input source #-------------------------------------------------------------------------def self.text_box_input(element, index) return if index == 0 commands = element.split('|') eval(commands[index]) end #-------------------------------------------------------------------------# * returns a list of parameters from an event's comments #-------------------------------------------------------------------------def self.event_comment_input(*args) parameters = [] list = *args[0].list
elements = *args[1] trigger = *args[2] return nil if list == nil return nil unless list.is_a?(array) for item in list next if item.code != 108 if item.parameters[0] == trigger start = list.index(item) + 1 finish = start + elements for id in start...finish next if !list[id] parameters.push(list[id].parameters[0]) end return parameters end end return nil end end #============================================================================== # ** object #-----------------------------------------------------------------------------# automatic_dispose looks after disposing all windows and sprites in a scene # when called. #============================================================================== class object #-------------------------------------------------------------------------# * automatic dispose #-------------------------------------------------------------------------def automatic_dispose self.instance_variables.each do |item| eval("#{item}.dispose if (#{item}.is_a?(sprite) or #{item}.is_a?(window_base)) and (!#{item}.disposed?)") end end end #============================================================================== # ** game_map #-----------------------------------------------------------------------------# this class handles the map. it includes scrolling and passable determining # functions. refer to "$game_map" for the instance of this class. #============================================================================== class game_map #-------------------------------------------------------------------------# * setup # map_id : map id #-------------------------------------------------------------------------def setup(map_id) setup_map_id(map_id) setup_load setup_tileset setup_display setup_refresh setup_events
setup_common_events setup_fog setup_scroll end #-------------------------------------------------------------------------# * setup map id #-------------------------------------------------------------------------def setup_map_id(map_id) # put map id in @map_id memory @map_id = map_id end #-------------------------------------------------------------------------# * load map data #-------------------------------------------------------------------------def setup_load # load map from file and set @map @map = load_data(sprintf("data/map%03d.rxdata", @map_id)) end #-------------------------------------------------------------------------# * setup tileset #-------------------------------------------------------------------------def setup_tileset # set tile set information in opening instance variables tileset = $data_tilesets[@map.tileset_id] @tileset_name = tileset.tileset_name @autotile_names = tileset.autotile_names @panorama_name = tileset.panorama_name @panorama_hue = tileset.panorama_hue @fog_name = tileset.fog_name @fog_hue = tileset.fog_hue @fog_opacity = tileset.fog_opacity @fog_blend_type = tileset.fog_blend_type @fog_zoom = tileset.fog_zoom @fog_sx = tileset.fog_sx @fog_sy = tileset.fog_sy @battleback_name = tileset.battleback_name @passages = tileset.passages @priorities = tileset.priorities @terrain_tags = tileset.terrain_tags end #-------------------------------------------------------------------------# * setup display #-------------------------------------------------------------------------def setup_display # initialize displayed coordinates @display_x = 0 @display_y = 0 end #-------------------------------------------------------------------------# * setup refresh #-------------------------------------------------------------------------def setup_refresh # clear refresh request flag @need_refresh = false end #-------------------------------------------------------------------------# * setup events #--------------------------------------------------------------------------
def setup_events # set map event data @events = {} for i in @map.events.keys @events[i] = game_event.new(@map_id, @map.events[i]) end end #-------------------------------------------------------------------------# * setup common events #-------------------------------------------------------------------------def setup_common_events # set common event data @common_events = {} for i in 1...$data_common_events.size @common_events[i] = game_commonevent.new(i) end end #-------------------------------------------------------------------------# * setup fog #-------------------------------------------------------------------------def setup_fog # initialize all fog information @fog_ox = 0 @fog_oy = 0 @fog_tone = tone.new(0, 0, 0, 0) @fog_tone_target = tone.new(0, 0, 0, 0) @fog_tone_duration = 0 @fog_opacity_duration = 0 @fog_opacity_target = 0 end #-------------------------------------------------------------------------# * setup scroll #-------------------------------------------------------------------------def setup_scroll # initialize scroll information @scroll_direction = 2 @scroll_rest = 0 @scroll_speed = 4 end #-------------------------------------------------------------------------# * frame update #-------------------------------------------------------------------------def update update_refresh update_scrolling update_events update_common_events update_fog_scroll update_fog_colour update_fog end #-------------------------------------------------------------------------# * refresh game map #-------------------------------------------------------------------------def update_refresh # refresh map if necessary if $game_map.need_refresh refresh
end end #-------------------------------------------------------------------------# * update scrolling #-------------------------------------------------------------------------def update_scrolling # if scrolling if @scroll_rest > 0 # change from scroll speed to distance in map coordinates distance = 2 ** @scroll_speed # execute scrolling case @scroll_direction when 2 # down scroll_down(distance) when 4 # left scroll_left(distance) when 6 # right scroll_right(distance) when 8 # up scroll_up(distance) end # subtract distance scrolled @scroll_rest -= distance end end #-------------------------------------------------------------------------# * update events #-------------------------------------------------------------------------def update_events # update map event for event in @events.values event.update end end #-------------------------------------------------------------------------# * update common events #-------------------------------------------------------------------------def update_common_events # update common event for common_event in @common_events.values common_event.update end end #-------------------------------------------------------------------------# * update fog scroll #-------------------------------------------------------------------------def update_fog_scroll # manage fog scrolling @fog_ox -= @fog_sx / 8.0 @fog_oy -= @fog_sy / 8.0 end #-------------------------------------------------------------------------# * update fog color #-------------------------------------------------------------------------def update_fog_colour # manage change in fog color tone if @fog_tone_duration >= 1 d = @fog_tone_duration
target = @fog_tone_target @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d @fog_tone_duration -= 1 end end #-------------------------------------------------------------------------# * update fog #-------------------------------------------------------------------------def update_fog # manage change in fog opacity level if @fog_opacity_duration >= 1 d = @fog_opacity_duration @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d @fog_opacity_duration -= 1 end end end #============================================================================== # ** game_character #-----------------------------------------------------------------------------# this class deals with characters. it's used as a superclass for the # game_player and game_event classes. #============================================================================== class game_character #-------------------------------------------------------------------------# * frame update #-------------------------------------------------------------------------def update unless update_wait == true update_movement_type update_animation return if update_force? == true return if update_event_execution? == true update_movement end end #-------------------------------------------------------------------------# * update movement type #-------------------------------------------------------------------------def update_movement_type # branch with jumping, moving, and stopping if jumping? update_jump elsif moving? update_move else update_stop end end #-------------------------------------------------------------------------# * update animation #-------------------------------------------------------------------------def update_animation
# if animation count exceeds maximum value # * maximum value is move speed * 1 taken from basic value 18 if @anime_count > 18 - @move_speed * 2 # if stop animation is off when stopping if not @step_anime and @stop_count > 0 # return to original pattern @pattern = @original_pattern # if stop animation is on when moving else # update pattern @pattern = (@pattern + 1) % 4 end # clear animation count @anime_count = 0 end end #-------------------------------------------------------------------------# * update wait #-------------------------------------------------------------------------def update_wait # reduce wait count @wait_count -= 1 if @wait_count > 0 return (@wait_count > 0) end #-------------------------------------------------------------------------# * update force #-------------------------------------------------------------------------def update_force? # if move route is forced if @move_route_forcing # custom move move_type_custom return true end return false end #-------------------------------------------------------------------------# * update event execution #-------------------------------------------------------------------------def update_event_execution? # when waiting for event execution or locked if @starting or lock? # not moving by self return true end return false end #-------------------------------------------------------------------------# * update movement #-------------------------------------------------------------------------def update_movement # if stop count exceeds a certain value (computed from move frequency) if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency) # branch by move type case @move_type when 1 # random move_type_random when 2 # approach
move_type_toward_player when 3 # custom move_type_custom end end end end #============================================================================== # ** game_event #-----------------------------------------------------------------------------# this class deals with events. it handles functions including event page # switching via condition determinants, and running parallel process events. # it's used within the game_map class. #============================================================================== class game_event < game_character #-------------------------------------------------------------------------# * refresh #-------------------------------------------------------------------------def refresh # initialize local variable: new_page new_page = nil # if not temporarily erased unless @erased new_page = refresh_trigger_conditions end # if event page is the same as last time if new_page == @page # end method return end # set @page as current event page @page = new_page # clear starting flag clear_starting # if no page fulfills conditions if @page == nil # reset values refresh_reset # end method return end # set page variables refresh_set_page # check parallel processing refresh_check_process # auto event start determinant check_event_trigger_auto end #-------------------------------------------------------------------------# * refresh trigger conditions #-------------------------------------------------------------------------def refresh_trigger_conditions # check in order of large event pages for page in @event.pages.reverse # make possible referrence for event condition with c c = page.condition
# switch 1 condition confirmation if c.switch1_valid if $game_switches[c.switch1_id] == false next end end # switch 2 condition confirmation if c.switch2_valid if $game_switches[c.switch2_id] == false next end end # variable condition confirmation if c.variable_valid if $game_variables[c.variable_id] < c.variable_value next end end # self switch condition confirmation if c.self_switch_valid key = [@map_id, @event.id, c.self_switch_ch] if $game_self_switches[key] != true next end end # set local variable: new_page new_page = page # remove loop break end # return new page return new_page end #-------------------------------------------------------------------------# * refresh reset #-------------------------------------------------------------------------def refresh_reset # set each instance variable @tile_id = 0 @character_name = "" @character_hue = 0 @move_type = 0 @through = true @trigger = nil @list = nil @interpreter = nil end #-------------------------------------------------------------------------# * refresh set page #-------------------------------------------------------------------------def refresh_set_page # set each instance variable @tile_id = @page.graphic.tile_id @character_name = @page.graphic.character_name @character_hue = @page.graphic.character_hue 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 @opacity = @page.graphic.opacity @blend_type = @page.graphic.blend_type @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 @always_on_top = @page.always_on_top @trigger = @page.trigger @list = @page.list @interpreter = nil end #-------------------------------------------------------------------------# * refresh check process #-------------------------------------------------------------------------def refresh_check_process # if trigger is [parallel process] if @trigger == 4 # create parallel process interpreter @interpreter = interpreter.new end end end #============================================================================== # ** game_player #-----------------------------------------------------------------------------# this class handles the player. its functions include event starting # determinants and map scrolling. refer to "$game_player" for the one # instance of this class. #============================================================================== class game_player < game_character #-------------------------------------------------------------------------# * frame update #-------------------------------------------------------------------------def update # remember whether or not moving in local variables last_moving = moving? # if moving, event running, move route forcing, and message window # display are all not occurring unless moving? or $game_system.map_interpreter.running? or @move_route_forcing or $game_temp.message_window_showing update_player_movement end # remember coordinates in local variables last_real_x = @real_x
last_real_y = @real_y super # scroll map update_scroll_down(last_real_y) update_scroll_left(last_real_x) update_scroll_right(last_real_x) update_scroll_up(last_real_y) # if not moving unless moving? # if player was moving last time if last_moving update_encounter end update_action_trigger end end #-------------------------------------------------------------------------# * player movement update #-------------------------------------------------------------------------def update_player_movement # move player in the direction the directional button is being pressed case input.dir4 when 2 move_down when 4 move_left when 6 move_right when 8 move_up end end #-------------------------------------------------------------------------# * scroll down #-------------------------------------------------------------------------def update_scroll_down(last_real_y) # if character moves down and is positioned lower than the center # of the screen if @real_y > last_real_y and @real_y - $game_map.display_y > center_y # scroll map down $game_map.scroll_down(@real_y - last_real_y) end end #-------------------------------------------------------------------------# * scroll left #-------------------------------------------------------------------------def update_scroll_left(last_real_x) # if character moves left and is positioned more let on-screen than # center if @real_x < last_real_x and @real_x - $game_map.display_x < center_x # scroll map left $game_map.scroll_left(last_real_x - @real_x) end end #-------------------------------------------------------------------------# * scroll right #-------------------------------------------------------------------------def update_scroll_right(last_real_x)
# if character moves right and is positioned more right on-screen than # center if @real_x > last_real_x and @real_x - $game_map.display_x > center_x # scroll map right $game_map.scroll_right(@real_x - last_real_x) end end #-------------------------------------------------------------------------# * scroll up #-------------------------------------------------------------------------def update_scroll_up(last_real_y) # if character moves up and is positioned higher than the center # of the screen if @real_y < last_real_y and @real_y - $game_map.display_y < center_y # scroll map up $game_map.scroll_up(last_real_y - @real_y) end end #-------------------------------------------------------------------------# * update action trigger #-------------------------------------------------------------------------def update_action_trigger # if c button was pressed if input.trigger?(input::c) # same position and front event determinant check_event_trigger_here([0]) check_event_trigger_there([0,1,2]) end end #-------------------------------------------------------------------------# * scroll encounter #-------------------------------------------------------------------------def update_encounter # event determinant is via touch of same position event result = check_event_trigger_here([1,2]) # if event which started does not exist if result == false # disregard if debug mode is on and ctrl key was pressed unless $debug and input.press?(input::ctrl) # encounter countdown if @encounter_count > 0 @encounter_count -= 1 end end end end end #============================================================================== # ** sprite_battler #-----------------------------------------------------------------------------# this sprite is used to display the battler.it observes the game_character # class and automatically changes sprite conditions. #============================================================================== class sprite_battler #-------------------------------------------------------------------------# * update
#-------------------------------------------------------------------------def update super # if battler is nil if @battler == nil remove_battler return end # if file name or hue are different than current ones redraw_battler # if animation id is different than current one loop_anim # if actor which should be displayed adjust_actor_opacity # blink adjust_blink # if invisible adjust_visibility # if visible if @battler_visible # escape sprite_escape # white flash sprite_white_flash # animation sprite_animation # damage sprite_damage # collapse sprite_collapse end # set sprite coordinates self.x = @battler.screen_x self.y = @battler.screen_y self.z = @battler.screen_z end #-------------------------------------------------------------------------# * remove battler #-------------------------------------------------------------------------def remove_battler self.bitmap = nil loop_animation(nil) end #-------------------------------------------------------------------------# * redraw battler #-------------------------------------------------------------------------def redraw_battler if @battler.battler_name != @battler_name or @battler.battler_hue != @battler_hue # get and set bitmap @battler_name = @battler.battler_name @battler_hue = @battler.battler_hue self.bitmap = rpg::cache.battler(@battler_name, @battler_hue) @width = bitmap.width @height = bitmap.height self.ox = @width / 2 self.oy = @height # change opacity level to 0 when dead or hidden
if @battler.dead? or @battler.hidden self.opacity = 0 end end end #-------------------------------------------------------------------------# * loop sprite animation #-------------------------------------------------------------------------def loop_anim if @battler.damage == nil and @battler.state_animation_id != @state_animation_id @state_animation_id = @battler.state_animation_id loop_animation($data_animations[@state_animation_id]) end end #-------------------------------------------------------------------------# * adjust actor opacity #-------------------------------------------------------------------------def adjust_actor_opacity if @battler.is_a?(game_actor) and @battler_visible # bring opacity level down a bit when not in main phase if $game_temp.battle_main_phase self.opacity += 3 if self.opacity < 255 else self.opacity -= 3 if self.opacity > 207 end end end #-------------------------------------------------------------------------# * adjust blink #-------------------------------------------------------------------------def adjust_blink if @battler.blink blink_on else blink_off end end #-------------------------------------------------------------------------# * adjust visibility #-------------------------------------------------------------------------def adjust_visibility unless @battler_visible # appear if not @battler.hidden and not @battler.dead? and (@battler.damage == nil or @battler.damage_pop) appear @battler_visible = true end end end #-------------------------------------------------------------------------# * sprite: escape #-------------------------------------------------------------------------def sprite_escape if @battler.hidden $game_system.se_play($data_system.escape_se) escape
@battler_visible = false end end #-------------------------------------------------------------------------# * sprite: white flash #-------------------------------------------------------------------------def sprite_white_flash if @battler.white_flash whiten @battler.white_flash = false end end #-------------------------------------------------------------------------# * sprite: animation #-------------------------------------------------------------------------def sprite_animation if @battler.animation_id != 0 animation = $data_animations[@battler.animation_id] animation(animation, @battler.animation_hit) @battler.animation_id = 0 end end #-------------------------------------------------------------------------# * sprite: damage #-------------------------------------------------------------------------def sprite_damage if @battler.damage_pop damage(@battler.damage, @battler.critical) @battler.damage = nil @battler.critical = false @battler.damage_pop = false end end #-------------------------------------------------------------------------# * sprite: collapse #-------------------------------------------------------------------------def sprite_collapse if @battler.damage == nil and @battler.dead? if @battler.is_a?(game_enemy) $game_system.se_play($data_system.enemy_collapse_se) else $game_system.se_play($data_system.actor_collapse_se) end collapse @battler_visible = false end end end #============================================================================== # ** spriteset_map #-----------------------------------------------------------------------------# this class brings together map screen sprites, tilemaps, etc. # it's used within the scene_map class. #============================================================================== class spriteset_map #--------------------------------------------------------------------------
# * object initialization #-------------------------------------------------------------------------def initialize init_viewports init_tilemap init_panorama init_fog init_characters init_player init_weather init_pictures init_timer # frame update update end #-------------------------------------------------------------------------# * viewport initialization #-------------------------------------------------------------------------def init_viewports # make viewports @viewport1 = viewport.new(0, 0, 640, 480) @viewport2 = viewport.new(0, 0, 640, 480) @viewport3 = viewport.new(0, 0, 640, 480) @viewport2.z = 200 @viewport3.z = 5000 end #-------------------------------------------------------------------------# * tilemap initialization #-------------------------------------------------------------------------def init_tilemap # make tilemap @tilemap = tilemap.new(@viewport1) @tilemap.tileset = rpg::cache.tileset($game_map.tileset_name) for i in 0..6 autotile_name = $game_map.autotile_names[i] @tilemap.autotiles[i] = rpg::cache.autotile(autotile_name) end @tilemap.map_data = $game_map.data @tilemap.priorities = $game_map.priorities end #-------------------------------------------------------------------------# * panorama initialization #-------------------------------------------------------------------------def init_panorama # make panorama plane @panorama = plane.new(@viewport1) @panorama.z = -1000 end #-------------------------------------------------------------------------# * fog initialization #-------------------------------------------------------------------------def init_fog # make fog plane @fog = plane.new(@viewport1) @fog.z = 3000 end #-------------------------------------------------------------------------# * character sprite initialization
#-------------------------------------------------------------------------def init_characters # make character sprites @character_sprites = [] for i in $game_map.events.keys.sort sprite = sprite_character.new(@viewport1, $game_map.events[i]) @character_sprites.push(sprite) end end #-------------------------------------------------------------------------# * player initialization #-------------------------------------------------------------------------def init_player @character_sprites.push(sprite_character.new(@viewport1, $game_player)) end #-------------------------------------------------------------------------# * weather initialization #-------------------------------------------------------------------------def init_weather # make weather @weather = rpg::weather.new(@viewport1) end #-------------------------------------------------------------------------# * picture initialization #-------------------------------------------------------------------------def init_pictures # make picture sprites @picture_sprites = [] for i in 1..50 @picture_sprites.push(sprite_picture.new(@viewport2, $game_screen.pictures[i])) end end #-------------------------------------------------------------------------# * timer initialization #-------------------------------------------------------------------------def init_timer # make timer sprite @timer_sprite = sprite_timer.new end #-------------------------------------------------------------------------# * frame update #-------------------------------------------------------------------------def update update_panorama update_fog update_tilemap update_panorama_plane update_fog_plane update_character_sprites update_weather update_picture_sprites # update timer sprite @timer_sprite.update # set screen color tone and shake position @viewport1.tone = $game_screen.tone @viewport1.ox = $game_screen.shake # set screen flash color
@viewport3.color = $game_screen.flash_color # update viewports @viewport1.update @viewport3.update end #-------------------------------------------------------------------------# * update panorama #-------------------------------------------------------------------------def update_panorama # if panorama is different from current one if @panorama_name != $game_map.panorama_name or @panorama_hue != $game_map.panorama_hue @panorama_name = $game_map.panorama_name @panorama_hue = $game_map.panorama_hue if @panorama.bitmap != nil @panorama.bitmap.dispose @panorama.bitmap = nil end if @panorama_name != "" @panorama.bitmap = rpg::cache.panorama(@panorama_name, @panorama_hue) end graphics.frame_reset end end #-------------------------------------------------------------------------# * update fog #-------------------------------------------------------------------------def update_fog # if fog is different than current fog if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue @fog_name = $game_map.fog_name @fog_hue = $game_map.fog_hue if @fog.bitmap != nil @fog.bitmap.dispose @fog.bitmap = nil end if @fog_name != "" @fog.bitmap = rpg::cache.fog(@fog_name, @fog_hue) end graphics.frame_reset end end #-------------------------------------------------------------------------# * update tilemap #-------------------------------------------------------------------------def update_tilemap # update tilemap @tilemap.ox = $game_map.display_x / 4 @tilemap.oy = $game_map.display_y / 4 @tilemap.update end #-------------------------------------------------------------------------# * update panorama plane #-------------------------------------------------------------------------def update_panorama_plane # update panorama plane @panorama.ox = $game_map.display_x / 8 @panorama.oy = $game_map.display_y / 8
end #-------------------------------------------------------------------------# * update fog plane #-------------------------------------------------------------------------def update_fog_plane # update fog plane @fog.zoom_x = $game_map.fog_zoom / 100.0 @fog.zoom_y = $game_map.fog_zoom / 100.0 @fog.opacity = $game_map.fog_opacity @fog.blend_type = $game_map.fog_blend_type @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy @fog.tone = $game_map.fog_tone end #-------------------------------------------------------------------------# * update character sprites #-------------------------------------------------------------------------def update_character_sprites # update character sprites for sprite in @character_sprites sprite.update end end #-------------------------------------------------------------------------# * update weather #-------------------------------------------------------------------------def update_weather # update weather graphic @weather.type = $game_screen.weather_type @weather.max = $game_screen.weather_max @weather.ox = $game_map.display_x / 4 @weather.oy = $game_map.display_y / 4 @weather.update end #-------------------------------------------------------------------------# * update picture sprites #-------------------------------------------------------------------------def update_picture_sprites # update picture sprites for sprite in @picture_sprites sprite.update end end end #============================================================================== # ** scene_title #-----------------------------------------------------------------------------# this class performs title screen processing. #============================================================================== class scene_title #-------------------------------------------------------------------------# * main processing #-------------------------------------------------------------------------def main return if main_battle_test? main_database
main_background main_menu main_test_continue main_audio # execute transition graphics.transition # main loop loop do main_loop break if main_scenechange? end # prepare for transition graphics.freeze main_dispose end #-------------------------------------------------------------------------# * battle test check #-------------------------------------------------------------------------def main_battle_test? # if battle test if $btest battle_test return true end return false end #-------------------------------------------------------------------------# * load database #-------------------------------------------------------------------------def main_database # load database $data_actors = load_data("data/actors.rxdata") $data_classes = load_data("data/classes.rxdata") $data_skills = load_data("data/skills.rxdata") $data_items = load_data("data/items.rxdata") $data_weapons = load_data("data/weapons.rxdata") $data_armors = load_data("data/armors.rxdata") $data_enemies = load_data("data/enemies.rxdata") $data_troops = load_data("data/troops.rxdata") $data_states = load_data("data/states.rxdata") $data_animations = load_data("data/animations.rxdata") $data_tilesets = load_data("data/tilesets.rxdata") $data_common_events = load_data("data/commonevents.rxdata") $data_system = load_data("data/system.rxdata") # make system object $game_system = game_system.new end #-------------------------------------------------------------------------# * background initialization #-------------------------------------------------------------------------def main_background # make title graphic @sprite = sprite.new @sprite.bitmap = rpg::cache.title($data_system.title_name) end #-------------------------------------------------------------------------# * main menu initialization #--------------------------------------------------------------------------
def main_menu # make command window s1 = "new game" s2 = "continue" s3 = "shutdown" @command_window = window_command.new(192, [s1, s2, s3]) @command_window.back_opacity = 160 @command_window.x = 320 - @command_window.width / 2 @command_window.y = 288 end #-------------------------------------------------------------------------# * main test initialization #-------------------------------------------------------------------------def main_test_continue # continue enabled determinant # check if at least one save file exists # if enabled, make @continue_enabled true; if disabled, make it false @continue_enabled = false for i in 0..3 if filetest.exist?("save#{i+1}.rxdata") @continue_enabled = true end end # if continue is enabled, move cursor to "continue" # if disabled, display "continue" text in gray if @continue_enabled @command_window.index = 1 else @command_window.disable_item(1) end end #-------------------------------------------------------------------------# * main audio initialization #-------------------------------------------------------------------------def main_audio # play title bgm $game_system.bgm_play($data_system.title_bgm) # stop playing me and bgs audio.me_stop audio.bgs_stop end #-------------------------------------------------------------------------# * main loop #-------------------------------------------------------------------------def main_loop # update game screen graphics.update # update input information input.update # frame update update end #-------------------------------------------------------------------------# * main scene scene change #-------------------------------------------------------------------------def main_scenechange? # abort loop if screen is changed if $scene != self
return true end return false end #-------------------------------------------------------------------------# * main dispose #-------------------------------------------------------------------------def main_dispose automatic_dispose end end #============================================================================== # ** scene_map #-----------------------------------------------------------------------------# this class performs map screen processing. #============================================================================== class scene_map #-------------------------------------------------------------------------# * main processing #-------------------------------------------------------------------------def main main_draw # main loop loop do main_loop break if main_scenechange? end main_dispose main_tiletrigger end #-------------------------------------------------------------------------# * main draw #-------------------------------------------------------------------------def main_draw # make sprite set @spriteset = spriteset_map.new # make message window @message_window = window_message.new # transition run graphics.transition end #-------------------------------------------------------------------------# * main loop #-------------------------------------------------------------------------def main_loop # update game screen graphics.update # update input information input.update # frame update update end #-------------------------------------------------------------------------# * main scene change #-------------------------------------------------------------------------def main_scenechange?
# abort loop if screen is changed if $scene != self return true end return false end #-------------------------------------------------------------------------# * main dispose #-------------------------------------------------------------------------def main_dispose graphics.freeze @spriteset.dispose automatic_dispose end #-------------------------------------------------------------------------# * main tiletrigger #-------------------------------------------------------------------------def main_tiletrigger # if switching to title screen if $scene.is_a?(scene_title) # fade out screen graphics.transition graphics.freeze end end #-------------------------------------------------------------------------# * frame update #-------------------------------------------------------------------------def update # loop loop do update_systems # abort loop if player isn't place moving unless $game_temp.player_transferring break end # run place move transfer_player # abort loop if transition processing if $game_temp.transition_processing break end end update_graphics return if update_game_over? == true return if update_to_title? == true # if transition processing if $game_temp.transition_processing # clear transition processing flag $game_temp.transition_processing = false # execute transition if $game_temp.transition_name == "" graphics.transition(20) else graphics.transition(40, "graphics/transitions/" + $game_temp.transition_name) end end
# if showing message window if $game_temp.message_window_showing return end # if encounter list isn't empty, and encounter count is 0 if $game_player.encounter_count == 0 and $game_map.encounter_list != [] # if event is running or encounter is not forbidden unless $game_system.map_interpreter.running? or $game_system.encounter_disabled # confirm troop n = rand($game_map.encounter_list.size) troop_id = $game_map.encounter_list[n] # if troop is valid if $data_troops[troop_id] != nil # set battle calling flag $game_temp.battle_calling = true $game_temp.battle_troop_id = troop_id $game_temp.battle_can_escape = true $game_temp.battle_can_lose = false $game_temp.battle_proc = nil end end end update_call_menu update_call_debug # if player is not moving unless $game_player.moving? update_scene end end #-------------------------------------------------------------------------# * update systems #-------------------------------------------------------------------------def update_systems # update map, interpreter, and player order # (this update order is important for when conditions are fulfilled # to run any event, and the player isn't provided the opportunity to # move in an instant) $game_map.update $game_system.map_interpreter.update $game_player.update # update system (timer), screen $game_system.update $game_screen.update end #-------------------------------------------------------------------------# * update graphics #-------------------------------------------------------------------------def update_graphics # update sprite set @spriteset.update # update message window @message_window.update end #-------------------------------------------------------------------------# * update game over #-------------------------------------------------------------------------def update_game_over?
# if game over if $game_temp.gameover # switch to game over screen $scene = scene_gameover.new return true end return false end #-------------------------------------------------------------------------# * update to title #-------------------------------------------------------------------------def update_to_title? # if returning to title screen if $game_temp.to_title # change to title screen $scene = scene_title.new return true end return false end #-------------------------------------------------------------------------# * update menu call #-------------------------------------------------------------------------def update_call_menu # if b button was pressed if input.trigger?(input::b) # if event is running, or menu is not forbidden unless $game_system.map_interpreter.running? or $game_system.menu_disabled # set menu calling flag or beep flag $game_temp.menu_calling = true $game_temp.menu_beep = true end end end #-------------------------------------------------------------------------# * update debug call #-------------------------------------------------------------------------def update_call_debug # if debug mode is on and f9 key was pressed if $debug and input.press?(input::f9) # set debug calling flag $game_temp.debug_calling = true end end #-------------------------------------------------------------------------# * update scene #-------------------------------------------------------------------------def update_scene # run calling of each screen if $game_temp.battle_calling call_battle elsif $game_temp.shop_calling call_shop elsif $game_temp.name_calling call_name elsif $game_temp.menu_calling call_menu
elsif $game_temp.save_calling call_save elsif $game_temp.debug_calling call_debug end end end #============================================================================== # ** scene_menu #-----------------------------------------------------------------------------# this class performs menu screen processing. #============================================================================== class scene_menu #-------------------------------------------------------------------------# * object initialization # menu_index : command cursor's initial position #-------------------------------------------------------------------------def initialize(menu_index = 0) @menu_index = menu_index commands_init end #-------------------------------------------------------------------------# * set commands #-------------------------------------------------------------------------def commands_init @commands = [] s1 = $data_system.words.item s2 = $data_system.words.skill s3 = $data_system.words.equip s4 = "status" s5 = "save" s6 = "end game" @commands.push(s1, s2, s3, s4, s5, s6).flatten! end #-------------------------------------------------------------------------# * main processing #-------------------------------------------------------------------------def main main_command_window main_windows # execute transition graphics.transition # main loop loop do main_loop break if main_scenechange? end # refresh map $game_map.refresh # prepare for transition graphics.freeze main_dispose end #-------------------------------------------------------------------------# * main command window #--------------------------------------------------------------------------
def main_command_window @command_window = window_command.new(160, @commands) @command_window.index = @menu_index @command_window.height = 224 # if number of party members is 0 if $game_party.actors.size == 0 # disable items, skills, equipment, and status @command_window.disable_item(0) @command_window.disable_item(1) @command_window.disable_item(2) @command_window.disable_item(3) end # if save is forbidden if $game_system.save_disabled # disable save @command_window.disable_item(4) end end #-------------------------------------------------------------------------# * main command window #-------------------------------------------------------------------------def main_windows # make play time window @playtime_window = window_playtime.new @playtime_window.x = 0 @playtime_window.y = 224 # make steps window @steps_window = window_steps.new @steps_window.x = 0 @steps_window.y = 320 # make gold window @gold_window = window_gold.new @gold_window.x = 0 @gold_window.y = 416 # make status window @status_window = window_menustatus.new @status_window.x = 160 @status_window.y = 0 end #-------------------------------------------------------------------------# * main loop #-------------------------------------------------------------------------def main_loop # update game screen graphics.update # update input information input.update # frame update update end #-------------------------------------------------------------------------# * scene change #-------------------------------------------------------------------------def main_scenechange? # abort loop if screen is changed if $scene != self return true end
return false end #-------------------------------------------------------------------------# * main dispose #-------------------------------------------------------------------------def main_dispose # dispose of windows @command_window.dispose @playtime_window.dispose @steps_window.dispose @gold_window.dispose @status_window.dispose end #-------------------------------------------------------------------------# * frame update #-------------------------------------------------------------------------def update # update windows @command_window.update @playtime_window.update @steps_window.update @gold_window.update @status_window.update # if command window is active: call update_command if @command_window.active update_command return end # if status window is active: call update_status if @status_window.active update_status return end end #-------------------------------------------------------------------------# * frame update (when command window is active) #-------------------------------------------------------------------------def update_command # if b button was pressed if input.trigger?(input::b) # play cancel se $game_system.se_play($data_system.cancel_se) # switch to map screen $scene = scene_map.new return end # if c button was pressed if input.trigger?(input::c) update_command_check return end end #-------------------------------------------------------------------------# * frame update (when status window is active) #-------------------------------------------------------------------------def update_status # if b button was pressed if input.trigger?(input::b)
# play cancel se $game_system.se_play($data_system.cancel_se) # make command window active @command_window.active = true @status_window.active = false @status_window.index = -1 return end # if c button was pressed if input.trigger?(input::c) buzzer_check update_status_check unless buzzer_check return end end #-------------------------------------------------------------------------# * buzzer check #-------------------------------------------------------------------------def buzzer_check # if command other than save or end game, and party members = 0 if $game_party.actors.size == 0 and @command_window.index < 4 # play buzzer se $game_system.se_play($data_system.buzzer_se) return true end end #-------------------------------------------------------------------------# * update command check #-------------------------------------------------------------------------def update_command_check # loads current command command = @commands[@command_window.index] # checks commands if command == $data_system.words.item command_item elsif command == $data_system.words.skill command_start_skill elsif command == $data_system.words.equip command_start_equip elsif command == 'status' command_start_status elsif command == 'save' command_save elsif command == 'end game' command_endgame end end #-------------------------------------------------------------------------# * update status check #-------------------------------------------------------------------------def update_status_check # loads current command command = @commands[@command_window.index] # checks command by name if command == $data_system.words.skill command_skill elsif command == $data_system.words.equip command_equip
elsif command == 'status' command_status end end #-------------------------------------------------------------------------# * command item #-------------------------------------------------------------------------def command_item # play decision se $game_system.se_play($data_system.decision_se) # switch to item screen $scene = scene_item.new end #-------------------------------------------------------------------------# * command start skill #-------------------------------------------------------------------------def command_start_skill activate_status end #-------------------------------------------------------------------------# * command skill #-------------------------------------------------------------------------def command_skill # if this actor's action limit is 2 or more if $game_party.actors[@status_window.index].restriction >= 2 # play buzzer se $game_system.se_play($data_system.buzzer_se) return end # play decision se $game_system.se_play($data_system.decision_se) # switch to skill screen $scene = scene_skill.new(@status_window.index) end #-------------------------------------------------------------------------# * command start equip #-------------------------------------------------------------------------def command_start_equip activate_status end #-------------------------------------------------------------------------# * command equip #-------------------------------------------------------------------------def command_equip # play decision se $game_system.se_play($data_system.decision_se) # switch to equipment screen $scene = scene_equip.new(@status_window.index) end #-------------------------------------------------------------------------# * command start status #-------------------------------------------------------------------------def command_start_status activate_status end #-------------------------------------------------------------------------# * command status #--------------------------------------------------------------------------
def command_status # play decision se $game_system.se_play($data_system.decision_se) # switch to status screen $scene = scene_status.new(@status_window.index) end #-------------------------------------------------------------------------# * command save #-------------------------------------------------------------------------def command_save # if saving is forbidden if $game_system.save_disabled # play buzzer se $game_system.se_play($data_system.buzzer_se) return end # play decision se $game_system.se_play($data_system.decision_se) # switch to save screen $scene = scene_save.new end #-------------------------------------------------------------------------# * command end game #-------------------------------------------------------------------------def command_endgame # play decision se $game_system.se_play($data_system.decision_se) # switch to end game screen $scene = scene_end.new end #-------------------------------------------------------------------------# * activate status window #-------------------------------------------------------------------------def activate_status # play decision se $game_system.se_play($data_system.decision_se) # make status window active @command_window.active = false @status_window.active = true @status_window.index = 0 end end #============================================================================== # ** scene_save #-----------------------------------------------------------------------------# this class performs save screen processing. #============================================================================== class scene_save < scene_file #-------------------------------------------------------------------------# * write save data # file : write file object (opened) #-------------------------------------------------------------------------def write_save_data(file) write_characters(file) write_frame(file) write_setup(file)
write_data(file) end #-------------------------------------------------------------------------# * make character data #-------------------------------------------------------------------------def write_characters(file) # make character data for drawing save file characters = [] for i in 0...$game_party.actors.size actor = $game_party.actors[i] characters.push([actor.character_name, actor.character_hue]) end # write character data for drawing save file marshal.dump(characters, file) end #-------------------------------------------------------------------------# * write frame count #-------------------------------------------------------------------------def write_frame(file) # wrire frame count for measuring play time marshal.dump(graphics.frame_count, file) end #-------------------------------------------------------------------------# * write setup #-------------------------------------------------------------------------def write_setup(file) # increase save count by 1 $game_system.save_count += 1 # save magic number # (a random value will be written each time saving with editor) $game_system.magic_number = $data_system.magic_number end #-------------------------------------------------------------------------# * write data #-------------------------------------------------------------------------def write_data(file) # write each type of game object marshal.dump($game_system, file) marshal.dump($game_switches, file) marshal.dump($game_variables, file) marshal.dump($game_self_switches, file) marshal.dump($game_screen, file) marshal.dump($game_actors, file) marshal.dump($game_party, file) marshal.dump($game_troop, file) marshal.dump($game_map, file) marshal.dump($game_player, file) end end #============================================================================== # ** scene_load #-----------------------------------------------------------------------------# this class performs load screen processing. #============================================================================== class scene_load < scene_file #--------------------------------------------------------------------------
# * read save data # file : file object for reading (opened) #-------------------------------------------------------------------------def read_save_data(file) read_characters(file) read_frame(file) read_data(file) read_edit read_refresh end #-------------------------------------------------------------------------# * read character data #-------------------------------------------------------------------------def read_characters(file) # read character data for drawing save file characters = marshal.load(file) end #-------------------------------------------------------------------------# * read frame count #-------------------------------------------------------------------------def read_frame(file) # read frame count for measuring play time graphics.frame_count = marshal.load(file) end #-------------------------------------------------------------------------# * read data #-------------------------------------------------------------------------def read_data(file) # read each type of game object $game_system = marshal.load(file) $game_switches = marshal.load(file) $game_variables = marshal.load(file) $game_self_switches = marshal.load(file) $game_screen = marshal.load(file) $game_actors = marshal.load(file) $game_party = marshal.load(file) $game_troop = marshal.load(file) $game_map = marshal.load(file) $game_player = marshal.load(file) end #-------------------------------------------------------------------------# * read edit #-------------------------------------------------------------------------def read_edit # if magic number is different from when saving # (if editing was added with editor) if $game_system.magic_number != $data_system.magic_number # load map $game_map.setup($game_map.map_id) $game_player.center($game_player.x, $game_player.y) end end #-------------------------------------------------------------------------# * refresh game party #-------------------------------------------------------------------------def read_refresh # refresh party members $game_party.refresh
end end #============================================================================== # ** scene_battle #-----------------------------------------------------------------------------# this class performs battle screen processing. #============================================================================== class scene_battle #-------------------------------------------------------------------------# * object initialization # menu_index : command cursor's initial position #-------------------------------------------------------------------------def initialize commands_init end #-------------------------------------------------------------------------# * set commands #-------------------------------------------------------------------------def commands_init @commands = [] s1 = $data_system.words.attack s2 = $data_system.words.skill s3 = $data_system.words.guard s4 = $data_system.words.item @commands.push(s1, s2, s3, s4).flatten! end #-------------------------------------------------------------------------# * main processing #-------------------------------------------------------------------------def main main_temp main_troop main_command main_windows main_spriteset main_transition # start pre-battle phase start_phase1 # execute transition graphics.transition # main loop loop do main_loop break if main_scenechange? end # refresh map $game_map.refresh # prepare for transition graphics.freeze main_dispose main_end end #-------------------------------------------------------------------------# * game temp variable setup #-------------------------------------------------------------------------def main_temp
# initialize each kind of temporary battle data $game_temp.in_battle = true $game_temp.battle_turn = 0 $game_temp.battle_event_flags.clear $game_temp.battle_abort = false $game_temp.battle_main_phase = false $game_temp.battleback_name = $game_map.battleback_name $game_temp.forcing_battler = nil # initialize battle event interpreter $game_system.battle_interpreter.setup(nil, 0) end #-------------------------------------------------------------------------# * troop setup #-------------------------------------------------------------------------def main_troop # prepare troop @troop_id = $game_temp.battle_troop_id $game_troop.setup(@troop_id) end #-------------------------------------------------------------------------# * main command setup #-------------------------------------------------------------------------def main_command @actor_command_window = window_command.new(160, @commands) @actor_command_window.height = 160 @actor_command_window.y = 160 @actor_command_window.back_opacity = 160 @actor_command_window.active = false @actor_command_window.visible = false end #-------------------------------------------------------------------------# * scene window setup #-------------------------------------------------------------------------def main_windows # make other windows @party_command_window = window_partycommand.new @help_window = window_help.new @help_window.back_opacity = 160 @help_window.visible = false @status_window = window_battlestatus.new @message_window = window_message.new end #-------------------------------------------------------------------------# * spriteset setup #-------------------------------------------------------------------------def main_spriteset # make sprite set @spriteset = spriteset_battle.new # initialize wait count @wait_count = 0 end #-------------------------------------------------------------------------# * main transition #-------------------------------------------------------------------------def main_transition # execute transition if $data_system.battle_transition == "" graphics.transition(20)
else graphics.transition(40, "graphics/transitions/" + $data_system.battle_transition) end end #-------------------------------------------------------------------------# * main loop #-------------------------------------------------------------------------def main_loop # update game screen graphics.update # update input information input.update # frame update update end #-------------------------------------------------------------------------# * scene change #-------------------------------------------------------------------------def main_scenechange? # abort loop if screen is changed if $scene != self return true end return false end #-------------------------------------------------------------------------# * main dispose #-------------------------------------------------------------------------def main_dispose # dispose of windows @actor_command_window.dispose @party_command_window.dispose @help_window.dispose @status_window.dispose @message_window.dispose @skill_window.dispose unless @skill_window == nil @item_window.dispose unless @item_window == nil @result_window.dispose unless @result_window == nil # dispose of sprite set @spriteset.dispose end #-------------------------------------------------------------------------# * main end #-------------------------------------------------------------------------def main_end # if switching to title screen if $scene.is_a?(scene_title) # fade out screen graphics.transition graphics.freeze end # if switching from battle test to any screen other than game over screen if $btest and not $scene.is_a?(scene_gameover) $scene = nil end end #--------------------------------------------------------------------------
# * frame update #-------------------------------------------------------------------------def update update_event update_system update_objects update_transition # if message window is showing if $game_temp.message_window_showing return end # if effect is showing if @spriteset.effect? return end update_scene_exit update_abort update_waiting update_phase end #-------------------------------------------------------------------------# * event update #-------------------------------------------------------------------------def update_event # if battle event is running if $game_system.battle_interpreter.running? # update interpreter $game_system.battle_interpreter.update # if a battler which is forcing actions doesn't exist if $game_temp.forcing_battler == nil # if battle event has finished running unless $game_system.battle_interpreter.running? # rerun battle event set up if battle continues unless judge setup_battle_event end end # if not after battle phase if @phase != 5 # refresh status window @status_window.refresh end end end end #-------------------------------------------------------------------------# * system update #-------------------------------------------------------------------------def update_system # update system (timer) and screen $game_system.update $game_screen.update # if timer has reached 0 if $game_system.timer_working and $game_system.timer == 0 # abort battle $game_temp.battle_abort = true end end
#-------------------------------------------------------------------------# * windows and sprites update #-------------------------------------------------------------------------def update_objects # update windows @help_window.update @party_command_window.update @actor_command_window.update @status_window.update @message_window.update # update sprite set @spriteset.update end #-------------------------------------------------------------------------# * transition update #-------------------------------------------------------------------------def update_transition # if transition is processing if $game_temp.transition_processing # clear transition processing flag $game_temp.transition_processing = false # execute transition if $game_temp.transition_name == "" graphics.transition(20) else graphics.transition(40, "graphics/transitions/" + $game_temp.transition_name) end end end #-------------------------------------------------------------------------# * scene exit update #-------------------------------------------------------------------------def update_scene_exit # if game over if $game_temp.gameover # switch to game over screen $scene = scene_gameover.new return end # if returning to title screen if $game_temp.to_title # switch to title screen $scene = scene_title.new return end end #-------------------------------------------------------------------------# * abort update #-------------------------------------------------------------------------def update_abort # if battle is aborted if $game_temp.battle_abort # return to bgm used before battle started $game_system.bgm_play($game_temp.map_bgm) # battle ends battle_end(1) return
end end #-------------------------------------------------------------------------# * waiting update #-------------------------------------------------------------------------def update_waiting # if waiting if @wait_count > 0 # decrease wait count @wait_count -= 1 return end # if battler forcing an action doesn't exist, # and battle event is running if $game_temp.forcing_battler == nil and $game_system.battle_interpreter.running? return end end #-------------------------------------------------------------------------# * phase update #-------------------------------------------------------------------------def update_phase # branch according to phase case @phase when 1 # pre-battle phase update_phase1 when 2 # party command phase update_phase2 when 3 # actor command phase update_phase3 when 4 # main phase update_phase4 when 5 # after battle phase update_phase5 end end #-------------------------------------------------------------------------# * frame update (actor command phase : basic command) #-------------------------------------------------------------------------def update_phase3_basic_command # if b button was pressed if input.trigger?(input::b) # play cancel se $game_system.se_play($data_system.cancel_se) # go to command input for previous actor phase3_prior_actor return end # if c button was pressed if input.trigger?(input::c) check_commands return end end #-------------------------------------------------------------------------# * check commands #--------------------------------------------------------------------------
def check_commands # loads current command command = @commands[@actor_command_window.index] # branches possible commands if command == $data_system.words.attack update_phase3_command_attack elsif command == $data_system.words.skill update_phase3_command_skill elsif command == $data_system.words.guard update_phase3_command_guard elsif command == $data_system.words.item update_phase3_command_item end end #-------------------------------------------------------------------------# * command : attack #-------------------------------------------------------------------------def update_phase3_command_attack # play decision se $game_system.se_play($data_system.decision_se) # set action @active_battler.current_action.kind = 0 @active_battler.current_action.basic = 0 # start enemy selection start_enemy_select end #-------------------------------------------------------------------------# * command : skill #-------------------------------------------------------------------------def update_phase3_command_skill # play decision se $game_system.se_play($data_system.decision_se) # set action @active_battler.current_action.kind = 1 # start skill selection start_skill_select end #-------------------------------------------------------------------------# * command : guard #-------------------------------------------------------------------------def update_phase3_command_guard # play decision se $game_system.se_play($data_system.decision_se) # set action @active_battler.current_action.kind = 0 @active_battler.current_action.basic = 1 # go to command input for next actor phase3_next_actor end #-------------------------------------------------------------------------# * command : item #-------------------------------------------------------------------------def update_phase3_command_item # play decision se $game_system.se_play($data_system.decision_se) # set action @active_battler.current_action.kind = 2 # start item selection
start_item_select end #-------------------------------------------------------------------------# * make basic action results #-------------------------------------------------------------------------def make_basic_action_result # if attack if @active_battler.current_action.basic == 0 make_basic_action_result_attack return end # if guard if @active_battler.current_action.basic == 1 make_basic_action_result_guard return end # if escape if @active_battler.is_a?(game_enemy) and @active_battler.current_action.basic == 2 make_basic_action_result_escape return end # if doing nothing if @active_battler.current_action.basic == 3 make_basic_action_result_nothing return end end #-------------------------------------------------------------------------# * make basic action results - attack #-------------------------------------------------------------------------def make_basic_action_result_attack # set anaimation id @animation1_id = @active_battler.animation1_id @animation2_id = @active_battler.animation2_id # if action battler is enemy if @active_battler.is_a?(game_enemy) if @active_battler.restriction == 3 target = $game_troop.random_target_enemy elsif @active_battler.restriction == 2 target = $game_party.random_target_actor else index = @active_battler.current_action.target_index target = $game_party.smooth_target_actor(index) end end # if action battler is actor if @active_battler.is_a?(game_actor) if @active_battler.restriction == 3 target = $game_party.random_target_actor elsif @active_battler.restriction == 2 target = $game_troop.random_target_enemy else index = @active_battler.current_action.target_index target = $game_troop.smooth_target_enemy(index) end end # set array of targeted battlers
@target_battlers = [target] # apply normal attack results for target in @target_battlers target.attack_effect(@active_battler) end end #-------------------------------------------------------------------------# * make basic action results - guard #-------------------------------------------------------------------------def make_basic_action_result_guard # display "guard" in help window @help_window.set_text($data_system.words.guard, 1) end #-------------------------------------------------------------------------# * make basic action results - escape #-------------------------------------------------------------------------def make_basic_action_result_escape # display "escape" in help window @help_window.set_text("escape", 1) # escape @active_battler.escape end #-------------------------------------------------------------------------# * make basic action results - nothing #-------------------------------------------------------------------------def make_basic_action_result_nothing # clear battler being forced into action $game_temp.forcing_battler = nil # shift to step 1 @phase4_step = 1 end end