CrowMakerVX

IxfuruZylosSynthShopRedo

May 1st, 2014
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 28.59 KB | None | 0 0
  1. ################################################################################
  2. #                         Synth Shop
  3. #                         By: Ixfuru
  4. ################################################################################
  5. # This script was based off the existing script SynthesisShopVX by Zylos.  As
  6. # requested by Revival, who wanted to improve how the script handles synthesis.  
  7. # For instance, the ability to require more than one of the specific item.  And
  8. # also the ability to use more than two items for synthesis.  This script adds
  9. # those features and changes a few other things.  The script was written holding
  10. # as true to the basic layout of the Synthesis scene from Zylos' script as
  11. # possible.  Anyone who uses this script MUST credit Zylos above all else, for his
  12. # script set the foundation and inspiration for this one.  
  13. #
  14. # Basically, the script enables the player to a new shop scene by turning ON an
  15. # in game switch (which you provide the ID of) prior to calling the scene.  Inside
  16. # the scene, the player can create weapons/armor/and now items if they have
  17. # the required items in their possession and by paying a synthesis fee.  All these
  18. # things can be set up in the database via notebox tags:
  19. #
  20. #                    <synth item_type, item_id, item_amount>
  21. #
  22. # For each item involved (required) to make the item in question, you have to
  23. # have ONE of these note tags.  This enables you to use several different
  24. # items to create a new i/w/a.  Use the following in order to understand the
  25. # note tags better:
  26. #
  27. #              item_type    : 0 for item, 1 for weapon, 2 for armor; of the material
  28. #              item_id      : the database ID of the required material
  29. #              item_amount  : the required amount of the material item
  30. #
  31. # Here are a few examples of the note tags in action:
  32. #
  33. # EXAMPLE ONE:
  34. #
  35. #              <synth 0, 12, 2>
  36. #
  37. # EXAMPLE TWO:
  38. #              <synth 0, 6, 3>
  39. #              <synth 0, 25, 2>
  40. #
  41. # EXAMPLE THREE:
  42. #              <synth 0, 14, 2>
  43. #              <synth 1, 8, 1>
  44. #              <synth 2, 15, 1>
  45. #
  46. # In EXAMPLE ONE, you would require 2 database ITEMS with the ID of 12.
  47. #
  48. # In EXAMPLE TWO, you would require 3 database ITEMS with the ID of 6 and
  49. #                                   2 database ITEMS with the ID of 25.
  50. #
  51. # In EXAMPLE THREE, you would require 2 database ITEMS with the ID of 14,
  52. #                                     1 database WEAPON with the ID of 8 and
  53. #                                     1 database ARMOR with the ID of 15.
  54. #
  55. # There is no limit to the amount of synth items required.  I made the required
  56. # window selectable so that the player could scroll through them if there is
  57. # more than would fit on the window's bitmap.
  58. #
  59. # If you want there to be a charge for synthesis, you need to also add the following
  60. # tag:
  61. #
  62. #                     <synth_cost gold_amount>
  63. #
  64. #      gold_amount : the amount of gold to charge the player for synthesis.  If
  65. #                    no amount is given, then the price will be the value you
  66. #                    set in the DEFAULT_SYNTH_PRICE below in the settings module.
  67. #
  68. ################################################################################
  69.  
  70. module Ixfuru
  71.   module SynthShop
  72.    
  73.     SYNTH_SHOP_SWITCH = 1  # Set this to the game switch ID of the switch which
  74.                            # calls the SynthShop.
  75.                            
  76.     DEFAULT_SYNTH_PRICE = 50 # If no price is set for a synthesis item in the
  77.                              # item's notebox, this value is rendered as the price
  78.    
  79.     SYNTH_SOUND = ["Saint5", 80, 100] # SE played when a new item is created
  80.                               # [se_filename, volume, pitch]
  81.    
  82.     # Below is the strings you wish to use for the scene's, upper-right hand
  83.     # corner status window.  The first one is used to describe how much
  84.     # gold the party has.  The second one tells how many of the selected item
  85.     # the party has in stock, and the third one tells how many of the selected
  86.     # item the party has equipped.
  87.     SYNTH_STATUS_STRINGS = ["Funds", "Stock", "Equipped"]
  88.    
  89.     # The next value sets what string you want to accompany the item's icon
  90.     # and name when a new item is created.  
  91.     SYNTH_SUCCESS_STRING = " was created!"  # make sure you leave a space at the
  92.                                             # beginning.
  93.    
  94.     # The following setting is used to map input buttons to control of the scene.
  95.     # The buttons you decide upon, will cause control to jump back and forth
  96.     # from the items in the SynthShop window, to the required items in the
  97.     # Required window.  This is necessary because you can place more synth items
  98.     # in the required window for a given item than there is room to hold them.
  99.     # For instance, if you have an item that requires five different synth
  100.     # materials, you will probably only see three listed.  This ensures that you
  101.     # can press a button and take control of the required window in order to
  102.     # scroll it down and see the additional required items.
  103.     #
  104.     # You can either place 0 for using "Q" and "W"
  105.     # or place 1 for using the LEFT/RIGHT arrow keys.
  106.     SYNTH_WINDOW_CONTROL_KEYS = 0
  107.    
  108.   end
  109. end
  110.  
  111. ################################################################################
  112. #                         DONT EDIT PAST THIS POINT!
  113. ################################################################################
  114.  
  115. module Ixfuru
  116.   module Regexp
  117.    
  118.     SYNTH = /<synth[\s]*(\d+),[\s]*(\d+),[\s]*(\d+)>/i
  119.     SYNTH_COST = /<synth_cost[\s]*(\d+)>/i
  120.    
  121.   end
  122. end
  123.  
  124. ################################################################################
  125. #*******************************************************************************
  126. #                           RPG::BaseItem
  127. ################################################################################
  128. class RPG::BaseItem
  129.  
  130.   #-----------------------------------------------------------------------------
  131.   # Synth
  132.   #-----------------------------------------------------------------------------
  133.   def synth
  134.     s = []
  135.     self.note.split(/[\r\n]/).each { |line|
  136.     case line
  137.     when Ixfuru::Regexp::SYNTH
  138.       t = $1.to_i
  139.       i = $2.to_i
  140.       a = $3.to_i
  141.       s.push([t, i, a])
  142.     end
  143.     }
  144.     return s
  145.   end
  146.  
  147.   #-----------------------------------------------------------------------------
  148.   # Synth Cost
  149.   #-----------------------------------------------------------------------------
  150.   def synth_cost
  151.     return 0 if synth.empty?
  152.     c = Ixfuru::SynthShop::DEFAULT_SYNTH_PRICE
  153.     self.note.split(/[\r\n]/).each { |line|
  154.     case line
  155.     when Ixfuru::Regexp::SYNTH_COST
  156.       c = $1.to_i
  157.     end
  158.     }
  159.     return c
  160.   end
  161.  
  162. end
  163.  
  164. ################################################################################
  165. #*******************************************************************************
  166. #                        Scene Map
  167. ################################################################################
  168. class Scene_Map < Scene_Base
  169.  
  170.   #-----------------------------------------------------------------------------
  171.   # Call Shop (Aliased)
  172.   #-----------------------------------------------------------------------------
  173.   alias ixsynth_callshop call_shop unless $@
  174.   def call_shop
  175.     $game_temp.next_scene = nil
  176.     if $game_switches[Ixfuru::SynthShop::SYNTH_SHOP_SWITCH]
  177.       $scene = Scene_SynthShop.new
  178.     else
  179.       ixsynth_callshop
  180.     end
  181.   end
  182.  
  183. end
  184.  
  185. ################################################################################
  186. #*******************************************************************************
  187. #                       Window SynthShopItems
  188. ################################################################################
  189. class Window_SynthShopItems < Window_Selectable
  190.  
  191.   attr_reader :goods
  192.  
  193.   #-----------------------------------------------------------------------------
  194.   # Initialize
  195.   #-----------------------------------------------------------------------------
  196.   def initialize
  197.     super(0, 56, 304, 232)
  198.     @goods = synth_shop_goods
  199.     @item_max = @goods.size
  200.     refresh
  201.     self.index = 0
  202.   end
  203.  
  204.   #-----------------------------------------------------------------------------
  205.   # Synth Shop Goods
  206.   #-----------------------------------------------------------------------------
  207.   def synth_shop_goods
  208.     synth_goods = []
  209.     sg = $game_temp.shop_goods
  210.     for g in sg
  211.       case g[0]
  212.       when 0
  213.         i = $data_items[g[1]]
  214.       when 1
  215.         i = $data_weapons[g[1]]
  216.       when 2
  217.         i = $data_armors[g[1]]
  218.       end
  219.       synth_goods.push(i)
  220.     end
  221.     return synth_goods
  222.   end
  223.  
  224.   #-----------------------------------------------------------------------------
  225.   # Refresh
  226.   #-----------------------------------------------------------------------------
  227.   def refresh
  228.     create_contents
  229.     unless @goods.empty?
  230.       for i in 0...@item_max
  231.         draw_item(i)
  232.       end
  233.     end
  234.   end
  235.  
  236.   #-----------------------------------------------------------------------------
  237.   # Draw Item
  238.   #-----------------------------------------------------------------------------
  239.   def draw_item(index)
  240.     rect = item_rect(index)
  241.     rect.x += 4
  242.     rect.width -= 8
  243.     e = enabled?(index)
  244.     draw_item_name(@goods[index], rect.x, rect.y, e)
  245.     self.contents.font.color.alpha = e ? 255 : 128
  246.     self.contents.draw_text(rect, @goods[index].synth_cost.to_s, 2)
  247.   end
  248.  
  249.   #-----------------------------------------------------------------------------
  250.   # Synth Item
  251.   #
  252.   # synthesis: [item_type, item_id, item_amount])
  253.   #-----------------------------------------------------------------------------
  254.   def synth_item(synthesis)
  255.     case synthesis[0]
  256.     when 0 # item
  257.       return $data_items[synthesis[1]]
  258.     when 1 # weapon
  259.       return $data_weapons[synthesis[1]]
  260.     when 2 # armor
  261.       return $data_armors[synthesis[1]]
  262.     end
  263.     return nil
  264.   end
  265.  
  266.   #-----------------------------------------------------------------------------
  267.   # Enabled?
  268.   #-----------------------------------------------------------------------------
  269.   def enabled?(index)
  270.     return false if @goods[index].nil?
  271.     item = @goods[index]
  272.     party = $game_party
  273.     members = $game_party.members
  274.     requireds = 0
  275.     return true if item.synth.empty?
  276.     for s in item.synth
  277.       s_item = synth_item(s)
  278.       next if s_item.nil?  # Skip it if there is no such database material item
  279.       if party.has_item?(s_item) && party.item_number(s_item) > s[2]
  280.         requireds += 1
  281.       end
  282.     end
  283.     return false if requireds < item.synth.size
  284.     return true
  285.   end
  286.  
  287. end
  288.  
  289. ################################################################################
  290. #******************************************************************************
  291. #                        Window SynthShopStatus
  292. ################################################################################
  293. class Window_SynthShopStatus < Window_Base
  294.  
  295.   attr_accessor :item
  296.  
  297.   #-----------------------------------------------------------------------------
  298.   # Initialize
  299.   #-----------------------------------------------------------------------------
  300.   def initialize(item)
  301.     super(304, 56, 240, 116)
  302.     @strings = Ixfuru::SynthShop::SYNTH_STATUS_STRINGS
  303.     @item = item
  304.     refresh
  305.   end
  306.  
  307.   #-----------------------------------------------------------------------------
  308.   # Refresh
  309.   #-----------------------------------------------------------------------------
  310.   def refresh
  311.     self.contents.clear
  312.     ly = 0
  313.     self.contents.font.color = system_color
  314.     for i in 0...@strings.size
  315.       self.contents.draw_text(0, ly, self.width, WLH, @strings[i])
  316.       ly += WLH
  317.     end
  318.     self.contents.font.color = normal_color
  319.     self.contents.draw_text(0, 0, self.width - 32, WLH, $game_party.gold.to_s, 2)
  320.     self.contents.draw_text(0, WLH, self.width - 32, WLH, $game_party.item_number(@item).to_s, 2)
  321.     self.contents.draw_text(0, WLH * 2, self.width - 32, WLH, party_equipped.to_s, 2)
  322.   end
  323.  
  324.   #-----------------------------------------------------------------------------
  325.   # Party Equipped
  326.   #
  327.   # retrieved value for the amount of a selected item the party has as part of
  328.   # their equipments.
  329.   #-----------------------------------------------------------------------------
  330.   def party_equipped
  331.     e = 0
  332.     return e if @item.is_a?(RPG::Item)
  333.     for member in $game_party.members
  334.       case @item
  335.       when RPG::Weapon
  336.         if member.weapons.include?(@item)
  337.           e += 1
  338.         end
  339.       when RPG::Armor
  340.         if member.armors.include?(@item)
  341.           e += 1
  342.         end
  343.       end
  344.     end
  345.     return e
  346.   end
  347.  
  348. end
  349.  
  350. ################################################################################
  351. #*******************************************************************************
  352. #                       Window SynthShopActors
  353. ################################################################################
  354. class Window_SynthShopActors < Window_Selectable
  355.  
  356.   attr_accessor :item
  357.  
  358.   #-----------------------------------------------------------------------------
  359.   # Initialize
  360.   #-----------------------------------------------------------------------------
  361.   def initialize(item)
  362.     super(0, 288, 544, 128)
  363.     @party = $game_party.members
  364.     @item = item
  365.     @item_max = @party.size
  366.     @column_max = @party.size
  367.     refresh
  368.     self.index = -1
  369.     self.active = false
  370.   end
  371.  
  372.   #-----------------------------------------------------------------------------
  373.   # Refresh
  374.   #-----------------------------------------------------------------------------
  375.   def refresh
  376.     create_contents
  377.     for i in 0...@item_max
  378.       draw_member(i)
  379.     end
  380.   end
  381.  
  382.   #-----------------------------------------------------------------------------
  383.   # New Equipment Change
  384.   #-----------------------------------------------------------------------------
  385.   def new_equipment_change(value1, value2)
  386.     return 0 if value1 == value2
  387.     return value1 - value2
  388.   end
  389.  
  390.   #-----------------------------------------------------------------------------
  391.   # Draw Member
  392.   #-----------------------------------------------------------------------------
  393.   def draw_member(index)
  394.     rect = item_rect(index)
  395.     rect.x += 3
  396.     rect.width -= 8
  397.     draw_actor_face(@party[index], rect.x, rect.y, 96)
  398.     return if @item.is_a?(RPG::Item)
  399.     return if !@party[index].equippable?(@item)
  400.     mimic = @party[index].clone
  401.     if @item.is_a?(RPG::Weapon)
  402.       mimic.change_equip(0, @item)
  403.       change = new_equipment_change(mimic.atk, @party[index].atk)
  404.     else
  405.       mimic.change_equip(@item.kind, @item)
  406.       change = new_equipment_change(mimic.def, @party[index].def)
  407.     end
  408.     return if change == 0
  409.     up = change > 0 ? true : false
  410.     self.contents.font.color = change > 0 ? power_up_color : power_down_color
  411.     if up
  412.       self.contents.draw_text(rect.x + 72, rect.y, self.width, WLH, "+" + change.to_s)
  413.     else
  414.       self.contents.draw_text(rect.x + 72, rect.y, self.width, WLH, change.to_s)
  415.     end
  416.   end
  417.  
  418.   #-----------------------------------------------------------------------------
  419.   # Item Rect
  420.   #-----------------------------------------------------------------------------
  421.   def item_rect(index)
  422.     rect = Rect.new(0, 0, 0, 0)
  423.     rect.width = (contents.width + @spacing) / @column_max - @spacing
  424.     rect.height = 96
  425.     rect.x = index % @column_max * (rect.width + @spacing)
  426.     rect.y = index / @column_max * 96
  427.     return rect
  428.   end
  429.  
  430. end
  431.  
  432. ################################################################################
  433. #*******************************************************************************
  434. #                        Window SynthShopRequired
  435. ################################################################################
  436. class Window_SynthShopRequired < Window_Selectable
  437.  
  438.   attr_accessor :item
  439.  
  440.   #-----------------------------------------------------------------------------
  441.   # Initialize
  442.   #-----------------------------------------------------------------------------
  443.   def initialize(item)
  444.     super(304, 172, 240, 116)
  445.     @item = item
  446.     @synth = []
  447.     refresh
  448.     self.active = false
  449.     self.index = 0
  450.   end
  451.  
  452.   #-----------------------------------------------------------------------------
  453.   # Synth Item
  454.   #
  455.   # synthesis : [item_type, item_id, item_amount]
  456.   #-----------------------------------------------------------------------------
  457.   def synth_item(synthesis)
  458.     case synthesis[0]
  459.     when 0
  460.       return $data_items[synthesis[1]]
  461.     when 1
  462.       return $data_weapons[synthesis[1]]
  463.     when 2
  464.       return $data_armors[synthesis[1]]
  465.     end
  466.   end
  467.  
  468.   #-----------------------------------------------------------------------------
  469.   # Refresh
  470.   #-----------------------------------------------------------------------------
  471.   def refresh
  472.     self.contents.clear
  473.     if @item.nil?
  474.       @item_max = 0
  475.     else
  476.       @item_max = @item.synth.size
  477.     end
  478.     self.index = 0
  479.     return if @item_max == 0
  480.     for i in 0...@item_max
  481.       draw_material(i, @item.synth[i])
  482.     end
  483.   end
  484.  
  485.   #-----------------------------------------------------------------------------
  486.   # Draw Material
  487.   #-----------------------------------------------------------------------------
  488.   def draw_material(index, synthesis)
  489.     rect = item_rect(index)
  490.     rect.x += 4
  491.     rect.width -= 8
  492.     s_item = synth_item(synthesis)
  493.     draw_icon(s_item.icon_index, rect.x, rect.y)
  494.     self.contents.draw_text(rect.x + 26, rect.y, self.width, WLH, s_item.name)
  495.     self.contents.draw_text(rect.x, rect.y, self.width - 50, WLH, "x" + synthesis[2].to_s, 2)
  496.   end
  497.  
  498. end
  499.  
  500. ################################################################################
  501. #*******************************************************************************
  502. #                        Window SynthSuccess
  503. ################################################################################
  504. class Window_SynthSuccess < Window_Base
  505.  
  506.   attr_accessor :created_item
  507.   attr_accessor :created_amount
  508.  
  509.   #-----------------------------------------------------------------------------
  510.   # Initialize
  511.   #-----------------------------------------------------------------------------
  512.   def initialize
  513.     super(0, 180, 544, 56)
  514.     @string = Ixfuru::SynthShop::SYNTH_SUCCESS_STRING
  515.     @created_item = nil
  516.     @created_amount = 0
  517.     refresh
  518.     self.visible = false
  519.   end
  520.  
  521.   #-----------------------------------------------------------------------------
  522.   # Refresh
  523.   #-----------------------------------------------------------------------------
  524.   def refresh
  525.     self.contents.clear
  526.     return if @created_item.nil?
  527.     as = self.contents.text_size(@created_amount.to_s).width
  528.     ts = self.contents.text_size(@created_item.name).width + 26 + as
  529.     ss = self.contents.text_size(@string).width
  530.     csize = ts + ss
  531.     centered_x = ((self.width - 32) / 2) - (csize / 2)
  532.     self.contents.draw_text(centered_x, 0, self.width, WLH, @created_amount.to_s)
  533.     draw_icon(@created_item.icon_index, centered_x + as, 0)
  534.     self.contents.draw_text(centered_x + as + 26, 0, self.width, WLH, @created_item.name)
  535.     self.contents.draw_text((centered_x + as) + ts, 0, self.width, WLH, @string)
  536.   end
  537.  
  538. end
  539.  
  540. ################################################################################
  541. #*******************************************************************************
  542. #                            WINDOW SYNTH NUMBER
  543. ################################################################################
  544. class Window_SynthNumber < Window_Base
  545.  
  546.   attr_accessor :number
  547.   attr_accessor   :max_number
  548.   attr_accessor :price
  549.  
  550.   #-----------------------------------------------------------------------------
  551.   # Initialize
  552.   #-----------------------------------------------------------------------------
  553.   def initialize
  554.     super(154, 144, 204, 128)
  555.     @number = 1
  556.     @max_number = 99
  557.     @price = 0
  558.     refresh
  559.     self.visible = false
  560.   end
  561.  
  562.   #-----------------------------------------------------------------------------
  563.   # Refresh
  564.   #-----------------------------------------------------------------------------
  565.   def refresh
  566.     self.contents.clear
  567.     self.contents.font.color = system_color
  568.     self.contents.draw_text(0, 0, self.width - 32, WLH, "How many?", 1)
  569.     self.contents.draw_text(0, WLH * 2, self.width - 32, WLH, "Total Price:", 1)
  570.     self.contents.font.color = normal_color
  571.     self.contents.draw_text(0, WLH, self.width - 32, WLH, "x" + @number.to_s, 1)
  572.     self.contents.draw_text(0, WLH * 3, self.width - 32, WLH, total_synth_price.to_s, 1)
  573.   end
  574.  
  575.   #-----------------------------------------------------------------------------
  576.   # Total Synth Price
  577.   #-----------------------------------------------------------------------------
  578.   def total_synth_price
  579.     return @number * @price
  580.   end
  581.  
  582. end
  583.  
  584. ################################################################################
  585. #*******************************************************************************
  586. #                       Scene SynthShop
  587. ################################################################################
  588. class Scene_SynthShop < Scene_Base
  589.  
  590.  
  591.   #-----------------------------------------------------------------------------
  592.   # Start
  593.   #-----------------------------------------------------------------------------
  594.   def start
  595.     super
  596.     create_menu_background
  597.     @win_shop = Window_SynthShopItems.new
  598.     @item = @win_shop.goods[@win_shop.index]
  599.     @win_status = Window_SynthShopStatus.new(@item)
  600.     @win_actors = Window_SynthShopActors.new(@item)
  601.     @win_required = Window_SynthShopRequired.new(@item)
  602.     @win_help = Window_Help.new
  603.     @win_number = Window_SynthNumber.new
  604.     @win_success = Window_SynthSuccess.new
  605.   end
  606.  
  607.   #-----------------------------------------------------------------------------
  608.   # Frame Update
  609.   #-----------------------------------------------------------------------------
  610.   def update
  611.     super
  612.     if @win_success.visible
  613.       update_success
  614.     elsif @win_number.visible
  615.       update_number
  616.     elsif @win_required.active
  617.       update_required
  618.     elsif @win_shop.active
  619.       update_shop
  620.     end
  621.   end
  622.  
  623.   #-----------------------------------------------------------------------------
  624.   # Update Success
  625.   #-----------------------------------------------------------------------------
  626.   def update_success
  627.     if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  628.       Sound.play_cancel
  629.       @win_success.visible = false
  630.       @win_shop.active = true
  631.     end
  632.   end
  633.  
  634.   #------------------------------------------------------------------------------
  635.   # Window Toggle Button
  636.   #-----------------------------------------------------------------------------
  637.   def window_toggle_button
  638.     case Ixfuru::SynthShop::SYNTH_WINDOW_CONTROL_KEYS
  639.     when 0
  640.       if @win_required.active
  641.         return Input::L
  642.       else
  643.         return Input::R
  644.       end
  645.     when 1
  646.       if @win_required.active
  647.         return Input::LEFT
  648.       else
  649.         return Input::RIGHT
  650.       end
  651.     end
  652.   end
  653.  
  654.   #-----------------------------------------------------------------------------
  655.   # Update Required
  656.   #-----------------------------------------------------------------------------
  657.   def update_required
  658.     @win_required.update
  659.     if Input.trigger?(window_toggle_button)
  660.       Sound.play_decision
  661.       @win_required.active = false
  662.       @win_shop.active = true
  663.     end
  664.   end
  665.  
  666.   #-----------------------------------------------------------------------------
  667.   # Update Shop
  668.   #-----------------------------------------------------------------------------
  669.   def update_shop
  670.     @win_shop.update
  671.     @item = @win_shop.goods[@win_shop.index]
  672.     @win_help.set_text(@item.description, 1)
  673.     update_item_windows
  674.     if Input.trigger?(Input::C)
  675.       if @win_shop.enabled?(@win_shop.index)
  676.         Sound.play_decision
  677.         activate_number
  678.       else
  679.         Sound.play_buzzer
  680.       end
  681.     elsif Input.trigger?(Input::B)
  682.       Sound.play_cancel
  683.       $game_switches[Ixfuru::SynthShop::SYNTH_SHOP_SWITCH] = false
  684.       $scene = Scene_Map.new
  685.     elsif Input.trigger?(window_toggle_button)
  686.       Sound.play_decision
  687.       @win_shop.active = false
  688.       @win_required.active = true
  689.     end
  690.   end
  691.  
  692.   #-----------------------------------------------------------------------------
  693.   # Activate Number
  694.   #-----------------------------------------------------------------------------
  695.   def activate_number
  696.     @win_shop.active = false
  697.     @win_number.number = 1
  698.     @win_number.price = @item.synth_cost
  699.     @win_number.max_number = maximum_possible_builds
  700.     @win_number.refresh
  701.     @win_number.visible = true
  702.   end
  703.  
  704.   #-----------------------------------------------------------------------------
  705.   # Synth Material
  706.   #-----------------------------------------------------------------------------
  707.   def synth_material(synthesis)
  708.     case synthesis[0]
  709.     when 0 # item
  710.       return $data_items[synthesis[1]]
  711.     when 1 # weapon
  712.       return $data_weapons[synthesis[1]]
  713.     when 2 # armor
  714.       return $data_armors[synthesis[1]]
  715.     end
  716.   end
  717.  
  718.   #-----------------------------------------------------------------------------
  719.   # Maximum Possible Builds
  720.   #-----------------------------------------------------------------------------
  721.   def maximum_possible_builds
  722.     return 99 if @item.synth.empty?
  723.     result = 0
  724.     party = $game_party
  725.     gold = party.gold
  726.     for i in 1..99
  727.       has = 0
  728.       for s in @item.synth
  729.         material = synth_material(s)
  730.         a = s[2] # Amount required for each synth
  731.         next unless party.item_number(material) >= a * i
  732.         next unless gold >= @item.synth_cost * i
  733.         has += 1
  734.       end
  735.       if has >= @item.synth.size
  736.         result += 1
  737.       end
  738.     end
  739.     return [result, 99].min
  740.   end
  741.  
  742.   #-----------------------------------------------------------------------------
  743.   # Update Number
  744.   #-----------------------------------------------------------------------------
  745.   def update_number
  746.     if Input.trigger?(Input::C)
  747.       if @win_number.number <= @win_number.max_number
  748.         play_synth_success
  749.         process_synthesis
  750.       else
  751.         Sound.play_buzzer
  752.       end
  753.     elsif Input.trigger?(Input::UP)
  754.       Sound.play_cursor
  755.       @win_number.number = [@win_number.number + 1, @win_number.max_number].min
  756.       @win_number.refresh
  757.     elsif Input.trigger?(Input::DOWN)
  758.       Sound.play_cursor
  759.       @win_number.number = [@win_number.number - 1, 1].max
  760.       @win_number.refresh
  761.     elsif Input.trigger?(Input::B)
  762.       Sound.play_cancel
  763.       @win_number.visible = false
  764.       @win_shop.active = true
  765.     end
  766.   end
  767.  
  768.   #-----------------------------------------------------------------------------
  769.   # Play Synth Success
  770.   #-----------------------------------------------------------------------------
  771.   def play_synth_success
  772.     se = Ixfuru::SynthShop::SYNTH_SOUND
  773.     RPG::SE.new(se[0], se[1], se[2]).play
  774.   end
  775.  
  776.   #-----------------------------------------------------------------------------
  777.   # Process Synthesis
  778.   #-----------------------------------------------------------------------------
  779.   def process_synthesis
  780.     for i in 0...@win_number.number
  781.       for s in @item.synth
  782.         material = synth_material(s)
  783.         $game_party.lose_item(material, s[2])
  784.       end
  785.     end
  786.     $game_party.gain_item(@item, @win_number.number)
  787.     $game_party.lose_gold(@item.synth_cost * @win_number.number)
  788.     @win_success.created_item = @item
  789.     @win_success.created_amount = @win_number.number
  790.     @win_success.refresh
  791.     @win_status.refresh
  792.     @win_shop.refresh
  793.     @win_number.visible = false
  794.     @win_success.visible = true
  795.   end
  796.  
  797.   #-----------------------------------------------------------------------------
  798.   # Update Item Windows
  799.   #-----------------------------------------------------------------------------
  800.   def update_item_windows
  801.     windows = [@win_status, @win_actors, @win_required]
  802.     for window in windows
  803.       if window.item != @item
  804.         window.item = @item
  805.         window.refresh
  806.       end
  807.     end
  808.   end
  809.  
  810.   #-----------------------------------------------------------------------------
  811.   # Terminate
  812.   #-----------------------------------------------------------------------------
  813.   def terminate
  814.     super
  815.     dispose_menu_background
  816.     windows = [@win_shop, @win_required, @win_status, @win_actors, @win_help,
  817.     @win_success, @win_number]
  818.     for window in windows
  819.       window.dispose
  820.     end
  821.   end
  822.      
  823. end
Advertisement
Add Comment
Please, Sign In to add comment