neutale

Only Sell Shop

Jul 2nd, 2019
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.68 KB | None | 0 0
  1. class Game_Interpreter
  2.   #--------------------------------------------------------------------------
  3.   # ● start sell shop
  4.   #--------------------------------------------------------------------------
  5.   def only_sell_shop(sell_rate = 50)
  6.     return if $game_party.in_battle
  7.     SceneManager.call(Scene_Sell_Shop)
  8.     SceneManager.scene.prepare(sell_rate)
  9.     Fiber.yield
  10.   end
  11. end
  12.  
  13. class Window_Sell_ShopCommand < Window_HorzCommand
  14.   #--------------------------------------------------------------------------
  15.   # ● initialize window width
  16.   #--------------------------------------------------------------------------
  17.   def initialize(window_width)
  18.     @window_width = window_width
  19.     super(0, 0)
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # ● window width
  23.   #--------------------------------------------------------------------------
  24.   def window_width
  25.     @window_width
  26.   end
  27.   #--------------------------------------------------------------------------
  28.   # ● max list
  29.   #--------------------------------------------------------------------------
  30.   def col_max
  31.     return 2
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● create command list
  35.   #--------------------------------------------------------------------------
  36.   def make_command_list
  37.     add_command(Vocab::ShopSell,   :sell)
  38.     add_command(Vocab::ShopCancel, :cancel)
  39.   end
  40. end
  41.  
  42. class Scene_Sell_Shop < Scene_MenuBase
  43.   #--------------------------------------------------------------------------
  44.   # ● prepare (sell rate)
  45.   #--------------------------------------------------------------------------
  46.   def prepare(sell_rate)
  47.     @sell_rate = sell_rate
  48.   end
  49.   #--------------------------------------------------------------------------
  50.   # ● start
  51.   #--------------------------------------------------------------------------
  52.   def start
  53.     super
  54.     create_help_window
  55.     create_gold_window
  56.     create_command_window
  57.     create_dummy_window
  58.     create_number_window
  59.     create_status_window
  60.     create_category_window
  61.     create_sell_window
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # ● create gold window
  65.   #--------------------------------------------------------------------------
  66.   def create_gold_window
  67.     @gold_window = Window_Gold.new
  68.     @gold_window.viewport = @viewport
  69.     @gold_window.x = Graphics.width - @gold_window.width
  70.     @gold_window.y = @help_window.height
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # ● create command window
  74.   #--------------------------------------------------------------------------
  75.   def create_command_window
  76.     @command_window = Window_Sell_ShopCommand.new(@gold_window.x)
  77.     @command_window.viewport = @viewport
  78.     @command_window.y = @help_window.height
  79.     @command_window.set_handler(:sell,   method(:command_sell))
  80.     @command_window.set_handler(:cancel, method(:return_scene))
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # ● create dummy window
  84.   #--------------------------------------------------------------------------
  85.   def create_dummy_window
  86.     wy = @command_window.y + @command_window.height
  87.     wh = Graphics.height - wy
  88.     @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
  89.     @dummy_window.viewport = @viewport
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● create number window
  93.   #--------------------------------------------------------------------------
  94.   def create_number_window
  95.     wy = @dummy_window.y
  96.     wh = @dummy_window.height
  97.     @number_window = Window_ShopNumber.new(0, wy, wh)
  98.     @number_window.viewport = @viewport
  99.     @number_window.hide
  100.     @number_window.set_handler(:ok,     method(:on_number_ok))
  101.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # ● create status window
  105.   #--------------------------------------------------------------------------
  106.   def create_status_window
  107.     wx = @number_window.width
  108.     wy = @dummy_window.y
  109.     ww = Graphics.width - wx
  110.     wh = @dummy_window.height
  111.     @status_window = Window_ShopStatus.new(wx, wy, ww, wh)
  112.     @status_window.viewport = @viewport
  113.     @status_window.hide
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # ● create category window
  117.   #--------------------------------------------------------------------------
  118.   def create_category_window
  119.     @category_window = Window_ItemCategory.new
  120.     @category_window.viewport = @viewport
  121.     @category_window.help_window = @help_window
  122.     @category_window.y = @dummy_window.y
  123.     @category_window.hide.deactivate
  124.     @category_window.set_handler(:ok,     method(:on_category_ok))
  125.     @category_window.set_handler(:cancel, method(:on_category_cancel))
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● create sell window
  129.   #--------------------------------------------------------------------------
  130.   def create_sell_window
  131.     wy = @category_window.y + @category_window.height
  132.     wh = Graphics.height - wy
  133.     @sell_window = Window_ShopSell.new(0, wy, Graphics.width, wh)
  134.     @sell_window.viewport = @viewport
  135.     @sell_window.help_window = @help_window
  136.     @sell_window.hide
  137.     @sell_window.set_handler(:ok,     method(:on_sell_ok))
  138.     @sell_window.set_handler(:cancel, method(:on_sell_cancel))
  139.     @category_window.item_window = @sell_window
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # ● activate sale window
  143.   #--------------------------------------------------------------------------
  144.   def activate_sell_window
  145.     @category_window.show
  146.     @sell_window.refresh
  147.     @sell_window.show.activate
  148.     @status_window.hide
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ● command [sell]
  152.   #--------------------------------------------------------------------------
  153.   def command_sell
  154.     @dummy_window.hide
  155.     @category_window.show.activate
  156.     @sell_window.show
  157.     @sell_window.unselect
  158.     @sell_window.refresh
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   # ● category [select]
  162.   #--------------------------------------------------------------------------
  163.   def on_category_ok
  164.     activate_sell_window
  165.     @sell_window.select(0)
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # ● sale [select]
  169.   #--------------------------------------------------------------------------
  170.   def on_category_cancel
  171.     @command_window.activate
  172.     @dummy_window.show
  173.     @category_window.hide
  174.     @sell_window.hide
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● sell [select]
  178.   #--------------------------------------------------------------------------
  179.   def on_sell_ok
  180.     @item = @sell_window.item
  181.     @status_window.item = @item
  182.     @category_window.hide
  183.     @sell_window.hide
  184.     @number_window.set(@item, max_sell, selling_price, currency_unit)
  185.     @number_window.show.activate
  186.     @status_window.show
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # ● quantity input [cancel]
  190.   #--------------------------------------------------------------------------
  191.   def on_sell_cancel
  192.     @sell_window.unselect
  193.     @category_window.activate
  194.     @status_window.item = nil
  195.     @help_window.clear
  196.   end
  197.   #--------------------------------------------------------------------------
  198.   # ● number [select]
  199.   #--------------------------------------------------------------------------
  200.   def on_number_ok
  201.     Sound.play_shop
  202.     do_sell(@number_window.number)
  203.     end_number_input
  204.     @gold_window.refresh
  205.     @status_window.refresh
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # ● number [cancel]
  209.   #--------------------------------------------------------------------------
  210.   def on_number_cancel
  211.     Sound.play_cancel
  212.     end_number_input
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # ● get sell number
  216.   #--------------------------------------------------------------------------
  217.   def do_sell(number)
  218.     $game_party.gain_gold(number * selling_price)
  219.     $game_party.lose_item(@item, number)
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # ● get end number input
  223.   #--------------------------------------------------------------------------
  224.   def end_number_input
  225.     @number_window.hide
  226.     activate_sell_window
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # ● get max sell
  230.   #--------------------------------------------------------------------------
  231.   def max_sell
  232.     $game_party.item_number(@item)
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # ● get money
  236.   #--------------------------------------------------------------------------
  237.   def money
  238.     @gold_window.value
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # ● get currency unit
  242.   #--------------------------------------------------------------------------
  243.   def currency_unit
  244.     @gold_window.currency_unit
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # ● get selling price
  248.   #--------------------------------------------------------------------------
  249.   def selling_price
  250.     @item.price * @sell_rate / 100
  251.   end
  252. end
Advertisement
Add Comment
Please, Sign In to add comment