TheoAllen

Chest System (no Category)

Jan 25th, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 21.13 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Chest System
  3. # Version : 1.2b
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script is translated by AbsoluteIce)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_ChestSystem] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2014.01.26 - Remove Category Window
  12. # 2013.08.19 - Compatibility Patch with Limited Inventory
  13. # 2013.06.28 - Add custom chest name
  14. # 2013.06.01 - Adjust control and GUI
  15. # 2013.05.24 - Finished script
  16. # 2013.05.23 - Started Script
  17. # =============================================================================
  18. =begin
  19.  
  20.   Introduction :
  21.   This script lets you open a chest. It lets you take out, or fill in items
  22.   from your inventory. Similar to the western RPG game, Elder Scrolls.
  23.  
  24.   How to use :
  25.   Put this below materials, and above main in the script section.
  26.  
  27.   Use a comment on the event in this format before you do a script call to
  28.   initialize the chest starting items.
  29.   <item: id, amount>
  30.   <weapon: id, amount>
  31.   <armor: id, amount>
  32.  
  33.   Explanation of Id's :
  34.   id >> id of the item
  35.   amount >> number of items
  36.  
  37.   After using the comment, use this script call :
  38.   open_chest
  39.  
  40.   For custom name chest, you can use this script call. For example :
  41.   open_chest("Garbage")
  42.   open_chest("Eric's Chest")
  43.  
  44.   note : every comment in every event is read once. Make sure you put it before
  45.   the script call.
  46.  
  47.   Terms of use :
  48.   Credit me, TheoAllen. You're free to edit by your own as long as you don't
  49.   claim it's yours. If you want to use for a commercial project, share the
  50.   profit with me. And don't forget to give me free copy of the game
  51.  
  52. =end
  53. # =============================================================================
  54. # Configuration :
  55. # =============================================================================
  56. module THEO
  57.   module CHEST
  58.     # =========================================================================
  59.     # Vocabs
  60.     # -------------------------------------------------------------------------
  61.       AMOUNT_VOCAB  = "Amount :"    # Vocab for said amount.
  62.       ALL_VOCAB     = "All"         # Vocab for all categories.
  63.       INV_VOCAB     = "Inventory"   # Vocab for inventory.
  64.       ST_VOCAB      = "Stash"       # Vocab for stash/storage.
  65.     # =========================================================================
  66.    
  67.     # =========================================================================
  68.       TRIGGER_GAIN_ALL  = :CTRL
  69.     # -------------------------------------------------------------------------
  70.     # Trigger to take all items. If you write :CTRL, thus all items
  71.     # will be taken if you press CTRL + Confirm (z)
  72.     # =========================================================================
  73.    
  74.     # =========================================================================
  75.       SHOW_AMOUNT_MIN   = 10
  76.     # -------------------------------------------------------------------------
  77.     # minimum amount for viewing the window amount.
  78.     # =========================================================================
  79.    
  80.   end
  81. end
  82. # =============================================================================
  83. # End of Configuration (Don't edit if you don't know what you're doing)
  84. # =============================================================================
  85. module THEO
  86.   module CHEST
  87.   module REGEXP
  88.    
  89.     ITEM_REGEX   = /<(?:ITEM|item):[ ]*[ ]*(\d+\s*,\s*\d*)>/i
  90.     WEAPON_REGEX = /<(?:WEAPON|weapon):[ ]*[ ]*(\d+\s*,\s*\d*)>/i
  91.     ARMOR_REGEX  = /<(?:ARMOR|armor):[ ]*[ ]*(\d+\s*,\s*\d*)>/i
  92.    
  93.   end
  94.   end
  95. end
  96.  
  97. class Scene_Chest < Scene_MenuBase
  98.  
  99.   include THEO::CHEST
  100.  
  101.   def initialize(key,st_vocab)
  102.     $game_party.init_chest_cursors
  103.     @last_active = :stash
  104.     @key = key
  105.     @st_vocab = st_vocab
  106.   end
  107.  
  108.   def start
  109.     super
  110.     create_header_windows
  111.     create_footer_window
  112.     create_main_windows
  113.     create_amount_window
  114.     prepare
  115.   end
  116.  
  117.   def create_header_windows
  118.     create_help_window
  119. #~     create_category_window
  120.   end
  121.  
  122.   def create_main_windows
  123.     create_inventory_window
  124.     create_stash_window
  125.   end
  126.  
  127.   def create_help_window
  128.     @help = Window_Help.new
  129.     @help.viewport = @viewport
  130.   end
  131.  
  132.   def create_category_window
  133.     @category = Window_ChestCategory.new
  134.     @category.viewport = @viewport
  135.     @category.y = @help.height
  136.     @category.set_handler(:ok, method(:on_category_ok))
  137.     @category.set_handler(:cancel, method(:return_scene))
  138.   end
  139.  
  140.   def create_footer_window
  141.     create_inv_footer
  142.     create_st_footer
  143.   end
  144.  
  145.   def create_inv_footer
  146.     if $imported[:Theo_LimInventory]
  147.       x = 0
  148.       y = Graphics.height - 48
  149.       w = Graphics.width/2
  150.       @inv_footer = Window_ChestFreeSlot.new(x,y,w)
  151.       @inv_footer.viewport = @viewport
  152.     else
  153.       @inv_footer = Window_ChestFooter.new(INV_VOCAB,$game_party,0)
  154.       @inv_footer.viewport = @viewport
  155.     end
  156.   end
  157.  
  158.   def create_st_footer
  159.     @st_footer = Window_ChestFooter.new(@st_vocab,$game_chests[@key],1)
  160.     @st_footer.viewport = @viewport
  161.   end
  162.  
  163.   def create_inventory_window
  164.     x = 0
  165.     y = @help.height #+ @category.height
  166.     w = Graphics.width/2
  167.     h = Graphics.height - y - @inv_footer.height
  168.     @inventory = Window_Inventory.new(x,y,w,h)
  169.     @inventory.viewport = @viewport
  170.     @inventory.set_handler(:ok, method(:item_inventory_ok))
  171.     @inventory.set_handler(:cancel, method(:on_inventory_cancel))
  172.     @inventory.help_window = @help
  173.     @inventory.category = :all
  174. #~     @category.item_window = @inventory
  175.   end
  176.  
  177.   def create_stash_window
  178.     x = Graphics.width / 2
  179.     y = @inventory.y
  180.     w = x
  181.     h = @inventory.height
  182.     @stash = Window_Stash.new(x,y,w,h,@key)
  183.     @stash.viewport = @viewport
  184.     @stash.set_handler(:ok, method(:item_stash_ok))
  185.     @stash.set_handler(:cancel, method(:on_stash_cancel))
  186.     @stash.help_window = @help
  187.     @stash.category = :all
  188. #~     @category.stash_window = @stash
  189.   end
  190.  
  191.   def create_amount_window
  192.     @amount = Window_ChestAmount.new
  193.     @amount.viewport = @viewport
  194.     @amount.inv_window = @inv_footer if $imported[:Theo_LimInventory]
  195.   end
  196.  
  197.   # for future plan ~
  198.   def refresh_all_footers
  199.     @inv_footer.refresh
  200.     @st_footer.refresh
  201.   end
  202.  
  203.   def prepare
  204.     unselect_all
  205.     activate_itemlist
  206.     @item_phase = true
  207. #~     @category.show
  208. #~     @category.activate
  209. #~     @item_phase = false
  210. #~     deactivate_item_windows
  211. #~     hide_amount
  212.    
  213.   end
  214.  
  215.   def deactivate_item_windows
  216.     @inventory.deactivate
  217.     @stash.deactivate
  218.   end
  219.  
  220.   def on_category_ok
  221.     @category.deactivate
  222.     activate_itemlist
  223.     @item_phase = true
  224.   end
  225.  
  226.   def item_inventory_ok
  227.     unless @inventory.item
  228.       @inventory.activate
  229.       return
  230.     end
  231.     if @inventory.item_number < SHOW_AMOUNT_MIN
  232.       store_items(1)
  233.       @inventory.activate
  234.       refresh_itemlist
  235.     else
  236.       @last_active = :inventory
  237.       input_amount(@inventory)
  238.     end
  239.   end
  240.  
  241.   def item_stash_ok
  242.     unless @stash.item
  243.       @stash.activate
  244.       return
  245.     end
  246.     if @stash.item_number < SHOW_AMOUNT_MIN
  247.       gain_items(1)
  248.       @stash.activate
  249.       refresh_itemlist
  250.     else
  251.       @last_active = :stash
  252.       input_amount(@stash)
  253.     end
  254.   end
  255.  
  256.   def on_stash_cancel
  257.     return_scene
  258. #~     @last_active = :stash
  259. #~     memorize_st
  260. #~     prepare
  261.   end
  262.  
  263.   def on_inventory_cancel
  264.     return_scene
  265. #~     @last_active = :inventory
  266. #~     memorize_inv
  267. #~     prepare
  268.   end
  269.  
  270.   def input_amount(window)
  271.     memorize_all
  272.     if window.equal?(@stash)
  273.       @inventory.unselect
  274.     else
  275.       @stash.unselect
  276.     end
  277.     @amount.open
  278.     @amount.item_window = window
  279.     deactivate_item_windows
  280.   end
  281.  
  282.   def hide_amount
  283.     Sound.play_cancel
  284.     @amount.close
  285.     @amount.reset_amount
  286.   end
  287.  
  288.   def update
  289.     super
  290.     @amount.mode = @last_active
  291.     @inv_footer.mode = @last_active if $imported[:Theo_LimInventory]
  292.     select_item_phase if @item_phase
  293.     input_amount_phase if @amount.open?
  294.   end
  295.  
  296.   def select_item_phase
  297.     gain_all_items if trigger_gain_all_item?
  298.     switch_window if Input.repeat?(:RIGHT) || Input.repeat?(:LEFT)
  299.   end
  300.  
  301.   def input_amount_phase
  302.     activate_itemlist if Input.trigger?(:B)
  303.     if @amount.item_window.equal?(@stash) && Input.trigger?(:C)
  304.       gain_items(@amount.amount)
  305.     elsif @amount.item_window.equal?(@inventory) && Input.trigger?(:C)
  306.       store_items(@amount.amount)
  307.     end
  308.   end
  309.  
  310.   def switch_window
  311.     if @inventory.active
  312.       switch_stash
  313.     elsif @stash.active
  314.       switch_inventory
  315.     end
  316.   end
  317.  
  318.   def switch_inventory
  319.     memorize_st
  320.     @stash.deactivate
  321.     @stash.unselect
  322.     @inventory.activate
  323.     inv_select
  324.   end
  325.  
  326.   def switch_stash
  327.     @stash.activate
  328.     st_select
  329.     memorize_inv
  330.     @inventory.deactivate
  331.     @inventory.unselect
  332.   end
  333.  
  334.   def gain_all_items
  335.     if @stash.active
  336.       @stash.data.each do |item|
  337.         gain_items(@stash.item_number(item),item)
  338.       end
  339.       @stash.select(0)
  340.     else
  341.       @inventory.data.each do |item|
  342.         store_items(@inventory.item_number(item),item)
  343.       end
  344.       @inventory.select(0)
  345.     end
  346.     refresh_itemlist
  347.     refresh_all_footers
  348.   end
  349.  
  350.   def trigger_gain_all_item?
  351.     Input.press?(THEO::CHEST::TRIGGER_GAIN_ALL) && Input.trigger?(:C)
  352.   end
  353.  
  354.   def gain_items(amount, item = @stash.item)
  355.     if $imported[:Theo_LimInventory]
  356.       amount = [[amount,0].max,$game_party.inv_max_item(item)].min
  357.     end
  358.     $game_party.gain_item(item,amount)
  359.     $game_chests[@key].lose_item(item,amount)
  360.     on_amount_confirm if @amount.open?
  361.   end
  362.  
  363.   def store_items(amount, item = @inventory.item)
  364.     $game_chests[@key].gain_item(item,amount)
  365.     $game_party.lose_item(item,amount)
  366.     on_amount_confirm if @amount.open?
  367.   end
  368.  
  369.   def refresh_itemlist
  370.     @stash.refresh    
  371.     @inventory.refresh
  372.   end
  373.  
  374.   def on_amount_confirm
  375.     Sound.play_ok
  376.     refresh_itemlist
  377.     unselect_all
  378.     activate_itemlist
  379.   end
  380.  
  381.   def activate_itemlist
  382.     hide_amount
  383.     case @last_active
  384.     when :stash
  385.       activate_stash
  386.     when :inventory
  387.       activate_inventory
  388.     end
  389.     @item_phase = true
  390.   end
  391.  
  392.   def activate_inventory
  393.     @inventory.activate
  394.     @stash.unselect
  395.     inv_select
  396.   end
  397.  
  398.   def activate_stash
  399.     @stash.activate
  400.     @inventory.unselect
  401.     st_select
  402.   end
  403.  
  404.   def memorize_inv
  405.     $game_party.last_inv = @inventory.index
  406.   end
  407.  
  408.   def memorize_st
  409.     $game_party.last_st = @stash.index
  410.   end
  411.  
  412.   def inv_select
  413.     @inventory.index = [[$game_party.last_inv,@inventory.item_max-1].min,0].max
  414.   end
  415.  
  416.   def st_select
  417.     @stash.index = [[$game_party.last_st,@stash.item_max-1].min,0].max
  418.   end
  419.  
  420.   def unselect_all
  421.     @inventory.unselect
  422.     @stash.unselect
  423.   end
  424.  
  425.   def memorize_all
  426.     memorize_inv
  427.     memorize_st
  428.   end
  429.  
  430. end
  431.  
  432. if $imported[:Theo_LimInventory]
  433. class Window_ChestFreeSlot < Window_FreeSlot
  434.   attr_accessor :item
  435.   attr_accessor :mode
  436.  
  437.   def initialize(x,y,w)
  438.     @add_number = 0
  439.     @mode = :stash
  440.     super(x,y,w)
  441.   end
  442.  
  443.   def add_number=(number)
  444.     temp = @add_number
  445.     @add_number = number
  446.     refresh if temp != number
  447.   end
  448.  
  449.   def draw_inv_slot(x,y,width = contents.width,align = 2)
  450.     item_size = @item.nil? ? 0 : @item.inv_size
  451.     item_size = -item_size if @mode == :inventory
  452.     txt = sprintf("%d/%d",$game_party.total_inv_size + @add_number *
  453.     item_size, $game_party.inv_max)
  454.     color = THEO::LimInv::NearMaxed_Color
  455.     near_max = ($game_party.total_inv_size + @add_number * item_size).to_f /
  456.       $game_party.inv_max >= (100 - THEO::LimInv::NearMaxed_Percent)/100.0
  457.     if near_max
  458.       change_color(text_color(color))
  459.     else
  460.       change_color(normal_color)
  461.     end
  462.     draw_text(x,y,width,line_height,txt,align)
  463.     change_color(normal_color)
  464.   end
  465.  
  466. end
  467. end
  468.  
  469. class Window_ChestCategory < Window_ItemCategory
  470.   attr_reader :stash_window
  471.  
  472.   def col_max
  473.     return 4
  474.   end
  475.  
  476.   def update
  477.     super
  478.     @stash_window.category = current_symbol if @stash_window
  479.   end
  480.  
  481.   def make_command_list
  482.     add_command(THEO::CHEST::ALL_VOCAB, :all)
  483.     add_command(Vocab::item,     :item)
  484.     add_command(Vocab::weapon,   :weapon)
  485.     add_command(Vocab::armor,    :armor)
  486.   end
  487.  
  488.   def stash_window=(stash_window)
  489.     @stash_window = stash_window
  490.     update
  491.   end
  492.  
  493. end
  494.  
  495. class Window_Inventory < Window_ItemList
  496.   attr_reader :data
  497.  
  498.   def col_max
  499.     return 1
  500.   end
  501.  
  502.   def current_item_enabled?
  503.     return true
  504.   end
  505.  
  506.   def include?(item)
  507.     case @category
  508.     when :item
  509.       item.is_a?(RPG::Item) && !item.key_item?
  510.     when :weapon
  511.       item.is_a?(RPG::Weapon)
  512.     when :armor
  513.       item.is_a?(RPG::Armor)
  514.     when :all
  515.       item.is_a?(RPG::Armor) || item.is_a?(RPG::Weapon) || item.is_a?(RPG::Item)
  516.     else
  517.       false
  518.     end
  519.   end
  520.  
  521.   def draw_item(index)
  522.     item = @data[index]
  523.     if item
  524.       rect = item_rect(index)
  525.       rect.width -= 4
  526.       draw_item_name(item, rect.x, rect.y, true,contents.width)
  527.       draw_item_number(rect, item)
  528.     end
  529.   end
  530.  
  531.   def item_number(item = @data[index])
  532.     $game_party.item_number(item)
  533.   end
  534.  
  535.   def process_ok
  536.     return if Input.press?(THEO::CHEST::TRIGGER_GAIN_ALL)
  537.     super
  538.   end
  539.  
  540. end
  541.  
  542. class Window_Stash < Window_ItemList
  543.   attr_reader :data
  544.  
  545.   def initialize(x, y, width, height, key)
  546.     @key = key
  547.     super(x,y,width,height)
  548.     @category = :none
  549.     @data = []
  550.   end
  551.  
  552.   def col_max
  553.     return 1
  554.   end
  555.  
  556.   def current_item_enabled?
  557.     enable?(item)
  558.   end
  559.  
  560.   def enable?(item)
  561.     return true unless $imported[:Theo_LimInventory]
  562.     return $game_party.inv_max_item(item) > 0
  563.   end
  564.  
  565.   def include?(item)
  566.     case @category
  567.     when :item
  568.       item.is_a?(RPG::Item) && !item.key_item?
  569.     when :weapon
  570.       item.is_a?(RPG::Weapon)
  571.     when :armor
  572.       item.is_a?(RPG::Armor)
  573.     when :all
  574.       item.is_a?(RPG::Armor) || item.is_a?(RPG::Weapon) || item.is_a?(RPG::Item)
  575.     else
  576.       false
  577.     end
  578.   end
  579.  
  580.   def make_item_list
  581.     @data = $game_chests[@key].all_items.select {|item| include?(item) }
  582.     @data.push(nil) if include?(nil)
  583.   end
  584.  
  585.   def draw_item(index)
  586.     item = @data[index]
  587.     if item
  588.       rect = item_rect(index)
  589.       rect.width -= 4
  590.       draw_item_name(item, rect.x, rect.y, enable?(item),contents.width)
  591.       draw_item_number(rect, item)
  592.     end
  593.   end
  594.  
  595.   def draw_item_number(rect, item)
  596.     draw_text(rect, sprintf(":%2d", $game_chests[@key].item_number(item)), 2)
  597.   end
  598.  
  599.   def item_number(item = @data[index])
  600.     $game_chests[@key].item_number(item)
  601.   end
  602.  
  603.   def process_ok
  604.     return if Input.press?(THEO::CHEST::TRIGGER_GAIN_ALL)
  605.     super
  606.   end
  607.  
  608. end
  609.  
  610. class Window_ChestAmount < Window_Base  
  611.   attr_accessor :item_window
  612.   attr_accessor :mode
  613.   attr_reader   :amount
  614.  
  615.   def initialize
  616.     super(0,0,window_width,window_height)
  617.     self.openness = 0
  618.     @mode = :stash
  619.     reset_amount
  620.     update_position
  621.     refresh
  622.   end
  623.  
  624.   def inv_window=(window)
  625.     @inv_window = window
  626.   end
  627.  
  628.   def reset_amount
  629.     @amount = 0
  630.     refresh
  631.   end
  632.  
  633.   def open
  634.     super
  635.     reset_amount
  636.   end
  637.  
  638.   def update_position
  639.     self.x = (Graphics.width / 2) - (self.width / 2)
  640.     self.y = (Graphics.height / 2) - (self.height / 2)
  641.   end
  642.  
  643.   def refresh
  644.     contents.clear
  645.     draw_text(0,0,contents.width,24,THEO::CHEST::AMOUNT_VOCAB,)
  646.     draw_text(0,0,contents.width,24,@amount,2)
  647.   end
  648.  
  649.   def window_width
  650.     return 200
  651.   end
  652.  
  653.   def window_height
  654.     return 24+24
  655.   end
  656.  
  657.   def update
  658.     super
  659.     if @inv_window
  660.       @inv_window.add_number = @amount
  661.       @inv_window.item = @item_window.item if @item_window
  662.     end
  663.     if open?
  664.       increment if Input.repeat?(:RIGHT)
  665.       decrement if Input.repeat?(:LEFT)
  666.       ten_increment if Input.repeat?(:UP)
  667.       ten_decrement if Input.repeat?(:DOWN)
  668.     end
  669.   end
  670.  
  671.   def increment
  672.     change_amount(1)
  673.   end
  674.  
  675.   def decrement
  676.     change_amount(-1)
  677.   end
  678.  
  679.   def ten_increment
  680.     change_amount(10)
  681.   end
  682.  
  683.   def ten_decrement
  684.     change_amount(-10)
  685.   end
  686.  
  687.   def change_amount(modifier)
  688.     @amount = [[@amount+modifier,0].max,max_amount].min
  689.     refresh
  690.   end
  691.  
  692.   def show
  693.     super
  694.     reset_amount
  695.   end
  696.  
  697.   def max_amount
  698.     if $imported[:Theo_LimInventory]
  699.       if @mode == :inventory
  700.         @item_window.item_number rescue 0
  701.       elsif @mode == :stash
  702.         [@item_window.item_number,$game_party.inv_max_item(@item_window.item)].min
  703.       end
  704.     else
  705.       @item_window.item_number rescue 0
  706.     end
  707.   end
  708.  
  709. end
  710.  
  711. class Window_ChestFooter < Window_Base
  712.  
  713.   include THEO::CHEST
  714.  
  715.   def initialize(vocab,object,x)
  716.     w = Graphics.width/2
  717.     h = fitting_height(1)
  718.     y = Graphics.height - h
  719.     x = (Graphics.width/2) * x
  720.     @vocab = vocab
  721.     super(x,y,w,h)
  722.     @object = object
  723.     refresh
  724.   end
  725.  
  726.   def refresh
  727.     contents.clear
  728.     cx = text_size(@vocab).width
  729.     draw_text(0,0,contents.width,line_height,@vocab,1)
  730.   end
  731.  
  732. end
  733.  
  734. module DataManager
  735.  
  736.   class << self
  737.     alias pre_create_chest create_game_objects
  738.     alias pre_chest_save_contents make_save_contents
  739.     alias pre_extract_chests extract_save_contents
  740.   end
  741.  
  742.   def self.create_game_objects
  743.     pre_create_chest
  744.     create_chest_object
  745.   end
  746.  
  747.   def self.create_chest_object
  748.     $game_chests = Game_Chest.new
  749.   end
  750.  
  751.   def self.make_save_contents
  752.     contents = pre_chest_save_contents
  753.     contents[:chest] = $game_chests
  754.     contents
  755.   end
  756.  
  757.   def extract_save_contents(contents)
  758.     pre_extract_chests(contents)
  759.     $game_chests = contents[:chest]
  760.   end
  761.  
  762. end
  763.  
  764. class Game_Chest
  765.  
  766.   def initialize
  767.     @data = {}
  768.     @explored = {}
  769.   end
  770.  
  771.   def[](key)
  772.     (@data[key] ||= Game_Stash.new)
  773.   end
  774.  
  775.   def explored
  776.     @explored
  777.   end
  778.  
  779. end
  780.  
  781. class Game_Stash
  782.   attr_accessor :items_stash
  783.   attr_accessor :weapons_stash
  784.   attr_accessor :armors_stash
  785.  
  786.   def initialize
  787.     @items_stash = {}
  788.     @weapons_stash = {}
  789.     @armors_stash = {}
  790.   end
  791.  
  792.   def refresh
  793.     evaluate(@items_stash)
  794.     evaluate(@weapons_stash)
  795.     evaluate(@armors_stash)
  796.   end
  797.  
  798.   def evaluate(stash)
  799.     stash.keys.each do |key|
  800.       stash.delete(key) if stash[key] <= 0
  801.     end
  802.   end
  803.  
  804.   def items
  805.     @items_stash.keys.collect {|id| $data_items[id] }
  806.   end
  807.  
  808.   def weapons
  809.     @weapons_stash.keys.collect {|id| $data_weapons[id] }
  810.   end
  811.  
  812.   def armors
  813.     @armors_stash.keys.collect {|id| $data_armors[id] }
  814.   end
  815.  
  816.   def all_items
  817.     items + weapons + armors
  818.   end
  819.  
  820.   def item_number(item)
  821.     if item.is_a?(RPG::Item)
  822.       return @items_stash[item.id] ||= 0
  823.     elsif item.is_a?(RPG::Weapon)
  824.       return @weapons_stash[item.id] ||= 0
  825.     elsif item.is_a?(RPG::Armor)
  826.       return @armors_stash[item.id] ||= 0
  827.     end
  828.     refresh
  829.   end
  830.  
  831.   def gain_item(item, amount)
  832.     return unless item
  833.     stash = pick_stash(item)
  834.     stash[item.id] = 0 if stash[item.id].nil?
  835.     stash[item.id] += amount
  836.     refresh
  837.   end
  838.  
  839.   def lose_item(item,amount)
  840.     gain_item(item,-amount)
  841.   end
  842.  
  843.   def pick_stash(item)
  844.     if item.is_a?(RPG::Item)
  845.       return @items_stash
  846.     elsif item.is_a?(RPG::Weapon)
  847.       return @weapons_stash
  848.     elsif item.is_a?(RPG::Armor)
  849.       return @armors_stash
  850.     end
  851.   end
  852.  
  853. end
  854.  
  855. class Game_Party
  856.   attr_accessor :last_inv
  857.   attr_accessor :last_st
  858.  
  859.   alias pre_chest_init initialize
  860.   def initialize
  861.     pre_chest_init
  862.     init_chest_cursors
  863.   end
  864.  
  865.   def init_chest_cursors
  866.     @last_inv   = 0
  867.     @last_st = 0
  868.   end
  869.  
  870. end
  871.  
  872. class Game_Interpreter
  873.  
  874.   def open_chest(st_vocab = THEO::CHEST::ST_VOCAB,key = [@map_id,@event_id])
  875.     if st_vocab.is_a?(Numeric)
  876.       key = st_vocab
  877.       st_vocab = THEO::CHEST::ST_VOCAB
  878.     end
  879.     SceneManager.call_chest(key,st_vocab)
  880.   end
  881.  
  882.   alias pre_chest_command_108 command_108
  883.   def command_108
  884.     pre_chest_command_108
  885.     read_chest_comments
  886.   end
  887.  
  888.   def read_chest_comments
  889.     map = @map_id
  890.     event = @event_id
  891.     key = [map,event]
  892.     return if $game_chests.explored[key]
  893.     @comments.each do |comment|
  894.       case comment
  895.       when THEO::CHEST::REGEXP::ITEM_REGEX
  896.         x = $1.scan(/\d+/)
  897.         $game_chests[key].items_stash[x[0].to_i] = x[1].to_i
  898.       when THEO::CHEST::REGEXP::WEAPON_REGEX
  899.         x = $1.scan(/\d+/)
  900.         $game_chests[key].weapons_stash[x[0].to_i] = x[1].to_i
  901.       when THEO::CHEST::REGEXP::ARMOR_REGEX
  902.         x = $1.scan(/\d+/)
  903.         $game_chests[key].armors_stash[x[0].to_i] = x[1].to_i
  904.       end
  905.     end
  906.     $game_chests.explored[key] = next_event_code != 108
  907.   end
  908.  
  909. end
  910.  
  911. module SceneManager
  912.  
  913.   def self.call_chest(key,st_vocab = THEO::CHEST::ST_VOCAB)
  914.     @stack.push(@scene)
  915.     @scene = Scene_Chest.new(key,st_vocab)
  916.   end
  917.  
  918. end
Advertisement
Add Comment
Please, Sign In to add comment