From 36ff7c4ba377e860060be321e48f1eae2fd7e33d Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sun, 17 Oct 2021 23:02:58 +0100 Subject: [PATCH] Renamed variables and methods relating to the Bag, renamed $PokemonBag to $Bag, $bag.has? can now check for a minimum quantity --- .../002_Save data/004_Game_SaveValues.rb | 4 +- .../002_Save data/005_Game_SaveConversions.rb | 25 + .../001_Hardcoded data/007_Evolution.rb | 4 +- .../003_Battle/001_PokeBattle_BattleCommon.rb | 2 +- .../004_Battle_ExpAndMoveLearning.rb | 4 +- .../003_Battle/007_Battle_Action_UseItem.rb | 6 +- .../003_Battle/009_Battle_Action_Other.rb | 4 +- .../005_Battle scene/008_Scene_Commands.rb | 18 +- Data/Scripts/012_Overworld/001_Overworld.rb | 12 +- .../003_Overworld_WildEncounters.rb | 2 +- .../006_Overworld_BerryPlants.rb | 16 +- .../012_Overworld/007_Overworld_DayCare.rb | 8 +- Data/Scripts/013_Items/001_Item_Utilities.rb | 40 +- Data/Scripts/013_Items/002_Item_Effects.rb | 48 +- Data/Scripts/013_Items/008_PokemonBag.rb | 453 ++++++++++-------- Data/Scripts/016_UI/001_UI_PauseMenu.rb | 2 +- Data/Scripts/016_UI/005_UI_Party.rb | 6 +- Data/Scripts/016_UI/006_UI_Summary.rb | 2 +- Data/Scripts/016_UI/007_UI_Bag.rb | 84 ++-- Data/Scripts/016_UI/016_UI_ReadyMenu.rb | 8 +- Data/Scripts/016_UI/017_UI_PokemonStorage.rb | 6 +- Data/Scripts/016_UI/019_UI_PC.rb | 8 +- Data/Scripts/016_UI/020_UI_PokeMart.rb | 16 +- Data/Scripts/016_UI/023_UI_MysteryGift.rb | 4 +- .../017_Minigames/002_Minigame_TripleTriad.rb | 124 ++--- .../017_Minigames/003_Minigame_SlotMachine.rb | 2 +- .../017_Minigames/004_Minigame_VoltorbFlip.rb | 2 +- .../017_Minigames/006_Minigame_Mining.rb | 2 +- .../003_Debug menus/002_Debug_MenuCommands.rb | 12 +- .../004_Compiler_MapsAndEvents.rb | 4 +- 30 files changed, 502 insertions(+), 426 deletions(-) diff --git a/Data/Scripts/002_Save data/004_Game_SaveValues.rb b/Data/Scripts/002_Save data/004_Game_SaveValues.rb index 988c6f1e7..b2e0839c0 100644 --- a/Data/Scripts/002_Save data/004_Game_SaveValues.rb +++ b/Data/Scripts/002_Save data/004_Game_SaveValues.rb @@ -103,8 +103,8 @@ end SaveData.register(:bag) do ensure_class :PokemonBag - save_value { $PokemonBag } - load_value { |value| $PokemonBag = value } + save_value { $bag } + load_value { |value| $bag = $PokemonBag = value } new_game_value { PokemonBag.new } from_old_format { |old_format| old_format[13] } end diff --git a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb index e2a26324d..5380b8358 100644 --- a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb +++ b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb @@ -169,3 +169,28 @@ SaveData.register_conversion(:v20_increment_player_character_id) do player.character_ID += 1 end end + +SaveData.register_conversion(:v20_rename_bag_variables) do + essentials_version 20 + display_title 'Renaming Bag variables' + to_value :bag do |bag| + bag.instance_eval do + if @lastPocket + @last_viewed_pocket = @lastPocket + @lastPocket = nil + end + if @choices + @last_pocket_selections = @choices.clone + @choices = nil + end + if @registeredItems + @registered_items = @registeredItems || [] + @registeredItems = nil + end + if @registeredIndex + @ready_menu_selection = @registeredIndex || [0, 0, 1] + @registeredIndex = nil + end + end + end +end diff --git a/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb b/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb index be942097b..95e9974cb 100644 --- a/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb +++ b/Data/Scripts/010_Data/001_Hardcoded data/007_Evolution.rb @@ -268,9 +268,9 @@ GameData::Evolution.register({ }, :after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species| next false if $Trainer.party_full? - next false if !$PokemonBag.pbHasItem?(:POKEBALL) + next false if !$bag.has?(:POKEBALL) PokemonEvolutionScene.pbDuplicatePokemon(pkmn, new_species) - $PokemonBag.pbDeleteItem(:POKEBALL) + $bag.remove(:POKEBALL) next true } }) diff --git a/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb b/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb index 26ea787c3..8bc4d2388 100644 --- a/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb +++ b/Data/Scripts/011_Battle/003_Battle/001_PokeBattle_BattleCommon.rb @@ -207,7 +207,7 @@ module PokeBattle_BattleCommon elsif numOwned>30 dex_modifier = 1 end - dex_modifier *= 2 if $PokemonBag.pbHasItem?(:CATCHINGCHARM) + dex_modifier *= 2 if $bag.has?(:CATCHINGCHARM) c = x * dex_modifier / 12 # Calculate the number of shakes if c>0 && pbRandom(256)0 },false) @@ -304,10 +304,10 @@ class PokeBattle_Scene break if yield item.id, useType, idxBattler, -1, itemScene end end - @bagLastPocket = $PokemonBag.lastpocket - @bagChoices = $PokemonBag.getAllChoices - $PokemonBag.lastpocket = oldLastPocket - $PokemonBag.setAllChoices(oldChoices) + @bagLastPocket = $bag.last_viewed_pocket + @bagChoices = $bag.last_pocket_selections.clone + $bag.last_viewed_pocket = oldLastPocket + $bag.last_pocket_selections = oldChoices # Close Bag screen itemScene.pbEndScene # Fade back into battle screen (if not already showing it) diff --git a/Data/Scripts/012_Overworld/001_Overworld.rb b/Data/Scripts/012_Overworld/001_Overworld.rb index d0892eaff..53f709a29 100644 --- a/Data/Scripts/012_Overworld/001_Overworld.rb +++ b/Data/Scripts/012_Overworld/001_Overworld.rb @@ -135,9 +135,7 @@ Events.onStepTakenFieldMovement += proc { |_sender,e| tile_id = map.data[thistile[1],thistile[2],i] next if tile_id == nil next if GameData::TerrainTag.try_get(map.terrain_tags[tile_id]).id != :SootGrass - if event == $game_player && GameData::Item.exists?(:SOOTSACK) - $Trainer.soot += 1 if $PokemonBag.pbHasItem?(:SOOTSACK) - end + $Trainer.soot += 1 if event == $game_player && $bag.has?(:SOOTSACK) # map.data[thistile[1], thistile[2], i] = 0 # $scene.createSingleSpriteset(map.map_id) break @@ -711,7 +709,7 @@ def pbItemBall(item,quantity=1) itemname = (quantity>1) ? item.name_plural : item.name pocket = item.pocket move = item.move - if $PokemonBag.pbStoreItem(item,quantity) # If item can be picked up + if $bag.add(item, quantity) # If item can be picked up meName = (item.is_key_item?) ? "Key item get" : "Item get" if item == :LEFTOVERS pbMessage(_INTL("\\me[{1}]You found some \\c[1]{2}\\c[0]!\\wtnp[30]",meName,itemname)) @@ -727,7 +725,7 @@ def pbItemBall(item,quantity=1) pbMessage(_INTL("\\me[{1}]You found a \\c[1]{2}\\c[0]!\\wtnp[30]",meName,itemname)) end pbMessage(_INTL("You put the {1} in\\nyour Bag's \\c[1]{3}\\c[0] pocket.", - itemname,pocket,PokemonBag.pocketNames()[pocket])) + itemname, pocket, PokemonBag.pocket_names[pocket])) return true end # Can't add the item @@ -771,9 +769,9 @@ def pbReceiveItem(item,quantity=1) else pbMessage(_INTL("\\me[{1}]You obtained a \\c[1]{2}\\c[0]!\\wtnp[30]",meName,itemname)) end - if $PokemonBag.pbStoreItem(item,quantity) # If item can be added + if $bag.add(item, quantity) # If item can be added pbMessage(_INTL("You put the {1} in\\nyour Bag's \\c[1]{3}\\c[0] pocket.", - itemname,pocket,PokemonBag.pocketNames()[pocket])) + itemname, pocket, PokemonBag.pocket_names[pocket])) return true end return false # Can't add the item diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb b/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb index df9200052..73b428f64 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/003_Overworld_WildEncounters.rb @@ -414,7 +414,7 @@ def pbGenerateWildPokemon(species,level,isRoamer=false) # Improve chances of shiny Pokémon with Shiny Charm and battling more of the # same species shiny_retries = 0 - shiny_retries += 2 if GameData::Item.exists?(:SHINYCHARM) && $PokemonBag.pbHasItem?(:SHINYCHARM) + shiny_retries += 2 if $bag.has?(:SHINYCHARM) if Settings::HIGHER_SHINY_CHANCES_WITH_NUMBER_BATTLED values = [0, 0] case $Trainer.pokedex.battled_count(species) diff --git a/Data/Scripts/012_Overworld/006_Overworld_BerryPlants.rb b/Data/Scripts/012_Overworld/006_Overworld_BerryPlants.rb index 4a75ca442..2404d0b10 100644 --- a/Data/Scripts/012_Overworld/006_Overworld_BerryPlants.rb +++ b/Data/Scripts/012_Overworld/006_Overworld_BerryPlants.rb @@ -354,7 +354,7 @@ def pbBerryPlant end # Water the growing plant GameData::BerryPlant::WATERING_CANS.each do |item| - next if !GameData::Item.exists?(item) || !$PokemonBag.pbHasItem?(item) + next if !$bag.has?(item) break if !pbConfirmMessage(_INTL("Want to sprinkle some water with the {1}?", GameData::Item.get(item).name)) berry_plant.water @@ -381,14 +381,14 @@ def pbBerryPlant mulch = nil pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene, $PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) mulch = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_mulch? }) } return if !mulch mulch_data = GameData::Item.get(mulch) if mulch_data.is_mulch? berry_plant.mulch_id = mulch - $PokemonBag.pbDeleteItem(mulch, 1) + $bag.remove(mulch) pbMessage(_INTL("The {1} was scattered on the soil.\1", mulch_data.name)) else pbMessage(_INTL("That won't fertilize the soil!")) @@ -408,12 +408,12 @@ def pbBerryPlant if !ask_to_plant || pbConfirmMessage(_INTL("Want to plant a Berry?")) pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene, $PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) berry = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_berry? }) } if berry berry_plant.plant(berry) - $PokemonBag.pbDeleteItem(berry, 1) + $bag.remove(berry) if Settings::NEW_BERRY_PLANTS pbMessage(_INTL("The {1} was planted in the soft, earthy soil.", GameData::Item.get(berry).name)) @@ -437,11 +437,11 @@ def pbPickBerry(berry, qty = 1) message = _INTL("There is 1 \\c[1]{1}\\c[0]!\nWant to pick it?", berry_name) end return false if !pbConfirmMessage(message) - if !$PokemonBag.pbCanStore?(berry, qty) + if !$bag.can_add?(berry, qty) pbMessage(_INTL("Too bad...\nThe Bag is full...")) return false end - $PokemonBag.pbStoreItem(berry, qty) + $bag.add(berry, qty) if qty > 1 pbMessage(_INTL("You picked the {1} \\c[1]{2}\\c[0].\\wtnp[30]", qty, berry_name)) else @@ -449,7 +449,7 @@ def pbPickBerry(berry, qty = 1) end pocket = berry.pocket pbMessage(_INTL("{1} put the \\c[1]{2}\\c[0] in the \\c[1]{4}\\c[0] Pocket.\1", - $Trainer.name, berry_name, pocket, PokemonBag.pocketNames[pocket])) + $Trainer.name, berry_name, pocket, PokemonBag.pocket_names[pocket])) if Settings::NEW_BERRY_PLANTS pbMessage(_INTL("The soil returned to its soft and earthy state.")) else diff --git a/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb b/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb index e0f35dea5..63c199410 100644 --- a/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb +++ b/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb @@ -316,7 +316,7 @@ def pbDayCareGenerateEgg # Masuda method and Shiny Charm shinyretries = 0 shinyretries += 5 if father.owner.language != mother.owner.language - shinyretries += 2 if GameData::Item.exists?(:SHINYCHARM) && $PokemonBag.pbHasItem?(:SHINYCHARM) + shinyretries += 2 if $bag.has?(:SHINYCHARM) if shinyretries>0 shinyretries.times do break if egg.shiny? @@ -380,10 +380,8 @@ Events.onStepTaken += proc { |_sender,_e| $PokemonGlobal.daycareEggSteps += 1 if $PokemonGlobal.daycareEggSteps==256 $PokemonGlobal.daycareEggSteps = 0 - compatval = [0,20,50,70][pbDayCareGetCompat] - if GameData::Item.exists?(:OVALCHARM) && $PokemonBag.pbHasItem?(:OVALCHARM) - compatval = [0,40,80,88][pbDayCareGetCompat] - end + compatval = [0, 20, 50, 70][pbDayCareGetCompat] + compatval = [0, 40, 80, 88][pbDayCareGetCompat] if $bag.has?(:OVALCHARM) $PokemonGlobal.daycareEgg = 1 if rand(100)= 0 - bag.pbDeleteItem(item) if intret == 1 && itm.consumed_after_use? + bag.remove(item) if intret == 1 && itm.consumed_after_use? return intret end pbMessage(_INTL("Can't use that here.")) @@ -654,7 +654,7 @@ def pbUseItemOnPokemon(item,pkmn,scene) pbMessage(_INTL("\\se[PC access]You booted up {1}.\1",itm.name)) { scene.pbUpdate } if pbConfirmMessage(_INTL("Do you want to teach {1} to {2}?",movename,pkmn.name)) { scene.pbUpdate } if pbLearnMove(pkmn,machine,false,true) { scene.pbUpdate } - $PokemonBag.pbDeleteItem(item) if itm.consumed_after_use? + $bag.remove(item) if itm.consumed_after_use? return true end end @@ -666,8 +666,8 @@ def pbUseItemOnPokemon(item,pkmn,scene) scene.pbClearAnnotations scene.pbHardRefresh if ret && itm.consumed_after_use? - $PokemonBag.pbDeleteItem(item) - if !$PokemonBag.pbHasItem?(item) + $bag.remove(item) + if !$bag.has?(item) pbMessage(_INTL("You used your last {1}.",itm.name)) { scene.pbUpdate } end end @@ -679,7 +679,7 @@ def pbUseKeyItemInField(item) if ret==-1 # Item effect not found pbMessage(_INTL("Can't use that here.")) elsif ret > 0 && GameData::Item.get(item).consumed_after_use? - $PokemonBag.pbDeleteItem(item) + $bag.remove(item) end return ret > 0 end @@ -719,9 +719,9 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0) scene.pbDisplay(_INTL("{1} is already holding a {2}.\1",pkmn.name,olditemname)) end if scene.pbConfirm(_INTL("Would you like to switch the two items?")) - $PokemonBag.pbDeleteItem(item) - if !$PokemonBag.pbStoreItem(pkmn.item) - if !$PokemonBag.pbStoreItem(item) + $bag.remove(item) + if !$bag.add(pkmn.item) + if !$bag.add(item) raise _INTL("Could't re-store deleted item in Bag somehow") end scene.pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed.")) @@ -732,7 +732,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0) scene.pbDisplay(_INTL("Took the {1} from {2} and gave it the {3}.",olditemname,pkmn.name,newitemname)) return true else - if !$PokemonBag.pbStoreItem(item) + if !$bag.add(item) raise _INTL("Couldn't re-store deleted item in Bag somehow") end end @@ -745,7 +745,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0) end else if !GameData::Item.get(item).is_mail? || pbWriteMail(item,pkmn,pkmnid,scene) - $PokemonBag.pbDeleteItem(item) + $bag.remove(item) pkmn.item = item scene.pbDisplay(_INTL("{1} is now holding the {2}.",pkmn.name,newitemname)) return true @@ -758,7 +758,7 @@ def pbTakeItemFromPokemon(pkmn,scene) ret = false if !pkmn.hasItem? scene.pbDisplay(_INTL("{1} isn't holding anything.",pkmn.name)) - elsif !$PokemonBag.pbCanStore?(pkmn.item) + elsif !$bag.can_add?(pkmn.item) scene.pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed.")) elsif pkmn.mail if scene.pbConfirm(_INTL("Save the removed mail in your PC?")) @@ -770,14 +770,14 @@ def pbTakeItemFromPokemon(pkmn,scene) ret = true end elsif scene.pbConfirm(_INTL("If the mail is removed, its message will be lost. OK?")) - $PokemonBag.pbStoreItem(pkmn.item) + $bag.add(pkmn.item) scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name)) pkmn.item = nil pkmn.mail = nil ret = true end else - $PokemonBag.pbStoreItem(pkmn.item) + $bag.add(pkmn.item) scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name)) pkmn.item = nil ret = true @@ -792,7 +792,7 @@ def pbChooseItem(var = 0, *args) ret = nil pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) ret = screen.pbChooseItemScreen } $game_variables[var] = ret || :NONE if var > 0 @@ -803,7 +803,7 @@ def pbChooseApricorn(var = 0) ret = nil pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_apricorn? }) } $game_variables[var] = ret || :NONE if var > 0 @@ -814,7 +814,7 @@ def pbChooseFossil(var = 0) ret = nil pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_fossil? }) } $game_variables[var] = ret || :NONE if var > 0 @@ -829,7 +829,7 @@ def pbChooseItemFromList(message, variable, *args) for item in args next if !GameData::Item.exists?(item) itm = GameData::Item.get(item) - next if !$PokemonBag.pbHasItem?(itm) + next if !$bag.has?(itm) commands.push(itm.name) itemid.push(itm.id) end diff --git a/Data/Scripts/013_Items/002_Item_Effects.rb b/Data/Scripts/013_Items/002_Item_Effects.rb index 5a16a9bf8..6669fc065 100644 --- a/Data/Scripts/013_Items/002_Item_Effects.rb +++ b/Data/Scripts/013_Items/002_Item_Effects.rb @@ -109,19 +109,17 @@ Events.onStepTaken += proc { if $PokemonGlobal.repel > 0 && !$game_player.terrain_tag.ice # Shouldn't count down if on ice $PokemonGlobal.repel -= 1 if $PokemonGlobal.repel <= 0 - if $PokemonBag.pbHasItem?(:REPEL) || - $PokemonBag.pbHasItem?(:SUPERREPEL) || - $PokemonBag.pbHasItem?(:MAXREPEL) + if $bag.has?(:REPEL) || $bag.has?(:SUPERREPEL) || $bag.has?(:MAXREPEL) if pbConfirmMessage(_INTL("The repellent's effect wore off! Would you like to use another one?")) ret = nil pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) ret = screen.pbChooseItemScreen(Proc.new { |item| [:REPEL, :SUPERREPEL, :MAXREPEL].include?(item) }) } - pbUseItem($PokemonBag,ret) if ret + pbUseItem($bag, ret) if ret end else pbMessage(_INTL("The repellent's effect wore off!")) @@ -314,13 +312,13 @@ ItemHandlers::UseInField.add(:COINCASE,proc { |item| }) ItemHandlers::UseInField.add(:EXPALL,proc { |item| - $PokemonBag.pbChangeItem(:EXPALL,:EXPALLOFF) + $bag.replace_item(:EXPALL, :EXPALLOFF) pbMessage(_INTL("The Exp Share was turned off.")) next true }) ItemHandlers::UseInField.add(:EXPALLOFF,proc { |item| - $PokemonBag.pbChangeItem(:EXPALLOFF,:EXPALL) + $bag.replace_item(:EXPALLOFF, :EXPALL) pbMessage(_INTL("The Exp Share was turned on.")) next true }) @@ -896,13 +894,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYXS, proc { |item, pkmn, scene| end gain_amount = 100 maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil - maximum = [maximum, $PokemonBag.pbQuantity(item)].min + maximum = [maximum, $bag.quantity(item)].min qty = scene.scene.pbChooseNumber( _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) next false if qty == 0 scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) - $PokemonBag.pbDeleteItem(item, qty - 1) + $bag.remove(item, qty - 1) scene.pbHardRefresh next true }) @@ -914,13 +912,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYS, proc { |item, pkmn, scene| end gain_amount = 800 maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil - maximum = [maximum, $PokemonBag.pbQuantity(item)].min + maximum = [maximum, $bag.quantity(item)].min qty = scene.scene.pbChooseNumber( _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) next false if qty == 0 scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) - $PokemonBag.pbDeleteItem(item, qty - 1) + $bag.remove(item, qty - 1) scene.pbHardRefresh next true }) @@ -932,13 +930,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYM, proc { |item, pkmn, scene| end gain_amount = 3_000 maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil - maximum = [maximum, $PokemonBag.pbQuantity(item)].min + maximum = [maximum, $bag.quantity(item)].min qty = scene.scene.pbChooseNumber( _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) next false if qty == 0 scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) - $PokemonBag.pbDeleteItem(item, qty - 1) + $bag.remove(item, qty - 1) scene.pbHardRefresh next true }) @@ -950,13 +948,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYL, proc { |item, pkmn, scene| end gain_amount = 10_000 maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil - maximum = [maximum, $PokemonBag.pbQuantity(item)].min + maximum = [maximum, $bag.quantity(item)].min qty = scene.scene.pbChooseNumber( _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) next false if qty == 0 scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) - $PokemonBag.pbDeleteItem(item, qty - 1) + $bag.remove(item, qty - 1) scene.pbHardRefresh next true }) @@ -968,13 +966,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYXL, proc { |item, pkmn, scene| end gain_amount = 30_000 maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil - maximum = [maximum, $PokemonBag.pbQuantity(item)].min + maximum = [maximum, $bag.quantity(item)].min qty = scene.scene.pbChooseNumber( _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) next false if qty == 0 scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) - $PokemonBag.pbDeleteItem(item, qty - 1) + $bag.remove(item, qty - 1) scene.pbHardRefresh next true }) @@ -1275,7 +1273,7 @@ ItemHandlers::UseOnPokemon.add(:DNASPLICERS,proc { |item,pkmn,scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:DNASPLICERS, :DNASPLICERSUSED) + $bag.replace_item(:DNASPLICERS, :DNASPLICERSUSED) next true }) @@ -1297,7 +1295,7 @@ ItemHandlers::UseOnPokemon.add(:DNASPLICERSUSED,proc { |item,pkmn,scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:DNASPLICERSUSED, :DNASPLICERS) + $bag.replace_item(:DNASPLICERSUSED, :DNASPLICERS) next true }) @@ -1332,7 +1330,7 @@ ItemHandlers::UseOnPokemon.add(:NSOLARIZER,proc { |item,pkmn,scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:NSOLARIZER, :NSOLARIZERUSED) + $bag.replace_item(:NSOLARIZER, :NSOLARIZERUSED) next true }) @@ -1354,7 +1352,7 @@ ItemHandlers::UseOnPokemon.add(:NSOLARIZERUSED,proc { |item,pkmn,scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:NSOLARIZERUSED, :NSOLARIZER) + $bag.replace_item(:NSOLARIZERUSED, :NSOLARIZER) next true }) @@ -1389,7 +1387,7 @@ ItemHandlers::UseOnPokemon.add(:NLUNARIZER,proc { |item,pkmn,scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:NLUNARIZER, :NLUNARIZERUSED) + $bag.replace_item(:NLUNARIZER, :NLUNARIZERUSED) next true }) @@ -1411,7 +1409,7 @@ ItemHandlers::UseOnPokemon.add(:NLUNARIZERUSED,proc { |item,pkmn,scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:NLUNARIZERUSED, :NLUNARIZER) + $bag.replace_item(:NLUNARIZERUSED, :NLUNARIZER) next true }) @@ -1450,7 +1448,7 @@ ItemHandlers::UseOnPokemon.add(:REINSOFUNITY, proc { |item, pkmn, scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:REINSOFUNITY, :REINSOFUNITYUSED) + $bag.replace_item(:REINSOFUNITY, :REINSOFUNITYUSED) next true }) @@ -1472,6 +1470,6 @@ ItemHandlers::UseOnPokemon.add(:REINSOFUNITYUSED, proc { |item, pkmn, scene| scene.pbHardRefresh scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) } - $PokemonBag.pbChangeItem(:REINSOFUNITYUSED, :REINSOFUNITY) + $bag.replace_item(:REINSOFUNITYUSED, :REINSOFUNITY) next true }) diff --git a/Data/Scripts/013_Items/008_PokemonBag.rb b/Data/Scripts/013_Items/008_PokemonBag.rb index aea316f95..7ba6c9182 100644 --- a/Data/Scripts/013_Items/008_PokemonBag.rb +++ b/Data/Scripts/013_Items/008_PokemonBag.rb @@ -1,57 +1,35 @@ #=============================================================================== -# The Bag object, which actually contains all the items +# The Bag object, which actually contains all the items. #=============================================================================== class PokemonBag - attr_accessor :lastpocket + attr_accessor :last_viewed_pocket + attr_accessor :last_pocket_selections + attr_reader :registered_items + attr_reader :ready_menu_selection - def self.pocketNames + def self.pocket_names return Settings.bag_pocket_names end - def self.numPockets - return self.pocketNames.length-1 + def self.pocket_count + return self.pocket_names.length - 1 end def initialize - @lastpocket = 1 - @pockets = [] - @choices = [] - for i in 0..PokemonBag.numPockets + @last_viewed_pocket = 1 + @pockets = [] + @last_pocket_selections = [] + for i in 0..PokemonBag.pocket_count @pockets[i] = [] - @choices[i] = 0 + @last_pocket_selections[i] = 0 end - @registeredItems = [] - @registeredIndex = [0, 0, 1] # Used by the Ready Menu to remember cursor positions - end - - def rearrange - return if @pockets.length == PokemonBag.numPockets + 1 - @lastpocket = 1 - new_pockets = [] - @choices = [] - for i in 0..PokemonBag.numPockets - new_pockets[i] = [] - @choices[i] = 0 - end - @pockets.each do |pocket| - next if !pocket - pocket.each do |item| - p = GameData::Item.get(item[0]).pocket - new_pockets[p].push(item) - end - end - new_pockets.each_with_index do |pocket, i| - next if i == 0 || !Settings::BAG_POCKET_AUTO_SORT[i] - pocket.sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) } - end - @pockets = new_pockets + @registered_items = [] + @ready_menu_selection = [0, 0, 1] # Used by the Ready Menu to remember cursor positions end def clear @pockets.each { |pocket| pocket.clear } - for i in 0..PokemonBag.numPockets - @choices[i] = 0 - end + (PokemonBag.pocket_count + 1).times { |i| @last_pocket_selections[i] = 0 } end def pockets @@ -59,131 +37,156 @@ class PokemonBag return @pockets end - def maxPocketSize(pocket) - maxsize = Settings::BAG_MAX_POCKET_SIZE[pocket] - return -1 if !maxsize - return maxsize - end + #============================================================================= # Gets the index of the current selected item in the pocket - def getChoice(pocket) - if pocket <= 0 || pocket > PokemonBag.numPockets + def last_viewed_index(pocket) + if pocket <= 0 || pocket > PokemonBag.pocket_count raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect)) end rearrange - return [@choices[pocket], @pockets[pocket].length].min || 0 + return [@last_pocket_selections[pocket], @pockets[pocket].length].min || 0 end # Sets the index of the current selected item in the pocket - def setChoice(pocket,value) - if pocket <= 0 || pocket > PokemonBag.numPockets + def set_last_viewed_index(pocket, value) + if pocket <= 0 || pocket > PokemonBag.pocket_count raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect)) end rearrange - @choices[pocket] = value if value <= @pockets[pocket].length + @last_pocket_selections[pocket] = value if value <= @pockets[pocket].length end - def getAllChoices - ret = @choices.clone - for i in 0...@choices.length - @choices[i] = 0 + #============================================================================= + + def quantity(item) + item_data = GameData::Item.try_get(item) + return 0 if !item_data + pocket = item_data.pocket + return ItemStorageHelper.quantity(@pockets[pocket], item_data.id) + end + + def has?(item, qty = 1) + return quantity(item) >= qty + end + alias can_remove? has? + + def can_add?(item, qty = 1) + item_data = GameData::Item.try_get(item) + return false if !item_data + pocket = item_data.pocket + max_size = max_pocket_size(pocket) + max_size = @pockets[pocket].length + 1 if max_size < 0 # Infinite size + return ItemStorageHelper.can_add?( + @pockets[pocket], max_size, Settings::BAG_MAX_PER_SLOT, item_data.id, qty) + end + + def add(item, qty = 1) + item_data = GameData::Item.try_get(item) + return false if !item_data + pocket = item_data.pocket + max_size = max_pocket_size(pocket) + max_size = @pockets[pocket].length + 1 if max_size < 0 # Infinite size + ret = ItemStorageHelper.add(@pockets[pocket], + max_size, Settings::BAG_MAX_PER_SLOT, item_data.id, qty) + if ret && Settings::BAG_POCKET_AUTO_SORT[pocket] + @pockets[pocket].sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) } end return ret end - def setAllChoices(choices) - @choices = choices + # Adds qty number of item. Doesn't add anything if it can't add all of them. + def add_all(item, qty = 1) + return false if !can_add?(item, qty) + return add(item, qty) end - def pbQuantity(item) - item = GameData::Item.get(item) + # Deletes as many of item as possible (up to qty), and returns whether it + # managed to delete qty of them. + def remove(item, qty = 1) + item_data = GameData::Item.try_get(item) + return false if !item_data pocket = item.pocket - return ItemStorageHelper.pbQuantity(@pockets[pocket], item.id) + return ItemStorageHelper.remove(@pockets[pocket], item.id, qty) end - def pbHasItem?(item) - return pbQuantity(item) > 0 + # Deletes qty number of item. Doesn't delete anything if there are less than + # qty of the item in the Bag. + def remove_all(item, qty = 1) + return false if !can_remove?(item, qty) + return remove(item, qty) end - def pbCanStore?(item, qty = 1) - item = GameData::Item.get(item) - pocket = item.pocket - maxsize = maxPocketSize(pocket) - maxsize = @pockets[pocket].length + 1 if maxsize < 0 - return ItemStorageHelper.pbCanStore?( - @pockets[pocket], maxsize, Settings::BAG_MAX_PER_SLOT, item.id, qty) - end - - def pbStoreItem(item, qty = 1) - item = GameData::Item.get(item) - pocket = item.pocket - maxsize = maxPocketSize(pocket) - maxsize = @pockets[pocket].length + 1 if maxsize < 0 - return ItemStorageHelper.pbStoreItem( - @pockets[pocket], maxsize, Settings::BAG_MAX_PER_SLOT, item.id, qty, true) - end - - def pbStoreAllOrNone(item, qty = 1) - return false if !pbCanStore?(item, qty) - return pbStoreItem(item, qty) - end - - def pbChangeItem(old_item, new_item) - old_item = GameData::Item.get(old_item) - new_item = GameData::Item.get(new_item) - pocket = old_item.pocket + # This only works if the old and new items are in the same pocket. Used for + # switching on/off certain Key Items. Replaces all old_item in its pocket with + # new_item. + def replace_item(old_item, new_item) + old_item_data = GameData::Item.try_get(old_item) + new_item_data = GameData::Item.try_get(new_item) + return false if !old_item_data || !new_item_data + pocket = old_item_data.pocket + old_id = old_item_data.id + new_id = new_item_data.id ret = false @pockets[pocket].each do |item| - next if !item || item[0] != old_item.id - item[0] = new_item.id + next if !item || item[0] != old_id + item[0] = new_id ret = true end return ret end - def pbChangeQuantity(pocket, index, newqty = 1) - return false if pocket <= 0 || pocket > self.numPockets - return false if !@pockets[pocket][index] - newqty = [newqty, maxPocketSize(pocket)].min - @pockets[pocket][index][1] = newqty - return true - end + #============================================================================= - def pbDeleteItem(item, qty = 1) - item = GameData::Item.get(item) - pocket = item.pocket - ret = ItemStorageHelper.pbDeleteItem(@pockets[pocket], item.id, qty) - return ret - end - - def registeredItems - @registeredItems = [] if !@registeredItems - return @registeredItems - end - - def pbIsRegistered?(item) - item = GameData::Item.get(item).id - registeredlist = self.registeredItems - return registeredlist.include?(item) + # Returns whether item has been registered for quick access in the Ready Menu. + def registered?(item) + item_data = GameData::Item.try_get(item) + return false if !item_data + return @registered_items.include?(item_data.id) end # Registers the item in the Ready Menu. - def pbRegisterItem(item) - item = GameData::Item.get(item).id - registeredlist = self.registeredItems - registeredlist.push(item) if !registeredlist.include?(item) + def register(item) + item_data = GameData::Item.try_get(item) + return if !item_data + @registered_items.push(item_data.id) if !@registered_items.include?(item_data.id) end # Unregisters the item from the Ready Menu. - def pbUnregisterItem(item) - item = GameData::Item.get(item).id - registeredlist = self.registeredItems - registeredlist.delete_at(registeredlist.index(item)) + def unregister(item) + item_data = GameData::Item.try_get(item) + @registered_items.delete(item_data.id) if item_data end - def registeredIndex - @registeredIndex = [0, 0, 1] if !@registeredIndex - return @registeredIndex + #============================================================================= + + private + + def max_pocket_size(pocket) + return Settings::BAG_MAX_POCKET_SIZE[pocket] || -1 + end + + def rearrange + return if @pockets.length == PokemonBag.pocket_count + 1 + @last_viewed_pocket = 1 + new_pockets = [] + @last_pocket_selections = [] + (PokemonBag.pocket_count + 1).times do |i| + new_pockets[i] = [] + @last_pocket_selections[i] = 0 + end + @pockets.each do |pocket| + next if !pocket + pocket.each do |item| + item_pocket = GameData::Item.get(item[0]).pocket + new_pockets[item_pocket].push(item) + end + end + new_pockets.each_with_index do |pocket, i| + next if i == 0 || !Settings::BAG_POCKET_AUTO_SORT[i] + pocket.sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) } + end + @pockets = new_pockets end end @@ -201,7 +204,7 @@ class PCItemStorage def initialize @items = [] # Start storage with a Potion - pbStoreItem(:POTION) if GameData::Item.exists?(:POTION) + add(:POTION) if GameData::Item.exists?(:POTION) end def [](i) @@ -220,32 +223,35 @@ class PCItemStorage @items.clear end - def getItem(index) + # Unused + def get_item(index) return (index < 0 || index >= @items.length) ? nil : @items[index][0] end - def getCount(index) + # Number of the item in the given index + # Unused + def get_item_count(index) return (index < 0 || index >= @items.length) ? 0 : @items[index][1] end - def pbQuantity(item) + def quantity(item) item = GameData::Item.get(item).id - return ItemStorageHelper.pbQuantity(@items, item) + return ItemStorageHelper.quantity(@items, item) end - def pbCanStore?(item, qty = 1) + def can_add?(item, qty = 1) item = GameData::Item.get(item).id - return ItemStorageHelper.pbCanStore?(@items, MAX_SIZE, MAX_PER_SLOT, item, qty) + return ItemStorageHelper.can_add?(@items, MAX_SIZE, MAX_PER_SLOT, item, qty) end - def pbStoreItem(item, qty = 1) + def add(item, qty = 1) item = GameData::Item.get(item).id - return ItemStorageHelper.pbStoreItem(@items, MAX_SIZE, MAX_PER_SLOT, item, qty) + return ItemStorageHelper.add(@items, MAX_SIZE, MAX_PER_SLOT, item, qty) end - def pbDeleteItem(item, qty = 1) + def remove(item, qty = 1) item = GameData::Item.get(item).id - return ItemStorageHelper.pbDeleteItem(@items, item, qty) + return ItemStorageHelper.remove(@items, item, qty) end end @@ -257,25 +263,62 @@ end # Used by the Bag, PC item storage, and Triple Triad. #=============================================================================== module ItemStorageHelper - # Returns the quantity of check_item in item_array - def self.pbQuantity(item_array, check_item) + # Returns the quantity of item in items + def self.quantity(items, item) ret = 0 - item_array.each { |i| ret += i[1] if i && i[0] == check_item } + items.each { |i| ret += i[1] if i && i[0] == item } return ret end + def self.can_add?(items, max_slots, max_per_slot, item, qty) + raise "Invalid value for qty: #{qty}" if qty < 0 + return true if qty == 0 + max_slots.times do |i| + item_slot = items[i] + if !item_slot + qty -= [qty, max_per_slot].min + return true if qty == 0 + elsif item_slot[0] == item && item_slot[1] < max_per_slot + new_amt = item_slot[1] + new_amt = [new_amt + qty, max_per_slot].min + qty -= (new_amt - item_slot[1]) + return true if qty == 0 + end + end + return false + end + + def self.add(items, max_slots, max_per_slot, item, qty) + raise "Invalid value for qty: #{qty}" if qty < 0 + return true if qty == 0 + max_slots.times do |i| + item_slot = items[i] + if !item_slot + items[i] = [item, [qty, max_per_slot].min] + qty -= items[i][1] + return true if qty == 0 + elsif item_slot[0] == item && item_slot[1] < max_per_slot + new_amt = item_slot[1] + new_amt = [new_amt + qty, max_per_slot].min + qty -= (new_amt - item_slot[1]) + item_slot[1] = new_amt + return true if qty == 0 + end + end + return false + end + # Deletes an item (items array, max. size per slot, item, no. of items to delete) - def self.pbDeleteItem(items, item, qty) + def self.remove(items, item, qty) raise "Invalid value for qty: #{qty}" if qty < 0 return true if qty == 0 ret = false - for i in 0...items.length - itemslot = items[i] - next if !itemslot || itemslot[0] != item - amount = [qty, itemslot[1]].min - itemslot[1] -= amount + items.each_with_index do |item_slot, i| + next if !item_slot || item_slot[0] != item + amount = [qty, item_slot[1]].min + item_slot[1] -= amount qty -= amount - items[i] = nil if itemslot[1] == 0 + items[i] = nil if item_slot[1] == 0 next if qty > 0 ret = true break @@ -283,72 +326,86 @@ module ItemStorageHelper items.compact! return ret end - - def self.pbCanStore?(items, maxsize, maxPerSlot, item, qty) - raise "Invalid value for qty: #{qty}" if qty < 0 - return true if qty == 0 - for i in 0...maxsize - itemslot = items[i] - if !itemslot - qty -= [qty, maxPerSlot].min - return true if qty == 0 - elsif itemslot[0] == item && itemslot[1] < maxPerSlot - newamt = itemslot[1] - newamt = [newamt + qty, maxPerSlot].min - qty -= (newamt - itemslot[1]) - return true if qty == 0 - end - end - return false - end - - def self.pbStoreItem(items, maxsize, maxPerSlot, item, qty, sorting = false) - raise "Invalid value for qty: #{qty}" if qty < 0 - return true if qty == 0 - itm = GameData::Item.try_get(item) - itemPocket = (itm) ? itm.pocket : 0 - for i in 0...maxsize - itemslot = items[i] - if !itemslot - items[i] = [item, [qty, maxPerSlot].min] - qty -= items[i][1] - if itemPocket > 0 && sorting && Settings::BAG_POCKET_AUTO_SORT[itemPocket] - items.sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) } - end - return true if qty == 0 - elsif itemslot[0] == item && itemslot[1] < maxPerSlot - newamt = itemslot[1] - newamt = [newamt + qty, maxPerSlot].min - qty -= (newamt - itemslot[1]) - itemslot[1] = newamt - return true if qty == 0 - end - end - return false - end end #=============================================================================== -# Shortcut methods +# Deprecated methods #=============================================================================== -def pbQuantity(*args) - return $PokemonBag.pbQuantity(*args) +class PokemonBag + def pbQuantity(item) + Deprecation.warn_method('pbQuantity', 'v21', '$bag.quantity(item)') + return quantity(item) + end + + def pbHasItem?(item) + Deprecation.warn_method('pbHasItem?', 'v21', '$bag.has?(item)') + return has?(item) + end + + def pbCanStore?(item, quantity = 1) + Deprecation.warn_method('pbCanStore?', 'v21', '$bag.can_add?(item, quantity)') + return can_add?(item, quantity) + end + + def pbStoreItem(item, quantity = 1) + Deprecation.warn_method('pbStoreItem', 'v21', '$bag.add(item, quantity)') + return add(item, quantity) + end + + def pbStoreAllOrNone(item, quantity = 1) + Deprecation.warn_method('pbStoreAllOrNone', 'v21', '$bag.add_all(item, quantity)') + return add_all(item, quantity) + end + + def pbChangeItem(old_item, new_item) + Deprecation.warn_method('pbChangeItem', 'v21', '$bag.replace_item(old_item, new_item)') + return replace_item(old_item, new_item) + end + + def pbDeleteItem(item, quantity = 1) + Deprecation.warn_method('pbDeleteItem', 'v21', '$bag.remove(item, quantity)') + return remove(item, quantity) + end + + def pbIsRegistered?(item) + Deprecation.warn_method('pbIsRegistered?', 'v21', '$bag.registered?(item)') + return registered?(item) + end + + def pbRegisterItem(item) + Deprecation.warn_method('pbRegisterItem', 'v21', '$bag.register(item)') + register(item) + end + + def pbUnregisterItem(item) + Deprecation.warn_method('pbUnregisterItem', 'v21', '$bag.unregister(item)') + unregister(item) + end end -def pbHasItem?(*args) - return $PokemonBag.pbHasItem?(*args) +def pbQuantity(item) + Deprecation.warn_method('pbQuantity', 'v21', '$bag.quantity(item)') + return $bag.quantity(item) end -def pbCanStore?(*args) - return $PokemonBag.pbCanStore?(*args) +def pbHasItem?(item) + Deprecation.warn_method('pbHasItem?', 'v21', '$bag.has?(item)') + return $bag.has?(item) end -def pbStoreItem(*args) - return $PokemonBag.pbStoreItem(*args) +def pbCanStore?(item, quantity = 1) + Deprecation.warn_method('pbCanStore?', 'v21', '$bag.can_add?(item, quantity)') + return $bag.can_add?(item, quantity) end -def pbStoreAllOrNone(*args) - return $PokemonBag.pbStoreAllOrNone(*args) +def pbStoreItem(item, quantity = 1) + Deprecation.warn_method('pbStoreItem', 'v21', '$bag.add(item, quantity)') + return $bag.add(item, quantity) +end + +def pbStoreAllOrNone(item, quantity = 1) + Deprecation.warn_method('pbStoreAllOrNone', 'v21', '$bag.add_all(item, quantity)') + return $bag.add_all(item, quantity) end diff --git a/Data/Scripts/016_UI/001_UI_PauseMenu.rb b/Data/Scripts/016_UI/001_UI_PauseMenu.rb index f1614fc31..5b8c23f10 100644 --- a/Data/Scripts/016_UI/001_UI_PauseMenu.rb +++ b/Data/Scripts/016_UI/001_UI_PauseMenu.rb @@ -192,7 +192,7 @@ class PokemonPauseMenu item = nil pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) item = screen.pbStartScreen (item) ? @scene.pbEndScene : @scene.pbRefresh } diff --git a/Data/Scripts/016_UI/005_UI_Party.rb b/Data/Scripts/016_UI/005_UI_Party.rb index 22408c6db..8769bbed6 100644 --- a/Data/Scripts/016_UI/005_UI_Party.rb +++ b/Data/Scripts/016_UI/005_UI_Party.rb @@ -1149,7 +1149,7 @@ class PokemonPartyScreen def pbPokemonScreen can_access_storage = false - if GameData::Item.exists?(:POKEMONBOXLINK) && $PokemonBag.pbHasItem?(:POKEMONBOXLINK) + if $bag.has?(:POKEMONBOXLINK) if !$game_switches[Settings::DISABLE_BOX_LINK_SWITCH] && !$game_map.metadata&.has_flag?("DisableBoxLink") can_access_storage = true @@ -1298,7 +1298,7 @@ class PokemonPartyScreen itemcommands[itemcommands.length] = _INTL("Cancel") command = @scene.pbShowCommands(_INTL("Do what with an item?"),itemcommands) if cmdUseItem>=0 && command==cmdUseItem # Use - item = @scene.pbUseItem($PokemonBag,pkmn) { + item = @scene.pbUseItem($bag,pkmn) { @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel.")) } if item @@ -1306,7 +1306,7 @@ class PokemonPartyScreen pbRefreshSingle(pkmnid) end elsif cmdGiveItem>=0 && command==cmdGiveItem # Give - item = @scene.pbChooseItem($PokemonBag) { + item = @scene.pbChooseItem($bag) { @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel.")) } if item diff --git a/Data/Scripts/016_UI/006_UI_Summary.rb b/Data/Scripts/016_UI/006_UI_Summary.rb index 0567fe3e7..47a5319aa 100644 --- a/Data/Scripts/016_UI/006_UI_Summary.rb +++ b/Data/Scripts/016_UI/006_UI_Summary.rb @@ -1198,7 +1198,7 @@ class PokemonSummary_Scene item = nil pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) item = screen.pbChooseItemScreen(Proc.new { |itm| GameData::Item.get(itm).can_hold? }) } if item diff --git a/Data/Scripts/016_UI/007_UI_Bag.rb b/Data/Scripts/016_UI/007_UI_Bag.rb index fefbf90b9..c738499c9 100644 --- a/Data/Scripts/016_UI/007_UI_Bag.rb +++ b/Data/Scripts/016_UI/007_UI_Bag.rb @@ -25,7 +25,7 @@ class Window_PokemonBag < Window_DrawableCommand def pocket=(value) @pocket = value @item_max = (@filterlist) ? @filterlist[@pocket].length+1 : @bag.pockets[@pocket].length+1 - self.index = @bag.getChoice(@pocket) + self.index = @bag.last_viewed_index(@pocket) end def page_row_max; return PokemonBag_Scene::ITEMSVISIBLE; end @@ -79,7 +79,7 @@ class Window_PokemonBag < Window_DrawableCommand [@adapter.getDisplayName(item),rect.x,rect.y-2,false,baseColor,shadowColor] ) if GameData::Item.get(item).is_important? - if @bag.pbIsRegistered?(item) + if @bag.registered?(item) pbDrawImagePositions(self.contents,[ ["Graphics/Pictures/Bag/icon_register",rect.x+rect.width-72,rect.y+8,0,0,-1,24] ]) @@ -142,7 +142,7 @@ class PokemonBag_Scene @choosing = choosing @filterproc = filterproc pbRefreshFilter - lastpocket = @bag.lastpocket + lastpocket = @bag.last_viewed_pocket numfilledpockets = @bag.pockets.length-1 if @choosing numfilledpockets = 0 @@ -155,7 +155,7 @@ class PokemonBag_Scene numfilledpockets += 1 if @bag.pockets[i].length>0 end end - lastpocket = (resetpocket) ? 1 : @bag.lastpocket + lastpocket = (resetpocket) ? 1 : @bag.last_viewed_pocket if (@filterlist && @filterlist[lastpocket].length==0) || (!@filterlist && @bag.pockets[lastpocket].length==0) for i in 1...@bag.pockets.length @@ -169,7 +169,7 @@ class PokemonBag_Scene end end end - @bag.lastpocket = lastpocket + @bag.last_viewed_pocket = lastpocket @sliderbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_slider")) @pocketbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_pocket")) @sprites = {} @@ -193,7 +193,7 @@ class PokemonBag_Scene @sprites["itemlist"] = Window_PokemonBag.new(@bag,@filterlist,lastpocket,168,-8,314,40+32+ITEMSVISIBLE*32) @sprites["itemlist"].viewport = @viewport @sprites["itemlist"].pocket = lastpocket - @sprites["itemlist"].index = @bag.getChoice(lastpocket) + @sprites["itemlist"].index = @bag.last_viewed_index(lastpocket) @sprites["itemlist"].baseColor = ITEMLISTBASECOLOR @sprites["itemlist"].shadowColor = ITEMLISTSHADOWCOLOR @sprites["itemicon"] = ItemIconSprite.new(48,Graphics.height-48,nil,@viewport) @@ -251,13 +251,13 @@ class PokemonBag_Scene def pbRefresh # Set the background image - @sprites["background"].setBitmap(sprintf("Graphics/Pictures/Bag/bg_#{@bag.lastpocket}")) + @sprites["background"].setBitmap(sprintf("Graphics/Pictures/Bag/bg_#{@bag.last_viewed_pocket}")) # Set the bag sprite - fbagexists = pbResolveBitmap(sprintf("Graphics/Pictures/Bag/bag_#{@bag.lastpocket}_f")) + fbagexists = pbResolveBitmap(sprintf("Graphics/Pictures/Bag/bag_#{@bag.last_viewed_pocket}_f")) if $Trainer.female? && fbagexists - @sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.lastpocket}_f") + @sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.last_viewed_pocket}_f") else - @sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.lastpocket}") + @sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.last_viewed_pocket}") end # Draw the pocket icons @sprites["pocketicon"].bitmap.clear @@ -283,7 +283,7 @@ class PokemonBag_Scene overlay.clear # Draw the pocket name pbDrawTextPositions(overlay,[ - [PokemonBag.pocketNames[@bag.lastpocket],94,176,2,POCKETNAMEBASECOLOR,POCKETNAMESHADOWCOLOR] + [PokemonBag.pocket_names[@bag.last_viewed_pocket], 94, 176, 2, POCKETNAMEBASECOLOR, POCKETNAMESHADOWCOLOR] ]) # Draw slider arrows showslider = false @@ -353,7 +353,7 @@ class PokemonBag_Scene thispocket.insert(itemwindow.index,thispocket.delete_at(oldindex)) end # Update selected item for current pocket - @bag.setChoice(itemwindow.pocket,itemwindow.index) + @bag.set_last_viewed_index(itemwindow.pocket,itemwindow.index) pbRefresh end if itemwindow.sorting @@ -374,7 +374,7 @@ class PokemonBag_Scene if Input.trigger?(Input::LEFT) newpocket = itemwindow.pocket loop do - newpocket = (newpocket==1) ? PokemonBag.numPockets : newpocket-1 + newpocket = (newpocket==1) ? PokemonBag.pocket_count : newpocket-1 break if !@choosing || newpocket==itemwindow.pocket if @filterlist break if @filterlist[newpocket].length>0 @@ -384,7 +384,7 @@ class PokemonBag_Scene end if itemwindow.pocket!=newpocket itemwindow.pocket = newpocket - @bag.lastpocket = itemwindow.pocket + @bag.last_viewed_pocket = itemwindow.pocket thispocket = @bag.pockets[itemwindow.pocket] pbPlayCursorSE pbRefresh @@ -392,7 +392,7 @@ class PokemonBag_Scene elsif Input.trigger?(Input::RIGHT) newpocket = itemwindow.pocket loop do - newpocket = (newpocket==PokemonBag.numPockets) ? 1 : newpocket+1 + newpocket = (newpocket==PokemonBag.pocket_count) ? 1 : newpocket+1 break if !@choosing || newpocket==itemwindow.pocket if @filterlist break if @filterlist[newpocket].length>0 @@ -402,17 +402,17 @@ class PokemonBag_Scene end if itemwindow.pocket!=newpocket itemwindow.pocket = newpocket - @bag.lastpocket = itemwindow.pocket + @bag.last_viewed_pocket = itemwindow.pocket thispocket = @bag.pockets[itemwindow.pocket] pbPlayCursorSE pbRefresh end # elsif Input.trigger?(Input::SPECIAL) # Register/unregister selected item # if !@choosing && itemwindow.index 0 && itm.can_hold? commands[cmdToss = commands.length] = _INTL("Toss") if !itm.is_important? || $DEBUG - if @bag.pbIsRegistered?(item) + if @bag.registered?(item) commands[cmdRegister = commands.length] = _INTL("Deselect") elsif pbCanRegisterItem?(item) commands[cmdRegister = commands.length] = _INTL("Register") @@ -508,7 +508,7 @@ class PokemonBagScreen } end elsif cmdToss>=0 && command==cmdToss # Toss item - qty = @bag.pbQuantity(item) + qty = @bag.quantity(item) if qty>1 helptext = _INTL("Toss out how many {1}?",itm.name_plural) qty = @scene.pbChooseNumber(helptext,qty) @@ -517,15 +517,15 @@ class PokemonBagScreen itemname = itm.name_plural if qty>1 if pbConfirm(_INTL("Is it OK to throw away {1} {2}?",qty,itemname)) pbDisplay(_INTL("Threw away {1} {2}.",qty,itemname)) - qty.times { @bag.pbDeleteItem(item) } + qty.times { @bag.remove(item) } @scene.pbRefresh end end elsif cmdRegister>=0 && command==cmdRegister # Register item - if @bag.pbIsRegistered?(item) - @bag.pbUnregisterItem(item) + if @bag.registered?(item) + @bag.unregister(item) else - @bag.pbRegisterItem(item) + @bag.register(item) end @scene.pbRefresh elsif cmdDebug>=0 && command==cmdDebug # Debug @@ -542,7 +542,7 @@ class PokemonBagScreen break ### Change quantity ### when 0 - qty = @bag.pbQuantity(item) + qty = @bag.quantity(item) itemplural = itm.name_plural params = ChooseNumberParams.new params.setRange(0, Settings::BAG_MAX_PER_SLOT) @@ -550,9 +550,9 @@ class PokemonBagScreen newqty = pbMessageChooseNumber( _INTL("Choose new quantity of {1} (max. #{Settings::BAG_MAX_PER_SLOT}).",itemplural),params) { @scene.pbUpdate } if newqty>qty - @bag.pbStoreItem(item,newqty-qty) + @bag.add(item, newqty - qty) elsif newqty1 && !itm.is_important? qty = @scene.pbChooseNumber(_INTL("How many do you want to withdraw?"),qty) end next if qty<=0 - if @bag.pbCanStore?(item,qty) - if !storage.pbDeleteItem(item,qty) + if @bag.can_add?(item,qty) + if !storage.remove(item,qty) raise "Can't delete items from storage" end - if !@bag.pbStoreItem(item,qty) + if !@bag.add(item,qty) raise "Can't withdraw items from storage" end @scene.pbRefresh @@ -632,18 +632,18 @@ class PokemonBagScreen item = @scene.pbChooseItem break if !item itm = GameData::Item.get(item) - qty = @bag.pbQuantity(item) + qty = @bag.quantity(item) if qty>1 && !itm.is_important? qty = @scene.pbChooseNumber(_INTL("How many do you want to deposit?"),qty) end if qty>0 - if !storage.pbCanStore?(item,qty) + if !storage.can_add?(item,qty) pbDisplay(_INTL("There's no room to store items.")) else - if !@bag.pbDeleteItem(item,qty) + if !@bag.remove(item,qty) raise "Can't delete items from Bag" end - if !storage.pbStoreItem(item,qty) + if !storage.add(item,qty) raise "Can't deposit items to storage" end @scene.pbRefresh @@ -671,7 +671,7 @@ class PokemonBagScreen @scene.pbDisplay(_INTL("That's too important to toss out!")) next end - qty = storage.pbQuantity(item) + qty = storage.quantity(item) itemname = itm.name itemnameplural = itm.name_plural if qty>1 @@ -680,7 +680,7 @@ class PokemonBagScreen if qty>0 itemname = itemnameplural if qty>1 if pbConfirm(_INTL("Is it OK to throw away {1} {2}?",qty,itemname)) - if !storage.pbDeleteItem(item,qty) + if !storage.remove(item,qty) raise "Can't delete items from storage" end @scene.pbRefresh diff --git a/Data/Scripts/016_UI/016_UI_ReadyMenu.rb b/Data/Scripts/016_UI/016_UI_ReadyMenu.rb index 39cdf18df..98f8c743c 100644 --- a/Data/Scripts/016_UI/016_UI_ReadyMenu.rb +++ b/Data/Scripts/016_UI/016_UI_ReadyMenu.rb @@ -75,7 +75,7 @@ class ReadyMenuButton < SpriteWrapper ] if !@command[2] if !GameData::Item.get(@command[0]).is_important? - qty = $PokemonBag.pbQuantity(@command[0]) + qty = $bag.quantity(@command[0]) if qty>99 textpos.push([_INTL(">99"),230,16,1, Color.new(248,248,248),Color.new(40,40,40),1]) @@ -110,7 +110,7 @@ class PokemonReadyMenu_Scene for i in 0...@commands[1].length @itemcommands.push(@commands[1][i][1]) end - @index = $PokemonBag.registeredIndex + @index = $bag.ready_menu_selection if @index[0]>=@movecommands.length && @movecommands.length>0 @index[0] = @movecommands.length-1 end @@ -312,9 +312,9 @@ def pbUseKeyItem end end real_items = [] - for i in $PokemonBag.registeredItems + for i in $bag.registered_items itm = GameData::Item.get(i).id - real_items.push(itm) if $PokemonBag.pbHasItem?(itm) + real_items.push(itm) if $bag.has?(itm) end if real_items.length == 0 && real_moves.length == 0 pbMessage(_INTL("An item in the Bag can be registered to this key for instant use.")) diff --git a/Data/Scripts/016_UI/017_UI_PokemonStorage.rb b/Data/Scripts/016_UI/017_UI_PokemonStorage.rb index 1b80ee5eb..9e0060a8a 100644 --- a/Data/Scripts/016_UI/017_UI_PokemonStorage.rb +++ b/Data/Scripts/016_UI/017_UI_PokemonStorage.rb @@ -1873,7 +1873,7 @@ class PokemonStorageScreen if pokemon.item itemname = pokemon.item.name if pbConfirm(_INTL("Take this {1}?",itemname)) - if !$PokemonBag.pbStoreItem(pokemon.item) + if !$bag.add(pokemon.item) pbDisplay(_INTL("Can't store the {1}.",itemname)) else pbDisplay(_INTL("Took the {1}.",itemname)) @@ -1882,11 +1882,11 @@ class PokemonStorageScreen end end else - item = scene.pbChooseItem($PokemonBag) + item = scene.pbChooseItem($bag) if item itemname = GameData::Item.get(item).name pokemon.item = item - $PokemonBag.pbDeleteItem(item) + $bag.remove(item) pbDisplay(_INTL("{1} is now being held.",itemname)) @scene.pbHardRefresh end diff --git a/Data/Scripts/016_UI/019_UI_PC.rb b/Data/Scripts/016_UI/019_UI_PC.rb index ad84530f3..8f2587fa4 100644 --- a/Data/Scripts/016_UI/019_UI_PC.rb +++ b/Data/Scripts/016_UI/019_UI_PC.rb @@ -134,14 +134,14 @@ def pbPCItemStorage else pbFadeOutIn { scene = WithdrawItemScene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) screen.pbWithdrawItemScreen } end when 1 # Deposit Item pbFadeOutIn { scene = PokemonBag_Scene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) screen.pbDepositItemScreen } when 2 # Toss Item @@ -153,7 +153,7 @@ def pbPCItemStorage else pbFadeOutIn { scene = TossItemScene.new - screen = PokemonBagScreen.new(scene,$PokemonBag) + screen = PokemonBagScreen.new(scene, $bag) screen.pbTossItemScreen } end @@ -191,7 +191,7 @@ def pbPCMailbox } when 1 # Move to Bag if pbConfirmMessage(_INTL("The message will be lost. Is that OK?")) - if $PokemonBag.pbStoreItem($PokemonGlobal.mailbox[mailIndex].item) + if $bag.add($PokemonGlobal.mailbox[mailIndex].item) pbMessage(_INTL("The Mail was returned to the Bag with its message erased.")) $PokemonGlobal.mailbox.delete_at(mailIndex) else diff --git a/Data/Scripts/016_UI/020_UI_PokeMart.rb b/Data/Scripts/016_UI/020_UI_PokeMart.rb index 4ed0abdcd..064b13f74 100644 --- a/Data/Scripts/016_UI/020_UI_PokeMart.rb +++ b/Data/Scripts/016_UI/020_UI_PokeMart.rb @@ -15,7 +15,7 @@ class PokemonMartAdapter end def getInventory - return $PokemonBag + return $bag end def getName(item) @@ -45,7 +45,7 @@ class PokemonMartAdapter end def getQuantity(item) - return $PokemonBag.pbQuantity(item) + return $bag.quantity(item) end def showQuantity?(item) @@ -74,11 +74,11 @@ class PokemonMartAdapter end def addItem(item) - return $PokemonBag.pbStoreItem(item) + return $bag.add(item) end def removeItem(item) - return $PokemonBag.pbDeleteItem(item) + return $bag.remove(item) end end @@ -241,7 +241,7 @@ class PokemonMart_Scene end def pbStartSellScene(bag, adapter) - if $PokemonBag + if $bag pbStartSellScene2(bag, adapter) else pbStartBuyOrSellScene(false, bag, adapter) @@ -588,9 +588,9 @@ class PokemonMartScreen pbDisplayPaused(_INTL("You have no more room in the Bag.")) else @adapter.setMoney(@adapter.getMoney-price) - @stock.delete_if { |item| GameData::Item.get(item).is_important? && $PokemonBag.pbHasItem?(item) } + @stock.delete_if { |item| GameData::Item.get(item).is_important? && $bag.has?(item) } pbDisplayPaused(_INTL("Here you are! Thank you!")) { pbSEPlay("Mart buy item") } - if quantity >= 10 && $PokemonBag && GameData::Item.exists?(:PREMIERBALL) + if quantity >= 10 && $bag && GameData::Item.exists?(:PREMIERBALL) if Settings::MORE_BONUS_PREMIER_BALLS && GameData::Item.get(item).is_poke_ball? premier_balls_added = 0 (quantity / 10).times do @@ -655,7 +655,7 @@ end # #=============================================================================== def pbPokemonMart(stock,speech=nil,cantsell=false) - stock.delete_if { |item| GameData::Item.get(item).is_important? && $PokemonBag.pbHasItem?(item) } + stock.delete_if { |item| GameData::Item.get(item).is_important? && $bag.has?(item) } commands = [] cmdBuy = -1 cmdSell = -1 diff --git a/Data/Scripts/016_UI/023_UI_MysteryGift.rb b/Data/Scripts/016_UI/023_UI_MysteryGift.rb index 50b46dea5..3fa8f04da 100644 --- a/Data/Scripts/016_UI/023_UI_MysteryGift.rb +++ b/Data/Scripts/016_UI/023_UI_MysteryGift.rb @@ -396,8 +396,8 @@ def pbReceiveMysteryGift(id) elsif gift[1]>0 # Item item=gift[2] qty=gift[1] - if $PokemonBag.pbCanStore?(item,qty) - $PokemonBag.pbStoreItem(item,qty) + if $bag.can_add?(item,qty) + $bag.add(item,qty) itm = GameData::Item.get(item) itemname=(qty>1) ? itm.name_plural : itm.name if item == :LEFTOVERS diff --git a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb index ce2c5b6cf..1d79b4645 100644 --- a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb +++ b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb @@ -301,7 +301,7 @@ class TriadScene elsif Input.trigger?(Input::USE) break if chosenCards.length==@battle.maxCards item = cardStorage[command.index] - if !item || @battle.pbQuantity(cardStorage,item[0])==0 + if !item || @battle.quantity(cardStorage,item[0])==0 pbPlayBuzzerSE else pbPlayDecisionSE @@ -631,17 +631,17 @@ class TriadScreen return @board[y*@width+x] end - def pbQuantity(items,item) - return ItemStorageHelper.pbQuantity(items, item) + def quantity(items,item) + return ItemStorageHelper.quantity(items, item) end def pbAdd(items,item) - return ItemStorageHelper.pbStoreItem(items,$PokemonGlobal.triads.maxSize, - $PokemonGlobal.triads.maxPerSlot,item,1) + return ItemStorageHelper.add(items, $PokemonGlobal.triads.maxSize, + TriadStorage::MAX_PER_SLOT, item, 1) end def pbSubtract(items, item) - return ItemStorageHelper.pbDeleteItem(items, item, 1) + return ItemStorageHelper.remove(items, item, 1) end def flipBoard(x,y,attackerParam=nil,recurse=false) @@ -718,11 +718,8 @@ class TriadScreen count = 0 for i in 0...$PokemonGlobal.triads.length item = $PokemonGlobal.triads[i] - ItemStorageHelper.pbStoreItem(@triadCards, - $PokemonGlobal.triads.maxSize, - $PokemonGlobal.triads.maxPerSlot, - item[0],item[1] - ) + ItemStorageHelper.add(@triadCards, $PokemonGlobal.triads.maxSize, + TriadStorage::MAX_PER_SLOT, item[0], item[1]) count += item[1] # Add item count to total count end @board = [] @@ -880,15 +877,15 @@ class TriadScreen if @trade==1 # Keep only cards of your color for card in originalCards - $PokemonGlobal.triads.pbDeleteItem(card) + $PokemonGlobal.triads.remove(card) end for i in cards - $PokemonGlobal.triads.pbStoreItem(i) + $PokemonGlobal.triads.add(i) end for i in 0...@width*@height if board[i].owner==1 card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id - $PokemonGlobal.triads.pbStoreItem(card) + $PokemonGlobal.triads.add(card) end end @scene.pbDisplayPaused(_INTL("Kept all cards of your color.")) @@ -898,34 +895,34 @@ class TriadScreen result = 1 if prize species_data = GameData::Species.try_get(prize) - if species_data && $PokemonGlobal.triads.pbStoreItem(species_data.id) + if species_data && $PokemonGlobal.triads.add(species_data.id) @scene.pbDisplayPaused(_INTL("Got opponent's {1} card.", species_data.name)) end else case @trade when 0 # Gain 1 random card from opponent's deck card = originalOpponentCards[rand(originalOpponentCards.length)] - if $PokemonGlobal.triads.pbStoreItem(card) + if $PokemonGlobal.triads.add(card) cardname = GameData::Species.get(card).name @scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname)) end when 1 # Keep only cards of your color for card in originalCards - $PokemonGlobal.triads.pbDeleteItem(card) + $PokemonGlobal.triads.remove(card) end for i in cards - $PokemonGlobal.triads.pbStoreItem(i) + $PokemonGlobal.triads.add(i) end for i in 0...@width*@height if board[i].owner==1 card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id - $PokemonGlobal.triads.pbStoreItem(card) + $PokemonGlobal.triads.add(card) end end @scene.pbDisplayPaused(_INTL("Kept all cards of your color.")) when 2 # Gain all opponent's cards for card in originalOpponentCards - $PokemonGlobal.triads.pbStoreItem(card) + $PokemonGlobal.triads.add(card) end @scene.pbDisplayPaused(_INTL("Got all opponent's cards.")) end @@ -936,26 +933,26 @@ class TriadScreen case @trade when 0 # Lose 1 random card from your deck card = originalCards[rand(originalCards.length)] - $PokemonGlobal.triads.pbDeleteItem(card) + $PokemonGlobal.triads.remove(card) cardname = GameData::Species.get(card).name @scene.pbDisplayPaused(_INTL("Opponent won your {1} card.",cardname)) when 1 # Keep only cards of your color for card in originalCards - $PokemonGlobal.triads.pbDeleteItem(card) + $PokemonGlobal.triads.remove(card) end for i in cards - $PokemonGlobal.triads.pbStoreItem(i) + $PokemonGlobal.triads.add(i) end for i in 0...@width*@height if board[i].owner==1 card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id - $PokemonGlobal.triads.pbStoreItem(card) + $PokemonGlobal.triads.add(card) end end @scene.pbDisplayPaused(_INTL("Kept all cards of your color.",cardname)) when 2 # Lose all your cards for card in originalCards - $PokemonGlobal.triads.pbDeleteItem(card) + $PokemonGlobal.triads.remove(card) end @scene.pbDisplayPaused(_INTL("Opponent won all your cards.")) end @@ -999,54 +996,57 @@ end class TriadStorage attr_reader :items + MAX_PER_SLOT = 999 # Max. number of items per slot + def initialize @items = [] end - def maxSize - return @items.length + 1 - end - - def maxPerSlot - return 999 - end - - def empty? - return @items.length == 0 - end - - def length - return @items.length - end - def [](i) return @items[i] end - def getItem(index) + def length + return @items.length + end + + def empty? + return @items.length == 0 + end + + def maxSize + return @items.length + 1 + end + + def clear + @items.clear + end + + def get_item(index) return nil if index < 0 || index >= @items.length return @items[index][0] end - def getCount(index) + # Number of the item in the given index + def get_item_count(index) return 0 if index < 0 || index >= @items.length return @items[index][1] end - def pbQuantity(item) - return ItemStorageHelper.pbQuantity(@items, item) + def quantity(item) + return ItemStorageHelper.quantity(@items, item) end - def pbCanStore?(item, qty = 1) - return ItemStorageHelper.pbCanStore?(@items, self.maxSize, self.maxPerSlot, item, qty) + def can_add?(item, qty = 1) + return ItemStorageHelper.can_add?(@items, self.maxSize, MAX_PER_SLOT, item, qty) end - def pbStoreItem(item, qty = 1) - return ItemStorageHelper.pbStoreItem(@items, self.maxSize, self.maxPerSlot, item, qty) + def add(item, qty = 1) + return ItemStorageHelper.add(@items, self.maxSize, MAX_PER_SLOT, item, qty) end - def pbDeleteItem(item, qty = 1) - return ItemStorageHelper.pbDeleteItem(@items, item, qty) + def remove(item, qty = 1) + return ItemStorageHelper.remove(@items, item, qty) end end @@ -1126,11 +1126,11 @@ def pbBuyTriads pbMessage(_INTL("You don't have enough money.")) next end - if !$PokemonGlobal.triads.pbCanStore?(item,quantity) + if !$PokemonGlobal.triads.can_add?(item, quantity) pbMessage(_INTL("You have no room for more cards.")) next end - $PokemonGlobal.triads.pbStoreItem(item,quantity) + $PokemonGlobal.triads.add(item, quantity) $Trainer.money -= price goldwindow.text = _INTL("Money:\r\n{1}",pbGetGoldString) pbMessage(_INTL("Here you are! Thank you!\\se[Mart buy item]")) @@ -1171,9 +1171,9 @@ def pbSellTriads preview.x = Graphics.width*3/4-40 preview.y = Graphics.height/2-48 preview.z = 4 - item = $PokemonGlobal.triads.getItem(cmdwindow.index) + item = $PokemonGlobal.triads.get_item(cmdwindow.index) preview.bitmap = TriadCard.new(item).createBitmap(1) - olditem = $PokemonGlobal.triads.getItem(cmdwindow.index) + olditem = $PokemonGlobal.triads.get_item(cmdwindow.index) done = false Graphics.frame_reset while !done @@ -1183,7 +1183,7 @@ def pbSellTriads cmdwindow.active = true cmdwindow.update goldwindow.update - item = $PokemonGlobal.triads.getItem(cmdwindow.index) + item = $PokemonGlobal.triads.get_item(cmdwindow.index) if olditem != item preview.bitmap.dispose if preview.bitmap if item @@ -1200,9 +1200,9 @@ def pbSellTriads done = true break end - item = $PokemonGlobal.triads.getItem(cmdwindow.index) + item = $PokemonGlobal.triads.get_item(cmdwindow.index) itemname = GameData::Species.get(item).name - quantity = $PokemonGlobal.triads.pbQuantity(item) + quantity = $PokemonGlobal.triads.quantity(item) price = TriadCard.new(item).price if price==0 pbDisplayPaused(_INTL("The {1} card? Oh, no. I can't buy that.",itemname)) @@ -1224,7 +1224,7 @@ def pbSellTriads if pbConfirmMessage(_INTL("I can pay ${1}. Would that be OK?",price.to_s_formatted)) $Trainer.money += price goldwindow.text = _INTL("Money:\r\n{1}",pbGetGoldString) - $PokemonGlobal.triads.pbDeleteItem(item,quantity) + $PokemonGlobal.triads.remove(item,quantity) pbMessage(_INTL("Turned over the {1} card and received ${2}.\\se[Mart buy item]",itemname,price.to_s_formatted)) commands = [] for i in 0...$PokemonGlobal.triads.length @@ -1277,7 +1277,7 @@ def pbTriadList if lastIndex!=cmdwindow.index sprite.bitmap.dispose if sprite.bitmap if cmdwindow.index<$PokemonGlobal.triads.length - sprite.bitmap = TriadCard.new($PokemonGlobal.triads.getItem(cmdwindow.index)).createBitmap(1) + sprite.bitmap = TriadCard.new($PokemonGlobal.triads.get_item(cmdwindow.index)).createBitmap(1) end lastIndex = cmdwindow.index end @@ -1303,7 +1303,7 @@ end def pbGiveTriadCard(species, quantity = 1) sp = GameData::Species.try_get(species) return false if !sp - return false if !$PokemonGlobal.triads.pbCanStore?(sp.id, quantity) - $PokemonGlobal.triads.pbStoreItem(sp.id, quantity) + return false if !$PokemonGlobal.triads.can_add?(sp.id, quantity) + $PokemonGlobal.triads.add(sp.id, quantity) return true end diff --git a/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb b/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb index a460a60ac..c8a7f514a 100644 --- a/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb +++ b/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb @@ -388,7 +388,7 @@ end def pbSlotMachine(difficulty=1) - if GameData::Item.exists?(:COINCASE) && !$PokemonBag.pbHasItem?(:COINCASE) + if !$bag.has?(:COINCASE) pbMessage(_INTL("It's a Slot Machine.")) elsif $Trainer.coins == 0 pbMessage(_INTL("You don't have any Coins to play!")) diff --git a/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb b/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb index 609c78968..7cf53a646 100644 --- a/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb +++ b/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb @@ -614,7 +614,7 @@ end def pbVoltorbFlip - if GameData::Item.exists?(:COINCASE) && !$PokemonBag.pbHasItem?(:COINCASE) + if !$bag.has?(:COINCASE) pbMessage(_INTL("You can't play unless you have a Coin Case.")) elsif $Trainer.coins == Settings::MAX_COINS pbMessage(_INTL("Your Coin Case is full!")) diff --git a/Data/Scripts/017_Minigames/006_Minigame_Mining.rb b/Data/Scripts/017_Minigames/006_Minigame_Mining.rb index 226722428..6d5823710 100644 --- a/Data/Scripts/017_Minigames/006_Minigame_Mining.rb +++ b/Data/Scripts/017_Minigames/006_Minigame_Mining.rb @@ -586,7 +586,7 @@ class MiningGameScene def pbGiveItems if @itemswon.length>0 for i in @itemswon - if $PokemonBag.pbStoreItem(i) + if $bag.add(i) pbMessage(_INTL("One {1} was obtained.\\se[Mining item get]\\wtnp[30]", GameData::Item.get(i).name)) else diff --git a/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb b/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb index fc94fe400..e63f26a9e 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb @@ -481,7 +481,7 @@ DebugMenuCommands.register("additem", { qty = pbMessageChooseNumber(_INTL("Add how many {1}?", GameData::Item.get(item).name_plural), params) if qty > 0 - $PokemonBag.pbStoreItem(item, qty) + $bag.add(item, qty) pbMessage(_INTL("Gave {1}x {2}.", qty, GameData::Item.get(item).name)) end end @@ -500,11 +500,11 @@ DebugMenuCommands.register("fillbag", { params.setCancelValue(0) qty = pbMessageChooseNumber(_INTL("Choose the number of items."), params) if qty > 0 - $PokemonBag.clear - # NOTE: This doesn't simply use $PokemonBag.pbStoreItem for every item in - # turn, because that's really slow when done in bulk. + $bag.clear + # NOTE: This doesn't simply use $bag.add for every item in turn, because + # that's really slow when done in bulk. pocket_sizes = Settings::BAG_MAX_POCKET_SIZE - bag = $PokemonBag.pockets # Called here so that it only rearranges itself once + bag = $bag.pockets # Called here so that it only rearranges itself once GameData::Item.each do |i| next if !pocket_sizes[i.pocket] || pocket_sizes[i.pocket] == 0 next if pocket_sizes[i.pocket] > 0 && bag[i.pocket].length >= pocket_sizes[i.pocket] @@ -523,7 +523,7 @@ DebugMenuCommands.register("emptybag", { "name" => _INTL("Empty Bag"), "description" => _INTL("Remove all items from the Bag."), "effect" => proc { - $PokemonBag.clear + $bag.clear pbMessage(_INTL("The Bag was cleared.")) } }) diff --git a/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb b/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb index e2847601f..ac4edba05 100644 --- a/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb +++ b/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb @@ -926,7 +926,7 @@ module Compiler list.delete_at(i) newEvents = [] if cost==0 - push_branch(newEvents,"$PokemonBag.pbCanStore?(:#{itemname})",oldIndent) + push_branch(newEvents,"$bag.can_add?(:#{itemname})",oldIndent) push_text(newEvents,_INTL("Here you go!"),oldIndent+1) push_script(newEvents,"pbReceiveItem(:#{itemname})",oldIndent+1) push_else(newEvents,oldIndent+1) @@ -934,7 +934,7 @@ module Compiler push_branch_end(newEvents,oldIndent+1) else push_event(newEvents,111,[7,cost,0],oldIndent) - push_branch(newEvents,"$PokemonBag.pbCanStore?(:#{itemname})",oldIndent+1) + push_branch(newEvents,"$bag.can_add?(:#{itemname})",oldIndent+1) push_event(newEvents,125,[1,0,cost],oldIndent+2) push_text(newEvents,_INTL("\\GHere you go!"),oldIndent+2) push_script(newEvents,"pbReceiveItem(:#{itemname})",oldIndent+2)