This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Item Cap

By: AngryPacman on Jan 30th, 2012  |  syntax: Ruby  |  size: 14.03 KB  |  views: 154  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #===============================================================================
  2. #
  3. # Item Cap - Pacman (29/12/2011)
  4. # Version 2.3
  5. # Written for rgangsta (http://www.omega-dev.net/forums/showthread.php?tid=1280)
  6. # Suggestion by Scalinger2
  7. # Use the tag <item cap: x> to set the cap of an item to number x.
  8. # Use the tax \EXEMPT_CAP to make the windows not draw the cap at all in the
  9. # item and shop scenes.
  10. # Set the default maximum gold in the module below.
  11. # Set the default caps of items (when not set through notebox) in the module.
  12. # Change the TEXT if you want for some reason.
  13. # You can change the maximum amount of gold with the script call:
  14. # $game_system.gold_max = x
  15. # Where x is the maximum amount of gold.
  16. # Set which items can have their item cap drawn in the below module. The
  17. # available options are:
  18. #   :items
  19. #   :weapons
  20. #   :armors
  21. # New in 2.1: no longer crashes upon entering equip scene.
  22. # New in 2.2: no longer crashes upon entering shop scene.
  23. # New in 2.3: draws item name more efficiently.
  24. #
  25. #===============================================================================
  26. #
  27. # CONFIGURATION
  28. #
  29. #===============================================================================
  30.  
  31. module ITEM_CAP
  32.   GOLD_MAX = 40000    # Maximum amount of gold
  33.   DEFAULT_LIMIT = 50  # Default item cap (if not set through notebox)
  34.   TEXT = ": %s / %s"    # Text to display the cap
  35.   SHOW_CAP = [        # Show cap of which items?
  36.     :items,           # Items
  37.     :weapons,         # Weapons
  38.     :armors,          # Armors
  39.   ]
  40. end
  41.  
  42. #===============================================================================
  43. #
  44. # NO EDITING >:D
  45. #
  46. #===============================================================================
  47.  
  48. #==============================================================================
  49. # ** RPG::BaseItem
  50. #------------------------------------------------------------------------------
  51. # Superclass of Skill, Item, Weapon, and Armor.
  52. #==============================================================================
  53.  
  54. class RPG::BaseItem
  55.   #--------------------------------------------------------------------------
  56.   # * Maximum possession of item
  57.   #--------------------------------------------------------------------------
  58.   def item_cap
  59.     return if self.is_a?(RPG::Skill)  # Only items, weapons and armors
  60.     return @item_cap if @item_cap != nil  # Don't perform if already set
  61.     @item_cap = ITEM_CAP::DEFAULT_LIMIT
  62.     self.note.split(/[\r\n]+/).each { |line|
  63.       case line
  64.       when /<(?:ITEM_CAP|item cap):[ ](\d+)>/i
  65.         @item_cap = $1.to_i
  66.       end
  67.     }
  68.     return @item_cap
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # * Don't draw the item's cap
  72.   #--------------------------------------------------------------------------
  73.   def exempt_cap?
  74.     return if self.is_a?(RPG::Skill)
  75.     return @exempt if @exempt != nil
  76.     @exempt = false
  77.     self.note.split(/[\r\n]+/).each { |line|
  78.       case line
  79.       when /\\EXEMPT_CAP/i
  80.         @exempt = true
  81.       end
  82.     }
  83.     return @exempt
  84.   end
  85. end
  86.  
  87. #==============================================================================
  88. # ** Game_System
  89. #------------------------------------------------------------------------------
  90. #  This class handles system-related data. Also manages vehicles and BGM, etc.
  91. # The instance of this class is referenced by $game_system.
  92. #==============================================================================
  93.  
  94. class Game_System
  95.   #--------------------------------------------------------------------------
  96.   # Public Instance Variables
  97.   #--------------------------------------------------------------------------
  98.   attr_accessor :gold_cap
  99.   #--------------------------------------------------------------------------
  100.   # alias listing
  101.   #--------------------------------------------------------------------------
  102.   alias item_max_initialize initialize
  103.   #--------------------------------------------------------------------------
  104.   # * Object Initialization
  105.   #--------------------------------------------------------------------------
  106.   def initialize
  107.     item_max_initialize
  108.     @gold_cap = ITEM_CAP::GOLD_MAX
  109.   end
  110. end
  111.  
  112. #==============================================================================
  113. # ** Game_Party
  114. #------------------------------------------------------------------------------
  115. #  This class handles the party. It includes information on amount of gold
  116. # and items. The instance of this class is referenced by $game_party.
  117. #==============================================================================
  118.  
  119. class Game_Party < Game_Unit
  120.   #--------------------------------------------------------------------------
  121.   # alias listing
  122.   #--------------------------------------------------------------------------
  123.   alias item_max_gain_gold gain_gold
  124.   alias item_max_gain_item gain_item
  125.   #--------------------------------------------------------------------------
  126.   # * Gain Gold (or lose)
  127.   #     n : amount of gold
  128.   #--------------------------------------------------------------------------
  129.   def gain_gold(n)
  130.     new_gold = item_max_gain_gold(n)
  131.     @gold = [new_gold, $game_system.gold_cap].min
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * Gain Items (or lose)
  135.   #     item          : Item
  136.   #     n             : Number
  137.   #     include_equip : Include equipped items
  138.   #--------------------------------------------------------------------------
  139.   def gain_item(item, n, include_equip = false)
  140.     unless $scene.is_a?(Scene_Equip)
  141.       number = item_number(item)
  142.       cap = item.item_cap
  143.       case item
  144.       when RPG::Item
  145.         @items[item.id] = [[number + n, 0].max, cap].min
  146.       when RPG::Weapon
  147.         @weapons[item.id] = [[number + n, 0].max, cap].min
  148.       when RPG::Armor
  149.         @armors[item.id] = [[number + n, 0].max, cap].min
  150.       end
  151.       n += number
  152.       if include_equip and n < 0
  153.         for actor in members
  154.           while n < 0 and actor.equips.include?(item)
  155.             actor.discard_equip(item)
  156.             n += 1
  157.           end
  158.         end
  159.       end
  160.     else
  161.       item_max_gain_item(item, n, include_equip)
  162.     end
  163.   end
  164. end
  165.  
  166. #==============================================================================
  167. # ** Window_Base
  168. #------------------------------------------------------------------------------
  169. #  This is a superclass of all windows in the game.
  170. #==============================================================================
  171.  
  172. class Window_Base
  173.   #--------------------------------------------------------------------------
  174.   # * Draw Item Name
  175.   #     item    : Item (skill, weapon, armor are also possible)
  176.   #     x       : draw spot x-coordinate
  177.   #     y       : draw spot y-coordinate
  178.   #     enabled : Enabled flag. When false, draw semi-transparently.
  179.   #     ctext   : Text to display the cap.
  180.   #--------------------------------------------------------------------------
  181.   def draw_item_name(item, x, y, enabled = true, ctext = "")
  182.     if item != nil
  183.       w = self.contents.text_size(ctext).width - 48
  184.       draw_icon(item.icon_index, x, y, enabled)
  185.       self.contents.font.color = normal_color
  186.       self.contents.font.color.alpha = enabled ? 255 : 128
  187.       self.contents.draw_text(x + 24, y, 172 - w, WLH, item.name)
  188.     end
  189.   end
  190. end
  191.  
  192. #==============================================================================
  193. # ** Window_Item
  194. #------------------------------------------------------------------------------
  195. #  This window displays a list of inventory items for the item screen, etc.
  196. #==============================================================================
  197.  
  198. class Window_Item < Window_Selectable
  199.   #--------------------------------------------------------------------------
  200.   # alias listing
  201.   #--------------------------------------------------------------------------
  202.   alias item_cap_draw_item draw_item
  203.   #--------------------------------------------------------------------------
  204.   # * Draw Item
  205.   #     index : item number
  206.   #--------------------------------------------------------------------------
  207.   def draw_item(index)
  208.     if draw_cap?(index)
  209.       rect = item_rect(index)
  210.       self.contents.clear_rect(rect)
  211.       item = @data[index]
  212.       if item != nil
  213.         number1 = $game_party.item_number(item); number2 = item.item_cap
  214.         enabled = enable?(item)
  215.         rect.width -= 4
  216.         ctext = sprintf(ITEM_CAP::TEXT, number1, number2)
  217.         draw_item_name(item, rect.x, rect.y, enabled, ctext)
  218.         self.contents.draw_text(rect, ctext, 2)
  219.       end
  220.     else
  221.       item_cap_draw_item(index)
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * Determine whether or not to draw cap
  226.   #     item : item to be checked
  227.   #--------------------------------------------------------------------------
  228.   def draw_cap?(index)
  229.     check = ITEM_CAP::SHOW_CAP
  230.     item = @data[index]
  231.     return true if item == nil and $scene.is_a?(Scene_Equip)
  232.     return false if item.exempt_cap?
  233.     return true if check.include?(:items) and item.is_a?(RPG::Item)
  234.     return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
  235.     return true if check.include?(:armors) and item.is_a?(RPG::Armor)
  236.     return false
  237.   end
  238. end
  239.  
  240. #==============================================================================
  241. # ** Window_ShopBuy
  242. #------------------------------------------------------------------------------
  243. #  This window displays buyable goods on the shop screen.
  244. #==============================================================================
  245.  
  246. class Window_ShopBuy < Window_Selectable
  247.   #--------------------------------------------------------------------------
  248.   # * Draw Item
  249.   #     index : item number
  250.   #--------------------------------------------------------------------------
  251.   def draw_item(index)
  252.     item = @data[index]
  253.     number = $game_party.item_number(item)
  254.     enabled = (item.price <= $game_party.gold and number < item.item_cap)
  255.     rect = item_rect(index)
  256.     self.contents.clear_rect(rect)
  257.     draw_item_name(item, rect.x, rect.y, enabled)
  258.     rect.width -= 4
  259.     self.contents.draw_text(rect, item.price, 2)
  260.   end
  261. end
  262.  
  263. #==============================================================================
  264. # ** Window_ShopStatus
  265. #------------------------------------------------------------------------------
  266. #  This window displays number of items in possession and the actor's equipment
  267. # on the shop screen.
  268. #==============================================================================
  269.  
  270. class Window_ShopStatus < Window_Base
  271.   #--------------------------------------------------------------------------
  272.   # Alias listing
  273.   #--------------------------------------------------------------------------
  274.   alias item_cap_refresh refresh
  275.   #--------------------------------------------------------------------------
  276.   # * Refresh
  277.   #--------------------------------------------------------------------------
  278.   def refresh
  279.     if draw_cap?(@item)
  280.       self.contents.clear
  281.       if @item != nil
  282.         number = $game_party.item_number(@item); cap = @item.item_cap
  283.         text = sprintf(ITEM_CAP::TEXT, number, cap)
  284.         self.contents.font.color = system_color
  285.         self.contents.draw_text(4, 0, 200, WLH, Vocab::Possession)
  286.         self.contents.font.color = normal_color
  287.         self.contents.draw_text(4, 0, 200, WLH, text, 2)
  288.         for actor in $game_party.members
  289.           x = 4
  290.           y = WLH * (2 + actor.index * 2)
  291.           draw_actor_parameter_change(actor, x, y)
  292.         end
  293.       end
  294.     else
  295.       item_cap_refresh
  296.     end
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # * Determine whether or not to draw cap
  300.   #     item : item to be checked
  301.   #--------------------------------------------------------------------------
  302.   def draw_cap?(index)
  303.     check = ITEM_CAP::SHOW_CAP
  304.     item = @item
  305.     return true unless item
  306.     return false if item.exempt_cap?
  307.     return true if check.include?(:items) and item.is_a?(RPG::Item)
  308.     return true if check.include?(:weapons) and item.is_a?(RPG::Weapon)
  309.     return true if check.include?(:armors) and item.is_a?(RPG::Armor)
  310.     return false
  311.   end
  312. end
  313.  
  314. #==============================================================================
  315. # ** Scene_Shop
  316. #------------------------------------------------------------------------------
  317. #  This class performs shop screen processing.
  318. #==============================================================================
  319.  
  320. class Scene_Shop < Scene_Base
  321.   #--------------------------------------------------------------------------
  322.   # * Update Buy Item Selection
  323.   #--------------------------------------------------------------------------
  324.   def update_buy_selection
  325.     @status_window.item = @buy_window.item
  326.     if Input.trigger?(Input::B)
  327.       Sound.play_cancel
  328.       @command_window.active = true
  329.       @dummy_window.visible = true
  330.       @buy_window.active = false
  331.       @buy_window.visible = false
  332.       @status_window.visible = false
  333.       @status_window.item = nil
  334.       @help_window.set_text("")
  335.       return
  336.     end
  337.     if Input.trigger?(Input::C)
  338.       @item = @buy_window.item
  339.       number = $game_party.item_number(@item)
  340.       if @item == nil or @item.price > $game_party.gold or
  341.        number == @item.item_cap
  342.         Sound.play_buzzer
  343.       else
  344.         Sound.play_decision
  345.         max = @item.price == 0 ? @item.item_cap : $game_party.gold / @item.price
  346.         max = [max, @item.item_cap - number].min
  347.         @buy_window.active = false
  348.         @buy_window.visible = false
  349.         @number_window.set(@item, max, @item.price)
  350.         @number_window.active = true
  351.         @number_window.visible = true
  352.       end      
  353.     end
  354.   end
  355. end
  356.  
  357. $imported = {} unless $imported
  358. $imported["Pacman Item Cap"] = [2.3]
  359.  
  360. #===============================================================================
  361. #
  362. # END OF SCRIPT
  363. #
  364. #===============================================================================
clone this paste RAW Paste Data