Advertisement
mephis

KrEX - Syntesis Shop

Jan 20th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.54 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. #  ▼ Synthesis Shop (Магазин синтеза)
  3. #  Автор: Kread-EX
  4. #  Версия 1.0
  5. #  Дата выхода: 12.12.2011
  6. #  Требует: Kread-EX Alchemic Synthesis GO GO TOTORI!
  7. #
  8. #  Перевод: mephis
  9. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  10.  
  11. #-------------------------------------------------------------------------------------------------
  12. #  ▼ УСЛОВИЯ ИСПОЛЬЗОВАНИЯ
  13. #-------------------------------------------------------------------------------------------------
  14. # Вы можете изменять код этого скрипта под ваши нужды.
  15. # Вы можете использовать этот скрипт в коммерческих целях.
  16. # Обязательно указывайте автора.
  17. #
  18. # # По поддержке можно со мной связаться здесь:
  19. # # grimoirecastle.wordpress.com
  20. # # или здесь
  21. # # rpgmakervxace.net
  22. # # или здесь
  23. # # rpgrevolution.com
  24. #-------------------------------------------------------------------------------------------------
  25. #  ▼ ВВЕДЕНИЕ
  26. #-------------------------------------------------------------------------------------------------
  27. # Это дополнение к скрипту алхимического синтеза. Оно добавляет в игру
  28. # Магазин Синтеза, специальный магазин, в котором продаются синтезированныев вещи.
  29. #-------------------------------------------------------------------------------------------------
  30. #  ▼ ИНСТРУКЦИЯ
  31. #-------------------------------------------------------------------------------------------------
  32. # Поместите этот скрипт ниже скрипта Alchemic Synthesis.
  33. # Затем, в Заметках синтезируемой вещи вставьте ещё один тег:
  34. # <synth_shop: x>
  35. # Где х это количество копий этой вещи, доступное в магазине.
  36. #
  37. # Чтобы вызвать магазин используйте команду скрипта:
  38. # SceneManager.call(Scene_SynthesisShop)
  39. #-------------------------------------------------------------------------------------------------
  40. #  ▼ СОВМЕСТИМОСТЬ
  41. #-------------------------------------------------------------------------------------------------
  42. # Пока что на Ace не так много скриптов, но этот должен нормально работать со
  43. # скриптами Yanfly.
  44. #
  45. # Новые классы: Scene_SynthesisShop Window_SynthShopBuy, Window_SynthShopStatus
  46. #
  47. # Список псевдонимов и перекрытий:
  48. #
  49. #  DataManager
  50. #   load_database (псевдоним)
  51. #   load_synthshop_notetags (новый метод)
  52. #
  53. #  Game_Party
  54. #   initialize (псевдоним)
  55. #
  56. #  RPG::Item, RPG::Weapon, RPG::Armor
  57. #   load_synthshop_notetags (новый метод)
  58. #-------------------------------------------------------------------------------------------------
  59.  
  60. # Quits if the synthesis system isn't found
  61.  
  62. if $imported.nil? || $imported['KRX-AlchemicSynthesis'].nil?
  63.  
  64. msgbox('Чтобы использовать Магазин Синтеза вам нужен скрипт Alchemic Synthesis. Загрузка прервана.')
  65.  
  66. else
  67.  
  68. $imported['KRX-SynthesisShop'] = true
  69.  
  70. puts 'Load: Synthesis Shop v1.0 by Kread-EX'
  71.  
  72. module KRX
  73.  
  74.   module REGEXP
  75.     SYNTHESIS_SHOP = /<synth_shop:[ ]*(\d+)>/i
  76.   end
  77.  
  78.   module VOCAB
  79.     SYNTHESIS_SHOP_STOCK = 'Запасы магазина:'
  80.   end
  81.  
  82. end
  83.  
  84. #===========================================================================
  85. # ■ DataManager
  86. #===========================================================================
  87.  
  88. module DataManager  
  89.   #--------------------------------------------------------------------------
  90.   # ● Loads the database
  91.   #--------------------------------------------------------------------------
  92.   class << self
  93.     alias_method(:krx_synthshop_dm_load_database, :load_database)
  94.   end
  95.   def self.load_database
  96.     krx_synthshop_dm_load_database
  97.     load_synthshop_notetags
  98.   end  
  99.   #--------------------------------------------------------------------------
  100.   # ● Loads the note tags
  101.   #--------------------------------------------------------------------------
  102.   def self.load_synthshop_notetags
  103.     groups = [$data_items, $data_weapons, $data_armors]
  104.     classes = [RPG::Item, RPG::Weapon, RPG::Armor]
  105.     for group in groups
  106.       for obj in group
  107.         next if obj.nil?
  108.         obj.load_synthshop_notetags if classes.include?(obj.class)
  109.       end
  110.     end
  111.     puts "Read: Synthesis Shop Notetags"
  112.   end
  113. end
  114.  
  115. #==========================================================================
  116. #  ■  RPG::Item
  117. #==========================================================================
  118.  
  119. class RPG::Item < RPG::UsableItem
  120.   #--------------------------------------------------------------------------
  121.   # ● Public instance variables
  122.   #--------------------------------------------------------------------------
  123.   attr_reader    :synthesis_shop_nb
  124.   #--------------------------------------------------------------------------
  125.   # ● Loads the note tags
  126.   #--------------------------------------------------------------------------
  127.   def load_synthshop_notetags
  128.     @synthesis_shop_nb = 0
  129.     @note.split(/[\r\n]+/).each do |line|
  130.       case line
  131.       when  KRX::REGEXP::SYNTHESIS_SHOP
  132.         @synthesis_shop_nb = $1.to_i
  133.       end
  134.     end
  135.   end
  136. end
  137.  
  138. #==========================================================================
  139. #  ■  RPG::Weapon
  140. #==========================================================================
  141.  
  142. class RPG::Weapon < RPG::EquipItem
  143.   #--------------------------------------------------------------------------
  144.   # ● Public instance variables
  145.   #--------------------------------------------------------------------------
  146.   attr_reader    :synthesis_shop_nb
  147.   #--------------------------------------------------------------------------
  148.   # ● Loads the note tags
  149.   #--------------------------------------------------------------------------
  150.   def load_synthshop_notetags
  151.     @synthesis_shop_nb = 0
  152.     @note.split(/[\r\n]+/).each do |line|
  153.       case line
  154.       when  KRX::REGEXP::SYNTHESIS_SHOP
  155.         @synthesis_shop_nb = $1.to_i
  156.       end
  157.     end
  158.   end
  159. end
  160.  
  161. #==========================================================================
  162. #  ■  RPG::Armor
  163. #==========================================================================
  164.  
  165. class RPG::Armor < RPG::EquipItem
  166.   #--------------------------------------------------------------------------
  167.   # ● Public instance variables
  168.   #--------------------------------------------------------------------------
  169.   attr_reader    :synthesis_shop_nb
  170.   #--------------------------------------------------------------------------
  171.   # ● Loads the note tags
  172.   #--------------------------------------------------------------------------
  173.   def load_synthshop_notetags
  174.     @synthesis_shop_nb = 0
  175.     @note.split(/[\r\n]+/).each do |line|
  176.       case line
  177.       when  KRX::REGEXP::SYNTHESIS_SHOP
  178.         @synthesis_shop_nb = $1.to_i
  179.       end
  180.     end
  181.   end
  182. end
  183.  
  184. #==========================================================================
  185. #  ■  Game_Party
  186. #==========================================================================
  187.  
  188. class Game_Party < Game_Unit
  189.   #--------------------------------------------------------------------------
  190.   # ● Public instance variables
  191.   #--------------------------------------------------------------------------
  192.   attr_accessor  :synthesis_stock
  193.   #--------------------------------------------------------------------------
  194.   # ● Object Initialize
  195.   #--------------------------------------------------------------------------
  196.   alias_method(:krx_synthshop_gp_initialize, :initialize) unless $@
  197.   def initialize
  198.     krx_synthshop_gp_initialize
  199.     @synthesis_stock = {}
  200.   end
  201. end
  202.  
  203. #==========================================================================
  204. #  ■  Window_SynthShopStatus
  205. #==========================================================================
  206.  
  207. class Window_SynthShopStatus < Window_ShopStatus
  208.   #--------------------------------------------------------------------------
  209.   # ● Refreshes the contents
  210.   #--------------------------------------------------------------------------
  211.   def refresh
  212.     contents.clear
  213.     draw_possession(4, 0)
  214.     draw_vendor_stock(4, line_height)
  215.     draw_item_traits
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # ● Displays the number of items in stock for the vendor
  219.   #--------------------------------------------------------------------------
  220.   def draw_vendor_stock(x, y)
  221.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  222.     change_color(system_color)
  223.     draw_text(rect, KRX::VOCAB::SYNTHESIS_SHOP_STOCK)
  224.     change_color(normal_color)
  225.     draw_text(rect, $game_party.synthesis_stock[@item].to_s, 2)
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # ● Displays the item traits
  229.   #--------------------------------------------------------------------------
  230.   def draw_item_traits
  231.     return if @item.nil?
  232.     draw_horz_line(line_height * 2)
  233.     change_color(system_color)
  234.     contents.draw_text(4, line_height * 3, width, line_height, KRX::VOCAB::TRAITS)
  235.     change_color(normal_color)
  236.     (1..4).each {|i| contents.draw_text(4, line_height * (i + 3), width, line_height, "#{i}.")}
  237.     @item.synthesis_traits.each_index do |i|
  238.       trait = @item.synthesis_traits[i]
  239.       contents.draw_text(28, line_height * (i + 4), width - 24, line_height, trait)
  240.     end
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # ● Displays an horizontal line
  244.   #--------------------------------------------------------------------------
  245.   def draw_horz_line(y)
  246.     line_y = y + line_height / 2 - 1
  247.     contents.fill_rect(0, line_y, contents_width, 2, line_color)
  248.   end
  249.   #--------------------------------------------------------------------------
  250.   # ● Returns the color used for horizontal lines
  251.   #--------------------------------------------------------------------------
  252.   def line_color
  253.     color = normal_color
  254.     color.alpha = 48
  255.     return color
  256.   end
  257. end
  258.  
  259. #==========================================================================
  260. #  ■  Window_SynthShopBuy
  261. #==========================================================================
  262.  
  263. class Window_SynthShopBuy < Window_ShopBuy
  264.   #--------------------------------------------------------------------------
  265.   # ● Creates the list of items
  266.   #--------------------------------------------------------------------------
  267.   def make_item_list
  268.     @data = []
  269.     @price = {}
  270.     @quantity = {}
  271.     @shop_goods.each_key do |item|
  272.       next if item.nil?
  273.       @quantity[item] = $game_party.synthesis_stock[item]
  274.       next if @quantity[item].nil? || @quantity[item] == 0
  275.       @data.push(item)
  276.       @price[item] = item.price
  277.     end
  278.   end
  279.   #--------------------------------------------------------------------------
  280.   # ● Determines if an item can be bought
  281.   #--------------------------------------------------------------------------
  282.   def enable?(item)
  283.     item && price(item) <= @money && !$game_party.item_max?(item) &&
  284.     $game_party.synthesis_stock[item] > 0
  285.   end
  286. end
  287.  
  288. #==========================================================================
  289. #  ■  Scene_SynthesisShop
  290. #==========================================================================
  291.  
  292. class Scene_SynthesisShop < Scene_Shop
  293.   #--------------------------------------------------------------------------
  294.   # ● Object Initialize
  295.   #--------------------------------------------------------------------------
  296.   def initialize
  297.     super
  298.     @goods = $game_party.synthesis_stock
  299.     @purchase_only = true
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # ● Constructs the window showing the goods in sale
  303.   #--------------------------------------------------------------------------
  304.   def create_buy_window
  305.     wy = @dummy_window.y
  306.     wh = @dummy_window.height
  307.     @buy_window = Window_SynthShopBuy.new(0, wy, wh, @goods)
  308.     @buy_window.viewport = @viewport
  309.     @buy_window.help_window = @help_window
  310.     @buy_window.status_window = @status_window
  311.     @buy_window.hide
  312.     @buy_window.set_handler(:ok,     method(:on_buy_ok))
  313.     @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  314.   end
  315.   #--------------------------------------------------------------------------
  316.   # ● Constructs the window showing the actors' status
  317.   #--------------------------------------------------------------------------
  318.   def create_status_window
  319.     wx = @number_window.width
  320.     wy = @dummy_window.y
  321.     ww = Graphics.width - wx
  322.     wh = @dummy_window.height
  323.     @status_window = Window_SynthShopStatus.new(wx, wy, ww, wh)
  324.     @status_window.viewport = @viewport
  325.     @status_window.hide
  326.   end
  327.   #--------------------------------------------------------------------------
  328.   # ● Confirms the item selection
  329.   #--------------------------------------------------------------------------
  330.   def on_buy_ok
  331.     @item = @buy_window.item
  332.     @buy_window.hide
  333.     @number_window.set(@item, $game_party.synthesis_stock[@item], buying_price, currency_unit)
  334.     @number_window.show.activate
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # ● Performs the deal
  338.   #--------------------------------------------------------------------------
  339.   def do_buy(number)
  340.     super(number)
  341.     $game_party.synthesis_stock[@item] -= number
  342.   end
  343. end
  344.  
  345. #==========================================================================
  346. #  ■  Scene_Alchemy
  347. #==========================================================================
  348.  
  349. class Scene_Alchemy < Scene_MenuBase
  350.   #--------------------------------------------------------------------------
  351.   # ● Synthesis outcome
  352.   #--------------------------------------------------------------------------
  353.   alias_method(:krx_synthshop_outcome, :process_outcome)
  354.   def process_outcome(failure = false)
  355.     krx_synthshop_outcome(false)
  356.     unless failure
  357.       itm = $game_party.last_item.object
  358.       $game_party.synthesis_stock[itm] = itm.synthesis_shop_nb
  359.     end
  360.   end
  361. end
  362.  
  363. end # Parent script check
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement