赞 | 8 |
VIP | 0 |
好人卡 | 0 |
积分 | 21 |
经验 | 11208 |
最后登录 | 2024-10-18 |
在线时间 | 664 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 2084
- 在线时间
- 664 小时
- 注册时间
- 2014-2-15
- 帖子
- 81
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 资深萝莉控 于 2017-12-24 19:01 编辑
影月千秋的脚本我看过了,我需要的是在每个商店那边设定的出售价格都不同的,也就是说,不是他那样只能调整所有的出售比例,而是每一个卖品在每一个商店有各自的卖价,这个比例不是一定的。就像Hime的shop manager 里面设定那样,不过她的脚本和我的真实商店会冲突。所以希望找一个类似的价格宏展。- #
- # 要使用的店主可以在整个购物过程中更改图形
- # 让他们笑或其他任何你的想象力认为的。
- # 它还增加了在此过程中为店主的谈话显示文本。
- #
- # 该脚本不包括图形供您使用。你需要创建
- #
- # 该脚本还可以跟踪的股票在不同的商店,即使你卖
- # 项目到店,这将增加该项目,以它的购买清单
- #
- #------------------------------------------------------------------------------#
- # INSTRUCTIONS:
- #------------------------------------------------------------------------------#
- # 把在材料与上述主要脚本
- # 图片进去 /Graphics/Pictures/ 文件夹中。
- #
- #------------------------------------------------------------------------------#
- # 脚本调用来改变图像
- #------------------------------------------------------------------------------#
- #
- # $game_system.shopkeeper = "ImageName" # 变化店主图像
- #
- # $game_system.shopback = "ImageName" # 更改背景图片
- #
- # $game_system.shop_windowskin = "ImageName" # Change windowskin for shop
- # # /Graphics/System/ folder
- #
- #------------------------------------------------------------------------------#
- # 高级脚本调用改变店主的谈话(x是设置的行)
- #------------------------------------------------------------------------------#
- #
- # $game_system.shop_talk[x] = "New shopkeeper saying here"
- #
- #------------------------------------------------------------------------------#
- # 我说这是先进的,是因为它是在微小的脚本callbox使用
- # 您可能需要使用额外的代码。下面的例子:
- #
- # $game_system.shop_talk[0] = "This will " +
- # "change the text for the initial welcome
- # message."
- #
- # 下面reasSee在店主TALK每个报价将被编号用在这里.
- #------------------------------------------------------------------------------#
- #------------------------------------------------------------------------------#
- # 脚本调用控制SHOP STOCK
- #------------------------------------------------------------------------------#
- #
- # shop(shop_id) # Use this script call to set the next shop processing event
- # # to be a certain shop number. If you do not use this script
- # # call before a shop event, the shop will not use stock.
- #
- # add_stock(shop_id,type,item_id,amount) # Add a number of items to the shop
- # # number you specify.
- #
- # rem_stock(shop_id,type,item_id,amount) # Remove a number of items from the
- # # shop number you specify.
- #
- # bulk_fill(shop_id,type,amount,[id,id,id]) # Add items to a shop in bulk.
- #
- #
- # # If you do NOT add an item as stock (using the above script call) to a shop
- # # that includes that item in the shop processing event - that item will be
- # # unlimited.
- #
- #------------------------------------------------------------------------------#
- # 上述脚本调用说明
- #------------------------------------------------------------------------------#
- # shop_id
- # This is a number you choose to use for a certain shop. You can use this
- # number for any shop anywhere and it will keep track of what items are sold
- # and bought from it. You can have as many different shop id's as you likd.
- #
- # type
- # 0 = an item 1 = a weapon 2 = an armor
- #
- # item_id or id
- # The id of the item/weapon/armor in your database.
- #
- # amount
- # How many of the item you wish to add or remove from the chosen shop id.
- #
- #------------------------------------------------------------------------------#
- # EXAMPLES
- #------------------------------------------------------------------------------#
- #
- # add_stock(2,0,1,20) # 将新增项目120至店数2
- # add_stock(6,1,10,2) # Will add 2 of weapon 10 to shop number 6
- # rem_stock(6,1,10,2) # Will remove 2 of weapon 10 from shop number 6
- #
- # bulk_fill(1,0,20,[1,2,3,4,5,6]) # Will add 20 of each item inside square
- # # brackets to shop number 1
- #
- # bulk_fill(3,2,1,[12,22,13]) # Will add 1 of each armor inside square
- # # brackets to shop number 3
- #
- # shop(3) # The next shop processing will use shop number 3
- #
- #------------------------------------------------------------------------------#
- #------------------------------------------------------------------------------#
- # NOTETAG for CLASS
- #------------------------------------------------------------------------------#
- #
- # <primary_params: x,y> # 武器和装甲paramater一类将使用
- # # 比较,如果该武器(x)或铠(y)为更好
- # # 对于演员的装备或不.
- #
- # 不包括本notetag的类将使用默认的2,3(ATK和DEF)
- #
- # 参数ID是:
- #
- # 0 - MaxHP 1 - MaxMP 2 - ATK 3 - DEF
- # 4 - MAT 5 - MDF 6 - AGI 7 - LUK
- #
- #------------------------------------------------------------------------------#
- ($imported ||= {})["Galvs_Shopkeepers"] = true
- module Galv_Shopkeeper
- #------------------------------------------------------------------------------#
- # SCRIPT SETTINGS
- #------------------------------------------------------------------------------#
- #-------------------#
- # SHOPKEEPER IMAGES #
- #-------------------#
-
- SHOPKEEPER_IMAGE = "shopkeeper"
-
- # Shopkeeper will change to an image using the current shopkeeper file name
- # with the below extentions added (eg. Graphics/Pictures/shopkeeper_happy.png)
-
- GREET = "_happy" # image extension greeting when you enter shop
- FAREWELL = "_happy" # image extension when you leave the shop
-
- BUY = "_happy" # image extension when you buy an item
- SELL = "_happy" # image extension when you sell an item
-
- DONT_BUY = "_annoyed" # image extension when you don't buy something
- DONT_SELL = "_annoyed" # image extension when you don't sell something
-
- CANT_BUY = "_annoyed" # image extension when you can't afford something
- CANT_SELL = "_annoyed" # image extension when you can't sell an item
- MAX_ITEMS = "_annoyed" # image extension when you can't hold more of an item
- SOLD_OUT = "_happy" # image extension when can't buy sold out item
-
- SHOW_DETAILS = "_happy" # image extension when show details window is open
- NO_DETAILS = "_annoyed" # image extension when no item when 'd' pressed
- #-------------------#
- # BACKGROUND IMAGE #
- #-------------------#
-
- SHOP_BACKGROUND = "shop_background" # background image behind shopkeeper
- BACKGROUND_SCROLL_X = 0 # speed background scroll horizontally
- BACKGROUND_SCROLL_Y = 0 # speed background scroll vertically
- WINDOWSKIN = "Window" # windowskin used by shop
- #-----------------#
- # SHOPKEEPER TALK #
- #-----------------#
-
- # These are defaults. You can change them using script calls during game.
-
- TALK = [ # don't touch
-
- "欢迎!商品都是很棒的哦!", # 0: when entering a shop
- "谢谢你的购买!!!", # 1: when purchase an item
- "你的物品也是不错的!.", # 2: when sell an item
- "你需要再看看其他商品么?", # 3: when in root menu after shopping
- "只是看看商品么?", # 4: when in root menu but didn't buy
- "你这是浪费我的时间还是什么?", # 5: when in root menu but didn't sell
- "对不起呢,你的金币不够的样子呢!", # 6: when try to buy too pricey item
- "我不能买这个...", # 7: when try to sell something you cant
- "你已经不能携带更多的这个商品了!",# 8: when try to buy when items maxed
- "谢谢, 欢迎下次再来购物!", # 9: when leaving a shop
- "这个无法查看详细信息的说!", # 10: when pressing 'd' on no item.
- "那些我们已经卖完了!", # 11: when item is sold out
-
- ] # don't touch
-
-
- #---------------#
- # OTHER OPTIONS #
- #---------------#
-
- ITEM_COUNT_TEXT = "所持金币" # Text that appears before item amount
- HOW_MANY_TEXT = "数量?" # Text for when determining how many
- STOCK_TEXT = "库存" # Text to display how many items in stock
- # only displays if a limit is set.
- NO_STOCK = "已经卖完" # Displayed if limit of 0 is reached
- STOCK_COLOR = 6 # 色股份文本。
-
- FRAME_TIME = 75 # time that above text and images stay active before
- # returning to default image and no talk.
- # (60 = 1 second)
-
- SALE_VAR = 1 # variable that controls sale price as a % of item's
- # price. Default is 50, use control variables to change
- # this during the game. Make this 0 to not use this
- # feature.
- DETAILS_KEY = :Z # :Z is "D". Press "D" in the shop to show the item
- # selected's details.
- D_IMAGE = "shop_detail" # The image used to show what key to press for details
- # This image goes in /Graphics/System/
- SE1 = ["Book2", 85, 100] # Sound effect played when opening details
- SE2 = ["Blow1", 85, 150] # Sound effect played when closing details
-
- ACTORS_SHOWN = 4 # Number of actors shown in the equip status window
- ACTORS_X = 15 # x position of first actor in the equip status window
- ACTORS_SPACE = 70 # space between each actor in equip status window
- # Settings to fit 6 actors here nicely are:
- # ACTORS_SHOWN = 6, ACTORS_X = 5, ACTORS_SPACE = 50
- #---------------#
- # EQUIP COMPARE #
- #---------------#
- SHOW_COMPARE_IMAGE = true # if true: shop will display only an image behind
- # the characters shown when viewing equipment
- SHOW_PARAM_CHANGE = true # shows by how much the primary parameter changes
-
- SHOW_PARAM_NAME = true # shows which paramater it is changing
- IMAGE_OVER = false # false: images are under the characters
- # true: images are on top of them.
- # Below images are taken from /Graphics/System/
- E_INCREASE = "shop_up" # Image displayed when equip is better
- E_DECREASE = "shop_down" # Image displayed when equip is worse
- E_SAME = "" # Image displayed when euqip is same
- #------------------------------------------------------------------------------#
- # END SCRIPT SETTINGS
- #------------------------------------------------------------------------------#
- end
- module Shop_Stock
- def check_stock(item)
- if item.is_a?(RPG::Item); itype = 0
- elsif item.is_a?(RPG::Weapon); itype = 1
- else; itype = 2; end
- return -1 if item.nil?
- return -1 if $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]].nil?
- if $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]] >= 0
- return $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]]
- else
- return -1
- end
- end
- end
- class Game_Interpreter
- def shop(shop_id)
- $game_system.shop_selected = shop_id
- end
-
- def add_stock(shop_id,type,item_id,amount)
- # type 0 = item, 1 = weapon, 2 = armor
- $game_system.shop_stock[shop_id] ||= {}
- $game_system.shop_stock[shop_id][[type,item_id]] ||= 0
- $game_system.shop_stock[shop_id][[type,item_id]] += amount
- end
-
- def rem_stock(shop_id,type,item_id,amount)
- # type 0 = item, 1 = weapon, 2 = armor
- return if $game_system.shop_stock[shop_id].nil?
- return if $game_system.shop_stock[shop_id][[type,item_id]].nil?
- $game_system.shop_stock[shop_id][[type,item_id]] -= amount
- if $game_system.shop_stock[shop_id][[type,item_id]] < 0
- $game_system.shop_stock[shop_id][[type,item_id]] = 0
- end
- end
-
- def reset_shop_settings
- $game_system.shopkeeper = Galv_Shopkeeper::SHOPKEEPER_IMAGE
- $game_system.shopback = Galv_Shopkeeper::SHOP_BACKGROUND
- $game_system.shop_windowskin = Galv_Shopkeeper::WINDOWSKIN
- $game_system.shop_talk = Array.new(Galv_Shopkeeper::TALK)
- end
-
- def bulk_fill(*args)
- array = [*args]
- shop_id = array[0]
- type = array[1]
- amount = array[2]
- ids = array[3]
-
- $game_system.shop_stock[shop_id] ||= {}
- ids.each do |i|
- $game_system.shop_stock[shop_id][[type,i]] ||= 0
- $game_system.shop_stock[shop_id][[type,i]] += amount
- end
- end
- end # Game_Interpreter
- class Game_System
- attr_accessor :shop_selected
- attr_accessor :shop_stock
- attr_accessor :shopback
- attr_accessor :shopkeeper
- attr_accessor :shop_talk
- attr_accessor :shop_spose
- attr_accessor :shop_windowskin
-
- alias galv_shopkeeper_system_initialize initialize
- def initialize
- galv_shopkeeper_system_initialize
- @shopback = Galv_Shopkeeper::SHOP_BACKGROUND
- @shopkeeper = Galv_Shopkeeper::SHOPKEEPER_IMAGE
- @shop_talk = Array.new(Galv_Shopkeeper::TALK)
- @shop_windowskin = Galv_Shopkeeper::WINDOWSKIN
- @shop_spose = nil
- @shop_selected = 0
- @shop_stock = {0=>{}}
- end
-
- end # Game_System
- class Scene_Shop < Scene_MenuBase
-
- alias galv_shopkeeper_scene_shop_prepare prepare
- def prepare(goods, purchase_only)
- galv_shopkeeper_scene_shop_prepare(goods, purchase_only)
- return if $game_system.shop_stock[$game_system.shop_selected].nil?
- stock_change
- end
-
- def stock_change
- temp_list = $game_system.shop_stock[$game_system.shop_selected].keys
- @goods.each do |i|
- if temp_list.include?([i[0],i[1]])
- temp_list.delete([i[0],i[1]])
- end
- end
- temp_list.each do |i|
- if $game_system.shop_stock[$game_system.shop_selected][[i[0],i[1]]] != 0
- @goods << [i[0],i[1],0,0]
- end
- end
- end
-
- alias galv_shopkeeper_scene_shop_start start
- def start
- galv_shopkeeper_scene_shop_start
- @shoptime = 0
- @has_shopped = false
- create_talk_window
- create_desc_window
- create_shop_background
- create_shopkeeper
- create_images
- @leave_shop = false
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::GREET) rescue Cache.picture($game_system.shopkeeper)
- @shoptime = Galv_Shopkeeper::FRAME_TIME
- end
-
- def create_desc_window
- b = @buy_window
- @desc_window = Window_ItemDesc.new(b.x, b.y, b.width, b.height)
- @desc_window.viewport = @viewport
- @desc_window.hide
- end
-
- def create_talk_window
- @talk_window = Window_Help.new
- @talk_window.viewport = @viewport
- @talk_window.set_text($game_system.shop_talk[0])
- @help_window.hide
- end
-
- def create_itemcount_window
- wy = @dummy_window.y
- ww = Graphics.width - 304
- wh = @gold_window.height
- @itemcount_window = Window_ItemCount.new(0, wy, ww, wh)
- @itemcount_window.viewport = @viewport
- @itemcount_window.hide
- end
-
- # OVERWRITE
- def create_dummy_window
- wy = @command_window.y + @command_window.height
- wh = Graphics.height - wy - @gold_window.height * 2
- @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
- @dummy_window.viewport = @viewport
- end
-
- # OVERWRITE
- def create_buy_window
- wy = @dummy_window.y
- wh = @dummy_window.height
- @buy_window = Window_ShopBuy.new(0, wy, wh, @goods)
- @buy_window.viewport = @viewport
- @buy_window.help_window = @help_window
- @buy_window.status_window = @status_window
- @buy_window.count_window = @itemcount_window
- @buy_window.desc_window = @desc_window
- @buy_window.hide
- @buy_window.set_handler(:ok, method(:on_buy_ok))
- @buy_window.set_handler(:cancel, method(:on_buy_cancel))
- @buy_window.x = Graphics.width - @buy_window.width
- end
-
- # OVERWRITE
- def create_sell_window
- wy = @category_window.y + @category_window.height
- wh = Graphics.height - wy
- @sell_window = Window_ShopSell.new(0, wy, @buy_window.width, wh)
- @sell_window.viewport = @viewport
- @sell_window.help_window = @help_window
- @sell_window.status_window = @itemcount_window
- @sell_window.hide
- @sell_window.set_handler(:ok, method(:on_sell_ok))
- @sell_window.set_handler(:cancel, method(:on_sell_cancel))
- @category_window.item_window = @sell_window
- @sell_window.x = Graphics.width - @buy_window.width
- end
-
- alias galv_shopkeeper_create_number_window create_number_window
- def create_number_window
- galv_shopkeeper_create_number_window
- @number_window.x = Graphics.width - @number_window.width
- end
-
- # OVERWRITE
- def create_status_window
- wx = @number_window.x
- wy = @dummy_window.y + @dummy_window.height
- ww = @number_window.width
- wh = Graphics.height - @dummy_window.height - @dummy_window.y
- @status_window = Window_ShopStatus.new(wx, wy, ww, wh)
- @status_window.viewport = @viewport
- @status_window.hide
- create_itemcount_window
- end
-
- alias galv_shopkeeper_create_dummy_window create_dummy_window
- def create_dummy_window
- galv_shopkeeper_create_dummy_window
- @dummy_window.hide
- end
-
- def create_shopkeeper
- @keeper = Sprite.new
- @keeper.bitmap = Cache.picture($game_system.shopkeeper)
- @keeper.y = Graphics.height - @keeper.bitmap.height
- end
-
- def create_images
- @dkey = Sprite.new
- @dkey.opacity = 0
- @dkey.bitmap = Cache.system(Galv_Shopkeeper::D_IMAGE) rescue Cache.system("")
- @dkey.y = Graphics.height - @dkey.bitmap.height
- end
-
- def create_shop_background
- @shopback = Plane.new
- @shopback.bitmap = Cache.picture($game_system.shopback)
- end
-
- alias galv_shopkeer_sell_on_category_ok on_category_ok
- def on_category_ok
- galv_shopkeer_sell_on_category_ok
- @dkey.opacity = 255
- end
-
- # OVERWRITE
- def on_category_cancel
- @command_window.activate
- @category_window.hide
- @sell_window.hide
- if @has_shopped == true
- @talk_window.set_text($game_system.shop_talk[3])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper)
- else
- @talk_window.set_text($game_system.shop_talk[5])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::DONT_SELL)
- end
- show_talk
- @has_shopped = false
- end
-
- # OVERWRITE
- def on_buy_cancel
- @command_window.activate
- @buy_window.hide
- @itemcount_window.hide
- @status_window.hide
- @status_window.item = nil
- @itemcount_window.item = nil
- @help_window.clear
- if @has_shopped == true
- @talk_window.set_text($game_system.shop_talk[3])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper)
- else
- @talk_window.set_text($game_system.shop_talk[4])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::DONT_BUY)
- end
- show_talk
- @has_shopped = false
- @dkey.opacity = 0
- end
- # OVERWRITE
- def on_sell_cancel
- @sell_window.unselect
- @category_window.activate
- @status_window.item = nil
- @itemcount_window.item = nil
- @itemcount_window.hide
- @help_window.clear
- @dkey.opacity = 0
- end
-
- alias galv_shopkeeper_command_buy command_buy
- def command_buy
- galv_shopkeeper_command_buy
- @keeper.bitmap = Cache.picture($game_system.shopkeeper)
- @itemcount_window.show
- hide_talk
- @dkey.opacity = 255
- @desc_window.y = @buy_window.y
- @desc_window.height = @buy_window.height
- end
-
- alias galv_shopkeeper_command_sell command_sell
- def command_sell
- galv_shopkeeper_command_sell
- @keeper.bitmap = Cache.picture($game_system.shopkeeper)
- hide_talk
- @desc_window.y = @sell_window.y
- @desc_window.height = @sell_window.height
- end
-
- alias galv_shopkeeper_do_buy do_buy
- def do_buy(number)
- @has_shopped = true
- galv_shopkeeper_do_buy(number)
- remove_stock(@item,number)
- @talk_window.set_text($game_system.shop_talk[1])
- show_talk
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::BUY) rescue Cache.picture($game_system.shopkeeper)
- @shoptime = Galv_Shopkeeper::FRAME_TIME
- end
-
- def remove_stock(item,number)
- return if $game_system.shop_stock[$game_system.shop_selected].nil? ||
- $game_system.shop_selected == 0
- if item.is_a?(RPG::Item); itype = 0
- elsif item.is_a?(RPG::Weapon); itype = 1
- else; itype = 2; end
- return if $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]].nil?
- $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]] -= number
- end
- alias galv_shopkeeper_do_sell do_sell
- def do_sell(number)
- @has_shopped = true
- galv_shopkeeper_do_sell(number)
- add_stock(@item,number)
- stock_change
- @talk_window.set_text($game_system.shop_talk[2])
- show_talk
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::SELL) rescue Cache.picture($game_system.shopkeeper)
- @shoptime = Galv_Shopkeeper::FRAME_TIME
- end
-
- def add_stock(item,number)
- return if $game_system.shop_selected == 0
- if item.is_a?(RPG::Item); itype = 0
- elsif item.is_a?(RPG::Weapon); itype = 1
- else; itype = 2; end
- @goods.each do |i|
- if i[0] == itype && i[1] == item.id && $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]].nil?
- return
- end
- end
- $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]] ||= 0
- $game_system.shop_stock[$game_system.shop_selected][[itype,item.id]] += number
- end
-
- # OVERWRITE
- def on_number_ok
- Sound.play_shop
- case @command_window.current_symbol
- when :buy
- do_buy(@number_window.number)
- when :sell
- do_sell(@number_window.number)
- @itemcount_window.hide
- end
- end_number_input
- @gold_window.refresh
- @status_window.refresh
- @itemcount_window.refresh
- @dkey.opacity = 255
- end
-
- alias galv_shopkeeper_on_number_cancel on_number_cancel
- def on_number_cancel
- galv_shopkeeper_on_number_cancel
- case @command_window.current_symbol
- when :sell
- @itemcount_window.hide
- end
- @dkey.opacity = 255
- end
- alias galv_shopkeeper_on_sell_ok on_sell_ok
- def on_sell_ok
- @number_window.trans = :sell
- galv_shopkeeper_on_sell_ok
- @itemcount_window.show
- @dkey.opacity = 0
- end
-
- alias galv_shopkeeper_on_buy_ok on_buy_ok
- def on_buy_ok
- @number_window.trans = :buy
- galv_shopkeeper_on_buy_ok
- @dkey.opacity = 0
- end
-
-
- def end_shopanim
- SceneManager.return if @leave_shop == true
- @keeper.bitmap = Cache.picture($game_system.shopkeeper)
- hide_talk unless @command_window.active
- end
-
- def show_talk
- @talk_window.show
- @help_window.hide
- end
-
- def hide_talk
- @talk_window.hide
- @help_window.show
- end
- def update
- super
- @shoptime -= 1
- end_shopanim if @shoptime == 0
- if @shoptime.odd?
- @shopback.ox += Galv_Shopkeeper::BACKGROUND_SCROLL_X
- @shopback.oy += Galv_Shopkeeper::BACKGROUND_SCROLL_Y
- end
- check_button
- other_poses if $game_system.shop_spose != nil
- end
-
- def check_button
- if @desc_window.visible
- if Input.trigger?(Galv_Shopkeeper::DETAILS_KEY) || Input.trigger?(:B)
- case @command_window.current_symbol
- when :buy
- @buy_window.show.activate
- when :sell
- @sell_window.show.activate
- end
- RPG::SE.new(Galv_Shopkeeper::SE2[0], Galv_Shopkeeper::SE2[1], Galv_Shopkeeper::SE2[2]).play
- @desc_window.hide
- @keeper.bitmap = Cache.picture($game_system.shopkeeper)
- end
- elsif @buy_window.active || @sell_window.active
- if Input.trigger?(Galv_Shopkeeper::DETAILS_KEY)
- case @command_window.current_symbol
- when :buy
- return if @buy_window.item.nil?
- @buy_window.hide.deactivate
- @desc_window.refresh(@buy_window.item,0)
- when :sell
- if @sell_window.item.nil?
- $game_system.shop_spose = 3
- return other_poses
- end
- @sell_window.hide.deactivate
- @desc_window.refresh(@sell_window.item,1)
- end
- @shoptime = 0
- RPG::SE.new(Galv_Shopkeeper::SE1[0], Galv_Shopkeeper::SE1[1], Galv_Shopkeeper::SE1[2]).play
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::SHOW_DETAILS) rescue Cache.picture($game_system.shopkeeper)
- hide_talk
- @desc_window.show
- end
- end
- end
-
- def other_poses
- case $game_system.shop_spose
- when 0
- @talk_window.set_text($game_system.shop_talk[6])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::CANT_BUY) rescue Cache.picture($game_system.shopkeeper)
- when 1
- @talk_window.set_text($game_system.shop_talk[7])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::CANT_SELL) rescue Cache.picture($game_system.shopkeeper)
- when 2
- @talk_window.set_text($game_system.shop_talk[8])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::MAX_ITEMS) rescue Cache.picture($game_system.shopkeeper)
- when 3
- @talk_window.set_text($game_system.shop_talk[10])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::NO_DETAILS) rescue Cache.picture($game_system.shopkeeper)
- when 4
- @talk_window.set_text($game_system.shop_talk[11])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::SOLD_OUT) rescue Cache.picture($game_system.shopkeeper)
- end
- show_talk
- @shoptime = Galv_Shopkeeper::FRAME_TIME
- $game_system.shop_spose = nil
- end
-
- def return_scene
- @talk_window.set_text($game_system.shop_talk[9])
- @keeper.bitmap = Cache.picture($game_system.shopkeeper + Galv_Shopkeeper::FAREWELL) rescue Cache.picture($game_system.shopkeeper)
- show_talk
- @shoptime = Galv_Shopkeeper::FRAME_TIME
- @leave_shop = true
- $game_system.shop_selected = 0
- end
-
- def terminate
- super
- @keeper.dispose
- @keeper.bitmap.dispose
- @shopback.dispose
- @dkey.bitmap.dispose
- @dkey.dispose
- end
-
- # OVERWRITE
- def selling_price
- if $game_variables[Galv_Shopkeeper::SALE_VAR] > 0
- ((@item.price * 0.01) * $game_variables[Galv_Shopkeeper::SALE_VAR]).round
- else
- @item.price / 2
- end
- end
-
- end # Scene_Shop < Scene_MenuBase
- class Scene_Title < Scene_Base
- alias galv_shopkeeper_command_new_game command_new_game
- def command_new_game
- galv_shopkeeper_command_new_game
- $game_variables[Galv_Shopkeeper::SALE_VAR] = 50 if $game_variables[Galv_Shopkeeper::SALE_VAR] > 0
- end
- end # Scene_Title < Scene_Base
- class Window_ItemCount < Window_Base
- def initialize(x, y, width, height)
- super(x, y, width, height)
- @item = nil
- refresh
- end
- def refresh
- contents.clear
- draw_possession(4, 0)
- end
- def item=(item)
- @item = item
- refresh
- end
- def draw_possession(x, y)
- rect = Rect.new(x, y, contents.width - 4 - x, line_height)
- change_color(system_color)
- draw_text(rect, Galv_Shopkeeper::ITEM_COUNT_TEXT)
- change_color(normal_color)
- draw_text(rect, $game_party.item_number(@item), 2)
- end
- end # Window_ItemCount < Window_Base
- class Window_ShopNumber < Window_Selectable
- attr_accessor :trans
- alias galv_shopkeeper_number_initialize initialize
- def initialize(x, y, height)
- galv_shopkeeper_number_initialize(x, y, height)
- @trans = :buy
- draw_how_many
- draw_stock
- end
-
- alias galv_shopkeeper_number_refresh refresh
- def refresh
- galv_shopkeeper_number_refresh
- draw_how_many
- draw_stock
- end
-
- def draw_how_many
- change_color(system_color)
- draw_text(4, 4, contents.width, line_height, Galv_Shopkeeper::HOW_MANY_TEXT)
- change_color(normal_color)
- end
-
- def draw_stock
- return if $game_system.shop_stock[$game_system.shop_selected].nil?
- @stock = check_stock(@item)
-
- if @stock > 0
- text = @stock.to_s + " " + Galv_Shopkeeper::STOCK_TEXT
- elsif @stock == 0
- text = Galv_Shopkeeper::NO_STOCK
- elsif @stock < 0
- text = ""
- end
- change_color(text_color(Galv_Shopkeeper::STOCK_COLOR))
- draw_text(4, 4, contents.width, line_height, text + " ",2) if @trans != :sell
- change_color(normal_color)
- end
-
- def change_number(amount)
- if @stock > 0; stock = @stock
- else stock = @max
- end
- if @trans == :buy
- @number = [[@number + amount, @max, stock].min, 1].max
- elsif @trans == :sell
- @number = [[@number + amount, @max].min, 1].max
- end
- end
-
- include Shop_Stock
-
- end # Window_ShopNumber < Window_Selectable
- class Window_ShopStatus < Window_Base
- alias galv_shopkeeper_window_status_initialize initialize
- def initialize(x, y, width, height)
- @walk = 0
- @step = 0 # 0 is left, 1 is right
- @animtime = 0
- @e_images = {}
- galv_shopkeeper_window_status_initialize(x, y, width, height)
- end
-
- # OVERWRITE
- def refresh
- contents.clear
- draw_equip_info(Galv_Shopkeeper::ACTORS_X + 5, 40) if @item.is_a?(RPG::EquipItem)
- end
-
- def update
- super
- @animtime += 1
- if @animtime == 10
- case @walk
- when 1; @walk -= 1
- when -1; @walk += 1
- when 0
- if @step == 1
- @walk = -1
- @step = 0
- else
- @walk = 1
- @step = 1
- end
- end
- refresh
- @animtime = 0
- end
- end
- # OVERWRITE
- def draw_equip_info(x, y)
- status_members.each_with_index do |actor, i|
- draw_actor_equip_info(x + (i * Galv_Shopkeeper::ACTORS_SPACE), y, actor)
- end
- end
- # OVERWRITE
- def page_size
- return Galv_Shopkeeper::ACTORS_SHOWN
- end
- # OVERWRITE
- def draw_actor_equip_info(x, y, actor)
- enabled = actor.equippable?(@item)
- change_color(normal_color, enabled)
- item1 = current_equipped_item(actor, @item.etype_id)
- if Galv_Shopkeeper::IMAGE_OVER
- draw_character(actor.character_name, actor.character_index, x + 10, y + 11, enabled)
- draw_actor_param_change(x - 10, y + 10, actor, item1) if enabled
- else
- draw_actor_param_change(x - 10, y + 10, actor, item1) if enabled
- draw_character(actor.character_name, actor.character_index, x + 10, y + 11, enabled)
- end
- if Galv_Shopkeeper::SHOW_PARAM_NAME
- draw_text(x - 8, y - 40, 40, line_height, Vocab::param(@p_id),1) if enabled
- end
- end
- def draw_character(character_name, character_index, x, y,enabled)
- return unless character_name
- bitmap = Cache.character(character_name)
- sign = character_name[/^[\!\$]./]
- if sign && sign.include?('$')
- cw = bitmap.width / 3
- ch = bitmap.height / 4
- else
- cw = bitmap.width / 12
- ch = bitmap.height / 8
- end
- n = character_index
- step = 0
- step = @walk if enabled
- src_rect = Rect.new((n%4*3+1+step)*cw, (n/4*4)*ch, cw, ch)
- contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
- end
- # OVERWRITE
- def draw_actor_param_change(x, y, actor, item1)
- @p_id = pid(actor.class_id)
- rect = Rect.new(x, y - 2, 40, line_height)
- change = @item.params[@p_id] - (item1 ? item1.params[@p_id] : 0)
- change_color(param_change_color(change))
- draw_e_image(rect.x,rect.y,actor.id,change) if Galv_Shopkeeper::SHOW_COMPARE_IMAGE
- contents.font.size = 20
- draw_text(rect, sprintf("%+d", change), 1) if Galv_Shopkeeper::SHOW_PARAM_CHANGE
- contents.font.size = 20
- end
-
- def pid(cid)
- primary_param = $data_classes[cid].primary_params
- @item.is_a?(RPG::Weapon) ? type = primary_param[0] : primary_param[1]
- end
-
- def draw_e_image(x,y,actor_id,change)
- if change > 0
- bitmap = Cache.system(Galv_Shopkeeper::E_INCREASE)
- elsif change < 0
- bitmap = Cache.system(Galv_Shopkeeper::E_DECREASE)
- else
- bitmap = Cache.system(Galv_Shopkeeper::E_SAME)
- end
- src_rect = Rect.new(0, 0, 100, 100)
- contents.blt(x, 0, bitmap, src_rect)
- end
-
-
-
-
- end # Window_ShopStatus < Window_Base
- class Window_ShopBuy < Window_Selectable
-
- # OVERWRITE
- def initialize(x, y, height, shop_goods)
- super(x, y, window_width, height)
- @shop_goods = shop_goods
- @money = 0
- @max_items_reached = false
- refresh
- select(0)
- end
-
- def count_window=(count_window)
- @count_window = count_window
- end
-
- def desc_window=(desc_window)
- @desc_window = desc_window
- end
- # OVERWRITE
- def update_help
- @help_window.set_item(item) if @help_window
- @status_window.item = item if @status_window
- @count_window.item = item if @count_window
- @desc_window.item = item if @desc_window
- end
-
- # OVERWRITE
- def current_item_enabled?
- if $game_party.item_max?(item)
- @max_items_reached = true
- else
- @max_items_reached = false
- end
- if check_stock(item) == 0
- @item_sold_out = true
- else
- @item_sold_out = false
- end
- enable?(@data[index])
- end
-
- def enable?(item)
- item && price(item) <= @money && !$game_party.item_max?(item) &&
- check_stock(item) != 0
- end
-
- # OVERWRITE
- def draw_item(index)
- item = @data[index]
- stock = check_stock(item)
- rect = item_rect(index)
- draw_item_name(item, rect.x, rect.y, enable?(item))
- rect.width -= 4
- if stock == 0
- draw_text(rect, Galv_Shopkeeper::NO_STOCK, 2)
- else
- draw_text(rect, price(item), 2)
- end
- end
-
- def process_ok
- if current_item_enabled?
- Sound.play_ok
- Input.update
- deactivate
- call_ok_handler
- else
- if @item_sold_out == true
- $game_system.shop_spose = 4
- elsif @max_items_reached == false
- $game_system.shop_spose = 0
- else
- $game_system.shop_spose = 2
- end
- Sound.play_buzzer
- end
- end
-
- include Shop_Stock
-
- end # class Window_ShopBuy < Window_Selectable
- class Window_ShopSell < Window_ItemList
- def col_max
- return 1
- end
-
- def process_ok
- if current_item_enabled?
- Sound.play_ok
- Input.update
- deactivate
- call_ok_handler
- else
- $game_system.shop_spose = 1
- Sound.play_buzzer
- end
- end
-
- def status_window=(status_window)
- @status_window = status_window
- end
- def update_help
- @help_window.set_item(item) if @help_window
- @status_window.item = item if @status_window
- end
- end # Window_ShopSell < Window_ItemList
- class Window_ItemDesc < Window_Base
- def initialize(x, y, width, height)
- super(x, y, width, height)
- @item = nil
- @shop_type = 0
- end
-
- def refresh(item,type)
- @item = item
- contents.clear
- return if item.nil?
- @shop_type = type
- draw_item_name(@item, 0, 0)
- draw_currency_value(get_price, Vocab::currency_unit, 0, 0, contents.width)
- equip_stats if @item.is_a?(RPG::EquipItem)
- item_stats if @item.is_a?(RPG::Item)
- end
-
- def get_price
- if @shop_type == 0
- return @item.price
- else
- if $game_variables[Galv_Shopkeeper::SALE_VAR] > 0
- return ((@item.price * 0.01) * $game_variables[Galv_Shopkeeper::SALE_VAR]).round
- else
- return @item.price / 2
- end
- end
- end
- def stat_col
- contents.width / 2
- end
-
- def equip_stats
- y_offset = -15
- draw_equip_stats(0, line_height * 2 + y_offset, 0) # HP
- draw_equip_stats(stat_col, line_height * 2 + y_offset, 1) # MP
- draw_equip_stats(0, line_height * 3 + y_offset, 2) # ATK
- draw_equip_stats(stat_col, line_height * 3 + y_offset, 3) # DEF
- draw_equip_stats(0, line_height * 4 + y_offset, 4) # MAT
- draw_equip_stats(stat_col, line_height * 4 + y_offset, 5) # MDF
- draw_equip_stats(0, line_height * 5 + y_offset, 6) # AGI
- draw_equip_stats(stat_col, line_height * 5 + y_offset, 7) # LUK
- draw_icons(100, line_height * 6 , width = 96) # States
- end
-
- def item=(item)
- @item = item
- refresh
- end
-
- def draw_equip_stats(x, y, param_id)
- draw_param_name(x + 4, y, param_id)
- draw_param(x + 94, y, param_id)
- end
-
- def draw_icons(x, y, width = 96)
- icons = [] # atk
- icons2 = [] # resistances
- @item.features.each do |f|
- if f.code == 32
- icons << $data_states[f.data_id].icon_index
- elsif f.code == 14
- icons2 << $data_states[f.data_id].icon_index
- end
- end
- if icons != []
- change_color(system_color)
- draw_text(0, line_height * 6, 120, line_height, "Inflicts")
- change_color(normal_color)
- icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) }
- elsif icons2 != []
- change_color(system_color)
- draw_text(0, line_height * 6, 120, line_height, "Resists")
- change_color(normal_color)
- icons2.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) }
- end
- end
- def draw_param_name(x, y, param_id)
- change_color(system_color)
- draw_text(x, y, 80, line_height, Vocab::param(param_id))
- end
-
- def draw_param(x, y, param_id)
- if @item.params[param_id] > 0
- change_color(power_up_color)
- elsif @item.params[param_id] < 0
- change_color(power_down_color)
- else
- change_color(normal_color)
- end
- draw_text(x, y, 32, line_height, @item.params[param_id].to_s, 2)
-
- end
- def item_stats
- x = 0
- y = 0
- line = 1
- y_offset = 15
- width = contents.width
- rem_states = []
- add_states = []
- add_buffs = []
- rem_buffs = []
-
- if @item.damage.type != 0
- change_color(system_color)
- case @item.damage.type
- when 1; vocab = Vocab::hp_a + " Damage"
- when 2; vocab = Vocab::mp_a + " Damage"
- when 3; vocab = Vocab::hp_a + " Restore"
- when 4; vocab = Vocab::mp_a + " Restore"
- when 5; vocab = Vocab::hp_a + " Drain"
- when 6; vocab = Vocab::mp_a + " Drain"
- end
- draw_text(0, line_height * line + y_offset, width, line_height, vocab, 0)
- change_color(normal_color)
- draw_text(0, line_height * line + y_offset, width, line_height, @item.damage.formula.to_s, 2)
- line += 1
- end
-
- @item.effects.each do |e|
- next if line == 6
- change_color(system_color)
- case e.code
- when 11; vocab = Vocab::hp_a; vocab2 = Vocab::hp
- when 12; vocab = Vocab::mp_a; vocab2 = Vocab::mp
- when 13; vocab = Vocab::tp_a; vocab2 = Vocab::tp
- end
-
- case e.code
- when 11, 12
- draw_text(0, line_height * line + y_offset, width, line_height, vocab + " (" + vocab2 + ")", 0)
- v1 = (e.value1 * 100).to_i
- v2 = e.value2.to_i
- if e.value1 == 0
- check_color(v2)
- draw_text(0, line_height * line + y_offset, width, line_height, v2.to_s, 2)
- elsif e.value2 == 0
- check_color(v1)
- draw_text(0, line_height * line + y_offset, width, line_height, v1.to_s + "%", 2)
- else
- check_color(v1)
- draw_text(0, line_height * line + y_offset, width, line_height, v2.to_s + " + " + v1.to_s + "%", 2)
- end
- line += 1
- when 13
- draw_text(0, line_height * line + y_offset, width, line_height, vocab + " (" + vocab2 + ")", 0)
- check_color(e.value1)
- draw_text(0, line_height * line + y_offset, width, line_height, e.value1.to_i.to_s + "%", 2)
- line += 1
- when 21
- #add state
- add_states << e.data_id unless e.data_id == 0
- when 22
- #remove state
- rem_states << e.data_id unless e.data_id == 0
- when 31, 32
- #add buff/debuffs
- add_buffs << (64 + e.data_id) if e.code == 31
- add_buffs << (64 + e.data_id + 16) if e.code == 32
- when 33, 34
- rem_buffs << (64 + e.data_id) if e.code == 33
- rem_buffs << (64 + e.data_id + 16) if e.code == 34
- when 42
- #grow stat
- change_color(system_color)
- name = $data_system.terms.params[e.data_id] + " Increase"
- draw_text(0, line_height * line + y_offset, width, line_height, name, 0)
- change_color(normal_color)
- draw_text(0, line_height * line + y_offset, width, line_height, e.value1.to_i.to_s, 2)
- line += 1
- when 43
- #learn skill
- change_color(system_color)
- skill = $data_skills[e.data_id].name
- draw_text(0, line_height * line + y_offset, width, line_height, "Learn", 0)
- change_color(normal_color)
- draw_text(0, line_height * line + y_offset, width, line_height, skill, 2)
- line += 1
- end
- end
-
- if add_states != [] && line < 6 || add_buffs != [] && line < 6
- x = 90
- icons = []
- add_states.each do |s|
- icons << $data_states[s].icon_index
- end
- add_buffs.each do |b|
- icons << b
- end
- change_color(system_color)
- draw_text(0, line_height * line + y_offset, width, line_height, "Applies")
- change_color(normal_color)
- icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, line_height * line + y_offset) }
- line += 1
- end
-
- if rem_states != [] && line < 6 || rem_buffs != [] && line < 6
- x = 90
- icons2 = []
- rem_states.each do |s|
- icons2 << $data_states[s].icon_index
- end
- rem_buffs.each do |b|
- icons2 << b
- end
- change_color(system_color)
- draw_text(0, line_height * line + y_offset, width, line_height, "Removes")
- change_color(normal_color)
- icons2.each_with_index {|n, i| draw_icon(n, x + 24 * i, line_height * line + y_offset) }
- line += 1
- end
- end
-
- def check_color(amount)
- if amount < 0
- change_color(power_down_color)
- else
- change_color(normal_color)
- end
- end
- end # Window_ItemDesc < Window_Base
- class Window_Base < Window
- alias galv_shopkeeper_windowbase_initialize initialize
- def initialize(x, y, width, height)
- galv_shopkeeper_windowbase_initialize(x, y, width, height)
- if SceneManager.scene_is?(Scene_Shop)
- self.windowskin = Cache.system($game_system.shop_windowskin)
- end
- end
- end # Window_Base < Window
- class RPG::Class
- def primary_params
- if @primary_params.nil?
- if @note =~ /<primary_params:[ ](.*),(.*)>/i
- @primary_params = [$1.to_i,$2.to_i]
- else
- @primary_params = [2,3]
- end
- end
- @primary_params
- end
- end # RPG::Class
- #------------------------------------------------------------------------------#
- # COMPATABILITY PATCH FOR YANFLY'S EQUIP DYNAMIC STATS SCRIPT
- #------------------------------------------------------------------------------#
- # If you don't use this script from Yanfly, you can remove this. #
- #------------------------------------------------------------------------------#
- if $imported["YEA-EquipDynamicStats"]
- class Window_ShopStatus < Window_Base
- def draw_actor_param_change(x, y, actor, item1)
- rect = Rect.new(x, y, 40, line_height)
- change = actor_param_change_value(actor, item1)
- change_color(param_change_color(change))
- text = change.group
- text = "+" + text if change >= 0
- draw_text(rect, sprintf("%+d", change), 1)
- end
- end # Window_ShopStatus
- class Window_ItemDesc < Window_Base
- def draw_equip_stats(x, y, param_id)
- draw_param_name(x + 4, y, param_id)
- draw_param(x + 30, y, param_id)
- end
-
- def draw_param(x, y, param_id)
- a = @item.params[param_id] + $game_variables[@item.var_params[param_id]]
- b = @item.per_params[param_id]
- if a > 0 || b > 0; change_color(power_up_color)
- elsif a < 0 || b < 0; change_color(power_down_color)
- else; change_color(normal_color); end
- a != 0 && b != 0 ? plus = "+" : plus = ""
- if b != 0; perc = "%"; b = (b *= 100).to_i.to_s; else; perc = ""; b = ""; end
- if b == "" && a == 0; a = 0; elsif b != "" && a == 0; a = ""; end
- draw_text(x, y, 100, line_height, a.to_s + plus + b.to_s + perc, 2)
- end
- end # Window_ItemDesc < Window_Base
- end
复制代码- =begin
- #===============================================================================
- Title: Shop Manager
- Author: Hime
- Date: Aug 4, 2014
- --------------------------------------------------------------------------------
- ** Change log
- 2.3 Aug 4, 2014
- - added shop ID's
- 2.2 Apr 9, 2014
- - fixed bug where calling a common event causes all shops to call wrong shop
- 2.1 Apr 1, 2014
- - fixed bug where game crashes after loading from an event save
- 2.0 Mar 12, 2014
- - added support for custom sell prices for each shop
- 1.9 Dec 2, 2013
- - fixed bug where shop common event ID was not cleared out properly
- 1.81 Nov 21, 2013
- - game shops are initialized on game load if necessary
- 1.8 Nov 20, 2013
- - Game_ShopGood formulas are evaluated in the context of the interpreter
- 1.7 Oct 24, 2013
- - added `add_shop_good` script call to add shop goods programmatically
- - added "price formulas" to specify a good's price using a formula
- 1.6 Oct 15, 2013
- - removed page refreshing. It doesn't work.
- 1.5 Mar 29, 2013
- - added simple shop refreshing on page change. Will need a better solution
- since this does not track the state of a shop on a different page
- 1.4 Mar 13, 2013
- - fixed bug where common event shops were not handled appropriately when
- called through effects
- 1.3 Mar 1, 2013
- - Game_ShopGood now determines whether it should be included or enabled
- - Two shop options implemented: hidden, disabled
- 1.2 Feb 25
- - fixed issue where common event shops were not handled correctly
- - exposed Shop Good variables as readers
- 1.1
- - ShopManager handles shop scene changing depending on the type of shop
- - added handling for different "types" of shops
- - all goods in a shop can be accessed via shop.shop_goods
- - reference to shop added to shop scene
- - added support for adding and removing goods from a shop
- 1.0 Feb 22, 2013
- - Initial Release
- --------------------------------------------------------------------------------
- ** Terms of Use
- * Free to use in non-commercial projects
- * Contact me for commercial use
- * No real support. The script is provided as-is
- * Will do bug fixes, but no compatibility patches
- * Features may be requested but no guarantees, especially if it is non-trivial
- * Credits to Hime Works in your project
- * Preserve this header
- --------------------------------------------------------------------------------
- ** Description
-
- This script enhances the game shop, providing useful options that allow you
- to customize each shop good individually.
- This script provides functionality for remembering a shop’s “state”. Each
- shop is uniquely identified by a shop ID, and if you visit the same shop
- repeatedly, you should see the same settings.
- For example, if a shop holds 10 potions, and you bought 5, then you can
- expect that the next time you visit the shop, it will only have 5 potions
- remaining.
- Of course, you will need extra plugins to have that kind of functionality.
-
- In summary:
- -more control over your shops
- -simple API for developers to write shop-related scripts
-
- --------------------------------------------------------------------------------
- ** Usage
-
- This script provides a number of built-in shop options for you to customize your shop goods for each shop.
- Each shop option requires you to pass in a “good ID”, which is basically the order that the items appear in your “shop processing” list. The shop good at the top of the list has a good ID of 1, the next has a good ID of 2, and so on.
- All shop options must be set before the shop processing command.
- The following variables are available for all formulas:
- v - game variables
- s - game switches
- p - game party
-
- -- Hiding Goods --
- You can prevent a shop good from appear in the shop list by using a
- “hide formula”. To set a hide formula for a particular good, use the
- script call
-
- hide_good(good_id, hide_formula)
- -- Disabling Goods --
- Disabling a shop good means the player can’t buy it, but it will still appear
- on the list. The default windows simply change the color of the good to
- indicate that it can’t be selected. You can disable a shop good using a
- “disable formula”, and can be set using the script call
- disable_good(good_id, hide_formula)
- -- Price Formulas --
- Each shop good can have a custom price by defining a “price formula”. The
- price is evaluated when the player visits the shop, so it is dynamically
- generated based on the current game state.
-
- To set a price formula, use the script call
- price_good(good_id, price_formula)
-
- -- Selling price formulas --
-
- You can specify the selling price of all items for a particular shop.
- To set the selling price, use the script call
-
- sell_price(item_string, price_formula)
-
- The item string uses the following format:
-
- i2 - item ID 2
- w4 - weapon ID 4
- a12 - armor ID 12
-
- If the sell price is not specified, then it is assumed to be half the
- buy price.
-
- --------------------------------------------------------------------------------
- ** Developers
-
- Here are some specifications that I have written.
-
- Have a look through each class to see what is available for use.
- If you have any suggestions that will improve the base script (ie: this),
- I will consider adding them.
-
- -- Shop Manager --
-
- This module serves are the interface for all shop-related queries. It handles
- how shops are stored for you so that it is easy to properly obtain a reference
- to a shop.
-
- You should use the Shop Manager whenever possible.
-
- -- Game Shop --
-
- This script treats a shop as a concrete object. A shop is created the first
- time it is accessed, and will be stored with the game for the remainder of
- the game.
-
- A very basic shop is provided, which manages what items are available for sale.
- All shops are stored in a global Game_Shops hash in $game_shops
-
- -- Shop Type --
-
- On top of the basic Game_Shop class, you can define your own shops and
- associate them with custom scenes specific to those shops.
-
- The Shop Manager only requires you to be consistent with your shop name.
- For example, if your shop type is "CraftShop", then you must define a
-
- Game_CraftShop - the shop object that the shop will be instantiated with
- Scene_CraftShop - the scene that will be called when visiting a CraftShop
-
- Users will set a @shop_type attribute in Game_Interpreter to determine
- what type of shop should be created
-
- -- Managing shops --
-
- This script assumes shops are only called through events or common events.
- Troop events are not supported.
-
- A shop is identified by a map ID and an event ID.
- Shops that are called via common events will have a map ID of 0.
-
- In order to determine whether a normal event or a common event called the
- shop, the "depth" of the interpreter is used.
-
- When depth = 0, then it is a normal event
- When depth > 0, then it is a common event
-
- The shop processing should be handled appropriately depending on the depth
-
- This script assumes that an event is triggered through "normal" interaction;
- that is, you can only interact with events within a map. Any events that should
- be treated as the same event should be done as a common event call.
-
- --- Shop Goods ---
-
- Rather than storing all goods as a simple array of values, this script
- provides a Game_ShopGood class. You can use this to store any additional
- information that you want.
-
- All shop related scenes and windows MUST provide support for handling shop
- goods. While backwards compatibility is provided for the default scripts,
- additional methods have been defined to allow you to retrieve the currently
- selected shop good.
-
- --- Shop Options ---
-
- Since there isn't actually a way to setup individual shop goods, external
- approaches must be used. There is not much specification here yet, so it
- is up to you how you wish to populate your ShopGood objects. I have provided
- a "setup_goods" method in Game_Interpreter that you can alias.
-
- --------------------------------------------------------------------------------
- ** Compatibility
-
- This script changes the following from the default scripts
-
- DataManager
- aliased - create_game_objects
- aliased - make_save_contents
- aliased - extract_save_contents
- Game_Interpreter
- replaced - command_302
- Window_ShopBuy
- replaced - prepare
- Scene_Shop
- replaced - make_item_list
- #===============================================================================
- =end
- $imported = {} if $imported.nil?
- $imported["TH_ShopManager"] = 2.4
- #===============================================================================
- # ** Rest of the Script
- #===============================================================================
- #-------------------------------------------------------------------------------
- # Main shop manager that acts as the interface between shops and other objects
- # The main role of the ShopManager is to essentially manage any shop objects
- # that exist in the game. In particular, it provides all of the methods for
- # creating, retrieving, and deleting shops.
- #-------------------------------------------------------------------------------
- module ShopManager
-
- #-----------------------------------------------------------------------------
- # Return a reference to a specific shop
- #-----------------------------------------------------------------------------
- def self.get_shop(shop_id)
- return $game_shops[shop_id]
- end
-
- #-----------------------------------------------------------------------------
- # Indicate that a shop needs to be refreshed
- #-----------------------------------------------------------------------------
- def self.refresh_shop(shop_id)
- shop = get_shop(shop_id)
- shop.need_refresh = true if shop
- end
-
- #-----------------------------------------------------------------------------
- # Setup shop if first time visiting
- #-----------------------------------------------------------------------------
- def self.setup_shop(shop_id, goods, purchase_only, shop_type)
- shop = get_shop(shop_id)
- return shop if shop && !shop.need_refresh
- shop = shop_class(shop_type).new(goods, purchase_only)
- $game_shops[shop_id] = shop
- return shop
- end
-
- #-----------------------------------------------------------------------------
- # Return the appropriate shop class given the shop type
- #-----------------------------------------------------------------------------
- def self.shop_class(shop_type)
- shop_type = "Game_" + shop_type.to_s
- return Object.const_get(shop_type.to_sym)
- end
-
- #-----------------------------------------------------------------------------
- # Return the scene associated with this shop.
- # TO DO
- #-----------------------------------------------------------------------------
- def self.shop_scene(shop)
- shop_scene = "Scene_" + shop.class.name.gsub("Game_", "")
- return Object.const_get(shop_scene.to_sym)
- end
-
- #-----------------------------------------------------------------------------
- # Invokes SceneManager.call on the appropriate scene
- #-----------------------------------------------------------------------------
- def self.call_scene(shop)
- SceneManager.call(shop_scene(shop))
- SceneManager.scene.prepare(shop)
- end
-
- #-----------------------------------------------------------------------------
- # Invokes SceneManager.goto on the appropriate scene
- #-----------------------------------------------------------------------------
- def self.goto_scene(shop)
- SceneManager.goto(shop_scene(shop))
- SceneManager.scene.prepare(shop)
- end
-
- #-----------------------------------------------------------------------------
- # Returns a good ID, given a shop and an item. If the item is already in
- # the shop, it will return that good's ID. Otherwise, it will return a new ID
- #-----------------------------------------------------------------------------
- def self.get_good_id(shop, item)
- good = shop.shop_goods.detect {|good| good.item == item}
- return good.nil? ? shop.shop_goods.size + 1 : good.id
- end
-
- #-----------------------------------------------------------------------------
- # Returns a good, given a shop and an item. If the shop already has that good
- # just return it. Otherwise, make a new good. If the price is negative, then
- # the price is the default price. Otherwise, it is the specified price.
- #-----------------------------------------------------------------------------
- def self.get_good(shop, item, price=-1)
- good = shop.shop_goods.detect {|good| good.item == item}
- return good if good
- good_id = shop.shop_goods.size + 1
- type = item_type(item)
- if price < 0
- price_type = price = 0
- else
- price_type = 1
- end
- return Game_ShopGood.new(good_id, type, item.id, price_type, price)
- end
-
- #-----------------------------------------------------------------------------
- # Returns the type of an item.
- #-----------------------------------------------------------------------------
- def self.item_type(item)
- return 0 if item.is_a?(RPG::Item)
- return 1 if item.is_a?(RPG::Weapon)
- return 2 if item.is_a?(RPG::Armor)
- return -1
- end
- end
- #-------------------------------------------------------------------------------
- # Shops are stored in a global variable `$game_shops`. This is dumped and
- # loaded appropriately.
- #-------------------------------------------------------------------------------
- module DataManager
-
- class << self
- alias :th_shop_manager_create_game_objects :create_game_objects
- alias :th_shop_manager_make_save_contents :make_save_contents
- alias :th_shop_manager_extract_save_contents :extract_save_contents
- end
-
- def self.create_game_objects
- th_shop_manager_create_game_objects
- $game_shops = Game_Shops.new
- end
-
- def self.make_save_contents
- contents = th_shop_manager_make_save_contents
- contents[:shops] = $game_shops
- contents
- end
-
- #-----------------------------------------------------------------------------
- # Load shop data
- #-----------------------------------------------------------------------------
- def self.extract_save_contents(contents)
- th_shop_manager_extract_save_contents(contents)
- $game_shops = contents[:shops] || Game_Shops.new
- end
- end
- class Game_Temp
-
- # even if we're not actually calling a shop, it shouldn't affect anything
- # because we are always setting this at each common event call by an event
- attr_accessor :shop_common_event_id
-
- alias :th_shop_manager_reserve_common_event :reserve_common_event
- def reserve_common_event(common_event_id)
- th_shop_manager_reserve_common_event(common_event_id)
- @shop_common_event_id = common_event_id
- end
-
- alias :th_shop_manager_clear_common_event :clear_common_event
- def clear_common_event
- th_shop_manager_clear_common_event
- clear_shop_event_id
- end
-
- def clear_shop_event_id
- @shop_common_event_id = nil
- end
- end
- class Game_Interpreter
-
- alias :th_shop_manager_initialize :initialize
- def initialize(*args)
- @shop_common_event_id = $game_temp.shop_common_event_id if $game_temp
- th_shop_manager_initialize(*args)
- end
-
- alias :th_shop_manager_clear :clear
- def clear
- th_shop_manager_clear
- clear_shop_options
- @custom_goods = {}
- @shop_type = nil
- @shop_id = nil
- end
-
- def shop_options
- return @shop_options if @shop_options
- clear_shop_options
- return @shop_options
- end
-
- def custom_goods
- @custom_goods ||= {}
- end
-
- #-----------------------------------------------------------------------------
- # New.
- #-----------------------------------------------------------------------------
- def clear_shop_options
- @shop_options = {}
- @shop_options[:hidden] = {}
- @shop_options[:disabled] = {}
- @shop_options[:price] = {}
- @shop_options[:sell_price] = {}
- end
-
- #-----------------------------------------------------------------------------
- # New. We are in a common event only if the shop common event ID is set.
- #-----------------------------------------------------------------------------
- def shop_map_id
- @shop_common_event_id ? 0 : @map_id
- end
-
- def shop_event_id
- @shop_common_event_id ? @shop_common_event_id : @event_id
- end
-
- #-----------------------------------------------------------------------------
- # Set the shop's common event ID so that the child interpreter can pick it
- # up. Then clear it out
- #-----------------------------------------------------------------------------
- alias :th_shop_manager_command_117 :command_117
- def command_117
- $game_temp.shop_common_event_id = @params[0]
- th_shop_manager_command_117
- $game_temp.clear_shop_event_id
- end
-
- #-----------------------------------------------------------------------------
- # Replaced. A shop is setup only once, and is retrieved whenever it is
- # called in the future. This assumes the shop is invoked through "normal"
- # event interactions.
- #-----------------------------------------------------------------------------
- def command_302
- return if $game_party.in_battle
- shop_type = @shop_type || :Shop
-
- # load goods
- goods = load_all_goods
-
- shop_id = @shop_id || [shop_map_id, shop_event_id]
-
- # Setup shop if needed
- shop = ShopManager.setup_shop(shop_id, goods, @params[4], shop_type)
- setup_shop(shop)
-
- # prepare the shop with a reference to the actual shop
- ShopManager.call_scene(shop)
- Fiber.yield
- end
-
- def load_all_goods
- good_id = 1
- goods = []
- # setup goods
- good = make_good(@params[0..-1], good_id) # last param is for the shop
- goods.push(good)
- good_id +=1
-
- while next_event_code == 605
- @index += 1
- good = make_good(@list[@index].parameters, good_id)
- goods.push(good)
- good_id +=1
- end
- goods.concat(load_custom_goods)
- return goods
- end
-
- #-----------------------------------------------------------------------------
- # Goods that should be added to the shop, but are not added through the
- # shop editor (eg: script calls)
- #-----------------------------------------------------------------------------
- def load_custom_goods
- goods = []
- custom_goods.each do |id, goods_array|
- good = make_good(goods_array, id)
- goods.push(good)
- end
- return goods
- end
-
- #-----------------------------------------------------------------------------
- # New. This is where the goods are setup.
- #-----------------------------------------------------------------------------
- def make_good(goods_array, good_id)
- item_type, item_id, price_type, price = goods_array
- good = Game_ShopGood.new(good_id, item_type, item_id, price_type, price)
-
- # additional setup
- setup_good(good, good_id)
- return good
- end
-
- #-----------------------------------------------------------------------------
- # New. Adds a shop good to the list of goods. Note that you must check
- # that ID of the shop good is unique. I will not generate an ID automatically
- # because otherwise you'd have no way of applying shop options to it
- #-----------------------------------------------------------------------------
- def add_shop_good(good_id, item_type, item_id, price=nil)
- if item_type == :item
- item_type = 0
- elsif item_type == :weapon
- item_type = 1
- elsif item_type == :armor
- item_type = 2
- end
- price_type = price ? 1 : 0
- custom_goods[good_id] = [item_type, item_id, price_type, price]
- end
-
- def get_shop(id)
- @shop_id = id
- end
-
- def setup_shop(shop)
- setup_sell_prices(shop)
- end
-
- def setup_sell_prices(shop)
- shop_options[:sell_price].each do |item_str, formula|
- type, id = item_str[0].downcase, item_str[1..-1].to_i
- case type
- when "i"
- item = $data_items[id]
- when "w"
- item = $data_weapons[id]
- when "a"
- item = $data_armors[id]
- end
- shop.set_sell_price(item, formula)
- end
- end
-
- #-----------------------------------------------------------------------------
- # New. You can do more things with your good here
- #-----------------------------------------------------------------------------
- def setup_good(good, good_id)
- setup_hidden_option(good, good_id)
- setup_disabled_option(good, good_id)
- setup_price_option(good, good_id)
- end
-
- #-----------------------------------------------------------------------------
- # New. Shop options
- #-----------------------------------------------------------------------------
- def price_good(good_id, price_formula)
- shop_options[:price][good_id] = price_formula
- end
-
- def hide_good(good_id, condition)
- shop_options[:hidden][good_id] = condition
- end
-
- def disable_good(good_id, condition)
- shop_options[:disabled][good_id] = condition
- end
-
- def sell_price(item_str, price_formula)
- shop_options[:sell_price][item_str] = price_formula
- end
-
- #-----------------------------------------------------------------------------
- # New. Apply shop option to the goods
- #-----------------------------------------------------------------------------
- def setup_hidden_option(good, good_id)
- return unless shop_options[:hidden][good_id]
- good.hidden_condition = shop_options[:hidden][good_id]
- end
-
- def setup_disabled_option(good, good_id)
- return unless shop_options[:disabled][good_id]
- good.disable_condition = shop_options[:disabled][good_id]
- end
-
- def setup_price_option(good, good_id)
- return unless shop_options[:price][good_id]
- good.price_formula = shop_options[:price][good_id].to_s
- end
-
- def eval_shop_condition(formula, v=$game_variables, s=$game_switches, p=$game_party, t=$game_troop)
- eval(formula)
- end
- end
- #-------------------------------------------------------------------------------
- # A shop good.
- # This is a wrapper around a raw item (RPG::Item, RPG::Weapon, etc).
- #-------------------------------------------------------------------------------
- class Game_ShopGood
-
- attr_reader :id # ID of this good
- attr_reader :item_type
- attr_reader :item_id
- attr_reader :price_type
- attr_accessor :hidden_condition
- attr_accessor :disable_condition
- attr_accessor :price_formula
-
- @@interpreter = Game_Interpreter.new
-
- def initialize(id, item_type, item_id, price_type, price)
- @id = id
- @item_type = item_type
- @item_id = item_id
- @price_type = price_type
- @price = price
- @hidden_condition = ""
- @disable_condition = ""
- @price_formula = ""
- end
-
- #-----------------------------------------------------------------------------
- # Determines whether the shop item should be included
- #-----------------------------------------------------------------------------
- def include?
- return false if eval_shop_condition(@hidden_condition)
- return true
- end
-
- #-----------------------------------------------------------------------------
- # Determines whether the shop item is enabled
- #-----------------------------------------------------------------------------
- def enable?
- return false if eval_shop_condition(@disable_condition)
- return true
- end
-
- #-----------------------------------------------------------------------------
- # Returns the appropriate object based on the item type. This implementation
- # is limited because it assumes you are pulling objects from the database.
- # Currently designed for compatibility with default implementation
- #-----------------------------------------------------------------------------
- def item
- return $data_items[@item_id] if @item_type == 0
- return $data_weapons[@item_id] if @item_type == 1
- return $data_armors[@item_id] if @item_type == 2
- end
-
- #-----------------------------------------------------------------------------
- # Returns the price of the shop good.
- #-----------------------------------------------------------------------------
- def price
- return eval_shop_condition(@price_formula) unless @price_formula.empty?
- return item.price if @price_type == 0
- return @price
- end
-
- #-----------------------------------------------------------------------------
- # Any shop formula that needs to be evaluated goes through here
- #-----------------------------------------------------------------------------
- def eval_shop_condition(formula)
- @@interpreter.eval_shop_condition(formula)
- end
- end
- #-------------------------------------------------------------------------------
- # A shop object. Stores information about the shop such as its inventory
- # and other shop-related data
- #-------------------------------------------------------------------------------
- class Game_Shop
- attr_reader :purchase_only
- attr_reader :shop_goods # all goods that this shop has.
- attr_accessor :need_refresh # shop needs to be refreshed
- attr_accessor :sell_prices
-
- @@interpreter = Game_Interpreter.new
-
- def initialize(goods, purchase_only=false)
- @shop_goods = goods
- @purchase_only = purchase_only
- @need_refresh = false
- setup_sell_prices
- end
-
- def setup_sell_prices
- @items = {}
- @weapons = {}
- @armors = {}
- end
-
- #-----------------------------------------------------------------------------
- # Returns true if the goods should be included
- #-----------------------------------------------------------------------------
- def include?(index)
- true
- end
-
- #-----------------------------------------------------------------------------
- # Return a set of goods for sale
- #-----------------------------------------------------------------------------
- def goods
- @shop_goods
- end
-
- #-----------------------------------------------------------------------------
- # Add a new good to the shop
- #-----------------------------------------------------------------------------
- def add_good(good)
- @shop_goods.push(good) unless @shop_goods.include?(good)
- end
-
- #-----------------------------------------------------------------------------
- # Remove the specified good from the shop
- #-----------------------------------------------------------------------------
- def remove_good(good_id)
- @shop_goods.delete_at(good_id - 1)
- end
-
- def item_container(item)
- return @weapons if item.is_a?(RPG::Weapon)
- return @armors if item.is_a?(RPG::Armor)
- return @items if item.is_a?(RPG::Item)
- end
-
- def set_sell_price(item, price_formula)
- container = item_container(item)
- container[item.id] = price_formula
- end
-
- def sell_price(item)
- container = item_container(item)
- if container.include?(item.id)
- return @@interpreter.eval_shop_condition(container[item.id])
- else
- return 0
- end
- end
- end
- #-------------------------------------------------------------------------------
- # A wrapper containing all shops in the game.
- #-------------------------------------------------------------------------------
- class Game_Shops
-
- #-----------------------------------------------------------------------------
- # Initializes a hash of game shops. Each key is a map ID, pointing to another
- # hash whose keys are event ID's and values are Game_Shop objects.
- #-----------------------------------------------------------------------------
- def initialize
- @data = {}
- end
-
- def [](id)
- @data[id]
- end
-
- def []=(id, shop)
- @data[id] = shop
- end
- end
- #-------------------------------------------------------------------------------
- # The shop scene now works with the Shop and ShopGood objects
- #-------------------------------------------------------------------------------
- class Scene_Shop < Scene_MenuBase
- #--------------------------------------------------------------------------
- # Replaced. The scene now takes a Game_Shop object
- #--------------------------------------------------------------------------
- def prepare(shop)
- @shop = shop
- @goods = shop.goods
- @purchase_only = shop.purchase_only
- end
-
- alias :th_shop_manager_on_buy_ok :on_buy_ok
- def on_buy_ok
- @selected_good = @buy_window.current_good
- th_shop_manager_on_buy_ok
- end
-
- #-----------------------------------------------------------------------------
- #
- #-----------------------------------------------------------------------------
- alias :th_shop_manager_selling_price :selling_price
- def selling_price
- price = @shop.sell_price(@sell_window.item)
- if price != 0
- return price
- else
- return th_shop_manager_selling_price
- end
- end
- end
- #-------------------------------------------------------------------------------
- # @shop_goods is now an array of Game_ShopGoods
- #-------------------------------------------------------------------------------
- class Window_ShopBuy < Window_Selectable
-
- #--------------------------------------------------------------------------
- # New. Returns true if the good should be included in the shop inventory
- #--------------------------------------------------------------------------
- def include?(shopGood)
- shopGood.include?
- end
-
- alias :th_shop_manager_enable? :enable?
- def enable?(item)
- return false unless @goods[item].enable?
- th_shop_manager_enable?(item)
- end
-
- #--------------------------------------------------------------------------
- # New. Get the currently selected good
- #--------------------------------------------------------------------------
- def current_good
- @goods[item]
- end
-
- #-----------------------------------------------------------------------------
- # Replaced. ShopGood takes care of most information. The data still contains
- # a list of RPG items for now since I don't want to change them to goods yet
- # A separate list of goods for sale is used for 1-1 correspondence
- #-----------------------------------------------------------------------------
- def make_item_list
- @data = []
- @goods = {}
- @price = {}
- @shop_goods.each do |shopGood|
- next unless include?(shopGood)
- item = shopGood.item
- @data.push(item)
- @goods[item] = shopGood
- @price[item] = shopGood.price
- end
- end
- end
复制代码 |
|