#------------------------------------------------------------------------------#
#-----Hex's Custom Prize Shop--------------------------------------------------#
# With this, you can have a token you can collect in your game, and exchange #
# the token for items. #
#-----Instructions-------------------------------------------------------------#
# Create a new event, and use this in a call script: #
# $scene = Prize_Shop(x1, x2, x3) #
# Where x1, x2, etc., are the items' Database IDs you want in the shop. You #
# can have up to 10 items per shop. #
# EXAMPLE: #
# $scene = Prize_Shop(1, 5, 8, 3, 41) #
# In the above example, the shop would sell items with Database IDs 1, 5, 8, 3 #
# and 41. #
# #
# In the configuration below: #
# PRIZE = [singular, plural] #
# singular = Singular name of your token #
# plural = Plural name of your token #
# #
# GVAR = number #
# number = game_variable used for your party's tokens #
# #
# when X: return C #
# X = item, weapon, armor ID #
# C = the price in tokens #
#------------------------------------------------------------------------------#
#-----Begin Configuration------------------------------------------------------#
#------------------------------------------------------------------------------#
module Prize
PRIZE = ["Token", "Tokens"]
GVAR = 777
#------------------------------------------------------------------------------#
#-----Item Prices--------------------------------------------------------------#
#------------------------------------------------------------------------------#
def self.item_price(id)
case id
when 1: return 5
when 2: return 1
when 4: return 11
when 5: return 3
when 9: return 32
when 10: return 641
end
return 10
end
#------------------------------------------------------------------------------#
#-----Weapon Prices------------------------------------------------------------#
#------------------------------------------------------------------------------#
def self.weapon_price(id)
case id
when 1: return 68
end
return 75
end
#------------------------------------------------------------------------------#
#-----Armor Prices-------------------------------------------------------------#
#------------------------------------------------------------------------------#
def self.armor_price(id)
case id
when 1: return 49
end
return 60
end
end
#------------------------------------------------------------------------------#
#-----End Configuration--------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Shop
def initialize(items=[], weapons=[], armors=[], menu_index=0)
@menu_index=menu_index
@commands = []
@data = []
@type = []
for i in 0..items.size
if items[i] != 0 && items[i] != nil
@data.push($data_items[items[i]])
@type.push(0)
end
end
for i in 0..weapons.size
if weapons[i] != 0 && weapons[i] != nil
@data.push($data_weapons[weapons[i]])
@type.push(1)
end
end
for i in 0..armors.size
if armors[i] != 0 && armors[i] != nil
@data.push($data_armors[armors[i]])
@type.push(2)
end
end
for i in 0..(@data.size - 1)
@commands.push(@data[i].name)
end
end
def main
@map = Spriteset_Map.new
@options = Window_Command.new(200, @commands)
@options.y = 128
@buy = Window_Command.new(90, ["Yes", "No"])
@buy.x = 550
@buy.y = 192
@buy.active = false
@buy.visible = false
@help = Prize_Help.new
@cost = Prize_Cost.new
@trophy = Trophies_Avail.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help.dispose
@options.dispose
@cost.dispose
@trophy.dispose
@map.dispose
end
def update
if @options.active
index = @options.index
@options.update
@help.update(@data[index])
@cost.update(@type[index], @data[index])
@trophy.update
update_options
return
end
if @buy.active
@buy.update
update_buy
return
end
end
def update_options
@index = @options.index
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
case @type[@index]
when 0
if Prize.item_price(@data[@index].id) > $game_variables[Prize::GVAR]
$game_system.se_play($data_system.buzzer_se)
return
end
when 1
if Prize.weapon_price(@data[@index].id) > $game_variables[Prize::GVAR]
$game_system.se_play($data_system.buzzer_se)
return
end
when 2
if Prize.armor_price(@data[@index].id) > $game_variables[Prize::GVAR]
$game_system.se_play($data_system.buzzer_se)
return
end
end
$game_system.se_play($data_system.decision_se)
@options.active = false
@purchase = Prize_Purchase.new
@buy.active = true
@buy.visible = true
@buy.index = 0
end
end
def update_buy
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@buy.active = false
@buy.visible = false
@buy.index = -1
@options.active = true
@purchase.dispose
end
if Input.trigger?(Input::C)
case @buy.index
when 0
$game_system.se_play($data_system.shop_se)
case @type[@index]
when 0
$game_variables[Prize::GVAR] -= Prize.item_price(@data[@index].id)
$game_party.gain_item(@data[@index].id, 1)
when 1
$game_variables[Prize::GVAR] -= Prize.weapon_price(@data[@index].id)
$game_party.gain_weapon(@data[@index].id, 1)
when 2
$game_variables[Prize::GVAR] -= Prize.armor_price(@data[@index].id)
$game_party.gain_armor(@data[@index].id, 1)
end
@trophy.update
@buy.active = false
@buy.visible = false
@buy.index = -1
@options.active = true
@purchase.dispose
when 1
$game_system.se_play($data_system.cancel_se)
@buy.active = false
@buy.visible = false
@buy.index = -1
@options.active = true
@purchase.dispose
end
end
end
end
#------------------------------------------------------------------------------#
#-----Prize Help Window--------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Help < Window_Base
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width-32, height-32)
self.contents.font.name = "Arial"
self.contents.font.size = 24
end
def update(x)
self.contents.clear
if x != 0
self.contents.draw_text(0, 0, 608, 32, x.description)
end
end
end
#------------------------------------------------------------------------------#
#-----Prize Cost Window--------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Cost < Window_Base
def initialize
super(0, 64, 240, 64)
self.contents = Bitmap.new(width-32, height-32)
self.contents.font.name = "Arial"
self.contents.font.size = 24
end
def update(y, x)
self.contents.clear
case y
when 0
if Prize.item_price(x.id) == 1
str = Prize::PRIZE[0]
else
str = Prize::PRIZE[1]
end
prc = Prize.item_price(x.id).to_s
when 1
if Prize.weapon_price(x.id) == 1
str = Prize::PRIZE[0]
else
str = Prize::PRIZE[1]
end
prc = Prize.weapon_price(x.id).to_s
when 2
if Prize.armor_price(x.id) == 1
str = Prize::PRIZE[0]
else
str = Prize::PRIZE[1]
end
prc = Prize.armor_price(x.id).to_s
end
cx = contents.text_size(str).width
self.contents.font.color = system_color
self.contents.draw_text(0, 0, 64, 32, "Cost:")
self.contents.font.color = normal_color
self.contents.draw_text(200-cx-64, 0, 64, 32, prc, align=2)
self.contents.draw_text(208-cx, 0, cx, 32, str)
end
end
#------------------------------------------------------------------------------#
#-----Trophies Available Window------------------------------------------------#
#------------------------------------------------------------------------------#
class Trophies_Avail < Window_Base
def initialize
super(400, 64, 240, 64)
self.contents = Bitmap.new(width-32, height-32)
self.contents.font.name = "Arial"
self.contents.font.size = 24
update
end
def update
self.contents.clear
x = $game_variables[Prize::GVAR]
str = Prize::PRIZE[1]
self.contents.font.color = system_color
self.contents.draw_text(0, 0, 160, 32, "Available" + " " + str + ":")
self.contents.font.color = normal_color
self.contents.draw_text(160, 0, 48, 32, x.to_s, align = 2)
end
end
#------------------------------------------------------------------------------#
#-----Purchase Window----------------------------------------------------------#
#------------------------------------------------------------------------------#
class Prize_Purchase < Window_Base
def initialize
super(486, 128, 154, 64)
self.contents = Bitmap.new(width-32, height-32)
self.contents.font.name = "Arial"
self.contents.font.size = 24
self.contents.draw_text(0, 0, 128, 32, "Purchase?", align = 1)
end
end