[RC] KGlobalShop XP - kyonides - 01-24-2021
KGlobalShop XP
Release Candidate 2
by Kyonides Arkanthes
Introduction
Normally any in game shop would only offer products or let you sell something to get rid of that nasty junk that has been filling your bag for quite some time. This script wants to allow you to sell them to a Global Shop. By global I mean it's a shop event you usually create but it won't eat the items you sell there as a hungry monster. Instead it will keep them and they will be available for other gamers.
Yes, my dear game developers! This is all about letting you exchange items between game saves!
Since this is a Release Candidate, most of the promised features are currently implemented. Still, I do need somebody to test it for me.
Yeah, I know. People often claim I should do it myself, and I am not really against it. What happens here is that experience has taught me how important it might be to let people that think as some (amateur) game developer to fiddle with it. You see, they do not share the same thoughts so their expectations could be different from the very beginning. This is what might cause the surge of weird and unexpected bugs that otherwise would not have been discovered because, well, the scripter is used to use the script as intended so he does not make the same mistakes as the average user. Plus there are other users that love to break a script or a whole game just for the sake of it.
List of Currently Available Features
- Your usual list of shop goods
- Default or custom price modifications of items
- Separate script calls that allow you to set those prices, either for sales or purchases
- Hide or restore shop goods!
- List of transactions, both sales and purchases - not displayed on screen right now
- Automatically saved data, you still can save it manually if deemed necessary
- An empty help window
Script
Code: # * KGlobalShop XP - RC2
# Scripter : Kyonides Arkanthes
# 2021-01-29 - Release Candidate
# It now offers you the Hidden Goods!
# * Script Calls * #
# - Save all Global Shop's goods!
# KGlobalShop.save_goods
# - Get or Set a Specific Price, Kinds: 0 - Item, 1 - Weapon, 2 - Armor
# KGlobalShop.buy_price(Kind, ItemID)
# KGlobalShop.sell_price(Kind, ItemID)
# KGlobalShop.set_buy_price(Kind, ItemID, Price)
# KGlobalShop.set_sell_price(Kind, ItemID, Price)
# - Hide or Restore an Item!
# KGlobalShop.hide_item(Kind, ItemID)
# KGlobalShop.restore_item(Kind, ItemID)
module KGlobalShop
FILENAME = 'KGlobalShop.rxdata'
SELECT_LABEL = 'Main Menu'
PARTY_BAG_LABEL = "Party's Items"
SHOP_LABEL = 'Global Shop'
OPTIONS = ["Party's Bag", 'Global Shop', 'Help Menu']
# Default Player's Purchases
PRICE_MULTIPLIER = { 0 => 1.25, 1 => 1.5, 2 => 1.4 }
# Default Player's Sales
PRICE_REDUCTION = { 0 => 0.75, 1 => 0.85, 2 => 0.9 }
class << self
attr_accessor :goods, :buy_prices, :sell_prices, :gold
def buy_price(kind, item_id) @buy_prices[kind][item_id] end
def sell_price(kind, item_id) @sell_prices[kind][item_id] end
def set_buy_price(kind, item_id, price)
@buy_prices[kind][item_id] = price.round
end
def set_sell_price(kind, item_id, price)
@sell_prices[kind][item_id] = price.round
end
def store_item(kind, oid, number)
goods = @goods[kind]
goods[oid] ||= 0
goods[oid] += number
end
def sell_item(kind, oid, number)
goods = @goods[kind]
goods[oid] -= number
goods.delete(oid) if goods[oid] == 0
end
def hide_item(kind, oid)
@hidden_goods[kind] ||= { oid => 0 }
@hidden_goods[kind][oid] += @goods[kind].delete(oid)
end
def restore_item(kind, oid)
number = @hidden_goods[kind].delete(oid)
store_item(kind, oid, number)
end
def save_goods
file = File.open(FILENAME, 'wb')
Marshal.dump(@goods, FILENAME)
Marshal.dump(@hidden_goods, FILENAME)
Marshal.dump(@buy_prices, FILENAME)
Marshal.dump(@sell_prices, FILENAME)
Marshal.dump(@gold, FILENAME)
file.close
end
def load_stored_goods
file = File.open(FILENAME, 'rb')
@goods = Marshal.load(file)
@hidden_goods = Marshal.load(file)
@buy_prices = Marshal.load(file)
@sell_prices = Marshal.load(file)
@gold = Marshal.load(file)
file.close
end
def load_empty_goods
@goods = { 0 => {}, 1 => {}, 2 => {} }
@hidden_goods = { 0 => {}, 1 => {}, 2 => {} }
@buy_prices = { 0 => {}, 1 => {}, 2 => {} }
@sell_prices = { 0 => {}, 1 => {}, 2 => {} }
@gold = { :purchase => 0, :sale => 0 }
end
def load_goods
File.exist?(FILENAME)? load_stored_goods : load_empty_goods
end
end
load_goods
end
class Game_Party
def stuff_number(kind, item_id)
case kind
when 0 then $game_party.item_number(item_id)
when 1 then $game_party.weapon_number(item_id)
when 2 then $game_party.armor_number(item_id)
end
end
def lose_stuff(kind, item_id, number)
case kind
when 0 then lose_item(item_id, number)
when 1 then lose_weapon(item_id, number)
when 2 then lose_armor(item_id, number)
end
end
end
class KNormalItemWindow < Window_Item
def update_help
if self.item
text = self.item.description
align = 0
else
text = KGlobalShop::PARTY_BAG_LABEL
align = 1
end
@help_window.set_text(text, align)
end
end
class KGlobalItemWindow < Window_Item
def collect_list(pos)
@data << @list[pos]
@source << @kind
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
all_goods = KGlobalShop.goods
@data = []
@source = []
@kind = 0
@list = $data_items
all_goods[@kind].keys.sort.each {|i| collect_list(i) }
@kind = 1
@list = $data_weapons
all_goods[@kind].keys.sort.each {|i| collect_list(i) }
@kind = 2
@list = $data_armors
all_goods[@kind].keys.sort.each {|i| collect_list(i) }
@item_max = @data.size
return if @item_max == 0
self.contents = Bitmap.new(width - 32, row_max * 32)
@item_max.times{|i| draw_item(i) }
end
def draw_item(index)
item = @data[index]
kind = @source[index]
number = KGlobalShop.goods[kind][item.id]
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
def update_help
if self.item
text = self.item.description
align = 0
else
text = KGlobalShop::SHOP_LABEL
align = 1
end
@help_window.set_text(text, align)
end
def item_kind() @source[@index] end
end
class KGlobalInfoWindow < Window_Base
def initialize
super(0, 64, 640, 436)
end
end
class KGlobalShopScene
def main
@stage = 0
@help_window = Window_Help.new
@help_window.set_text(KGlobalShop::SELECT_LABEL, 1)
@dummy_window = Window_Base.new(0, 64, 640, 436)
@info_window = KGlobalInfoWindow.new
@info_window.visible = false
@command_window = Window_Command.new(200, KGlobalShop::OPTIONS)
@command_window.x = 220
@command_window.y = 240
@bag_window = KNormalItemWindow.new
@bag_window.visible = false
@bag_window.active = false
@bag_window.help_window = @help_window
@global_window = KGlobalItemWindow.new
@global_window.visible = false
@global_window.active = false
@global_window.help_window = @help_window
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
Graphics.freeze
@global_window.dispose
@bag_window.dispose
@command_window.dispose
@info_window.dispose
@dummy_window.dispose
@help_window.dispose
KGlobalShop.save_goods if @changed
end
def update
case @stage
when 0
update_main
when 1
update_party_bag
when 2
update_global_bag
when 3
update_info
end
end
def update_main
@command_window.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@command_window.visible = false
@command_window.active = false
@dummy_window.visible = false
@stage = @command_window.index + 1
if @stage == 1
@bag_window.visible = true
@bag_window.active = true
elsif @stage == 2
@global_window.visible = true
@global_window.active = true
else
@info_window.visible = true
end
end
end
def exit_current_bag
$game_system.se_play($data_system.cancel_se)
@help_window.set_text(KGlobalShop::SELECT_LABEL, 1)
@command_window.visible = true
@command_window.active = true
@dummy_window.visible = true
@stage = 0
end
def update_party_bag
@bag_window.update
if Input.trigger?(Input::B)
@bag_window.visible = false
@bag_window.active = false
exit_current_bag
elsif Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@changed = true
item = @bag_window.item
item_id = item.id
price = item.price
kind = @bag_window.item_kind
number = $game_party.stuff_number(kind, item_id)
$game_party.lose_stuff(kind, item_id, number)
found_price = KGlobalShop.sell_price(kind, item_id)
if found_price
price = found_price * number
else
price = (KGlobalShop::PRICE_REDUCTION[kind] * price).round * number
end
$game_party.gain_gold(price)
KGlobalShop.gold[:purchase] += price
KGlobalShop.store_item(kind, item_id, number)
end
end
def update_global_bag
@global_window.update
if Input.trigger?(Input::B)
@global_window.visible = false
@global_window.active = false
exit_current_bag
elsif Input.trigger?(Input::C)
item = @global_window.item
item_id = item.id
price = item.price
case item
when RPG::Item
kind = 0
when RPG::Weapon
kind = 1
when RPG::Armor
kind = 2
end
number = KGlobalShop.goods[kind][item_id]
found_price = KGlobalShop.buy_price(kind, item_id)
if found_price
price = found_price * number
else
price = (KGlobalShop::PRICE_MULTIPLIER[kind] * price).round * number
end
if $game_party.gold < price
return $game_system.se_play($data_system.buzzer_se)
end
$game_system.se_play($data_system.decision_se)
@changed = true
$game_party.lose_gold(price)
KGlobalShop.gold[:sale] += price
KGlobalShop.sell_item(kind, item_id, number)
end
end
def update_info
if Input.trigger?(Input::B)
@info_window.visible = false
exit_current_bag
end
end
end
Terms & Conditions
Since it's a Release Candidate, you'd need to send me a copy of your game if you include two of my scripts.
RE: [BETA] KGlobalShop XP - kyonides - 01-28-2021
Update
I've modified the script once more and wanted you to test it if you've got some spare time to help me debug or improve it.
List of Currently Available Features
- Your usual list of shop goods
- Default or custom price modifications of items
- Separate script calls that allow you to set those prices, either for sales or purchases
- List of transactions, both sales and purchases - not displayed on screen right now
- Automatically saved data, you still can save it manually if deemed necessary
- An empty help window
I wouldn't mind if you send me sketches showing me how the menu or a specific part of it might look like.
RE: [RC] KGlobalShop XP - kyonides - 01-30-2021
Update
I've modified the script a third time to add another curious feature.
List of Currently Available Features
- Your usual list of shop goods
- Default or custom price modifications of items
- Separate script calls that allow you to set those prices, either for sales or purchases
- Hide or restore shop goods!
- List of transactions, both sales and purchases - not displayed on screen right now
- Automatically saved data, you still can save it manually if deemed necessary
- An empty help window
Got any idea how the script's GUI should look like?
Fee free to send me a PM then!
|