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

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

View File

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

View File

@@ -1198,7 +1198,7 @@ class PokemonSummary_Scene
item = nil
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene,$PokemonBag)
screen = PokemonBagScreen.new(scene, $bag)
item = screen.pbChooseItemScreen(Proc.new { |itm| GameData::Item.get(itm).can_hold? })
}
if item

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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