TheoAllen

Theo - Chest System

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