Advertisement
Demonicskyers

Depozyt/Item Storage

Jul 29th, 2013
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.24 KB | None | 0 0
  1. #===============================================================================
  2. # Item Storage
  3. # Author game_guy
  4. # Version 1.42
  5. #-------------------------------------------------------------------------------
  6. # Intro:
  7. # Okay. Well if you've played the Elder Scrolls Series or Fallout then you'd
  8. # know that it has an item storage system. What it does is lets you open up
  9. # closets, chests, ect and store and take items out of it.
  10. #
  11. # Features:
  12. # Store and Take Items Out of Chests, Closets, ect
  13. # Have Seperate Chests, Closets, ect
  14. # Easy to Use
  15. # Stores Chests into Game System Instead of Variables
  16. # Have Max Amount of Items In Chest
  17. # Set Default Items in Chest
  18. # Mark Items as "Key Items" to prevent removal from inventory (e.g. "Quest Items")
  19. # Take All/Store All Items in Chest (Not built into scene)
  20. #
  21. # Instructions:
  22. # First lets go over the syntaxes.
  23. #
  24. # Calling the Item Storage:
  25. # $scene = Scene_Chest.new(chest_id, max_items)
  26. # chest_id is the number chest you want open
  27. # max_items is the max amount of any item the chest can hold
  28. # you can just use this to
  29. # $scene = Scene_Chest.new(chest_id)
  30. # because in the config this ChestMaxItems is the default so if you dont use
  31. # the long one, it'll use the default.
  32. #
  33. # New Syntaxes:
  34. # You can now take all items from a chest and empty your entire inventory
  35. # into a chest. While this isn't built into the scene, you'll have to do this
  36. # through a script call.
  37. # -Take All
  38. #   chest = $game_system.chests(chest_id)
  39. #   chest.take_all
  40. # -Empty Inventory
  41. #   chest = $game_system.chests(chest_id)
  42. #   chest.empty_all
  43. #
  44. # You can now add/remove items to and from chests.
  45. #   chest = $game_system.chests(chest_id)
  46. #   chest.aaa_bbb(ccc, ddd)
  47. #   aaa = add/take
  48. #   bbb = item/weapon/armor
  49. #   ccc = item/weapon/armor id
  50. #   ddd = amount
  51. #
  52. # Okay so thats done with the syntaxes. Now onto the configuration.
  53. # Go down to Begin Config and do all your configuration there.
  54. #
  55. # Credits:
  56. # game_guy ~ for making it
  57. # MightyLink ~ requesting the system
  58. #===============================================================================
  59. module GameGuy
  60.   #============================================================================
  61.   # KeyItemId       = Element ID for non removable items.
  62.   #                   Items/weapons/armors with marked with this element
  63.   #                   cannot be removed.
  64.   #============================================================================
  65.   KeyItemId         = 17
  66.  
  67.   #============================================================================
  68.   # ChestMaxItems   = The max amount of any item a chest can hold. So example
  69.   #                   Its 9999 so it can have 9999 of any item.
  70.   #============================================================================
  71.   ChestMaxItems     = 9999
  72.   def self.chest_items(id)
  73.     case id
  74.     #==========================================================================
  75.     # Config Chest Items
  76.     # Use this
  77.     # when chest_id then return [[id, amount, type], [id, amount, type]]
  78.     # id = item, weapon, or armor id
  79.     # amount = the amount
  80.     # type = 0, 1, or 2 0 = item, 1 = weapon, 2 = armor
  81.     # Example:
  82.     # when 1 then return [[1, 3, 0], [1, 1, 1]]
  83.     # This has 3 potions, and 1 bronze sword. So when this is called
  84.     # $scene = Scene_Chest.new(1)
  85.     # it will have those items in the chest already.
  86.     #==========================================================================
  87.     when 1 then return [[1, 999, 0], [1, 1, 1]]
  88.     when 2 then return [[1, 10, 0], [1, 1, 2], [1, 2, 1]]
  89.     when 3 then return [[1, 10, 2], [3, 1, 1], [9, 1, 1]]
  90.     when 5 then return [[33, 1, 0]]
  91.     when 6 then return [[1, 50, 2], [3, 1, 1]]
  92.     end
  93.     return []
  94.   end
  95. end
  96.  
  97. #==============================================================================
  98. # Game_System
  99. #------------------------------------------------------------------------------
  100. # Modded it so it makes it store every chest.
  101. #==============================================================================
  102. class Game_System
  103.   alias gg_add_item_storage initialize
  104.   def initialize
  105.     @chests = []
  106.     return gg_add_item_storage
  107.   end
  108.   def chests(n)
  109.     if @chests[n] == nil
  110.       @chests[n] = Game_Chest.new(GameGuy::ChestMaxItems)
  111.       items = GameGuy.chest_items(n)
  112.       for i in 0...items.size
  113.         item = items[i][2]
  114.         case item
  115.         when 0
  116.           @chests[n].add_item(items[i][0], items[i][1])
  117.         when 1
  118.           @chests[n].add_weapon(items[i][0], items[i][1])
  119.         when 2
  120.           @chests[n].add_armor(items[i][0], items[i][1])
  121.         else
  122.           @chests[n].add_item(items[i][0], items[i][1])
  123.         end
  124.       end
  125.     end
  126.     return @chests[n]
  127.   end
  128. end
  129.  
  130. #==============================================================================
  131. # Game_Chest
  132. #------------------------------------------------------------------------------
  133. # Holds all the data for a single chest.
  134. #==============================================================================
  135. class Game_Chest
  136.   attr_accessor :max
  137.   def initialize(max = GameGuy::ChestMaxItems)
  138.     @max = max
  139.     @items = {}
  140.     @weapons = {}
  141.     @armors = {}
  142.   end
  143.   def item_amount(item_id)
  144.     return @items.include?(item_id) ? @items[item_id] : 0
  145.   end
  146.   def weapon_amount(weapon_id)
  147.     return @weapons.include?(weapon_id) ? @weapons[weapon_id] : 0
  148.   end
  149.   def armor_amount(armor_id)
  150.     return @armors.include?(armor_id) ? @armors[armor_id] : 0
  151.   end
  152.   def add_item(item_id, n)
  153.     if item_id > 0
  154.       @items[item_id] = [[item_amount(item_id) + n, 0].max, @max].min
  155.     end
  156.   end
  157.   def add_weapon(weapon_id, n)
  158.     if weapon_id > 0
  159.       @weapons[weapon_id] = [[weapon_amount(weapon_id) + n, 0].max, @max].min
  160.     end
  161.   end
  162.   def add_armor(armor_id, n)
  163.     if armor_id > 0
  164.       @armors[armor_id] = [[armor_amount(armor_id) + n, 0].max, @max].min
  165.     end
  166.   end
  167.   def take_item(item_id, n)
  168.     add_item(item_id, -n)
  169.   end
  170.   def take_weapon(weapon_id, n)
  171.     add_weapon(weapon_id, -n)
  172.   end
  173.   def take_armor(armor_id, n)
  174.     add_armor(armor_id, -n)
  175.   end
  176.   def empty_all
  177.     for i in 1...$data_items.size
  178.       if $game_party.item_number(i) > 0
  179.         add_item(i, $game_party.item_number(i))
  180.         $game_party.lose_item(i, $game_party.item_number(i))
  181.       end
  182.     end
  183.     for i in 1...$data_weapons.size
  184.       if $game_party.weapon_number(i) > 0
  185.         add_weapon(i, $game_party.weapon_number(i))
  186.         $game_party.lose_weapon(i, $game_party.weapon_number(i))
  187.       end
  188.     end
  189.     for i in 1...$data_armors.size
  190.       if $game_party.armor_number(i) > 0
  191.        add_armor(i, $game_party.armor_number(i))
  192.        $game_party.lose_armor(i, $game_party.armor_number(i))
  193.       end
  194.     end
  195.   end
  196.   def take_all
  197.     for i in 1...$data_items.size
  198.       if item_amount(i) > 0
  199.         n = [99, ($game_party.item_number(i) - item_amount(i)).abs].min
  200.         $game_party.gain_item(i, n)
  201.         take_item(i, n)
  202.       end
  203.     end
  204.     for i in 1...$data_weapons.size
  205.       if weapon_amount(i) > 0
  206.         n = [99, ($game_party.weapon_number(i) - weapon_amount(i)).abs].min
  207.         $game_party.gain_weapon(i, n)
  208.         take_weapon(i, n)
  209.       end
  210.     end
  211.     for i in 1...$data_armors.size
  212.       if armor_amount(i) > 0
  213.          n = [99, ($game_party.armor_number(i) - armor_amount(i)).abs].min
  214.         $game_party.gain_armor(i, n)
  215.         take_armor(i, n)
  216.       end
  217.     end
  218.   end
  219. end
  220.  
  221. #==============================================================================
  222. # Window_Chest_Choices
  223. #------------------------------------------------------------------------------
  224. # The choices for the chest when the scene is opened.
  225. #==============================================================================
  226. class Window_Chest_Choices < Window_Selectable
  227.   def initialize
  228.     super(0, 0, 640, 64)
  229.     self.contents = Bitmap.new(width - 32, height - 32)
  230.     @item_max = 3
  231.     @column_max = 3
  232.     @commands = ["Zdeponuj", "Pobierz", "WyjdΕΊ"]
  233.     self.z = 200
  234.     refresh
  235.     self.index = 0
  236.   end
  237.   def refresh
  238.     self.contents.clear
  239.     for i in 0...@item_max
  240.       draw_item(i)
  241.     end
  242.   end
  243.   def draw_item(index)
  244.     x = 4 + index * 215
  245.     self.contents.draw_text(x, 0, 128, 32, @commands[index], 1)
  246.   end
  247. end
  248.  
  249. #==============================================================================
  250. # Window_Chest_Item
  251. #------------------------------------------------------------------------------
  252. # Displays all items in the chest.
  253. #==============================================================================
  254. class Window_Chest_Item < Window_Selectable
  255.   def initialize(chest)
  256.     super(320, 64, 320, 416)
  257.     @chest = chest
  258.     @column_max = 1
  259.     refresh
  260.     self.index = 0
  261.     if $game_temp.in_battle
  262.       self.y = 64
  263.       self.height = 256
  264.       self.back_opacity = 160
  265.     end
  266.   end
  267.   def item
  268.     return @data[self.index]
  269.   end
  270.   def refresh
  271.     if self.contents != nil
  272.       self.contents.dispose
  273.       self.contents = nil
  274.     end
  275.     @data = []
  276.     for i in 1...$data_items.size
  277.       if @chest.item_amount(i) > 0
  278.         @data.push($data_items[i])
  279.       end
  280.     end
  281.     unless $game_temp.in_battle
  282.       for i in 1...$data_weapons.size
  283.         if @chest.weapon_amount(i) > 0
  284.           @data.push($data_weapons[i])
  285.         end
  286.       end
  287.       for i in 1...$data_armors.size
  288.         if @chest.armor_amount(i) > 0
  289.           @data.push($data_armors[i])
  290.         end
  291.       end
  292.     end
  293.     @item_max = @data.size
  294.     if @item_max > 0
  295.       self.contents = Bitmap.new(width - 32, row_max * 32)
  296.       for i in 0...@item_max
  297.         draw_item(i)
  298.       end
  299.     end
  300.   end
  301.   def draw_item(index)
  302.     item = @data[index]
  303.     self.contents.font.color = normal_color
  304.     if item.is_a?(RPG::Weapon) || item.is_a?(RPG::Item)
  305.       if item.element_set.include?(GameGuy::KeyItemId)
  306.         self.contents.font.color = disabled_color
  307.       end
  308.     else
  309.       if item.guard_element_set.include?(GameGuy::KeyItemId)
  310.         self.contents.font.color = disabled_color
  311.       end
  312.     end
  313.     case item
  314.     when RPG::Item
  315.       number = @chest.item_amount(item.id)
  316.     when RPG::Weapon
  317.       number = @chest.weapon_amount(item.id)
  318.     when RPG::Armor
  319.       number = @chest.armor_amount(item.id)
  320.     end
  321.     x = 4 + index % @column_max * (288 + 32)
  322.     y = index / @column_max * 32
  323.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  324.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  325.     bitmap = RPG::Cache.icon(item.icon_name)
  326.     opacity = self.contents.font.color == normal_color ? 255 : 128
  327.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  328.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  329.     self.contents.draw_text(x + 216, y, 16, 32, ":", 1)
  330.     self.contents.draw_text(x + 224, y, 48, 32, number.to_s, 2)
  331.   end
  332.   def update_help
  333.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  334.   end
  335. end
  336.  
  337. #==============================================================================
  338. # Window_Party_Item
  339. #------------------------------------------------------------------------------
  340. # Displays all items the party has.
  341. #==============================================================================
  342. class Window_Party_Item < Window_Selectable
  343.   def initialize
  344.     super(0, 64, 320, 416)
  345.     @column_max = 1
  346.     refresh
  347.     self.index = 0
  348.     if $game_temp.in_battle
  349.       self.y = 64
  350.       self.height = 256
  351.       self.back_opacity = 160
  352.     end
  353.   end
  354.   def item
  355.     return @data[self.index]
  356.   end
  357.   def refresh
  358.     if self.contents != nil
  359.       self.contents.dispose
  360.       self.contents = nil
  361.     end
  362.     @data = []
  363.     for i in 1...$data_items.size
  364.       if $game_party.item_number(i) > 0
  365.         @data.push($data_items[i])
  366.       end
  367.     end
  368.     unless $game_temp.in_battle
  369.       for i in 1...$data_weapons.size
  370.         if $game_party.weapon_number(i) > 0
  371.           @data.push($data_weapons[i])
  372.         end
  373.       end
  374.       for i in 1...$data_armors.size
  375.         if $game_party.armor_number(i) > 0
  376.           @data.push($data_armors[i])
  377.         end
  378.       end
  379.     end
  380.     @item_max = @data.size
  381.     if @item_max > 0
  382.       self.contents = Bitmap.new(width - 32, row_max * 32)
  383.       for i in 0...@item_max
  384.         draw_item(i)
  385.       end
  386.     end
  387.   end
  388.   def draw_item(index)
  389.     item = @data[index]
  390.     self.contents.font.color = normal_color
  391.     if item.is_a?(RPG::Weapon) || item.is_a?(RPG::Item)
  392.       if item.element_set.include?(GameGuy::KeyItemId)
  393.         self.contents.font.color = disabled_color
  394.       end
  395.     else
  396.       if item.guard_element_set.include?(GameGuy::KeyItemId)
  397.         self.contents.font.color = disabled_color
  398.       end
  399.     end
  400.     case item
  401.     when RPG::Item
  402.       number = $game_party.item_number(item.id)
  403.     when RPG::Weapon
  404.       number = $game_party.weapon_number(item.id)
  405.     when RPG::Armor
  406.       number = $game_party.armor_number(item.id)
  407.     end
  408.     x = 4 + index % @column_max * (288 + 32)
  409.     y = index / @column_max * 32
  410.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  411.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  412.     bitmap = RPG::Cache.icon(item.icon_name)
  413.     opacity = self.contents.font.color == normal_color ? 255 : 128
  414.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  415.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  416.     self.contents.draw_text(x + 216, y, 16, 32, ":", 1)
  417.     self.contents.draw_text(x + 224, y, 48, 32, number.to_s, 2)
  418.   end
  419.   def update_help
  420.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  421.   end
  422. end
  423.  
  424. #==============================================================================
  425. # Scene_Chest
  426. #------------------------------------------------------------------------------
  427. # The scene that controls storing and taking items.
  428. #==============================================================================
  429. class Scene_Chest
  430.   def initialize(chest=1, max=GameGuy::ChestMaxItems)
  431.     @chestid = chest
  432.     @chest = $game_system.chests(@chestid)
  433.   end
  434.   def main
  435.     @help_window = Window_Help.new
  436.     @help_window.visible = false
  437.     @command_window = Window_Chest_Choices.new
  438.     @party_window = Window_Party_Item.new
  439.     @party_window.active = false
  440.     @chest_window = Window_Chest_Item.new(@chest)
  441.     @chest_window.active = false
  442.     Graphics.transition
  443.     loop do
  444.       Graphics.update
  445.       Input.update
  446.       update
  447.       if $scene != self
  448.         break
  449.       end
  450.     end
  451.     @help_window.dispose
  452.     @command_window.dispose
  453.     @party_window.dispose
  454.     @chest_window.dispose
  455.   end
  456.   def update
  457.     @help_window.update
  458.     @command_window.update
  459.     @party_window.update
  460.     @chest_window.update
  461.     if @command_window.active
  462.       update_command
  463.       return
  464.     end
  465.     if @party_window.active
  466.       update_party
  467.       return
  468.     end
  469.     if @chest_window.active
  470.       update_chest
  471.       return
  472.     end
  473.   end
  474.   def update_command
  475.     if Input.trigger?(Input::B)
  476.       $game_system.se_play($data_system.cancel_se)
  477.       $scene = Scene_Map.new
  478.       return
  479.     end
  480.     if Input.trigger?(Input::C)
  481.       case @command_window.index
  482.       when 0
  483.         $game_system.se_play($data_system.decision_se)
  484.         @party_window.active = true
  485.         @party_window.help_window = @help_window
  486.         @command_window.active = false
  487.         @help_window.z = 500
  488.         @help_window.visible = true
  489.       when 1
  490.         $game_system.se_play($data_system.decision_se)
  491.         @chest_window.active = true
  492.         @chest_window.help_window = @help_window
  493.         @command_window.active = false
  494.         @help_window.z = 500
  495.         @help_window.visible = true
  496.       when 2
  497.         $game_system.se_play($data_system.cancel_se)
  498.         $scene = Scene_Map.new
  499.       end
  500.       return
  501.     end
  502.   end
  503.   def update_party
  504.     if Input.trigger?(Input::B)
  505.       $game_system.se_play($data_system.cancel_se)
  506.       @command_window.active = true
  507.       @help_window.visible = false
  508.       @party_window.help_window = nil
  509.       @party_window.active = false
  510.       return
  511.     end
  512.     if Input.repeat?(Input::C)
  513.       @item = @party_window.item
  514.       unless @item.is_a?(RPG::Item) or @item.is_a?(RPG::Weapon) or
  515.              @item.is_a?(RPG::Armor)
  516.         $game_system.se_play($data_system.buzzer_se)
  517.         return
  518.       end
  519.       if @item.element_set.include?(GameGuy::KeyItemId)
  520.         $game_system.se_play($data_system.buzzer_se)
  521.         return
  522.       end
  523.       case @item
  524.       when RPG::Item
  525.         amount = @chest.item_amount(@item.id)
  526.         if amount < @chest.max
  527.           $game_system.se_play($data_system.decision_se)
  528.           @chest.add_item(@item.id, 1)
  529.           $game_party.lose_item(@item.id, 1)
  530.         else
  531.           $game_system.se_play($data_system.buzzer_se)
  532.           return
  533.         end
  534.       when RPG::Weapon
  535.         amount = @chest.weapon_amount(@item.id)
  536.         if amount < @chest.max
  537.           $game_system.se_play($data_system.decision_se)
  538.           @chest.add_weapon(@item.id, 1)
  539.           $game_party.lose_weapon(@item.id, 1)
  540.         else
  541.           $game_system.se_play($data_system.buzzer_se)
  542.           return
  543.         end
  544.       when RPG::Armor
  545.         amount = @chest.armor_amount(@item.id)
  546.         if amount < @chest.max
  547.           $game_system.se_play($data_system.decision_se)
  548.           @chest.add_armor(@item.id, 1)
  549.           $game_party.lose_armor(@item.id, 1)
  550.         else
  551.           $game_system.se_play($data_system.buzzer_se)
  552.           return
  553.         end
  554.       end
  555.       @party_window.refresh
  556.       @chest_window.refresh
  557.       return
  558.     end
  559.   end
  560.   def update_chest
  561.     if Input.trigger?(Input::B)
  562.       $game_system.se_play($data_system.cancel_se)
  563.       @command_window.active = true
  564.       @help_window.visible = false
  565.       @chest_window.help_window = nil
  566.       @chest_window.active = false
  567.       return
  568.     end
  569.     if Input.repeat?(Input::C)
  570.       @item = @chest_window.item
  571.       unless @item.is_a?(RPG::Item) or @item.is_a?(RPG::Weapon) or
  572.              @item.is_a?(RPG::Armor)
  573.         $game_system.se_play($data_system.buzzer_se)
  574.         return
  575.       end
  576.       case @item
  577.       when RPG::Item
  578.         amount = $game_party.item_number(@item.id)
  579.         if amount < 99
  580.           $game_system.se_play($data_system.decision_se)
  581.           @chest.take_item(@item.id, 1)
  582.           $game_party.gain_item(@item.id, 1)
  583.         else
  584.           $game_system.se_play($data_system.buzzer_se)
  585.           return
  586.         end
  587.       when RPG::Weapon
  588.         amount = $game_party.weapon_number(@item.id)
  589.         if amount < 99
  590.           $game_system.se_play($data_system.decision_se)
  591.           @chest.take_weapon(@item.id, 1)
  592.           $game_party.gain_weapon(@item.id, 1)
  593.         else
  594.           $game_system.se_play($data_system.buzzer_se)
  595.           return
  596.         end
  597.       when RPG::Armor
  598.         amount = $game_party.armor_number(@item.id)
  599.         if amount < 99
  600.           $game_system.se_play($data_system.decision_se)
  601.           @chest.take_armor(@item.id, 1)
  602.           $game_party.gain_armor(@item.id, 1)
  603.         else
  604.           $game_system.se_play($data_system.buzzer_se)
  605.           return
  606.         end
  607.       end
  608.       @party_window.refresh
  609.       @chest_window.refresh
  610.       return
  611.     end
  612.   end
  613.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement