nio_kasgami

Emoji Engine Ace - Mercantile "dynamic shopkeeper" {Beta}

Aug 19th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.53 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Emoji Engine Ace - Mercantile "Dynamic Shopkeeper"
  3. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  4. # Script who redesign the shop scene for be more intuitive and add new option
  5. # to it
  6. # Created by Nio Kasgami.
  7. # Data : 2015/07/24
  8. # Version : 1.0.0
  9. # Require : Emoji Engine Ace - Origin "AI Core"
  10. #==============================================================================
  11.  
  12. #==============================================================================
  13. # Introduction
  14. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. # do you always dreams to have a interactive AI in your shop but was
  16. # never able to implement it only via Events??
  17. # Then this script is the good one for peeps who love having dynamic
  18. # interactions with the shopkeeper.
  19. # It's permit to redesign the whole Shop scene for permit better informations
  20. # and better shop processing
  21. #==============================================================================
  22.  
  23. #==============================================================================
  24. # Features
  25. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  26. # | - Whole Redesigned Shop System for be more intuitive |
  27. # | - Adding possibility to have both BGS and BGM in the scene |
  28. # | - Removing superflue coding and window |
  29. # | - Adding Extra command Bar for goods organisation sake |
  30. #==============================================================================
  31.  
  32. #==============================================================================
  33. # History
  34. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  35. # 2015/07/24 - Begin of the script
  36. #==============================================================================
  37.  
  38.  
  39.  
  40.  
  41.  
  42. module Emoji
  43.     module AI
  44.         System ={
  45.  
  46.         }
  47.  
  48.         AI_Personality ||= { }
  49.  
  50.         AI_Personality[1] ={
  51.             :music_shop => "armor_shop"
  52.         }
  53.  
  54.  
  55.     end
  56.  
  57.     module Mercantile
  58.         System ={
  59.             :shop_music_enable => true,
  60.             :face_enable => true,
  61.             :face_index_name => "actor"
  62.  
  63.         }
  64.  
  65.  
  66.         Shop_name ={
  67.         }
  68.  
  69.  
  70.     end
  71. end
  72.  
  73.  
  74. module Cache
  75.     def self.shop(index,filename)
  76.         load_bitmap("Graphics/shop/#{index}/",filename)
  77.     end
  78. end
  79.  
  80. class Scene_Shop < Scene_MenuBase
  81.     include Emoji::Mercantile
  82.  
  83. #----------------------------------------------------------------------------
  84. # ○ overwrite method : prepare
  85. #----------------------------------------------------------------------------
  86.     def prepare(goods,enable,ai_id,)
  87.         @goods = goods
  88.         @enable = enable
  89.         @ai_id = ai_id
  90.     end
  91. #----------------------------------------------------------------------------
  92. # ○ overwrite method : start
  93. #----------------------------------------------------------------------------
  94.     def start
  95.     super
  96.     @ai = $game_personalities[@ai_id]
  97.     save_map_music
  98.     create_sup_graphics
  99.     create_all_window
  100.     init_music if System[:shop_music_enable]
  101.     end
  102.  
  103.     def save_map_music
  104.         @map_bgm = RTP::BGM.last
  105.         @map_bgs = RTP::BGS.last
  106.     end
  107. #----------------------------------------------------------------------------
  108. # ○ new method: create_background
  109. #----------------------------------------------------------------------------
  110.     def create_background
  111.         shop_index = "shop_#{@ai_id}"
  112.         bitmap = @ai[:background_file]
  113.  
  114.         if bitmap != ""
  115.             @back = Plane.new
  116.             @back.bitmap = Cache.shop(shop_index,bitmap)
  117.             @back.z = 0
  118.         else
  119.             super
  120.         end
  121.     end
  122. #----------------------------------------------------------------------------
  123. # ○ new method: init_music
  124. #----------------------------------------------------------------------------
  125.     def init_music
  126.         @file = @ai[:music_shop]
  127.         @file_se = @ai[:bgs_shop]
  128.  
  129.         if System[:shop_music_enable]
  130.             RTP::BGM.new(@file,100,100).play
  131.         end
  132.         if System[:bgs_enable]
  133.             RTP::BGS.new(@file_se,80,100).play
  134.         else
  135.             RTP::BGS.stop
  136.         end
  137.     end
  138. #----------------------------------------------------------------------------
  139. # ○ new method: retrieve_dialogues_and_voices
  140. #----------------------------------------------------------------------------
  141.     def create_sup_graphics
  142.         create_shop_name
  143.         create_face if System[:face_enable]
  144.     end
  145. #----------------------------------------------------------------------------
  146. # ○ new method: retrieve_dialogues_and_voices
  147. #----------------------------------------------------------------------------
  148.     def create_shop_name
  149.         @name = Sprite.new
  150.         @name.bitmap = Cache.shop(@ai[:shop_name_filename])
  151.         @name.x = Shop_name[:pos_x]
  152.         @name.y = Shop_name[:pos_y]
  153.         @name.z = Shop_name[:pos_z]
  154.         @name.opacity = 0
  155.         @slide_speed =  Shop_name[:slide_speed]
  156.         @time_value = 0
  157.     end
  158. #================================================================================
  159.     def create_all_window
  160.     create_help_window
  161.     create_gold_window
  162.     create_command_window
  163.     create_dummy_window
  164.     create_number_windowa
  165.     create_status_window
  166.     create_buy_window
  167.     create_category_window
  168.     create_sell_window
  169.     end
  170.  
  171.  #--------------------------------------------------------------------------
  172.   # * Create Gold Window
  173.   #--------------------------------------------------------------------------
  174.   def create_gold_window
  175.     @gold_window = Window_Gold.new
  176.     @gold_window.viewport = @viewport
  177.     @gold_window.x = Graphics.width - @gold_window.width
  178.     @gold_window.y = @help_window.height
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * Create Command Window
  182.   #--------------------------------------------------------------------------
  183.   def create_command_window
  184.     @command_window = Window_ShopCommand.new(@gold_window.x, @purchase_only)
  185.     @command_window.viewport = @viewport
  186.     @command_window.y = @help_window.height
  187.     @command_window.set_handler(:buy,    method(:command_buy))
  188.     @command_window.set_handler(:sell,   method(:command_sell))
  189.     @command_window.set_handler(:cancel, method(:return_scene))
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # * Create Dummy Window
  193.   #--------------------------------------------------------------------------
  194.   def create_dummy_window
  195.     wy = @command_window.y + @command_window.height
  196.     wh = Graphics.height - wy
  197.     @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
  198.     @dummy_window.viewport = @viewport
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # * Create Quantity Input Window
  202.   #--------------------------------------------------------------------------
  203.   def create_number_window
  204.     wy = @dummy_window.y
  205.     wh = @dummy_window.height
  206.     @number_window = Window_ShopNumber.new(0, wy, wh)
  207.     @number_window.viewport = @viewport
  208.     @number_window.hide
  209.     @number_window.set_handler(:ok,     method(:on_number_ok))
  210.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Create Status Window
  214.   #--------------------------------------------------------------------------
  215.   def create_status_window
  216.     wx = @number_window.width
  217.     wy = @dummy_window.y
  218.     ww = Graphics.width - wx
  219.     wh = @dummy_window.height
  220.     @status_window = Window_ShopStatus.new(wx, wy, ww, wh)
  221.     @status_window.viewport = @viewport
  222.     @status_window.hide
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * Create Purchase Window
  226.   #--------------------------------------------------------------------------
  227.   def create_buy_window
  228.     wy = @dummy_window.y
  229.     wh = @dummy_window.height
  230.     @buy_window = Window_ShopBuy.new(0, wy, wh, @goods)
  231.     @buy_window.viewport = @viewport
  232.     @buy_window.help_window = @help_window
  233.     @buy_window.status_window = @status_window
  234.     @buy_window.hide
  235.     @buy_window.set_handler(:ok,     method(:on_buy_ok))
  236.     @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Create Category Window
  240.   #--------------------------------------------------------------------------
  241.   def create_category_window
  242.     @category_window = Window_ItemCategory.new
  243.     @category_window.viewport = @viewport
  244.     @category_window.help_window = @help_window
  245.     @category_window.y = @dummy_window.y
  246.     @category_window.hide.deactivate
  247.     @category_window.set_handler(:ok,     method(:on_category_ok))
  248.     @category_window.set_handler(:cancel, method(:on_category_cancel))
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # * Create Sell Window
  252.   #--------------------------------------------------------------------------
  253.   def create_sell_window
  254.     wy = @category_window.y + @category_window.height
  255.     wh = Graphics.height - wy
  256.     @sell_window = Window_ShopSell.new(0, wy, Graphics.width, wh)
  257.     @sell_window.viewport = @viewport
  258.     @sell_window.help_window = @help_window
  259.     @sell_window.hide
  260.     @sell_window.set_handler(:ok,     method(:on_sell_ok))
  261.     @sell_window.set_handler(:cancel, method(:on_sell_cancel))
  262.     @category_window.item_window = @sell_window
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # * Activate Purchase Window
  266.   #--------------------------------------------------------------------------
  267.   def activate_buy_window
  268.     @buy_window.money = money
  269.     @buy_window.show.activate
  270.     @status_window.show
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # * Activate Sell Window
  274.   #--------------------------------------------------------------------------
  275.   def activate_sell_window
  276.     @category_window.show
  277.     @sell_window.refresh
  278.     @sell_window.show.activate
  279.     @status_window.hide
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # * [Buy] Command
  283.   #--------------------------------------------------------------------------
  284.   def command_buy
  285.     @dummy_window.hide
  286.     activate_buy_window
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # * [Sell] Command
  290.   #--------------------------------------------------------------------------
  291.   def command_sell
  292.     @dummy_window.hide
  293.     @category_window.show.activate
  294.     @sell_window.show
  295.     @sell_window.unselect
  296.     @sell_window.refresh
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # * Buy [OK]
  300.   #--------------------------------------------------------------------------
  301.   def on_buy_ok
  302.     @item = @buy_window.item
  303.     @buy_window.hide
  304.     @number_window.set(@item, max_buy, buying_price, currency_unit)
  305.     @number_window.show.activate
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # * Buy [Cancel]
  309.   #--------------------------------------------------------------------------
  310.   def on_buy_cancel
  311.     @command_window.activate
  312.     @dummy_window.show
  313.     @buy_window.hide
  314.     @status_window.hide
  315.     @status_window.item = nil
  316.     @help_window.clear
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   # * Category [OK]
  320.   #--------------------------------------------------------------------------
  321.   def on_category_ok
  322.     activate_sell_window
  323.     @sell_window.select(0)
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # * Category [Cancel]
  327.   #--------------------------------------------------------------------------
  328.   def on_category_cancel
  329.     @command_window.activate
  330.     @dummy_window.show
  331.     @category_window.hide
  332.     @sell_window.hide
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # * Sell [OK]
  336.   #--------------------------------------------------------------------------
  337.   def on_sell_ok
  338.     @item = @sell_window.item
  339.     @status_window.item = @item
  340.     @category_window.hide
  341.     @sell_window.hide
  342.     @number_window.set(@item, max_sell, selling_price, currency_unit)
  343.     @number_window.show.activate
  344.     @status_window.show
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   # * Sell [Cancel]
  348.   #--------------------------------------------------------------------------
  349.   def on_sell_cancel
  350.     @sell_window.unselect
  351.     @category_window.activate
  352.     @status_window.item = nil
  353.     @help_window.clear
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Quantity Input [OK]
  357.   #--------------------------------------------------------------------------
  358.   def on_number_ok
  359.     Sound.play_shop
  360.     case @command_window.current_symbol
  361.     when :buy
  362.       do_buy(@number_window.number)
  363.     when :sell
  364.       do_sell(@number_window.number)
  365.     end
  366.     end_number_input
  367.     @gold_window.refresh
  368.     @status_window.refresh
  369.   end
  370.   #--------------------------------------------------------------------------
  371.   # * Quantity Input [Cancel]
  372.   #--------------------------------------------------------------------------
  373.   def on_number_cancel
  374.     Sound.play_cancel
  375.     end_number_input
  376.   end
  377.   #--------------------------------------------------------------------------
  378.   # * Execute Purchase
  379.   #--------------------------------------------------------------------------
  380.   def do_buy(number)
  381.     $game_party.lose_gold(number * buying_price)
  382.     $game_party.gain_item(@item, number)
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   # * Execute Sale
  386.   #--------------------------------------------------------------------------
  387.   def do_sell(number)
  388.     $game_party.gain_gold(number * selling_price)
  389.     $game_party.lose_item(@item, number)
  390.   end
  391.   #--------------------------------------------------------------------------
  392.   # * Exit Quantity Input
  393.   #--------------------------------------------------------------------------
  394.   def end_number_input
  395.     @number_window.hide
  396.     case @command_window.current_symbol
  397.     when :buy
  398.       activate_buy_window
  399.     when :sell
  400.       activate_sell_window
  401.     end
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * Get Maximum Quantity Buyable
  405.   #--------------------------------------------------------------------------
  406.   def max_buy
  407.     max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
  408.     buying_price == 0 ? max : [max, money / buying_price].min
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * Get Maximum Quantity Sellable
  412.   #--------------------------------------------------------------------------
  413.   def max_sell
  414.     $game_party.item_number(@item)
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # * Get Party Gold
  418.   #--------------------------------------------------------------------------
  419.   def money
  420.     @gold_window.value
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # Get Currency Unit
  424.   #--------------------------------------------------------------------------
  425.   def currency_unit
  426.     @gold_window.currency_unit
  427.   end
  428.   #--------------------------------------------------------------------------
  429.   # * Get Purchase Price
  430.   #--------------------------------------------------------------------------
  431.   def buying_price
  432.     @buy_window.price(@item)
  433.   end
  434.   #--------------------------------------------------------------------------
  435.   # * Get Sale Price
  436.   #--------------------------------------------------------------------------
  437.   def selling_price
  438.     @item.price / 2
  439.   end
  440. end
Advertisement
Add Comment
Please, Sign In to add comment