Renamed variables and methods relating to the Bag, renamed $PokemonBag to $Bag, $bag.has? can now check for a minimum quantity

This commit is contained in:
Maruno17
2021-10-17 23:02:58 +01:00
parent 72c50db6c0
commit 36ff7c4ba3
30 changed files with 502 additions and 426 deletions

View File

@@ -103,8 +103,8 @@ end
SaveData.register(:bag) do SaveData.register(:bag) do
ensure_class :PokemonBag ensure_class :PokemonBag
save_value { $PokemonBag } save_value { $bag }
load_value { |value| $PokemonBag = value } load_value { |value| $bag = $PokemonBag = value }
new_game_value { PokemonBag.new } new_game_value { PokemonBag.new }
from_old_format { |old_format| old_format[13] } from_old_format { |old_format| old_format[13] }
end end

View File

@@ -169,3 +169,28 @@ SaveData.register_conversion(:v20_increment_player_character_id) do
player.character_ID += 1 player.character_ID += 1
end end
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

View File

@@ -268,9 +268,9 @@ GameData::Evolution.register({
}, },
:after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species| :after_evolution_proc => proc { |pkmn, new_species, parameter, evo_species|
next false if $Trainer.party_full? next false if $Trainer.party_full?
next false if !$PokemonBag.pbHasItem?(:POKEBALL) next false if !$bag.has?(:POKEBALL)
PokemonEvolutionScene.pbDuplicatePokemon(pkmn, new_species) PokemonEvolutionScene.pbDuplicatePokemon(pkmn, new_species)
$PokemonBag.pbDeleteItem(:POKEBALL) $bag.remove(:POKEBALL)
next true next true
} }
}) })

View File

@@ -207,7 +207,7 @@ module PokeBattle_BattleCommon
elsif numOwned>30 elsif numOwned>30
dex_modifier = 1 dex_modifier = 1
end end
dex_modifier *= 2 if $PokemonBag.pbHasItem?(:CATCHINGCHARM) dex_modifier *= 2 if $bag.has?(:CATCHINGCHARM)
c = x * dex_modifier / 12 c = x * dex_modifier / 12
# Calculate the number of shakes # Calculate the number of shakes
if c>0 && pbRandom(256)<c if c>0 && pbRandom(256)<c

View File

@@ -8,7 +8,7 @@ class PokeBattle_Battle
return if !@internalBattle || !@expGain return if !@internalBattle || !@expGain
# Go through each battler in turn to find the Pokémon that participated in # Go through each battler in turn to find the Pokémon that participated in
# battle against it, and award those Pokémon Exp/EVs # battle against it, and award those Pokémon Exp/EVs
expAll = (GameData::Item.exists?(:EXPALL) && $PokemonBag.pbHasItem?(:EXPALL)) expAll = $bag.has?(:EXPALL)
p1 = pbParty(0) p1 = pbParty(0)
@battlers.each do |b| @battlers.each do |b|
next unless b && b.opposes? # Can only gain Exp from fainted foes next unless b && b.opposes? # Can only gain Exp from fainted foes
@@ -145,7 +145,7 @@ class PokeBattle_Battle
end end
end end
# Exp. Charm increases Exp gained # Exp. Charm increases Exp gained
exp = exp * 3 / 2 if GameData::Item.exists?(:EXPCHARM) && $PokemonBag.pbHasItem?(:EXPCHARM) exp = exp * 3 / 2 if $bag.has?(:EXPCHARM)
# Modify Exp gain based on pkmn's held item # Modify Exp gain based on pkmn's held item
i = BattleHandlers.triggerExpGainModifierItem(pkmn.item,pkmn,exp) i = BattleHandlers.triggerExpGainModifierItem(pkmn.item,pkmn,exp)
if i<0 if i<0

View File

@@ -43,7 +43,7 @@ class PokeBattle_Battle
return if !item return if !item
return if !GameData::Item.get(item).consumed_after_use? return if !GameData::Item.get(item).consumed_after_use?
if pbOwnedByPlayer?(idxBattler) if pbOwnedByPlayer?(idxBattler)
if !$PokemonBag.pbDeleteItem(item) if !$bag.remove(item)
raise _INTL("Tried to consume item that wasn't in the Bag somehow.") raise _INTL("Tried to consume item that wasn't in the Bag somehow.")
end end
else else
@@ -56,8 +56,8 @@ class PokeBattle_Battle
return if !item return if !item
return if !GameData::Item.get(item).consumed_after_use? return if !GameData::Item.get(item).consumed_after_use?
if pbOwnedByPlayer?(idxBattler) if pbOwnedByPlayer?(idxBattler)
if $PokemonBag && $PokemonBag.pbCanStore?(item) if $bag && $bag.can_add?(item)
$PokemonBag.pbStoreItem(item) $bag.add(item)
else else
raise _INTL("Couldn't return unused item to Bag somehow.") raise _INTL("Couldn't return unused item to Bag somehow.")
end end

View File

@@ -63,14 +63,14 @@ class PokeBattle_Battle
#============================================================================= #=============================================================================
def pbHasMegaRing?(idxBattler) def pbHasMegaRing?(idxBattler)
return true if !pbOwnedByPlayer?(idxBattler) # Assume AI trainer have a ring return true if !pbOwnedByPlayer?(idxBattler) # Assume AI trainer have a ring
Settings::MEGA_RINGS.each { |item| return true if $PokemonBag.pbHasItem?(item) } Settings::MEGA_RINGS.each { |item| return true if $bag.has?(item) }
return false return false
end end
def pbGetMegaRingName(idxBattler) def pbGetMegaRingName(idxBattler)
if pbOwnedByPlayer?(idxBattler) if pbOwnedByPlayer?(idxBattler)
Settings::MEGA_RINGS.each do |item| Settings::MEGA_RINGS.each do |item|
return GameData::Item.get(item).name if $PokemonBag.pbHasItem?(item) return GameData::Item.get(item).name if $bag.has?(item)
end end
end end
# NOTE: Add your own Mega objects for particular NPC trainers here. # NOTE: Add your own Mega objects for particular NPC trainers here.

View File

@@ -193,13 +193,13 @@ class PokeBattle_Scene
# Fade out and hide all sprites # Fade out and hide all sprites
visibleSprites = pbFadeOutAndHide(@sprites) visibleSprites = pbFadeOutAndHide(@sprites)
# Set Bag starting positions # Set Bag starting positions
oldLastPocket = $PokemonBag.lastpocket oldLastPocket = $bag.last_viewed_pocket
oldChoices = $PokemonBag.getAllChoices oldChoices = $bag.last_pocket_selections.clone
$PokemonBag.lastpocket = @bagLastPocket if @bagLastPocket!=nil $bag.last_viewed_pocket = @bagLastPocket if @bagLastPocket != nil
$PokemonBag.setAllChoices(@bagChoices) if @bagChoices!=nil $bag.last_pocket_selections = @bagChoices if @bagChoices != nil
# Start Bag screen # Start Bag screen
itemScene = PokemonBag_Scene.new itemScene = PokemonBag_Scene.new
itemScene.pbStartScene($PokemonBag,true,Proc.new { |item| itemScene.pbStartScene($bag, true, Proc.new { |item|
useType = GameData::Item.get(item).battle_use useType = GameData::Item.get(item).battle_use
next useType && useType>0 next useType && useType>0
},false) },false)
@@ -304,10 +304,10 @@ class PokeBattle_Scene
break if yield item.id, useType, idxBattler, -1, itemScene break if yield item.id, useType, idxBattler, -1, itemScene
end end
end end
@bagLastPocket = $PokemonBag.lastpocket @bagLastPocket = $bag.last_viewed_pocket
@bagChoices = $PokemonBag.getAllChoices @bagChoices = $bag.last_pocket_selections.clone
$PokemonBag.lastpocket = oldLastPocket $bag.last_viewed_pocket = oldLastPocket
$PokemonBag.setAllChoices(oldChoices) $bag.last_pocket_selections = oldChoices
# Close Bag screen # Close Bag screen
itemScene.pbEndScene itemScene.pbEndScene
# Fade back into battle screen (if not already showing it) # Fade back into battle screen (if not already showing it)

View File

@@ -135,9 +135,7 @@ Events.onStepTakenFieldMovement += proc { |_sender,e|
tile_id = map.data[thistile[1],thistile[2],i] tile_id = map.data[thistile[1],thistile[2],i]
next if tile_id == nil next if tile_id == nil
next if GameData::TerrainTag.try_get(map.terrain_tags[tile_id]).id != :SootGrass 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 event == $game_player && $bag.has?(:SOOTSACK)
$Trainer.soot += 1 if $PokemonBag.pbHasItem?(:SOOTSACK)
end
# map.data[thistile[1], thistile[2], i] = 0 # map.data[thistile[1], thistile[2], i] = 0
# $scene.createSingleSpriteset(map.map_id) # $scene.createSingleSpriteset(map.map_id)
break break
@@ -711,7 +709,7 @@ def pbItemBall(item,quantity=1)
itemname = (quantity>1) ? item.name_plural : item.name itemname = (quantity>1) ? item.name_plural : item.name
pocket = item.pocket pocket = item.pocket
move = item.move 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" meName = (item.is_key_item?) ? "Key item get" : "Item get"
if item == :LEFTOVERS if item == :LEFTOVERS
pbMessage(_INTL("\\me[{1}]You found some \\c[1]{2}\\c[0]!\\wtnp[30]",meName,itemname)) 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)) pbMessage(_INTL("\\me[{1}]You found a \\c[1]{2}\\c[0]!\\wtnp[30]",meName,itemname))
end end
pbMessage(_INTL("You put the {1} in\\nyour Bag's <icon=bagPocket{2}>\\c[1]{3}\\c[0] pocket.", pbMessage(_INTL("You put the {1} in\\nyour Bag's <icon=bagPocket{2}>\\c[1]{3}\\c[0] pocket.",
itemname,pocket,PokemonBag.pocketNames()[pocket])) itemname, pocket, PokemonBag.pocket_names[pocket]))
return true return true
end end
# Can't add the item # Can't add the item
@@ -771,9 +769,9 @@ def pbReceiveItem(item,quantity=1)
else else
pbMessage(_INTL("\\me[{1}]You obtained a \\c[1]{2}\\c[0]!\\wtnp[30]",meName,itemname)) pbMessage(_INTL("\\me[{1}]You obtained a \\c[1]{2}\\c[0]!\\wtnp[30]",meName,itemname))
end 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 <icon=bagPocket{2}>\\c[1]{3}\\c[0] pocket.", pbMessage(_INTL("You put the {1} in\\nyour Bag's <icon=bagPocket{2}>\\c[1]{3}\\c[0] pocket.",
itemname,pocket,PokemonBag.pocketNames()[pocket])) itemname, pocket, PokemonBag.pocket_names[pocket]))
return true return true
end end
return false # Can't add the item return false # Can't add the item

View File

@@ -414,7 +414,7 @@ def pbGenerateWildPokemon(species,level,isRoamer=false)
# Improve chances of shiny Pokémon with Shiny Charm and battling more of the # Improve chances of shiny Pokémon with Shiny Charm and battling more of the
# same species # same species
shiny_retries = 0 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 if Settings::HIGHER_SHINY_CHANCES_WITH_NUMBER_BATTLED
values = [0, 0] values = [0, 0]
case $Trainer.pokedex.battled_count(species) case $Trainer.pokedex.battled_count(species)

View File

@@ -354,7 +354,7 @@ def pbBerryPlant
end end
# Water the growing plant # Water the growing plant
GameData::BerryPlant::WATERING_CANS.each do |item| 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}?", break if !pbConfirmMessage(_INTL("Want to sprinkle some water with the {1}?",
GameData::Item.get(item).name)) GameData::Item.get(item).name))
berry_plant.water berry_plant.water
@@ -381,14 +381,14 @@ def pbBerryPlant
mulch = nil mulch = nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new 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? }) mulch = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_mulch? })
} }
return if !mulch return if !mulch
mulch_data = GameData::Item.get(mulch) mulch_data = GameData::Item.get(mulch)
if mulch_data.is_mulch? if mulch_data.is_mulch?
berry_plant.mulch_id = 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)) pbMessage(_INTL("The {1} was scattered on the soil.\1", mulch_data.name))
else else
pbMessage(_INTL("That won't fertilize the soil!")) 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?")) if !ask_to_plant || pbConfirmMessage(_INTL("Want to plant a Berry?"))
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new 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? }) berry = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_berry? })
} }
if berry if berry
berry_plant.plant(berry) berry_plant.plant(berry)
$PokemonBag.pbDeleteItem(berry, 1) $bag.remove(berry)
if Settings::NEW_BERRY_PLANTS if Settings::NEW_BERRY_PLANTS
pbMessage(_INTL("The {1} was planted in the soft, earthy soil.", pbMessage(_INTL("The {1} was planted in the soft, earthy soil.",
GameData::Item.get(berry).name)) 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) message = _INTL("There is 1 \\c[1]{1}\\c[0]!\nWant to pick it?", berry_name)
end end
return false if !pbConfirmMessage(message) return false if !pbConfirmMessage(message)
if !$PokemonBag.pbCanStore?(berry, qty) if !$bag.can_add?(berry, qty)
pbMessage(_INTL("Too bad...\nThe Bag is full...")) pbMessage(_INTL("Too bad...\nThe Bag is full..."))
return false return false
end end
$PokemonBag.pbStoreItem(berry, qty) $bag.add(berry, qty)
if qty > 1 if qty > 1
pbMessage(_INTL("You picked the {1} \\c[1]{2}\\c[0].\\wtnp[30]", qty, berry_name)) pbMessage(_INTL("You picked the {1} \\c[1]{2}\\c[0].\\wtnp[30]", qty, berry_name))
else else
@@ -449,7 +449,7 @@ def pbPickBerry(berry, qty = 1)
end end
pocket = berry.pocket pocket = berry.pocket
pbMessage(_INTL("{1} put the \\c[1]{2}\\c[0] in the <icon=bagPocket{3}>\\c[1]{4}\\c[0] Pocket.\1", pbMessage(_INTL("{1} put the \\c[1]{2}\\c[0] in the <icon=bagPocket{3}>\\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 if Settings::NEW_BERRY_PLANTS
pbMessage(_INTL("The soil returned to its soft and earthy state.")) pbMessage(_INTL("The soil returned to its soft and earthy state."))
else else

View File

@@ -316,7 +316,7 @@ def pbDayCareGenerateEgg
# Masuda method and Shiny Charm # Masuda method and Shiny Charm
shinyretries = 0 shinyretries = 0
shinyretries += 5 if father.owner.language != mother.owner.language 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 if shinyretries>0
shinyretries.times do shinyretries.times do
break if egg.shiny? break if egg.shiny?
@@ -380,10 +380,8 @@ Events.onStepTaken += proc { |_sender,_e|
$PokemonGlobal.daycareEggSteps += 1 $PokemonGlobal.daycareEggSteps += 1
if $PokemonGlobal.daycareEggSteps==256 if $PokemonGlobal.daycareEggSteps==256
$PokemonGlobal.daycareEggSteps = 0 $PokemonGlobal.daycareEggSteps = 0
compatval = [0,20,50,70][pbDayCareGetCompat] compatval = [0, 20, 50, 70][pbDayCareGetCompat]
if GameData::Item.exists?(:OVALCHARM) && $PokemonBag.pbHasItem?(:OVALCHARM) compatval = [0, 40, 80, 88][pbDayCareGetCompat] if $bag.has?(:OVALCHARM)
compatval = [0,40,80,88][pbDayCareGetCompat]
end
$PokemonGlobal.daycareEgg = 1 if rand(100)<compatval # Egg is generated $PokemonGlobal.daycareEgg = 1 if rand(100)<compatval # Egg is generated
end end
end end

View File

@@ -579,7 +579,7 @@ def pbUseItem(bag,item,bagscene=nil)
if !pbConfirmMessage(_INTL("Do you want to teach {1} to a Pokémon?",movename)) if !pbConfirmMessage(_INTL("Do you want to teach {1} to a Pokémon?",movename))
return 0 return 0
elsif pbMoveTutorChoose(machine,nil,true,itm.is_TR?) elsif pbMoveTutorChoose(machine,nil,true,itm.is_TR?)
bag.pbDeleteItem(item) if itm.consumed_after_use? bag.remove(item) if itm.consumed_after_use?
return 1 return 1
end end
return 0 return 0
@@ -612,8 +612,8 @@ def pbUseItem(bag,item,bagscene=nil)
if pbCheckUseOnPokemon(item,pkmn,screen) if pbCheckUseOnPokemon(item,pkmn,screen)
ret = ItemHandlers.triggerUseOnPokemon(item,pkmn,screen) ret = ItemHandlers.triggerUseOnPokemon(item,pkmn,screen)
if ret && itm.consumed_after_use? if ret && itm.consumed_after_use?
bag.pbDeleteItem(item) bag.remove(item)
if !bag.pbHasItem?(item) if !bag.has?(item)
pbMessage(_INTL("You used your last {1}.",itm.name)) { screen.pbUpdate } pbMessage(_INTL("You used your last {1}.",itm.name)) { screen.pbUpdate }
break break
end end
@@ -627,7 +627,7 @@ def pbUseItem(bag,item,bagscene=nil)
elsif useType==2 # Item is usable from Bag elsif useType==2 # Item is usable from Bag
intret = ItemHandlers.triggerUseFromBag(item) intret = ItemHandlers.triggerUseFromBag(item)
if intret >= 0 if intret >= 0
bag.pbDeleteItem(item) if intret == 1 && itm.consumed_after_use? bag.remove(item) if intret == 1 && itm.consumed_after_use?
return intret return intret
end end
pbMessage(_INTL("Can't use that here.")) 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 } 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 pbConfirmMessage(_INTL("Do you want to teach {1} to {2}?",movename,pkmn.name)) { scene.pbUpdate }
if pbLearnMove(pkmn,machine,false,true) { 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 return true
end end
end end
@@ -666,8 +666,8 @@ def pbUseItemOnPokemon(item,pkmn,scene)
scene.pbClearAnnotations scene.pbClearAnnotations
scene.pbHardRefresh scene.pbHardRefresh
if ret && itm.consumed_after_use? if ret && itm.consumed_after_use?
$PokemonBag.pbDeleteItem(item) $bag.remove(item)
if !$PokemonBag.pbHasItem?(item) if !$bag.has?(item)
pbMessage(_INTL("You used your last {1}.",itm.name)) { scene.pbUpdate } pbMessage(_INTL("You used your last {1}.",itm.name)) { scene.pbUpdate }
end end
end end
@@ -679,7 +679,7 @@ def pbUseKeyItemInField(item)
if ret==-1 # Item effect not found if ret==-1 # Item effect not found
pbMessage(_INTL("Can't use that here.")) pbMessage(_INTL("Can't use that here."))
elsif ret > 0 && GameData::Item.get(item).consumed_after_use? elsif ret > 0 && GameData::Item.get(item).consumed_after_use?
$PokemonBag.pbDeleteItem(item) $bag.remove(item)
end end
return ret > 0 return ret > 0
end 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)) scene.pbDisplay(_INTL("{1} is already holding a {2}.\1",pkmn.name,olditemname))
end end
if scene.pbConfirm(_INTL("Would you like to switch the two items?")) if scene.pbConfirm(_INTL("Would you like to switch the two items?"))
$PokemonBag.pbDeleteItem(item) $bag.remove(item)
if !$PokemonBag.pbStoreItem(pkmn.item) if !$bag.add(pkmn.item)
if !$PokemonBag.pbStoreItem(item) if !$bag.add(item)
raise _INTL("Could't re-store deleted item in Bag somehow") raise _INTL("Could't re-store deleted item in Bag somehow")
end end
scene.pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed.")) 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)) scene.pbDisplay(_INTL("Took the {1} from {2} and gave it the {3}.",olditemname,pkmn.name,newitemname))
return true return true
else else
if !$PokemonBag.pbStoreItem(item) if !$bag.add(item)
raise _INTL("Couldn't re-store deleted item in Bag somehow") raise _INTL("Couldn't re-store deleted item in Bag somehow")
end end
end end
@@ -745,7 +745,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0)
end end
else else
if !GameData::Item.get(item).is_mail? || pbWriteMail(item,pkmn,pkmnid,scene) if !GameData::Item.get(item).is_mail? || pbWriteMail(item,pkmn,pkmnid,scene)
$PokemonBag.pbDeleteItem(item) $bag.remove(item)
pkmn.item = item pkmn.item = item
scene.pbDisplay(_INTL("{1} is now holding the {2}.",pkmn.name,newitemname)) scene.pbDisplay(_INTL("{1} is now holding the {2}.",pkmn.name,newitemname))
return true return true
@@ -758,7 +758,7 @@ def pbTakeItemFromPokemon(pkmn,scene)
ret = false ret = false
if !pkmn.hasItem? if !pkmn.hasItem?
scene.pbDisplay(_INTL("{1} isn't holding anything.",pkmn.name)) 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.")) scene.pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed."))
elsif pkmn.mail elsif pkmn.mail
if scene.pbConfirm(_INTL("Save the removed mail in your PC?")) if scene.pbConfirm(_INTL("Save the removed mail in your PC?"))
@@ -770,14 +770,14 @@ def pbTakeItemFromPokemon(pkmn,scene)
ret = true ret = true
end end
elsif scene.pbConfirm(_INTL("If the mail is removed, its message will be lost. OK?")) 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)) scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name))
pkmn.item = nil pkmn.item = nil
pkmn.mail = nil pkmn.mail = nil
ret = true ret = true
end end
else else
$PokemonBag.pbStoreItem(pkmn.item) $bag.add(pkmn.item)
scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name)) scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name))
pkmn.item = nil pkmn.item = nil
ret = true ret = true
@@ -792,7 +792,7 @@ def pbChooseItem(var = 0, *args)
ret = nil ret = nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene,$PokemonBag) screen = PokemonBagScreen.new(scene, $bag)
ret = screen.pbChooseItemScreen ret = screen.pbChooseItemScreen
} }
$game_variables[var] = ret || :NONE if var > 0 $game_variables[var] = ret || :NONE if var > 0
@@ -803,7 +803,7 @@ def pbChooseApricorn(var = 0)
ret = nil ret = nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new 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? }) ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_apricorn? })
} }
$game_variables[var] = ret || :NONE if var > 0 $game_variables[var] = ret || :NONE if var > 0
@@ -814,7 +814,7 @@ def pbChooseFossil(var = 0)
ret = nil ret = nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new 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? }) ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_fossil? })
} }
$game_variables[var] = ret || :NONE if var > 0 $game_variables[var] = ret || :NONE if var > 0
@@ -829,7 +829,7 @@ def pbChooseItemFromList(message, variable, *args)
for item in args for item in args
next if !GameData::Item.exists?(item) next if !GameData::Item.exists?(item)
itm = GameData::Item.get(item) itm = GameData::Item.get(item)
next if !$PokemonBag.pbHasItem?(itm) next if !$bag.has?(itm)
commands.push(itm.name) commands.push(itm.name)
itemid.push(itm.id) itemid.push(itm.id)
end end

View File

@@ -109,19 +109,17 @@ Events.onStepTaken += proc {
if $PokemonGlobal.repel > 0 && !$game_player.terrain_tag.ice # Shouldn't count down if on ice if $PokemonGlobal.repel > 0 && !$game_player.terrain_tag.ice # Shouldn't count down if on ice
$PokemonGlobal.repel -= 1 $PokemonGlobal.repel -= 1
if $PokemonGlobal.repel <= 0 if $PokemonGlobal.repel <= 0
if $PokemonBag.pbHasItem?(:REPEL) || if $bag.has?(:REPEL) || $bag.has?(:SUPERREPEL) || $bag.has?(:MAXREPEL)
$PokemonBag.pbHasItem?(:SUPERREPEL) ||
$PokemonBag.pbHasItem?(:MAXREPEL)
if pbConfirmMessage(_INTL("The repellent's effect wore off! Would you like to use another one?")) if pbConfirmMessage(_INTL("The repellent's effect wore off! Would you like to use another one?"))
ret = nil ret = nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene,$PokemonBag) screen = PokemonBagScreen.new(scene, $bag)
ret = screen.pbChooseItemScreen(Proc.new { |item| ret = screen.pbChooseItemScreen(Proc.new { |item|
[:REPEL, :SUPERREPEL, :MAXREPEL].include?(item) [:REPEL, :SUPERREPEL, :MAXREPEL].include?(item)
}) })
} }
pbUseItem($PokemonBag,ret) if ret pbUseItem($bag, ret) if ret
end end
else else
pbMessage(_INTL("The repellent's effect wore off!")) pbMessage(_INTL("The repellent's effect wore off!"))
@@ -314,13 +312,13 @@ ItemHandlers::UseInField.add(:COINCASE,proc { |item|
}) })
ItemHandlers::UseInField.add(:EXPALL,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.")) pbMessage(_INTL("The Exp Share was turned off."))
next true next true
}) })
ItemHandlers::UseInField.add(:EXPALLOFF,proc { |item| ItemHandlers::UseInField.add(:EXPALLOFF,proc { |item|
$PokemonBag.pbChangeItem(:EXPALLOFF,:EXPALL) $bag.replace_item(:EXPALLOFF, :EXPALL)
pbMessage(_INTL("The Exp Share was turned on.")) pbMessage(_INTL("The Exp Share was turned on."))
next true next true
}) })
@@ -896,13 +894,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYXS, proc { |item, pkmn, scene|
end end
gain_amount = 100 gain_amount = 100
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil 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( qty = scene.scene.pbChooseNumber(
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
next false if qty == 0 next false if qty == 0
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
$PokemonBag.pbDeleteItem(item, qty - 1) $bag.remove(item, qty - 1)
scene.pbHardRefresh scene.pbHardRefresh
next true next true
}) })
@@ -914,13 +912,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYS, proc { |item, pkmn, scene|
end end
gain_amount = 800 gain_amount = 800
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil 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( qty = scene.scene.pbChooseNumber(
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
next false if qty == 0 next false if qty == 0
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
$PokemonBag.pbDeleteItem(item, qty - 1) $bag.remove(item, qty - 1)
scene.pbHardRefresh scene.pbHardRefresh
next true next true
}) })
@@ -932,13 +930,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYM, proc { |item, pkmn, scene|
end end
gain_amount = 3_000 gain_amount = 3_000
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil 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( qty = scene.scene.pbChooseNumber(
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
next false if qty == 0 next false if qty == 0
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
$PokemonBag.pbDeleteItem(item, qty - 1) $bag.remove(item, qty - 1)
scene.pbHardRefresh scene.pbHardRefresh
next true next true
}) })
@@ -950,13 +948,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYL, proc { |item, pkmn, scene|
end end
gain_amount = 10_000 gain_amount = 10_000
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil 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( qty = scene.scene.pbChooseNumber(
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
next false if qty == 0 next false if qty == 0
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
$PokemonBag.pbDeleteItem(item, qty - 1) $bag.remove(item, qty - 1)
scene.pbHardRefresh scene.pbHardRefresh
next true next true
}) })
@@ -968,13 +966,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYXL, proc { |item, pkmn, scene|
end end
gain_amount = 30_000 gain_amount = 30_000
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil 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( qty = scene.scene.pbChooseNumber(
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum) _INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
next false if qty == 0 next false if qty == 0
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen) scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene) pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
$PokemonBag.pbDeleteItem(item, qty - 1) $bag.remove(item, qty - 1)
scene.pbHardRefresh scene.pbHardRefresh
next true next true
}) })
@@ -1275,7 +1273,7 @@ ItemHandlers::UseOnPokemon.add(:DNASPLICERS,proc { |item,pkmn,scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:DNASPLICERS, :DNASPLICERSUSED) $bag.replace_item(:DNASPLICERS, :DNASPLICERSUSED)
next true next true
}) })
@@ -1297,7 +1295,7 @@ ItemHandlers::UseOnPokemon.add(:DNASPLICERSUSED,proc { |item,pkmn,scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:DNASPLICERSUSED, :DNASPLICERS) $bag.replace_item(:DNASPLICERSUSED, :DNASPLICERS)
next true next true
}) })
@@ -1332,7 +1330,7 @@ ItemHandlers::UseOnPokemon.add(:NSOLARIZER,proc { |item,pkmn,scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:NSOLARIZER, :NSOLARIZERUSED) $bag.replace_item(:NSOLARIZER, :NSOLARIZERUSED)
next true next true
}) })
@@ -1354,7 +1352,7 @@ ItemHandlers::UseOnPokemon.add(:NSOLARIZERUSED,proc { |item,pkmn,scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:NSOLARIZERUSED, :NSOLARIZER) $bag.replace_item(:NSOLARIZERUSED, :NSOLARIZER)
next true next true
}) })
@@ -1389,7 +1387,7 @@ ItemHandlers::UseOnPokemon.add(:NLUNARIZER,proc { |item,pkmn,scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:NLUNARIZER, :NLUNARIZERUSED) $bag.replace_item(:NLUNARIZER, :NLUNARIZERUSED)
next true next true
}) })
@@ -1411,7 +1409,7 @@ ItemHandlers::UseOnPokemon.add(:NLUNARIZERUSED,proc { |item,pkmn,scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:NLUNARIZERUSED, :NLUNARIZER) $bag.replace_item(:NLUNARIZERUSED, :NLUNARIZER)
next true next true
}) })
@@ -1450,7 +1448,7 @@ ItemHandlers::UseOnPokemon.add(:REINSOFUNITY, proc { |item, pkmn, scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:REINSOFUNITY, :REINSOFUNITYUSED) $bag.replace_item(:REINSOFUNITY, :REINSOFUNITYUSED)
next true next true
}) })
@@ -1472,6 +1470,6 @@ ItemHandlers::UseOnPokemon.add(:REINSOFUNITYUSED, proc { |item, pkmn, scene|
scene.pbHardRefresh scene.pbHardRefresh
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name)) scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
} }
$PokemonBag.pbChangeItem(:REINSOFUNITYUSED, :REINSOFUNITY) $bag.replace_item(:REINSOFUNITYUSED, :REINSOFUNITY)
next true next true
}) })

View File

@@ -1,57 +1,35 @@
#=============================================================================== #===============================================================================
# The Bag object, which actually contains all the items # The Bag object, which actually contains all the items.
#=============================================================================== #===============================================================================
class PokemonBag 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 return Settings.bag_pocket_names
end end
def self.numPockets def self.pocket_count
return self.pocketNames.length-1 return self.pocket_names.length - 1
end end
def initialize def initialize
@lastpocket = 1 @last_viewed_pocket = 1
@pockets = [] @pockets = []
@choices = [] @last_pocket_selections = []
for i in 0..PokemonBag.numPockets for i in 0..PokemonBag.pocket_count
@pockets[i] = [] @pockets[i] = []
@choices[i] = 0 @last_pocket_selections[i] = 0
end end
@registeredItems = [] @registered_items = []
@registeredIndex = [0, 0, 1] # Used by the Ready Menu to remember cursor positions @ready_menu_selection = [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
end end
def clear def clear
@pockets.each { |pocket| pocket.clear } @pockets.each { |pocket| pocket.clear }
for i in 0..PokemonBag.numPockets (PokemonBag.pocket_count + 1).times { |i| @last_pocket_selections[i] = 0 }
@choices[i] = 0
end
end end
def pockets def pockets
@@ -59,131 +37,156 @@ class PokemonBag
return @pockets return @pockets
end 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 # Gets the index of the current selected item in the pocket
def getChoice(pocket) def last_viewed_index(pocket)
if pocket <= 0 || pocket > PokemonBag.numPockets if pocket <= 0 || pocket > PokemonBag.pocket_count
raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect)) raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect))
end end
rearrange rearrange
return [@choices[pocket], @pockets[pocket].length].min || 0 return [@last_pocket_selections[pocket], @pockets[pocket].length].min || 0
end end
# Sets the index of the current selected item in the pocket # Sets the index of the current selected item in the pocket
def setChoice(pocket,value) def set_last_viewed_index(pocket, value)
if pocket <= 0 || pocket > PokemonBag.numPockets if pocket <= 0 || pocket > PokemonBag.pocket_count
raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect)) raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect))
end end
rearrange rearrange
@choices[pocket] = value if value <= @pockets[pocket].length @last_pocket_selections[pocket] = value if value <= @pockets[pocket].length
end end
def getAllChoices #=============================================================================
ret = @choices.clone
for i in 0...@choices.length def quantity(item)
@choices[i] = 0 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 end
return ret return ret
end end
def setAllChoices(choices) # Adds qty number of item. Doesn't add anything if it can't add all of them.
@choices = choices def add_all(item, qty = 1)
return false if !can_add?(item, qty)
return add(item, qty)
end end
def pbQuantity(item) # Deletes as many of item as possible (up to qty), and returns whether it
item = GameData::Item.get(item) # 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 pocket = item.pocket
return ItemStorageHelper.pbQuantity(@pockets[pocket], item.id) return ItemStorageHelper.remove(@pockets[pocket], item.id, qty)
end end
def pbHasItem?(item) # Deletes qty number of item. Doesn't delete anything if there are less than
return pbQuantity(item) > 0 # 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 end
def pbCanStore?(item, qty = 1) # This only works if the old and new items are in the same pocket. Used for
item = GameData::Item.get(item) # switching on/off certain Key Items. Replaces all old_item in its pocket with
pocket = item.pocket # new_item.
maxsize = maxPocketSize(pocket) def replace_item(old_item, new_item)
maxsize = @pockets[pocket].length + 1 if maxsize < 0 old_item_data = GameData::Item.try_get(old_item)
return ItemStorageHelper.pbCanStore?( new_item_data = GameData::Item.try_get(new_item)
@pockets[pocket], maxsize, Settings::BAG_MAX_PER_SLOT, item.id, qty) return false if !old_item_data || !new_item_data
end pocket = old_item_data.pocket
old_id = old_item_data.id
def pbStoreItem(item, qty = 1) new_id = new_item_data.id
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
ret = false ret = false
@pockets[pocket].each do |item| @pockets[pocket].each do |item|
next if !item || item[0] != old_item.id next if !item || item[0] != old_id
item[0] = new_item.id item[0] = new_id
ret = true ret = true
end end
return ret return ret
end 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) # Returns whether item has been registered for quick access in the Ready Menu.
item = GameData::Item.get(item) def registered?(item)
pocket = item.pocket item_data = GameData::Item.try_get(item)
ret = ItemStorageHelper.pbDeleteItem(@pockets[pocket], item.id, qty) return false if !item_data
return ret return @registered_items.include?(item_data.id)
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)
end end
# Registers the item in the Ready Menu. # Registers the item in the Ready Menu.
def pbRegisterItem(item) def register(item)
item = GameData::Item.get(item).id item_data = GameData::Item.try_get(item)
registeredlist = self.registeredItems return if !item_data
registeredlist.push(item) if !registeredlist.include?(item) @registered_items.push(item_data.id) if !@registered_items.include?(item_data.id)
end end
# Unregisters the item from the Ready Menu. # Unregisters the item from the Ready Menu.
def pbUnregisterItem(item) def unregister(item)
item = GameData::Item.get(item).id item_data = GameData::Item.try_get(item)
registeredlist = self.registeredItems @registered_items.delete(item_data.id) if item_data
registeredlist.delete_at(registeredlist.index(item))
end 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
end end
@@ -201,7 +204,7 @@ class PCItemStorage
def initialize def initialize
@items = [] @items = []
# Start storage with a Potion # Start storage with a Potion
pbStoreItem(:POTION) if GameData::Item.exists?(:POTION) add(:POTION) if GameData::Item.exists?(:POTION)
end end
def [](i) def [](i)
@@ -220,32 +223,35 @@ class PCItemStorage
@items.clear @items.clear
end end
def getItem(index) # Unused
def get_item(index)
return (index < 0 || index >= @items.length) ? nil : @items[index][0] return (index < 0 || index >= @items.length) ? nil : @items[index][0]
end 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] return (index < 0 || index >= @items.length) ? 0 : @items[index][1]
end end
def pbQuantity(item) def quantity(item)
item = GameData::Item.get(item).id item = GameData::Item.get(item).id
return ItemStorageHelper.pbQuantity(@items, item) return ItemStorageHelper.quantity(@items, item)
end end
def pbCanStore?(item, qty = 1) def can_add?(item, qty = 1)
item = GameData::Item.get(item).id 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 end
def pbStoreItem(item, qty = 1) def add(item, qty = 1)
item = GameData::Item.get(item).id 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 end
def pbDeleteItem(item, qty = 1) def remove(item, qty = 1)
item = GameData::Item.get(item).id item = GameData::Item.get(item).id
return ItemStorageHelper.pbDeleteItem(@items, item, qty) return ItemStorageHelper.remove(@items, item, qty)
end end
end end
@@ -257,25 +263,62 @@ end
# Used by the Bag, PC item storage, and Triple Triad. # Used by the Bag, PC item storage, and Triple Triad.
#=============================================================================== #===============================================================================
module ItemStorageHelper module ItemStorageHelper
# Returns the quantity of check_item in item_array # Returns the quantity of item in items
def self.pbQuantity(item_array, check_item) def self.quantity(items, item)
ret = 0 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 return ret
end 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) # 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 raise "Invalid value for qty: #{qty}" if qty < 0
return true if qty == 0 return true if qty == 0
ret = false ret = false
for i in 0...items.length items.each_with_index do |item_slot, i|
itemslot = items[i] next if !item_slot || item_slot[0] != item
next if !itemslot || itemslot[0] != item amount = [qty, item_slot[1]].min
amount = [qty, itemslot[1]].min item_slot[1] -= amount
itemslot[1] -= amount
qty -= amount qty -= amount
items[i] = nil if itemslot[1] == 0 items[i] = nil if item_slot[1] == 0
next if qty > 0 next if qty > 0
ret = true ret = true
break break
@@ -283,72 +326,86 @@ module ItemStorageHelper
items.compact! items.compact!
return ret return ret
end 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 end
#=============================================================================== #===============================================================================
# Shortcut methods # Deprecated methods
#=============================================================================== #===============================================================================
def pbQuantity(*args) class PokemonBag
return $PokemonBag.pbQuantity(*args) 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 end
def pbHasItem?(*args) def pbQuantity(item)
return $PokemonBag.pbHasItem?(*args) Deprecation.warn_method('pbQuantity', 'v21', '$bag.quantity(item)')
return $bag.quantity(item)
end end
def pbCanStore?(*args) def pbHasItem?(item)
return $PokemonBag.pbCanStore?(*args) Deprecation.warn_method('pbHasItem?', 'v21', '$bag.has?(item)')
return $bag.has?(item)
end end
def pbStoreItem(*args) def pbCanStore?(item, quantity = 1)
return $PokemonBag.pbStoreItem(*args) Deprecation.warn_method('pbCanStore?', 'v21', '$bag.can_add?(item, quantity)')
return $bag.can_add?(item, quantity)
end end
def pbStoreAllOrNone(*args) def pbStoreItem(item, quantity = 1)
return $PokemonBag.pbStoreAllOrNone(*args) 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 end

View File

@@ -192,7 +192,7 @@ class PokemonPauseMenu
item = nil item = nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene,$PokemonBag) screen = PokemonBagScreen.new(scene, $bag)
item = screen.pbStartScreen item = screen.pbStartScreen
(item) ? @scene.pbEndScene : @scene.pbRefresh (item) ? @scene.pbEndScene : @scene.pbRefresh
} }

View File

@@ -1149,7 +1149,7 @@ class PokemonPartyScreen
def pbPokemonScreen def pbPokemonScreen
can_access_storage = false can_access_storage = false
if GameData::Item.exists?(:POKEMONBOXLINK) && $PokemonBag.pbHasItem?(:POKEMONBOXLINK) if $bag.has?(:POKEMONBOXLINK)
if !$game_switches[Settings::DISABLE_BOX_LINK_SWITCH] && if !$game_switches[Settings::DISABLE_BOX_LINK_SWITCH] &&
!$game_map.metadata&.has_flag?("DisableBoxLink") !$game_map.metadata&.has_flag?("DisableBoxLink")
can_access_storage = true can_access_storage = true
@@ -1298,7 +1298,7 @@ class PokemonPartyScreen
itemcommands[itemcommands.length] = _INTL("Cancel") itemcommands[itemcommands.length] = _INTL("Cancel")
command = @scene.pbShowCommands(_INTL("Do what with an item?"),itemcommands) command = @scene.pbShowCommands(_INTL("Do what with an item?"),itemcommands)
if cmdUseItem>=0 && command==cmdUseItem # Use 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.")) @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
} }
if item if item
@@ -1306,7 +1306,7 @@ class PokemonPartyScreen
pbRefreshSingle(pkmnid) pbRefreshSingle(pkmnid)
end end
elsif cmdGiveItem>=0 && command==cmdGiveItem # Give 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.")) @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
} }
if item if item

View File

@@ -1198,7 +1198,7 @@ class PokemonSummary_Scene
item = nil item = nil
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new 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? }) item = screen.pbChooseItemScreen(Proc.new { |itm| GameData::Item.get(itm).can_hold? })
} }
if item if item

View File

@@ -25,7 +25,7 @@ class Window_PokemonBag < Window_DrawableCommand
def pocket=(value) def pocket=(value)
@pocket = value @pocket = value
@item_max = (@filterlist) ? @filterlist[@pocket].length+1 : @bag.pockets[@pocket].length+1 @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 end
def page_row_max; return PokemonBag_Scene::ITEMSVISIBLE; 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] [@adapter.getDisplayName(item),rect.x,rect.y-2,false,baseColor,shadowColor]
) )
if GameData::Item.get(item).is_important? if GameData::Item.get(item).is_important?
if @bag.pbIsRegistered?(item) if @bag.registered?(item)
pbDrawImagePositions(self.contents,[ pbDrawImagePositions(self.contents,[
["Graphics/Pictures/Bag/icon_register",rect.x+rect.width-72,rect.y+8,0,0,-1,24] ["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 @choosing = choosing
@filterproc = filterproc @filterproc = filterproc
pbRefreshFilter pbRefreshFilter
lastpocket = @bag.lastpocket lastpocket = @bag.last_viewed_pocket
numfilledpockets = @bag.pockets.length-1 numfilledpockets = @bag.pockets.length-1
if @choosing if @choosing
numfilledpockets = 0 numfilledpockets = 0
@@ -155,7 +155,7 @@ class PokemonBag_Scene
numfilledpockets += 1 if @bag.pockets[i].length>0 numfilledpockets += 1 if @bag.pockets[i].length>0
end end
end end
lastpocket = (resetpocket) ? 1 : @bag.lastpocket lastpocket = (resetpocket) ? 1 : @bag.last_viewed_pocket
if (@filterlist && @filterlist[lastpocket].length==0) || if (@filterlist && @filterlist[lastpocket].length==0) ||
(!@filterlist && @bag.pockets[lastpocket].length==0) (!@filterlist && @bag.pockets[lastpocket].length==0)
for i in 1...@bag.pockets.length for i in 1...@bag.pockets.length
@@ -169,7 +169,7 @@ class PokemonBag_Scene
end end
end end
end end
@bag.lastpocket = lastpocket @bag.last_viewed_pocket = lastpocket
@sliderbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_slider")) @sliderbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_slider"))
@pocketbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_pocket")) @pocketbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Bag/icon_pocket"))
@sprites = {} @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"] = Window_PokemonBag.new(@bag,@filterlist,lastpocket,168,-8,314,40+32+ITEMSVISIBLE*32)
@sprites["itemlist"].viewport = @viewport @sprites["itemlist"].viewport = @viewport
@sprites["itemlist"].pocket = lastpocket @sprites["itemlist"].pocket = lastpocket
@sprites["itemlist"].index = @bag.getChoice(lastpocket) @sprites["itemlist"].index = @bag.last_viewed_index(lastpocket)
@sprites["itemlist"].baseColor = ITEMLISTBASECOLOR @sprites["itemlist"].baseColor = ITEMLISTBASECOLOR
@sprites["itemlist"].shadowColor = ITEMLISTSHADOWCOLOR @sprites["itemlist"].shadowColor = ITEMLISTSHADOWCOLOR
@sprites["itemicon"] = ItemIconSprite.new(48,Graphics.height-48,nil,@viewport) @sprites["itemicon"] = ItemIconSprite.new(48,Graphics.height-48,nil,@viewport)
@@ -251,13 +251,13 @@ class PokemonBag_Scene
def pbRefresh def pbRefresh
# Set the background image # 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 # 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 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 else
@sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.lastpocket}") @sprites["bagsprite"].setBitmap("Graphics/Pictures/Bag/bag_#{@bag.last_viewed_pocket}")
end end
# Draw the pocket icons # Draw the pocket icons
@sprites["pocketicon"].bitmap.clear @sprites["pocketicon"].bitmap.clear
@@ -283,7 +283,7 @@ class PokemonBag_Scene
overlay.clear overlay.clear
# Draw the pocket name # Draw the pocket name
pbDrawTextPositions(overlay,[ 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 # Draw slider arrows
showslider = false showslider = false
@@ -353,7 +353,7 @@ class PokemonBag_Scene
thispocket.insert(itemwindow.index,thispocket.delete_at(oldindex)) thispocket.insert(itemwindow.index,thispocket.delete_at(oldindex))
end end
# Update selected item for current pocket # Update selected item for current pocket
@bag.setChoice(itemwindow.pocket,itemwindow.index) @bag.set_last_viewed_index(itemwindow.pocket,itemwindow.index)
pbRefresh pbRefresh
end end
if itemwindow.sorting if itemwindow.sorting
@@ -374,7 +374,7 @@ class PokemonBag_Scene
if Input.trigger?(Input::LEFT) if Input.trigger?(Input::LEFT)
newpocket = itemwindow.pocket newpocket = itemwindow.pocket
loop do loop do
newpocket = (newpocket==1) ? PokemonBag.numPockets : newpocket-1 newpocket = (newpocket==1) ? PokemonBag.pocket_count : newpocket-1
break if !@choosing || newpocket==itemwindow.pocket break if !@choosing || newpocket==itemwindow.pocket
if @filterlist if @filterlist
break if @filterlist[newpocket].length>0 break if @filterlist[newpocket].length>0
@@ -384,7 +384,7 @@ class PokemonBag_Scene
end end
if itemwindow.pocket!=newpocket if itemwindow.pocket!=newpocket
itemwindow.pocket = newpocket itemwindow.pocket = newpocket
@bag.lastpocket = itemwindow.pocket @bag.last_viewed_pocket = itemwindow.pocket
thispocket = @bag.pockets[itemwindow.pocket] thispocket = @bag.pockets[itemwindow.pocket]
pbPlayCursorSE pbPlayCursorSE
pbRefresh pbRefresh
@@ -392,7 +392,7 @@ class PokemonBag_Scene
elsif Input.trigger?(Input::RIGHT) elsif Input.trigger?(Input::RIGHT)
newpocket = itemwindow.pocket newpocket = itemwindow.pocket
loop do loop do
newpocket = (newpocket==PokemonBag.numPockets) ? 1 : newpocket+1 newpocket = (newpocket==PokemonBag.pocket_count) ? 1 : newpocket+1
break if !@choosing || newpocket==itemwindow.pocket break if !@choosing || newpocket==itemwindow.pocket
if @filterlist if @filterlist
break if @filterlist[newpocket].length>0 break if @filterlist[newpocket].length>0
@@ -402,17 +402,17 @@ class PokemonBag_Scene
end end
if itemwindow.pocket!=newpocket if itemwindow.pocket!=newpocket
itemwindow.pocket = newpocket itemwindow.pocket = newpocket
@bag.lastpocket = itemwindow.pocket @bag.last_viewed_pocket = itemwindow.pocket
thispocket = @bag.pockets[itemwindow.pocket] thispocket = @bag.pockets[itemwindow.pocket]
pbPlayCursorSE pbPlayCursorSE
pbRefresh pbRefresh
end end
# elsif Input.trigger?(Input::SPECIAL) # Register/unregister selected item # elsif Input.trigger?(Input::SPECIAL) # Register/unregister selected item
# if !@choosing && itemwindow.index<thispocket.length # if !@choosing && itemwindow.index<thispocket.length
# if @bag.pbIsRegistered?(itemwindow.item) # if @bag.registered?(itemwindow.item)
# @bag.pbUnregisterItem(itemwindow.item) # @bag.unregister(itemwindow.item)
# elsif pbCanRegisterItem?(itemwindow.item) # elsif pbCanRegisterItem?(itemwindow.item)
# @bag.pbRegisterItem(itemwindow.item) # @bag.register(itemwindow.item)
# end # end
# pbPlayDecisionSE # pbPlayDecisionSE
# pbRefresh # pbRefresh
@@ -474,7 +474,7 @@ class PokemonBagScreen
end end
commands[cmdGive = commands.length] = _INTL("Give") if $Trainer.pokemon_party.length > 0 && itm.can_hold? commands[cmdGive = commands.length] = _INTL("Give") if $Trainer.pokemon_party.length > 0 && itm.can_hold?
commands[cmdToss = commands.length] = _INTL("Toss") if !itm.is_important? || $DEBUG 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") commands[cmdRegister = commands.length] = _INTL("Deselect")
elsif pbCanRegisterItem?(item) elsif pbCanRegisterItem?(item)
commands[cmdRegister = commands.length] = _INTL("Register") commands[cmdRegister = commands.length] = _INTL("Register")
@@ -508,7 +508,7 @@ class PokemonBagScreen
} }
end end
elsif cmdToss>=0 && command==cmdToss # Toss item elsif cmdToss>=0 && command==cmdToss # Toss item
qty = @bag.pbQuantity(item) qty = @bag.quantity(item)
if qty>1 if qty>1
helptext = _INTL("Toss out how many {1}?",itm.name_plural) helptext = _INTL("Toss out how many {1}?",itm.name_plural)
qty = @scene.pbChooseNumber(helptext,qty) qty = @scene.pbChooseNumber(helptext,qty)
@@ -517,15 +517,15 @@ class PokemonBagScreen
itemname = itm.name_plural if qty>1 itemname = itm.name_plural if qty>1
if pbConfirm(_INTL("Is it OK to throw away {1} {2}?",qty,itemname)) if pbConfirm(_INTL("Is it OK to throw away {1} {2}?",qty,itemname))
pbDisplay(_INTL("Threw 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 @scene.pbRefresh
end end
end end
elsif cmdRegister>=0 && command==cmdRegister # Register item elsif cmdRegister>=0 && command==cmdRegister # Register item
if @bag.pbIsRegistered?(item) if @bag.registered?(item)
@bag.pbUnregisterItem(item) @bag.unregister(item)
else else
@bag.pbRegisterItem(item) @bag.register(item)
end end
@scene.pbRefresh @scene.pbRefresh
elsif cmdDebug>=0 && command==cmdDebug # Debug elsif cmdDebug>=0 && command==cmdDebug # Debug
@@ -542,7 +542,7 @@ class PokemonBagScreen
break break
### Change quantity ### ### Change quantity ###
when 0 when 0
qty = @bag.pbQuantity(item) qty = @bag.quantity(item)
itemplural = itm.name_plural itemplural = itm.name_plural
params = ChooseNumberParams.new params = ChooseNumberParams.new
params.setRange(0, Settings::BAG_MAX_PER_SLOT) params.setRange(0, Settings::BAG_MAX_PER_SLOT)
@@ -550,9 +550,9 @@ class PokemonBagScreen
newqty = pbMessageChooseNumber( newqty = pbMessageChooseNumber(
_INTL("Choose new quantity of {1} (max. #{Settings::BAG_MAX_PER_SLOT}).",itemplural),params) { @scene.pbUpdate } _INTL("Choose new quantity of {1} (max. #{Settings::BAG_MAX_PER_SLOT}).",itemplural),params) { @scene.pbUpdate }
if newqty>qty if newqty>qty
@bag.pbStoreItem(item,newqty-qty) @bag.add(item, newqty - qty)
elsif newqty<qty elsif newqty<qty
@bag.pbDeleteItem(item,qty-newqty) @bag.remove(item, qty - newqty)
end end
@scene.pbRefresh @scene.pbRefresh
break if newqty==0 break if newqty==0
@@ -577,13 +577,13 @@ class PokemonBagScreen
# UI logic for the item screen for choosing an item. # UI logic for the item screen for choosing an item.
def pbChooseItemScreen(proc=nil) def pbChooseItemScreen(proc=nil)
oldlastpocket = @bag.lastpocket oldlastpocket = @bag.last_viewed_pocket
oldchoices = @bag.getAllChoices oldchoices = @bag.last_pocket_selections.clone
@scene.pbStartScene(@bag,true,proc) @scene.pbStartScene(@bag,true,proc)
item = @scene.pbChooseItem item = @scene.pbChooseItem
@scene.pbEndScene @scene.pbEndScene
@bag.lastpocket = oldlastpocket @bag.last_viewed_pocket = oldlastpocket
@bag.setAllChoices(oldchoices) @bag.last_pocket_selections = oldchoices
return item return item
end end
@@ -598,16 +598,16 @@ class PokemonBagScreen
item = @scene.pbChooseItem item = @scene.pbChooseItem
break if !item break if !item
itm = GameData::Item.get(item) itm = GameData::Item.get(item)
qty = storage.pbQuantity(item) qty = storage.quantity(item)
if qty>1 && !itm.is_important? if qty>1 && !itm.is_important?
qty = @scene.pbChooseNumber(_INTL("How many do you want to withdraw?"),qty) qty = @scene.pbChooseNumber(_INTL("How many do you want to withdraw?"),qty)
end end
next if qty<=0 next if qty<=0
if @bag.pbCanStore?(item,qty) if @bag.can_add?(item,qty)
if !storage.pbDeleteItem(item,qty) if !storage.remove(item,qty)
raise "Can't delete items from storage" raise "Can't delete items from storage"
end end
if !@bag.pbStoreItem(item,qty) if !@bag.add(item,qty)
raise "Can't withdraw items from storage" raise "Can't withdraw items from storage"
end end
@scene.pbRefresh @scene.pbRefresh
@@ -632,18 +632,18 @@ class PokemonBagScreen
item = @scene.pbChooseItem item = @scene.pbChooseItem
break if !item break if !item
itm = GameData::Item.get(item) itm = GameData::Item.get(item)
qty = @bag.pbQuantity(item) qty = @bag.quantity(item)
if qty>1 && !itm.is_important? if qty>1 && !itm.is_important?
qty = @scene.pbChooseNumber(_INTL("How many do you want to deposit?"),qty) qty = @scene.pbChooseNumber(_INTL("How many do you want to deposit?"),qty)
end end
if qty>0 if qty>0
if !storage.pbCanStore?(item,qty) if !storage.can_add?(item,qty)
pbDisplay(_INTL("There's no room to store items.")) pbDisplay(_INTL("There's no room to store items."))
else else
if !@bag.pbDeleteItem(item,qty) if !@bag.remove(item,qty)
raise "Can't delete items from Bag" raise "Can't delete items from Bag"
end end
if !storage.pbStoreItem(item,qty) if !storage.add(item,qty)
raise "Can't deposit items to storage" raise "Can't deposit items to storage"
end end
@scene.pbRefresh @scene.pbRefresh
@@ -671,7 +671,7 @@ class PokemonBagScreen
@scene.pbDisplay(_INTL("That's too important to toss out!")) @scene.pbDisplay(_INTL("That's too important to toss out!"))
next next
end end
qty = storage.pbQuantity(item) qty = storage.quantity(item)
itemname = itm.name itemname = itm.name
itemnameplural = itm.name_plural itemnameplural = itm.name_plural
if qty>1 if qty>1
@@ -680,7 +680,7 @@ class PokemonBagScreen
if qty>0 if qty>0
itemname = itemnameplural if qty>1 itemname = itemnameplural if qty>1
if pbConfirm(_INTL("Is it OK to throw away {1} {2}?",qty,itemname)) 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" raise "Can't delete items from storage"
end end
@scene.pbRefresh @scene.pbRefresh

View File

@@ -75,7 +75,7 @@ class ReadyMenuButton < SpriteWrapper
] ]
if !@command[2] if !@command[2]
if !GameData::Item.get(@command[0]).is_important? if !GameData::Item.get(@command[0]).is_important?
qty = $PokemonBag.pbQuantity(@command[0]) qty = $bag.quantity(@command[0])
if qty>99 if qty>99
textpos.push([_INTL(">99"),230,16,1, textpos.push([_INTL(">99"),230,16,1,
Color.new(248,248,248),Color.new(40,40,40),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 for i in 0...@commands[1].length
@itemcommands.push(@commands[1][i][1]) @itemcommands.push(@commands[1][i][1])
end end
@index = $PokemonBag.registeredIndex @index = $bag.ready_menu_selection
if @index[0]>=@movecommands.length && @movecommands.length>0 if @index[0]>=@movecommands.length && @movecommands.length>0
@index[0] = @movecommands.length-1 @index[0] = @movecommands.length-1
end end
@@ -312,9 +312,9 @@ def pbUseKeyItem
end end
end end
real_items = [] real_items = []
for i in $PokemonBag.registeredItems for i in $bag.registered_items
itm = GameData::Item.get(i).id itm = GameData::Item.get(i).id
real_items.push(itm) if $PokemonBag.pbHasItem?(itm) real_items.push(itm) if $bag.has?(itm)
end end
if real_items.length == 0 && real_moves.length == 0 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.")) pbMessage(_INTL("An item in the Bag can be registered to this key for instant use."))

View File

@@ -1873,7 +1873,7 @@ class PokemonStorageScreen
if pokemon.item if pokemon.item
itemname = pokemon.item.name itemname = pokemon.item.name
if pbConfirm(_INTL("Take this {1}?",itemname)) 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)) pbDisplay(_INTL("Can't store the {1}.",itemname))
else else
pbDisplay(_INTL("Took the {1}.",itemname)) pbDisplay(_INTL("Took the {1}.",itemname))
@@ -1882,11 +1882,11 @@ class PokemonStorageScreen
end end
end end
else else
item = scene.pbChooseItem($PokemonBag) item = scene.pbChooseItem($bag)
if item if item
itemname = GameData::Item.get(item).name itemname = GameData::Item.get(item).name
pokemon.item = item pokemon.item = item
$PokemonBag.pbDeleteItem(item) $bag.remove(item)
pbDisplay(_INTL("{1} is now being held.",itemname)) pbDisplay(_INTL("{1} is now being held.",itemname))
@scene.pbHardRefresh @scene.pbHardRefresh
end end

View File

@@ -134,14 +134,14 @@ def pbPCItemStorage
else else
pbFadeOutIn { pbFadeOutIn {
scene = WithdrawItemScene.new scene = WithdrawItemScene.new
screen = PokemonBagScreen.new(scene,$PokemonBag) screen = PokemonBagScreen.new(scene, $bag)
screen.pbWithdrawItemScreen screen.pbWithdrawItemScreen
} }
end end
when 1 # Deposit Item when 1 # Deposit Item
pbFadeOutIn { pbFadeOutIn {
scene = PokemonBag_Scene.new scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene,$PokemonBag) screen = PokemonBagScreen.new(scene, $bag)
screen.pbDepositItemScreen screen.pbDepositItemScreen
} }
when 2 # Toss Item when 2 # Toss Item
@@ -153,7 +153,7 @@ def pbPCItemStorage
else else
pbFadeOutIn { pbFadeOutIn {
scene = TossItemScene.new scene = TossItemScene.new
screen = PokemonBagScreen.new(scene,$PokemonBag) screen = PokemonBagScreen.new(scene, $bag)
screen.pbTossItemScreen screen.pbTossItemScreen
} }
end end
@@ -191,7 +191,7 @@ def pbPCMailbox
} }
when 1 # Move to Bag when 1 # Move to Bag
if pbConfirmMessage(_INTL("The message will be lost. Is that OK?")) 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.")) pbMessage(_INTL("The Mail was returned to the Bag with its message erased."))
$PokemonGlobal.mailbox.delete_at(mailIndex) $PokemonGlobal.mailbox.delete_at(mailIndex)
else else

View File

@@ -15,7 +15,7 @@ class PokemonMartAdapter
end end
def getInventory def getInventory
return $PokemonBag return $bag
end end
def getName(item) def getName(item)
@@ -45,7 +45,7 @@ class PokemonMartAdapter
end end
def getQuantity(item) def getQuantity(item)
return $PokemonBag.pbQuantity(item) return $bag.quantity(item)
end end
def showQuantity?(item) def showQuantity?(item)
@@ -74,11 +74,11 @@ class PokemonMartAdapter
end end
def addItem(item) def addItem(item)
return $PokemonBag.pbStoreItem(item) return $bag.add(item)
end end
def removeItem(item) def removeItem(item)
return $PokemonBag.pbDeleteItem(item) return $bag.remove(item)
end end
end end
@@ -241,7 +241,7 @@ class PokemonMart_Scene
end end
def pbStartSellScene(bag, adapter) def pbStartSellScene(bag, adapter)
if $PokemonBag if $bag
pbStartSellScene2(bag, adapter) pbStartSellScene2(bag, adapter)
else else
pbStartBuyOrSellScene(false, bag, adapter) pbStartBuyOrSellScene(false, bag, adapter)
@@ -588,9 +588,9 @@ class PokemonMartScreen
pbDisplayPaused(_INTL("You have no more room in the Bag.")) pbDisplayPaused(_INTL("You have no more room in the Bag."))
else else
@adapter.setMoney(@adapter.getMoney-price) @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") } 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? if Settings::MORE_BONUS_PREMIER_BALLS && GameData::Item.get(item).is_poke_ball?
premier_balls_added = 0 premier_balls_added = 0
(quantity / 10).times do (quantity / 10).times do
@@ -655,7 +655,7 @@ end
# #
#=============================================================================== #===============================================================================
def pbPokemonMart(stock,speech=nil,cantsell=false) 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 = [] commands = []
cmdBuy = -1 cmdBuy = -1
cmdSell = -1 cmdSell = -1

View File

@@ -396,8 +396,8 @@ def pbReceiveMysteryGift(id)
elsif gift[1]>0 # Item elsif gift[1]>0 # Item
item=gift[2] item=gift[2]
qty=gift[1] qty=gift[1]
if $PokemonBag.pbCanStore?(item,qty) if $bag.can_add?(item,qty)
$PokemonBag.pbStoreItem(item,qty) $bag.add(item,qty)
itm = GameData::Item.get(item) itm = GameData::Item.get(item)
itemname=(qty>1) ? itm.name_plural : itm.name itemname=(qty>1) ? itm.name_plural : itm.name
if item == :LEFTOVERS if item == :LEFTOVERS

View File

@@ -301,7 +301,7 @@ class TriadScene
elsif Input.trigger?(Input::USE) elsif Input.trigger?(Input::USE)
break if chosenCards.length==@battle.maxCards break if chosenCards.length==@battle.maxCards
item = cardStorage[command.index] item = cardStorage[command.index]
if !item || @battle.pbQuantity(cardStorage,item[0])==0 if !item || @battle.quantity(cardStorage,item[0])==0
pbPlayBuzzerSE pbPlayBuzzerSE
else else
pbPlayDecisionSE pbPlayDecisionSE
@@ -631,17 +631,17 @@ class TriadScreen
return @board[y*@width+x] return @board[y*@width+x]
end end
def pbQuantity(items,item) def quantity(items,item)
return ItemStorageHelper.pbQuantity(items, item) return ItemStorageHelper.quantity(items, item)
end end
def pbAdd(items,item) def pbAdd(items,item)
return ItemStorageHelper.pbStoreItem(items,$PokemonGlobal.triads.maxSize, return ItemStorageHelper.add(items, $PokemonGlobal.triads.maxSize,
$PokemonGlobal.triads.maxPerSlot,item,1) TriadStorage::MAX_PER_SLOT, item, 1)
end end
def pbSubtract(items, item) def pbSubtract(items, item)
return ItemStorageHelper.pbDeleteItem(items, item, 1) return ItemStorageHelper.remove(items, item, 1)
end end
def flipBoard(x,y,attackerParam=nil,recurse=false) def flipBoard(x,y,attackerParam=nil,recurse=false)
@@ -718,11 +718,8 @@ class TriadScreen
count = 0 count = 0
for i in 0...$PokemonGlobal.triads.length for i in 0...$PokemonGlobal.triads.length
item = $PokemonGlobal.triads[i] item = $PokemonGlobal.triads[i]
ItemStorageHelper.pbStoreItem(@triadCards, ItemStorageHelper.add(@triadCards, $PokemonGlobal.triads.maxSize,
$PokemonGlobal.triads.maxSize, TriadStorage::MAX_PER_SLOT, item[0], item[1])
$PokemonGlobal.triads.maxPerSlot,
item[0],item[1]
)
count += item[1] # Add item count to total count count += item[1] # Add item count to total count
end end
@board = [] @board = []
@@ -880,15 +877,15 @@ class TriadScreen
if @trade==1 if @trade==1
# Keep only cards of your color # Keep only cards of your color
for card in originalCards for card in originalCards
$PokemonGlobal.triads.pbDeleteItem(card) $PokemonGlobal.triads.remove(card)
end end
for i in cards for i in cards
$PokemonGlobal.triads.pbStoreItem(i) $PokemonGlobal.triads.add(i)
end end
for i in 0...@width*@height for i in 0...@width*@height
if board[i].owner==1 if board[i].owner==1
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id 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
end end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color.")) @scene.pbDisplayPaused(_INTL("Kept all cards of your color."))
@@ -898,34 +895,34 @@ class TriadScreen
result = 1 result = 1
if prize if prize
species_data = GameData::Species.try_get(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)) @scene.pbDisplayPaused(_INTL("Got opponent's {1} card.", species_data.name))
end end
else else
case @trade case @trade
when 0 # Gain 1 random card from opponent's deck when 0 # Gain 1 random card from opponent's deck
card = originalOpponentCards[rand(originalOpponentCards.length)] card = originalOpponentCards[rand(originalOpponentCards.length)]
if $PokemonGlobal.triads.pbStoreItem(card) if $PokemonGlobal.triads.add(card)
cardname = GameData::Species.get(card).name cardname = GameData::Species.get(card).name
@scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname)) @scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname))
end end
when 1 # Keep only cards of your color when 1 # Keep only cards of your color
for card in originalCards for card in originalCards
$PokemonGlobal.triads.pbDeleteItem(card) $PokemonGlobal.triads.remove(card)
end end
for i in cards for i in cards
$PokemonGlobal.triads.pbStoreItem(i) $PokemonGlobal.triads.add(i)
end end
for i in 0...@width*@height for i in 0...@width*@height
if board[i].owner==1 if board[i].owner==1
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id 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
end end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color.")) @scene.pbDisplayPaused(_INTL("Kept all cards of your color."))
when 2 # Gain all opponent's cards when 2 # Gain all opponent's cards
for card in originalOpponentCards for card in originalOpponentCards
$PokemonGlobal.triads.pbStoreItem(card) $PokemonGlobal.triads.add(card)
end end
@scene.pbDisplayPaused(_INTL("Got all opponent's cards.")) @scene.pbDisplayPaused(_INTL("Got all opponent's cards."))
end end
@@ -936,26 +933,26 @@ class TriadScreen
case @trade case @trade
when 0 # Lose 1 random card from your deck when 0 # Lose 1 random card from your deck
card = originalCards[rand(originalCards.length)] card = originalCards[rand(originalCards.length)]
$PokemonGlobal.triads.pbDeleteItem(card) $PokemonGlobal.triads.remove(card)
cardname = GameData::Species.get(card).name cardname = GameData::Species.get(card).name
@scene.pbDisplayPaused(_INTL("Opponent won your {1} card.",cardname)) @scene.pbDisplayPaused(_INTL("Opponent won your {1} card.",cardname))
when 1 # Keep only cards of your color when 1 # Keep only cards of your color
for card in originalCards for card in originalCards
$PokemonGlobal.triads.pbDeleteItem(card) $PokemonGlobal.triads.remove(card)
end end
for i in cards for i in cards
$PokemonGlobal.triads.pbStoreItem(i) $PokemonGlobal.triads.add(i)
end end
for i in 0...@width*@height for i in 0...@width*@height
if board[i].owner==1 if board[i].owner==1
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id 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
end end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color.",cardname)) @scene.pbDisplayPaused(_INTL("Kept all cards of your color.",cardname))
when 2 # Lose all your cards when 2 # Lose all your cards
for card in originalCards for card in originalCards
$PokemonGlobal.triads.pbDeleteItem(card) $PokemonGlobal.triads.remove(card)
end end
@scene.pbDisplayPaused(_INTL("Opponent won all your cards.")) @scene.pbDisplayPaused(_INTL("Opponent won all your cards."))
end end
@@ -999,54 +996,57 @@ end
class TriadStorage class TriadStorage
attr_reader :items attr_reader :items
MAX_PER_SLOT = 999 # Max. number of items per slot
def initialize def initialize
@items = [] @items = []
end 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) def [](i)
return @items[i] return @items[i]
end 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 nil if index < 0 || index >= @items.length
return @items[index][0] return @items[index][0]
end 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 0 if index < 0 || index >= @items.length
return @items[index][1] return @items[index][1]
end end
def pbQuantity(item) def quantity(item)
return ItemStorageHelper.pbQuantity(@items, item) return ItemStorageHelper.quantity(@items, item)
end end
def pbCanStore?(item, qty = 1) def can_add?(item, qty = 1)
return ItemStorageHelper.pbCanStore?(@items, self.maxSize, self.maxPerSlot, item, qty) return ItemStorageHelper.can_add?(@items, self.maxSize, MAX_PER_SLOT, item, qty)
end end
def pbStoreItem(item, qty = 1) def add(item, qty = 1)
return ItemStorageHelper.pbStoreItem(@items, self.maxSize, self.maxPerSlot, item, qty) return ItemStorageHelper.add(@items, self.maxSize, MAX_PER_SLOT, item, qty)
end end
def pbDeleteItem(item, qty = 1) def remove(item, qty = 1)
return ItemStorageHelper.pbDeleteItem(@items, item, qty) return ItemStorageHelper.remove(@items, item, qty)
end end
end end
@@ -1126,11 +1126,11 @@ def pbBuyTriads
pbMessage(_INTL("You don't have enough money.")) pbMessage(_INTL("You don't have enough money."))
next next
end end
if !$PokemonGlobal.triads.pbCanStore?(item,quantity) if !$PokemonGlobal.triads.can_add?(item, quantity)
pbMessage(_INTL("You have no room for more cards.")) pbMessage(_INTL("You have no room for more cards."))
next next
end end
$PokemonGlobal.triads.pbStoreItem(item,quantity) $PokemonGlobal.triads.add(item, quantity)
$Trainer.money -= price $Trainer.money -= price
goldwindow.text = _INTL("Money:\r\n{1}",pbGetGoldString) goldwindow.text = _INTL("Money:\r\n{1}",pbGetGoldString)
pbMessage(_INTL("Here you are! Thank you!\\se[Mart buy item]")) 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.x = Graphics.width*3/4-40
preview.y = Graphics.height/2-48 preview.y = Graphics.height/2-48
preview.z = 4 preview.z = 4
item = $PokemonGlobal.triads.getItem(cmdwindow.index) item = $PokemonGlobal.triads.get_item(cmdwindow.index)
preview.bitmap = TriadCard.new(item).createBitmap(1) preview.bitmap = TriadCard.new(item).createBitmap(1)
olditem = $PokemonGlobal.triads.getItem(cmdwindow.index) olditem = $PokemonGlobal.triads.get_item(cmdwindow.index)
done = false done = false
Graphics.frame_reset Graphics.frame_reset
while !done while !done
@@ -1183,7 +1183,7 @@ def pbSellTriads
cmdwindow.active = true cmdwindow.active = true
cmdwindow.update cmdwindow.update
goldwindow.update goldwindow.update
item = $PokemonGlobal.triads.getItem(cmdwindow.index) item = $PokemonGlobal.triads.get_item(cmdwindow.index)
if olditem != item if olditem != item
preview.bitmap.dispose if preview.bitmap preview.bitmap.dispose if preview.bitmap
if item if item
@@ -1200,9 +1200,9 @@ def pbSellTriads
done = true done = true
break break
end end
item = $PokemonGlobal.triads.getItem(cmdwindow.index) item = $PokemonGlobal.triads.get_item(cmdwindow.index)
itemname = GameData::Species.get(item).name itemname = GameData::Species.get(item).name
quantity = $PokemonGlobal.triads.pbQuantity(item) quantity = $PokemonGlobal.triads.quantity(item)
price = TriadCard.new(item).price price = TriadCard.new(item).price
if price==0 if price==0
pbDisplayPaused(_INTL("The {1} card? Oh, no. I can't buy that.",itemname)) 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)) if pbConfirmMessage(_INTL("I can pay ${1}. Would that be OK?",price.to_s_formatted))
$Trainer.money += price $Trainer.money += price
goldwindow.text = _INTL("Money:\r\n{1}",pbGetGoldString) 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)) pbMessage(_INTL("Turned over the {1} card and received ${2}.\\se[Mart buy item]",itemname,price.to_s_formatted))
commands = [] commands = []
for i in 0...$PokemonGlobal.triads.length for i in 0...$PokemonGlobal.triads.length
@@ -1277,7 +1277,7 @@ def pbTriadList
if lastIndex!=cmdwindow.index if lastIndex!=cmdwindow.index
sprite.bitmap.dispose if sprite.bitmap sprite.bitmap.dispose if sprite.bitmap
if cmdwindow.index<$PokemonGlobal.triads.length 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 end
lastIndex = cmdwindow.index lastIndex = cmdwindow.index
end end
@@ -1303,7 +1303,7 @@ end
def pbGiveTriadCard(species, quantity = 1) def pbGiveTriadCard(species, quantity = 1)
sp = GameData::Species.try_get(species) sp = GameData::Species.try_get(species)
return false if !sp return false if !sp
return false if !$PokemonGlobal.triads.pbCanStore?(sp.id, quantity) return false if !$PokemonGlobal.triads.can_add?(sp.id, quantity)
$PokemonGlobal.triads.pbStoreItem(sp.id, quantity) $PokemonGlobal.triads.add(sp.id, quantity)
return true return true
end end

View File

@@ -388,7 +388,7 @@ end
def pbSlotMachine(difficulty=1) def pbSlotMachine(difficulty=1)
if GameData::Item.exists?(:COINCASE) && !$PokemonBag.pbHasItem?(:COINCASE) if !$bag.has?(:COINCASE)
pbMessage(_INTL("It's a Slot Machine.")) pbMessage(_INTL("It's a Slot Machine."))
elsif $Trainer.coins == 0 elsif $Trainer.coins == 0
pbMessage(_INTL("You don't have any Coins to play!")) pbMessage(_INTL("You don't have any Coins to play!"))

View File

@@ -614,7 +614,7 @@ end
def pbVoltorbFlip 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.")) pbMessage(_INTL("You can't play unless you have a Coin Case."))
elsif $Trainer.coins == Settings::MAX_COINS elsif $Trainer.coins == Settings::MAX_COINS
pbMessage(_INTL("Your Coin Case is full!")) pbMessage(_INTL("Your Coin Case is full!"))

View File

@@ -586,7 +586,7 @@ class MiningGameScene
def pbGiveItems def pbGiveItems
if @itemswon.length>0 if @itemswon.length>0
for i in @itemswon for i in @itemswon
if $PokemonBag.pbStoreItem(i) if $bag.add(i)
pbMessage(_INTL("One {1} was obtained.\\se[Mining item get]\\wtnp[30]", pbMessage(_INTL("One {1} was obtained.\\se[Mining item get]\\wtnp[30]",
GameData::Item.get(i).name)) GameData::Item.get(i).name))
else else

View File

@@ -481,7 +481,7 @@ DebugMenuCommands.register("additem", {
qty = pbMessageChooseNumber(_INTL("Add how many {1}?", qty = pbMessageChooseNumber(_INTL("Add how many {1}?",
GameData::Item.get(item).name_plural), params) GameData::Item.get(item).name_plural), params)
if qty > 0 if qty > 0
$PokemonBag.pbStoreItem(item, qty) $bag.add(item, qty)
pbMessage(_INTL("Gave {1}x {2}.", qty, GameData::Item.get(item).name)) pbMessage(_INTL("Gave {1}x {2}.", qty, GameData::Item.get(item).name))
end end
end end
@@ -500,11 +500,11 @@ DebugMenuCommands.register("fillbag", {
params.setCancelValue(0) params.setCancelValue(0)
qty = pbMessageChooseNumber(_INTL("Choose the number of items."), params) qty = pbMessageChooseNumber(_INTL("Choose the number of items."), params)
if qty > 0 if qty > 0
$PokemonBag.clear $bag.clear
# NOTE: This doesn't simply use $PokemonBag.pbStoreItem for every item in # NOTE: This doesn't simply use $bag.add for every item in turn, because
# turn, because that's really slow when done in bulk. # that's really slow when done in bulk.
pocket_sizes = Settings::BAG_MAX_POCKET_SIZE 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| GameData::Item.each do |i|
next if !pocket_sizes[i.pocket] || pocket_sizes[i.pocket] == 0 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] 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"), "name" => _INTL("Empty Bag"),
"description" => _INTL("Remove all items from the Bag."), "description" => _INTL("Remove all items from the Bag."),
"effect" => proc { "effect" => proc {
$PokemonBag.clear $bag.clear
pbMessage(_INTL("The Bag was cleared.")) pbMessage(_INTL("The Bag was cleared."))
} }
}) })

View File

@@ -926,7 +926,7 @@ module Compiler
list.delete_at(i) list.delete_at(i)
newEvents = [] newEvents = []
if cost==0 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_text(newEvents,_INTL("Here you go!"),oldIndent+1)
push_script(newEvents,"pbReceiveItem(:#{itemname})",oldIndent+1) push_script(newEvents,"pbReceiveItem(:#{itemname})",oldIndent+1)
push_else(newEvents,oldIndent+1) push_else(newEvents,oldIndent+1)
@@ -934,7 +934,7 @@ module Compiler
push_branch_end(newEvents,oldIndent+1) push_branch_end(newEvents,oldIndent+1)
else else
push_event(newEvents,111,[7,cost,0],oldIndent) 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_event(newEvents,125,[1,0,cost],oldIndent+2)
push_text(newEvents,_INTL("\\GHere you go!"),oldIndent+2) push_text(newEvents,_INTL("\\GHere you go!"),oldIndent+2)
push_script(newEvents,"pbReceiveItem(:#{itemname})",oldIndent+2) push_script(newEvents,"pbReceiveItem(:#{itemname})",oldIndent+2)