diff --git a/Data/Scripts/011_Data/001_Game data/012_Trainer.rb b/Data/Scripts/011_Data/001_Game data/012_Trainer.rb index 0fc9879a2..09db47be7 100644 --- a/Data/Scripts/011_Data/001_Game data/012_Trainer.rb +++ b/Data/Scripts/011_Data/001_Game data/012_Trainer.rb @@ -118,21 +118,20 @@ module GameData pkmn.forcedForm = pkmn_data[:form] if MultipleForms.hasFunction?(species, "getForm") pkmn.formSimple = pkmn_data[:form] end - pkmn.setItem(pkmn_data[:item]) + pkmn.item = pkmn_data[:item] if pkmn_data[:moves] && pkmn_data[:moves].length > 0 pkmn_data[:moves].each { |move| pkmn.pbLearnMove(move) } else pkmn.resetMoves end - pkmn.setAbility(pkmn_data[:ability_flag]) - gender = pkmn_data[:gender] || ((trainer.female?) ? 1 : 0) - pkmn.setGender(gender) - (pkmn_data[:shininess]) ? pkmn.makeShiny : pkmn.makeNotShiny + pkmn.ability_index = pkmn_data[:ability_flag] + pkmn.gender = pkmn_data[:gender] || ((trainer.male?) ? 0 : 1) + pkmn.shiny = (pkmn_data[:shininess]) ? true : false if pkmn_data[:nature] - pkmn.setNature(pkmn_data[:nature]) + pkmn.nature = pkmn_data[:nature] else nature = pkmn.species_data.id_number + GameData::TrainerType.get(trainer.trainertype).id_number - pkmn.setNature(nature % (PBNatures.maxValue + 1)) + pkmn.nature = nature % (PBNatures.maxValue + 1) end PBStats.eachStat do |s| if pkmn_data[:iv] && pkmn_data[:iv].length > 0 @@ -151,7 +150,7 @@ module GameData if pkmn_data[:shadowness] pkmn.makeShadow pkmn.pbUpdateShadowMoves(true) - pkmn.makeNotShiny + pkmn.shiny = false end pkmn.ballused = pkmn_data[:poke_ball] if pkmn_data[:poke_ball] pkmn.calcStats diff --git a/Data/Scripts/012_Battle/001_Battler/001_PokeBattle_Battler.rb b/Data/Scripts/012_Battle/001_Battler/001_PokeBattle_Battler.rb index 76395c055..a597e2543 100644 --- a/Data/Scripts/012_Battle/001_Battler/001_PokeBattle_Battler.rb +++ b/Data/Scripts/012_Battle/001_Battler/001_PokeBattle_Battler.rb @@ -76,7 +76,7 @@ class PokeBattle_Battler def item=(value) new_item = GameData::Item.try_get(value) @item_id = (new_item) ? new_item.id : nil - @pokemon.setItem(@item_id) if @pokemon + @pokemon.item = @item_id if @pokemon end def defense diff --git a/Data/Scripts/012_Battle/001_Battler/002_Battler_Initialize.rb b/Data/Scripts/012_Battle/001_Battler/002_Battler_Initialize.rb index c31223ef9..2924f693d 100644 --- a/Data/Scripts/012_Battle/001_Battler/002_Battler_Initialize.rb +++ b/Data/Scripts/012_Battle/001_Battler/002_Battler_Initialize.rb @@ -93,7 +93,7 @@ class PokeBattle_Battler @participants = [] # Participants earn Exp. if this battler is defeated @moves = [] pkmn.moves.each_with_index do |m,i| - @moves[i] = PokeBattle_Move.pbFromPBMove(@battle,m) + @moves[i] = PokeBattle_Move.from_pokemon_move(@battle,m) end @iv = pkmn.iv.clone end diff --git a/Data/Scripts/012_Battle/001_Battler/003_Battler_ChangeSelf.rb b/Data/Scripts/012_Battle/001_Battler/003_Battler_ChangeSelf.rb index 2bd3efa81..b0352aa8c 100644 --- a/Data/Scripts/012_Battle/001_Battler/003_Battler_ChangeSelf.rb +++ b/Data/Scripts/012_Battle/001_Battler/003_Battler_ChangeSelf.rb @@ -281,7 +281,7 @@ class PokeBattle_Battler end @moves.clear target.moves.each_with_index do |m,i| - @moves[i] = PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(m.id)) + @moves[i] = PokeBattle_Move.from_pokemon_move(@battle, Pokemon::Move.new(m.id)) @moves[i].pp = 5 @moves[i].total_pp = 5 end diff --git a/Data/Scripts/012_Battle/001_Battler/007_Battler_UseMove.rb b/Data/Scripts/012_Battle/001_Battler/007_Battler_UseMove.rb index 7d5ff4e4f..e99e32407 100644 --- a/Data/Scripts/012_Battle/001_Battler/007_Battler_UseMove.rb +++ b/Data/Scripts/012_Battle/001_Battler/007_Battler_UseMove.rb @@ -150,7 +150,7 @@ class PokeBattle_Battler if idxMove>=0 choice[2] = @moves[idxMove] else - choice[2] = PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(moveID)) # PokeBattle_Move object + choice[2] = PokeBattle_Move.from_pokemon_move(@battle, Pokemon::Move.new(moveID)) choice[2].pp = -1 end choice[3] = target # Target (-1 means no target yet) @@ -169,7 +169,7 @@ class PokeBattle_Battler pbBeginTurn(choice) # Force the use of certain moves if they're already being used if usingMultiTurnAttack? - choice[2] = PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(@currentMove)) + choice[2] = PokeBattle_Move.from_pokemon_move(@battle, Pokemon::Move.new(@currentMove)) specialUsage = true elsif @effects[PBEffects::Encore]>0 && choice[1]>=0 && @battle.pbCanShowCommands?(@index) diff --git a/Data/Scripts/012_Battle/002_Move/001_PokeBattle_Move.rb b/Data/Scripts/012_Battle/002_Move/001_PokeBattle_Move.rb index 65f0ff564..545a40a29 100644 --- a/Data/Scripts/012_Battle/002_Move/001_PokeBattle_Move.rb +++ b/Data/Scripts/012_Battle/002_Move/001_PokeBattle_Move.rb @@ -47,8 +47,8 @@ class PokeBattle_Move # This is the code actually used to generate a PokeBattle_Move object. The # object generated is a subclass of this one which depends on the move's # function code (found in the script section PokeBattle_MoveEffect). - def PokeBattle_Move.pbFromPBMove(battle, move) - validate move => PBMove + def PokeBattle_Move.from_pokemon_move(battle, move) + validate move => Pokemon::Move moveFunction = move.function_code || "000" className = sprintf("PokeBattle_Move_%s", moveFunction) if Object.const_defined?(className) diff --git a/Data/Scripts/012_Battle/002_Move/005_Move_Effects_000-07F.rb b/Data/Scripts/012_Battle/002_Move/005_Move_Effects_000-07F.rb index a3021f4d7..64c3a24d5 100644 --- a/Data/Scripts/012_Battle/002_Move/005_Move_Effects_000-07F.rb +++ b/Data/Scripts/012_Battle/002_Move/005_Move_Effects_000-07F.rb @@ -1720,8 +1720,8 @@ class PokeBattle_Move_05C < PokeBattle_Move def pbEffectAgainstTarget(user,target) user.eachMoveWithIndex do |m,i| next if m.id!=@id - newMove = PBMove.new(target.lastRegularMoveUsed) - user.moves[i] = PokeBattle_Move.pbFromPBMove(@battle,newMove) + newMove = Pokemon::Move.new(target.lastRegularMoveUsed) + user.moves[i] = PokeBattle_Move.from_pokemon_move(@battle,newMove) @battle.pbDisplay(_INTL("{1} learned {2}!",user.pbThis,newMove.name)) user.pbCheckFormOnMovesetChange break @@ -1770,9 +1770,9 @@ class PokeBattle_Move_05D < PokeBattle_Move def pbEffectAgainstTarget(user,target) user.eachMoveWithIndex do |m,i| next if m.id!=@id - newMove = PBMove.new(target.lastRegularMoveUsed) + newMove = Pokemon::Move.new(target.lastRegularMoveUsed) user.pokemon.moves[i] = newMove - user.moves[i] = PokeBattle_Move.pbFromPBMove(@battle,newMove) + user.moves[i] = PokeBattle_Move.from_pokemon_move(@battle,newMove) @battle.pbDisplay(_INTL("{1} learned {2}!",user.pbThis,newMove.name)) user.pbCheckFormOnMovesetChange break diff --git a/Data/Scripts/012_Battle/003_Battle/001_PokeBattle_BattleCommon.rb b/Data/Scripts/012_Battle/003_Battle/001_PokeBattle_BattleCommon.rb index 2e7f1f9cd..57806dba0 100644 --- a/Data/Scripts/012_Battle/003_Battle/001_PokeBattle_BattleCommon.rb +++ b/Data/Scripts/012_Battle/003_Battle/001_PokeBattle_BattleCommon.rb @@ -5,9 +5,9 @@ module PokeBattle_BattleCommon def pbStorePokemon(pkmn) # Nickname the Pokémon (unless it's a Shadow Pokémon) if !pkmn.shadowPokemon? - if pbDisplayConfirm(_INTL("Would you like to give a nickname to {1}?",pkmn.name)) - nickname = @scene.pbNameEntry(_INTL("{1}'s nickname?",pkmn.speciesName),pkmn) - pkmn.name = nickname if nickname!="" + if pbDisplayConfirm(_INTL("Would you like to give a nickname to {1}?", pkmn.name)) + nickname = @scene.pbNameEntry(_INTL("{1}'s nickname?", pkmn.speciesName), pkmn) + pkmn.name = nickname end end # Store the Pokémon diff --git a/Data/Scripts/012_Battle/003_Battle/002_PokeBattle_Battle.rb b/Data/Scripts/012_Battle/003_Battle/002_PokeBattle_Battle.rb index 79f09a5f5..fe6735ea3 100644 --- a/Data/Scripts/012_Battle/003_Battle/002_PokeBattle_Battle.rb +++ b/Data/Scripts/012_Battle/003_Battle/002_PokeBattle_Battle.rb @@ -161,9 +161,9 @@ class PokeBattle_Battle @runCommand = 0 @nextPickupUse = 0 if GameData::Move.exists?(:STRUGGLE) - @struggle = PokeBattle_Move.pbFromPBMove(self,PBMove.new(:STRUGGLE)) + @struggle = PokeBattle_Move.from_pokemon_move(self, Pokemon::Move.new(:STRUGGLE)) else - @struggle = PokeBattle_Struggle.new(self,nil) + @struggle = PokeBattle_Struggle.new(self, nil) end end diff --git a/Data/Scripts/012_Battle/003_Battle/003_Battle_StartAndEnd.rb b/Data/Scripts/012_Battle/003_Battle/003_Battle_StartAndEnd.rb index c22a3cc1d..cba8942e2 100644 --- a/Data/Scripts/012_Battle/003_Battle/003_Battle_StartAndEnd.rb +++ b/Data/Scripts/012_Battle/003_Battle/003_Battle_StartAndEnd.rb @@ -478,7 +478,7 @@ class PokeBattle_Battle pbParty(0).each_with_index do |pkmn,i| next if !pkmn @peer.pbOnLeavingBattle(self,pkmn,@usedInBattle[0][i],true) # Reset form - pkmn.setItem(@initialItems[0][i]) + pkmn.item = @initialItems[0][i] end return @decision end diff --git a/Data/Scripts/012_Battle/003_Battle/004_Battle_ExpAndMoveLearning.rb b/Data/Scripts/012_Battle/003_Battle/004_Battle_ExpAndMoveLearning.rb index dc90c1061..d5c6e5287 100644 --- a/Data/Scripts/012_Battle/003_Battle/004_Battle_ExpAndMoveLearning.rb +++ b/Data/Scripts/012_Battle/003_Battle/004_Battle_ExpAndMoveLearning.rb @@ -89,7 +89,7 @@ class PokeBattle_Battle def pbGainExpOne(idxParty,defeatedBattler,numPartic,expShare,expAll,showMessages=true) pkmn = pbParty(0)[idxParty] # The Pokémon gaining EVs from defeatedBattler - growthRate = pkmn.growthrate + growthRate = pkmn.growth_rate # Don't bother calculating if gainer is already at max Exp if pkmn.exp>=PBExperience.pbGetMaxExperience(growthRate) pkmn.calcStats # To ensure new EVs still have an effect @@ -100,7 +100,7 @@ class PokeBattle_Battle level = defeatedBattler.level # Main Exp calculation exp = 0 - a = level*defeatedBattler.pokemon.baseExp + a = level*defeatedBattler.pokemon.base_exp if expShare.length>0 && (isPartic || hasExpShare) if numPartic==0 # No participants, all Exp goes to Exp Share holders exp = a/(SPLIT_EXP_BETWEEN_GAINERS ? expShare.length : 1) @@ -227,8 +227,8 @@ class PokeBattle_Battle for i in 0...Pokemon::MAX_MOVES m = pkmn.moves[i] return if m && m.id==newMove # Already knows the new move - pkmn.moves[i] = PBMove.new(newMove) - battler.moves[i] = PokeBattle_Move.pbFromPBMove(self,pkmn.moves[i]) if battler + pkmn.moves[i] = Pokemon::Move.new(newMove) + battler.moves[i] = PokeBattle_Move.from_pokemon_move(self, pkmn.moves[i]) if battler pbDisplay(_INTL("{1} learned {2}!",pkmnName,moveName)) { pbSEPlay("Pkmn move learnt") } battler.pbCheckFormOnMovesetChange if battler return @@ -241,8 +241,8 @@ class PokeBattle_Battle forgetMove = @scene.pbForgetMove(pkmn,newMove) if forgetMove>=0 oldMoveName = pkmn.moves[forgetMove].name - pkmn.moves[forgetMove] = PBMove.new(newMove) # Replaces current/total PP - battler.moves[forgetMove] = PokeBattle_Move.pbFromPBMove(self,pkmn.moves[forgetMove]) if battler + pkmn.moves[forgetMove] = Pokemon::Move.new(newMove) # Replaces current/total PP + battler.moves[forgetMove] = PokeBattle_Move.from_pokemon_move(self, pkmn.moves[forgetMove]) if battler pbDisplayPaused(_INTL("1, 2, and... ... ... Ta-da!")) pbDisplayPaused(_INTL("{1} forgot how to use {2}. And...",pkmnName,oldMoveName)) pbDisplay(_INTL("{1} learned {2}!",pkmnName,moveName)) { pbSEPlay("Pkmn move learnt") } diff --git a/Data/Scripts/013_Overworld/006_PField_Battles.rb b/Data/Scripts/013_Overworld/006_PField_Battles.rb index 336eb1727..e96bcf977 100644 --- a/Data/Scripts/013_Overworld/006_PField_Battles.rb +++ b/Data/Scripts/013_Overworld/006_PField_Battles.rb @@ -686,17 +686,16 @@ def pbPickup(pkmn) chances.each_with_index do |c,i| cumul += c next if rnd>=cumul - pkmn.setItem(items[i]) + pkmn.item = items[i] break end end # Try to gain a Honey item after a battle if a Pokemon has the ability Honey Gather. def pbHoneyGather(pkmn) - return if pkmn.egg? || !pkmn.hasAbility?(:HONEYGATHER) - return if pkmn.hasItem? return if !GameData::Item.exists?(:HONEY) - chance = 5+((pkmn.level-1)/10)*5 - return unless rand(100) 0 new_nature = (new_natures.length == 1) ? new_natures[0] : new_natures[rand(new_natures.length)] - egg.setNature(new_nature) + egg.nature = new_nature end # Masuda method and Shiny Charm shinyretries = 0 @@ -327,12 +327,12 @@ def pbDayCareGenerateEgg if !ditto0 || !ditto1 parent = (ditto0) ? father : mother # The non-Ditto if parent.hasHiddenAbility? - egg.setAbility(parent.abilityIndex) if rand(100) < 60 + egg.ability_index = parent.ability_index if rand(100) < 60 elsif !ditto0 && !ditto1 if rand(100) < 80 - egg.setAbility(mother.abilityIndex) + egg.ability_index = mother.ability_index else - egg.setAbility((mother.abilityIndex + 1) % 2) + egg.ability_index = (mother.ability_index + 1) % 2 end end end @@ -390,7 +390,7 @@ Events.onStepTaken += proc { |_sender,_e| for i in 0...2 pkmn = $PokemonGlobal.daycare[i][0] next if !pkmn - maxexp = PBExperience.pbGetMaxExperience(pkmn.growthrate) + maxexp = PBExperience.pbGetMaxExperience(pkmn.growth_rate) next if pkmn.exp>=maxexp oldlevel = pkmn.level pkmn.exp += 1 # Gain Exp diff --git a/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb b/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb index 1bc08cb44..2a36c12fb 100644 --- a/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb +++ b/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb @@ -44,7 +44,7 @@ def pbNewTrainer(tr_type, tr_name, tr_version, save_changes = true) trainer = [tr_type, tr_name, [], party, tr_version] if save_changes trainer_hash = { - :id => GameData::Trainer::HASH.keys.length / 2, + :id => GameData::Trainer::DATA.keys.length / 2, :trainer_type => tr_type, :name => tr_name, :version => tr_version, diff --git a/Data/Scripts/015_Items/001_PItem_Items.rb b/Data/Scripts/015_Items/001_PItem_Items.rb index ff6335b76..1d1f39037 100644 --- a/Data/Scripts/015_Items/001_PItem_Items.rb +++ b/Data/Scripts/015_Items/001_PItem_Items.rb @@ -431,7 +431,7 @@ def pbLearnMove(pkmn,move,ignoreifknown=false,bymachine=false,&block) if forgetmove>=0 oldmovename = pkmn.moves[forgetmove].name oldmovepp = pkmn.moves[forgetmove].pp - pkmn.moves[forgetmove] = PBMove.new(move) # Replaces current/total PP + pkmn.moves[forgetmove] = Pokemon::Move.new(move) # Replaces current/total PP if bymachine && TAUGHT_MACHINES_KEEP_OLD_PP pkmn.moves[forgetmove].pp = [oldmovepp,pkmn.moves[forgetmove].total_pp].min end @@ -633,7 +633,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0) else if GameData::Item.get(item).is_mail? if pbWriteMail(item,pkmn,pkmnid,scene) - pkmn.setItem(item) + pkmn.item = item scene.pbDisplay(_INTL("Took the {1} from {2} and gave it the {3}.",olditemname,pkmn.name,newitemname)) return true else @@ -642,7 +642,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0) end end else - pkmn.setItem(item) + pkmn.item = item scene.pbDisplay(_INTL("Took the {1} from {2} and gave it the {3}.",olditemname,pkmn.name,newitemname)) return true end @@ -651,7 +651,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0) else if !GameData::Item.get(item).is_mail? || pbWriteMail(item,pkmn,pkmnid,scene) $PokemonBag.pbDeleteItem(item) - pkmn.setItem(item) + pkmn.item = item scene.pbDisplay(_INTL("{1} is now holding the {2}.",pkmn.name,newitemname)) return true end @@ -671,20 +671,20 @@ def pbTakeItemFromPokemon(pkmn,scene) scene.pbDisplay(_INTL("Your PC's Mailbox is full.")) else scene.pbDisplay(_INTL("The mail was saved in your PC.")) - pkmn.setItem(nil) + pkmn.item = nil ret = true end elsif scene.pbConfirm(_INTL("If the mail is removed, its message will be lost. OK?")) $PokemonBag.pbStoreItem(pkmn.item) scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name)) - pkmn.setItem(nil) + pkmn.item = nil pkmn.mail = nil ret = true end else $PokemonBag.pbStoreItem(pkmn.item) scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name)) - pkmn.setItem(nil) + pkmn.item = nil ret = true end return ret diff --git a/Data/Scripts/015_Items/002_PItem_ItemEffects.rb b/Data/Scripts/015_Items/002_PItem_ItemEffects.rb index c2e8dcb88..4a574df9f 100644 --- a/Data/Scripts/015_Items/002_PItem_ItemEffects.rb +++ b/Data/Scripts/015_Items/002_PItem_ItemEffects.rb @@ -1107,11 +1107,11 @@ ItemHandlers::UseOnPokemon.add(:ABILITYCAPSULE,proc { |item,pkmn,scene| scene.pbDisplay(_INTL("It won't have any effect.")) next false end - newabil = (pkmn.abilityIndex+1)%2 + newabil = (pkmn.ability_index + 1) % 2 newabilname = GameData::Ability.get((newabil==0) ? abil1 : abil2).name if scene.pbConfirm(_INTL("Would you like to change {1}'s Ability to {2}?", pkmn.name,newabilname)) - pkmn.setAbility(newabil) + pkmn.ability_index = newabil scene.pbRefresh scene.pbDisplay(_INTL("{1}'s Ability changed to {2}!",pkmn.name,newabilname)) next true diff --git a/Data/Scripts/015_Items/005_PItem_PokeRadar.rb b/Data/Scripts/015_Items/005_PItem_PokeRadar.rb index 7bf11e0d1..225fe553b 100644 --- a/Data/Scripts/015_Items/005_PItem_PokeRadar.rb +++ b/Data/Scripts/015_Items/005_PItem_PokeRadar.rb @@ -196,7 +196,7 @@ Events.onWildPokemonCreate += proc { |_sender,e| next if !grasses for grass in grasses next if $game_player.x!=grass[0] || $game_player.y!=grass[1] - pokemon.makeShiny if grass[3]==2 + pokemon.shiny = true if grass[3]==2 break end } diff --git a/Data/Scripts/015_Items/006_PItem_Mail.rb b/Data/Scripts/015_Items/006_PItem_Mail.rb index 7dd845ae8..6940b4fad 100644 --- a/Data/Scripts/015_Items/006_PItem_Mail.rb +++ b/Data/Scripts/015_Items/006_PItem_Mail.rb @@ -1,10 +1,9 @@ # Data structure representing mail that the Pokémon can hold -class PokemonMail - attr_accessor :item,:message,:sender,:poke1,:poke2,:poke3 +class Mail + attr_accessor :item, :message, :sender, :poke1, :poke2, :poke3 def initialize(item, message, sender, poke1 = nil, poke2 = nil, poke3 = nil) - item = item.id if !item.is_a?(Symbol) && item.respond_to?("id") - @item = item # Item represented by this mail + @item = GameData::Item.get(item).id # Item represented by this mail @message = message # Message text @sender = sender # Name of the message's sender @poke1 = poke1 # [species,gender,shininess,form,shadowness,is egg] @@ -15,6 +14,17 @@ end +# @deprecated Use {Mail} instead. PokemonMail is slated to be removed in v20. +class PokemonMail + attr_reader :item, :message, :sender, :poke1, :poke2, :poke3 + + def self.copy(mail) + return Mail.new(mail.item, item.message, item.sender, item.poke1, item.poke2, item.poke3) + end +end + + + def pbMoveToMailbox(pokemon) $PokemonGlobal.mailbox = [] if !$PokemonGlobal.mailbox return false if $PokemonGlobal.mailbox.length>=10 @@ -26,7 +36,7 @@ end def pbStoreMail(pkmn,item,message,poke1=nil,poke2=nil,poke3=nil) raise _INTL("Pokémon already has mail") if pkmn.mail - pkmn.mail = PokemonMail.new(item,message,$Trainer.name,poke1,poke2,poke3) + pkmn.mail = Mail.new(item,message, $Trainer.name, poke1, poke2, poke3) end def pbDisplayMail(mail,_bearer=nil) @@ -102,15 +112,15 @@ def pbWriteMail(item,pkmn,pkmnid,scene) poke1 = poke2 = nil if $Trainer.party[pkmnid+2] p = $Trainer.party[pkmnid+2] - poke1 = [p.species,p.gender,p.shiny?,(p.form rescue 0),p.shadowPokemon?] + poke1 = [p.species,p.gender,p.shiny?,p.form,p.shadowPokemon?] poke1.push(true) if p.egg? end if $Trainer.party[pkmnid+1] p = $Trainer.party[pkmnid+1] - poke2 = [p.species,p.gender,p.shiny?,(p.form rescue 0),p.shadowPokemon?] + poke2 = [p.species,p.gender,p.shiny?,p.form,p.shadowPokemon?] poke2.push(true) if p.egg? end - poke3 = [pkmn.species,pkmn.gender,pkmn.shiny?,(pkmn.form rescue 0),pkmn.shadowPokemon?] + poke3 = [pkmn.species,pkmn.gender,pkmn.shiny?,pkmn.form,pkmn.shadowPokemon?] poke3.push(true) if pkmn.egg? pbStoreMail(pkmn,item,message,poke1,poke2,poke3) return true diff --git a/Data/Scripts/016_Pokemon/001_Pokemon.rb b/Data/Scripts/016_Pokemon/001_Pokemon.rb index b5c740977..8a0866353 100644 --- a/Data/Scripts/016_Pokemon/001_Pokemon.rb +++ b/Data/Scripts/016_Pokemon/001_Pokemon.rb @@ -3,104 +3,86 @@ # The player's party Pokémon are stored in the array $Trainer.party. #=============================================================================== class Pokemon - # @return [String] the nickname of this Pokémon - attr_accessor :name # @return [Integer] this Pokémon's national Pokédex number attr_reader :species - # If defined, is the time (in Integer form) when this Pokémon's form was set. - # @return [Integer, nil] the time this Pokémon's form was set - attr_accessor :formTime # If defined, this Pokémon's form will be this value even if a MultipleForms # handler tries to say otherwise. # @return [Integer, nil] this Pokémon's form attr_accessor :forcedForm + # If defined, is the time (in Integer form) when this Pokémon's form was set. + # @return [Integer, nil] the time this Pokémon's form was set + attr_accessor :formTime # @return [Integer] the current experience points attr_reader :exp + # @return [Integer] the number of steps until this Pokémon hatches, 0 if this Pokémon is not an egg + attr_accessor :eggsteps # @return [Integer] the current HP attr_reader :hp - # @return [Integer] the current Total HP - attr_reader :totalhp - # @return [Integer] the current Attack stat - attr_reader :attack - # @return [Integer] the current Defense stat - attr_reader :defense - # @return [Integer] the current Special Attack stat - attr_reader :spatk - # @return [Integer] the current Special Defense stat - attr_reader :spdef - # @return [Integer] the current Speed stat - attr_reader :speed - # If defined, forces the Pokémon's ability to be the first natural (0), - # second natural (1) or a hidden (2-5) ability available to its species. - # It is not possible to give the Pokémon any ability other than those - # defined in the PBS file "pokemon.txt" for its species - # (or "pokemonforms.txt" for its species and form). - # @return [0, 1, 2, 3, 4, 5, nil] forced ability index (nil if none is set) - attr_accessor :abilityflag - # If defined, forces this Pokémon to be male (0) or female (1). - # @return [0, 1, nil] gender to force: male (0) or female (1) (nil if undefined) - attr_accessor :genderflag - # If defined, forces this Pokémon to have a particular nature. - # @return [Integer, nil] ID of the nature to force (nil if undefined) - attr_accessor :natureflag - # If defined, overrides this Pokémon's nature's stat-changing effects. - # @return [Integer, nil] overridden nature stat-changing effects (nil if undefined) - attr_accessor :natureOverride - # If defined, forces the Pokémon to be shiny (true) or not (false). - # @return [Boolean, nil] whether shininess should be forced (nil if undefined) - attr_accessor :shinyflag - # @return [Array] the moves known by this Pokémon - attr_accessor :moves - # @return [Array] the IDs of moves known by this Pokémon when it was obtained - attr_accessor :firstmoves - # @return [Symbol] the ID of the item held by this Pokémon (nil = no held item) - attr_accessor :item_id # @return [Integer] this Pokémon's current status (from PBStatuses) attr_reader :status # @return [Integer] sleep count / toxic flag / 0: # sleep (number of rounds before waking up), toxic (0 = regular poison, 1 = toxic) attr_accessor :statusCount - # Another Pokémon which has been fused with this Pokémon (or nil if there is none). - # Currently only used by Kyurem, to record a fused Reshiram or Zekrom. - # @return [Pokemon, nil] the Pokémon fused into this one (nil if there is none) - attr_accessor :fused - # @return [Array] an array of IV values for HP, Atk, Def, Speed, Sp. Atk and Sp. Def - attr_accessor :iv - # @param value [Array] an array of booleans that max each IV value - attr_writer :ivMaxed - # @return [Array] this Pokémon's effort values - attr_accessor :ev + # This Pokémon's shininess (true, false, nil). Is recalculated if made nil. + # @param value [Boolean, nil] whether this Pokémon is shiny + attr_writer :shiny + # The index of this Pokémon's ability (0, 1 are natural abilities, 2+ are + # hidden abilities)as defined for its species/form. An ability may not be + # defined at this index. Is recalculated (as 0 or 1) if made nil. + # @param value [Integer, nil] forced ability index (nil if none is set) + attr_writer :ability_index + # If defined, this Pokémon's nature is considered to be this when calculating stats. + # @param value [Integer, nil] ID of the nature to use for calculating stats + attr_writer :nature_for_stats + # @return [Array] the moves known by this Pokémon + attr_accessor :moves + # @return [Array] the IDs of moves known by this Pokémon when it was obtained + attr_accessor :firstmoves + # @return [Array] an array of ribbons owned by this Pokémon + attr_accessor :ribbons + # @return [Integer] contest stats + attr_accessor :cool, :beauty, :cute, :smart, :tough, :sheen + # @return [Integer] the Pokérus strain and infection time + attr_accessor :pokerus # @return [Integer] this Pokémon's current happiness (an integer between 0 and 255) attr_accessor :happiness # @return [Integer] the type of ball used (refer to {$BallTypes} for valid types) attr_accessor :ballused - # @return [Integer] the number of steps until this Pokémon hatches, 0 if this Pokémon is not an egg - attr_accessor :eggsteps - # @param value [Integer] new markings for this Pokémon - attr_writer :markings - # @return [Array] an array of ribbons owned by this Pokémon - attr_accessor :ribbons - # @return [Integer] the Pokérus strain and infection time - attr_accessor :pokerus - # @return [Integer] this Pokémon's personal ID - attr_accessor :personalID + # @return [Integer] this Pokémon's markings, one bit per marking + attr_accessor :markings + # @return [Array] an array of IV values for HP, Atk, Def, Speed, Sp. Atk and Sp. Def + attr_accessor :iv + # An array of booleans indicating whether a stat is made to have maximum IVs + # (for Hyper Training). Set like @ivMaxed[PBStats::ATTACK] = true + # @return [Array] an array of booleans that max each IV value + attr_accessor :ivMaxed + # @return [Array] this Pokémon's effort values + attr_accessor :ev + # @return [Integer] calculated stats + attr_reader :totalhp, :attack, :defense, :spatk, :spdef, :speed + # @return [Owner] this Pokémon's owner + attr_reader :owner # @return [Integer] the manner this Pokémon was obtained: # 0 (met), 1 (as egg), 2 (traded), 4 (fateful encounter) - attr_accessor :obtainMode + attr_accessor :obtain_method # @return [Integer] the ID of the map this Pokémon was obtained in attr_accessor :obtainMap # Describes the manner this Pokémon was obtained. If left undefined, # the obtain map's name is used. # @return [String] the obtain text attr_accessor :obtainText - # @param value [Integer] new obtain level - attr_writer :obtainLevel + # @return [Integer] the level of this Pokémon when it was obtained + attr_accessor :obtainLevel # If this Pokémon hatched from an egg, returns the map ID where the hatching happened. # Otherwise returns 0. # @return [Integer] the map ID where egg was hatched (0 by default) attr_accessor :hatchedMap - # @param value [Integer] new contest stat - attr_writer :cool,:beauty,:cute,:smart,:tough,:sheen + # Another Pokémon which has been fused with this Pokémon (or nil if there is none). + # Currently only used by Kyurem, to record a fused Reshiram or Zekrom. + # @return [Pokemon, nil] the Pokémon fused into this one (nil if there is none) + attr_accessor :fused + # @return [Integer] this Pokémon's personal ID + attr_accessor :personalID # Max total IVs IV_STAT_LIMIT = 31 @@ -113,58 +95,63 @@ class Pokemon # Maximum number of moves a Pokémon can know at once MAX_MOVES = 4 + def species_data + return GameData::Species.get_species_form(@species, formSimple) + end + #============================================================================= - # Ownership, obtained information + # Species and form #============================================================================= - # @return [Owner] this Pokémon's owner - def owner - return @owner + # Changes the Pokémon's species and re-calculates its statistics. + # @param species_id [Integer] id of the species to change this Pokémon to + def species=(species_id) + new_species_data = GameData::Species.get(species_id) + return if @species == new_species_data.species + @species = new_species_data.species + @form = new_species_data.form if new_species_data.form != 0 + @forcedForm = nil + @level = nil # In case growth rate is different for the new species + @ability = nil + calcStats end - # Changes this Pokémon's owner. - # @param new_owner [Owner] the owner to change to - def owner=(new_owner) - validate new_owner => Owner - @owner = new_owner + # @param check_species [Integer, Symbol, String] id of the species to check for + # @return [Boolean] whether this Pokémon is of the specified species + def isSpecies?(check_species) + return @species == check_species || (GameData::Species.exists?(check_species) && + @species == GameData::Species.get(check_species).species) end - # @param trainer [PokeBattle_Trainer] the trainer to compare to the OT - # @return [Boolean] whether the given trainer and this Pokémon's original trainer don't match - def foreign?(trainer) - return @owner.id != trainer.id || @owner.name != trainer.name - end - alias isForeign? foreign? - - # @return [Integer] this Pokémon's level when it was obtained - def obtainLevel - return @obtainLevel || 0 + def form + return @forcedForm if !@forcedForm.nil? + return @form if $game_temp.in_battle + calc_form = MultipleForms.call("getForm", self) + self.form = calc_form if calc_form != nil && calc_form != @form + return @form end - # @return [Time] the time when this Pokémon was obtained - def timeReceived - return @timeReceived ? Time.at(@timeReceived) : Time.gm(2000) + def formSimple + return @forcedForm || @form end - # Sets the time when this Pokémon was obtained. - # @param value [Integer, Time, #to_i] time in seconds since Unix epoch - def timeReceived=(value) - @timeReceived = value.to_i + def form=(value) + oldForm = @form + @form = value + @ability = nil + yield if block_given? + MultipleForms.call("onSetForm", self, value, oldForm) + calcStats + pbSeenForm(self) end - # @return [Time] the time when this Pokémon hatched - def timeEggHatched - if obtainMode == 1 - return @timeEggHatched ? Time.at(@timeEggHatched) : Time.gm(2000) - else - return Time.gm(2000) - end + def setForm(value) + self.form = value end - # Sets the time when this Pokémon hatched. - # @param value [Integer, Time, #to_i] time in seconds since Unix epoch - def timeEggHatched=(value) - @timeEggHatched = value.to_i + def formSimple=(value) + @form = value + calcStats end #============================================================================= @@ -173,7 +160,7 @@ class Pokemon # @return [Integer] this Pokémon's level def level - @level = PBExperience.pbGetLevelFromExperience(@exp, self.growthrate) if !@level + @level = PBExperience.pbGetLevelFromExperience(@exp, growth_rate) if !@level return @level end @@ -184,8 +171,8 @@ class Pokemon if value < 1 || value > PBExperience.maxLevel raise ArgumentError.new(_INTL("The level number ({1}) is invalid.", value)) end + @exp = PBExperience.pbGetStartExperience(value, growth_rate) @level = value - self.exp = PBExperience.pbGetStartExperience(value, self.growthrate) end # Sets this Pokémon's Exp. Points. @@ -202,12 +189,12 @@ class Pokemon alias isEgg? egg? # @return [Integer] this Pokémon's growth rate (from PBGrowthRates) - def growthrate + def growth_rate return species_data.growth_rate end # @return [Integer] this Pokémon's base Experience value - def baseExp + def base_exp return species_data.base_exp end @@ -216,531 +203,23 @@ class Pokemon def expFraction lvl = self.level return 0.0 if lvl >= PBExperience.maxLevel - growth_rate = self.growthrate - start_exp = PBExperience.pbGetStartExperience(lvl, growth_rate) - end_exp = PBExperience.pbGetStartExperience(lvl + 1, growth_rate) - return 1.0 * (@exp - start_exp) / (end_exp - start_exp) - end - - #============================================================================= - # Gender - #============================================================================= - - # @return [0, 1, 2] this Pokémon's gender (0 = male, 1 = female, 2 = genderless) - def gender - gender_rate = species_data.gender_rate - # Return sole gender option for all male/all female/genderless species - case gender_rate - when PBGenderRates::AlwaysMale then return 0 - when PBGenderRates::AlwaysFemale then return 1 - when PBGenderRates::Genderless then return 2 - end - # Return gender for species that can be male or female - return @genderflag if @genderflag && (@genderflag == 0 || @genderflag == 1) - return ((@personalID & 0xFF) < PBGenderRates.genderByte(gender_rate)) ? 1 : 0 - end - - # @return [Boolean] whether this Pokémon species is restricted to only ever being one - # gender (or genderless) - def singleGendered? - gender_rate = species_data.gender_rate - return gender_rate == PBGenderRates::AlwaysMale || - gender_rate == PBGenderRates::AlwaysFemale || - gender_rate == PBGenderRates::Genderless - end - alias isSingleGendered? singleGendered? - - # @return [Boolean] whether this Pokémon is male - def male? - return self.gender == 0 - end - alias isMale? male? - - # @return [Boolean] whether this Pokémon is female - def female? - return self.gender == 1 - end - alias isFemale? female? - - # @return [Boolean] whether this Pokémon is genderless - def genderless? - return self.gender == 2 - end - alias isGenderless? genderless? - - # Sets this Pokémon's gender to a particular gender (if possible). - # @param value [0, 1, 2] new gender (0 = male, 1 = female, 2 = genderless) - def setGender(value) - @genderflag = value if !singleGendered? - end - - # Makes this Pokémon male. - def makeMale; setGender(0); end - # Makes this Pokémon female. - def makeFemale; setGender(1); end - - #============================================================================= - # Shininess - #============================================================================= - - # @return [Boolean] whether this Pokémon is shiny (differently colored) - def shiny? - return @shinyflag if @shinyflag != nil - a = @personalID ^ @owner.id - b = a & 0xFFFF - c = (a >> 16) & 0xFFFF - d = b ^ c - return d < SHINY_POKEMON_CHANCE - end - alias isShiny? shiny? - - # Makes this Pokémon shiny. - def makeShiny - @shinyflag = true - end - - # Makes this Pokémon not shiny. - def makeNotShiny - @shinyflag = false - end - - #============================================================================= - # Types - #============================================================================= - - # @return [Integer] this Pokémon's first type - def type1 - return species_data.type1 - end - - # @return [Integer] this Pokémon's second type, or the first type if none is defined - def type2 - sp_data = species_data - return sp_data.type2 || sp_data.type1 - end - - # @return [Array] an array of this Pokémon's types - def types - sp_data = species_data - ret = [sp_data.type1] - ret.push(sp_data.type2) if sp_data.type2 && sp_data.type2 != sp_data.type1 - return ret - end - - # @param type [Integer, Symbol, String] type to check - # @return [Boolean] whether this Pokémon has the specified type - def hasType?(type) - type = GameData::Type.get(type).id - return self.types.include?(type) - end - - #============================================================================= - # Ability - #============================================================================= - - # @return [Integer] the index of this Pokémon's ability - def abilityIndex - return @abilityflag || (@personalID & 1) - end - - # @return [GameData::Ability, nil] an Ability object corresponding to this Pokémon's ability - def ability - ret = ability_id - return GameData::Ability.try_get(ret) - end - - # @return [Symbol, nil] the ability symbol of this Pokémon's ability - def ability_id - sp_data = species_data - abil_index = abilityIndex - # Hidden ability - if abil_index >= 2 - ret = sp_data.hidden_abilities[abil_index - 2] - return ret if ret - abil_index = (@personalID & 1) - end - # Natural ability - ret = sp_data.abilities[abil_index] - return ret || sp_data.abilities[0] - end - - # Returns whether this Pokémon has a particular ability. If no value - # is given, returns whether this Pokémon has an ability set. - # @param check_ability [Symbol, GameData::Ability, Integer] ability ID to check - # @return [Boolean] whether this Pokémon has a particular ability or - # an ability at all - def hasAbility?(check_ability = nil) - current_ability = self.ability - return !current_ability.nil? if check_ability.nil? - return current_ability == check_ability - end - - # Sets this Pokémon's ability index. - # @param value [Integer] new ability index - def setAbility(value) - @abilityflag = value - end - - # @return [Boolean] whether this Pokémon has a hidden ability - def hasHiddenAbility? - abil = abilityIndex - return abil >= 2 - end - - # @return [Array>] the abilities this Pokémon can have, - # where every element is [ability ID, ability index] - def getAbilityList - ret = [] - sp_data = species_data - sp_data.abilities.each_with_index { |a, i| ret.push([a, i]) if a } - sp_data.hidden_abilities.each_with_index { |a, i| ret.push([a, i + 2]) if a } - return ret - end - - #============================================================================= - # Moves - #============================================================================= - - # @return [Integer] the number of moves known by the Pokémon - def numMoves - return @moves.length - end - - # @param move_id [Integer, Symbol, String] ID of the move to check - # @return [Boolean] whether the Pokémon knows the given move - def hasMove?(move_id) - move_data = GameData::Move.try_get(move_id) - return false if !move_data - return @moves.any? { |m| m.id == move_data.id } - end - alias knowsMove? hasMove? - - # Returns the list of moves this Pokémon can learn by levelling up. - # @return [Array>] this Pokémon's move list, where every element is [level, move ID] - def getMoveList - return species_data.moves - end - - # Sets this Pokémon's movelist to the default movelist it originally had. - def resetMoves - this_level = self.level - # Find all level-up moves that self could have learned - moveset = self.getMoveList - knowable_moves = [] - moveset.each { |m| knowable_moves.push(m[1]) if m[0] <= this_level } - # Remove duplicates (retaining the latest copy of each move) - knowable_moves = knowable_moves.reverse - knowable_moves |= [] - knowable_moves = knowable_moves.reverse - # Add all moves - @moves.clear - first_move_index = knowable_moves.length - MAX_MOVES - first_move_index = 0 if first_move_index < 0 - for i in first_move_index...knowable_moves.length - @moves.push(PBMove.new(knowable_moves[i])) - end - end - - # Silently learns the given move. Will erase the first known move if it has to. - # @param move_id [Integer, Symbol, String] ID of the move to learn - def pbLearnMove(move_id) - move_data = GameData::Move.try_get(move_id) - return if !move_data - # Check if self already knows the move; if so, move it to the end of the array - @moves.each_with_index do |m, i| - next if m.id != move_data.id - @moves.push(m) - @moves.delete_at(i) - return - end - # Move is not already known; learn it - @moves.push(PBMove.new(move_data.id)) - # Delete the first known move if self now knows more moves than it should - @moves.shift if numMoves > MAX_MOVES - end - - # Deletes the given move from the Pokémon. - # @param move_id [Integer, Symbol, String] ID of the move to delete - def pbDeleteMove(move_id) - move_data = GameData::Move.try_get(move_id) - return if !move_data - @moves.delete_if { |m| m.id == move_data.id } - end - - # Deletes the move at the given index from the Pokémon. - # @param index [Integer] index of the move to be deleted - def pbDeleteMoveAtIndex(index) - @moves.delete_at(index) - end - - # Deletes all moves from the Pokémon. - def pbDeleteAllMoves - @moves = [] - end - - # Copies currently known moves into a separate array, for Move Relearner. - def pbRecordFirstMoves - @firstmoves = [] - @moves.each { |m| @firstmoves.push(m.id) } - end - - # Adds a move to this Pokémon's first moves. - # @param move_id [Integer, Symbol, String] ID of the move to add - def pbAddFirstMove(move_id) - move_data = GameData::Move.try_get(move_id) - @firstmoves.push(move_data.id) if move_data && !@firstmoves.include?(move_data.id) - end - - # Removes a move from this Pokémon's first moves. - # @param move_id [Integer, Symbol, String] ID of the move to remove - def pbRemoveFirstMove(move_id) - move_data = GameData::Move.try_get(move_id) - @firstmoves.delete(move_data.id) if move_data - end - - # Clears this Pokémon's first moves. - def pbClearFirstMoves - @firstmoves = [] - end - - # @param move_id [Integer, Symbol, String] ID of the move to check - # @return [Boolean] whether the Pokémon is compatible with the given move - def compatibleWithMove?(move_id) - move_data = GameData::Move.try_get(move_id) - return move_data && species_data.tutor_moves.include?(move_data.id) - end - - #============================================================================= - # Items - #============================================================================= - - # @return [GameData::Item, nil] an Item object corresponding to this Pokémon's item - def item - ret = @item_id - return GameData::Item.try_get(ret) - end - - # Returns whether this Pokémon is holding an item. If an item id is passed, - # returns whether the Pokémon is holding that item. - # @param check_item [Symbol, GameData::Item, Integer] item ID to check - # @return [Boolean] whether the Pokémon is holding the specified item or - # an item at all - def hasItem?(check_item = nil) - current_item = self.item - return !current_item.nil? if check_item.nil? - return current_item == check_item - end - - # Gives an item to this Pokémon. Passing 0 as the argument removes the held item. - # @param value [Symbol, GameData::Item, Integer] id of the item to give to this - # Pokémon (a non-valid value sets it to nil) - def setItem(value) - new_item = GameData::Item.try_get(value) - @item_id = (new_item) ? new_item.id : nil - end - - # @return [Array] the items this species can be found holding in the wild - def wildHoldItems - sp_data = species_data - return [sp_data.wild_item_common, sp_data.wild_item_uncommon, sp_data.wild_item_rare] - end - - # @return [PokemonMail, nil] mail held by this Pokémon (nil if there is none) - def mail - return nil if !@mail - @mail = nil if !@mail.item || !hasItem?(@mail.item) - return @mail - end - - # If mail is a PokemonMail object, gives that mail to this Pokémon. If nil is given, - # removes the held mail. - # @param mail [PokemonMail, nil] mail to be held by this Pokémon (nil if mail is to be removed) - def mail=(mail) - if !mail.nil? && !mail.is_a?(PokemonMail) - raise ArgumentError, _INTL('Invalid value {1} given', mail.inspect) - end - @mail = mail - end - - #============================================================================= - # Nature - #============================================================================= - - # @return [Integer] the ID of this Pokémon's nature - def nature - return @natureflag || (@personalID % 25) - end - - # Returns the calculated nature, taking into account things that change its - # stat-altering effect (i.e. Gen 8 mints). Only used for calculating stats. - # @return [Integer] this Pokémon's calculated nature - def calcNature - return @natureOverride if @natureOverride - return self.nature - end - - # Returns whether this Pokémon has a particular nature. If no value - # is given, returns whether this Pokémon has a nature set. - # @param nature [Integer] nature ID to check - # @return [Boolean] whether this Pokémon has a particular nature or - # a nature at all - def hasNature?(nature = -1) - current_nature = self.nature - return current_nature >= 0 if nature < 0 - return current_nature == getID(PBNatures, nature) - end - - # Sets this Pokémon's nature to a particular nature. - # @param value [Integer, String, Symbol] nature to change to - def setNature(value) - @natureflag = getID(PBNatures, value) - calcStats - end - - #============================================================================= - # Pokérus - #============================================================================= - - # @return [Integer] the Pokérus infection stage for this Pokémon - def pokerusStrain - return @pokerus / 16 - end - - # Returns the Pokérus infection stage for this Pokémon. The possible stages are - # 0 (not infected), 1 (infected) and 2 (cured) - # @return [0, 1, 2] current Pokérus infection stage - def pokerusStage - return 0 if !@pokerus || @pokerus == 0 - return 2 if @pokerus > 0 && (@pokerus % 16) == 0 - return 1 - end - - # Gives this Pokémon Pokérus (either the specified strain or a random one). - # @param strain [Integer] Pokérus strain to give - def givePokerus(strain = 0) - return if self.pokerusStage == 2 # Can't re-infect a cured Pokémon - strain = 1 + rand(15) if strain <= 0 || strain >= 16 - time = 1 + (strain % 4) - @pokerus = time - @pokerus |= strain << 4 - end - - # Resets the infection time for this Pokémon's Pokérus (even if cured). - def resetPokerusTime - return if @pokerus == 0 - strain = @pokerus % 16 - time = 1 + (strain % 4) - @pokerus = time - @pokerus |= strain << 4 - end - - # Reduces the time remaining for this Pokémon's Pokérus (if infected). - def lowerPokerusCount - return if self.pokerusStage != 1 - @pokerus -= 1 - end - - #============================================================================= - # Contest attributes, ribbons - #============================================================================= - - # @return [Integer] this Pokémon's cool contest attribute - def cool - return @cool || 0 - end - - # @return [Integer] this Pokémon's beauty contest attribute - def beauty - return @beauty || 0 - end - - # @return [Integer] this Pokémon's cute contest attribute - def cute - return @cute || 0 - end - - # @return [Integer] this Pokémon's smart contest attribute - def smart - return @smart || 0 - end - - # @return [Integer] this Pokémon's tough contest attribute - def tough - return @tough || 0 - end - - # @return [Integer] this Pokémon's sheen contest attribute - def sheen - return @sheen || 0 - end - - # @return [Integer] the number of ribbons this Pokémon has - def ribbonCount - return (@ribbons) ? @ribbons.length : 0 - end - - # @param ribbon [Integer, Symbol, String] ribbon ID to check - # @return [Boolean] whether this Pokémon has the specified ribbon - def hasRibbon?(ribbon) - return false if !@ribbons - ribbon = getID(PBRibbons, ribbon) - return false if ribbon == 0 - return @ribbons.include?(ribbon) - end - - # Gives a ribbon to this Pokémon. - # @param ribbon [Integer, Symbol, String] ID of the ribbon to give - def giveRibbon(ribbon) - @ribbons = [] if !@ribbons - ribbon = getID(PBRibbons, ribbon) - return if ribbon == 0 - @ribbons.push(ribbon) if !@ribbons.include?(ribbon) - end - - # Replaces one ribbon with the next one along, if possible. - def upgradeRibbon(*arg) - @ribbons = [] if !@ribbons - for i in 0...arg.length - 1 - for j in 0...@ribbons.length - thisribbon = (arg[i].is_a?(Integer)) ? arg[i] : getID(PBRibbons, arg[i]) - if @ribbons[j] == thisribbon - nextribbon = (arg[i+1].is_a?(Integer)) ? arg[i+1] : getID(PBRibbons, arg[i+1]) - @ribbons[j] = nextribbon - return nextribbon - end - end - end - if !hasRibbon?(arg[arg.length - 1]) - firstribbon = (arg[0].is_a?(Integer)) ? arg[0] : getID(PBRibbons, arg[0]) - giveRibbon(firstribbon) - return firstribbon - end - return 0 - end - - # Removes the specified ribbon from this Pokémon. - # @param ribbon [Integer, Symbol, String] id of the ribbon to remove - def takeRibbon(ribbon) - return if !@ribbons - ribbon = getID(PBRibbons, ribbon) - return if ribbon == 0 - for i in 0...@ribbons.length - next if @ribbons[i] != ribbon - @ribbons[i] = nil - break - end - @ribbons.compact! - end - - # Removes all ribbons from this Pokémon. - def clearAllRibbons - @ribbons = [] + g_rate = growth_rate + start_exp = PBExperience.pbGetStartExperience(lvl, g_rate) + end_exp = PBExperience.pbGetStartExperience(lvl + 1, g_rate) + return (@exp - start_exp).to_f / (end_exp - start_exp) end #============================================================================= # Status #============================================================================= + # Sets the Pokémon's health. + # @param value [Integer] new HP value + def hp=(value) + @hp = value.clamp(0, @totalhp) + healStatus if @hp == 0 + end + # Sets this Pokémon's status. See {PBStatuses} for all possible status effects. # @param value [Integer, Symbol, String] status to set (from {PBStatuses}) def status=(value) @@ -798,81 +277,533 @@ class Pokemon end #============================================================================= - # Species and form + # Types #============================================================================= - # Changes the Pokémon's species and re-calculates its statistics. - # @param species_id [Integer] id of the species to change this Pokémon to - def species=(species_id) - new_species_data = GameData::Species.get(species_id) - return if @species == new_species_data.species - has_nickname = nicknamed? - @species = new_species_data.species - @form = new_species_data.form if new_species_data.form != 0 - @name = speciesName unless has_nickname - @level = nil # In case growth rate is different for the new species - @forcedForm = nil - calcStats + # @return [Integer] this Pokémon's first type + def type1 + return species_data.type1 end - # @param check_species [Integer, Symbol, String] id of the species to check for - # @return [Boolean] whether this Pokémon is of the specified species - def isSpecies?(check_species) - return @species == check_species || (GameData::Species.exists?(check_species) && - @species == GameData::Species.get(check_species).species) + # @return [Integer] this Pokémon's second type, or the first type if none is defined + def type2 + sp_data = species_data + return sp_data.type2 || sp_data.type1 end - def form - return @forcedForm if !@forcedForm.nil? - return @form if $game_temp.in_battle - v = MultipleForms.call("getForm", self) - self.form = v if v != nil && (!@form || v != @form) - return @form + # @return [Array] an array of this Pokémon's types + def types + sp_data = species_data + ret = [sp_data.type1] + ret.push(sp_data.type2) if sp_data.type2 && sp_data.type2 != sp_data.type1 + return ret end - def formSimple - return @forcedForm || @form + # @param type [Integer, Symbol, String] type to check + # @return [Boolean] whether this Pokémon has the specified type + def hasType?(type) + type = GameData::Type.get(type).id + return self.types.include?(type) end - def form=(value) - oldForm = @form - @form = value - yield if block_given? - MultipleForms.call("onSetForm", self, value, oldForm) - calcStats - pbSeenForm(self) + #============================================================================= + # Gender + #============================================================================= + + # @return [0, 1, 2] this Pokémon's gender (0 = male, 1 = female, 2 = genderless) + def gender + if !@gender + gender_rate = species_data.gender_rate + case gender_rate + when PBGenderRates::AlwaysMale then @gender = 0 + when PBGenderRates::AlwaysFemale then @gender = 1 + when PBGenderRates::Genderless then @gender = 2 + else + @gender = ((@personalID & 0xFF) < PBGenderRates.genderByte(gender_rate)) ? 1 : 0 + end + end + return @gender end - def setForm(value) - self.form = value + # Sets this Pokémon's gender to a particular gender (if possible). + # @param value [0, 1] new gender (0 = male, 1 = female) + def gender=(value) + return if singleGendered? + @gender = value if value.nil? || value == 0 || value == 1 end - def formSimple=(value) - @form = value - calcStats + # Makes this Pokémon male. + def makeMale; self.gender = 0; end + + # Makes this Pokémon female. + def makeFemale; self.gender = 1; end + + # @return [Boolean] whether this Pokémon is male + def male?; return self.gender == 0; end + alias isMale? male? + + # @return [Boolean] whether this Pokémon is female + def female?; return self.gender == 1; end + alias isFemale? female? + + # @return [Boolean] whether this Pokémon is genderless + def genderless?; return self.gender == 2; end + alias isGenderless? genderless? + + # @return [Boolean] whether this Pokémon species is restricted to only ever being one + # gender (or genderless) + def singleGendered? + gender_rate = species_data.gender_rate + return [PBGenderRates::AlwaysMale, PBGenderRates::AlwaysFemale, + PBGenderRates::Genderless].include?(gender_rate) + end + alias isSingleGendered? singleGendered? + + #============================================================================= + # Shininess + #============================================================================= + + # @return [Boolean] whether this Pokémon is shiny (differently colored) + def shiny? + if @shiny.nil? + a = @personalID ^ @owner.id + b = a & 0xFFFF + c = (a >> 16) & 0xFFFF + d = b ^ c + @shiny = d < SHINY_POKEMON_CHANCE + end + return @shiny + end + alias isShiny? shiny? + + #============================================================================= + # Ability + #============================================================================= + + # @return [Integer] the index of this Pokémon's ability + def ability_index + @ability_index = (@personalID & 1) if !@ability_index + return @ability_index end - def species_data - return GameData::Species.get_species_form(@species, formSimple) + # @return [GameData::Ability, nil] an Ability object corresponding to this Pokémon's ability + def ability + return GameData::Ability.try_get(ability_id) + end + + # @return [Symbol, nil] the ability symbol of this Pokémon's ability + def ability_id + if !@ability + sp_data = species_data + abil_index = ability_index + if abil_index >= 2 # Hidden ability + @ability = sp_data.hidden_abilities[abil_index - 2] + abil_index = (@personalID & 1) if !@ability + end + if !@ability # Natural ability or no hidden ability defined + @ability = sp_data.abilities[abil_index] || sp_data.abilities[0] + end + end + return @ability + end + + def ability=(value) + return if value && !GameData::Ability.exists?(value) + @ability = (value) ? GameData::Ability.get(value).id : value + end + + # Returns whether this Pokémon has a particular ability. If no value + # is given, returns whether this Pokémon has an ability set. + # @param check_ability [Symbol, GameData::Ability, Integer] ability ID to check + # @return [Boolean] whether this Pokémon has a particular ability or + # an ability at all + def hasAbility?(check_ability = nil) + current_ability = self.ability + return !current_ability.nil? if check_ability.nil? + return current_ability == check_ability + end + + # @return [Boolean] whether this Pokémon has a hidden ability + def hasHiddenAbility? + return ability_index >= 2 + end + + # @return [Array>] the abilities this Pokémon can have, + # where every element is [ability ID, ability index] + def getAbilityList + ret = [] + sp_data = species_data + sp_data.abilities.each_with_index { |a, i| ret.push([a, i]) if a } + sp_data.hidden_abilities.each_with_index { |a, i| ret.push([a, i + 2]) if a } + return ret + end + + #============================================================================= + # Nature + #============================================================================= + + # @return [Integer] the ID of this Pokémon's nature + def nature + @nature = (@personalID % 25) if !@nature + return @nature + end + + # Returns the calculated nature, taking into account things that change its + # stat-altering effect (i.e. Gen 8 mints). Only used for calculating stats. + # @return [Integer] this Pokémon's calculated nature + def nature_for_stats + return @nature_for_stats || self.nature + end + + # Sets this Pokémon's nature to a particular nature. + # @param value [Integer, String, Symbol] nature to change to + def nature=(value) + @nature = getID(PBNatures, value) + calcStats if !@nature_for_stats + end + + # Returns whether this Pokémon has a particular nature. If no value is given, + # returns whether this Pokémon has a nature set. + # @param nature [Integer] nature ID to check + # @return [Boolean] whether this Pokémon has a particular nature or a nature + # at all + def hasNature?(check_nature = -1) + current_nature = self.nature + return current_nature >= 0 if check_nature < 0 + return current_nature == getID(PBNatures, check_nature) + end + + #============================================================================= + # Items + #============================================================================= + + # @return [GameData::Item, nil] an Item object corresponding to this Pokémon's item + def item + return GameData::Item.try_get(@item) + end + + def item_id + return @item + end + + # Gives an item to this Pokémon to hold. + # @param value [Symbol, GameData::Item, Integer, nil] ID of the item to give + # to this Pokémon + def item=(value) + return if value && !GameData::Item.exists?(value) + @item = (value) ? GameData::Item.get(value).id : value + end + + # Returns whether this Pokémon is holding an item. If an item id is passed, + # returns whether the Pokémon is holding that item. + # @param check_item [Symbol, GameData::Item, Integer] item ID to check + # @return [Boolean] whether the Pokémon is holding the specified item or + # an item at all + def hasItem?(check_item = nil) + return !@item.nil? if check_item.nil? + return self.item == check_item + end + + # @return [Array] the items this species can be found holding in the wild + def wildHoldItems + sp_data = species_data + return [sp_data.wild_item_common, sp_data.wild_item_uncommon, sp_data.wild_item_rare] + end + + # @return [Mail, nil] mail held by this Pokémon (nil if there is none) + def mail + @mail = nil if @mail && (!@mail.item || !hasItem?(@mail.item)) + return @mail + end + + # If mail is a Mail object, gives that mail to this Pokémon. If nil is given, + # removes the held mail. + # @param mail [Mail, nil] mail to be held by this Pokémon + def mail=(mail) + if !mail.nil? && !mail.is_a?(Mail) + raise ArgumentError, _INTL('Invalid value {1} given', mail.inspect) + end + @mail = mail + end + + #============================================================================= + # Moves + #============================================================================= + + # @return [Integer] the number of moves known by the Pokémon + def numMoves + return @moves.length + end + + # @param move_id [Integer, Symbol, String] ID of the move to check + # @return [Boolean] whether the Pokémon knows the given move + def hasMove?(move_id) + move_data = GameData::Move.try_get(move_id) + return false if !move_data + return @moves.any? { |m| m.id == move_data.id } + end + alias knowsMove? hasMove? + + # Returns the list of moves this Pokémon can learn by levelling up. + # @return [Array>] this Pokémon's move list, where every element is [level, move ID] + def getMoveList + return species_data.moves + end + + # Sets this Pokémon's movelist to the default movelist it originally had. + def resetMoves + this_level = self.level + # Find all level-up moves that self could have learned + moveset = self.getMoveList + knowable_moves = [] + moveset.each { |m| knowable_moves.push(m[1]) if m[0] <= this_level } + # Remove duplicates (retaining the latest copy of each move) + knowable_moves = knowable_moves.reverse + knowable_moves |= [] + knowable_moves = knowable_moves.reverse + # Add all moves + @moves.clear + first_move_index = knowable_moves.length - MAX_MOVES + first_move_index = 0 if first_move_index < 0 + for i in first_move_index...knowable_moves.length + @moves.push(Pokemon::Move.new(knowable_moves[i])) + end + end + + # Silently learns the given move. Will erase the first known move if it has to. + # @param move_id [Integer, Symbol, String] ID of the move to learn + def pbLearnMove(move_id) + move_data = GameData::Move.try_get(move_id) + return if !move_data + # Check if self already knows the move; if so, move it to the end of the array + @moves.each_with_index do |m, i| + next if m.id != move_data.id + @moves.push(m) + @moves.delete_at(i) + return + end + # Move is not already known; learn it + @moves.push(Pokemon::Move.new(move_data.id)) + # Delete the first known move if self now knows more moves than it should + @moves.shift if numMoves > MAX_MOVES + end + + # Deletes the given move from the Pokémon. + # @param move_id [Integer, Symbol, String] ID of the move to delete + def pbDeleteMove(move_id) + move_data = GameData::Move.try_get(move_id) + return if !move_data + @moves.delete_if { |m| m.id == move_data.id } + end + + # Deletes the move at the given index from the Pokémon. + # @param index [Integer] index of the move to be deleted + def pbDeleteMoveAtIndex(index) + @moves.delete_at(index) + end + + # Deletes all moves from the Pokémon. + def pbDeleteAllMoves + @moves.clear + end + + # Copies currently known moves into a separate array, for Move Relearner. + def pbRecordFirstMoves + pbClearFirstMoves + @moves.each { |m| @firstmoves.push(m.id) } + end + + # Adds a move to this Pokémon's first moves. + # @param move_id [Integer, Symbol, String] ID of the move to add + def pbAddFirstMove(move_id) + move_data = GameData::Move.try_get(move_id) + @firstmoves.push(move_data.id) if move_data && !@firstmoves.include?(move_data.id) + end + + # Removes a move from this Pokémon's first moves. + # @param move_id [Integer, Symbol, String] ID of the move to remove + def pbRemoveFirstMove(move_id) + move_data = GameData::Move.try_get(move_id) + @firstmoves.delete(move_data.id) if move_data + end + + # Clears this Pokémon's first moves. + def pbClearFirstMoves + @firstmoves.clear + end + + # @param move_id [Integer, Symbol, String] ID of the move to check + # @return [Boolean] whether the Pokémon is compatible with the given move + def compatibleWithMove?(move_id) + move_data = GameData::Move.try_get(move_id) + return move_data && species_data.tutor_moves.include?(move_data.id) + end + + #============================================================================= + # Ribbons + #============================================================================= + + # @return [Integer] the number of ribbons this Pokémon has + def ribbonCount + return @ribbons.length + end + + # @param ribbon [Integer, Symbol, String] ribbon ID to check + # @return [Boolean] whether this Pokémon has the specified ribbon + def hasRibbon?(ribbon) + ribbon = getID(PBRibbons, ribbon) + return ribbon > 0 && @ribbons.include?(ribbon) + end + + # Gives a ribbon to this Pokémon. + # @param ribbon [Integer, Symbol, String] ID of the ribbon to give + def giveRibbon(ribbon) + ribbon = getID(PBRibbons, ribbon) + return if ribbon == 0 + @ribbons.push(ribbon) if !@ribbons.include?(ribbon) + end + + # Replaces one ribbon with the next one along, if possible. + def upgradeRibbon(*arg) + for i in 0...arg.length - 1 + for j in 0...@ribbons.length + next if @ribbons[j] != getID(PBRibbons, arg[i]) + @ribbons[j] = getID(PBRibbons, arg[i + 1]) + return @ribbons[j] + end + end + if !hasRibbon?(arg[arg.length - 1]) + first_ribbon = getID(PBRibbons, arg[0]) + giveRibbon(first_ribbon) + return first_ribbon + end + return 0 + end + + # Removes the specified ribbon from this Pokémon. + # @param ribbon [Integer, Symbol, String] id of the ribbon to remove + def takeRibbon(ribbon) + return if !@ribbons + ribbon = getID(PBRibbons, ribbon) + return if ribbon == 0 + for i in 0...@ribbons.length + next if @ribbons[i] != ribbon + @ribbons[i] = nil + break + end + @ribbons.compact! + end + + # Removes all ribbons from this Pokémon. + def clearAllRibbons + @ribbons.clear + end + + #============================================================================= + # Pokérus + #============================================================================= + + # @return [Integer] the Pokérus infection stage for this Pokémon + def pokerusStrain + return @pokerus / 16 + end + + # Returns the Pokérus infection stage for this Pokémon. The possible stages are + # 0 (not infected), 1 (infected) and 2 (cured) + # @return [0, 1, 2] current Pokérus infection stage + def pokerusStage + return 0 if @pokerus == 0 + return ((@pokerus % 16) == 0) ? 2 : 1 + end + + # Gives this Pokémon Pokérus (either the specified strain or a random one). + # @param strain [Integer] Pokérus strain to give + def givePokerus(strain = 0) + return if self.pokerusStage == 2 # Can't re-infect a cured Pokémon + strain = rand(1, 16) if strain <= 0 || strain >= 16 + time = 1 + (strain % 4) + @pokerus = time + @pokerus |= strain << 4 + end + + # Resets the infection time for this Pokémon's Pokérus (even if cured). + def resetPokerusTime + return if @pokerus == 0 + strain = @pokerus % 16 + time = 1 + (strain % 4) + @pokerus = time + @pokerus |= strain << 4 + end + + # Reduces the time remaining for this Pokémon's Pokérus (if infected). + def lowerPokerusCount + return if self.pokerusStage != 1 + @pokerus -= 1 + end + + #============================================================================= + # Ownership, obtained information + #============================================================================= + + # Changes this Pokémon's owner. + # @param new_owner [Owner] the owner to change to + def owner=(new_owner) + validate new_owner => Owner + @owner = new_owner + end + + # @param trainer [PokeBattle_Trainer] the trainer to compare to the original trainer + # @return [Boolean] whether the given trainer is not this Pokémon's original trainer + def foreign?(trainer) + return @owner.id != trainer.id || @owner.name != trainer.name + end + alias isForeign? foreign? + + # @return [Time] the time when this Pokémon was obtained + def timeReceived + return Time.at(@timeReceived) + end + + # Sets the time when this Pokémon was obtained. + # @param value [Integer, Time, #to_i] time in seconds since Unix epoch + def timeReceived=(value) + @timeReceived = value.to_i + end + + # @return [Time] the time when this Pokémon hatched + def timeEggHatched + return (obtain_method == 1) ? Time.at(@timeEggHatched) : nil + end + + # Sets the time when this Pokémon hatched. + # @param value [Integer, Time, #to_i] time in seconds since Unix epoch + def timeEggHatched=(value) + @timeEggHatched = value.to_i end #============================================================================= # Other #============================================================================= - # @return [String] the species name of this Pokémon - def speciesName - return species_data.name + # @return [String] the name of this Pokémon + def name + return (nicknamed?) ? @name || speciesName + end + + # @param value [String] the nickname of this Pokémon + def name=(value) + value = nil if !value || value.empty? || value == speciesName + @name = value end # @return [Boolean] whether this Pokémon has been nicknamed def nicknamed? - return @name != self.speciesName + return @name && !@name.empty? end - # @return [Integer] the markings this Pokémon has - def markings - return @markings || 0 + # @return [String] the species name of this Pokémon + def speciesName + return species_data.name end # @return [String] a string stating the Unown form of this Pokémon @@ -895,92 +826,45 @@ class Pokemon return species_data.evs.clone end - # Returns an array of booleans indicating whether a stat is made to have - # maximum IVs (for Hyper Training). Set like @ivMaxed[PBStats::ATTACK] = true - # @return [Array] array indicating whether each stat has maximum IVs - def ivMaxed - return @ivMaxed || [] - end - - # Returns this Pokémon's effective IVs, taking into account Hyper Training. - # Only used for calculating stats. - # @return [Array] array containing this Pokémon's effective IVs - def calcIV - ret = self.iv.clone - if @ivMaxed - PBStats.eachStat { |s| ret[s] = IV_STAT_LIMIT if @ivMaxed[s] } - end - return ret - end - - # Sets the Pokémon's health. - # @param value [Integer] new hp value - def hp=(value) - value = 0 if value < 0 - @hp = value - if @hp == 0 - @status = PBStatuses::NONE - @statusCount = 0 - end - end - # Changes the happiness of this Pokémon depending on what happened to change it. # @param method [String] the happiness changing method (e.g. 'walking') def changeHappiness(method) gain = 0 + happiness_range = @happiness / 100 case method when "walking" - gain = 1 - gain = 2 if @happiness < 200 + gain = [2, 2, 1][happiness_range] when "levelup" - gain = 3 - gain = 4 if @happiness < 200 - gain = 5 if @happiness < 100 + gain = [5, 4, 3][happiness_range] when "groom" - gain = 4 - gain = 10 if @happiness < 200 + gain = [10, 10, 4][happiness_range] when "evberry" - gain = 2 - gain = 5 if @happiness < 200 - gain = 10 if @happiness < 100 + gain = [10, 5, 2][happiness_range] when "vitamin" - gain = 2 - gain = 3 if @happiness < 200 - gain = 5 if @happiness < 100 + gain = [5, 3, 2][happiness_range] when "wing" - gain = 1 - gain = 2 if @happiness < 200 - gain = 3 if @happiness < 100 - when "machine" - gain = 0 - gain = 1 if @happiness < 200 - when "battleitem" - gain = 0 - gain = 1 if @happiness < 200 + gain = [3, 2, 1][happiness_range] + when "machine", "battleitem" + gain = [1, 1, 0][happiness_range] when "faint" gain = -1 when "faintbad" # Fainted against an opponent that is 30+ levels higher - gain = -10 - gain = -5 if @happiness < 200 + gain = [-5, -5, -10][happiness_range] when "powder" - gain = -10 - gain = -5 if @happiness < 200 + gain = [-5, -5, -10][happiness_range] when "energyroot" - gain = -15 - gain = -10 if @happiness < 200 + gain = [-10, -10, -15][happiness_range] when "revivalherb" - gain = -20 - gain = -15 if @happiness < 200 + gain = [-15, -15, -20][happiness_range] else raise _INTL("Unknown happiness-changing method: {1}", method.to_s) end if gain > 0 gain += 1 if @obtainMap == $game_map.map_id - gain += 1 if self.ballused == pbGetBallType(:LUXURYBALL) - gain = (gain * 1.5).floor if self.hasItem?(:SOOTHEBELL) + gain += 1 if @ballused == pbGetBallType(:LUXURYBALL) + gain = (gain * 1.5).floor if hasItem?(:SOOTHEBELL) end - @happiness += gain - @happiness = [[255, @happiness].min, 0].max + @happiness = (@happiness + gain).clamp(0, 255) end #============================================================================= @@ -992,6 +876,15 @@ class Pokemon return species_data.base_stats.clone end + # Returns this Pokémon's effective IVs, taking into account Hyper Training. + # Only used for calculating stats. + # @return [Array] array containing this Pokémon's effective IVs + def calcIV + ret = self.iv.clone + PBStats.eachStat { |s| ret[s] = IV_STAT_LIMIT if @ivMaxed[s] } + return ret + end + # @return [Integer] the maximum HP of this Pokémon def calcHP(base, level, iv, ev) return 1 if base == 1 # For Shedinja @@ -999,29 +892,27 @@ class Pokemon end # @return [Integer] the specified stat of this Pokémon (not used for total HP) - def calcStat(base, level, iv, ev, pv) - return ((((base * 2 + iv + (ev / 4)) * level / 100).floor + 5) * pv / 100).floor + def calcStat(base, level, iv, ev, nat) + return ((((base * 2 + iv + (ev / 4)) * level / 100).floor + 5) * nat / 100).floor end # Recalculates this Pokémon's stats. def calcStats - bs = self.baseStats - usedLevel = self.level - usedIV = self.calcIV - pValues = PBNatures.getStatChanges(self.calcNature) + base_stats = self.baseStats + this_level = self.level + this_IV = self.calcIV + nature_mod = PBNatures.getStatChanges(self.nature_for_stats) stats = [] PBStats.eachStat do |s| if s == PBStats::HP - stats[s] = calcHP(bs[s], usedLevel, usedIV[s], @ev[s]) + stats[s] = calcHP(base_stats[s], this_level, this_IV[s], @ev[s]) else - stats[s] = calcStat(bs[s], usedLevel, usedIV[s], @ev[s], pValues[s]) + stats[s] = calcStat(base_stats[s], this_level, this_IV[s], @ev[s], nature_mod[s]) end end hpDiff = @totalhp - @hp @totalhp = stats[PBStats::HP] @hp = @totalhp - hpDiff - @hp = 0 if @hp < 0 - @hp = @totalhp if @hp > @totalhp @attack = stats[PBStats::ATTACK] @defense = stats[PBStats::DEFENSE] @spatk = stats[PBStats::SPATK] @@ -1037,13 +928,14 @@ class Pokemon # @return [Pokemon] a copy of this Pokémon def clone ret = super - ret.iv = @iv.clone - ret.ivMaxed = @ivMaxed.clone - ret.ev = @ev.clone - ret.moves = [] - ret.owner = @owner.clone + ret.iv = @iv.clone + ret.ivMaxed = @ivMaxed.clone + ret.ev = @ev.clone + ret.moves = [] @moves.each_with_index { |m, i| ret.moves[i] = m.clone } - ret.ribbons = @ribbons.clone if @ribbons + ret.firstmoves = @firstmoves.cline + ret.owner = @owner.clone + ret.ribbons = @ribbons.clone return ret end @@ -1054,28 +946,43 @@ class Pokemon # @param withMoves [Boolean] whether the Pokémon should have moves def initialize(species, level, owner = $Trainer, withMoves = true) species_data = GameData::Species.get(species) - @species = species_data.species - @form = species_data.form - @name = species_data.name - @personalID = rand(2 ** 16) | rand(2 ** 16) << 16 - @hp = 1 - @totalhp = 1 - @iv = [] - @ivMaxed = [] - @ev = [] + @species = species_data.species + @form = species_data.form + @forcedForm = nil + @formTime = nil + self.level = level + @eggsteps = 0 + healStatus + @gender = nil + @shiny = nil + @ability_index = nil + @ability = nil + @nature = nil + @nature_for_stats = nil + @item = nil + @mail = nil + @moves = [] + resetMoves if withMoves + @firstmoves = [] + @ribbons = [] + @cool = 0 + @beauty = 0 + @cute = 0 + @smart = 0 + @tough = 0 + @sheen = 0 + @pokerus = 0 + @name = nil + @happiness = species_data.happiness + @ballused = 0 + @markings = 0 + @iv = [] + @ivMaxed = [] + @ev = [] PBStats.eachStat do |s| - @iv[s] = rand(IV_STAT_LIMIT + 1) - @ev[s] = 0 + @iv[s] = rand(IV_STAT_LIMIT + 1) + @ev[s] = 0 end - @moves = [] - @status = PBStatuses::NONE - @statusCount = 0 - @item_id = nil - @mail = nil - @fused = nil - @ribbons = [] - @ballused = 0 - @eggsteps = 0 if owner.is_a?(Owner) @owner = owner elsif owner.is_a?(PokeBattle_Trainer) @@ -1083,23 +990,24 @@ class Pokemon else @owner = Owner.new(0, '', 2, 2) end - @obtainMap = ($game_map) ? $game_map.map_id : 0 - @obtainText = nil - @obtainLevel = level - @obtainMode = 0 # Met - @obtainMode = 4 if $game_switches && $game_switches[FATEFUL_ENCOUNTER_SWITCH] - @hatchedMap = 0 - @timeReceived = pbGetTimeNow.to_i - self.level = level + @obtain_method = 0 # Met + @obtain_method = 4 if $game_switches && $game_switches[FATEFUL_ENCOUNTER_SWITCH] + @obtainMap = ($game_map) ? $game_map.map_id : 0 + @obtainText = nil + @obtainLevel = level + @hatchedMap = 0 + @timeReceived = pbGetTimeNow.to_i + @timeEggHatched = nil + @fused = nil + @personalID = rand(2 ** 16) | rand(2 ** 16) << 16 + @hp = 1 + @totalhp = 1 calcStats - @hp = @totalhp - @happiness = species_data.happiness - resetMoves if withMoves if @form == 0 f = MultipleForms.call("getFormOnCreation", self) if f self.form = f - resetMoves + resetMoves if withMoves end end end diff --git a/Data/Scripts/016_Pokemon/003_PBMove.rb b/Data/Scripts/016_Pokemon/003_PBMove.rb deleted file mode 100644 index 33b117694..000000000 --- a/Data/Scripts/016_Pokemon/003_PBMove.rb +++ /dev/null @@ -1,43 +0,0 @@ -#=============================================================================== -# Move objects known by Pokémon. -#=============================================================================== -class PBMove - attr_reader :id # This move's ID - attr_accessor :pp # The amount of PP remaining for this move - attr_accessor :ppup # The number of PP Ups used on this move - - # Initializes this object to the specified move ID. - def initialize(move_id) - @id = GameData::Move.get(move_id).id - @ppup = 0 - @pp = total_pp - end - - # Changes this move's ID, and caps the PP amount if it is now greater than the - # new move's total PP. - def id=(value) - old_id = @id - @id = GameData::Move.get(value).id - @pp = [@pp, total_pp].min - end - - # Gets the maximum PP for this move. - def total_pp - max_pp = GameData::Move.get(@id).total_pp - return max_pp + max_pp * @ppup / 5 - end - alias totalpp total_pp - - def function_code; return GameData::Move.get(@id).function_code; end - def base_damage; return GameData::Move.get(@id).base_damage; end - def type; return GameData::Move.get(@id).type; end - def category; return GameData::Move.get(@id).category; end - def accuracy; return GameData::Move.get(@id).accuracy; end - def effect_chance; return GameData::Move.get(@id).effect_chance; end - def target; return GameData::Move.get(@id).target; end - def priority; return GameData::Move.get(@id).priority; end - def flags; return GameData::Move.get(@id).flags; end - def name; return GameData::Move.get(@id).name; end - def description; return GameData::Move.get(@id).description; end - def hidden_move?; return GameData::Move.get(@id).hidden_move?; end -end diff --git a/Data/Scripts/016_Pokemon/003_Pokemon_Move.rb b/Data/Scripts/016_Pokemon/003_Pokemon_Move.rb new file mode 100644 index 000000000..941cab755 --- /dev/null +++ b/Data/Scripts/016_Pokemon/003_Pokemon_Move.rb @@ -0,0 +1,77 @@ +#=============================================================================== +# Move objects known by Pokémon. +#=============================================================================== +class Pokemon + class Move + # This move's ID. + attr_reader :id + # The amount of PP remaining for this move. + attr_reader :pp + # The number of PP Ups used on this move (each one adds 20% to the total PP). + attr_reader :ppup + + # Creates a new Move object. + # @param move_id [Symbol, String, Integer] move ID + def initialize(move_id) + @id = GameData::Move.get(move_id).id + @ppup = 0 + @pp = total_pp + end + + # Sets this move's ID, and caps the PP amount if it is now greater than this + # move's total PP. + # @param value [Symbol, String, Integer] the new move ID + def id=(value) + @id = GameData::Move.get(value).id + @pp = @pp.clamp(0, total_pp) + end + + # Sets this move's PP, capping it at this move's total PP. + # @param value [Integer] the new PP amount + def pp=(value) + @pp = value.clamp(0, total_pp) + end + + # Sets this move's PP Up count, and caps the PP if necessary. + # @param value [Integer] the new PP Up value + def ppup=(value) + @ppup = value + @pp = @pp.clamp(0, total_pp) + end + + # Returns the total PP of this move, taking PP Ups into account. + # @return [Integer] total PP + def total_pp + max_pp = GameData::Move.get(@id).total_pp + return max_pp + max_pp * @ppup / 5 + end + alias totalpp total_pp + + def function_code; return GameData::Move.get(@id).function_code; end + def base_damage; return GameData::Move.get(@id).base_damage; end + def type; return GameData::Move.get(@id).type; end + def category; return GameData::Move.get(@id).category; end + def accuracy; return GameData::Move.get(@id).accuracy; end + def effect_chance; return GameData::Move.get(@id).effect_chance; end + def target; return GameData::Move.get(@id).target; end + def priority; return GameData::Move.get(@id).priority; end + def flags; return GameData::Move.get(@id).flags; end + def name; return GameData::Move.get(@id).name; end + def description; return GameData::Move.get(@id).description; end + def hidden_move?; return GameData::Move.get(@id).hidden_move?; end + end +end + +#=============================================================================== +# Move objects known by Pokémon. +#=============================================================================== +class PBMove + attr_reader :id, :pp, :ppup + + def self.copy(move) + ret = Pokemon::Move.new(move.id) + ret.ppup = move.ppup + ret.pp = move.pp + return ret + end +end diff --git a/Data/Scripts/016_Pokemon/004_Pokemon_ShadowPokemon.rb b/Data/Scripts/016_Pokemon/004_Pokemon_ShadowPokemon.rb index ac6b0546b..cc49de1ec 100644 --- a/Data/Scripts/016_Pokemon/004_Pokemon_ShadowPokemon.rb +++ b/Data/Scripts/016_Pokemon/004_Pokemon_ShadowPokemon.rb @@ -36,9 +36,9 @@ def pbPurify(pokemon,scene) end pokemon.savedev = nil end - newexp = PBExperience.pbAddExperience(pokemon.exp,pokemon.savedexp||0,pokemon.growthrate) + newexp = PBExperience.pbAddExperience(pokemon.exp,pokemon.savedexp||0,pokemon.growth_rate) pokemon.savedexp = nil - newlevel = PBExperience.pbGetLevelFromExperience(newexp,pokemon.growthrate) + newlevel = PBExperience.pbGetLevelFromExperience(newexp,pokemon.growth_rate) curlevel = pokemon.level if newexp!=pokemon.exp scene.pbDisplay(_INTL("{1} regained {2} Exp. Points!",pokemon.name,newexp-pokemon.exp)) @@ -53,7 +53,7 @@ def pbPurify(pokemon,scene) if scene.pbConfirm(_INTL("Would you like to give a nickname to {1}?", pokemon.speciesName)) newname = pbEnterPokemonName(_INTL("{1}'s nickname?", pokemon.speciesName), 0, Pokemon::MAX_NAME_SIZE, "", pokemon) - pokemon.name = newname if newname!="" + pokemon.name = newname end end diff --git a/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb b/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb index e29d972c2..e0e68772f 100644 --- a/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb +++ b/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb @@ -529,7 +529,7 @@ PBEvolution.register(:HappinessHoldItem, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) @@ -557,7 +557,7 @@ PBEvolution.register(:HoldItem, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) @@ -570,7 +570,7 @@ PBEvolution.register(:HoldItemMale, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) @@ -583,7 +583,7 @@ PBEvolution.register(:HoldItemFemale, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) @@ -596,7 +596,7 @@ PBEvolution.register(:DayHoldItem, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) @@ -609,7 +609,7 @@ PBEvolution.register(:NightHoldItem, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) @@ -622,7 +622,7 @@ PBEvolution.register(:HoldItemHappiness, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) @@ -757,7 +757,7 @@ PBEvolution.register(:TradeItem, { }, "afterEvolution" => proc { |pkmn, new_species, parameter, evo_species| next false if evo_species != new_species || !pkmn.hasItem?(parameter) - pkmn.setItem(nil) # Item is now consumed + pkmn.item = nil # Item is now consumed next true } }) diff --git a/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb b/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb index 129a2e36e..d1a9249c2 100644 --- a/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb +++ b/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb @@ -28,49 +28,50 @@ class PokeBattle_Pokemon def self.copy(pkmn) owner = Pokemon::Owner.new(pkmn.trainerID, pkmn.ot, pkmn.otgender, pkmn.language) ret = Pokemon.new(pkmn.species, pkmn.level, owner, false) - ret.name = pkmn.name - ret.exp = pkmn.exp + ret.forcedForm = pkmn.forcedForm if pkmn.forcedForm ret.formTime = pkmn.formTime - ret.forcedForm = pkmn.forcedForm - ret.hp = pkmn.hp - ret.abilityflag = pkmn.abilityflag - ret.genderflag = pkmn.genderflag - ret.natureflag = pkmn.natureflag - ret.natureOverride = pkmn.natureOverride - ret.shinyflag = pkmn.shinyflag - ret.item_id = pkmn.item - ret.mail = pkmn.mail - ret.moves = pkmn.moves - ret.firstmoves = pkmn.firstmoves.clone + ret.exp = pkmn.exp + ret.eggsteps = pkmn.eggsteps ret.status = pkmn.status ret.statusCount = pkmn.statusCount - ret.iv = pkmn.iv.clone - ret.ev = pkmn.ev.clone - ret.ivMaxed = pkmn.ivMaxed if pkmn.ivMaxed - ret.happiness = pkmn.happiness - ret.ballused = pkmn.ballused - ret.eggsteps = pkmn.eggsteps - ret.markings = pkmn.markings if pkmn.markings - ret.ribbons = pkmn.ribbons.clone - ret.pokerus = pkmn.pokerus - ret.personalID = pkmn.personalID - ret.obtainMode = pkmn.obtainMode - ret.obtainMap = pkmn.obtainMap - ret.obtainText = pkmn.obtainText - ret.obtainLevel = pkmn.obtainLevel if pkmn.obtainLevel - ret.hatchedMap = pkmn.hatchedMap - ret.timeReceived = pkmn.timeReceived - ret.timeEggHatched = pkmn.timeEggHatched + ret.gender = pkmn.genderflag + ret.shiny = pkmn.shinyflag + ret.ability_index = pkmn.abilityflag + ret.nature = pkmn.natureflag + ret.nature_for_stats = pkmn.natureOverride + ret.item = pkmn.item + ret.mail = PokemonMail.copy(pkmn.mail) if pkmn.mail + pkmn.moves.each { |m| ret.moves.push(PBMove.copy(m)) if m && m.id > 0 } + pkmn.firstmoves.each { |m| ret.pbAddFirstMove(m) } + ret.ribbons = pkmn.ribbons.clone if pkmn.ribbons ret.cool = pkmn.cool if pkmn.cool ret.beauty = pkmn.beauty if pkmn.beauty ret.cute = pkmn.cute if pkmn.cute ret.smart = pkmn.smart if pkmn.smart ret.tough = pkmn.tough if pkmn.tough ret.sheen = pkmn.sheen if pkmn.sheen + ret.pokerus = pkmn.pokerus if pkmn.pokerus + ret.name = pkmn.name + ret.happiness = pkmn.happiness + ret.ballused = pkmn.ballused + ret.markings = pkmn.markings if pkmn.markings + ret.iv = pkmn.iv.clone + ret.ivMaxed = pkmn.ivMaxed.clone if pkmn.ivMaxed + ret.ev = pkmn.ev.clone + ret.obtain_method = pkmn.obtainMode + ret.obtainMap = pkmn.obtainMap + ret.obtainText = pkmn.obtainText + ret.obtainLevel = pkmn.obtainLevel if pkmn.obtainLevel + ret.hatchedMap = pkmn.hatchedMap + ret.timeReceived = pkmn.timeReceived + ret.timeEggHatched = pkmn.timeEggHatched if pkmn.fused ret.fused = PokeBattle_Pokemon.copy(pkmn.fused) if pkmn.fused.is_a?(PokeBattle_Pokemon) ret.fused = pkmn.fused if pkmn.fused.is_a?(Pokemon) end + ret.personalID = pkmn.personalID + ret.hp = pkmn.hp + ret.shadow = pkmn.shadow ret.heartgauge = pkmn.heartgauge ret.savedexp = pkmn.savedexp @@ -79,7 +80,8 @@ class PokeBattle_Pokemon ret.shadowmoves = pkmn.shadowmoves.clone ret.shadowmovenum = pkmn.shadowmovenum # NOTE: Intentionally set last, as it recalculates stats. - ret.formSimple = pkmn.form + ret.formSimple = pkmn.form || 0 + return ret end end @@ -140,6 +142,42 @@ class Pokemon Deprecation.warn_method('Pokemon#language=', 'v20', 'Pokemon::Owner#language=') @owner.language = value end + + # @deprecated Use {Pokemon#gender=} instead. This alias is slated to be removed in v20. + def setGender(value) + Deprecation.warn_method('Pokemon#setGender', 'v20', 'Pokemon#gender=') + self.gender = value + end + + # @deprecated Use {Pokemon#shiny=} instead. This alias is slated to be removed in v20. + def makeShiny + Deprecation.warn_method('Pokemon#makeShiny', 'v20', 'Pokemon#shiny=true') + self.shiny = true + end + + # @deprecated Use {Pokemon#shiny=} instead. This alias is slated to be removed in v20. + def makeNotShiny + Deprecation.warn_method('Pokemon#makeNotShiny', 'v20', 'Pokemon#shiny=false') + self.shiny = false + end + + # @deprecated Use {Pokemon#ability_index=} instead. This alias is slated to be removed in v20. + def setAbility(value) + Deprecation.warn_method('Pokemon#setAbility', 'v20', 'Pokemon#ability_index=') + self.ability_index = value + end + + # @deprecated Use {Pokemon#nature=} instead. This alias is slated to be removed in v20. + def setNature(value) + Deprecation.warn_method('Pokemon#setNature', 'v20', 'Pokemon#nature=') + self.nature = value + end + + # @deprecated Use {Pokemon#item=} instead. This alias is slated to be removed in v20. + def setItem(value) + Deprecation.warn_method('Pokemon#setItem', 'v20', 'Pokemon#item=') + self.item = value + end end # (see Pokemon#initialize) diff --git a/Data/Scripts/017_UI/005_PScreen_Party.rb b/Data/Scripts/017_UI/005_PScreen_Party.rb index fc50f26c5..88a778b9f 100644 --- a/Data/Scripts/017_UI/005_PScreen_Party.rb +++ b/Data/Scripts/017_UI/005_PScreen_Party.rb @@ -866,7 +866,7 @@ class PokemonPartyScreen else pbDisplay(_INTL("Mail was transferred from the Mailbox.")) pkmn.mail = $PokemonGlobal.mailbox[mailIndex] - pkmn.setItem(pkmn.mail.item) + pkmn.item = pkmn.mail.item $PokemonGlobal.mailbox.delete_at(mailIndex) pbRefreshSingle(pkmnid) end @@ -1286,8 +1286,8 @@ class PokemonPartyScreen if newpkmn.egg? pbDisplay(_INTL("Eggs can't hold items.")) elsif !newpkmn.hasItem? - newpkmn.setItem(item) - pkmn.setItem(nil) + newpkmn.item = item + pkmn.item = nil @scene.pbClearSwitching pbRefresh pbDisplay(_INTL("{1} was given the {2} to hold.",newpkmn.name,itemname)) @@ -1305,8 +1305,8 @@ class PokemonPartyScreen pbDisplay(_INTL("{1} is already holding a {2}.\1",newpkmn.name,newitemname)) end if pbConfirm(_INTL("Would you like to switch the two items?")) - newpkmn.setItem(item) - pkmn.setItem(newitem) + newpkmn.item = item + pkmn.item = newitem @scene.pbClearSwitching pbRefresh pbDisplay(_INTL("{1} was given the {2} to hold.",newpkmn.name,itemname)) diff --git a/Data/Scripts/017_UI/006_PScreen_Summary.rb b/Data/Scripts/017_UI/006_PScreen_Summary.rb index 4c8fa2575..f6a007d57 100644 --- a/Data/Scripts/017_UI/006_PScreen_Summary.rb +++ b/Data/Scripts/017_UI/006_PScreen_Summary.rb @@ -191,7 +191,7 @@ class PokemonSummary_Scene @sprites["movesel"].visible = false @sprites["movesel"].visible = true @sprites["movesel"].index = 0 - new_move = (move_to_learn) ? PBMove.new(move_to_learn) : nil + new_move = (move_to_learn) ? Pokemon::Move.new(move_to_learn) : nil drawSelectedMove(new_move,@pokemon.moves[0]) pbFadeInAndShow(@sprites) end @@ -436,7 +436,7 @@ class PokemonSummary_Scene memo = sprintf("%s\n",heartmessage) drawFormattedTextEx(overlay,234,304,264,memo) else - endexp = PBExperience.pbGetStartExperience(@pokemon.level+1,@pokemon.growthrate) + endexp = PBExperience.pbGetStartExperience(@pokemon.level+1,@pokemon.growth_rate) textpos.push([_INTL("Exp. Points"),238,240,0,base,shadow]) textpos.push([@pokemon.exp.to_s_formatted,488,272,1,Color.new(64,64,64),Color.new(176,176,176)]) textpos.push([_INTL("To Next Lv."),238,304,0,base,shadow]) @@ -554,10 +554,10 @@ class PokemonSummary_Scene _INTL("Traded at Lv. {1}.",@pokemon.obtainLevel), "", _INTL("Had a fateful encounter at Lv. {1}.",@pokemon.obtainLevel) - ][@pokemon.obtainMode] + ][@pokemon.obtain_method] memo += sprintf("%s\n",mettext) if mettext && mettext!="" # If Pokémon was hatched, write when and where it hatched - if @pokemon.obtainMode==1 + if @pokemon.obtain_method == 1 if @pokemon.timeEggHatched date = @pokemon.timeEggHatched.day month = pbGetMonthName(@pokemon.timeEggHatched.mon) @@ -627,8 +627,8 @@ class PokemonSummary_Scene statshadows = [] PBStats.eachStat { |s| statshadows[s] = shadow } if !@pokemon.shadowPokemon? || @pokemon.heartStage>3 - natup = PBNatures.getStatRaised(@pokemon.calcNature) - natdn = PBNatures.getStatLowered(@pokemon.calcNature) + natup = PBNatures.getStatRaised(@pokemon.nature_for_stats) + natdn = PBNatures.getStatLowered(@pokemon.nature_for_stats) statshadows[natup] = Color.new(136,96,72) if natup!=natdn statshadows[natdn] = Color.new(64,120,152) if natup!=natdn end @@ -1202,7 +1202,7 @@ class PokemonSummary_Scene end def pbChooseMoveToForget(move_to_learn) - new_move = (move_to_learn) ? PBMove.new(move_to_learn) : nil + new_move = (move_to_learn) ? Pokemon::Move.new(move_to_learn) : nil selmove = 0 maxmove = (new_move) ? Pokemon::MAX_MOVES : Pokemon::MAX_MOVES - 1 loop do diff --git a/Data/Scripts/017_UI/007_PScreen_Bag.rb b/Data/Scripts/017_UI/007_PScreen_Bag.rb index fd09bed5b..155f2252f 100644 --- a/Data/Scripts/017_UI/007_PScreen_Bag.rb +++ b/Data/Scripts/017_UI/007_PScreen_Bag.rb @@ -489,7 +489,7 @@ class PokemonBagScreen command = @scene.pbShowCommands(_INTL("{1} is selected.",itemname),commands) if cmdRead>=0 && command==cmdRead # Read mail pbFadeOutIn { - pbDisplayMail(PokemonMail.new(item,"","")) + pbDisplayMail(Mail.new(item, "", "")) } elsif cmdUse>=0 && command==cmdUse # Use item ret = pbUseItem(@bag,item,@scene) diff --git a/Data/Scripts/017_UI/017_PScreen_PokemonStorage.rb b/Data/Scripts/017_UI/017_PScreen_PokemonStorage.rb index ec6856af9..7cfee61e6 100644 --- a/Data/Scripts/017_UI/017_PScreen_PokemonStorage.rb +++ b/Data/Scripts/017_UI/017_PScreen_PokemonStorage.rb @@ -1880,7 +1880,7 @@ class PokemonStorageScreen pbDisplay(_INTL("Can't store the {1}.",itemname)) else pbDisplay(_INTL("Took the {1}.",itemname)) - pokemon.setItem(nil) + pokemon.item = nil @scene.pbHardRefresh end end @@ -1888,7 +1888,7 @@ class PokemonStorageScreen item = scene.pbChooseItem($PokemonBag) if item itemname = GameData::Item.get(item).name - pokemon.setItem(item) + pokemon.item = item $PokemonBag.pbDeleteItem(item) pbDisplay(_INTL("{1} is now being held.",itemname)) @scene.pbHardRefresh diff --git a/Data/Scripts/017_UI/020_PScreen_EggHatching.rb b/Data/Scripts/017_UI/020_PScreen_EggHatching.rb index 49f4d6fe6..63fb5a9bd 100644 --- a/Data/Scripts/017_UI/020_PScreen_EggHatching.rb +++ b/Data/Scripts/017_UI/020_PScreen_EggHatching.rb @@ -104,13 +104,14 @@ class PokemonEggHatch_Scene updateScene(frames) pbBGMStop() pbMEPlay("Evolution success") - pbMessage(_INTL("\\se[]{1} hatched from the Egg!\\wt[80]",@pokemon.name)) { update } + @pokemon.name = nil + pbMessage(_INTL("\\se[]{1} hatched from the Egg!\\wt[80]", @pokemon.name)) { update } if pbConfirmMessage( - _INTL("Would you like to nickname the newly hatched {1}?",@pokemon.name)) { update } - nickname=pbEnterPokemonName(_INTL("{1}'s nickname?",@pokemon.name), + _INTL("Would you like to nickname the newly hatched {1}?", @pokemon.name)) { update } + nickname = pbEnterPokemonName(_INTL("{1}'s nickname?", @pokemon.name), 0, Pokemon::MAX_NAME_SIZE, "", @pokemon, true) - @pokemon.name=nickname if nickname!="" - @nicknamed=true + @pokemon.name = nickname + @nicknamed = true end end @@ -192,11 +193,11 @@ end def pbHatch(pokemon) speciesname = pokemon.speciesName - pokemon.name = speciesname + pokemon.name = nil pokemon.owner = Pokemon::Owner.new_from_trainer($Trainer) pokemon.happiness = 120 pokemon.timeEggHatched = pbGetTimeNow - pokemon.obtainMode = 1 # hatched from egg + pokemon.obtain_method = 1 # hatched from egg pokemon.hatchedMap = $game_map.map_id $Trainer.seen[pokemon.species] = true $Trainer.owned[pokemon.species] = true @@ -206,11 +207,11 @@ def pbHatch(pokemon) pbMessage(_INTL("Huh?\1")) pbMessage(_INTL("...\1")) pbMessage(_INTL("... .... .....\1")) - pbMessage(_INTL("{1} hatched from the Egg!",speciesname)) - if pbConfirmMessage(_INTL("Would you like to nickname the newly hatched {1}?",speciesname)) - nickname = pbEnterPokemonName(_INTL("{1}'s nickname?",speciesname), + pbMessage(_INTL("{1} hatched from the Egg!", speciesname)) + if pbConfirmMessage(_INTL("Would you like to nickname the newly hatched {1}?", speciesname)) + nickname = pbEnterPokemonName(_INTL("{1}'s nickname?", speciesname), 0, Pokemon::MAX_NAME_SIZE, "", pokemon) - pokemon.name = nickname if nickname!="" + pokemon.name = nickname end end end diff --git a/Data/Scripts/017_UI/021_PScreen_Evolution.rb b/Data/Scripts/017_UI/021_PScreen_Evolution.rb index 7f981bc1d..8238bc6ea 100644 --- a/Data/Scripts/017_UI/021_PScreen_Evolution.rb +++ b/Data/Scripts/017_UI/021_PScreen_Evolution.rb @@ -577,7 +577,6 @@ class PokemonEvolutionScene # Success jingle/message pbMEPlay("Evolution success") newspeciesname = GameData::Species.get(@newspecies).name - is_nicknamed = @pokemon.nicknamed? pbMessageDisplay(@sprites["msgwindow"], _INTL("\\se[]Congratulations! Your {1} evolved into {2}!\\wt[80]", @pokemon.name,newspeciesname)) { pbUpdate } @@ -586,7 +585,6 @@ class PokemonEvolutionScene pbEvolutionMethodAfterEvolution # Modify Pokémon to make it evolved @pokemon.species = @newspecies - @pokemon.name = newspeciesname if !is_nicknamed @pokemon.form = 0 if @pokemon.isSpecies?(:MOTHIM) @pokemon.calcStats # See and own evolved species @@ -611,10 +609,10 @@ class PokemonEvolutionScene def self.pbDuplicatePokemon(pkmn, new_species) new_pkmn = pkmn.clone new_pkmn.species = new_species - new_pkmn.name = GameData::Species.get(new_species).name + new_pkmn.name = nil new_pkmn.markings = 0 new_pkmn.ballused = 0 - new_pkmn.setItem(nil) + new_pkmn.item = nil new_pkmn.clearAllRibbons new_pkmn.calcStats new_pkmn.heal diff --git a/Data/Scripts/017_UI/022_PScreen_Trading.rb b/Data/Scripts/017_UI/022_PScreen_Trading.rb index 68673ffed..e7ebda5f7 100644 --- a/Data/Scripts/017_UI/022_PScreen_Trading.rb +++ b/Data/Scripts/017_UI/022_PScreen_Trading.rb @@ -208,8 +208,8 @@ def pbStartTrade(pokemonIndex,newpoke,nickname,trainerName,trainerGender=0) raise _INTL("Species does not exist ({1}).", newpoke) if !species_data yourPokemon = Pokemon.new(species_data.id, myPokemon.level, opponent) end - yourPokemon.name = nickname - yourPokemon.obtainMode = 2 # traded + yourPokemon.name = nickname + yourPokemon.obtain_method = 2 # traded yourPokemon.resetMoves if resetmoves yourPokemon.pbRecordFirstMoves $Trainer.seen[yourPokemon.species] = true diff --git a/Data/Scripts/017_UI/026_PScreen_MysteryGift.rb b/Data/Scripts/017_UI/026_PScreen_MysteryGift.rb index 033577370..ce9d09ed4 100644 --- a/Data/Scripts/017_UI/026_PScreen_MysteryGift.rb +++ b/Data/Scripts/017_UI/026_PScreen_MysteryGift.rb @@ -383,7 +383,7 @@ def pbReceiveMysteryGift(id) gift[2].calcStats time=pbGetTimeNow gift[2].timeReceived=time.getgm.to_i - gift[2].obtainMode=4 # Fateful encounter + gift[2].obtain_method = 4 # Fateful encounter gift[2].pbRecordFirstMoves if $game_map gift[2].obtainMap=$game_map.map_id diff --git a/Data/Scripts/019_Other battles/003_PBattle_OrgBattle.rb b/Data/Scripts/019_Other battles/003_PBattle_OrgBattle.rb index ab6775361..1264ca8e2 100644 --- a/Data/Scripts/019_Other battles/003_PBattle_OrgBattle.rb +++ b/Data/Scripts/019_Other battles/003_PBattle_OrgBattle.rb @@ -154,16 +154,16 @@ class PBPokemon def createPokemon(level,iv,trainer) pokemon=Pokemon.new(@species,level,trainer,false) - pokemon.setItem(@item) + pokemon.item = @item pokemon.personalID = rand(2**16) | rand(2**16) << 16 pokemon.personalID -= pokemon.personalID % 25 pokemon.personalID += nature pokemon.personalID &= 0xFFFFFFFF pokemon.happiness=0 - pokemon.moves[0]=PBMove.new(self.convertMove(@move1)) - pokemon.moves[1]=PBMove.new(self.convertMove(@move2)) - pokemon.moves[2]=PBMove.new(self.convertMove(@move3)) - pokemon.moves[3]=PBMove.new(self.convertMove(@move4)) + pokemon.moves[0] = Pokemon::Move.new(self.convertMove(@move1)) + pokemon.moves[1] = Pokemon::Move.new(self.convertMove(@move2)) + pokemon.moves[2] = Pokemon::Move.new(self.convertMove(@move3)) + pokemon.moves[3] = Pokemon::Move.new(self.convertMove(@move4)) evcount=0 for i in 0...6 evcount+=1 if ((@ev&(1< proc { |pkmn, pkmnid, heldpoke, settingUpBattle, screen| if pkmn.egg? screen.pbDisplay(_INTL("{1} is an egg.", pkmn.name)) - elsif pkmn.hp<=0 + elsif pkmn.hp <= 0 screen.pbDisplay(_INTL("{1} is fainted, can't change status.", pkmn.name)) else cmd = 0 @@ -219,8 +219,8 @@ PokemonDebugMenuCommands.register("setexp", { if pkmn.egg? screen.pbDisplay(_INTL("{1} is an egg.", pkmn.name)) else - minxp = PBExperience.pbGetStartExperience(pkmn.level, pkmn.growthrate) - maxxp = PBExperience.pbGetStartExperience(pkmn.level + 1, pkmn.growthrate) + minxp = PBExperience.pbGetStartExperience(pkmn.level, pkmn.growth_rate) + maxxp = PBExperience.pbGetStartExperience(pkmn.level + 1, pkmn.growth_rate) if minxp == maxxp screen.pbDisplay(_INTL("{1} is at the maximum level.", pkmn.name)) else @@ -228,7 +228,7 @@ PokemonDebugMenuCommands.register("setexp", { params.setRange(minxp, maxxp - 1) params.setDefaultValue(pkmn.exp) newexp = pbMessageChooseNumber( - _INTL("Set the Pokémon's Exp (range {1}-{2}).",minxp, maxxp - 1), params) { screen.pbUpdate } + _INTL("Set the Pokémon's Exp (range {1}-{2}).", minxp, maxxp - 1), params) { screen.pbUpdate } if newexp != pkmn.exp pkmn.exp = newexp pkmn.calcStats @@ -616,15 +616,15 @@ PokemonDebugMenuCommands.register("setability", { for i in abils commands.push(((i[1] < 2) ? "" : "(H) ") + GameData::Ability.get(i[0]).name) end - commands.push(_INTL("Remove override")) - msg = [_INTL("Ability {1} is natural.", oldabil), - _INTL("Ability {1} is being forced.", oldabil)][pkmn.abilityflag != nil ? 1 : 0] + commands.push(_INTL("[Reset]")) + msg = [_INTL("Ability is {1} (normal).", oldabil), + _INTL("Ability is {1} (hidden).", oldabil)][(pkmn.ability_index < 2) ? 0 : 1] cmd = screen.pbShowCommands(msg, commands, cmd) break if cmd < 0 - if cmd >= 0 && cmd < abils.length # Set ability override - pkmn.setAbility(abils[cmd][1]) - elsif cmd == abils.length # Remove override - pkmn.abilityflag = nil + if cmd >= 0 && cmd < abils.length # Set ability index + pkmn.ability_index = abils[cmd][1] + elsif cmd == abils.length # Reset + pkmn.ability_index = nil end screen.pbRefreshSingle(pkmnid) end @@ -648,19 +648,17 @@ PokemonDebugMenuCommands.register("setnature", { end commands.push(text) end - commands.push(_INTL("[Remove override]")) + commands.push(_INTL("[Reset]")) cmd = pkmn.nature loop do - oldnature = PBNatures.getName(pkmn.nature) - msg = [_INTL("Nature {1} is natural.", oldnature), - _INTL("Nature {1} is being forced.", oldnature)][pkmn.natureflag ? 1 : 0] - cmd = screen.pbShowCommands(msg, commands, cmd) + mag = _INTL("Nature is {1}.", PBNatures.getName(pkmn.nature)) + cmd = screen.pbShowCommands(mag, commands, cmd) break if cmd < 0 - if cmd >= 0 && cmd < PBNatures.getCount # Set nature override - pkmn.setNature(cmd) + if cmd >= 0 && cmd < PBNatures.getCount # Set nature + pkmn.nature = cmd pkmn.calcStats - elsif cmd == PBNatures.getCount # Remove override - pkmn.natureflag = nil + elsif cmd == PBNatures.getCount # Reset + pkmn.nature = nil end screen.pbRefreshSingle(pkmnid) end @@ -677,13 +675,11 @@ PokemonDebugMenuCommands.register("setgender", { else cmd = 0 loop do - oldgender = (pkmn.male?) ? _INTL("male") : _INTL("female") - msg = [_INTL("Gender {1} is natural.", oldgender), - _INTL("Gender {1} is being forced.", oldgender)][pkmn.genderflag ? 1 : 0] + msg = [_INTL("Gender is male."), _INTL("Gender is female.")][pkmn.male? ? 0 : 1] cmd = screen.pbShowCommands(msg, [ _INTL("Make male"), _INTL("Make female"), - _INTL("Remove override")], cmd) + _INTL("Reset")], cmd) break if cmd < 0 case cmd when 0 # Make male @@ -696,8 +692,8 @@ PokemonDebugMenuCommands.register("setgender", { if !pkmn.female? screen.pbDisplay(_INTL("{1}'s gender couldn't be changed.", pkmn.name)) end - when 2 # Remove override - pkmn.genderflag = nil + when 2 # Reset + pkmn.gender = nil end pbSeenForm(pkmn) if !settingUpBattle screen.pbRefreshSingle(pkmnid) @@ -718,7 +714,7 @@ PokemonDebugMenuCommands.register("speciesform", { cmd = screen.pbShowCommands(msg, [ _INTL("Set species"), _INTL("Set form"), - _INTL("Remove override")], cmd) + _INTL("Remove form override")], cmd) break if cmd < 0 case cmd when 0 # Set species @@ -757,7 +753,7 @@ PokemonDebugMenuCommands.register("speciesform", { screen.pbRefreshSingle(pkmnid) end end - when 2 # Remove override + when 2 # Remove form override pkmn.forcedForm = nil screen.pbRefreshSingle(pkmnid) end @@ -781,21 +777,19 @@ PokemonDebugMenuCommands.register("setshininess", { "effect" => proc { |pkmn, pkmnid, heldpoke, settingUpBattle, screen| cmd = 0 loop do - oldshiny = (pkmn.shiny?) ? _INTL("shiny") : _INTL("normal") - msg = [_INTL("Shininess ({1}) is natural.", oldshiny), - _INTL("Shininess ({1}) is being forced.", oldshiny)][pkmn.shinyflag != nil ? 1 : 0] + msg = [_INTL("Is shiny."), _INTL("Is normal (not shiny).")][pkmn.shiny? ? 0 : 1] cmd = screen.pbShowCommands(msg, [ _INTL("Make shiny"), _INTL("Make normal"), - _INTL("Remove override")], cmd) + _INTL("Reset")], cmd) break if cmd < 0 case cmd when 0 # Make shiny - pkmn.makeShiny + pkmn.shiny = true when 1 # Make normal - pkmn.makeNotShiny - when 2 # Remove override - pkmn.shinyflag = nil + pkmn.shiny = false + when 2 # Reset + pkmn.shiny = nil end screen.pbRefreshSingle(pkmnid) end @@ -874,22 +868,20 @@ PokemonDebugMenuCommands.register("setnickname", { loop do speciesname = pkmn.speciesName msg = [_INTL("{1} has the nickname {2}.", speciesname, pkmn.name), - _INTL("{1} has no nickname.", speciesname)][pkmn.name == speciesname ? 1 : 0] + _INTL("{1} has no nickname.", speciesname)][pkmn.nicknamed? ? 0 : 1] cmd = screen.pbShowCommands(msg, [ _INTL("Rename"), _INTL("Erase name")], cmd) break if cmd < 0 case cmd when 0 # Rename - oldname = (pkmn.name && pkmn.name != speciesname) ? pkmn.name : "" + oldname = (pkmn.nicknamed?) ? pkmn.name : "" newname = pbEnterPokemonName(_INTL("{1}'s nickname?", speciesname), 0, Pokemon::MAX_NAME_SIZE, oldname, pkmn) - if newname && newname != "" - pkmn.name = newname - screen.pbRefreshSingle(pkmnid) - end + pkmn.name = newname + screen.pbRefreshSingle(pkmnid) when 1 # Erase name - pkmn.name = speciesname + pkmn.name = nil screen.pbRefreshSingle(pkmnid) end end @@ -958,20 +950,20 @@ PokemonDebugMenuCommands.register("setegg", { when 0 # Make egg if !pkmn.egg? && (pbHasEgg?(pkmn.species) || screen.pbConfirm(_INTL("{1} cannot legally be an egg. Make egg anyway?", pkmn.speciesName))) - pkmn.level = EGG_LEVEL + pkmn.level = EGG_LEVEL pkmn.calcStats - pkmn.name = _INTL("Egg") - pkmn.eggsteps = pkmn.species_data.hatch_steps - pkmn.hatchedMap = 0 - pkmn.obtainMode = 1 + pkmn.name = _INTL("Egg") + pkmn.eggsteps = pkmn.species_data.hatch_steps + pkmn.hatchedMap = 0 + pkmn.obtain_method = 1 screen.pbRefreshSingle(pkmnid) end when 1 # Make Pokémon if pkmn.egg? - pkmn.name = pkmn.speciesName - pkmn.eggsteps = 0 - pkmn.hatchedMap = 0 - pkmn.obtainMode = 0 + pkmn.name = nil + pkmn.eggsteps = 0 + pkmn.hatchedMap = 0 + pkmn.obtain_method = 0 screen.pbRefreshSingle(pkmnid) end when 2 # Set eggsteps to 1 diff --git a/Data/Scripts/021_Debug/004_Editor_Screens.rb b/Data/Scripts/021_Debug/004_Editor_Screens.rb index 3304ef7a3..7a9f62a78 100644 --- a/Data/Scripts/021_Debug/004_Editor_Screens.rb +++ b/Data/Scripts/021_Debug/004_Editor_Screens.rb @@ -475,7 +475,7 @@ def pbTrainerBattleEditor t = pbNewTrainer(tr_type, tr_name, tr_version, false) if t trainer_hash = { - :id => GameData::Trainer::HASH.keys.length / 2, + :id => GameData::Trainer::DATA.keys.length / 2, :trainer_type => tr_type, :name => tr_name, :version => tr_version,