Advertisement
M3rein

Pokéride_Main

Oct 19th, 2017
1,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.73 KB | None | 0 0
  1. #==============================================================================#
  2. #                Pokéride for Pokémon Essentials v16.X | v17.X                 #
  3. #                                    v1.0                                      #
  4. #                                                                              #
  5. #                                  by Marin                                    #
  6. #==============================================================================#
  7. #                                    Note                                      #
  8. # This script is merely for functionality. It does not provide a whole system, #
  9. #    and things such as availability of certain Pokérides is not included.     #
  10. #==============================================================================#
  11. #                                    Usage                                     #
  12. #  To mount a Pokéride, use "pbMount(name)". "name" is the name of the module, #
  13. #                  which can be found in "Pokéride_Rides".                     #
  14. #==============================================================================#
  15.  
  16. # Example:
  17. # pbMount(Tauros)
  18. def pbMount(_module)
  19.   sheet = _module::MoveSheet[$Trainer.gender]
  20.   $game_player.setDefaultCharName(sheet,$game_player.fullPattern)
  21.   _module.mount if _module.respond_to?("mount")
  22.   $PokemonGlobal.surfing = true if defined?(_module::CanSurf) && _module::CanSurf
  23.   $PokemonGlobal.mount = _module
  24. end
  25.  
  26. def pbDismount
  27.   $PokemonGlobal.mount.dismount if $PokemonGlobal.mount &&
  28.                                    $PokemonGlobal.mount.respond_to?("dismount")
  29.   $PokemonGlobal.surfing = false if defined?(_module::CanSurf) && _module::CanSurf
  30.   $PokemonGlobal.mount = nil
  31.   $game_player.setDefaultCharName(nil,$game_player.fullPattern)
  32. end
  33.  
  34. # $Trainer.can_rock_climb has to be true if you want to be able to use Rock Climb.
  35. class PokeBattle_Trainer
  36.   attr_accessor :can_rock_climb
  37.  
  38.   alias pokeride_init initialize
  39.   def initialize(name, trainertype)
  40.     pokeride_init(name, trainertype)
  41.     @can_rock_climb = false
  42.   end
  43. end
  44.  
  45. unless defined?(pbList)
  46.   # If you call this on an event, it'll be no longer listed in the Itemfinder
  47.   # (if it even had ".hidden" in the name)
  48.   def pbUnlist(event_id)
  49.     $game_map.events[event_id].listed = false if $game_map.events[event_id]
  50.   end
  51.  
  52.   # The Itemfinder will show this event (but still only if it has .hidden in name)
  53.   def pbList(event_id)
  54.     $game_map.events[event_id].listed = true if $game_map.events[event_id]
  55.   end
  56. end
  57.  
  58.  
  59. class PokemonGlobalMetadata
  60.   attr_accessor :mount
  61.   attr_accessor :mount_action
  62. end
  63.  
  64. unless defined?(Game_Event.listed)
  65.   class Game_Event
  66.     attr_accessor :listed
  67.    
  68.     alias pokeride_init initialize
  69.     def initialize(map_id, event, map = nil)
  70.       pokeride_init(map_id, event, map)
  71.       @listed = true # Set to true, but whether it's actually listed or not
  72.                      # depends on the name.
  73.     end
  74.   end
  75. end
  76.  
  77. def pbHiddenItemNearby?
  78.   x = $game_player.x
  79.   y = $game_player.y
  80.   for event in $game_map.events
  81.     event = event[1]
  82.     if event.name.include?(".hidden") && event.listed
  83.       if event.x - x >= -4 && event.x - x <= 4
  84.         if event.y - y >= -4 && event.y - y <= 4
  85.           return true
  86.         end
  87.       end
  88.     end
  89.   end
  90.   return false
  91. end
  92.  
  93. class Game_Player
  94.   alias pokeride_update update
  95.   def update
  96.     pokeride_update
  97.     if $PokemonGlobal.mount
  98.       if Input.press?(Input::A)
  99.         @move_speed = $PokemonGlobal.mount::ActionSpeed
  100.         sheet = $PokemonGlobal.mount::ActionSheet[$Trainer.gender]
  101.         $game_player.setDefaultCharName(sheet,$game_player.fullPattern)
  102.         $PokemonGlobal.mount_action = true
  103.         if defined?($PokemonGlobal.mount::ShowHidden) && $PokemonGlobal.mount::ShowHidden
  104.           if pbHiddenItemNearby?
  105.             sheet = $PokemonGlobal.mount::HiddenNearbySheet[$Trainer.gender]
  106.             $game_player.setDefaultCharName(sheet,$game_player.fullPattern)
  107.             @move_speed = $PokemonGlobal.mount::HiddenNearbySpeed
  108.           end
  109.         end
  110.       else
  111.         @move_speed = $PokemonGlobal.mount::MoveSpeed
  112.         sheet = $PokemonGlobal.mount::MoveSheet[$Trainer.gender]
  113.         $game_player.setDefaultCharName(sheet,$game_player.fullPattern)
  114.         $PokemonGlobal.mount_action = false
  115.       end
  116.     end
  117.   end
  118.  
  119.   alias pokeride_trigger check_event_trigger_there
  120.   def check_event_trigger_there(triggers)
  121.     result = pokeride_trigger(triggers)
  122.     return result if ROCK_CLIMB_MOUNT.nil?
  123.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  124.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  125.     if result == false
  126.       for i in [2,1,0]
  127.         if $game_map.terrain_tags[$game_map.map.data[new_x, new_y, i]] == PBTerrain::RockClimb
  128.           activemount = $PokemonGlobal.mount && defined?($PokemonGlobal.mount::RockClimb) &&
  129.                         $PokemonGlobal.mount::RockClimb
  130.           if activemount || $Trainer.can_rock_climb && Kernel.pbConfirmMessage(_INTL("Do you want to rock climb here?"))
  131.             unless activemount
  132.               Kernel.pbCancelVehicles
  133.               pbMount(eval(ROCK_CLIMB_MOUNT))
  134.               pbWait(10)
  135.             end
  136.             climb = true
  137.             up = false
  138.             for j in [2,1,0]
  139.               if @y > 0 && (($game_map.terrain_tags[$game_map.map.data[@x+2,@y-1,j]] == PBTerrain::RockClimb rescue false) ||
  140.                  (@x > 1 && $game_map.terrain_tags[$game_map.map.data[@x-2,@y-1,j]] == PBTerrain::RockClimb))
  141.                 up = true
  142.                 break
  143.               end
  144.             end
  145.             unless @direction == 2 || direction == 8
  146.               @x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  147.             end
  148.             pbWait(4)
  149.             while climb
  150.               _x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  151.               _y = @y
  152.               if @direction == 2 || @direction == 8
  153.                 _y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  154.               elsif up
  155.                 _y -= 1
  156.               else
  157.                 _y += 1
  158.               end
  159.               pbWait(4)
  160.               climb = false
  161.               @x = _x
  162.               for j in [2,1,0]
  163.                 if $game_map.terrain_tags[$game_map.map.data[_x, _y, j]] == PBTerrain::RockClimb
  164.                   climb = true
  165.                   break
  166.                 end
  167.               end
  168.               @y = _y if climb || @direction == 2 || @direction == 8
  169.             end
  170.           end
  171.           return true
  172.         end
  173.       end
  174.     end
  175.     return result
  176.   end
  177. end
  178.  
  179. if defined?(Sprite_SurfBase)
  180.   class Sprite_SurfBase
  181.     alias pokeride_init initialize
  182.     def initialize(sprite, event, viewport = nil)
  183.       return if $PokemonGlobal.mount
  184.       pokeride_init(sprite, event, viewport)
  185.     end
  186.    
  187.     alias pokeride_update update
  188.     def update
  189.       return if $PokemonGlobal.mount
  190.       pokeride_update
  191.     end
  192.    
  193.     def dispose
  194.       if !@disposed
  195.         @sprite.dispose if @sprite
  196.         @sprite   = nil
  197.         @surfbitmap.dispose if @surfbitmap
  198.         @surfbitmap = nil
  199.         @disposed = true
  200.       end
  201.     end
  202.   end
  203. end
  204.  
  205. module Kernel
  206.   class << Kernel
  207.     alias pokeride_cancel_vehicles pbCancelVehicles
  208.     alias pokeride_surf pbSurf
  209.   end
  210.  
  211.   def self.pbCancelVehicles(destination = nil)
  212.     pbDismount
  213.     pokeride_cancel_vehicles(destination)
  214.   end
  215.  
  216.   def self.pbSurf
  217.     unless SURF_MOUNT.nil?
  218.       Kernel.pbCancelVehicles
  219.       $PokemonEncounters.clearStepCount
  220.       $PokemonGlobal.surfing = true
  221.       if defined?($PokemonTemp.surfJump)
  222.         $PokemonTemp.surfJump = $MapFactory.getFacingCoords($game_player.x,$game_player.y,$game_player.direction)
  223.       end
  224.       $PokemonGlobal.mount = eval(SURF_MOUNT)
  225.       Kernel.pbUpdateVehicle
  226.       Kernel.pbJumpToward
  227.       if defined?($PokemonTemp.surfJump)
  228.         $PokemonTemp.surfJump = nil
  229.       end
  230.       Kernel.pbUpdateVehicle
  231.       $game_player.check_event_trigger_here([1,2])
  232.     else
  233.       pokeride_surf
  234.     end
  235.   end
  236. end
  237.  
  238. unless defined?(pbSmashEvent)
  239.   def pbSmashEvent(event)
  240.     return if !event
  241.     if event.name=="Tree";    pbSEPlay("Cut",80)
  242.     elsif event.name=="Rock"; pbSEPlay("Rock Smash",80)
  243.     end
  244.     pbMoveRoute(event,[
  245.        PBMoveRoute::Wait,2,
  246.        PBMoveRoute::TurnLeft,
  247.        PBMoveRoute::Wait,2,
  248.        PBMoveRoute::TurnRight,
  249.        PBMoveRoute::Wait,2,
  250.        PBMoveRoute::TurnUp,
  251.        PBMoveRoute::Wait,2
  252.     ])
  253.     pbWait(2*2*4)
  254.     event.erase
  255.     $PokemonMap.addErasedEvent(event.id) if $PokemonMap
  256.   end
  257. end
  258.  
  259. class Game_Character
  260.   alias pokeride_passableex passableEx?
  261.   def passableEx?(x, y, d, strict = false)
  262.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  263.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  264.     return false unless self.map.valid?(new_x, new_y)
  265.     return true if @through
  266.     # Pokéride Rock Smash
  267.     if $PokemonGlobal.mount && $PokemonGlobal.mount_action &&
  268.        defined?($PokemonGlobal.mount::RockSmash) &&
  269.        $PokemonGlobal.mount::RockSmash
  270.       for event in self.map.events
  271.         if event[1].name == "Rock" && event[1].x == new_x && event[1].y == new_y
  272.           facingEvent = $game_player.pbFacingEvent
  273.           if facingEvent
  274.             pbSmashEvent(facingEvent)
  275.             return true
  276.           end
  277.         end
  278.       end
  279.     end
  280.     return pokeride_passableex(x, y, d, strict)
  281.   end
  282. end
  283.  
  284. class Spriteset_Map
  285.   alias pokeride_update update
  286.   def update
  287.     pokeride_update
  288.     if $PokemonGlobal.mount && defined?($PokemonGlobal.mount::Strength) &&
  289.        $PokemonGlobal.mount::Strength
  290.       $PokemonMap.strengthUsed = $PokemonGlobal.mount_action
  291.     end
  292.   end
  293. end
  294.  
  295. module PBTerrain
  296.   Mudsdale = 17 # Only passable if on a Mudsdale
  297.   RockClimb = 18 # Can only be traversed on a Pokéride with RockClimb capabilities
  298. end
  299.  
  300. class Game_Map
  301.   attr_reader :map
  302.  
  303.   alias pokeride_playerpassable playerPassable?
  304.   def playerPassable?(x, y, d, self_event = nil)
  305.     for i in [2, 1, 0]
  306.       if @terrain_tags[data[x, y, i]] == PBTerrain::Mudsdale
  307.         return $PokemonGlobal.mount && defined?($PokemonGlobal.mount::WalkOnMudsdale) &&
  308.                $PokemonGlobal.mount::WalkOnMudsdale
  309.       end
  310.     end
  311.     pokeride_playerpassable(x, y, d, self_event)
  312.   end
  313. end
  314.  
  315. def pbStartSurfing
  316.   Kernel.pbCancelVehicles
  317.   $PokemonEncounters.clearStepCount
  318.   $PokemonGlobal.surfing = true
  319.   if defined?($PokemonTemp.surfJump)
  320.     $PokemonTemp.surfJump = $MapFactory.getFacingCoords($game_player.x,$game_player.y,$game_player.direction)
  321.   end
  322.   Kernel.pbUpdateVehicle
  323.   Kernel.pbJumpToward
  324.   if defined?($PokemonTemp.surfJump)
  325.     $PokemonTemp.surfJump = nil
  326.   end
  327.   Kernel.pbUpdateVehicle
  328. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement