################################################################################
# #
# Tidloc's Dynamic Shop System v. 1.3 #
# by the request of Gnarizard #
# (http://rmrk.net/index.php/topic,32876.0.html) #
#------------------------------------------------------------------------------#
# This shop enables the following features: #
# -> Stocks items in Quantities #
# -> randomly gaining or loosing stock as time passes #
# -> Occasionally stocking a bonus (substantially more rare) item for sale #
# -> Items you sell become their stock #
#------------------------------------------------------------------------------#
# simply use the normal shop command of the Events to use this custom shop #
# for the calculation of bonus items use the last constants or call the #
# script Scene_Shop.bonus #
#------------------------------------------------------------------------------#
# Describing the defined constants: #
# DSHOP_SHOPVAR ... the global variable-id in which the shop number #
# is saved befor entering a shop #
# DSHOP_MAXGAIN ... Maximum gain every timestep [item,weap,armor] #
# DSHOP_TIMESTEP .. Minutes that have to pass to gain/loose stock #
# in ths shops #
# DSHOP_MINSTART .. Minimum start quantity of a single item #
# DSHOP_MAXSTART .. Maximum start quantity of a single item #
# DSHOP_WINDOW .... if a special windowskin shall be used enter here #
# it's name #
# DSHOP_ZERO ...... this boolean constant define wheter items with #
# no cost shall be displayed. #
# DSHOP_PROP ...... how high is the propability of getting a high #
# value item (out of 10'000) #
# DSHOP_CALCTIME .. bonus item calculation everytime the itemgain is #
# calculatated #
# DSHOP_CALCCALL .. bonus item calculation everytime the specific #
# shop is called #
# DSHOP_SPECIALS .. set in a set of 3 variables: [a,b,c} #
# a ... 1=item, 2=weapon, 3=armor #
# b ... ingame item-id #
# c ... an array of in which shops it shall be #
# available #
# DSHOP_EPIC ...... same as SPECIALS above, just that only one shop #
# may be entered in c. #
################################################################################
# As requested by Mr_Wiggles this script now differs normal items, weapons and #
# armors. #
# Simply with the MAXGAIN, MINSTART and MAXSTART use the following syntax: #
# ... = [item, weapon, armor] #
################################################################################
# You may us this script in any of your games, #
# but please credit me for this hell of work ^^ #
################################################################################
module Tidloc
D_Shop = true
DSHOP_SHOPVAR = 5
DSHOP_MAXGAIN = [5,2,2]
DSHOP_TIMESTEP = 1
DSHOP_MINSTART = [5,1,1]
DSHOP_MAXSTART = [35,4,4]
DSHOP_WINDOW = nil
DSHOP_ZERO = true
DSHOP_PROP = 1000
DSHOP_CALCTIME = false
DSHOP_CALCCALL = true
DSHOP_SPECIALS = [ [ 0,17,[1]],
[ 1, 4,[1,2]] ]
DSHOP_EPIC = [ [ 0, 31, 1] ]
if Language == "ger"
DSHOP_VOCAB = ["Kaufen","Verkaufen","Sonderangebote","Fertig"]
elsif Language == "eng"
DSHOP_VOCAB = ["Regular Items","Sell Items","Special Offers","Leave"]
end
end
# for storing the quantities of a shop
class Game_System
attr_accessor :tidloc_dshop
attr_accessor :tidloc_dshop_count
alias tidloc_dshop_init initialize
def initialize
tidloc_dshop_init
self.tidloc_dshop = []
self.tidloc_dshop_count = 0
end
def tidloc_dshop_add_shop(id)
if !tidloc_dshop_exist?(id)
self.tidloc_dshop.push Tidloc_D_Shop.new(id)
self.tidloc_dshop_count += 1
return true
end
return false
end
def tidloc_dshop_exist?(id)
for i in 0...self.tidloc_dshop_count
return i if self.tidloc_dshop[i]._id == id
end
return false
end
def tidloc_dshop_start_item(shop,item)
shopnum = tidloc_dshop_exist?(shop)
if !tidloc_dshop_item?(shop,item)
if !Tidloc::DSHOP_ZERO
if itme[0]==0
return false if $data_items[item[1]].price == 0
elsif item[0]==1
return false if $data_weapons[item[1]].price == 0
elsif item[0]==2
return false if $data_armors[item[1]].price == 0
end
end
delta=Tidloc::DSHOP_MAXSTART[item[0]]-Tidloc::DSHOP_MINSTART[item[0]]
self.tidloc_dshop[shopnum].items.push item
#------------- first time stocking:
self.tidloc_dshop[shopnum].stock.push (Tidloc::DSHOP_MINSTART[item[0]]+rand(delta/2)+rand(delta/2))
self.tidloc_dshop[shopnum].empty.push false
self.tidloc_dshop[shopnum].bonus.push false
self.tidloc_dshop[shopnum].sold.push false
self.tidloc_dshop[shopnum].count += 1
end
end
def tidloc_dshop_add_item(shop,item,amount)
shopnum = tidloc_dshop_exist?(shop)
id = tidloc_dshop_item?(shop,item)
if id == nil
self.tidloc_dshop[shopnum].items.push item
self.tidloc_dshop[shopnum].stock.push amount
self.tidloc_dshop[shopnum].empty.push false
self.tidloc_dshop[shopnum].bonus.push false
self.tidloc_dshop[shopnum].sold.push true
self.tidloc_dshop[shopnum].count += 1
else
self.tidloc_dshop[shopnum].stock[id] += amount
self.tidloc_dshop[shopnum].empty[id] = false if self.tidloc_dshop[shopnum].stock[id] > 0
end
end
def tidloc_dshop_add_bonus(shop,item)
shopnum = tidloc_dshop_exist?(shop)
id = tidloc_dshop_item?(shop,item)
if id == nil
#it = self.tidloc_dshop[shopnum].newitem(item)
self.tidloc_dshop[shopnum].items.push item
self.tidloc_dshop[shopnum].stock.push 1
self.tidloc_dshop[shopnum].empty.push false
self.tidloc_dshop[shopnum].bonus.push true
self.tidloc_dshop[shopnum].epic.push false
self.tidloc_dshop[shopnum].sold.push false
self.tidloc_dshop[shopnum].count += 1
else
self.tidloc_dshop[shopnum].stock[id] += 1
self.tidloc_dshop[shopnum].empty[id] = false if self.tidloc_dshop[shopnum].stock[id] > 0
end
end
def tidloc_dshop_add_epic(shop, item)
shopnum = tidloc_dshop_exist?(shop)
id = tidloc_dshop_item?(shop,item)
if id == nil
self.tidloc_dshop[shopnum].items.push item
self.tidloc_dshop[shopnum].stock.push 1
self.tidloc_dshop[shopnum].empty.push false
self.tidloc_dshop[shopnum].bonus.push true
self.tidloc_dshop[shopnum].epic.push true
self.tidloc_dshop[shopnum].sold.push false
self.tidloc_dshop[shopnum].count += 1
end
end
def tidloc_dshop_item?(shop,item)
shopnum = tidloc_dshop_exist?(shop)
for i in 0...self.tidloc_dshop[shopnum].count
if self.tidloc_dshop[shopnum].items[i] == item
return i
end
end
return nil
end
end
# the structure of the stored Shopping-goods
class Tidloc_D_Shop
attr_accessor :_id
attr_accessor :items
attr_accessor :stock
attr_accessor :empty
attr_accessor :bonus
attr_accessor :epic
attr_accessor :sold
attr_accessor :count
def initialize(id)
self._id = id
self.items = []
self.stock = []
self.empty = []
self.bonus = []
self.epic = []
self.sold = []
self.count = 0
end
def stocking(item)
for i in 0...self.count
if ((self.items[i][0] == 0 && item.is_a?(RPG::Item)) || (self.items[i][0] == 1 && item.is_a?(RPG::Weapon)) || (self.items[i][0] == 2 && item.is_a?(RPG::Armor)) ) && self.items[i][1] == item.id
return self.stock[i]
end
end
return nil
end
def setstock(item,number)
for i in 0...self.count
if self.items[i]!=nil && ((self.items[i][0] == 0 && item.is_a?(RPG::Item)) || (self.items[i][0] == 1 && item.is_a?(RPG::Weapon)) || (self.items[i][0] == 2 && item.is_a?(RPG::Armor)) ) && self.items[i][1] == item.id
number = 0 if number < 0
self.stock[i] = number
if number == 0
self.empty[i] = true
#if self.bonus[i]
# delete(i)
#end
end
end
end
end
def delete(it)
sh = false
for i in it...self.count
self.items[i] = self.items[i+1]
self.stock[i] = self.stock[i+1]
self.empty[i] = self.empty[i+1]
self.bonus[i] = self.bonus[i+1]
self.sold[i] = self.sold[i+1]
end
self.items[self.count-1] = nil
self.stock[self.count-1] = nil
self.empty[self.count-1] = nil
self.bonus[self.count-1] = nil
self.sold[self.count-1] = nil
self.count -= 1
end
def newitem(item)
k = self.count
for i in 0...self.count
j = (self.count - i) - 1
if item[0] >= self.items[j][0]
if item[1] >= self.items[j][1]
k=j + 1 if k == self.count
end
end
end
for l in 0..(self.count-k)
m = (self.count - l)
self.items[m] = self.items[m-1]
self.stock[m] = self.stock[m-1]
self.empty[m] = self.empty[m-1]
self.bonus[m] = self.bonus[m-1]
self.sold[m] = self.sold[m-1]
end
self.count += 1
return k
end
def Tidloc_D_Shop.New_Item(shop, item)
$game_system.tidloc_dshop_start_item(shop,item)
end
def Tidloc_D_Shop.New_Epic(shop, item)
$game_system.tidloc_dshop_add_epic(shop,item)
end
end
class Window_ShopBuy < Window_Selectable
def initialize(shopnum,bonus=false)
super(0, 128, 368, 352)
@shop = $game_system.tidloc_dshop_exist?(shopnum)
@goods = $game_system.tidloc_dshop[@shop]
@bonus = bonus
refresh
self.index = 0
end
def item
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 0...@goods.count
if @goods.items[i]!=nil && (!@bonus && !@goods.bonus[i] && !@goods.empty[i]) || (@bonus && @goods.bonus[i] && !@goods.empty[i])
case @goods.items[i][0]
when 0
item = $data_items[@goods.items[i][1]]
when 1
item = $data_weapons[@goods.items[i][1]]
when 2
item = $data_armors[@goods.items[i][1]]
end
if item != nil
@data.push(item)
end
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
if item.price <= $game_party.gold and number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 160, 32, item.name, 0)
self.contents.draw_text(x + 160, y, 88, 32, "x"+$game_system.tidloc_dshop[@shop].stocking(item).to_s, 2)
self.contents.draw_text(x + 240, y, 88, 32, item.price.to_s, 2)
end
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#---------------Scene_Shop
class Scene_Shop
def main
@shopnum = $game_variables.[](Tidloc::DSHOP_SHOPVAR)
if $game_system.tidloc_dshop_add_shop(@shopnum)
@shop = $game_system.tidloc_dshop_exist?(@shopnum)
for i in $game_temp.shop_goods
$game_system.tidloc_dshop_start_item(@shopnum,i)
end
for x in Tidloc::DSHOP_EPIC
y = x[2]
if y == $game_system.tidloc_dshop[@shop]._id
$game_system.tidloc_dshop_add_epic($game_system.tidloc_dshop[@shop]._id,[x[0],x[1]])
end
end
end
@shop = $game_system.tidloc_dshop_exist?(@shopnum)
if Tidloc::DSHOP_CALCCALL
if rand(10000) < Tidloc::DSHOP_PROP
temp = []
a=0
for x in Tidloc::DSHOP_SPECIALS
for y in x[2]
if y == $game_system.tidloc_dshop[@shop]._id
temp.push [x[0],x[1]]
end
end
end
if temp.size > 0
t = rand(temp.length)
$game_system.tidloc_dshop_add_bonus($game_system.tidloc_dshop[@shop]._id,temp[t])
end
end
end
@help_window = Window_Help.new
@gold_window = Window_Gold.new
@gold_window.y = 224
@dummy_window = Window_Base.new(160, 64, 480, 416)
commands = Tidloc::DSHOP_VOCAB
@command_window = Window_Command.new(160, commands)
@command_window.y = 64
@command_window.active = true
@buy_window = Window_ShopBuy.new(@shopnum)
@buy_window.z = 250
@buy_window.active = false
@buy_window.visible = false
@buy_window.help_window = @help_window
@special_window = Window_ShopBuy.new(@shopnum,true)
@special_window.z = 250
@special_window.active = false
@special_window.visible = false
@special_window.help_window = @help_window
@status_window = Window_ShopStatus.new
@status_window.visible = false
@sell_window = Window_ShopSell.new
@sell_window.z = 250
@sell_window.active = false
@sell_window.visible = false
@sell_window.help_window = @help_window
@number_window = Window_ShopNumber.new
@number_window.z = 300
@number_window.active = false
@number_window.visible = false
if Tidloc::DSHOP_WINDOW != nil
@help_window.windowskin = Tidloc::DSHOP_WINDOW
@gold_window.windowskin = Tidloc::DSHOP_WINDOW
@dummy_window.windowskin = Tidloc::DSHOP_WINDOW
@command_window.windowskin = Tidloc::DSHOP_WINDOW
@buy_window.windowskin = Tidloc::DSHOP_WINDOW
@status_window.windowskin = Tidloc::DSHOP_WINDOW
@special_window.windowskin = Tidloc::DSHOP_WINDOW
@sell_window.windowskin = Tidloc::DSHOP_WINDOW
@number_window.windowskin = Tidloc::DSHOP_WINDOW
end
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@number_window.dispose
@sell_window.dispose
@special_window.dispose
@status_window.dispose
@buy_window.dispose
@command_window.dispose
@dummy_window.dispose
@help_window.dispose
@gold_window.dispose
end
def update
@number_window.update
@sell_window.update
@special_window.update
@status_window.update
@buy_window.update
@dummy_window.update
@command_window.update
@gold_window.update
@help_window.update
if @command_window.active
update_command
elsif @buy_window.active
update_buy
elsif @special_window.active
update_special
elsif @sell_window.active
update_sell
elsif @number_window.active
update_number
end
end
def update_command
case @command_window.index
when 0
@help_window.set_text("Buying of the regular stock of the shop")
when 1
@help_window.set_text("Selling items you own")
when 2
@help_window.set_text("Buying rare offers of this shop")
when 3
@help_window.set_text("Leaving shop")
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
case @command_window.index
when 0
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@buy_window.active = true
@buy_window.visible = true
@status_window.visible = true
when 1
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = true
when 2
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@special_window.active = true
@special_window.visible = true
@status_window.visible = true
when 3
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
end
end
end
def update_buy
@status_window.item = @buy_window.item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.active = true
@buy_window.active = false
@buy_window.visible = false
@status_window.visible = false
@status_window.item = nil
return
end
if Input.trigger?(Input::C)
@item = @buy_window.item
if @item == nil || @item.price > $game_party.gold
@item = nil
$game_system.se_play($data_system.buzzer_se)
return
end
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
if number == 99
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
max = @item.price == 0 ? 99 : $game_party.gold / @item.price
max = [max, 99 - number, $game_system.tidloc_dshop[@shop].stocking(@item)].min
@buy_window.active = false
@buy_window.visible = false
@number_window.set(@item, max, @item.price)
@number_window.active = true
@number_window.visible = true
end
end
def update_special
@status_window.item = @special_window.item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.active = true
@special_window.active = false
@special_window.visible = false
@status_window.visible = false
@status_window.item = nil
return
end
if Input.trigger?(Input::C)
@item = @special_window.item
if @item == nil || @item.price > $game_party.gold
@item = nil
$game_system.se_play($data_system.buzzer_se)
return
end
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
if number == 99
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
max = @item.price == 0 ? 99 : $game_party.gold / @item.price
max = [max, 99 - number, $game_system.tidloc_dshop[@shop].stocking(@item)].min
@special_window.active = false
@special_window.visible = false
@number_window.set(@item, max, @item.price)
@number_window.active = true
@number_window.visible = true
@special = true
end
end
def update_sell
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@command_window.active = true
@sell_window.active = false
@sell_window.visible = false
@status_window.item = nil
@help_window.set_text("")
return
end
if Input.trigger?(Input::C)
@item = @sell_window.item
@status_window.item = @item
if @item == nil or @item.price == 0
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
case @item
when RPG::Item
number = $game_party.item_number(@item.id)
when RPG::Weapon
number = $game_party.weapon_number(@item.id)
when RPG::Armor
number = $game_party.armor_number(@item.id)
end
max = number
@sell_window.active = false
@sell_window.visible = false
@number_window.set(@item, max, @item.price / 2)
@number_window.active = true
@number_window.visible = true
@status_window.visible = true
end
end
def update_number
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0
@buy_window.active = true
@buy_window.visible = true
when 1
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
when 2
@special_window.active = true
@special_window.visible = true
end
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.shop_se)
@number_window.active = false
@number_window.visible = false
case @command_window.index
when 0
$game_party.lose_gold(@number_window.number * @item.price)
$game_system.tidloc_dshop[@shop].setstock(@item,($game_system.tidloc_dshop[@shop].stocking(@item)-@number_window.number))
case @item
when RPG::Item
$game_party.gain_item(@item.id, @number_window.number)
when RPG::Weapon
$game_party.gain_weapon(@item.id, @number_window.number)
when RPG::Armor
$game_party.gain_armor(@item.id, @number_window.number)
end
@gold_window.refresh
@buy_window.refresh
@status_window.refresh
@sell_window.refresh
@buy_window.active = true
@buy_window.visible = true
when 1
$game_party.gain_gold(@number_window.number * (@item.price / 2))
it = []
case @item
when RPG::Item
$game_party.lose_item(@item.id, @number_window.number)
it[0]=0
when RPG::Weapon
$game_party.lose_weapon(@item.id, @number_window.number)
it[0]=1
when RPG::Armor
$game_party.lose_armor(@item.id, @number_window.number)
it[0]=2
end
it[1]=@item.id
$game_system.tidloc_dshop_add_item(@shopnum,it,@number_window.number)
@gold_window.refresh
@sell_window.refresh
@buy_window.refresh
@status_window.refresh
@sell_window.active = true
@sell_window.visible = true
@status_window.visible = false
when 2
$game_party.lose_gold(@number_window.number * @item.price)
$game_system.tidloc_dshop[@shop].setstock(@item,($game_system.tidloc_dshop[@shop].stocking(@item)-@number_window.number))
case @item
when RPG::Item
$game_party.gain_item(@item.id, @number_window.number)
when RPG::Weapon
$game_party.gain_weapon(@item.id, @number_window.number)
when RPG::Armor
$game_party.gain_armor(@item.id, @number_window.number)
end
@gold_window.refresh
@special_window.refresh
@status_window.refresh
@sell_window.refresh
@special_window.active = true
@special_window.visible = true
end
return
end
end
def Scene_Shop.bonus
for i in 0...$game_system.tidloc_dshop_count
if rand(10000) < Tidloc::DSHOP_PROP
temp = []
a=0
for x in Tidloc::DSHOP_SPECIALS
for y in x[2]
if y == $game_system.tidloc_dshop[i]._id
temp.push [x[0],x[1]]
end
end
end
if temp.size > 0
t = rand(temp.length)
$game_system.tidloc_dshop_add_bonus($game_system.tidloc_dshop[i]._id,temp[t])
end
end
end
end
end
class Scene_Load < Scene_File
alias tidloc_dshop_save_data read_save_data
def read_save_data(file)
tidloc_dshop_save_data(file)
$game_system.tidloc_dshop = [] if $game_system.tidloc_dshop.nil?
$game_system.tidloc_dshop_count = 0 if $game_system.tidloc_dshop_count.nil?
end
end