# train_actor =begin Caterpillar walking script Copyright (C) 2005 fukuyama This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA http://www.gnu.org/licenses/lgpl.html http://www.opensource.gr.jp/lesser/lgpl.ja.html =end # Config.rb #============================================================================== # ■ Train_Actor::Config #------------------------------------------------------------------------------ # Caterpillar movement of actor is carried out on map #============================================================================== module Train_Actor # ●Switch setup for transparent status # When true, switch control is used # TRANSPARENT_SWITCH = false TRANSPARENT_SWITCH = true # ●Switch number for transparent status # When TRANSPARENT_SWITCH is true, transparency will be activated when the switch of this number is on TRANSPARENT_SWITCHES_INDEX = 20 # ●Maximum number of actors # There will be support for a large number of people in a party in the future... TRAIN_ACTOR_SIZE_MAX = 4 # ●Actors are solid when Stuck. Checking an Actor allows you to recover them faster. STUCKSTOP = true # ●Actors loses Stuck when changing maps STUCKKEEP = false end # rgss # Spriteset_Map_Module.rb #============================================================================== # ■ Spriteset_Map_Module #------------------------------------------------------------------------------ # Caterpillar movement of actor is carried out on map #============================================================================== module Train_Actor module Spriteset_Map_Module def setup_actor_character_sprites? return @setup_actor_character_sprites_flag != nil end def setup_actor_character_sprites(characters) if !setup_actor_character_sprites? for character in characters.reverse @character_sprites.unshift( Sprite_Character.new(@viewport1, character) ) end @setup_actor_character_sprites_flag = true end end end end class Spriteset_Map include Train_Actor::Spriteset_Map_Module end # Scene_Map_Module.rb #============================================================================== # ■ Scene_Map_Module #------------------------------------------------------------------------------ # Caterpillar movement of actor is carried out on map #============================================================================== module Train_Actor module Scene_Map_Module def setup_actor_character_sprites(characters) @spriteset.setup_actor_character_sprites(characters) end end end class Scene_Map include Train_Actor::Scene_Map_Module alias dl_at_transfer_player transfer_player def transfer_player if !Train_Actor::STUCKKEEP and $game_map.map_id != $game_temp.player_new_map_id $game_party.actors.each do |member| Galv_Jump::STUCKSTATE.each do |state_id| member.remove_state(state_id) end end end dl_at_transfer_player end end # Game_Party_Module.rb #============================================================================== # ■ Game_Party_Module #------------------------------------------------------------------------------ # Caterpillar movement of actor is carried out on map #============================================================================== module Train_Actor module Game_Party_Module attr_reader :characters def actors_dead? for actor in actors if actor.dead? return true end end return false end def update_party_order if not actors_dead? return actors end alive_actors = [] dead_actors = [] for actor in actors if actor.dead? dead_actors.push actor else alive_actors.push actor end end return alive_actors + dead_actors end def setup_actor_character_sprites if @characters.nil? @characters = [] for i in 1 ... TRAIN_ACTOR_SIZE_MAX @characters.push(Game_Party_Actor.new) end end setup_actors = update_party_order for i in 1 ... TRAIN_ACTOR_SIZE_MAX @characters[i - 1].setup(setup_actors[i]) end if $scene.class.method_defined?('setup_actor_character_sprites') $scene.setup_actor_character_sprites(@characters) end end def update_party_actors update_party_order setup_actor_character_sprites transparent = $game_player.transparent if transparent == false if TRANSPARENT_SWITCH transparent = $game_switches[TRANSPARENT_SWITCHES_INDEX] end end for character in @characters character.transparent = transparent character.move_speed = $game_player.move_speed character.step_anime = $game_player.step_anime character.update end end def moveto_party_actors( x, y ) setup_actor_character_sprites for character in @characters character.moveto( x, y ) end if @move_list == nil @move_list = [] end move_list_setup end def leading_char(i) bob = i - 1 until bob < 0 do return @characters[bob] if $game_party.actors[bob + 1] != nil and !$game_party.actors[bob + 1].has_stuck? bob -= 1 end return $game_player end def move_party_actors return unless @characters i = @characters.size until i < 0 do i -= 1 if @characters[i] != nil next if @characters[i].moving? next if $game_party.actors[i + 1] == nil char = leading_char(i) dx = (char.x - @characters[i].x) dy = (char.y - @characters[i].y) if $game_party.actors[i + 1].has_stuck? next elsif $game_party.actors[i + 1].has_hop? @characters[i].randstep maxdis = 1 maxdis = 2 if dx == 0 or dy == 0 dx = dx > 0 ? [dx, maxdis].min : [dx, -maxdis].max dy = dy > 0 ? [dy, maxdis].min : [dy, -maxdis].max if !$game_map.passable?(@characters[i].x - dx, @characters[i].y - dy, @characters[i].direction) dx = dx > 0 ? [dx, 1].min : [dx, -1].max dy = dy > 0 ? [dy, 1].min : [dy, -1].max end @characters[i].jump(dx, dy) if @characters[i].passable?(@characters[i].x + dx, @characters[i].y + dy, 0) @characters[i].update_state_stepper if dx.abs + dy.abs != 0 else @characters[i].update_state_stepper if dx.abs + dy.abs != 0 if dx > 0 and dy > 0 and ((@characters[i].passable?(@characters[i].x, @characters[i].y, Input::UP) and @characters[i].passable?(@characters[i].x, @characters[i].y - 1, Input::RIGHT)) or (@characters[i].passable?(@characters[i].x, @characters[i].y, Input::RIGHT) and @characters[i].passable?(@characters[i].x + 1, @characters[i].y, Input::UP))) @characters[i].move_lower_right elsif dx < 0 and dy > 0 and ((@characters[i].passable?(@characters[i].x, @characters[i].y, Input::DOWN) and @characters[i].passable?(@characters[i].x, @characters[i].y + 1, Input::RIGHT)) or (@characters[i].passable?(@characters[i].x, @characters[i].y, Input::RIGHT) and @characters[i].passable?(@characters[i].x + 1, @characters[i].y, Input::DOWN))) @characters[i].move_lower_left elsif dx > 0 and dy < 0 and ((@characters[i].passable?(@characters[i].x, @characters[i].y, Input::DOWN) and @characters[i].passable?(@characters[i].x, @characters[i].y + 1, Input::LEFT)) or (@characters[i].passable?(@characters[i].x, @characters[i].y, Input::LEFT) and @characters[i].passable?(@characters[i].x - 1, @characters[i].y, Input::DOWN))) @characters[i].move_upper_right elsif dx < 0 and dy < 0 and ((@characters[i].passable?(@characters[i].x, @characters[i].y, Input::UP) and @characters[i].passable?(@characters[i].x, @characters[i].y - 1, Input::LEFT)) or (@characters[i].passable?(@characters[i].x, @characters[i].y, Input::LEFT) and @characters[i].passable?(@characters[i].x - 1, @characters[i].y, Input::UP))) @characters[i].move_upper_left elsif dy > 0 and @characters[i].passable?(@characters[i].x, @characters[i].y, 2) @characters[i].move_down(true) elsif dx < 0 and @characters[i].passable?(@characters[i].x, @characters[i].y, 4) @characters[i].move_left(true) elsif dx > 0 and @characters[i].passable?(@characters[i].x, @characters[i].y, 6) @characters[i].move_right(true) elsif dy < 0 and @characters[i].passable?(@characters[i].x, @characters[i].y, 8) @characters[i].move_up(true) end end end end end def move_list_setup for i in 0 .. Train_Actor::TRAIN_ACTOR_SIZE_MAX @move_list[i] = nil end end end end class Game_Party include Train_Actor::Game_Party_Module def check_map_slip_damage bob = self.actors[0] return unless bob if bob.hp > 0 and bob.slip_damage? and rand(3) == 0 bob.hp -= [ bob.maxhp / 100, 1].max if bob.hp == 0 $game_system.se_play($data_system.actor_collapse_se) end $game_screen.start_flash(Color.new(255,0,0,128), 4) $game_temp.gameover = $game_party.all_dead? end end end # Game_Player_Module.rb #============================================================================== # ■ Game_Player_Module #------------------------------------------------------------------------------ # Caterpillar movement of actor is carried out on map #============================================================================== module Train_Actor module Game_Player_Module attr_reader :move_speed attr_reader :step_anime def update_party_actors $game_party.update_party_actors $game_party.actors.each do |actor| if actor.dead? next end @character_name = actor.character_name @character_hue = actor.character_hue break end end def update update_party_actors super end def moveto( x, y ) $game_party.moveto_party_actors( x, y ) super( x, y ) end def move_down(turn_enabled = true) if passable?(@x, @y, Input::DOWN) $game_party.move_party_actors end super(turn_enabled) end def move_left(turn_enabled = true) if passable?(@x, @y, Input::LEFT) $game_party.move_party_actors end super(turn_enabled) end def move_right(turn_enabled = true) if passable?(@x, @y, Input::RIGHT) $game_party.move_party_actors end super(turn_enabled) end def move_up(turn_enabled = true) if passable?(@x, @y, Input::UP) $game_party.move_party_actors end super(turn_enabled) end def move_lower_left # When possible to move from down→left or from left→down if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT)) or (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN)) $game_party.move_party_actors end super end def move_lower_right # When possible to move from down→right or from right→down if (passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT)) or (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN)) $game_party.move_party_actors end super end def move_upper_left # When possible to move from up→left or from left→up if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT)) or (passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP)) $game_party.move_party_actors end super end def move_upper_right # When possible to move from up→right or from right→up if (passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT)) or (passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP)) $game_party.move_party_actors end super end def jump(x_plus, y_plus) # New coordinates are calculated new_x = @x + x_plus new_y = @y + y_plus # When addition values are (0,0), it is possible to jump to the destination if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0) $game_party.move_party_actors end super(x_plus, y_plus) end end end class Game_Player include Train_Actor::Game_Player_Module alias dl_cett check_event_trigger_there def check_event_trigger_there(triggers) abs_fight if Train_Actor::STUCKSTOP and Input.trigger?(Input::C) dl_cett(triggers) end def abs_fight d = @direction x2 = @x + (d == 6 ? 1 : d == 4 ? -1 : 0) y2 = @y + (d == 2 ? 1 : d == 8 ? -1 : 0) $game_party.characters.each do |follower| if follower.x == x2 and follower.y == y2 and follower.stuck_state? and Train_Actor::STUCKSTOP follower.abs_heal end end end alias dl_ta_passable? passable? def passable?(x, y, d) x2 = @x + (d == 6 ? 1 : d == 4 ? -1 : 0) y2 = @y + (d == 2 ? 1 : d == 8 ? -1 : 0) $game_party.characters.each do |follower| if follower.x == x2 and follower.y == y2 and follower.stuck_state? and Train_Actor::STUCKSTOP return false end end return dl_ta_passable?(x, y, d) end end # Game_Event_Module.rb #============================================================================== # ■ Game_Event_Module #------------------------------------------------------------------------------ # Caterpillar movement of actor is carried out on map #============================================================================== module Train_Actor module Game_Event_Module #-------------------------------------------------------------------------- # ● Judgement determined # x : X coordinates # y : Y coordinates # d : Direction (0,2,4,6,8) ※ 0 = Checks if all directions are not able to be passed (for a jump) # return : Passing is impossible (false), possible (true) #-------------------------------------------------------------------------- def passable?(x, y, d) result = super(x, y, d) if result # New coordinates are searched for new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0) new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0) # Loops for actor in train for actor in $game_party.characters # When displayed if not actor.character_name.empty? # When actor's coordinates correspond to the destination if actor.x == new_x and actor.y == new_y # When event if self != $game_player # Passing is impossible return false end end end end end return result end end end class Game_Event include Train_Actor::Game_Event_Module end # Game_Party_Actor.rb #============================================================================== # ■ Game_Party_Actor #------------------------------------------------------------------------------ # Caterpillar movement of actor is carried out on map #============================================================================== class Game_Party_Actor < Game_Character attr_writer :move_speed attr_writer :step_anime attr_writer :actor def initialize super() @through = true end def setup(actor) @actor = actor # The file name and hue of the character are set if actor != nil and (not actor.dead?) # When dead, it is erased for the time being... @character_name = actor.character_name @character_hue = actor.character_hue else @character_name = "" @character_hue = 0 @x = $game_player.x @y = $game_player.y end # Opacity and blending method are initialized @opacity = 255 @blend_type = 0 end def screen_z(height = 0) if $game_player.x == @x and $game_player.y == @y return $game_player.screen_z(height) - 1 end super(height) end def stuck_state? return @actor.has_stuck? if @actor return false end def hop_state? return @actor.has_hop? if @actor return false end def do_jump check_distance @can_jump = false unless passable?(@x,@y,@direction) jump(@jump_x, @jump_y) if @can_jump randstep end def update_state_stepper return if @actor == nil @actor.remove_states_auto if @actor.hp > 0 and @actor.slip_damage? @actor.hp -= [@actor.maxhp / 100, 1].max if @actor.hp == 0 $game_system.se_play($data_system.actor_collapse_se) end $game_screen.start_flash(Color.new(255,0,0,128), 4) $game_temp.gameover = $game_party.all_dead? end end def abs_heal return unless @actor and @actor.has_stuck? Audio.se_play(Galv_Jump::STUCK_SE) randstep @actor.remove_states_auto if rand(3) == 0 update_state_stepper $game_player.make_encounter_count end end alias dl_mp_update update def update dl_mp_update return unless @actor and @actor.has_stuck? @countdown = 2000 if @countdown == nil if @countdown > 0 @countdown -= rand(@actor.level + 50) else update_state_stepper randstep @countdown = 2000 end end end