Advertisement
mrbubble

Limit Sell Items to Buy Item Selections

Dec 31st, 2011
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.85 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Limit Sell Items to Buy Item Selections - v1.1 (1/01/12)
  3. #==============================================================================
  4. # Original RMVX/RGSS2 script by:
  5. #             Mithran
  6. # Ported to RMVXA/RGSS3 by:
  7. #             Mr. Bubble
  8. #--------------------------------------------------------------------------
  9. # This script restricts the types of items the player can sell to a shop
  10. # to only what the player can buy from the shop. Sellable item restrictions
  11. # can optionally be turned off or on with a game switch.
  12. #
  13. # Original script port request by Seiryuki.
  14. #--------------------------------------------------------------------------
  15. # ++ This script aliases the following methods:
  16. #       Scene_Shop#create_sell_window
  17. #==============================================================================
  18.  
  19. #--------------------------------------------------------------------------
  20. # ++ Customization Module - START
  21. #--------------------------------------------------------------------------
  22.  
  23. module Bubs
  24.   module MithranLimitSellItems
  25.   # ++ Limit Shop Default
  26.   #    Determines whether all shops only buyback items they can
  27.   #    sell by default
  28.   LIMIT_SHOP_SELL_DEFAULT = true
  29.  
  30.   # ++ Limit Shop Game Switch
  31.   #    Set whether you want a game switch ID to determine when Limit Shop
  32.   #    is active. Otherwise, you can leave it as nil.
  33.   LIMIT_SHOP_SELL_SWITCH = nil
  34.  
  35.   end
  36. end
  37.  
  38. #--------------------------------------------------------------------------
  39. # ++ Customization Module - END
  40. #--------------------------------------------------------------------------
  41.  
  42. $imported = {} if $imported.nil?
  43. $imported["MithranLimitSellItems"] = true
  44.  
  45. #==============================================================================
  46. # ++ Window_LimitShopSell : new class
  47. #==============================================================================
  48. # $game_temp.shop_goods no longer exists in RGSS3. Because of this, a new
  49. # class was created.
  50.  
  51. class Window_LimitShopSell < Window_ShopSell
  52.   #--------------------------------------------------------------------------
  53.   # ++ Object Initialization
  54.   #     x      : window x-coordinate
  55.   #     y      : window y-coordinate
  56.   #     width  : window width
  57.   #     height : window height
  58.   #     shop_goods : array of shop goods
  59.   #--------------------------------------------------------------------------
  60.   def initialize(x, y, width, height, shop_goods)
  61.     super(x, y, width, height)
  62.     @shop_goods = shop_goods
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # ++ Whether or not to include in item list
  66.   #     item : item
  67.   #--------------------------------------------------------------------------
  68.   def include?(item)
  69.     return false if @shop_goods.nil?
  70.     return false if item.nil?
  71.     for pair in @shop_goods
  72.       case @category
  73.       when :item
  74.         if item.is_a?(RPG::Item) && !item.key_item?
  75.           return true if pair[0] == 0 && pair[1] == item.id
  76.         end
  77.       when :weapon
  78.         if item.is_a?(RPG::Weapon)
  79.           return true if pair[0] == 1 && pair[1] == item.id
  80.         end
  81.       when :armor
  82.         if item.is_a?(RPG::Armor)
  83.           return true if pair[0] == 2 && pair[1] == item.id
  84.         end
  85.       when :key_item
  86.         if item.is_a?(RPG::Item) && item.key_item?
  87.           return true if pair[0] == 0 && pair[1] == item.id
  88.         end
  89.       else
  90.         return false
  91.       end # case
  92.     end # for
  93.     return false
  94.   end # def include?(item)
  95. end # class
  96.  
  97. #==============================================================================
  98. # ++ Scene_Shop
  99. #==============================================================================
  100. class Scene_Shop < Scene_MenuBase
  101.   #--------------------------------------------------------------------------
  102.   # ++ create_sell_window : alias
  103.   #--------------------------------------------------------------------------
  104.   alias create_sell_window_limit_shop_sell create_sell_window
  105.   def create_sell_window
  106.     if Bubs::MithranLimitSellItems::LIMIT_SHOP_SELL_DEFAULT ||
  107.                 $game_switches[Bubs::MithranLimitSellItems::LIMIT_SHOP_SELL_SWITCH]
  108.                
  109.       wy = @category_window.y + @category_window.height
  110.       wh = Graphics.height - wy
  111.       # changed to Window_LimitShopSell.new
  112.       @sell_window = Window_LimitShopSell.new(0, wy, Graphics.width, wh, @goods)
  113.       @sell_window.viewport = @viewport
  114.       @sell_window.help_window = @help_window
  115.       @sell_window.hide
  116.       @sell_window.set_handler(:ok,     method(:on_sell_ok))
  117.       @sell_window.set_handler(:cancel, method(:on_sell_cancel))
  118.       @category_window.item_window = @sell_window
  119.     else
  120.       create_sell_window_limit_shop_sell # alias
  121.     end # if
  122.   end # def create_sell_window
  123. end # class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement