Advertisement
Vendily

Sky Battles + Inverse Battles v20

Nov 17th, 2022
1,796
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.04 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Sky Battles + Inverse Battles
  3. # Credit: mej71 (original), bo4p5687 (update), Vendily (v20 update)
  4. #
  5. #   If you want to set inverse battles, call: setBattleRule("inverseBattle")
  6. #   If you want to set sky battles, call: setBattleRule("skyBattle")
  7. #-------------------------------------------------------------------------------
  8. #-------------------------------------------------------------------------------
  9. #-------------------------------------------------------------------------------
  10. module SkyBattle
  11.   # Store pokemon can't battle (sky mode)
  12.   # Pokemon aren't allowed to participate even though they are flying or have levitate
  13.   # Add new pokemon: ':NAME'
  14.   SkyPokemon = [
  15.         :PIDGEY, :SPEAROW, :FARFETCHD, :DODUO, :DODRIO, :GENGAR, :HOOTHOOT, :NATU,
  16.         :MURKROW, :DELIBIRD, :TAILLOW, :STARLY, :CHATOT, :SHAYMIN, :PIDOVE, :ARCHEN,
  17.         :DUCKLETT, :RUFFLET, :VULLABY, :FLETCHLING, :HAWLUCHA
  18.   ]
  19.  
  20.     # Store pokemon can battle (sky mode)
  21.     # Pokemon are allowed to participate even though they aren't flying or haven't levitate
  22.     # Add new pokemon: ':NAME'
  23.     CanBattle = [
  24.         # Example: :BULBASAUR
  25.         # Add below this:
  26.         :RATTATA, :EKANS
  27.     ]
  28.  
  29.   def self.checkPkmnSky?(pkmn)
  30.     list = []
  31.     SkyPokemon.each { |species| list <<  GameData::Species.get(species).id }
  32.     return true if list.include?(pkmn.species)
  33.     return false
  34.   end
  35.  
  36.     def self.checkExceptPkmn?(pkmn)
  37.     list = []
  38.     CanBattle.each { |species| list <<  GameData::Species.get(species).id }
  39.     return true if list.include?(pkmn.species)
  40.     return false
  41.   end
  42.  
  43.   # Check pokemon in sky battle
  44.     def self.canSkyBattle?(pkmn)
  45.     checktype    = pkmn.hasType?(:FLYING)
  46.     checkability = pkmn.hasAbility?(:LEVITATE)
  47.     checkpkmn    = SkyBattle.checkPkmnSky?(pkmn)
  48.     except       = SkyBattle.checkExceptPkmn?(pkmn)
  49.     return ( (checktype || checkability) && !checkpkmn ) || except
  50.   end
  51.  
  52.   # Store move pokemon can't use (sky mode)
  53.   # Add new move: ':MOVE'
  54.   SkyMove = [
  55.         :BODYSLAM, :BULLDOZE, :DIG, :DIVE, :EARTHPOWER, :EARTHQUAKE, :ELECTRICTERRAIN,
  56.         :FISSURE, :FIREPLEDGE, :FLYINGPRESS, :FRENZYPLANT, :GEOMANCY, :GRASSKNOT,
  57.         :GRASSPLEDGE, :GRASSYTERRAIN, :GRAVITY, :HEATCRASH, :HEAVYSLAM, :INGRAIN,
  58.         :LANDSWRATH, :MAGNITUDE, :MATBLOCK, :MISTYTERRAIN, :MUDSPORT, :MUDDYWATER,
  59.         :ROTOTILLER, :SEISMICTOSS, :SLAM, :SMACKDOWN, :SPIKES, :STOMP, :SUBSTITUTE,
  60.         :SURF, :TOXICSPIKES, :WATERPLEDGE, :WATERSPORT
  61.   ]
  62.  
  63.   def self.checkMoveSky?(id)
  64.     list = []
  65.     SkyMove.each { |moves| list << GameData::Move.get(moves).id }
  66.     return true if list.include?(id)
  67.     return false
  68.   end
  69. end
  70. #-------------------------------------------------------------------------------
  71. # Set rules
  72. #-------------------------------------------------------------------------------
  73. class Game_Temp
  74.   attr_accessor :battle_sky
  75.   attr_accessor :battle_inverse
  76.  
  77.   alias sky_inverse_battle_rule add_battle_rule
  78.   def add_battle_rule(rule, var = nil)
  79.     rules = self.battle_rules
  80.     case rule.to_s.downcase
  81.     when "skybattle";     rules["skyBattle"] = true
  82.     when "inversebattle"; rules["inverseBattle"] = true
  83.     else; sky_inverse_battle_rule(rule,var)
  84.     end
  85.   end
  86. end
  87.  
  88. EventHandlers.add(:on_end_battle, :end_inverse_sky_rule,
  89.   proc { |decision, canLose|
  90.     $game_temp.battle_sky = false
  91.     $game_temp.battle_inverse = false
  92.   }
  93. )
  94. #-------------------------------------------------------------------------------
  95. # Set type for 'inverse'
  96. #-------------------------------------------------------------------------------
  97. module GameData
  98.     class Type
  99.         alias inverse_effect effectiveness
  100.         def effectiveness(other_type)
  101.             return Effectiveness::NORMAL_EFFECTIVE_ONE if !other_type
  102.             ret = inverse_effect(other_type)
  103.             if $game_temp.battle_inverse
  104.                 case ret
  105.                 when Effectiveness::INEFFECTIVE, Effectiveness::NOT_VERY_EFFECTIVE_ONE
  106.           ret = Effectiveness::SUPER_EFFECTIVE_ONE
  107.                 when Effectiveness::SUPER_EFFECTIVE_ONE
  108.           ret = Effectiveness::NOT_VERY_EFFECTIVE_ONE
  109.                 end
  110.             end
  111.             return ret
  112.         end
  113.     end
  114. end
  115. #-------------------------------------------------------------------------------
  116. class Battle
  117.   alias sky_choose_move pbCanChooseMove?
  118.   def pbCanChooseMove?(idxBattler, idxMove, showMessages, sleepTalk = false)
  119.     ret = sky_choose_move(idxBattler,idxMove,showMessages,sleepTalk)
  120.     battler = @battlers[idxBattler]
  121.     move = battler.moves[idxMove]
  122.     # Check move
  123.     if ret && $game_temp.battle_sky && SkyBattle.checkMoveSky?(move.id)
  124.       pbDisplayPaused(_INTL("{1} can't use in a sky battle!",move.name)) if showMessages
  125.       return false
  126.     end
  127.     return ret
  128.   end
  129. end
  130. #-------------------------------------------------------------------------------
  131. # Set sky battle conditions
  132. #-------------------------------------------------------------------------------
  133. module BattleCreationHelperMethods
  134.   module_function
  135.  
  136.   # Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
  137.   def skip_battle?
  138.     return true if $player.able_pokemon_count == 0
  139.     if $game_temp.battle_rules["skyBattle"]
  140.       count = 0
  141.       $player.able_party.each { |p| count+=1 if SkyBattle.canSkyBattle?(p)}
  142.       return true if count==0
  143.     end
  144.     return true if $DEBUG && Input.press?(Input::CTRL)
  145.     return false
  146.   end
  147.  
  148.  def partner_can_participate?(foe_party)
  149.     return false if !$PokemonGlobal.partner || $game_temp.battle_rules["noPartner"]
  150.     if $game_temp.battle_rules["skyBattle"]
  151.       count = 0
  152.       $PokemonGlobal.partner[3].each { |p| count+=1 if SkyBattle.canSkyBattle?(p)}
  153.       return false if count==0
  154.     end
  155.     return true if foe_party.length > 1
  156.     if $game_temp.battle_rules["size"]
  157.       return false if $game_temp.battle_rules["size"] == "single" ||
  158.                       $game_temp.battle_rules["size"][/^1v/i]   # "1v1", "1v2", "1v3", etc.
  159.       return true
  160.     end
  161.     return false
  162.   end
  163.  
  164.   # Generate information for the player and partner trainer(s)
  165.   def set_up_player_trainers(foe_party)
  166.     trainer_array = [$player]
  167.     ally_items    = []
  168.     pokemon_array = $player.party
  169.     party_starts  = [0]
  170.     if $game_temp.battle_rules["skyBattle"]
  171.       pokemon_array = []
  172.       # allows fainted mons, if they could participate if revived
  173.       # leaves eggs alone, because they don't count anyways
  174.       $player.party.each { |p| pokemon_array.push(p) if p && SkyBattle.canSkyBattle?(p) }
  175.     end
  176.     if partner_can_participate?(foe_party)
  177.       ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0])
  178.       ally.id    = $PokemonGlobal.partner[2]
  179.       ally.party = $PokemonGlobal.partner[3]
  180.       ally_items[1] = ally.items.clone
  181.       trainer_array.push(ally)
  182.       pokemon_array = []
  183.       if $game_temp.battle_rules["skyBattle"]
  184.         # allows fainted mons, if they could participate if revived
  185.         # leaves eggs alone, because they don't count anyways
  186.         $player.party.each { |p| pokemon_array.push(p) if p && SkyBattle.canSkyBattle?(p) }
  187.       else
  188.         $player.party.each { |pkmn| pokemon_array.push(pkmn) }
  189.       end
  190.       party_starts.push(pokemon_array.length)
  191.       if $game_temp.battle_rules["skyBattle"]
  192.         # allows fainted mons, if they could participate if revived
  193.         # leaves eggs alone, because they don't count anyways
  194.         ally.party.each { |pkmn| pokemon_array.push(pkmn) if SkyBattle.canSkyBattle?(pkmn) }
  195.       else
  196.         ally.party.each { |pkmn| pokemon_array.push(pkmn) }
  197.       end
  198.       setBattleRule("double") if $game_temp.battle_rules["size"].nil?
  199.     end
  200.     return trainer_array, ally_items, pokemon_array, party_starts
  201.   end
  202.  
  203.   class << self
  204.     alias sky_inverse_prepare_battle prepare_battle
  205.     def prepare_battle(battle)
  206.       self.sky_inverse_prepare_battle(battle)
  207.       $game_temp.battle_sky = false
  208.       $game_temp.battle_sky = true if $game_temp.battle_rules["skyBattle"]
  209.       $game_temp.battle_inverse = false
  210.       $game_temp.battle_inverse = true if $game_temp.battle_rules["inverseBattle"]
  211.     end
  212.   end
  213. end
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement