Implemented GameData BagPocket

This commit is contained in:
Maruno17
2024-09-14 01:27:17 +01:00
parent d8263da05e
commit 801c2d35c6
15 changed files with 268 additions and 95 deletions

View File

@@ -259,31 +259,6 @@ module Settings
# this number.
ITEM_SELL_PRICE_DIVISOR = (MECHANICS_GENERATION >= 9) ? 4 : 2
#-----------------------------------------------------------------------------
# Bag
#-----------------------------------------------------------------------------
# The names of each pocket of the Bag.
def self.bag_pocket_names
return [
_INTL("Items"),
_INTL("Medicine"),
_INTL("Poké Balls"),
_INTL("TMs & HMs"),
_INTL("Berries"),
_INTL("Mail"),
_INTL("Battle Items"),
_INTL("Key Items")
]
end
# The maximum number of slots per pocket (-1 means infinite number).
BAG_MAX_POCKET_SIZE = [-1, -1, -1, -1, -1, -1, -1, -1]
# Whether each pocket in turn auto-sorts itself by the order items are defined
# in the PBS file items.txt.
BAG_POCKET_AUTO_SORT = [false, false, false, true, true, false, false, false]
# The maximum number of items each slot in the Bag can hold.
BAG_MAX_PER_SLOT = 999
#-----------------------------------------------------------------------------
# Pokédex
#-----------------------------------------------------------------------------

View File

@@ -81,3 +81,34 @@ SaveData.register_conversion(:v22_add_primal_reversion_stat) do
end
end
end
#===============================================================================
SaveData.register_conversion(:v22_convert_bag_object) do
essentials_version 22
display_title "Converting Bag's pockets"
to_value :bag do |bag|
bag.instance_eval do
all_pockets = GameData::BagPocket.all_pockets
if @last_viewed_pocket.is_a?(Integer)
@last_viewed_pocket = all_pockets[@last_viewed_pocket - 1]
end
if @last_pocket_selections.is_a?(Array)
new_sels = {}
@last_pocket_selections.each_with_index do |value, i|
next if i == 0
new_sels[all_pockets[i - 1]] = value
end
@last_pocket_selections = new_sels
end
if @pockets.is_a?(Array)
new_pockets = {}
@pockets.each_with_index do |value, i|
next if i == 0
new_pockets[all_pockets[i - 1]] = value
end
@pockets = new_pockets
end
end
end
end

View File

@@ -0,0 +1,133 @@
#===============================================================================
#
#===============================================================================
module GameData
class BagPocket
attr_reader :id
attr_reader :real_name
attr_reader :icon_position # Where this pocket's icon is within icon_pocket.png
attr_reader :order
attr_reader :max_slots
attr_reader :auto_sort
DATA = {}
extend ClassMethodsSymbols
include InstanceMethods
def self.load; end
def self.save; end
def self.all_pockets
ret = []
DATA.each_value { |pocket| ret.push([pocket.id, pocket.order]) }
ret.sort_by! { |pckt| pckt[1] }
ret.map! { |pckt| pckt[0] }
return ret
end
def self.index(pocket)
return self.all_pockets.index(pocket)
end
# @param other [Symbol, self, String]
# @return [self]
def self.get(other)
validate other => [Symbol, self, String, Integer]
return other if other.is_a?(self)
other = self.all_pockets[other - 1] if other.is_a?(Integer)
other = other.to_sym if other.is_a?(String)
raise "Unknown ID #{other}." unless self::DATA.has_key?(other)
return self::DATA[other]
end
# @param other [Symbol, self, String]
# @return [self, nil]
def try_get(other)
return nil if other.nil?
validate other => [Symbol, self, String, Integer]
return other if other.is_a?(self)
other = self.all_pockets[other - 1] if other.is_a?(Integer)
other = other.to_sym if other.is_a?(String)
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
end
#---------------------------------------------------------------------------
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@icon_position = hash[:icon_position] || 0
@order = hash[:order] || 999
@max_slots = hash[:max_slots] || -1
@auto_sort = hash[:auto_sort] || false
end
# @return [String] the translated name of this nature
def name
return _INTL(@real_name)
end
end
end
#===============================================================================
#
#===============================================================================
GameData::BagPocket.register({
:id => :Items,
:name => _INTL("Items"),
:icon_position => 0,
:order => 10
})
GameData::BagPocket.register({
:id => :Medicine,
:name => _INTL("Medicine"),
:icon_position => 1,
:order => 20
})
GameData::BagPocket.register({
:id => :PokeBalls,
:name => _INTL("Poké Balls"),
:icon_position => 2,
:order => 30
})
GameData::BagPocket.register({
:id => :Machines,
:name => _INTL("TMs & HMs"),
:icon_position => 3,
:order => 40,
:auto_sort => true
})
GameData::BagPocket.register({
:id => :Berries,
:name => _INTL("Berries"),
:icon_position => 4,
:order => 50,
:auto_sort => true
})
GameData::BagPocket.register({
:id => :Mail,
:name => _INTL("Mail"),
:icon_position => 5,
:order => 60
})
GameData::BagPocket.register({
:id => :BattleItems,
:name => _INTL("Battle Items"),
:icon_position => 6,
:order => 70
})
GameData::BagPocket.register({
:id => :KeyItems,
:name => _INTL("Key Items"),
:icon_position => 7,
:order => 80
})

View File

@@ -30,7 +30,7 @@ module GameData
"NamePlural" => [:real_name_plural, "s"],
"PortionName" => [:real_portion_name, "s"],
"PortionNamePlural" => [:real_portion_name_plural, "s"],
"Pocket" => [:pocket, "v"],
"Pocket" => [:pocket, "y", :BagPocket],
"Price" => [:price, "u"],
"SellPrice" => [:sell_price, "u"],
"BPPrice" => [:bp_price, "u"],
@@ -126,7 +126,7 @@ module GameData
@real_name_plural = hash[:real_name_plural] || "Unnamed"
@real_portion_name = hash[:real_portion_name]
@real_portion_name_plural = hash[:real_portion_name_plural]
@pocket = hash[:pocket] || 1
@pocket = hash[:pocket] || :None
@price = hash[:price] || 0
@sell_price = hash[:sell_price] || (@price / Settings::ITEM_SELL_PRICE_DIVISOR)
@bp_price = hash[:bp_price] || 1

View File

@@ -706,7 +706,7 @@ def pbItemBall(item, quantity = 1)
pbMessage("\\me[#{meName}]" + _INTL("You found a \\c[1]{1}\\c[0]!", itemname) + "\\wtnp[40]")
end
pbMessage(_INTL("You put the {1} in\nyour Bag's <icon=bagPocket{2}>\\c[1]{3}\\c[0] pocket.",
itemname, pocket, PokemonBag.pocket_names[pocket - 1]))
itemname, pocket, GameData::BagPocket.get(pocket).name))
return true
end
# Can't add the item
@@ -756,7 +756,7 @@ def pbReceiveItem(item, quantity = 1)
end
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.",
itemname, pocket, PokemonBag.pocket_names[pocket - 1]))
itemname, pocket, GameData::BagPocket.get(pocket).name))
return true
end
return false # Can't add the item
@@ -772,6 +772,6 @@ def pbBuyPrize(item, quantity = 1)
pocket = item.pocket
return false if !$bag.add(item, quantity)
pbMessage("\\CN" + _INTL("You put the {1} in\nyour Bag's <icon=bagPocket{2}>\\c[1]{3}\\c[0] pocket.",
item_name, pocket, PokemonBag.pocket_names[pocket - 1]))
item_name, pocket, GameData::BagPocket.get(pocket).name))
return true
end

View File

@@ -459,7 +459,7 @@ def pbPickBerry(berry, qty = 1)
end
pocket = berry.pocket
pbMessage(_INTL("You put the {1} in\nyour Bag's <icon=bagPocket{2}>\\c[1]{3}\\c[0] pocket.",
berry_name, pocket, PokemonBag.pocket_names[pocket - 1]) + "\1")
berry_name, pocket, GameData::BagPocket.get(pocket).name) + "\1")
if Settings::NEW_BERRY_PLANTS
pbMessage(_INTL("The soil returned to its soft and earthy state."))
else

View File

@@ -8,38 +8,36 @@ class PokemonBag
attr_reader :registered_items
attr_reader :ready_menu_selection
def self.pocket_names
return Settings.bag_pocket_names
end
MAX_PER_SLOT = 999
def self.pocket_count
return self.pocket_names.length
return GameData::BagPocket.count
end
def initialize
@pockets = []
(0..PokemonBag.pocket_count).each { |i| @pockets[i] = [] }
@pockets = {}
GameData::BagPocket.all_pockets.each { |pckt| @pockets[pckt] = [] }
reset_last_selections
@registered_items = []
@ready_menu_selection = [0, 0, 1] # Used by the Ready Menu to remember cursor positions
end
def reset_last_selections
@last_viewed_pocket = 1
@last_pocket_selections ||= []
(0..PokemonBag.pocket_count).each { |i| @last_pocket_selections[i] = 0 }
@last_viewed_pocket = GameData::BagPocket.all_pockets.first
@last_pocket_selections ||= {}
GameData::BagPocket.all_pockets.each { |pckt| @last_pocket_selections[pckt] = 0 }
end
def clear
@pockets.each { |pocket| pocket.clear }
(PokemonBag.pocket_count + 1).times { |i| @last_pocket_selections[i] = 0 }
@pockets.each_value { |pocket| pocket.clear }
GameData::BagPocket.all_pockets.each { |pckt| @last_pocket_selections[pckt] = 0 }
end
#-----------------------------------------------------------------------------
# Gets the index of the current selected item in the pocket
def last_viewed_index(pocket)
if pocket <= 0 || pocket > PokemonBag.pocket_count
if !GameData::BagPocket.exists?(pocket)
raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect))
end
return [@last_pocket_selections[pocket], @pockets[pocket].length].min || 0
@@ -47,7 +45,7 @@ class PokemonBag
# Sets the index of the current selected item in the pocket
def set_last_viewed_index(pocket, value)
if pocket <= 0 || pocket > PokemonBag.pocket_count
if !GameData::BagPocket.exists?(pocket)
raise ArgumentError.new(_INTL("Invalid pocket: {1}", pocket.inspect))
end
@last_pocket_selections[pocket] = value if value <= @pockets[pocket].length
@@ -74,7 +72,7 @@ class PokemonBag
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
@pockets[pocket], max_size, MAX_PER_SLOT, item_data.id, qty
)
end
@@ -85,8 +83,8 @@ class PokemonBag
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 - 1]
max_size, MAX_PER_SLOT, item_data.id, qty)
if ret && GameData::BagPocket.get(pocket).auto_sort
@pockets[pocket].sort! { |a, b| GameData::Item.keys.index(a[0]) <=> GameData::Item.keys.index(b[0]) }
end
return ret
@@ -160,7 +158,7 @@ class PokemonBag
private
def max_pocket_size(pocket)
return Settings::BAG_MAX_POCKET_SIZE[pocket - 1] || -1
return GameData::BagPocket.get(pocket).max_slots
end
end

View File

@@ -613,8 +613,8 @@ class PokemonMartScreen
itemname, price.to_s_formatted))
quantity = 1
else
maxafford = (price <= 0) ? Settings::BAG_MAX_PER_SLOT : @adapter.getMoney / price
maxafford = Settings::BAG_MAX_PER_SLOT if maxafford > Settings::BAG_MAX_PER_SLOT
maxafford = (price <= 0) ? PokemonBag::MAX_PER_SLOT : @adapter.getMoney / price
maxafford = PokemonBag::MAX_PER_SLOT if maxafford > PokemonBag::MAX_PER_SLOT
quantity = @scene.pbChooseNumber(
_INTL("So how many {1}?", itemnameplural), item, maxafford
)

View File

@@ -462,8 +462,8 @@ class BattlePointShopScreen
itemname, price.to_s_formatted))
quantity = 1
else
maxafford = (price <= 0) ? Settings::BAG_MAX_PER_SLOT : @adapter.getBP / price
maxafford = Settings::BAG_MAX_PER_SLOT if maxafford > Settings::BAG_MAX_PER_SLOT
maxafford = (price <= 0) ? PokemonBag::MAX_PER_SLOT : @adapter.getBP / price
maxafford = PokemonBag::MAX_PER_SLOT if maxafford > PokemonBag::MAX_PER_SLOT
quantity = @scene.pbChooseNumber(
_INTL("How many {1} would you like?", itemnameplural), item, maxafford
)

View File

@@ -211,7 +211,7 @@ class UI::BagVisuals < UI::BaseVisuals
@sprites[:item_list].switching_base_color = TEXT_COLOR_THEMES[:switching][0]
@sprites[:item_list].switching_shadow_color = TEXT_COLOR_THEMES[:switching][1]
@sprites[:item_list].items = @bag.pockets[@pocket]
@sprites[:item_list].index = @bag.last_viewed_index(@pocket)
@sprites[:item_list].index = @bag.last_viewed_index(@pocket) if @mode != :choose_item
@sprites[:item_list].active = false
end
@@ -231,7 +231,9 @@ class UI::BagVisuals < UI::BaseVisuals
#-----------------------------------------------------------------------------
def background_filename
return gendered_filename(self.class::BACKGROUND_FILENAME + "_" + @pocket.to_s)
ret = gendered_filename(self.class::BACKGROUND_FILENAME + "_" + @pocket.to_s)
return ret if pbResolveBitmap(graphics_folder + ret)
return super
end
def index
@@ -247,27 +249,27 @@ class UI::BagVisuals < UI::BaseVisuals
def set_filter_proc(filter_proc)
@filter_proc = filter_proc
# Create filtered pocket lists
@filtered_list = []
(1...@bag.pockets.length).each do |pckt|
all_pockets = GameData::BagPocket.all_pockets
@filtered_list = {}
all_pockets.each do |pckt|
@filtered_list[pckt] = []
@bag.pockets[pckt].length.times do |j|
@filtered_list[pckt].push(@bag.pockets[pckt][j]) if @filter_proc.call(@bag.pockets[pckt][j][0])
end
end
# Ensure current pocket is one that isn't empty
new_pocket = 1
new_pocket_index = 0
if @mode == :choose_item_in_battle && !@filtered_list[@bag.last_viewed_pocket].empty?
new_pocket = @bag.last_viewed_pocket
new_pocket_index = all_pockets.index(@bag.last_viewed_pocket)
end
num_pockets = PokemonBag.pocket_count
num_pockets.times do |i|
next_pocket = new_pocket + i
next_pocket -= num_pockets if next_pocket > num_pockets
next if @filtered_list[next_pocket].empty?
new_pocket = next_pocket
all_pockets.length.times do |i|
next_pocket_index = (new_pocket_index + i) % all_pockets.length
next if @filtered_list[all_pockets[next_pocket_index]].empty?
new_pocket_index = next_pocket_index
break
end
new_pocket = 1 if @filtered_list[new_pocket].empty? # In case all pockets are empty
new_pocket_index = 0 if @filtered_list[all_pockets[new_pocket_index]].empty? # In case all pockets are empty
new_pocket = all_pockets[new_pocket_index]
# Set the new pocket
set_pocket(new_pocket)
@sprites[:item_list].index = 0
@@ -275,7 +277,7 @@ class UI::BagVisuals < UI::BaseVisuals
def set_pocket(new_pocket)
@pocket = new_pocket
@bag.last_viewed_pocket = @pocket
@bag.last_viewed_pocket = @pocket if @mode != :choose_item
if @filtered_list
@sprites[:item_list].items = @filtered_list[@pocket]
else
@@ -287,8 +289,11 @@ class UI::BagVisuals < UI::BaseVisuals
def go_to_next_pocket
new_pocket = @pocket
all_pockets = GameData::BagPocket.all_pockets
new_pocket_index = all_pockets.index(new_pocket)
loop do
new_pocket = (new_pocket >= PokemonBag.pocket_count) ? 1 : new_pocket + 1
new_pocket_index = (new_pocket_index + 1) % all_pockets.length
new_pocket = all_pockets[new_pocket_index]
break if ![:choose_item, :choose_item_in_battle].include?(@mode)
break if new_pocket == @pocket # Bag is empty somehow
if @filtered_list
@@ -304,8 +309,11 @@ class UI::BagVisuals < UI::BaseVisuals
def go_to_previous_pocket
new_pocket = @pocket
all_pockets = GameData::BagPocket.all_pockets
new_pocket_index = all_pockets.index(new_pocket)
loop do
new_pocket = (new_pocket <= 1) ? PokemonBag.pocket_count : new_pocket - 1
new_pocket_index = (new_pocket_index - 1) % all_pockets.length
new_pocket = all_pockets[new_pocket_index]
break if ![:choose_item, :choose_item_in_battle].include?(@mode)
break if new_pocket == @pocket # Bag is empty somehow
if @filtered_list
@@ -327,7 +335,7 @@ class UI::BagVisuals < UI::BaseVisuals
return false if @mode != :normal || @filtered_list
return false if @bag.pockets[@pocket].length <= 1
return false if index >= @bag.pockets[@pocket].length
return false if Settings::BAG_POCKET_AUTO_SORT[@pocket - 1]
return false if GameData::BagPocket.get(@pocket).auto_sort
return true
end
@@ -373,26 +381,41 @@ class UI::BagVisuals < UI::BaseVisuals
end
def refresh_pocket_icons
icon_size = [28, 28]
icon_overlap = 6
icon_x = 2
icon_y = 2
@sprites[:pocket_icons].bitmap.clear
# Draw the pocket icons
all_pockets = GameData::BagPocket.all_pockets
# Draw regular pocket icons
all_pockets.each_with_index do |pckt, i|
icon_pos = GameData::BagPocket.get(pckt).icon_position
draw_image(@bitmaps[:pocket_icons], icon_x + (i * (icon_size[0] - icon_overlap)), icon_y,
icon_pos * icon_size[0], icon_size[1], *icon_size, overlay: :pocket_icons)
end
# Draw disabled pocket icons
if [:choose_item, :choose_item_in_battle].include?(@mode) && @filtered_list
(1...@bag.pockets.length).each do |i|
next if @filtered_list[i].length > 0
draw_image(@bitmaps[:pocket_icons], 6 + ((i - 1) * 22), 6,
(i - 1) * 20, 28, 20, 20, overlay: :pocket_icons)
all_pockets.each_with_index do |pckt, i|
next if @filtered_list[pckt].length > 0
icon_pos = GameData::BagPocket.get(pckt).icon_position
draw_image(@bitmaps[:pocket_icons], icon_x + (i * (icon_size[0] - icon_overlap)), icon_y,
icon_pos * icon_size[0], icon_size[1] * 2, *icon_size, overlay: :pocket_icons)
end
end
draw_image(@bitmaps[:pocket_icons], 2 + ((@pocket - 1) * 22), 2,
(@pocket - 1) * 28, 0, 28, 28, overlay: :pocket_icons)
# Draw selected pocket's icon
pocket_number = GameData::BagPocket.index(@pocket)
icon_pos = GameData::BagPocket.get(@pocket).icon_position
draw_image(@bitmaps[:pocket_icons], icon_x + (pocket_number * (icon_size[0] - icon_overlap)), icon_y,
icon_pos * icon_size[0], 0, *icon_size, overlay: :pocket_icons)
# TODO: Draw the left and right arrows, if @mode != :choose_item ||
# @filtered_list has 2+ non-empty pockets.
end
def refresh_pocket
# Draw pocket's name
draw_text(PokemonBag.pocket_names[@pocket - 1], 94, 186, align: :center, theme: :black)
draw_text(GameData::BagPocket.get(@pocket).name, 94, 186, align: :center, theme: :black)
# Set the bag sprite
bag_sprite_filename = graphics_folder + gendered_filename(sprintf("bag_%d", @pocket))
bag_sprite_filename = graphics_folder + gendered_filename(sprintf("bag_%s", @pocket.to_s))
@sprites[:bag].setBitmap(bag_sprite_filename)
end
@@ -482,7 +505,7 @@ class UI::BagVisuals < UI::BaseVisuals
this_pocket.insert(index, this_pocket.delete_at(old_index))
@sprites[:item_list].items = this_pocket
end
@bag.set_last_viewed_index(@pocket, index)
@bag.set_last_viewed_index(@pocket, index) if @mode != :choose_item
refresh_slider
refresh_selected_item
end
@@ -776,10 +799,10 @@ UIActionHandlers.add(UI::Bag::SCREEN_ID, :debug, {
qty = screen.bag.quantity(screen.item.id)
item_name_plural = screen.item.name_plural
params = ChooseNumberParams.new
params.setRange(0, Settings::BAG_MAX_PER_SLOT)
params.setRange(0, PokemonBag::MAX_PER_SLOT)
params.setDefaultValue(qty)
new_qty = screen.choose_number(
_INTL("Choose new quantity of {1} (max. {2}).", item_name_plural, Settings::BAG_MAX_PER_SLOT), params
_INTL("Choose new quantity of {1} (max. {2}).", item_name_plural, PokemonBag::MAX_PER_SLOT), params
)
if new_qty > qty
screen.bag.add(screen.item.id, new_qty - qty)

View File

@@ -97,7 +97,7 @@ class Window_PokemonBag < Window_DrawableCommand
end
if item_data.show_quantity? && !showing_register_icon
qty = (@filterlist) ? thispocket[@filterlist[@pocket][index]][1] : thispocket[index][1]
qtytext = _ISPRINTF("x{1: 3d}", qty)
qtytext = _ISPRINTF("×{1: 3d}", qty)
xQty = rect.x + rect.width - self.contents.text_size(qtytext).width - 16
textpos.push([qtytext, xQty, rect.y + 2, :left, baseColor, shadowColor])
end

View File

@@ -896,8 +896,8 @@ def pbItemEditorNew(default_name)
return
end
# Choose a pocket
pocket = PocketProperty.set("", 0)
return if pocket == 0
pocket = PocketProperty.set("", :None)
return if pocket == :None
# Choose a price
price = LimitProperty.new(999_999).set(_INTL("Purchase price"), -1)
return if price == -1

View File

@@ -923,18 +923,21 @@ end
#===============================================================================
module PocketProperty
def self.set(_settingname, oldsetting)
commands = Settings.bag_pocket_names.clone
cmd = pbMessage(_INTL("Choose a pocket for this item."), commands, -1)
return (cmd >= 0) ? cmd + 1 : oldsetting
pockets = GameData::BagPocket.all_pockets
commands = []
pockets.each { |pckt| commands.push(GameData::BagPocket.get(pckt).name) }
initial_val = pockets.index(GameData::BagPocket.get(oldsetting || 1).id)
cmd = pbMessage(_INTL("Choose a pocket for this item."), commands, -1, nil, initial_val)
return (cmd >= 0) ? pockets[cmd] : oldsetting
end
def self.defaultValue
return 1
return GameData::BagPocket.all_pockets.first
end
def self.format(value)
return _INTL("No Pocket") if value == 0
return (value) ? Settings.bag_pocket_names[value - 1] : value.inspect
return _INTL("No Pocket") if value == 0 || value == :None
return (value) ? GameData::BagPocket.get(value).name : value.inspect
end
end

View File

@@ -788,7 +788,7 @@ MenuHandlers.add(:debug_menu, :add_item, {
pbListScreenBlock(_INTL("ADD ITEM"), ItemLister.new) do |button, item|
if button == Input::USE && item
params = ChooseNumberParams.new
params.setRange(1, Settings::BAG_MAX_PER_SLOT)
params.setRange(1, PokemonBag::MAX_PER_SLOT)
params.setInitialValue(1)
params.setCancelValue(0)
qty = pbMessageChooseNumber(_INTL("Add how many {1}?",
@@ -808,7 +808,7 @@ MenuHandlers.add(:debug_menu, :fill_bag, {
"description" => _INTL("Empties the Bag and then fills it with a certain number of every item."),
"effect" => proc {
params = ChooseNumberParams.new
params.setRange(1, Settings::BAG_MAX_PER_SLOT)
params.setRange(1, PokemonBag::MAX_PER_SLOT)
params.setInitialValue(1)
params.setCancelValue(0)
qty = pbMessageChooseNumber(_INTL("Choose the number of items."), params)
@@ -816,11 +816,13 @@ MenuHandlers.add(:debug_menu, :fill_bag, {
$bag.clear
# NOTE: This doesn't simply use $bag.add for every item in turn, because
# that's really slow when done in bulk.
pocket_sizes = Settings::BAG_MAX_POCKET_SIZE
pocket_sizes = {}
GameData::BagPocket.each { |pckt| pocket_sizes[pckt.id] = pckt.max_slots }
bag = $bag.pockets # Called here so that it only rearranges itself once
GameData::Item.each do |i|
next if !pocket_sizes[i.pocket - 1] || pocket_sizes[i.pocket - 1] == 0
next if pocket_sizes[i.pocket - 1] > 0 && bag[i.pocket].length >= pocket_sizes[i.pocket - 1]
next if GameData::BagPocket.get(i.pocket).max_slots
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]
item_qty = (i.is_important?) ? 1 : qty
bag[i.pocket].push([i.id, item_qty])
end

View File

@@ -375,6 +375,14 @@ module Compiler
end
def validate_compiled_item(hash)
# Support for pockets still being numbers
if hash[:pocket] && hash[:pocket].is_a?(Integer)
all_pockets = GameData::BagPocket.all_pockets
if hash[:pocket] <= 0 || !all_pockets[hash[:pocket] - 1]
raise _INTL("Invalid pocket number {1} for item {2}.", hash[:pocket], hash[:id])
end
hash[:pocket] = all_pockets[hash[:pocket] - 1]
end
end
def validate_all_compiled_items