Advertisement
MrTrivel

MrTS_Shop_New_Items_On_Sell

Jun 12th, 2014
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.07 KB | None | 0 0
  1. # )--------------------------------------------------(
  2. # )--     Author:     Mr Trivel                    --(
  3. # )--     Name:       New Items in Shop on Sell    --(
  4. # )--     Created:    2014-06-12                   --(
  5. # )--     Version:    1.0                          --(
  6. # )--------------------------------------------------(
  7. # )--     Requires:   None                         --(
  8. # )--------------------------------------------------(
  9. # )--             Description                      --(
  10. # )--  Instead of having default shop where you    --(
  11. # )--  list items in it. Now you can call another  --(
  12. # )--  type of shop. Which gets new items as you   --(
  13. # )--  sell specific items to it.                  --(
  14. # )--  E.g. Sell 5 Copper Ore to unlock Copper     --(
  15. # )--  Dagger.                                     --(
  16. # )--  (You can still use normal shop, too!)       --(
  17. # )--------------------------------------------------(
  18. # )--             Instructions                     --(
  19. # )--  Call the shop by using:                     --(
  20. # )--  SceneManager.call(MrTS_Dynamic_Shop)        --(
  21. # )--                                              --(
  22. # )--  In item's note tag, write:                  --(
  23. # )--  <Shop:                                      --(
  24. # )--  i: X, Y                                     --(
  25. # )--  >                                           --(
  26. # )--                                              --(
  27. # )--  i - item, w - weapon, a - armor             --(
  28. # )--  X - ID of the item/weapon/armor             --(
  29. # )--  Y - Quantity                                --(
  30. # )--                                              --(
  31. # )--  E.g.                                        --(
  32. # )--  <Shop:                                      --(
  33. # )--  i: 10, 12                                   --(
  34. # )--  w: 2, 5                                     --(
  35. # )--  >                                           --(
  36. # )--  Means you need to have 12 of Item with ID 10--(
  37. # )--  sold at the shop and 5 of Weapon with ID 2  --(
  38. # )--  also sold at the shop.                      --(
  39. # )--                                              --(
  40. # )--  Or you can use                              --(
  41. # )--  <Shop: Default>                             --(
  42. # )--  To make item be automatically unlocked in   --(
  43. # )--  the shop.                                   --(
  44. # )--------------------------------------------------(
  45. # )--             LICENSE INFO                     --(
  46. # )--http://mrtrivelvx.wordpress.com/terms-of-use/ --(
  47. # )--------------------------------------------------(
  48.  
  49.  
  50. # )--------------------------------(
  51. # )--  Class: MrTS_Dynamic_Shop  --(
  52. # )--------------------------------(
  53. class MrTS_Dynamic_Shop < Scene_Shop
  54.  
  55.   # )---------------------(
  56.   # )--  Method: start  --(
  57.   # )---------------------(
  58.   alias mrts_start start
  59.   def start
  60.     prepare
  61.     mrts_start
  62.   end
  63.  
  64.   # )-----------------------(
  65.   # )--  Method: prepare  --(
  66.   # )-----------------------(
  67.   def prepare(purchase_only=false)
  68.     @goods = []
  69.     rgx_one = /<[s-sS-S]hop\s*:.*\s*^(([a-ai-iw-w]:\s*\d+,\s*\d+\s*^)+)>/
  70.     rgx_two = /([a-ai-iw-w]:\s*\d+,\s*\d+)/
  71.     rgx_three = /([a-ai-iw-w]):\s*(\d+),\s*(\d+)/
  72.     $data_items.each do |item|
  73.       if item
  74.         item.note[/<[s-sS-S]hop:\s*([d-dD-D]efault)>/]
  75.         if $1
  76.           @goods.push([0, item.id, 0, 0])
  77.         elsif
  78.           item_exists = true
  79.           item.note[rgx_one]
  80.           if $1
  81.             $1.scan(rgx_two).collect do |ele|
  82.               ele[0][rgx_three]
  83.               case $1
  84.               when "i"
  85.                 item_exists = false unless $game_party.item_available?($data_items[$2.to_i], $3.to_i)
  86.               when "a"
  87.                 item_exists = false unless $game_party.item_available?($data_armors[$2.to_i], $3.to_i)
  88.               when "w"
  89.                 item_exists = false unless $game_party.item_available?($data_weapons[$2.to_i], $3.to_i)
  90.               end # case
  91.             end # $1.scan
  92.             @goods.push([0, item.id, 0, 0]) if item_exists
  93.           end #if $1
  94.         end
  95.       end #if item
  96.     end
  97.    
  98.     $data_weapons.each do |item|
  99.       if item
  100.         item.note[/<[s-sS-S]hop:\s*([d-dD-D]efault)>/]
  101.         if $1
  102.           @goods.push([1, item.id, 0, 0])
  103.         elsif
  104.           item_exists = true
  105.           item.note[rgx_one]
  106.           if ($1)
  107.             $1.scan(rgx_two).collect do |ele|
  108.               ele[0][rgx_three]
  109.               case $1
  110.               when "i"
  111.                 item_exists = false unless $game_party.item_available?($data_items[$2.to_i], $3.to_i)
  112.               when "a"
  113.                 item_exists = false unless $game_party.item_available?($data_armors[$2.to_i], $3.to_i)
  114.               when "w"
  115.                 item_exists = false unless $game_party.item_available?($data_weapons[$2.to_i], $3.to_i)
  116.               end
  117.             end
  118.             @goods.push([1, item.id, 0, 0]) if item_exists
  119.           end
  120.         end
  121.       end
  122.     end
  123.    
  124.     $data_armors.each do |item|
  125.       if item
  126.         item.note[/<[s-sS-S]hop:\s*([d-dD-D]efault)>/]
  127.         if $1
  128.           @goods.push([2, item.id, 0, 0])
  129.         elsif
  130.           item_exists = true
  131.           item.note[rgx_one]
  132.           if ($1)
  133.             $1.scan(rgx_two).collect do |ele|
  134.               ele[0][rgx_three]
  135.               case $1
  136.               when "i"
  137.                 item_exists = false unless $game_party.item_available?($data_items[$2.to_i], $3.to_i)
  138.               when "a"
  139.                 item_exists = false unless $game_party.item_available?($data_armors[$2.to_i], $3.to_i)
  140.               when "w"
  141.                 item_exists = false unless $game_party.item_available?($data_weapons[$2.to_i], $3.to_i)
  142.               end
  143.             end
  144.             @goods.push([2, item.id, 0, 0]) if item_exists
  145.           end
  146.         end
  147.       end
  148.     end
  149.    
  150.     @purchase_only = purchase_only
  151.   end
  152.  
  153.   # )-----------------------(
  154.   # )--  Method: do_sell  --(
  155.   # )-----------------------(
  156.   def do_sell(number)
  157.     $game_party.gain_gold(number * selling_price)
  158.     $game_party.lose_item(@item, number)
  159.     $game_party.item_sold(@item, number)
  160.     prepare
  161.     @buy_window.set_goods(@goods)
  162.     @buy_window.refresh
  163.   end
  164. end
  165.  
  166. # )-------------------------(
  167. # )--  Class: Game_Party  --(
  168. # )-------------------------(
  169. class Game_Party < Game_Unit
  170.  
  171.   # )---------------------------------(
  172.   # )--  Public Instance Variables  --(
  173.   # )---------------------------------(
  174.   attr_reader   :items_sold               # To know which items have been sold
  175.   attr_reader   :items_quantities         # To know how many of that item has been sold
  176.  
  177.   # )---------------------------------(
  178.   # )--  Alias to: mrts_initialize  --(
  179.   # )---------------------------------(
  180.   alias mrts_initialize initialize
  181.   def initialize
  182.     mrts_initialize
  183.     @items_sold = []
  184.     @items_quantities = []
  185.   end
  186.  
  187.   # )-----------------------------(
  188.   # )--  New Method: item_sold  --(
  189.   # )-----------------------------(
  190.   def item_sold(t_item, t_quantity = 1)
  191.     @items_quantities.push(0) unless @items_sold.include?(t_item)
  192.     @items_sold.push(t_item) unless @items_sold.include?(t_item)
  193.     @items_quantities[@items_sold.index(t_item)]+=t_quantity
  194.   end
  195.  
  196.   # )-----------------------------(
  197.   # )--  New Method: item_sold  --(
  198.   # )-----------------------------(
  199.   def item_available?(t_item, t_quantity)
  200.     return false if !@items_sold.include?(t_item)
  201.     return false if !@items_quantities[@items_sold.index(t_item)] || @items_quantities[@items_sold.index(t_item)]<t_quantity
  202.     return true
  203.   end
  204.  
  205. end
  206.  
  207. # )-------------------------(
  208. # )--  Class: Scene_Shop  --(
  209. # )-------------------------(
  210. class Scene_Shop < Scene_MenuBase
  211.   alias mrts_do_sell do_sell
  212.   def do_sell(number)
  213.     mrts_do_sell(number)
  214.     $game_party.item_sold(@item, number)
  215.   end
  216. end
  217.  
  218. # )-----------------------------(
  219. # )--  Class: Window_ShopBuy  --(
  220. # )-----------------------------(
  221. class Window_ShopBuy < Window_Selectable
  222.  
  223.   def set_goods(shop_goods)
  224.     @shop_goods = shop_goods
  225.   end
  226. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement