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

Project1

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

[已经解决] 限量商店脚本出问题

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1433
在线时间
1705 小时
注册时间
2011-8-17
帖子
818
跳转到指定楼层
1
发表于 2014-9-8 10:24:37 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

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

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

x
这个脚本有2个,如果在商店处理里面设置1个以上的商品第一个脚本的376排就会报错
新建一个工程也是如此,可以排除脚本冲突的问题

第一个脚本
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. # Main shop manager that acts as the interface between shops and other objects
  163. # The main role of the ShopManager is to essentially manage any shop objects
  164. # that exist in the game. In particular, it provides all of the methods for
  165. # creating, retrieving, and deleting shops.
  166. #-------------------------------------------------------------------------------
  167. module ShopManager
  168.  
  169.   #-----------------------------------------------------------------------------
  170.   # Return a reference to a specific shop
  171.   #-----------------------------------------------------------------------------
  172.   def self.get_shop(map_id, event_id)
  173.     return $game_shops[map_id, event_id]
  174.   end
  175.  
  176.   #-----------------------------------------------------------------------------
  177.   # Indicate that a shop needs to be refreshed
  178.   #-----------------------------------------------------------------------------
  179.   def self.refresh_shop(map_id, event_id)
  180.     shop = get_shop(map_id, event_id)
  181.     shop.need_refresh = true if shop
  182.   end
  183.  
  184.   #-----------------------------------------------------------------------------
  185.   # Setup shop if first time visiting
  186.   #-----------------------------------------------------------------------------
  187.   def self.setup_shop(map_id, event_id, goods, purchase_only, shop_type)
  188.     shop = get_shop(map_id, event_id)
  189.     return shop if shop && !shop.need_refresh
  190.     shop = shop_class(shop_type).new(goods, purchase_only)
  191.     $game_shops[map_id, event_id] = shop
  192.     return shop
  193.   end
  194.  
  195.   #-----------------------------------------------------------------------------
  196.   # Return the appropriate shop class given the shop type
  197.   #-----------------------------------------------------------------------------
  198.   def self.shop_class(shop_type)
  199.     shop_type = "Game_" + shop_type.to_s
  200.     return Object.const_get(shop_type.to_sym)
  201.   end
  202.  
  203.   #-----------------------------------------------------------------------------
  204.   # Return the scene associated with this shop.
  205.   # TO DO
  206.   #-----------------------------------------------------------------------------
  207.   def self.shop_scene(shop)
  208.     shop_scene = "Scene_" + shop.class.name.gsub("Game_", "")
  209.     return Object.const_get(shop_scene.to_sym)
  210.   end
  211.  
  212.   #-----------------------------------------------------------------------------
  213.   # Invokes SceneManager.call on the appropriate scene
  214.   #-----------------------------------------------------------------------------
  215.   def self.call_scene(shop)
  216.  
  217.     SceneManager.call(shop_scene(shop))
  218.     SceneManager.scene.prepare(shop)
  219.   end
  220.  
  221.   #-----------------------------------------------------------------------------
  222.   # Invokes SceneManager.goto on the appropriate scene
  223.   #-----------------------------------------------------------------------------
  224.   def self.goto_scene(shop)
  225.     SceneManager.goto(shop_scene(shop))
  226.     SceneManager.scene.prepare(shop)
  227.   end
  228.  
  229.   #-----------------------------------------------------------------------------
  230.   # Returns a good ID, given a shop and an item. If the item is already in
  231.   # the shop, it will return that good's ID. Otherwise, it will return a new ID
  232.   #-----------------------------------------------------------------------------
  233.   def self.get_good_id(shop, item)
  234.     good = shop.shop_goods.detect {|good| good.item == item}
  235.     return good.nil? ? shop.shop_goods.size + 1 : good.id
  236.   end
  237.  
  238.   #-----------------------------------------------------------------------------
  239.   # Returns a good, given a shop and an item. If the shop already has that good
  240.   # just return it. Otherwise, make a new good. If the price is negative, then
  241.   # the price is the default price. Otherwise, it is the specified price.
  242.   #-----------------------------------------------------------------------------
  243.   def self.get_good(shop, item, price=-1)
  244.     good = shop.shop_goods.detect {|good| good.item == item}
  245.     return good if good
  246.     good_id = shop.shop_goods.size + 1
  247.     type = item_type(item)
  248.     if price < 0
  249.       price_type = price = 0
  250.     else
  251.       price_type = 1
  252.     end
  253.     return Game_ShopGood.new(good_id, type, item.id, price_type, price)
  254.   end
  255.  
  256.   #-----------------------------------------------------------------------------
  257.   # Returns the type of an item.
  258.   #-----------------------------------------------------------------------------
  259.   def self.item_type(item)
  260.     return 0 if item.is_a?(RPG::Item)
  261.     return 1 if item.is_a?(RPG::Weapon)
  262.     return 2 if item.is_a?(RPG::Armor)
  263.     return -1
  264.   end
  265. end
  266.  
  267. #-------------------------------------------------------------------------------
  268. # Shops are stored in a global variable `$game_shops`. This is dumped and
  269. # loaded appropriately.
  270. #-------------------------------------------------------------------------------
  271. module DataManager
  272.  
  273.   class << self
  274.     alias :th_shop_manager_create_game_objects :create_game_objects
  275.     alias :th_shop_manager_make_save_contents :make_save_contents
  276.     alias :th_shop_manager_extract_save_contents :extract_save_contents
  277.   end
  278.  
  279.   def self.create_game_objects
  280.     th_shop_manager_create_game_objects
  281.     $game_shops = Game_Shops.new
  282.   end
  283.  
  284.   def self.make_save_contents
  285.     contents = th_shop_manager_make_save_contents
  286.     contents[:shops] = $game_shops
  287.     contents
  288.   end
  289.  
  290.   #-----------------------------------------------------------------------------
  291.   # Load shop data
  292.   #-----------------------------------------------------------------------------
  293.   def self.extract_save_contents(contents)
  294.     th_shop_manager_extract_save_contents(contents)
  295.     $game_shops = contents[:shops]
  296.   end
  297. end
  298.  
  299. class Game_Temp
  300.  
  301.   # even if we're not actually calling a shop, it shouldn't affect anything
  302.   # because we are always setting this at each common event call by an event
  303.   attr_accessor :shop_common_event_id
  304.  
  305.   alias :th_shop_manager_reserve_common_event :reserve_common_event
  306.   def reserve_common_event(common_event_id)
  307.     th_shop_manager_reserve_common_event(common_event_id)
  308.     @shop_common_event_id = common_event_id
  309.   end
  310. end
  311.  
  312. class Game_Event < Game_Character
  313.  
  314.   alias :th_shop_manager_setup_page :setup_page
  315.   def setup_page(page)
  316.     th_shop_manager_setup_page(page)
  317.     ShopManager.refresh_shop(@map_id, @id)
  318.   end
  319. end
  320.  
  321. class Game_Interpreter
  322.  
  323.   alias :th_shop_manager_clear :clear
  324.   def clear
  325.     th_shop_manager_clear
  326.     clear_shop_options
  327.     @shop_type = nil
  328.   end
  329.  
  330.   #-----------------------------------------------------------------------------
  331.   # New.
  332.   #-----------------------------------------------------------------------------
  333.   def clear_shop_options
  334.     @shop_options = {}
  335.     @shop_options[:hidden] = {}
  336.     @shop_options[:disabled] = {}
  337.   end
  338.  
  339.   #-----------------------------------------------------------------------------
  340.   # New. We are in a common event only if the shop common event ID is set.
  341.   #-----------------------------------------------------------------------------
  342.   def shop_map_id
  343.     $game_temp.shop_common_event_id ? 0 : @map_id
  344.   end
  345.  
  346.   def shop_event_id
  347.     $game_temp.shop_common_event_id ? $game_temp.shop_common_event_id : @event_id
  348.   end
  349.  
  350.   #--------------------------------------------------------------------------
  351.   # Set the shop's common event ID
  352.   #--------------------------------------------------------------------------
  353.   alias :th_shop_manager_command_117 :command_117
  354.   def command_117
  355.     $game_temp.shop_common_event_id = @params[0]
  356.     th_shop_manager_command_117
  357.   end
  358.  
  359.   #-----------------------------------------------------------------------------
  360.   # Replaced. A shop is setup only once, and is retrieved whenever it is
  361.   # called in the future. This assumes the shop is invoked through "normal"
  362.   # event interactions.
  363.   #-----------------------------------------------------------------------------
  364.   def command_302
  365.     return if $game_party.in_battle
  366.     shop_type = @shop_type || :Shop
  367.     good_id = 1
  368.     goods = []
  369.  
  370.     # setup goods
  371.     good = make_good(@params[0..-1], good_id) # last param is for the shop
  372.     goods.push(good)
  373.     good_id +=1
  374.  
  375.     while next_event_code == 605
  376.      @Index += 1
  377.       good = make_good(@list[@index].parameters, good_id)
  378.       goods.push(good)
  379.       good_id +=1
  380.     end
  381.     # Setup shop if needed
  382.     shop = ShopManager.setup_shop(shop_map_id, shop_event_id, goods, @params[4], shop_type)
  383.  
  384.     # prepare the shop with a reference to the actual shop
  385.     ShopManager.call_scene(shop)
  386.     Fiber.yield
  387.  
  388.     # clear out the shop common event ID.
  389.     $game_temp.shop_common_event_id = nil
  390.   end
  391.  
  392.   #-----------------------------------------------------------------------------
  393.   # New. This is where the goods are setup.
  394.   #-----------------------------------------------------------------------------
  395.   def make_good(goods_array, good_id)
  396.     item_type, item_id, price_type, price = goods_array
  397.     good = Game_ShopGood.new(good_id, item_type, item_id, price_type, price)
  398.  
  399.     # additional setup
  400.     setup_good(good, good_id)
  401.     return good
  402.   end
  403.  
  404.   #-----------------------------------------------------------------------------
  405.   # New. You can do more things with your good here
  406.   #-----------------------------------------------------------------------------
  407.   def setup_good(good, good_id)
  408.     setup_hidden_option(good, good_id)
  409.     setup_disabled_option(good, good_id)
  410.   end
  411.  
  412.   #-----------------------------------------------------------------------------
  413.   # New. Shop options
  414.   #-----------------------------------------------------------------------------
  415.   def hide_good(good_id, condition)
  416.     @shop_options[:hidden][good_id] = condition
  417.   end
  418.  
  419.   def disable_good(good_id, condition)
  420.     @shop_options[:disabled][good_id] = condition
  421.   end
  422.  
  423.   def setup_hidden_option(good, good_id)
  424.     return unless @shop_options[:hidden][good_id]
  425.     good.hidden_condition = @shop_options[:hidden][good_id]
  426.   end
  427.  
  428.   def setup_disabled_option(good, good_id)
  429.     return unless @shop_options[:disabled][good_id]
  430.     good.disable_condition = @shop_options[:disabled][good_id]
  431.   end
  432. end
  433.  
  434. #-------------------------------------------------------------------------------
  435. # A shop good.
  436. # This is a wrapper around a raw item (RPG::Item, RPG::Weapon, etc).
  437. #-------------------------------------------------------------------------------
  438.  
  439. class Game_ShopGood
  440.  
  441.   attr_reader :id         # ID of this good
  442.   attr_reader :item_type
  443.   attr_reader :item_id
  444.   attr_reader :price_type
  445.   attr_accessor :hidden_condition
  446.   attr_accessor :disable_condition
  447.  
  448.   def initialize(id, item_type, item_id, price_type, price)
  449.     @id = id
  450.     @item_type = item_type
  451.     @item_id = item_id
  452.     @price_type = price_type
  453.     @price = price
  454.     @hidden_condition = ""
  455.     @disable_condition = ""
  456.   end
  457.  
  458.   def include?
  459.     return false if eval(@hidden_condition)
  460.     return true
  461.   end
  462.  
  463.   def enable?
  464.     return false if eval(@disable_condition)
  465.     return true
  466.   end
  467.  
  468.   def item
  469.     return $data_items[@item_id] if @item_type == 0
  470.     return $data_weapons[@item_id] if @item_type == 1
  471.     return $data_armors[@item_id] if @item_type == 2
  472.   end
  473.  
  474.   def price
  475.     return item.price if @price_type == 0
  476.     return @price
  477.   end
  478. end
  479.  
  480. #-------------------------------------------------------------------------------
  481. # A shop object. Stores information about the shop such as its inventory
  482. # and other shop-related data
  483. #-------------------------------------------------------------------------------
  484. class Game_Shop
  485.   attr_reader :purchase_only
  486.   attr_reader :shop_goods      # all goods that this shop has.
  487.   attr_accessor :need_refresh  # shop needs to be refreshed
  488.  
  489.   def initialize(goods, purchase_only=false)
  490.     @shop_goods = goods
  491.     @purchase_only = purchase_only
  492.     @need_refresh = false
  493.   end
  494.   #-----------------------------------------------------------------------------
  495.   # Returns true if the goods should be included
  496.   #-----------------------------------------------------------------------------
  497.   def include?(index)
  498.     true
  499.   end
  500.  
  501.   #-----------------------------------------------------------------------------
  502.   # Return a set of goods for sale
  503.   #-----------------------------------------------------------------------------
  504.   def goods
  505.     @shop_goods
  506.   end
  507.  
  508.   #-----------------------------------------------------------------------------
  509.   # Add a new good to the shop
  510.   #-----------------------------------------------------------------------------
  511.   def add_good(good)
  512.     @shop_goods.push(good) unless @shop_goods.include?(good)
  513.   end
  514.  
  515.   #-----------------------------------------------------------------------------
  516.   # Remove the specified good from the shop
  517.   #-----------------------------------------------------------------------------
  518.   def remove_good(good_id)
  519.     @shop_goods.delete_at(good_id - 1)
  520.   end
  521. end
  522.  
  523. #-------------------------------------------------------------------------------
  524. # A wrapper containing all shops in the game.
  525. #-------------------------------------------------------------------------------
  526. class Game_Shops
  527.  
  528.   #-----------------------------------------------------------------------------
  529.   # Initializes a hash of game shops. Each key is a map ID, pointing to another
  530.   # hash whose keys are event ID's and values are Game_Shop objects.
  531.   #-----------------------------------------------------------------------------
  532.   def initialize
  533.     @data = {}
  534.   end
  535.  
  536.   def [](i, j)
  537.     @data[i] ||= {}
  538.     @data[i][j]
  539.   end
  540.  
  541.   def []=(i, j, shop)
  542.     @data[i] ||= {}
  543.     @data[i][j] = shop
  544.   end
  545. end
  546.  
  547. #-------------------------------------------------------------------------------
  548. # The shop scene now works with the Shop and ShopGood objects
  549. #-------------------------------------------------------------------------------
  550. class Scene_Shop < Scene_MenuBase
  551.   #--------------------------------------------------------------------------
  552.   # Replaced. The scene now takes a Game_Shop object
  553.   #--------------------------------------------------------------------------
  554.   def prepare(shop)
  555.     @shop = shop
  556.     @goods = shop.goods
  557.     @purchase_only = shop.purchase_only
  558.   end
  559.  
  560.   alias :th_shop_manager_on_buy_ok :on_buy_ok
  561.   def on_buy_ok
  562.     @selected_good = @buy_window.current_good
  563.     th_shop_manager_on_buy_ok
  564.   end
  565. end
  566.  
  567. #-------------------------------------------------------------------------------
  568. # @shop_goods is now an array of Game_ShopGoods
  569. #-------------------------------------------------------------------------------
  570. class Window_ShopBuy < Window_Selectable
  571.  
  572.   #--------------------------------------------------------------------------
  573.   # New. Returns true if the good should be included in the shop inventory
  574.   #--------------------------------------------------------------------------
  575.   def include?(shopGood)
  576.     shopGood.include?
  577.   end
  578.  
  579.   alias :th_shop_manager_enable? :enable?
  580.   def enable?(item)
  581.     return false unless @goods[item].enable?
  582.     th_shop_manager_enable?(item)
  583.   end
  584.  
  585.   #--------------------------------------------------------------------------
  586.   # New. Get the currently selected good
  587.   #--------------------------------------------------------------------------
  588.   def current_good
  589.     @goods[item]
  590.   end
  591.  
  592.   #-----------------------------------------------------------------------------
  593.   # Replaced. ShopGood takes care of most information. The data still contains
  594.   # a list of RPG items for now since I don't want to change them to goods yet
  595.   # A separate list of goods for sale is used for 1-1 correspondence
  596.   #-----------------------------------------------------------------------------
  597.   def make_item_list
  598.     @data = []
  599.     @goods = {}
  600.     @price = {}
  601.     @shop_goods.each do |shopGood|
  602.       next unless include?(shopGood)
  603.       item = shopGood.item
  604.       @data.push(item)
  605.       @goods[item] = shopGood
  606.       @price[item] = shopGood.price
  607.     end
  608.   end
  609. 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. class Game_ShopGood
  81.   attr_reader :stock
  82.  
  83.   alias :th_shop_stock_init :initialize
  84.   def initialize(*args)
  85.     th_shop_stock_init(*args)
  86.     @stock = -1
  87.     [url=home.php?mod=space&uid=263900]@unlimited[/url] = true
  88.   end
  89.  
  90.   def stock=(amount)
  91.     @stock = amount
  92.    [url=home.php?mod=space&uid=263900]@unlimited[/url] = (amount < 0)
  93.   end
  94.  
  95.   def unlimited?
  96.     @unlimited
  97.   end
  98.  
  99.   def increase_stock(amount)
  100.     @stock += amount
  101.   end
  102.  
  103.   def decrease_stock(amount)
  104.     return if @unlimited
  105.     @stock = [@stock - amount, 0].max
  106.   end
  107. end
  108.  
  109. class Game_Shop
  110.  
  111.   alias :th_shop_stock_include? :include?
  112.   def include?(index)
  113.     return false if stock(index) == 0
  114.     th_shop_stock_include?(index)
  115.   end
  116.  
  117.   def stock(index)
  118.     @shop_goods[index].stock
  119.   end
  120. end
  121.  
  122. class Window_ShopBuy < Window_Selectable
  123.  
  124.   alias :th_shop_stock_include? :include?
  125.   def include?(shopGood)
  126.     return false if shopGood.stock == 0
  127.     th_shop_stock_include?(shopGood)
  128.   end
  129.  
  130.   alias :th_shop_stock_draw_item :draw_item
  131.   def draw_item(index)
  132.     th_shop_stock_draw_item(index)
  133.     rect = item_rect(index)
  134.     item = @data[index]
  135.     shopGood = @goods[item]
  136.     draw_text(rect, sprintf("庫存:%d", shopGood.stock), 1) unless shopGood.unlimited?
  137.   end
  138.  
  139.   alias :th_shop_stock_process_ok :process_ok
  140.   def process_ok
  141.     unless @data[index]
  142.       Sound.play_buzzer
  143.       return
  144.     end
  145.     th_shop_stock_process_ok
  146.   end
  147. end
  148.  
  149. class Scene_Shop < Scene_MenuBase
  150.  
  151.   #--------------------------------------------------------------------------
  152.   # Get amount you could buy, compared to the amount in-stock
  153.   #--------------------------------------------------------------------------
  154.   alias :th_shop_stock_max_buy :max_buy
  155.   def max_buy
  156.     party_max = th_shop_stock_max_buy
  157.     @selected_good.unlimited? ? party_max : [party_max, @selected_good.stock].min
  158.   end
  159.  
  160.   #--------------------------------------------------------------------------
  161.   # Decrease the amount of stock of the selected good
  162.   #--------------------------------------------------------------------------
  163.   alias :th_shop_stock_do_buy :do_buy
  164.   def do_buy(number)
  165.     th_shop_stock_do_buy(number)
  166.     @selected_good.decrease_stock(number)
  167.   end
  168. end
  
roguelike求生RPG研发中....

Lv4.逐梦者 (版主)

无限の剣制

梦石
0
星屑
10074
在线时间
5020 小时
注册时间
2013-2-28
帖子
5030

开拓者贵宾

2
发表于 2014-9-8 10:28:12 | 只看该作者
本帖最后由 VIPArcher 于 2014-9-8 10:29 编辑

@Index += 1 改成 @index += 1

评分

参与人数 2星屑 +210 收起 理由
taroxd + 150 认可答案
黑舞嗜 + 60 噗~我也是醉了

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-8 21:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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