设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2485|回复: 3
打印 上一主题 下一主题

[已经过期] 限量商店的问题

[复制链接]

Lv2.观梦者

梦石
0
星屑
536
在线时间
69 小时
注册时间
2016-5-5
帖子
31
跳转到指定楼层
1
发表于 2019-1-16 23:48:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
要如何用条件判断商店东西全卖完或是关闭商店
都卖完了还跳出商店不觉得奇怪么

前置脚本
RUBY 代码复制
  1. =begin
  2. #===============================================================================
  3.  Title: Shop Manager
  4.  Author: Tsukihime
  5.  Date: Mar 29, 2013
  6. --------------------------------------------------------------------------------
  7.  ** Change log
  8.  1.5 Mar 29
  9.    - added simple shop refreshing on page change. Will need a better solution
  10.      since this does not track the state of a shop on a different page
  11.  1.4 Mar 13
  12.    - fixed bug where common event shops were not handled appropriately when
  13.      called through effects
  14.  1.3 Mar 1
  15.    - Game_ShopGood now determines whether it should be included or enabled
  16.    - Two shop options implemented: hidden, disabled
  17.  1.2 Feb 25
  18.    - fixed issue where common event shops were not handled correctly
  19.    - exposed Shop Good variables as readers
  20.  1.1
  21.    - ShopManager handles shop scene changing depending on the type of shop
  22.    - added handling for different "types" of shops
  23.    - all goods in a shop can be accessed via shop.shop_goods
  24.    - reference to shop added to shop scene
  25.    - added support for adding and removing goods from a shop
  26.  1.0 Feb 22, 2013
  27.    - Initial Release
  28. --------------------------------------------------------------------------------   
  29.  ** Terms of Use
  30.  * Free to use in commercial/non-commercial projects
  31.  * No real support. The script is provided as-is
  32.  * Will do bug fixes, but no compatibility patches
  33.  * Features may be requested but no guarantees, especially if it is non-trivial
  34.  * Credits to Tsukihime in your project
  35.  * Preserve this header
  36. --------------------------------------------------------------------------------
  37.  ** Description
  38.  
  39.  This script serves as a base for all shop-related scripts.
  40.  
  41.  This script provides functionality for remember a shop's "state".
  42.  Each shop is uniquely identified by a shop ID, and if you visit the same
  43.  shop repeatedly, you should see the same settings.
  44.  
  45.  For example, if a shop holds 10 potions, and you bought 5, then you can
  46.  expect that the next time you visit the shop, it will only have 5 potions
  47.  remaining.
  48.  
  49.  Of course, you will need extra plugins to have that kind of functionality.
  50.  Several new classes have been defined for working with shops, and in
  51.  particular, shop goods.
  52.  
  53.  In summary:
  54.    -more control over your shops
  55.    -simple API for developers to write shop-related scripts
  56.  
  57. --------------------------------------------------------------------------------
  58.  ** Usage
  59.  
  60. --------------------------------------------------------------------------------
  61.  ** Developers
  62.  
  63.  Here are some specifications that I have written.
  64.  
  65.  Have a look through each class to see what is available for use.
  66.  If you have any suggestions that will improve the base script (ie: this),
  67.  I will consider adding them.
  68.  
  69.  -- Shop Manager --
  70.  
  71.  This module serves are the interface for all shop-related queries. It handles
  72.  how shops are stored for you so that it is easy to properly obtain a reference
  73.  to a shop.
  74.  
  75.  You should use the Shop Manager whenever possible.
  76.  
  77.  -- Game Shop --
  78.  
  79.  This script treats a shop as a concrete object. A shop is created the first
  80.  time it is accessed, and will be stored with the game for the remainder of
  81.  the game.
  82.  
  83.  A very basic shop is provided, which manages what items are available for sale.
  84.  All shops are stored in a global Game_Shops hash in $game_shops
  85.  
  86.  -- Shop Type --
  87.  
  88.  On top of the basic Game_Shop class, you can define your own shops and
  89.  associate them with custom scenes specific to those shops.
  90.  
  91.  The Shop Manager only requires you to be consistent with your shop name.
  92.  For example, if your shop type is "CraftShop", then you must define a
  93.  
  94.    Game_CraftShop  - the shop object that the shop will be instantiated with
  95.    Scene_CraftShop - the scene that will be called when visiting a CraftShop
  96.    
  97.  Users will set a @shop_type attribute in Game_Interpreter to determine
  98.  what type of shop should be created
  99.  
  100.  -- Managing shops --
  101.  
  102.  This script assumes shops are only called through events or common events.
  103.  Troop events are not supported.
  104.  
  105.  A shop is identified by a map ID and an event ID.
  106.  Shops that are called via common events will have a map ID of 0.
  107.  
  108.  In order to determine whether a normal event or a common event called the
  109.  shop, the "depth" of the interpreter is used.
  110.  
  111.     When depth = 0, then it is a normal event
  112.     When depth > 0, then it is a common event
  113.     
  114.  The shop processing should be handled appropriately depending on the depth
  115.  
  116.  This script assumes that an event is triggered through "normal" interaction;
  117.  that is, you can only interact with events within a map. Any events that should
  118.  be treated as the same event should be done as a common event call.
  119.  
  120.  --- Shop Goods ---
  121.  
  122.  Rather than storing all goods as a simple array of values, this script
  123.  provides a Game_ShopGood class. You can use this to store any additional
  124.  information that you want.
  125.  
  126.  All shop related scenes and windows MUST provide support for handling shop
  127.  goods. While backwards compatibility is provided for the default scripts,
  128.  additional methods have been defined to allow you to retrieve the currently
  129.  selected shop good.
  130.  
  131.  --- Shop Options ---
  132.  
  133.  Since there isn't actually a way to setup individual shop goods, external
  134.  approaches must be used. There is not much specification here yet, so it
  135.  is up to you how you wish to populate your ShopGood objects. I have provided
  136.  a "setup_goods" method in Game_Interpreter that you can alias.
  137.  
  138. --------------------------------------------------------------------------------
  139.  ** Compatibility
  140.  
  141.  This script changes the following from the default scripts
  142.  
  143.    DataManager
  144.      aliased  - create_game_objects   
  145.      aliased  - make_save_contents
  146.      aliased  - extract_save_contents
  147.    Game_Interpreter
  148.      replaced - command_302
  149.    Window_ShopBuy
  150.      replaced - prepare
  151.    Scene_Shop
  152.      replaced - make_item_list
  153. #===============================================================================
  154. =end
  155. $imported = {} if $imported.nil?
  156. $imported["TH_ShopManager"] = 1.5
  157. #===============================================================================
  158. # ** Rest of the Script
  159. #===============================================================================
  160.  
  161. #-------------------------------------------------------------------------------
  162. # 作为商店和其他对象之间的界面的主力店经理
  163. # ShopManager 的主要作用是本质上是管理店里的任何在游戏中存在的对象
  164. # 尤其是,它提供了所有的方法
  165. # 创建、 检索和删除商店。
  166. # 所有的商店都存储在 全局变量$game_shops 的 Game_Shops哈希表
  167. #-------------------------------------------------------------------------------
  168. module ShopManager
  169.  
  170.   #-----------------------------------------------------------------------------
  171.   # 返回一个引用到一个特定的商店
  172.   #-----------------------------------------------------------------------------
  173.   def self.get_shop(map_id, event_id)
  174.     return $game_shops[map_id, event_id]
  175.   end
  176.  
  177.   #-----------------------------------------------------------------------------
  178.   # 表明一家店需要刷新
  179.   #-----------------------------------------------------------------------------
  180.   def self.refresh_shop(map_id, event_id)
  181.     shop = get_shop(map_id, event_id)
  182.     shop.need_refresh = true if shop
  183.   end
  184.  
  185.   #-----------------------------------------------------------------------------
  186.   # 设置商店,如果第一次访问
  187.   #-----------------------------------------------------------------------------
  188.   def self.setup_shop(map_id, event_id, goods, purchase_only, shop_type)
  189.     shop = get_shop(map_id, event_id)
  190.     return shop if shop && !shop.need_refresh
  191.     shop = shop_class(shop_type).new(goods, purchase_only)
  192.     $game_shops[map_id, event_id] = shop
  193.     return shop
  194.   end
  195.  
  196.   #-----------------------------------------------------------------------------
  197.   # 返回给定商店类型的适当店类
  198.   #-----------------------------------------------------------------------------
  199.   def self.shop_class(shop_type)
  200.     shop_type = "Game_" + shop_type.to_s
  201.     return Object.const_get(shop_type.to_sym)
  202.   end
  203.  
  204.   #-----------------------------------------------------------------------------
  205.   # 返回与这家商店关联的场景
  206.   # TO DO
  207.   #-----------------------------------------------------------------------------
  208.   def self.shop_scene(shop)
  209.     shop_scene = "Scene_" + shop.class.name.gsub("Game_", "")
  210.     return Object.const_get(shop_scene.to_sym)
  211.   end
  212.  
  213.   #-----------------------------------------------------------------------------
  214.   # 在适当的舞台上调用 SceneManager.call
  215.   #-----------------------------------------------------------------------------
  216.   def self.call_scene(shop)
  217.  
  218.     SceneManager.call(shop_scene(shop))
  219.     SceneManager.scene.prepare(shop)
  220.   end
  221.  
  222.   #-----------------------------------------------------------------------------
  223.   # 在适当的舞台上调用 SceneManager.goto
  224.   #-----------------------------------------------------------------------------
  225.   def self.goto_scene(shop)
  226.     SceneManager.goto(shop_scene(shop))
  227.     SceneManager.scene.prepare(shop)
  228.   end
  229.  
  230.   #-----------------------------------------------------------------------------
  231.   # Returns a good ID, given a shop and an item. If the item is already in
  232.   # the shop, it will return that good's ID. Otherwise, it will return a new ID
  233.   # 给定一个商店和一个项目的情况下返回一个好的 ID。如果该项目已在
  234.   # 店里,它将返回货物的 id。否则,它将返回一个新的 ID
  235.   #-----------------------------------------------------------------------------
  236.   def self.get_good_id(shop, item)
  237.     good = shop.shop_goods.detect {|good| good.item == item}
  238.     return good.nil? ? shop.shop_goods.size + 1 : good.id
  239.   end
  240.  
  241.   #-----------------------------------------------------------------------------
  242.   # Returns a good, given a shop and an item. If the shop already has that good
  243.   # just return it. Otherwise, make a new good. If the price is negative, then
  244.   # the price is the default price. Otherwise, it is the specified price.
  245.   # 给定一个商店和一个项目的情况下返回一个货物。如果店里已经有货物
  246.   # 只返回它。否则,造就了一个新的货物。如果价格是消极的那么
  247.   # 价格是默认价格。否则,它是指定的价格。
  248.   #-----------------------------------------------------------------------------
  249.   def self.get_good(shop, item, price=-1)
  250.     good = shop.shop_goods.detect {|good| good.item == item}
  251.     return good if good
  252.     good_id = shop.shop_goods.size + 1
  253.     type = item_type(item)
  254.     if price < 0
  255.       price_type = price = 0
  256.     else
  257.       price_type = 1
  258.     end
  259.     return Game_ShopGood.new(good_id, type, item.id, price_type, price)
  260.   end
  261.  
  262.   #-----------------------------------------------------------------------------
  263.   # 返回的项的类型。
  264.   #-----------------------------------------------------------------------------
  265.   def self.item_type(item)
  266.     return 0 if item.is_a?(RPG::Item)
  267.     return 1 if item.is_a?(RPG::Weapon)
  268.     return 2 if item.is_a?(RPG::Armor)
  269.     return -1
  270.   end
  271. end
  272.  
  273. #-------------------------------------------------------------------------------
  274. # Shops are stored in a global variable `$game_shops`. This is dumped and
  275. # loaded appropriately.
  276. # 商店都存储在全局变量 '$game_shops'。这是适当的倾倒和加载
  277. #-------------------------------------------------------------------------------
  278. module DataManager
  279.  
  280.   class << self
  281.     alias :th_shop_manager_create_game_objects :create_game_objects
  282.     alias :th_shop_manager_make_save_contents :make_save_contents
  283.     alias :th_shop_manager_extract_save_contents :extract_save_contents
  284.   end
  285.  
  286.   def self.create_game_objects
  287.     th_shop_manager_create_game_objects
  288.     $game_shops = Game_Shops.new
  289.   end
  290.  
  291.   def self.make_save_contents
  292.     contents = th_shop_manager_make_save_contents
  293.     contents[:shops] = $game_shops
  294.     contents
  295.   end
  296.  
  297.   #-----------------------------------------------------------------------------
  298.   # Load shop data 商店数据加载
  299.   #-----------------------------------------------------------------------------
  300.   def self.extract_save_contents(contents)
  301.     th_shop_manager_extract_save_contents(contents)
  302.     $game_shops = contents[:shops]
  303.   end
  304. end
  305.  
  306. class Game_Temp
  307.  
  308.   # even if we're not actually calling a shop, it shouldn't affect anything
  309.   # because we are always setting this at each common event call by an event
  310.   attr_accessor :shop_common_event_id
  311.  
  312.   alias :th_shop_manager_reserve_common_event :reserve_common_event
  313.   def reserve_common_event(common_event_id)
  314.     th_shop_manager_reserve_common_event(common_event_id)
  315.     @shop_common_event_id = common_event_id
  316.   end
  317. end
  318.  
  319. class Game_Event < Game_Character
  320.  
  321.   alias :th_shop_manager_setup_page :setup_page
  322.   def setup_page(page)
  323.     th_shop_manager_setup_page(page)
  324.     ShopManager.refresh_shop(@map_id, @id)
  325.   end
  326. end
  327.  
  328. class Game_Interpreter
  329.  
  330.   alias :th_shop_manager_clear :clear
  331.   def clear
  332.     th_shop_manager_clear
  333.     clear_shop_options
  334.     @shop_type = nil
  335.   end
  336.  
  337.   #-----------------------------------------------------------------------------
  338.   # New.
  339.   #-----------------------------------------------------------------------------
  340.   def clear_shop_options
  341.     @shop_options = {}
  342.     @shop_options[:hidden] = {}
  343.     @shop_options[:disabled] = {}
  344.   end
  345.  
  346.   #-----------------------------------------------------------------------------
  347.   # New. We are in a common event only if the shop common event ID is set.
  348.   #-----------------------------------------------------------------------------
  349.   def shop_map_id
  350.     $game_temp.shop_common_event_id ? 0 : @map_id
  351.   end
  352.  
  353.   def shop_event_id
  354.     $game_temp.shop_common_event_id ? $game_temp.shop_common_event_id : @event_id
  355.   end
  356.  
  357.   #--------------------------------------------------------------------------
  358.   # Set the shop's common event ID
  359.   #--------------------------------------------------------------------------
  360.   alias :th_shop_manager_command_117 :command_117
  361.   def command_117
  362.     $game_temp.shop_common_event_id = @params[0]
  363.     th_shop_manager_command_117
  364.   end
  365.  
  366.   #-----------------------------------------------------------------------------
  367.   # Replaced. A shop is setup only once, and is retrieved whenever it is
  368.   # called in the future. This assumes the shop is invoked through "normal"
  369.   # event interactions.
  370.   #-----------------------------------------------------------------------------
  371.   def command_302
  372.     return if $game_party.in_battle
  373.     shop_type = @shop_type || :Shop
  374.     good_id = 1
  375.     goods = []
  376.  
  377.     # setup goods
  378.     good = make_good(@params[0..-1], good_id) # last param is for the shop
  379.     goods.push(good)
  380.     good_id +=1
  381.  
  382.     while next_event_code == 605
  383.       @index += 1
  384.       good = make_good(@list[@index].parameters, good_id)
  385.       goods.push(good)
  386.       good_id +=1
  387.     end
  388.     # Setup shop if needed
  389.     shop = ShopManager.setup_shop(shop_map_id, shop_event_id, goods, @params[4], shop_type)
  390.  
  391.     # prepare the shop with a reference to the actual shop
  392.     ShopManager.call_scene(shop)
  393.     Fiber.yield
  394.  
  395.     # clear out the shop common event ID.
  396.     $game_temp.shop_common_event_id = nil
  397.   end
  398.  
  399.   #-----------------------------------------------------------------------------
  400.   # New. This is where the goods are setup.
  401.   #-----------------------------------------------------------------------------
  402.   def make_good(goods_array, good_id)
  403.     item_type, item_id, price_type, price = goods_array
  404.     good = Game_ShopGood.new(good_id, item_type, item_id, price_type, price)
  405.  
  406.     # additional setup
  407.     setup_good(good, good_id)
  408.     return good
  409.   end
  410.  
  411.   #-----------------------------------------------------------------------------
  412.   # New. You can do more things with your good here
  413.   #-----------------------------------------------------------------------------
  414.   def setup_good(good, good_id)
  415.     setup_hidden_option(good, good_id)
  416.     setup_disabled_option(good, good_id)
  417.   end
  418.  
  419.   #-----------------------------------------------------------------------------
  420.   # New. Shop options
  421.   #-----------------------------------------------------------------------------
  422.   def hide_good(good_id, condition)
  423.     @shop_options[:hidden][good_id] = condition
  424.   end
  425.  
  426.   def disable_good(good_id, condition)
  427.     @shop_options[:disabled][good_id] = condition
  428.   end
  429.  
  430.   def setup_hidden_option(good, good_id)
  431.     return unless @shop_options[:hidden][good_id]
  432.     good.hidden_condition = @shop_options[:hidden][good_id]
  433.   end
  434.  
  435.   def setup_disabled_option(good, good_id)
  436.     return unless @shop_options[:disabled][good_id]
  437.     good.disable_condition = @shop_options[:disabled][good_id]
  438.   end
  439. end
  440.  
  441. #-------------------------------------------------------------------------------
  442. # A shop good.
  443. # This is a wrapper around a raw item (RPG::Item, RPG::Weapon, etc).
  444. #-------------------------------------------------------------------------------
  445.  
  446. class Game_ShopGood
  447.  
  448.   attr_reader :id         # ID of this good
  449.   attr_reader :item_type
  450.   attr_reader :item_id
  451.   attr_reader :price_type
  452.   attr_accessor :hidden_condition
  453.   attr_accessor :disable_condition
  454.  
  455.   def initialize(id, item_type, item_id, price_type, price)
  456.     @id = id
  457.     @item_type = item_type
  458.     @item_id = item_id
  459.     @price_type = price_type
  460.     @price = price
  461.     @hidden_condition = ""
  462.     @disable_condition = ""
  463.   end
  464.  
  465.   def include?
  466.     return false if eval(@hidden_condition)
  467.     return true
  468.   end
  469.  
  470.   def enable?
  471.     return false if eval(@disable_condition)
  472.     return true
  473.   end
  474.  
  475.   def item
  476.     return $data_items[@item_id] if @item_type == 0
  477.     return $data_weapons[@item_id] if @item_type == 1
  478.     return $data_armors[@item_id] if @item_type == 2
  479.   end
  480.  
  481.   def price
  482.     return item.price if @price_type == 0
  483.     return @price
  484.   end
  485. end
  486.  
  487. #-------------------------------------------------------------------------------
  488. # A shop object. Stores information about the shop such as its inventory
  489. # and other shop-related data
  490. #-------------------------------------------------------------------------------
  491. class Game_Shop
  492.   attr_reader :purchase_only
  493.   attr_reader :shop_goods      # all goods that this shop has.
  494.   attr_accessor :need_refresh  # shop needs to be refreshed
  495.  
  496.   def initialize(goods, purchase_only=false)
  497.     @shop_goods = goods
  498.     @purchase_only = purchase_only
  499.     @need_refresh = false
  500.   end
  501.   #-----------------------------------------------------------------------------
  502.   # Returns true if the goods should be included
  503.   #-----------------------------------------------------------------------------
  504.   def include?(index)
  505.     true
  506.   end
  507.  
  508.   #-----------------------------------------------------------------------------
  509.   # Return a set of goods for sale
  510.   #-----------------------------------------------------------------------------
  511.   def goods
  512.     @shop_goods
  513.   end
  514.  
  515.   #-----------------------------------------------------------------------------
  516.   # Add a new good to the shop
  517.   #-----------------------------------------------------------------------------
  518.   def add_good(good)
  519.     @shop_goods.push(good) unless @shop_goods.include?(good)
  520.   end
  521.  
  522.   #-----------------------------------------------------------------------------
  523.   # Remove the specified good from the shop
  524.   #-----------------------------------------------------------------------------
  525.   def remove_good(good_id)
  526.     @shop_goods.delete_at(good_id - 1)
  527.   end
  528. end
  529.  
  530. #-------------------------------------------------------------------------------
  531. # 包含在游戏中的所有商店的包装。
  532. #-------------------------------------------------------------------------------
  533. class Game_Shops
  534.  
  535.   #-----------------------------------------------------------------------------
  536.   # Initializes a hash of game shops. Each key is a map ID, pointing to another
  537.   # hash whose keys are event ID's and values are Game_Shop objects.
  538.   # 初始化游戏商店的哈希。每个键是一个地图 ID 指向另一个哈希,那个
  539.   # 哈希的键是事件 ID    值是 Game_Shop 对象。
  540.   #-----------------------------------------------------------------------------
  541.   def initialize
  542.     @data = {}
  543.   end
  544.  
  545.   def [](i, j)
  546.     @data[i] ||= {}
  547.     @data[i][j]
  548.   end
  549.  
  550.   def []=(i, j, shop)
  551.     @data[i] ||= {}
  552.     @data[i][j] = shop
  553.   end
  554. end
  555.  
  556. #-------------------------------------------------------------------------------
  557. # The shop scene now works with the Shop and ShopGood objects
  558. #-------------------------------------------------------------------------------
  559. class Scene_Shop < Scene_MenuBase
  560.   #--------------------------------------------------------------------------
  561.   # Replaced. The scene now takes a Game_Shop object
  562.   #--------------------------------------------------------------------------
  563.   def prepare(shop)
  564.     @shop = shop
  565.     @goods = shop.goods
  566.     @purchase_only = shop.purchase_only
  567.   end
  568.  
  569.   alias :th_shop_manager_on_buy_ok :on_buy_ok
  570.   def on_buy_ok
  571.     @selected_good = @buy_window.current_good
  572.     th_shop_manager_on_buy_ok
  573.   end
  574. end
  575.  
  576. #-------------------------------------------------------------------------------
  577. # @shop_goods is now an array of Game_ShopGoods
  578. #-------------------------------------------------------------------------------
  579. class Window_ShopBuy < Window_Selectable
  580.  
  581.   #--------------------------------------------------------------------------
  582.   # New. Returns true if the good should be included in the shop inventory
  583.   #--------------------------------------------------------------------------
  584.   def include?(shopGood)
  585.     shopGood.include?
  586.   end
  587.  
  588.   alias :th_shop_manager_enable? :enable?
  589.   def enable?(item)
  590.     return false unless @goods[item].enable?
  591.     th_shop_manager_enable?(item)
  592.   end
  593.  
  594.   #--------------------------------------------------------------------------
  595.   # New. Get the currently selected good
  596.   #--------------------------------------------------------------------------
  597.   def current_good
  598.     @goods[item]
  599.   end
  600.  
  601.   #-----------------------------------------------------------------------------
  602.   # Replaced. ShopGood takes care of most information. The data still contains
  603.   # a list of RPG items for now since I don't want to change them to goods yet
  604.   # A separate list of goods for sale is used for 1-1 correspondence
  605.   #-----------------------------------------------------------------------------
  606.   def make_item_list
  607.     @data = []
  608.     @goods = {}
  609.     @price = {}
  610.     @shop_goods.each do |shopGood|
  611.       next unless include?(shopGood)
  612.       item = shopGood.item
  613.       @data.push(item)
  614.       @goods[item] = shopGood
  615.       @price[item] = shopGood.price
  616.     end
  617.   end
  618. end



主要的
RUBY 代码复制
  1. =begin
  2. #===============================================================================
  3.  Title: Shop Stock
  4.  Author: Tsukihime
  5.  Date: Feb 22, 2013
  6. --------------------------------------------------------------------------------
  7.  ** Change log
  8.  Feb 22, 2013
  9.    - Initial release
  10. --------------------------------------------------------------------------------   
  11.  ** 使用协议
  12.  * 免费用于商业或非商业项目
  13.  * 自由使用
  14.  * 会有BUG修复,但没有兼容性补丁
  15.  * 功能可能没有保证
  16.  * Preserve this header
  17. --------------------------------------------------------------------------------
  18.  ** 必需
  19.  
  20.  -商店库存-基础 以下网址为外站Hime Works,请开在线代理浏览
  21.  ([url]http://himeworks.wordpress.com/2013/02/22/shop-manager/[/url])
  22. --------------------------------------------------------------------------------
  23.  ** 说明
  24.  
  25.  这个脚本添加了一个stock到每个商店
  26.  一旦一个商品的stock达到零,它将不能在商店继续售卖
  27.  
  28. --------------------------------------------------------------------------------
  29.  ** 用法
  30.  
  31.  在你的事件中,在商店处理命令的上面添加以下脚本
  32.  
  33.    @shop_stock[id] = 数值
  34.    
  35.  名词解用
  36.    id为商店处理中商品列表的id
  37.    第一项商品的id为1,依此类推
  38.    
  39.    数值是该商品有多少存货在该商店
  40.    
  41. --------------------------------------------------------------------------------
  42.  ** 作者的话
  43.  
  44.  一个店的商品存货有多少全取决于stock
  45.  
  46.    stock < 0, 没有限制
  47.    stock == 0, 没有库存
  48.    stock > 0, 还有那么多库存
  49.  
  50. #===============================================================================
  51. =end
  52. $imported = {} if $imported.nil?
  53. $imported["TH_ShopStock"] = true
  54. #===============================================================================
  55. # ** Configuration  配置
  56. #===============================================================================
  57. module TH
  58.   module Shop_Stock
  59.   end
  60. end
  61. #===============================================================================
  62. # ** Rest of the Script
  63. #===============================================================================
  64. class Game_Interpreter
  65.  
  66.   alias :th_shop_stock_clear :clear
  67.   def clear
  68.     th_shop_stock_clear
  69.     @shop_stock = []
  70.   end
  71.  
  72.   alias :th_shop_stock_setup_good :setup_good
  73.   def setup_good(good, id)
  74.     th_shop_stock_setup_good(good, id)
  75.     stock = @shop_stock[id]
  76.     return unless stock
  77.     good.stock = stock
  78.   end
  79. end
  80.  
  81. class Game_ShopGood
  82.   attr_reader :stock
  83.  
  84.   alias :th_shop_stock_init :initialize
  85.   def initialize(*args)
  86.     th_shop_stock_init(*args)
  87.     @stock = -1
  88.     @unlimited = true
  89.   end
  90.  
  91.   def stock=(amount)
  92.     @stock = amount
  93.    @unlimited = (amount < 0)
  94.   end
  95.  
  96.   def unlimited?
  97.     @unlimited
  98.   end
  99.  
  100.   def increase_stock(amount)
  101.     @stock += amount
  102.   end
  103.  
  104.   def decrease_stock(amount)
  105.     return if @unlimited
  106.     @stock = [@stock - amount, 0].max
  107.   end
  108. end
  109.  
  110. class Game_Shop
  111.  
  112.   alias :th_shop_stock_include? :include?
  113.   def include?(index)
  114.     return false if stock(index) == 0
  115.     th_shop_stock_include?(index)
  116.   end
  117.  
  118.   def stock(index)
  119.     @shop_goods[index].stock
  120.   end
  121. end
  122.  
  123. class Window_ShopBuy < Window_Selectable
  124.  
  125.   alias :th_shop_stock_include? :include?
  126.   def include?(shopGood)
  127.     return false if shopGood.stock == 0
  128.     th_shop_stock_include?(shopGood)
  129.   end
  130.  
  131.   alias :th_shop_stock_draw_item :draw_item
  132.   def draw_item(index)
  133.     th_shop_stock_draw_item(index)
  134.     rect = item_rect(index)
  135.     item = @data[index]
  136.     shopGood = @goods[item]
  137.     #draw_text(rect, sprintf("庫存:%d", shopGood.stock), 1) unless shopGood.unlimited?
  138.   end
  139.  
  140.   alias :th_shop_stock_process_ok :process_ok
  141.   def process_ok
  142.     unless @data[index]
  143.       Sound.play_buzzer
  144.       return
  145.     end
  146.     th_shop_stock_process_ok
  147.   end
  148. end
  149.  
  150. class Scene_Shop < Scene_MenuBase
  151.  
  152.   #--------------------------------------------------------------------------
  153.   # Get amount you could buy, compared to the amount in-stock
  154.   #--------------------------------------------------------------------------
  155.   alias :th_shop_stock_max_buy :max_buy
  156.   def max_buy
  157.     party_max = th_shop_stock_max_buy
  158.     @selected_good.unlimited? ? party_max : [party_max, @selected_good.stock].min
  159.   end
  160.  
  161.   #--------------------------------------------------------------------------
  162.   # Decrease the amount of stock of the selected good
  163.   #--------------------------------------------------------------------------
  164.   alias :th_shop_stock_do_buy :do_buy
  165.   def do_buy(number)
  166.     th_shop_stock_do_buy(number)
  167.     @selected_good.decrease_stock(number)
  168.   end
  169. end

Lv5.捕梦者

梦石
0
星屑
31935
在线时间
5081 小时
注册时间
2012-11-19
帖子
4877

开拓者

2
发表于 2019-1-17 09:16:30 | 只看该作者
可以查看这个商店卖的什么东西啊
先记住了,以后有货了再来买。
xp vx va mv  va mz 各类型脚本/插件定制
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
926
在线时间
83 小时
注册时间
2018-12-18
帖子
84
3
发表于 2019-1-17 10:12:44 | 只看该作者
哇  都写这么多代码了还不知道在哪加物品库存数量么...
说实话要看也很不情愿看完哈哈...
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
536
在线时间
69 小时
注册时间
2016-5-5
帖子
31
4
 楼主| 发表于 2019-1-25 03:41:35 | 只看该作者
当所有东西都卖完了 就不再开启商店
或是打开开关 是这个意思
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-27 10:07

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表