mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2026-01-22 14:26:01 +00:00
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:
@@ -579,7 +579,7 @@ def pbUseItem(bag,item,bagscene=nil)
|
||||
if !pbConfirmMessage(_INTL("Do you want to teach {1} to a Pokémon?",movename))
|
||||
return 0
|
||||
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
|
||||
end
|
||||
return 0
|
||||
@@ -612,8 +612,8 @@ def pbUseItem(bag,item,bagscene=nil)
|
||||
if pbCheckUseOnPokemon(item,pkmn,screen)
|
||||
ret = ItemHandlers.triggerUseOnPokemon(item,pkmn,screen)
|
||||
if ret && itm.consumed_after_use?
|
||||
bag.pbDeleteItem(item)
|
||||
if !bag.pbHasItem?(item)
|
||||
bag.remove(item)
|
||||
if !bag.has?(item)
|
||||
pbMessage(_INTL("You used your last {1}.",itm.name)) { screen.pbUpdate }
|
||||
break
|
||||
end
|
||||
@@ -627,7 +627,7 @@ def pbUseItem(bag,item,bagscene=nil)
|
||||
elsif useType==2 # Item is usable from Bag
|
||||
intret = ItemHandlers.triggerUseFromBag(item)
|
||||
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
|
||||
end
|
||||
pbMessage(_INTL("Can't use that here."))
|
||||
@@ -654,7 +654,7 @@ def pbUseItemOnPokemon(item,pkmn,scene)
|
||||
pbMessage(_INTL("\\se[PC access]You booted up {1}.\1",itm.name)) { scene.pbUpdate }
|
||||
if pbConfirmMessage(_INTL("Do you want to teach {1} to {2}?",movename,pkmn.name)) { scene.pbUpdate }
|
||||
if pbLearnMove(pkmn,machine,false,true) { scene.pbUpdate }
|
||||
$PokemonBag.pbDeleteItem(item) if itm.consumed_after_use?
|
||||
$bag.remove(item) if itm.consumed_after_use?
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -666,8 +666,8 @@ def pbUseItemOnPokemon(item,pkmn,scene)
|
||||
scene.pbClearAnnotations
|
||||
scene.pbHardRefresh
|
||||
if ret && itm.consumed_after_use?
|
||||
$PokemonBag.pbDeleteItem(item)
|
||||
if !$PokemonBag.pbHasItem?(item)
|
||||
$bag.remove(item)
|
||||
if !$bag.has?(item)
|
||||
pbMessage(_INTL("You used your last {1}.",itm.name)) { scene.pbUpdate }
|
||||
end
|
||||
end
|
||||
@@ -679,7 +679,7 @@ def pbUseKeyItemInField(item)
|
||||
if ret==-1 # Item effect not found
|
||||
pbMessage(_INTL("Can't use that here."))
|
||||
elsif ret > 0 && GameData::Item.get(item).consumed_after_use?
|
||||
$PokemonBag.pbDeleteItem(item)
|
||||
$bag.remove(item)
|
||||
end
|
||||
return ret > 0
|
||||
end
|
||||
@@ -719,9 +719,9 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0)
|
||||
scene.pbDisplay(_INTL("{1} is already holding a {2}.\1",pkmn.name,olditemname))
|
||||
end
|
||||
if scene.pbConfirm(_INTL("Would you like to switch the two items?"))
|
||||
$PokemonBag.pbDeleteItem(item)
|
||||
if !$PokemonBag.pbStoreItem(pkmn.item)
|
||||
if !$PokemonBag.pbStoreItem(item)
|
||||
$bag.remove(item)
|
||||
if !$bag.add(pkmn.item)
|
||||
if !$bag.add(item)
|
||||
raise _INTL("Could't re-store deleted item in Bag somehow")
|
||||
end
|
||||
scene.pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed."))
|
||||
@@ -732,7 +732,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0)
|
||||
scene.pbDisplay(_INTL("Took the {1} from {2} and gave it the {3}.",olditemname,pkmn.name,newitemname))
|
||||
return true
|
||||
else
|
||||
if !$PokemonBag.pbStoreItem(item)
|
||||
if !$bag.add(item)
|
||||
raise _INTL("Couldn't re-store deleted item in Bag somehow")
|
||||
end
|
||||
end
|
||||
@@ -745,7 +745,7 @@ def pbGiveItemToPokemon(item,pkmn,scene,pkmnid=0)
|
||||
end
|
||||
else
|
||||
if !GameData::Item.get(item).is_mail? || pbWriteMail(item,pkmn,pkmnid,scene)
|
||||
$PokemonBag.pbDeleteItem(item)
|
||||
$bag.remove(item)
|
||||
pkmn.item = item
|
||||
scene.pbDisplay(_INTL("{1} is now holding the {2}.",pkmn.name,newitemname))
|
||||
return true
|
||||
@@ -758,7 +758,7 @@ def pbTakeItemFromPokemon(pkmn,scene)
|
||||
ret = false
|
||||
if !pkmn.hasItem?
|
||||
scene.pbDisplay(_INTL("{1} isn't holding anything.",pkmn.name))
|
||||
elsif !$PokemonBag.pbCanStore?(pkmn.item)
|
||||
elsif !$bag.can_add?(pkmn.item)
|
||||
scene.pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed."))
|
||||
elsif pkmn.mail
|
||||
if scene.pbConfirm(_INTL("Save the removed mail in your PC?"))
|
||||
@@ -770,14 +770,14 @@ def pbTakeItemFromPokemon(pkmn,scene)
|
||||
ret = true
|
||||
end
|
||||
elsif scene.pbConfirm(_INTL("If the mail is removed, its message will be lost. OK?"))
|
||||
$PokemonBag.pbStoreItem(pkmn.item)
|
||||
$bag.add(pkmn.item)
|
||||
scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name))
|
||||
pkmn.item = nil
|
||||
pkmn.mail = nil
|
||||
ret = true
|
||||
end
|
||||
else
|
||||
$PokemonBag.pbStoreItem(pkmn.item)
|
||||
$bag.add(pkmn.item)
|
||||
scene.pbDisplay(_INTL("Received the {1} from {2}.",pkmn.item.name,pkmn.name))
|
||||
pkmn.item = nil
|
||||
ret = true
|
||||
@@ -792,7 +792,7 @@ def pbChooseItem(var = 0, *args)
|
||||
ret = nil
|
||||
pbFadeOutIn {
|
||||
scene = PokemonBag_Scene.new
|
||||
screen = PokemonBagScreen.new(scene,$PokemonBag)
|
||||
screen = PokemonBagScreen.new(scene, $bag)
|
||||
ret = screen.pbChooseItemScreen
|
||||
}
|
||||
$game_variables[var] = ret || :NONE if var > 0
|
||||
@@ -803,7 +803,7 @@ def pbChooseApricorn(var = 0)
|
||||
ret = nil
|
||||
pbFadeOutIn {
|
||||
scene = PokemonBag_Scene.new
|
||||
screen = PokemonBagScreen.new(scene,$PokemonBag)
|
||||
screen = PokemonBagScreen.new(scene, $bag)
|
||||
ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_apricorn? })
|
||||
}
|
||||
$game_variables[var] = ret || :NONE if var > 0
|
||||
@@ -814,7 +814,7 @@ def pbChooseFossil(var = 0)
|
||||
ret = nil
|
||||
pbFadeOutIn {
|
||||
scene = PokemonBag_Scene.new
|
||||
screen = PokemonBagScreen.new(scene,$PokemonBag)
|
||||
screen = PokemonBagScreen.new(scene, $bag)
|
||||
ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_fossil? })
|
||||
}
|
||||
$game_variables[var] = ret || :NONE if var > 0
|
||||
@@ -829,7 +829,7 @@ def pbChooseItemFromList(message, variable, *args)
|
||||
for item in args
|
||||
next if !GameData::Item.exists?(item)
|
||||
itm = GameData::Item.get(item)
|
||||
next if !$PokemonBag.pbHasItem?(itm)
|
||||
next if !$bag.has?(itm)
|
||||
commands.push(itm.name)
|
||||
itemid.push(itm.id)
|
||||
end
|
||||
|
||||
@@ -109,19 +109,17 @@ Events.onStepTaken += proc {
|
||||
if $PokemonGlobal.repel > 0 && !$game_player.terrain_tag.ice # Shouldn't count down if on ice
|
||||
$PokemonGlobal.repel -= 1
|
||||
if $PokemonGlobal.repel <= 0
|
||||
if $PokemonBag.pbHasItem?(:REPEL) ||
|
||||
$PokemonBag.pbHasItem?(:SUPERREPEL) ||
|
||||
$PokemonBag.pbHasItem?(:MAXREPEL)
|
||||
if $bag.has?(:REPEL) || $bag.has?(:SUPERREPEL) || $bag.has?(:MAXREPEL)
|
||||
if pbConfirmMessage(_INTL("The repellent's effect wore off! Would you like to use another one?"))
|
||||
ret = nil
|
||||
pbFadeOutIn {
|
||||
scene = PokemonBag_Scene.new
|
||||
screen = PokemonBagScreen.new(scene,$PokemonBag)
|
||||
screen = PokemonBagScreen.new(scene, $bag)
|
||||
ret = screen.pbChooseItemScreen(Proc.new { |item|
|
||||
[:REPEL, :SUPERREPEL, :MAXREPEL].include?(item)
|
||||
})
|
||||
}
|
||||
pbUseItem($PokemonBag,ret) if ret
|
||||
pbUseItem($bag, ret) if ret
|
||||
end
|
||||
else
|
||||
pbMessage(_INTL("The repellent's effect wore off!"))
|
||||
@@ -314,13 +312,13 @@ ItemHandlers::UseInField.add(:COINCASE,proc { |item|
|
||||
})
|
||||
|
||||
ItemHandlers::UseInField.add(:EXPALL,proc { |item|
|
||||
$PokemonBag.pbChangeItem(:EXPALL,:EXPALLOFF)
|
||||
$bag.replace_item(:EXPALL, :EXPALLOFF)
|
||||
pbMessage(_INTL("The Exp Share was turned off."))
|
||||
next true
|
||||
})
|
||||
|
||||
ItemHandlers::UseInField.add(:EXPALLOFF,proc { |item|
|
||||
$PokemonBag.pbChangeItem(:EXPALLOFF,:EXPALL)
|
||||
$bag.replace_item(:EXPALLOFF, :EXPALL)
|
||||
pbMessage(_INTL("The Exp Share was turned on."))
|
||||
next true
|
||||
})
|
||||
@@ -896,13 +894,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYXS, proc { |item, pkmn, scene|
|
||||
end
|
||||
gain_amount = 100
|
||||
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil
|
||||
maximum = [maximum, $PokemonBag.pbQuantity(item)].min
|
||||
maximum = [maximum, $bag.quantity(item)].min
|
||||
qty = scene.scene.pbChooseNumber(
|
||||
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
|
||||
next false if qty == 0
|
||||
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
|
||||
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
|
||||
$PokemonBag.pbDeleteItem(item, qty - 1)
|
||||
$bag.remove(item, qty - 1)
|
||||
scene.pbHardRefresh
|
||||
next true
|
||||
})
|
||||
@@ -914,13 +912,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYS, proc { |item, pkmn, scene|
|
||||
end
|
||||
gain_amount = 800
|
||||
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil
|
||||
maximum = [maximum, $PokemonBag.pbQuantity(item)].min
|
||||
maximum = [maximum, $bag.quantity(item)].min
|
||||
qty = scene.scene.pbChooseNumber(
|
||||
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
|
||||
next false if qty == 0
|
||||
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
|
||||
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
|
||||
$PokemonBag.pbDeleteItem(item, qty - 1)
|
||||
$bag.remove(item, qty - 1)
|
||||
scene.pbHardRefresh
|
||||
next true
|
||||
})
|
||||
@@ -932,13 +930,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYM, proc { |item, pkmn, scene|
|
||||
end
|
||||
gain_amount = 3_000
|
||||
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil
|
||||
maximum = [maximum, $PokemonBag.pbQuantity(item)].min
|
||||
maximum = [maximum, $bag.quantity(item)].min
|
||||
qty = scene.scene.pbChooseNumber(
|
||||
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
|
||||
next false if qty == 0
|
||||
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
|
||||
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
|
||||
$PokemonBag.pbDeleteItem(item, qty - 1)
|
||||
$bag.remove(item, qty - 1)
|
||||
scene.pbHardRefresh
|
||||
next true
|
||||
})
|
||||
@@ -950,13 +948,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYL, proc { |item, pkmn, scene|
|
||||
end
|
||||
gain_amount = 10_000
|
||||
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil
|
||||
maximum = [maximum, $PokemonBag.pbQuantity(item)].min
|
||||
maximum = [maximum, $bag.quantity(item)].min
|
||||
qty = scene.scene.pbChooseNumber(
|
||||
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
|
||||
next false if qty == 0
|
||||
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
|
||||
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
|
||||
$PokemonBag.pbDeleteItem(item, qty - 1)
|
||||
$bag.remove(item, qty - 1)
|
||||
scene.pbHardRefresh
|
||||
next true
|
||||
})
|
||||
@@ -968,13 +966,13 @@ ItemHandlers::UseOnPokemon.add(:EXPCANDYXL, proc { |item, pkmn, scene|
|
||||
end
|
||||
gain_amount = 30_000
|
||||
maximum = ((pkmn.growth_rate.maximum_exp - pkmn.exp) / gain_amount.to_f).ceil
|
||||
maximum = [maximum, $PokemonBag.pbQuantity(item)].min
|
||||
maximum = [maximum, $bag.quantity(item)].min
|
||||
qty = scene.scene.pbChooseNumber(
|
||||
_INTL("How many {1} do you want to use?", GameData::Item.get(item).name), maximum)
|
||||
next false if qty == 0
|
||||
scene.scene.pbSetHelpText("") if scene.is_a?(PokemonPartyScreen)
|
||||
pbChangeExp(pkmn, pkmn.exp + gain_amount * qty, scene)
|
||||
$PokemonBag.pbDeleteItem(item, qty - 1)
|
||||
$bag.remove(item, qty - 1)
|
||||
scene.pbHardRefresh
|
||||
next true
|
||||
})
|
||||
@@ -1275,7 +1273,7 @@ ItemHandlers::UseOnPokemon.add(:DNASPLICERS,proc { |item,pkmn,scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:DNASPLICERS, :DNASPLICERSUSED)
|
||||
$bag.replace_item(:DNASPLICERS, :DNASPLICERSUSED)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1297,7 +1295,7 @@ ItemHandlers::UseOnPokemon.add(:DNASPLICERSUSED,proc { |item,pkmn,scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:DNASPLICERSUSED, :DNASPLICERS)
|
||||
$bag.replace_item(:DNASPLICERSUSED, :DNASPLICERS)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1332,7 +1330,7 @@ ItemHandlers::UseOnPokemon.add(:NSOLARIZER,proc { |item,pkmn,scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:NSOLARIZER, :NSOLARIZERUSED)
|
||||
$bag.replace_item(:NSOLARIZER, :NSOLARIZERUSED)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1354,7 +1352,7 @@ ItemHandlers::UseOnPokemon.add(:NSOLARIZERUSED,proc { |item,pkmn,scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:NSOLARIZERUSED, :NSOLARIZER)
|
||||
$bag.replace_item(:NSOLARIZERUSED, :NSOLARIZER)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1389,7 +1387,7 @@ ItemHandlers::UseOnPokemon.add(:NLUNARIZER,proc { |item,pkmn,scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:NLUNARIZER, :NLUNARIZERUSED)
|
||||
$bag.replace_item(:NLUNARIZER, :NLUNARIZERUSED)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1411,7 +1409,7 @@ ItemHandlers::UseOnPokemon.add(:NLUNARIZERUSED,proc { |item,pkmn,scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:NLUNARIZERUSED, :NLUNARIZER)
|
||||
$bag.replace_item(:NLUNARIZERUSED, :NLUNARIZER)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1450,7 +1448,7 @@ ItemHandlers::UseOnPokemon.add(:REINSOFUNITY, proc { |item, pkmn, scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:REINSOFUNITY, :REINSOFUNITYUSED)
|
||||
$bag.replace_item(:REINSOFUNITY, :REINSOFUNITYUSED)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1472,6 +1470,6 @@ ItemHandlers::UseOnPokemon.add(:REINSOFUNITYUSED, proc { |item, pkmn, scene|
|
||||
scene.pbHardRefresh
|
||||
scene.pbDisplay(_INTL("{1} changed Forme!", pkmn.name))
|
||||
}
|
||||
$PokemonBag.pbChangeItem(:REINSOFUNITYUSED, :REINSOFUNITY)
|
||||
$bag.replace_item(:REINSOFUNITYUSED, :REINSOFUNITY)
|
||||
next true
|
||||
})
|
||||
|
||||
@@ -1,57 +1,35 @@
|
||||
#===============================================================================
|
||||
# The Bag object, which actually contains all the items
|
||||
# The Bag object, which actually contains all the items.
|
||||
#===============================================================================
|
||||
class PokemonBag
|
||||
attr_accessor :lastpocket
|
||||
attr_accessor :last_viewed_pocket
|
||||
attr_accessor :last_pocket_selections
|
||||
attr_reader :registered_items
|
||||
attr_reader :ready_menu_selection
|
||||
|
||||
def self.pocketNames
|
||||
def self.pocket_names
|
||||
return Settings.bag_pocket_names
|
||||
end
|
||||
|
||||
def self.numPockets
|
||||
return self.pocketNames.length-1
|
||||
def self.pocket_count
|
||||
return self.pocket_names.length - 1
|
||||
end
|
||||
|
||||
def initialize
|
||||
@lastpocket = 1
|
||||
@pockets = []
|
||||
@choices = []
|
||||
for i in 0..PokemonBag.numPockets
|
||||
@last_viewed_pocket = 1
|
||||
@pockets = []
|
||||
@last_pocket_selections = []
|
||||
for i in 0..PokemonBag.pocket_count
|
||||
@pockets[i] = []
|
||||
@choices[i] = 0
|
||||
@last_pocket_selections[i] = 0
|
||||
end
|
||||
@registeredItems = []
|
||||
@registeredIndex = [0, 0, 1] # Used by the Ready Menu to remember cursor positions
|
||||
end
|
||||
|
||||
def rearrange
|
||||
return if @pockets.length == PokemonBag.numPockets + 1
|
||||
@lastpocket = 1
|
||||
new_pockets = []
|
||||
@choices = []
|
||||
for i in 0..PokemonBag.numPockets
|
||||
new_pockets[i] = []
|
||||
@choices[i] = 0
|
||||
end
|
||||
@pockets.each do |pocket|
|
||||
next if !pocket
|
||||
pocket.each do |item|
|
||||
p = GameData::Item.get(item[0]).pocket
|
||||
new_pockets[p].push(item)
|
||||
end
|
||||
end
|
||||
new_pockets.each_with_index do |pocket, i|
|
||||
next if i == 0 || !Settings::BAG_POCKET_AUTO_SORT[i]
|
||||
pocket.sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) }
|
||||
end
|
||||
@pockets = new_pockets
|
||||
@registered_items = []
|
||||
@ready_menu_selection = [0, 0, 1] # Used by the Ready Menu to remember cursor positions
|
||||
end
|
||||
|
||||
def clear
|
||||
@pockets.each { |pocket| pocket.clear }
|
||||
for i in 0..PokemonBag.numPockets
|
||||
@choices[i] = 0
|
||||
end
|
||||
(PokemonBag.pocket_count + 1).times { |i| @last_pocket_selections[i] = 0 }
|
||||
end
|
||||
|
||||
def pockets
|
||||
@@ -59,131 +37,156 @@ class PokemonBag
|
||||
return @pockets
|
||||
end
|
||||
|
||||
def maxPocketSize(pocket)
|
||||
maxsize = Settings::BAG_MAX_POCKET_SIZE[pocket]
|
||||
return -1 if !maxsize
|
||||
return maxsize
|
||||
end
|
||||
#=============================================================================
|
||||
|
||||
# Gets the index of the current selected item in the pocket
|
||||
def getChoice(pocket)
|
||||
if pocket <= 0 || pocket > PokemonBag.numPockets
|
||||
def last_viewed_index(pocket)
|
||||
if pocket <= 0 || pocket > PokemonBag.pocket_count
|
||||
raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect))
|
||||
end
|
||||
rearrange
|
||||
return [@choices[pocket], @pockets[pocket].length].min || 0
|
||||
return [@last_pocket_selections[pocket], @pockets[pocket].length].min || 0
|
||||
end
|
||||
|
||||
# Sets the index of the current selected item in the pocket
|
||||
def setChoice(pocket,value)
|
||||
if pocket <= 0 || pocket > PokemonBag.numPockets
|
||||
def set_last_viewed_index(pocket, value)
|
||||
if pocket <= 0 || pocket > PokemonBag.pocket_count
|
||||
raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect))
|
||||
end
|
||||
rearrange
|
||||
@choices[pocket] = value if value <= @pockets[pocket].length
|
||||
@last_pocket_selections[pocket] = value if value <= @pockets[pocket].length
|
||||
end
|
||||
|
||||
def getAllChoices
|
||||
ret = @choices.clone
|
||||
for i in 0...@choices.length
|
||||
@choices[i] = 0
|
||||
#=============================================================================
|
||||
|
||||
def quantity(item)
|
||||
item_data = GameData::Item.try_get(item)
|
||||
return 0 if !item_data
|
||||
pocket = item_data.pocket
|
||||
return ItemStorageHelper.quantity(@pockets[pocket], item_data.id)
|
||||
end
|
||||
|
||||
def has?(item, qty = 1)
|
||||
return quantity(item) >= qty
|
||||
end
|
||||
alias can_remove? has?
|
||||
|
||||
def can_add?(item, qty = 1)
|
||||
item_data = GameData::Item.try_get(item)
|
||||
return false if !item_data
|
||||
pocket = item_data.pocket
|
||||
max_size = max_pocket_size(pocket)
|
||||
max_size = @pockets[pocket].length + 1 if max_size < 0 # Infinite size
|
||||
return ItemStorageHelper.can_add?(
|
||||
@pockets[pocket], max_size, Settings::BAG_MAX_PER_SLOT, item_data.id, qty)
|
||||
end
|
||||
|
||||
def add(item, qty = 1)
|
||||
item_data = GameData::Item.try_get(item)
|
||||
return false if !item_data
|
||||
pocket = item_data.pocket
|
||||
max_size = max_pocket_size(pocket)
|
||||
max_size = @pockets[pocket].length + 1 if max_size < 0 # Infinite size
|
||||
ret = ItemStorageHelper.add(@pockets[pocket],
|
||||
max_size, Settings::BAG_MAX_PER_SLOT, item_data.id, qty)
|
||||
if ret && Settings::BAG_POCKET_AUTO_SORT[pocket]
|
||||
@pockets[pocket].sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) }
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def setAllChoices(choices)
|
||||
@choices = choices
|
||||
# Adds qty number of item. Doesn't add anything if it can't add all of them.
|
||||
def add_all(item, qty = 1)
|
||||
return false if !can_add?(item, qty)
|
||||
return add(item, qty)
|
||||
end
|
||||
|
||||
def pbQuantity(item)
|
||||
item = GameData::Item.get(item)
|
||||
# Deletes as many of item as possible (up to qty), and returns whether it
|
||||
# managed to delete qty of them.
|
||||
def remove(item, qty = 1)
|
||||
item_data = GameData::Item.try_get(item)
|
||||
return false if !item_data
|
||||
pocket = item.pocket
|
||||
return ItemStorageHelper.pbQuantity(@pockets[pocket], item.id)
|
||||
return ItemStorageHelper.remove(@pockets[pocket], item.id, qty)
|
||||
end
|
||||
|
||||
def pbHasItem?(item)
|
||||
return pbQuantity(item) > 0
|
||||
# Deletes qty number of item. Doesn't delete anything if there are less than
|
||||
# qty of the item in the Bag.
|
||||
def remove_all(item, qty = 1)
|
||||
return false if !can_remove?(item, qty)
|
||||
return remove(item, qty)
|
||||
end
|
||||
|
||||
def pbCanStore?(item, qty = 1)
|
||||
item = GameData::Item.get(item)
|
||||
pocket = item.pocket
|
||||
maxsize = maxPocketSize(pocket)
|
||||
maxsize = @pockets[pocket].length + 1 if maxsize < 0
|
||||
return ItemStorageHelper.pbCanStore?(
|
||||
@pockets[pocket], maxsize, Settings::BAG_MAX_PER_SLOT, item.id, qty)
|
||||
end
|
||||
|
||||
def pbStoreItem(item, qty = 1)
|
||||
item = GameData::Item.get(item)
|
||||
pocket = item.pocket
|
||||
maxsize = maxPocketSize(pocket)
|
||||
maxsize = @pockets[pocket].length + 1 if maxsize < 0
|
||||
return ItemStorageHelper.pbStoreItem(
|
||||
@pockets[pocket], maxsize, Settings::BAG_MAX_PER_SLOT, item.id, qty, true)
|
||||
end
|
||||
|
||||
def pbStoreAllOrNone(item, qty = 1)
|
||||
return false if !pbCanStore?(item, qty)
|
||||
return pbStoreItem(item, qty)
|
||||
end
|
||||
|
||||
def pbChangeItem(old_item, new_item)
|
||||
old_item = GameData::Item.get(old_item)
|
||||
new_item = GameData::Item.get(new_item)
|
||||
pocket = old_item.pocket
|
||||
# This only works if the old and new items are in the same pocket. Used for
|
||||
# switching on/off certain Key Items. Replaces all old_item in its pocket with
|
||||
# new_item.
|
||||
def replace_item(old_item, new_item)
|
||||
old_item_data = GameData::Item.try_get(old_item)
|
||||
new_item_data = GameData::Item.try_get(new_item)
|
||||
return false if !old_item_data || !new_item_data
|
||||
pocket = old_item_data.pocket
|
||||
old_id = old_item_data.id
|
||||
new_id = new_item_data.id
|
||||
ret = false
|
||||
@pockets[pocket].each do |item|
|
||||
next if !item || item[0] != old_item.id
|
||||
item[0] = new_item.id
|
||||
next if !item || item[0] != old_id
|
||||
item[0] = new_id
|
||||
ret = true
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pbChangeQuantity(pocket, index, newqty = 1)
|
||||
return false if pocket <= 0 || pocket > self.numPockets
|
||||
return false if !@pockets[pocket][index]
|
||||
newqty = [newqty, maxPocketSize(pocket)].min
|
||||
@pockets[pocket][index][1] = newqty
|
||||
return true
|
||||
end
|
||||
#=============================================================================
|
||||
|
||||
def pbDeleteItem(item, qty = 1)
|
||||
item = GameData::Item.get(item)
|
||||
pocket = item.pocket
|
||||
ret = ItemStorageHelper.pbDeleteItem(@pockets[pocket], item.id, qty)
|
||||
return ret
|
||||
end
|
||||
|
||||
def registeredItems
|
||||
@registeredItems = [] if !@registeredItems
|
||||
return @registeredItems
|
||||
end
|
||||
|
||||
def pbIsRegistered?(item)
|
||||
item = GameData::Item.get(item).id
|
||||
registeredlist = self.registeredItems
|
||||
return registeredlist.include?(item)
|
||||
# Returns whether item has been registered for quick access in the Ready Menu.
|
||||
def registered?(item)
|
||||
item_data = GameData::Item.try_get(item)
|
||||
return false if !item_data
|
||||
return @registered_items.include?(item_data.id)
|
||||
end
|
||||
|
||||
# Registers the item in the Ready Menu.
|
||||
def pbRegisterItem(item)
|
||||
item = GameData::Item.get(item).id
|
||||
registeredlist = self.registeredItems
|
||||
registeredlist.push(item) if !registeredlist.include?(item)
|
||||
def register(item)
|
||||
item_data = GameData::Item.try_get(item)
|
||||
return if !item_data
|
||||
@registered_items.push(item_data.id) if !@registered_items.include?(item_data.id)
|
||||
end
|
||||
|
||||
# Unregisters the item from the Ready Menu.
|
||||
def pbUnregisterItem(item)
|
||||
item = GameData::Item.get(item).id
|
||||
registeredlist = self.registeredItems
|
||||
registeredlist.delete_at(registeredlist.index(item))
|
||||
def unregister(item)
|
||||
item_data = GameData::Item.try_get(item)
|
||||
@registered_items.delete(item_data.id) if item_data
|
||||
end
|
||||
|
||||
def registeredIndex
|
||||
@registeredIndex = [0, 0, 1] if !@registeredIndex
|
||||
return @registeredIndex
|
||||
#=============================================================================
|
||||
|
||||
private
|
||||
|
||||
def max_pocket_size(pocket)
|
||||
return Settings::BAG_MAX_POCKET_SIZE[pocket] || -1
|
||||
end
|
||||
|
||||
def rearrange
|
||||
return if @pockets.length == PokemonBag.pocket_count + 1
|
||||
@last_viewed_pocket = 1
|
||||
new_pockets = []
|
||||
@last_pocket_selections = []
|
||||
(PokemonBag.pocket_count + 1).times do |i|
|
||||
new_pockets[i] = []
|
||||
@last_pocket_selections[i] = 0
|
||||
end
|
||||
@pockets.each do |pocket|
|
||||
next if !pocket
|
||||
pocket.each do |item|
|
||||
item_pocket = GameData::Item.get(item[0]).pocket
|
||||
new_pockets[item_pocket].push(item)
|
||||
end
|
||||
end
|
||||
new_pockets.each_with_index do |pocket, i|
|
||||
next if i == 0 || !Settings::BAG_POCKET_AUTO_SORT[i]
|
||||
pocket.sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) }
|
||||
end
|
||||
@pockets = new_pockets
|
||||
end
|
||||
end
|
||||
|
||||
@@ -201,7 +204,7 @@ class PCItemStorage
|
||||
def initialize
|
||||
@items = []
|
||||
# Start storage with a Potion
|
||||
pbStoreItem(:POTION) if GameData::Item.exists?(:POTION)
|
||||
add(:POTION) if GameData::Item.exists?(:POTION)
|
||||
end
|
||||
|
||||
def [](i)
|
||||
@@ -220,32 +223,35 @@ class PCItemStorage
|
||||
@items.clear
|
||||
end
|
||||
|
||||
def getItem(index)
|
||||
# Unused
|
||||
def get_item(index)
|
||||
return (index < 0 || index >= @items.length) ? nil : @items[index][0]
|
||||
end
|
||||
|
||||
def getCount(index)
|
||||
# Number of the item in the given index
|
||||
# Unused
|
||||
def get_item_count(index)
|
||||
return (index < 0 || index >= @items.length) ? 0 : @items[index][1]
|
||||
end
|
||||
|
||||
def pbQuantity(item)
|
||||
def quantity(item)
|
||||
item = GameData::Item.get(item).id
|
||||
return ItemStorageHelper.pbQuantity(@items, item)
|
||||
return ItemStorageHelper.quantity(@items, item)
|
||||
end
|
||||
|
||||
def pbCanStore?(item, qty = 1)
|
||||
def can_add?(item, qty = 1)
|
||||
item = GameData::Item.get(item).id
|
||||
return ItemStorageHelper.pbCanStore?(@items, MAX_SIZE, MAX_PER_SLOT, item, qty)
|
||||
return ItemStorageHelper.can_add?(@items, MAX_SIZE, MAX_PER_SLOT, item, qty)
|
||||
end
|
||||
|
||||
def pbStoreItem(item, qty = 1)
|
||||
def add(item, qty = 1)
|
||||
item = GameData::Item.get(item).id
|
||||
return ItemStorageHelper.pbStoreItem(@items, MAX_SIZE, MAX_PER_SLOT, item, qty)
|
||||
return ItemStorageHelper.add(@items, MAX_SIZE, MAX_PER_SLOT, item, qty)
|
||||
end
|
||||
|
||||
def pbDeleteItem(item, qty = 1)
|
||||
def remove(item, qty = 1)
|
||||
item = GameData::Item.get(item).id
|
||||
return ItemStorageHelper.pbDeleteItem(@items, item, qty)
|
||||
return ItemStorageHelper.remove(@items, item, qty)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -257,25 +263,62 @@ end
|
||||
# Used by the Bag, PC item storage, and Triple Triad.
|
||||
#===============================================================================
|
||||
module ItemStorageHelper
|
||||
# Returns the quantity of check_item in item_array
|
||||
def self.pbQuantity(item_array, check_item)
|
||||
# Returns the quantity of item in items
|
||||
def self.quantity(items, item)
|
||||
ret = 0
|
||||
item_array.each { |i| ret += i[1] if i && i[0] == check_item }
|
||||
items.each { |i| ret += i[1] if i && i[0] == item }
|
||||
return ret
|
||||
end
|
||||
|
||||
def self.can_add?(items, max_slots, max_per_slot, item, qty)
|
||||
raise "Invalid value for qty: #{qty}" if qty < 0
|
||||
return true if qty == 0
|
||||
max_slots.times do |i|
|
||||
item_slot = items[i]
|
||||
if !item_slot
|
||||
qty -= [qty, max_per_slot].min
|
||||
return true if qty == 0
|
||||
elsif item_slot[0] == item && item_slot[1] < max_per_slot
|
||||
new_amt = item_slot[1]
|
||||
new_amt = [new_amt + qty, max_per_slot].min
|
||||
qty -= (new_amt - item_slot[1])
|
||||
return true if qty == 0
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def self.add(items, max_slots, max_per_slot, item, qty)
|
||||
raise "Invalid value for qty: #{qty}" if qty < 0
|
||||
return true if qty == 0
|
||||
max_slots.times do |i|
|
||||
item_slot = items[i]
|
||||
if !item_slot
|
||||
items[i] = [item, [qty, max_per_slot].min]
|
||||
qty -= items[i][1]
|
||||
return true if qty == 0
|
||||
elsif item_slot[0] == item && item_slot[1] < max_per_slot
|
||||
new_amt = item_slot[1]
|
||||
new_amt = [new_amt + qty, max_per_slot].min
|
||||
qty -= (new_amt - item_slot[1])
|
||||
item_slot[1] = new_amt
|
||||
return true if qty == 0
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
# Deletes an item (items array, max. size per slot, item, no. of items to delete)
|
||||
def self.pbDeleteItem(items, item, qty)
|
||||
def self.remove(items, item, qty)
|
||||
raise "Invalid value for qty: #{qty}" if qty < 0
|
||||
return true if qty == 0
|
||||
ret = false
|
||||
for i in 0...items.length
|
||||
itemslot = items[i]
|
||||
next if !itemslot || itemslot[0] != item
|
||||
amount = [qty, itemslot[1]].min
|
||||
itemslot[1] -= amount
|
||||
items.each_with_index do |item_slot, i|
|
||||
next if !item_slot || item_slot[0] != item
|
||||
amount = [qty, item_slot[1]].min
|
||||
item_slot[1] -= amount
|
||||
qty -= amount
|
||||
items[i] = nil if itemslot[1] == 0
|
||||
items[i] = nil if item_slot[1] == 0
|
||||
next if qty > 0
|
||||
ret = true
|
||||
break
|
||||
@@ -283,72 +326,86 @@ module ItemStorageHelper
|
||||
items.compact!
|
||||
return ret
|
||||
end
|
||||
|
||||
def self.pbCanStore?(items, maxsize, maxPerSlot, item, qty)
|
||||
raise "Invalid value for qty: #{qty}" if qty < 0
|
||||
return true if qty == 0
|
||||
for i in 0...maxsize
|
||||
itemslot = items[i]
|
||||
if !itemslot
|
||||
qty -= [qty, maxPerSlot].min
|
||||
return true if qty == 0
|
||||
elsif itemslot[0] == item && itemslot[1] < maxPerSlot
|
||||
newamt = itemslot[1]
|
||||
newamt = [newamt + qty, maxPerSlot].min
|
||||
qty -= (newamt - itemslot[1])
|
||||
return true if qty == 0
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def self.pbStoreItem(items, maxsize, maxPerSlot, item, qty, sorting = false)
|
||||
raise "Invalid value for qty: #{qty}" if qty < 0
|
||||
return true if qty == 0
|
||||
itm = GameData::Item.try_get(item)
|
||||
itemPocket = (itm) ? itm.pocket : 0
|
||||
for i in 0...maxsize
|
||||
itemslot = items[i]
|
||||
if !itemslot
|
||||
items[i] = [item, [qty, maxPerSlot].min]
|
||||
qty -= items[i][1]
|
||||
if itemPocket > 0 && sorting && Settings::BAG_POCKET_AUTO_SORT[itemPocket]
|
||||
items.sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) }
|
||||
end
|
||||
return true if qty == 0
|
||||
elsif itemslot[0] == item && itemslot[1] < maxPerSlot
|
||||
newamt = itemslot[1]
|
||||
newamt = [newamt + qty, maxPerSlot].min
|
||||
qty -= (newamt - itemslot[1])
|
||||
itemslot[1] = newamt
|
||||
return true if qty == 0
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Shortcut methods
|
||||
# Deprecated methods
|
||||
#===============================================================================
|
||||
def pbQuantity(*args)
|
||||
return $PokemonBag.pbQuantity(*args)
|
||||
class PokemonBag
|
||||
def pbQuantity(item)
|
||||
Deprecation.warn_method('pbQuantity', 'v21', '$bag.quantity(item)')
|
||||
return quantity(item)
|
||||
end
|
||||
|
||||
def pbHasItem?(item)
|
||||
Deprecation.warn_method('pbHasItem?', 'v21', '$bag.has?(item)')
|
||||
return has?(item)
|
||||
end
|
||||
|
||||
def pbCanStore?(item, quantity = 1)
|
||||
Deprecation.warn_method('pbCanStore?', 'v21', '$bag.can_add?(item, quantity)')
|
||||
return can_add?(item, quantity)
|
||||
end
|
||||
|
||||
def pbStoreItem(item, quantity = 1)
|
||||
Deprecation.warn_method('pbStoreItem', 'v21', '$bag.add(item, quantity)')
|
||||
return add(item, quantity)
|
||||
end
|
||||
|
||||
def pbStoreAllOrNone(item, quantity = 1)
|
||||
Deprecation.warn_method('pbStoreAllOrNone', 'v21', '$bag.add_all(item, quantity)')
|
||||
return add_all(item, quantity)
|
||||
end
|
||||
|
||||
def pbChangeItem(old_item, new_item)
|
||||
Deprecation.warn_method('pbChangeItem', 'v21', '$bag.replace_item(old_item, new_item)')
|
||||
return replace_item(old_item, new_item)
|
||||
end
|
||||
|
||||
def pbDeleteItem(item, quantity = 1)
|
||||
Deprecation.warn_method('pbDeleteItem', 'v21', '$bag.remove(item, quantity)')
|
||||
return remove(item, quantity)
|
||||
end
|
||||
|
||||
def pbIsRegistered?(item)
|
||||
Deprecation.warn_method('pbIsRegistered?', 'v21', '$bag.registered?(item)')
|
||||
return registered?(item)
|
||||
end
|
||||
|
||||
def pbRegisterItem(item)
|
||||
Deprecation.warn_method('pbRegisterItem', 'v21', '$bag.register(item)')
|
||||
register(item)
|
||||
end
|
||||
|
||||
def pbUnregisterItem(item)
|
||||
Deprecation.warn_method('pbUnregisterItem', 'v21', '$bag.unregister(item)')
|
||||
unregister(item)
|
||||
end
|
||||
end
|
||||
|
||||
def pbHasItem?(*args)
|
||||
return $PokemonBag.pbHasItem?(*args)
|
||||
def pbQuantity(item)
|
||||
Deprecation.warn_method('pbQuantity', 'v21', '$bag.quantity(item)')
|
||||
return $bag.quantity(item)
|
||||
end
|
||||
|
||||
def pbCanStore?(*args)
|
||||
return $PokemonBag.pbCanStore?(*args)
|
||||
def pbHasItem?(item)
|
||||
Deprecation.warn_method('pbHasItem?', 'v21', '$bag.has?(item)')
|
||||
return $bag.has?(item)
|
||||
end
|
||||
|
||||
def pbStoreItem(*args)
|
||||
return $PokemonBag.pbStoreItem(*args)
|
||||
def pbCanStore?(item, quantity = 1)
|
||||
Deprecation.warn_method('pbCanStore?', 'v21', '$bag.can_add?(item, quantity)')
|
||||
return $bag.can_add?(item, quantity)
|
||||
end
|
||||
|
||||
def pbStoreAllOrNone(*args)
|
||||
return $PokemonBag.pbStoreAllOrNone(*args)
|
||||
def pbStoreItem(item, quantity = 1)
|
||||
Deprecation.warn_method('pbStoreItem', 'v21', '$bag.add(item, quantity)')
|
||||
return $bag.add(item, quantity)
|
||||
end
|
||||
|
||||
def pbStoreAllOrNone(item, quantity = 1)
|
||||
Deprecation.warn_method('pbStoreAllOrNone', 'v21', '$bag.add_all(item, quantity)')
|
||||
return $bag.add_all(item, quantity)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user