Guest User

Alchemy Code v1.0.1

a guest
Nov 2nd, 2014
437
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Alchemy System
  3. # by: Jeneeus Guruman
  4. #------------------------------------------------------------------------------
  5. #  This script allows to:
  6. #     - Create items, weapons, and armors via using skills or items with a
  7. #     success rate based on the user's parameters, $game_variables, etc.
  8. #
  9. #   How to use:
  10. #
  11. #     * Plug-n-play
  12. #     * Place this below default and non-aliased scripts.
  13. #     * Only usable outside the battle. Therefore, the occasion must be set to
  14. #     "only from the menu" or the skill/item won't work.
  15. #     * When using an item creation SKILL, the scope must be set to "none" or
  16. #     the skill won't work.
  17. #     * When using an item creation ITEM, the scope must be set to either
  18. #     "one ally" or "user" or the item won't work.
  19. #      
  20. #       <alchemy>
  21. #         * Using the skill or item will activate item creation scene.
  22. #
  23. #     * Note: Place this notetag to the skill or item that opens the
  24. #       alchemy scene.
  25. #
  26. #       <alche_ireq: type, id, amount>
  27. #       type: the type of item
  28. #         0 = Items ($data_items)
  29. #         1 = Weapons ($data_weapons)
  30. #         2 = Armors ($data_armors)
  31. #       id: the id of an item/weapon/armor in the database
  32. #       amount: the amount of the specified item needed to create this item
  33. #       Notetag examples:
  34. #         <alche_ireq: 0, 1, 2>  => An item needs to have at least 2 "Potions"
  35. #       in the inventory to create this item.
  36. #
  37. #     * Note: If you put more than 1 requirement, the item can be made if ALL of
  38. #       the items is in the party's inventory.
  39. #
  40. #       <alche_areq: id>
  41. #       id: the actor that will able to exclusively create the item.
  42. #
  43. #     * Note: This notetag is optional. If this is not specified, all actors
  44. #       that have the ability can create this item.
  45. #
  46. #       <alche_lreq: n>
  47. #       n: the required level to create this item. the item will not be shown
  48. #       if the level is below the requirement.
  49. #
  50. #     * Note: This notetag is required or the item will not be shown.
  51. #
  52. #       <alche_greq: n>
  53. #       n: the required gold to create this item.
  54. #
  55. #     * Note: This notetag is optional. If this is not specified, no gold is
  56. #       needed.
  57. #
  58. #       <success_rate: 'formula'>
  59. #       formula: The formula for calculating the creation success rate.
  60. #       The formula is the same as the formula in skill damage except that
  61. #       there is no target (which is supposed to be expressed as 'b').
  62. #       Take note that the quotations (') are included to make it work.
  63. #       Also multiple lines of one fourmula are allowed.
  64. #       Notetag examples:
  65. #         <alche_success>: 'a.level + a.luk / 10'>  
  66. #       => If the user's level is 50 having 300 LUK, the success rate will have
  67. #       80% chance to make this item, provided that the maximum success rate is 100.
  68. #         <alche_success: '100'>  
  69. #       => The item has 100% chance to create this, provided that the maximum success rate is 100.
  70. #
  71. #     * Note: This notetag is required. To display the decimal parts, put #.0
  72. #     (if it is a whole number) or variable.to_f (if it is a variable).
  73. #     For example, <success_rate: 'a.level.to_f + a.luk.to_f / 10.0'>
  74. #
  75. #==============================================================================
  76.  
  77. module Jene
  78.   #--------------------------------------------------------------------------
  79.   # * BASE_SUCCESS
  80.   #     Minimum success rate chance.
  81.   #--------------------------------------------------------------------------
  82.   BASE_SUCCESS = 0
  83.   #--------------------------------------------------------------------------
  84.   # * MAX_SUCCESS
  85.   #     The target success rate to have sure creation. Take note that it needs
  86.   #   to be higher than BASE_SUCCESS.
  87.   #--------------------------------------------------------------------------
  88.   MAX_SUCCESS = 100
  89.   #--------------------------------------------------------------------------
  90.   # * CREATION_TIME
  91.   #     The time in frames that the item creation will be done.
  92.   #   60 frames = 1 second
  93.   #--------------------------------------------------------------------------
  94.   CREATION_TIME = 60
  95.   #--------------------------------------------------------------------------
  96.   # * CREATION_NAME
  97.   #     The text to be displayed during CREATION_TIME.
  98.   #--------------------------------------------------------------------------
  99.   CREATION_NAME = 'Creating Item'
  100.   #--------------------------------------------------------------------------
  101.   # * CREATION_FAIL_NAME
  102.   #     The text to be displayed if failed.
  103.   #--------------------------------------------------------------------------
  104.   CREATION_FAIL_NAME = 'EPIC FAIL!!!'
  105.   #--------------------------------------------------------------------------
  106.   # * CREATION_SUCCESS_NAME
  107.   #     The text to be displayed if successful.
  108.   #--------------------------------------------------------------------------
  109.   CREATION_SUCCESS_NAME = 'SO MUCH WIN!!!'
  110.   #--------------------------------------------------------------------------
  111.   # * CREATION_SOUND
  112.   #     The ME to play while creating an item. This will not be played if the
  113.   #   CREATION_TIME is less than 30 frames.
  114.   #--------------------------------------------------------------------------
  115.   CREATION_SOUND = 'Bell2'
  116.   #--------------------------------------------------------------------------
  117.   # * CREATION_FAIL_SOUND
  118.   #     The ME to play if item creation fails.
  119.   #--------------------------------------------------------------------------
  120.   CREATION_FAIL_SOUND = 'Break'
  121.   #--------------------------------------------------------------------------
  122.   # * CREATION_SUCCESS_SOUND
  123.   #     The ME to play if item creation is successful.
  124.   #--------------------------------------------------------------------------
  125.   CREATION_SUCCESS_SOUND = 'Item3'
  126.  
  127. #----------------------------------------------------------------------------
  128. # * Do not edit anything below here. Or else, evil errors will be released
  129. # from the other dimension of evil.
  130. #----------------------------------------------------------------------------
  131.  
  132.   JENE_ALCHEMY = /<alchemy>/i
  133.   ALCHE_SUCCESS_RATE = /<alche_success[:]?\s+'([\s\S]*)'>/i
  134.   ALCHE_LEVEL_REQ = /<alche_lreq[:]?\s+(\d+)>/i
  135.   ALCHE_GOLD_REQ = /<alche_greq[:]?\s+(\d+)>/i
  136.   ALCHE_ACTOR_REQ = /<alche_areq[:]?\s+(\d+)>/i
  137.   ALCHE_ITEM_REQ = /<alche_ireq[:]?\s*(\d+)\s*[,]?\s*(\d+)\s*[,]?\s*(\d+)>/i
  138.  
  139.   def self.alche_creation_se
  140.     Audio.se_play("Audio/SE/" + CREATION_SOUND)
  141.   end
  142.  
  143.   def self.alche_fail_se
  144.     Audio.se_play("Audio/SE/" + CREATION_FAIL_SOUND)
  145.   end
  146.  
  147.   def self.alche_success_se
  148.     Audio.se_play("Audio/SE/" + CREATION_SUCCESS_SOUND)
  149.   end
  150.  
  151.   def self.success_rate(f, a, v)
  152.     [[eval(f), BASE_SUCCESS].max, MAX_SUCCESS].min rescue BASE_SUCCESS
  153.   end
  154. end
  155.  
  156. class RPG::Item
  157.  
  158.   def alche_success(actor)
  159.     self.note.each_line { |line|
  160.       if line =~ Jene::ALCHE_SUCCESS_RATE
  161.         return Jene.success_rate($1, actor, $game_variables)
  162.       end
  163.     }
  164.     return Jene::BASE_SUCCESS
  165.   end
  166.  
  167.   def alche_ireq
  168.     bonus_arr = []
  169.     self.note.each_line { |line|
  170.       if line =~ Jene::ALCHE_ITEM_REQ
  171.         bonus_arr.push([$1.to_i, $2.to_i, $3.to_i])
  172.       end
  173.     }
  174.     return bonus_arr
  175.   end
  176.  
  177.   def alche_lreq
  178.     self.note.each_line { |line|
  179.       if line =~ Jene::ALCHE_LEVEL_REQ
  180.         return $1.to_i
  181.       end
  182.     }
  183.     return 0
  184.   end
  185.  
  186.   def alche_areq
  187.     bonus_arr = []
  188.     self.note.each_line { |line|
  189.       if line =~ Jene::ALCHE_ACTOR_REQ
  190.         return bonus_arr.push($1.to_i)
  191.       end
  192.     }
  193.     return bonus_arr
  194.   end
  195.  
  196.   def alche_greq
  197.     self.note.each_line { |line|
  198.       if line =~ Jene::ALCHE_GOLD_REQ
  199.         return $1.to_i
  200.       end
  201.     }
  202.     return 0
  203.   end
  204. end
  205.  
  206. class RPG::EquipItem
  207.  
  208.   def alche_success(actor)
  209.     self.note.each_line { |line|
  210.       if line =~ Jene::ALCHE_SUCCESS_RATE
  211.         return Jene.success_rate($1, actor, $game_variables)
  212.       end
  213.     }
  214.     return Jene::BASE_SUCCESS
  215.   end
  216.  
  217.   def alche_ireq
  218.     bonus_arr = []
  219.     self.note.each_line { |line|
  220.       if line =~ Jene::ALCHE_ITEM_REQ
  221.         bonus_arr.push([$1.to_i, $2.to_i, $3.to_i])
  222.       end
  223.     }
  224.     return bonus_arr
  225.   end
  226.  
  227.   def alche_lreq
  228.     self.note.each_line { |line|
  229.       if line =~ Jene::ALCHE_LEVEL_REQ
  230.         return $1.to_i
  231.       end
  232.     }
  233.     return 0
  234.   end
  235.  
  236.   def alche_areq
  237.     bonus_arr = []
  238.     self.note.each_line { |line|
  239.       if line =~ Jene::ALCHE_ACTOR_REQ
  240.         return bonus_arr.push($1.to_i)
  241.       end
  242.     }
  243.     return bonus_arr
  244.   end
  245.  
  246.   def alche_greq
  247.     self.note.each_line { |line|
  248.       if line =~ Jene::ALCHE_GOLD_REQ
  249.         return $1.to_i
  250.       end
  251.     }
  252.     return 0
  253.   end
  254. end
  255.  
  256. class RPG::UsableItem
  257.   def alchemy?
  258.     self.note.each_line { |line|
  259.       if line =~ Jene::JENE_ALCHEMY
  260.         return true
  261.       end
  262.     }
  263.     return false
  264.   end
  265. end
  266.  
  267. #==============================================================================
  268. # ** Game_BattlerBase
  269. #------------------------------------------------------------------------------
  270. #  This base class handles battlers. It mainly contains methods for calculating
  271. # parameters. It is used as a super class of the Game_Battler class.
  272. #==============================================================================
  273.  
  274. class Game_BattlerBase
  275.   #--------------------------------------------------------------------------
  276.   # * Determine Skill/Item Usability
  277.   #--------------------------------------------------------------------------
  278.   alias jene_alche_usable? usable?
  279.   def usable?(item)
  280.     return true if item.is_a?(RPG::UsableItem) && alche_any? && actor? && item.alchemy?
  281.     jene_alche_usable?(item)
  282.   end
  283.   #--------------------------------------------------------------------------
  284.   # * Check If Any Item Creation Exists
  285.   #--------------------------------------------------------------------------
  286.   def alche_any?
  287.     items = []
  288.     $data_items.each do |i|
  289.       next if i == nil
  290.       if i.alche_lreq <= level && i.alche_lreq > 0
  291.         items.push(i)
  292.       end
  293.     end
  294.     !items.empty?
  295.   end
  296. end
  297.  
  298. #==============================================================================
  299. # ** Window_Gold
  300. #------------------------------------------------------------------------------
  301. #  This window displays the party's gold.
  302. #==============================================================================
  303.  
  304. class Window_AlcheLoad < Window_Base
  305.   #--------------------------------------------------------------------------
  306.   # * Object Initialization
  307.   #--------------------------------------------------------------------------
  308.   def initialize
  309.     x = (Graphics.width - window_width) / 2
  310.     y = (Graphics.height - window_height) / 2
  311.     super(x, y, window_width, window_height)
  312.     @text = Jene::CREATION_NAME + "..."
  313.     @loaded = 0.0
  314.     @start = false
  315.     @item = nil
  316.     @success_rate = Jene::BASE_SUCCESS
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   # * Get Window Width
  320.   #--------------------------------------------------------------------------
  321.   def window_width
  322.     return Graphics.width / 2
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # * Get Window Width
  326.   #--------------------------------------------------------------------------
  327.   def window_height
  328.     return fitting_height(2)
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   # * Check Loading
  332.   #--------------------------------------------------------------------------
  333.   def loading?
  334.     @start
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # * Check Loading
  338.   #--------------------------------------------------------------------------
  339.   def done_loading?
  340.     !@start && @loaded > 0
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # * Start Loading
  344.   #--------------------------------------------------------------------------
  345.   def start_loading(item)
  346.     @loaded = 0.0
  347.     @start = true
  348.     @item = item
  349.   end
  350.   #--------------------------------------------------------------------------
  351.   # * Get Window Width
  352.   #--------------------------------------------------------------------------
  353.   def text=(text)
  354.     @text = text
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # * Set Success Rate
  358.   #--------------------------------------------------------------------------
  359.   def set_success
  360.     @success_rate = rand(Jene::MAX_SUCCESS)
  361.   end
  362.   #--------------------------------------------------------------------------
  363.   # * Get Success Rate
  364.   #--------------------------------------------------------------------------
  365.   def success?
  366.     return false if @item == nil
  367.     actor = SceneManager.scene.previous_scene.is_a?(Scene_Skill) ?
  368.       $game_party.menu_actor : $game_party.target_actor
  369.     @item.alche_success(actor) > @success_rate
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # * Frame Update
  373.   #--------------------------------------------------------------------------
  374.   def update
  375.     super
  376.     update_progress if @start
  377.   end
  378.   #--------------------------------------------------------------------------
  379.   # * Update Item Creation Processing
  380.   #--------------------------------------------------------------------------
  381.   def update_progress
  382.     contents.clear
  383.     pw = window_width - 24
  384.     if @loaded >= pw
  385.       @start = false
  386.       set_success
  387.       if success?
  388.         Jene.alche_success_se
  389.         @text = Jene::CREATION_SUCCESS_NAME
  390.       else
  391.         Jene.alche_fail_se
  392.         @text = Jene::CREATION_FAIL_NAME
  393.       end
  394.     else
  395.       @loaded += pw.to_f / [Jene::CREATION_TIME.to_f, 1.0].max
  396.     end
  397.     draw_text(4, 0, pw, line_height, @text, 1)
  398.     rate = [@loaded / pw, 1].min
  399.     draw_gauge(4, line_height + 4, pw, rate, system_color, normal_color)
  400.   end
  401. end
  402.  
  403. #==============================================================================
  404. # ** Game_Battler
  405. #------------------------------------------------------------------------------
  406. #  A battler class with methods for sprites and actions added. This class
  407. # is used as a super class of the Game_Actor class and Game_Enemy class.
  408. #==============================================================================
  409.  
  410. class Game_Battler < Game_BattlerBase
  411.   #--------------------------------------------------------------------------
  412.   # * Use Skill/Item
  413.   #    Called for the acting side and applies the effect to other than the user.
  414.   #--------------------------------------------------------------------------
  415.   alias jene_alche_use_item use_item
  416.   def use_item(item)
  417.     if !SceneManager.scene_is?(Scene_Battle) && item.alchemy? && actor?
  418.       scene = SceneManager.scene
  419.       SceneManager.call(Scene_Alche)
  420.       SceneManager.scene.previous_scene = scene
  421.     end
  422.     jene_alche_use_item(item) unless item.alchemy?
  423.   end
  424. end
  425.  
  426. #==============================================================================
  427. # ** Window_Alche
  428. #------------------------------------------------------------------------------
  429. #  This window displays a list of buyable goods on the shop screen.
  430. #==============================================================================
  431.  
  432. class Window_Alche < Window_Selectable
  433.   #--------------------------------------------------------------------------
  434.   # * Public Instance Variables
  435.   #--------------------------------------------------------------------------
  436.   attr_reader   :status_window            # Status window
  437.   #--------------------------------------------------------------------------
  438.   # * Object Initialization
  439.   #--------------------------------------------------------------------------
  440.   def initialize(x, y, height, actor)
  441.     super(x, y, window_width, height)
  442.     @actor = actor
  443.     @money = 0
  444.     refresh
  445.     select(0)
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # * Get Window Width
  449.   #--------------------------------------------------------------------------
  450.   def window_width
  451.     return 200
  452.   end
  453.   #--------------------------------------------------------------------------
  454.   # * Get Number of Items
  455.   #--------------------------------------------------------------------------
  456.   def item_max
  457.     @data ? @data.size : 1
  458.   end
  459.   #--------------------------------------------------------------------------
  460.   # * Get Item
  461.   #--------------------------------------------------------------------------
  462.   def item
  463.     @data[index]
  464.   end
  465.   #--------------------------------------------------------------------------
  466.   # * Get Activation State of Selection Item
  467.   #--------------------------------------------------------------------------
  468.   def current_item_enabled?
  469.     enable?(@data[index])
  470.   end
  471.   #--------------------------------------------------------------------------
  472.   # * Get Price of Item
  473.   #--------------------------------------------------------------------------
  474.   def ingre_ok?(item)
  475.     return false if item.alche_greq > $game_party.gold
  476.     item.alche_ireq.each_with_index do |ingre, i|
  477.       item_ingre = nil
  478.       case ingre[0]
  479.       when 0
  480.         item_ingre = $data_items[ingre[1]]
  481.       when 1
  482.         item_ingre = $data_weapons[ingre[1]]
  483.       when 2
  484.         item_ingre = $data_armors[ingre[1]]
  485.       end
  486.       return false if item_ingre == nil
  487.       return false if ingre[2] > $game_party.item_number(item_ingre)
  488.     end
  489.     return true
  490.   end
  491.   #--------------------------------------------------------------------------
  492.   # * Display in Enabled State?
  493.   #--------------------------------------------------------------------------
  494.   def enable?(item)
  495.     item && ingre_ok?(item) && !$game_party.item_max?(item)
  496.   end
  497.   #--------------------------------------------------------------------------
  498.   # * Refresh
  499.   #--------------------------------------------------------------------------
  500.   def refresh
  501.     make_item_list
  502.     create_contents
  503.     draw_all_items
  504.   end
  505.   #--------------------------------------------------------------------------
  506.   # * Create Item List
  507.   #--------------------------------------------------------------------------
  508.   def make_item_list
  509.     @data = []
  510.     ($data_items + $data_weapons + $data_armors).each do |items|
  511.       next if items == nil
  512.       if items.alche_lreq <= @actor.level && items.alche_lreq > 0 &&
  513.         (items.alche_areq.include?(@actor.id) || items.alche_areq.empty?)
  514.         @data.push(items)
  515.       end
  516.     end
  517.   end
  518.   #--------------------------------------------------------------------------
  519.   # * Draw Item
  520.   #--------------------------------------------------------------------------
  521.   def draw_item(index)
  522.     item = @data[index]
  523.     rect = item_rect(index)
  524.     draw_item_name(item, rect.x, rect.y, enable?(item), window_width * 3 / 4)
  525.   end
  526.   #--------------------------------------------------------------------------
  527.   # * Set Status Window
  528.   #--------------------------------------------------------------------------
  529.   def status_window=(status_window)
  530.     @status_window = status_window
  531.     call_update_help
  532.   end
  533.   #--------------------------------------------------------------------------
  534.   # * Update Help Text
  535.   #--------------------------------------------------------------------------
  536.   def update_help
  537.     @help_window.set_item(item) if @help_window
  538.     @status_window.item = item if @status_window
  539.   end
  540. end
  541.  
  542. #==============================================================================
  543. # ** Window_GameEnd
  544. #------------------------------------------------------------------------------
  545. #  This window is for selecting Go to Title/Shut Down on the game over screen.
  546. #==============================================================================
  547.  
  548. class Window_AlcheCommand < Window_Command
  549.   #--------------------------------------------------------------------------
  550.   # * Object Initialization
  551.   #--------------------------------------------------------------------------
  552.   def initialize(y)
  553.     super(12, y)
  554.     self.openness = 0
  555.     select(1)
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # * Create Command List
  559.   #--------------------------------------------------------------------------
  560.   def make_command_list
  561.     add_command("Yes", :make)
  562.     add_command("No",  :cancel)
  563.   end
  564. end
  565.  
  566.  
  567. #==============================================================================
  568. # ** Scene_Shop
  569. #------------------------------------------------------------------------------
  570. #  This class performs shop screen processing.
  571. #==============================================================================
  572.  
  573. class Scene_Alche < Scene_MenuBase
  574.   #--------------------------------------------------------------------------
  575.   # * Start Processing
  576.   #--------------------------------------------------------------------------
  577.   def start
  578.     super
  579.     create_help_window
  580.     create_alche_window
  581.     create_status_window
  582.     create_confirm_window
  583.     create_progress_window
  584.     activate_alche_window
  585.   end
  586.   #--------------------------------------------------------------------------
  587.   # * Set Previous Scene
  588.   #--------------------------------------------------------------------------
  589.   def previous_scene=(scene)
  590.     @scene = scene
  591.   end
  592.   #--------------------------------------------------------------------------
  593.   # * Set Previous Scene
  594.   #--------------------------------------------------------------------------
  595.   def previous_scene
  596.     @scene
  597.   end
  598.   #--------------------------------------------------------------------------
  599.   # * Frame Update
  600.   #--------------------------------------------------------------------------
  601.   def update
  602.     super
  603.     if @progress_window.active && @progress_window.done_loading?
  604.       on_alche_done if Input.trigger?(:C)
  605.     end
  606.   end
  607.   #--------------------------------------------------------------------------
  608.   # * Create Progress Window
  609.   #--------------------------------------------------------------------------
  610.   def create_progress_window
  611.     @progress_window = Window_AlcheLoad.new
  612.     @progress_window.viewport = @viewport
  613.     @progress_window.hide
  614.   end
  615.   #--------------------------------------------------------------------------
  616.   # * Create Status Window
  617.   #--------------------------------------------------------------------------
  618.   def create_status_window
  619.     wx = @result_window.width
  620.     wy = @help_window.y + @help_window.height
  621.     ww = Graphics.width - wx
  622.     wh = Graphics.height - wy
  623.     @status_window = Window_AlcheIngre.new(wx, wy, ww, wh)
  624.     @status_window.viewport = @viewport
  625.     @result_window.status_window = @status_window
  626.   end
  627.   #--------------------------------------------------------------------------
  628.   # * Create Status Window
  629.   #--------------------------------------------------------------------------
  630.   def create_confirm_window
  631.     wy = @result_window.y + 12 + @result_window.line_height * (@result_window.index + 1)
  632.     @confirm_window = Window_AlcheCommand.new(wy)
  633.     @confirm_window.viewport = @viewport
  634.     @confirm_window.set_handler(:make, method(:on_alche_confirm))
  635.     @confirm_window.set_handler(:cancel, method(:on_alche_cancel))
  636.   end
  637.   #--------------------------------------------------------------------------
  638.   # * Create Purchase Window
  639.   #--------------------------------------------------------------------------
  640.   def create_alche_window
  641.     wy = @help_window.y + @help_window.height
  642.     wh = Graphics.height - wy
  643.     actor = @scene.is_a?(Scene_Skill) ? $game_party.menu_actor : $game_party.target_actor
  644.     @result_window = Window_Alche.new(0, wy, wh, actor)
  645.     @result_window.viewport = @viewport
  646.     @result_window.help_window = @help_window
  647.     @result_window.set_handler(:ok,     method(:on_alche_ok))
  648.     @result_window.set_handler(:cancel, method(:return_scene))
  649.   end
  650.   #--------------------------------------------------------------------------
  651.   # * Activate Purchase Window
  652.   #--------------------------------------------------------------------------
  653.   def activate_alche_window
  654.     @result_window.show.activate
  655.     @status_window.show
  656.   end
  657.   #--------------------------------------------------------------------------
  658.   # * Buy [OK]
  659.   #--------------------------------------------------------------------------
  660.   def on_alche_ok
  661.     @confirm_window.open
  662.     @confirm_window.activate
  663.     @help_window.set_text("Continue " + Jene::CREATION_NAME + "?")
  664.   end
  665.   #--------------------------------------------------------------------------
  666.   # * Activate Purchase Window
  667.   #--------------------------------------------------------------------------
  668.   def activate_progress_window
  669.     @item = @result_window.item
  670.     @progress_window.text = Jene::CREATION_NAME
  671.     @progress_window.show.activate
  672.     @progress_window.start_loading(@item)
  673.   end
  674.   #--------------------------------------------------------------------------
  675.   # * Activate Purchase Window
  676.   #--------------------------------------------------------------------------
  677.   def deactivate_progress_window
  678.     @progress_window.hide.deactivate
  679.   end
  680.   #--------------------------------------------------------------------------
  681.   # * Buy [OK]
  682.   #--------------------------------------------------------------------------
  683.   def on_alche_confirm
  684.     Jene.alche_creation_se if Jene::CREATION_TIME >= 30
  685.     @confirm_window.close
  686.     activate_progress_window
  687.   end
  688.   #--------------------------------------------------------------------------
  689.   # * Buy [OK]
  690.   #--------------------------------------------------------------------------
  691.   def on_alche_done
  692.     Sound.play_ok
  693.     if @progress_window.success?
  694.       do_make
  695.     else
  696.       do_consume
  697.     end
  698.     deactivate_progress_window
  699.     @result_window.activate
  700.     @status_window.show
  701.     @result_window.refresh
  702.     @status_window.refresh
  703.   end
  704.   #--------------------------------------------------------------------------
  705.   # * Buy [OK]
  706.   #--------------------------------------------------------------------------
  707.   def on_alche_loaded
  708.     @confirm_window.open
  709.     @confirm_window.activate
  710.   end
  711.   #--------------------------------------------------------------------------
  712.   # * Buy [OK]
  713.   #--------------------------------------------------------------------------
  714.   def on_alche_cancel
  715.     @confirm_window.close
  716.     @result_window.activate
  717.   end
  718.   #--------------------------------------------------------------------------
  719.   # * Execute Purchase
  720.   #--------------------------------------------------------------------------
  721.   def do_make
  722.     do_consume
  723.     $game_party.gain_item(@item, 1)
  724.   end
  725.   #--------------------------------------------------------------------------
  726.   # * Lose All Item Requirements
  727.   #--------------------------------------------------------------------------
  728.   def do_consume
  729.     $game_party.lose_gold(@item.alche_greq)
  730.     @item.alche_ireq.each do |ingre|
  731.       item_ingre = nil
  732.       case ingre[0]
  733.       when 0
  734.         item_ingre = $data_items[ingre[1]]
  735.       when 1
  736.         item_ingre = $data_weapons[ingre[1]]
  737.       when 2
  738.         item_ingre = $data_armors[ingre[1]]
  739.       end
  740.       next if item_ingre == nil
  741.       $game_party.lose_item(item_ingre, ingre[2])
  742.     end
  743.   end
  744.   #--------------------------------------------------------------------------
  745.   # * Get Party Gold
  746.   #--------------------------------------------------------------------------
  747.   def money
  748.     @gold_window.value
  749.   end
  750.   #--------------------------------------------------------------------------
  751.   # Get Currency Unit
  752.   #--------------------------------------------------------------------------
  753.   def currency_unit
  754.     @gold_window.currency_unit
  755.   end
  756.   #--------------------------------------------------------------------------
  757.   # * Get Purchase Price
  758.   #--------------------------------------------------------------------------
  759.   def alche_price
  760.     @item.alche_greq
  761.   end
  762. end
  763.  
  764. #==============================================================================
  765. # ** Window_AlcheIngre
  766. #------------------------------------------------------------------------------
  767. #  This window displays number of items in possession and the actor's
  768. # equipment on the shop screen.
  769. #==============================================================================
  770.  
  771. class Window_AlcheIngre < Window_Base
  772.   #--------------------------------------------------------------------------
  773.   # * Object Initialization
  774.   #--------------------------------------------------------------------------
  775.   def initialize(x, y, width, height)
  776.     super(x, y, width, height)
  777.     @item = nil
  778.     @page_index = 0
  779.     refresh
  780.   end
  781.   #--------------------------------------------------------------------------
  782.   # * Refresh
  783.   #--------------------------------------------------------------------------
  784.   def refresh
  785.     contents.clear
  786.     draw_success_rate(4, 0)
  787.     draw_gold_cost(4, line_height)
  788.     draw_ingredients(4, line_height * 2) if @item != nil
  789.   end
  790.   #--------------------------------------------------------------------------
  791.   # * Set Actor
  792.   #--------------------------------------------------------------------------
  793.   def actor
  794.     SceneManager.scene.previous_scene.is_a?(Scene_Skill) ?
  795.       $game_party.menu_actor : $game_party.target_actor
  796.   end
  797.   #--------------------------------------------------------------------------
  798.   # * Set Item
  799.   #--------------------------------------------------------------------------
  800.   def item=(item)
  801.     @item = item
  802.     refresh
  803.   end
  804.   #--------------------------------------------------------------------------
  805.   # * Draw Quantity Possessed
  806.   #--------------------------------------------------------------------------
  807.   def draw_success_rate(x, y)
  808.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  809.     change_color(system_color)
  810.     draw_text(rect, "Success Rate")
  811.     change_color(normal_color)
  812.     success = Jene::BASE_SUCCESS
  813.     if @item != nil
  814.       success = @item.alche_success(actor)
  815.     end
  816.     draw_text(rect, (100.0 / Jene::MAX_SUCCESS * success).to_s + "%", 2)
  817.   end
  818.   #--------------------------------------------------------------------------
  819.   # * Draw Quantity Possessed
  820.   #--------------------------------------------------------------------------
  821.   def draw_gold_cost(x, y)
  822.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  823.     alche_gold = 0
  824.     if @item != nil
  825.       alche_gold = @item.alche_greq
  826.     end
  827.     change_color(system_color)
  828.     draw_text(rect, "Cost")
  829.     change_color(normal_color, alche_gold <= $game_party.gold)
  830.     draw_text(rect, $game_party.gold.to_s + Vocab::currency_unit +
  831.       "/" + alche_gold.to_s + Vocab::currency_unit, 2)
  832.   end
  833.   #--------------------------------------------------------------------------
  834.   # * Draw Equipment Information
  835.   #--------------------------------------------------------------------------
  836.   def draw_ingredients(x, y)
  837.     rect = Rect.new(x, y, contents.width - 4 - x, line_height)
  838.     change_color(system_color)
  839.     draw_text(rect, "Ingredients")
  840.     if @item.alche_ireq.empty?
  841.       rect.x += 24
  842.       rect.y += line_height
  843.       change_color(normal_color)
  844.       draw_text(rect, "None")
  845.     else
  846.       @item.alche_ireq.each_with_index do |ingre, i|
  847.         draw_individual_ingredients(x, y + line_height * i, ingre)
  848.       end
  849.     end
  850.   end
  851.   #--------------------------------------------------------------------------
  852.   # * Draw Actor Equipment Information
  853.   #--------------------------------------------------------------------------
  854.   def draw_individual_ingredients(x, y, ingre)
  855.     item_ingre = nil
  856.     case ingre[0]
  857.     when 0
  858.       item_ingre = $data_items[ingre[1]]
  859.     when 1
  860.       item_ingre = $data_weapons[ingre[1]]
  861.     when 2
  862.       item_ingre = $data_armors[ingre[1]]
  863.     end
  864.     qty_left = $game_party.item_number(item_ingre)
  865.     change_color(normal_color, qty_left >= ingre[2])
  866.     draw_item_name(item_ingre, x, y + line_height, qty_left >= ingre[2],
  867.       width * 3 / 4)
  868.     rect = Rect.new(x, y + line_height, contents.width - 4 - x, line_height)
  869.     draw_text(rect, qty_left.to_s + "/" + ingre[2].to_s, 2)
  870.   end
  871. end
  872.  
  873. #==============================================================================
  874. # ** Scene_ItemBase
  875. #------------------------------------------------------------------------------
  876. #  This class performs common processing for the item screen and skill screen.
  877. #==============================================================================
  878.  
  879. class Scene_ItemBase < Scene_MenuBase
  880.   #--------------------------------------------------------------------------
  881.   # * Determine if Item is Usable
  882.   #--------------------------------------------------------------------------
  883.   alias jene_alche_item_usable? item_usable?
  884.   def item_usable?
  885.     return true if alche_any? && [7, 11].include?(item.scope)
  886.     jene_alche_item_usable?
  887.   end
  888.   #--------------------------------------------------------------------------
  889.   # * Check If Any Item Creation Exists
  890.   #--------------------------------------------------------------------------
  891.   def alche_any?
  892.     items = []
  893.     ($data_items + $data_weapons + $data_armors).each do |i|
  894.       next if i == nil
  895.       if i.alche_lreq <= user.level && i.alche_lreq > 0
  896.         items.push(i)
  897.       end
  898.     end
  899.     !items.empty?
  900.   end
  901. end
RAW Paste Data