Advertisement
TheSixth

Enchant System - Main Code by Sixth

Sep 2nd, 2015
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 35.86 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Enchant System - Main Script
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.5
  6. # * Updated: 22/02/2015
  7. # * Requires: Vlue's W/A Randomizer script
  8. #             Sixth's Custom Feature Extension for Vlue's Randomizer
  9. #-------------------------------------------------------------------------------
  10. # * This part contains the code for the enchant system.
  11. #   Do not edit anything in it, unless you know what you are doing!
  12. #===============================================================================
  13. $imported = {} if $imported.nil?
  14. $imported["SixthEnchantSystem"] = true
  15.  
  16. class Game_Interpreter
  17.  
  18.   def enchant_scene(info1=Sixth_Enchant_Scene::Prefixes,
  19.                     info2=Sixth_Enchant_Scene::Suffixes,
  20.                     random=Sixth_Enchant_Scene::Default_Random_Command,
  21.                     phide=Sixth_Enchant_Scene::Hidden_Prefs,
  22.                     shide=Sixth_Enchant_Scene::Hidden_Suffs)
  23.     SceneManager.call(Scene_SixthEnchant)
  24.     SceneManager.scene.prepare(info1,info2,random,phide,shide)
  25.   end
  26.  
  27.   def edit_enc_bonus(categ,value)
  28.     $game_system.enchant_bonus[categ] = value
  29.   end
  30.  
  31.   def exclude_enc(t,excl)
  32.     l = t == :pref ? Sixth_Enchant_Scene::Prefixes : Sixth_Enchant_Scene::Suffixes
  33.     excl.each do |id|
  34.       l.delete(id)
  35.     end
  36.     return l
  37.   end
  38.    
  39.   def enc_categ(categ)
  40.     $game_system.enchant_categories = categ
  41.   end
  42.  
  43. end
  44.  
  45. class Window_Base
  46.  
  47.   def draw_affix_info(id,x,y,width,enabled=true)
  48.     color = id[:color] ? id[:color] : normal_color
  49.     icon = id[:enc_info][:icon]
  50.     text = Sixth_Enchant_Scene::BeforeTxt+id[:enc_info][:name]+Sixth_Enchant_Scene::AfterTxt
  51.     draw_icon(icon, x, y, enabled)
  52.     change_color(color, enabled)
  53.     draw_text(x + 26, y, width, line_height, text)
  54.     change_color(normal_color)
  55.   end
  56.  
  57.   def draw_random_enc_info(aff,x,y,width,enabled=true)
  58.     if aff == 0
  59.       affix = Sixth_Enchant_Scene::Rand_Enc_Pref
  60.     else
  61.       affix = Sixth_Enchant_Scene::Rand_Enc_Suff
  62.     end
  63.     color = Color.new(*affix[:color])
  64.     icon = affix[:icon]
  65.     text = affix[:name]
  66.     draw_icon(icon, x, y, enabled)
  67.     change_color(color, enabled)
  68.     draw_text(x + 26, y, width, line_height, text)
  69.     change_color(normal_color)
  70.   end
  71.  
  72. end
  73.  
  74. class RPG::BaseItem
  75.  
  76.   def enchant_price
  77.     @note =~ /<enc price: (\d+)>/i ? $1.to_i : Sixth_Enchant_Scene::Default_Enchant_Fee
  78.   end
  79.  
  80.   def hide_from_enchant?
  81.     @note =~ /<enchant hide>/i
  82.   end
  83.  
  84.   def enchant_chance
  85.     @note =~ /<enc chance: (\d+)>/i ? $1.to_i : Sixth_Enchant_Scene::Default_Enchant_Chance
  86.   end
  87.  
  88.   def pref_id # Not used yet!
  89.     @pref_id ? @pref_id : nil
  90.   end
  91.  
  92.   def suff_id # Not used yet!
  93.     @suff_id ? @suff_id : nil
  94.   end
  95.  
  96.   def set_aff_id(new_id,pref=false) # Not used yet!
  97.     if pref == true
  98.       @pref_id = new_id
  99.     else
  100.       @suff_id = new_id
  101.     end
  102.   end
  103.  
  104. end
  105.  
  106. class Game_System
  107.   attr_accessor  :enchant_bonus
  108.   attr_accessor  :enchant_categories  
  109.  
  110.   alias sixth_enc_ini12213 initialize
  111.   def initialize
  112.     sixth_enc_ini12213
  113.     @enchant_bonus = [0,0,0]
  114.     @enchant_categories = [:item,:weapon,:armor]
  115.   end
  116.  
  117. end
  118.  
  119. class Scene_SixthEnchant < Scene_Base
  120.   include Sixth_Enchant_Scene
  121.  
  122.   def start
  123.     super
  124.     create_all_windows
  125.   end
  126.    
  127.   def prepare(info1,info2,random,phide,shide)
  128.     @pref_list = info1
  129.     @suff_list = info2
  130.     @random = random
  131.     @phide = phide
  132.     @shide = shide
  133.   end
  134.    
  135.   def create_all_windows
  136.     @help_window = Window_Help.new
  137.     @help_window.y = Window_Setup[:help][:y_pos]
  138.     create_command_window
  139.     create_item_window
  140.     create_prefix_window
  141.     create_suffix_window
  142.     create_detail_window
  143.     create_gold_window
  144.     create_ending_window
  145.     @help_window.clear
  146.   end
  147.  
  148.   def create_command_window
  149.     @commands = Enchy_Commands.new
  150.     @commands.set_handler(:ok, method(:on_category_ok))
  151.     @commands.set_handler(:cancel, method(:on_category_cancel))
  152.   end
  153.  
  154.   def create_item_window
  155.     x = Window_Setup[:item][:pos][0]; y = Window_Setup[:item][:pos][1]
  156.     w = Window_Setup[:item][:size][0]; h = Window_Setup[:item][:size][1]
  157.     @items = Enchy_Items.new(x,y,w,h)
  158.     @items.set_handler(:ok, method(:on_items_ok))
  159.     @items.set_handler(:cancel, method(:on_items_cancel))
  160.     @items.help_window = @help_window
  161.     @commands.item_list = @items
  162.   end
  163.    
  164.   def create_prefix_window
  165.     @prefixes = Enchy_Prefixes.new(@pref_list,@random)
  166.     @prefixes.set_handler(:prefix, method(:on_prefixes))
  167.     @prefixes.set_handler(:cancel, method(:on_prefix_cancel))
  168.     @prefixes.help_window = @help_window
  169.     @prefixes.hide.close
  170.   end
  171.  
  172.   def create_suffix_window
  173.     @suffixes = Enchy_Suffixes.new(@suff_list,@random)
  174.     @suffixes.set_handler(:suffix, method(:on_suffixes))
  175.     @suffixes.set_handler(:cancel, method(:on_suffix_cancel))
  176.     @suffixes.help_window = @help_window
  177.     @suffixes.hide.close
  178.   end
  179.  
  180.   def create_detail_window
  181.     @details = Enchy_Details.new
  182.   end
  183.  
  184.   def create_gold_window
  185.     @goldy = Enchy_Gold.new
  186.   end
  187.  
  188.   def create_ending_window
  189.     @finish = Enchy_Finish.new
  190.     @finish.set_handler(:finish, method(:on_finish))
  191.     @finish.set_handler(:cancel, method(:on_finish_cancel))
  192.     @finish.hide.close
  193.   end
  194.  
  195.   def on_category_ok
  196.     Sound.play_ok
  197.     case @commands.current_symbol
  198.     when :item
  199.       @prefixes.enc_item[0] = @suffixes.enc_item[0] = 0
  200.       @item_sound = Item_OK
  201.       @bonus = $game_system.enchant_bonus[0]
  202.     when :weapon
  203.       @prefixes.enc_item[0] = @suffixes.enc_item[0] = 1
  204.       @item_sound = Weap_OK
  205.       @bonus = $game_system.enchant_bonus[1]
  206.     when :armor
  207.       @prefixes.enc_item[0] = @suffixes.enc_item[0] = 2
  208.       @item_sound = Armr_OK
  209.       @bonus = $game_system.enchant_bonus[2]
  210.     end
  211.     @prefixes.make_command_list
  212.     @suffixes.make_command_list
  213.     @items.select_last
  214.     @details.refresh(1)
  215.     @items.activate
  216.   end
  217.  
  218.   def on_category_cancel
  219.     Sound.play_cancel
  220.     $game_system.enchant_bonus = [0,0,0] if Reset_Bonus == true
  221.     $game_system.enchant_categories = Reset_Categories if !Reset_Categories.nil?
  222.     return_scene
  223.   end
  224.  
  225.   def on_items_ok
  226.     @item_sound.play
  227.     @item = @items.item
  228.     @gold = $game_party.gold
  229.     @gold -= @item.enchant_price
  230.     if Rand_Enc_Pref[:price] == :average
  231.       @r_price1 = get_random_price(@prefixes.pref_list,true)
  232.     else
  233.       @r_price1 = Rand_Enc_Pref[:price]
  234.     end
  235.     @prefixes.enc_item[2] = @r_price1
  236.     @prefixes.enc_item[1] = @gold
  237.     @prefixes.refresh
  238.     @details.refresh(2,@item)
  239.     @prefixes.select(0)
  240.     @prefixes.show.open
  241.     @prefixes.activate
  242.     @items.deactivate
  243.     @items.hide.close
  244.   end
  245.  
  246.   def on_items_cancel
  247.     Sound.play_cancel
  248.     @items.unselect
  249.     @details.refresh
  250.     @help_window.clear
  251.     @commands.activate
  252.   end
  253.    
  254.   def get_random_price(affixes,pref=false)
  255.     @rand_fee = 0
  256.     no_enc = pref == true ? No_Enchant[0] : No_Enchant[1]
  257.     affixes.each do |affix|
  258.       next if affix == no_enc && AFFIXES[no_enc][:enc_info][:price] == 0
  259.       @rand_fee += AFFIXES[affix][:enc_info][:price]
  260.     end
  261.     pdiv = affixes.size
  262.     pdiv -= 1 if affixes.include?(no_enc) && AFFIXES[no_enc][:enc_info][:price] == 0
  263.     pdiv = 1 if pdiv == 0
  264.     frand_fee = (@rand_fee/pdiv).to_i
  265.     return frand_fee
  266.   end
  267.  
  268.   def on_prefixes
  269.     Pref_OK.play
  270.     @prefixes.deactivate
  271.     @prefixes.hide.close
  272.     if @prefixes.current_ext == -10
  273.       @gold -= @r_price1
  274.     else
  275.       @gold -= AFFIXES[@prefixes.current_ext][:enc_info][:price]
  276.     end
  277.     if Rand_Enc_Suff[:price] == :average
  278.       @r_price2 = get_random_price(@suffixes.suff_list)
  279.     else
  280.       @r_price2 = Rand_Enc_Suff[:price]
  281.     end
  282.     @suffixes.enc_item[3] = @r_price2
  283.     @suffixes.enc_item[1] = @gold
  284.     if Allow_Clear == false
  285.       @suffixes.enc_item[2] = false if @prefixes.current_ext == No_Enchant[0]
  286.     end
  287.     @suffixes.refresh
  288.     @details.refresh(3,@item,@prefixes.current_ext,nil,[@r_price1,nil])
  289.     @suffixes.select(0)
  290.     @suffixes.show.open
  291.     @suffixes.activate
  292.   end
  293.  
  294.   def on_prefix_cancel
  295.     Sound.play_cancel
  296.     @prefixes.deactivate
  297.     @prefixes.hide.close
  298.     @details.refresh(1)
  299.     @items.show.open
  300.     @items.help_window.refresh
  301.     @items.activate
  302.   end
  303.    
  304.   def on_suffixes
  305.     Suff_OK.play
  306.     @suffixes.deactivate
  307.     @details.refresh(0,@item,@prefixes.current_ext,@suffixes.current_ext,[@r_price1,@r_price2])
  308.     @finish.show.open
  309.     @finish.activate
  310.   end
  311.  
  312.   def on_suffix_cancel
  313.     Sound.play_cancel
  314.     @suffixes.deactivate
  315.     @suffixes.hide.close
  316.     if @prefixes.current_ext == -10
  317.       @gold += @r_price1
  318.     else
  319.       @gold += AFFIXES[@prefixes.current_ext][:enc_info][:price]
  320.     end
  321.     @prefixes.enc_item[1] = @gold
  322.     @prefixes.refresh
  323.     @suffixes.enc_item[2] = true
  324.     @details.refresh(2,@item)
  325.     @prefixes.show.open
  326.     @prefixes.activate
  327.   end
  328.  
  329.   def get_extra_random_affix(list,categ)
  330.     @hide_mod = []
  331.     list.each do |id|
  332.       next if AFFIXES[id].nil? || AFFIXES[id][:enc_info].nil?
  333.       next if !AFFIXES[id][:enc_info][:category].include?(categ)
  334.       @hide_mod.push(id)
  335.     end
  336.   end
  337.  
  338.   def do_random_enchant_prefix
  339.     if @phide.size > 0
  340.       get_extra_random_affix(@phide,@prefixes.enc_item[0])
  341.     end
  342.     pl = @prefixes.pref_list.size
  343.     pl += @hide_mod.size if @phide.size > 0 && @hide_mod.size > 0
  344.     pp = rand(pl)
  345.     pfl = @prefixes.pref_list
  346.     pfl += @hide_mod if @phide.size > 0 && @hide_mod != []
  347.     prefix = pfl[pp]
  348.     if Rand_Enc_Pref[:bonus] == false
  349.       chance1 = Rand_Enc_Pref[:chance]
  350.     else
  351.       chance1 = [[0,Rand_Enc_Pref[:chance]*((@item.enchant_chance+@bonus)*0.01)].max,100].min
  352.     end
  353.     return "<PREFIX#{prefix} #{chance1.round}>"
  354.   end
  355.  
  356.   def do_random_enchant_suffix
  357.     if @shide.size > 0
  358.       get_extra_random_affix(@shide,@suffixes.enc_item[0])
  359.     end
  360.     sl = @suffixes.suff_list.size
  361.     sl += @hide_mod.size if @shide.size > 0 && @hide_mod.size > 0
  362.     ss = rand(sl)
  363.     sfl = @suffixes.suff_list
  364.     sfl += @hide_mod if @shide.size > 0 && @hide_mod != []
  365.     suffix = sfl[ss]
  366.     if Rand_Enc_Suff[:bonus] == false
  367.       chance2 = Rand_Enc_Suff[:chance]
  368.     else
  369.       chance2 = [[0,Rand_Enc_Suff[:chance]*((@item.enchant_chance+@bonus)*0.01)].max,100].min
  370.     end
  371.     return "<SUFFIX#{suffix} #{chance2.round}>"
  372.   end
  373.  
  374.   def on_finish
  375.     Fnsh_OK.play
  376.     @finish.deactivate
  377.     @finish.hide.close
  378.     if @prefixes.current_ext == -10
  379.       subnote1 = do_random_enchant_prefix
  380.       pprice = @r_price1
  381.       item_pre = $data_items[Rand_Enc_Pref[:item]] if Item_Req == true && !Rand_Enc_Pref[:item].nil?
  382.     else
  383.       prefix = AFFIXES[@prefixes.current_ext]
  384.       if prefix[:enc_info][:bonus] == false
  385.         chance1 = prefix[:enc_info][:chance]
  386.       else
  387.         chance1 = [[0,prefix[:enc_info][:chance]*((@item.enchant_chance+@bonus)*0.01)].max,100].min
  388.       end
  389.       subnote1 = "<PREFIX#{@prefixes.current_ext} #{chance1.round}>"
  390.       pprice = prefix[:enc_info][:price]
  391.       item_pre = $data_items[prefix[:enc_info][:item]] if Item_Req == true && !prefix[:enc_info][:item].nil?
  392.     end
  393.     if @suffixes.current_ext == -10
  394.       subnote2 = do_random_enchant_suffix
  395.       sprice = @r_price2
  396.       item_suf = $data_items[Rand_Enc_Suff[:item]] if Item_Req == true && !Rand_Enc_Suff[:item].nil?
  397.     else
  398.       suffix = AFFIXES[@suffixes.current_ext]
  399.       if suffix[:enc_info][:bonus] == false
  400.         chance2 = suffix[:enc_info][:chance]
  401.       else
  402.         chance2 = [[0,suffix[:enc_info][:chance]*((@item.enchant_chance+@bonus)*0.01)].max,100].min
  403.       end
  404.       subnote2 = "<SUFFIX#{@suffixes.current_ext} #{chance2.round}>"
  405.       sprice = suffix[:enc_info][:price]
  406.       item_suf = $data_items[suffix[:enc_info][:item]] if Item_Req == true && !suffix[:enc_info][:item].nil?
  407.     end
  408.     subnote = subnote1 + subnote2      
  409.     iprice = @item.enchant_price
  410.     total = pprice + sprice + iprice
  411.     if @item.is_a?(RPG::Item)
  412.       $game_party.add_item(@item.original_id,1,false,subnote)
  413.     elsif @item.is_a?(RPG::Weapon)
  414.       $game_party.add_weapon(@item.original_id,1,false,subnote)
  415.     elsif @item.is_a?(RPG::Armor)
  416.       $game_party.add_armor(@item.original_id,1,false,subnote)
  417.     end
  418.     $game_party.lose_item(@item,1)
  419.     if Item_Req == true
  420.       $game_party.lose_item(item_pre,1)
  421.       $game_party.lose_item(item_suf,1)
  422.     end
  423.     $game_party.lose_gold(total)
  424.     @suffixes.hide.close
  425.     @suffixes.enc_item[2] = true
  426.     @items.refresh
  427.     @details.refresh(1)
  428.     @goldy.refresh
  429.     @items.select(0)
  430.     @items.show.open
  431.     @items.help_window.refresh
  432.     @items.activate
  433.   end
  434.  
  435.   def on_finish_cancel
  436.     Sound.play_cancel
  437.     @finish.deactivate
  438.     @finish.hide.close
  439.     @details.refresh(3,@item,@prefixes.current_ext,nil,[@r_price1,nil])
  440.     @suffixes.activate
  441.   end
  442.    
  443. end
  444.  
  445. class Enchy_Commands < Window_Command
  446.   include Sixth_Enchant_Scene
  447.  
  448.   def initialize
  449.     x = Window_Setup[:category][:pos][0]; y = Window_Setup[:category][:pos][1]
  450.     super(x,y)
  451.     self.windowskin = Cache.system(Window_Setup[:category][:skin])
  452.   end
  453.  
  454.   def window_width
  455.     Window_Setup[:category][:size][0]
  456.   end
  457.  
  458.   def window_height
  459.     Window_Setup[:category][:size][1]
  460.   end
  461.  
  462.   def alignment
  463.     return Window_Setup[:category][:align]
  464.   end
  465.  
  466.   def spacing
  467.     Window_Setup[:category][:spacing]
  468.   end
  469.  
  470.   def col_max
  471.     return Window_Setup[:category][:columns]
  472.   end
  473.    
  474.   def update
  475.     super
  476.     @item_list.category = current_symbol if @item_list
  477.   end
  478.  
  479.   def make_command_list
  480.     add_command(Weaps_Cmd,:weapon) if $game_system.enchant_categories.include?(:weapon)
  481.     add_command(Armrs_Cmd,:armor) if $game_system.enchant_categories.include?(:armor)
  482.     add_command(Items_Cmd,:item) if $game_system.enchant_categories.include?(:item)
  483.     add_command(Exxit_Cmd,:cancel)    
  484.   end
  485.  
  486.   def draw_item(index)
  487.     contents.font.name = Text_Options[:cmnd_win][0]
  488.     contents.font.size = Text_Options[:cmnd_win][1]
  489.     super
  490.   end
  491.  
  492.   def item_list=(item_window)
  493.     @item_list = item_window
  494.     update
  495.   end
  496.  
  497.   def process_ok
  498.     if current_item_enabled?
  499.       Input.update
  500.       deactivate
  501.       call_ok_handler
  502.     else
  503.       Sound.play_buzzer
  504.     end
  505.   end
  506.  
  507. end
  508.  
  509. class Enchy_Items < Window_ItemList
  510.   include Sixth_Enchant_Scene
  511.  
  512.   def initialize(x,y,width,height)
  513.     super
  514.     self.windowskin = Cache.system(Window_Setup[:item][:skin])
  515.     refresh
  516.   end
  517.    
  518.   def col_max
  519.     1
  520.   end
  521.    
  522.   def update_padding_bottom
  523.     self.padding_bottom = padding
  524.   end
  525.  
  526.   def enable?(item)
  527.     return false unless item && item.enchant_price <= $game_party.gold
  528.     return false if !item.nil? && Enable_ReEnchant == false && item.original_id != item.id
  529.     true
  530.   end
  531.  
  532.   def current_item
  533.     @data[index]
  534.   end
  535.  
  536.   def select_last
  537.     select(@data.index($game_party.last_item.object) || 0)
  538.   end
  539.  
  540.   def make_item_list
  541.     @data = $game_party.all_items.select {|item| include?(item) }
  542.     @data.push(nil) if include?(nil)
  543.   end
  544.  
  545.   def item_height
  546.     line_height*2
  547.   end
  548.  
  549.   def include?(item)
  550.     return false if !item.nil? && item.hide_from_enchant?
  551.     super
  552.   end
  553.  
  554.   def draw_item_number(rect, item, enable)
  555.     change_color(system_color, enable)
  556.     draw_text(rect.x+contents.width/2+4,rect.y,contents.width/2-8,line_height,IOwned_Text)
  557.     change_color(normal_color, enable)
  558.     draw_text(rect.x+contents.width/2+4,rect.y,contents.width/2-8,line_height,$game_party.item_number(item),2)
  559.   end
  560.  
  561.   def draw_item_enc_price(rect, item, enable)
  562.     change_color(system_color, enable)
  563.     draw_text(rect.x+4,rect.y,contents.width/2-8,line_height,IPrice_Text)
  564.     change_color(normal_color, enable)
  565.     draw_text(rect.x+4,rect.y,contents.width/2-8,line_height,item.enchant_price,2)
  566.   end
  567.  
  568.   def draw_item(index)
  569.     contents.font.name = Text_Options[:item_win][0]
  570.     contents.font.size = Text_Options[:item_win][1]
  571.     item = @data[index]
  572.     if item
  573.       rect = item_rect(index)
  574.       contents.fill_rect(rect.x,rect.y+1,contents.width,rect.height-2,Color.new(*BackGrdColor))
  575.       draw_item_name(item, rect.x, rect.y, enable?(item),contents.width)
  576.       rect.y += line_height
  577.       draw_item_number(rect, item, enable?(item))
  578.       draw_item_enc_price(rect, item, enable?(item))
  579.     end
  580.   end
  581.  
  582.   def process_ok
  583.     if current_item_enabled?
  584.       Input.update
  585.       deactivate
  586.       call_ok_handler
  587.     else
  588.       Sound.play_buzzer
  589.     end
  590.   end
  591.  
  592. end
  593.  
  594. class Enchy_Prefixes < Window_Command
  595.   include Sixth_Enchant_Scene
  596.  
  597.   attr_accessor  :enc_item
  598.   attr_reader    :pref_list
  599.  
  600.   def initialize(enc_list,random)
  601.     x = Window_Setup[:item][:pos][0]; y = Window_Setup[:item][:pos][1]
  602.     @random = random
  603.     @pref_list = []
  604.     @enc_list = enc_list
  605.     @enc_item = [-1,0,0] #,nil]
  606.     super(x,y)
  607.     self.windowskin = Cache.system(Window_Setup[:item][:skin])
  608.   end
  609.  
  610.   def window_width
  611.     Window_Setup[:item][:size][0]
  612.   end
  613.  
  614.   def window_height
  615.     Window_Setup[:item][:size][1]
  616.   end
  617.  
  618.   def item_height
  619.     Item_Req == true ? line_height*2 : line_height
  620.   end
  621.  
  622.   def update_padding_bottom
  623.     self.padding_bottom = padding
  624.   end
  625.  
  626.   def make_command_list
  627.     @pref_list.clear
  628.     @enc_list.each do |id|
  629.       next if AFFIXES[id].nil? || AFFIXES[id][:enc_info].nil?
  630.       @pref_list.push(id) if !@pref_list.include?(id) && current_item_for_enc(id)
  631.       add_command(AFFIXES[id][:enc_info][:name],:prefix,can_add(id),id) if current_item_for_enc(id)
  632.     end
  633.     add_command(Rand_Enc_Pref[:name],:prefix,can_add_random,-10) if random_enchant_enabled
  634.   end
  635.  
  636.   def can_add(id)
  637.     if Item_Req == true && !AFFIXES[id][:enc_info][:item].nil?
  638.       return false if $game_party.item_number($data_items[AFFIXES[id][:enc_info][:item]]) <= 0
  639.     end
  640.     return true if AFFIXES[id][:enc_info][:price] <= @enc_item[1]
  641.     return false
  642.   end
  643.  
  644.   def current_item_for_enc(id)
  645.     if Item_Req == true && Show_All == false && !AFFIXES[id][:enc_info][:item].nil?
  646.       return false if $game_party.item_number($data_items[AFFIXES[id][:enc_info][:item]]) <= 0
  647.     end
  648.     return true if AFFIXES[id][:enc_info][:category].include?(@enc_item[0])
  649.     return false
  650.   end
  651.  
  652.   def can_add_random
  653.     return false if !Rand_Enc_Pref[:item].nil? && $game_party.item_number($data_items[Rand_Enc_Pref[:item]]) <= 0 && Item_Req == true
  654.     return true if @enc_item[2] <= @enc_item[1]
  655.     return false
  656.   end
  657.  
  658.   def random_enchant_enabled
  659.     if Item_Req == true && Show_All == false && !Rand_Enc_Pref[:item].nil?
  660.       return false if $game_party.item_number($data_items[Rand_Enc_Pref[:item]]) <= 0
  661.     end
  662.     return true if @random == true
  663.     return false
  664.   end
  665.  
  666.   def update_help
  667.     @help_window.contents.clear
  668.     return if current_ext.nil?
  669.     return if self.active == false
  670.     if current_ext == -10
  671.       @help_window.draw_random_enc_info(0,0,0,contents.width)
  672.       @help_window.draw_text_ex(0,line_height,Rand_Enc_Pref[:description])
  673.     else
  674.       id = AFFIXES[current_ext]
  675.       @help_window.draw_affix_info(id,0,0,contents.width)
  676.       @help_window.draw_text_ex(0,line_height,id[:enc_info][:description]) if !id[:enc_info][:description].nil?
  677.     end
  678.   end  
  679.  
  680.   def draw_item_number(rect, item, enable)
  681.     return if item.nil?
  682.     change_color(system_color, enable)
  683.     draw_text(rect.x+contents.width/2+4,rect.y,contents.width/2-8,line_height,IOwned_Text)
  684.     change_color(normal_color, enable)
  685.     draw_text(rect.x+contents.width/2+4,rect.y,contents.width/2-8,line_height,$game_party.item_number(item),2)
  686.   end
  687.  
  688.   def draw_item_enc_price(rect, price, enable)
  689.     change_color(system_color, enable)
  690.     draw_text(rect.x+4,rect.y,contents.width/2-8,line_height,IPrice_Text)
  691.     change_color(normal_color, enable)
  692.     draw_text(rect.x+4,rect.y,contents.width/2-8,line_height,price,2)
  693.   end
  694.  
  695.   def draw_item(index)
  696.     contents.font.name = Text_Options[:item_win][0]
  697.     contents.font.size = Text_Options[:item_win][1]
  698.     rect = item_rect(index)
  699.     contents.fill_rect(rect.x,rect.y+1,contents.width,rect.height-2,Color.new(*BackGrdColor))
  700.     if Item_Req == true
  701.       if @list[index][:ext] == -10
  702.         price = @enc_item[2]
  703.         enabled = can_add_random
  704.         draw_random_enc_info(0,rect.x,rect.y,contents.width,enabled)
  705.         rect.y += line_height
  706.         item = $data_items[Rand_Enc_Pref[:item]] if !Rand_Enc_Pref[:item].nil?
  707.         draw_item_number(rect, item, enabled)
  708.         draw_item_enc_price(rect, price, enabled)
  709.       else
  710.         id = AFFIXES[@list[index][:ext]]
  711.         price = id[:enc_info][:price]
  712.         enabled = can_add(@list[index][:ext])
  713.         draw_affix_info(id,rect.x,rect.y,rect.width,enabled)
  714.         rect.y += line_height
  715.         if !id[:enc_info][:item].nil?
  716.           item = $data_items[id[:enc_info][:item]]
  717.           draw_item_number(rect, item, enabled)
  718.         end
  719.         draw_item_enc_price(rect, price, enabled)
  720.       end
  721.     else
  722.       if @list[index][:ext] == -10
  723.         price = @enc_item[2]
  724.         enabled = can_add_random
  725.         draw_random_enc_info(0,rect.x,rect.y,contents.width,enabled)
  726.       else
  727.         id = AFFIXES[@list[index][:ext]]
  728.         price = id[:enc_info][:price]
  729.         enabled = can_add(@list[index][:ext])
  730.         draw_affix_info(id,rect.x,rect.y,rect.width,enabled)
  731.       end
  732.       contents.font.color.alpha = translucent_alpha unless enabled
  733.       draw_text(rect.x,rect.y,rect.width,rect.height,price,2)
  734.     end
  735.   end
  736.  
  737.   def process_ok
  738.     if current_item_enabled?
  739.       Input.update
  740.       deactivate
  741.       call_ok_handler
  742.     else
  743.       Sound.play_buzzer
  744.     end
  745.   end
  746.  
  747. end
  748.  
  749. class Enchy_Suffixes < Window_Command
  750.   include Sixth_Enchant_Scene
  751.  
  752.   attr_accessor  :enc_item
  753.   attr_reader    :suff_list
  754.  
  755.   def initialize(enc_list,random)
  756.     x = Window_Setup[:item][:pos][0]; y = Window_Setup[:item][:pos][1]
  757.     @random = random
  758.     @suff_list = []
  759.     @enc_list = enc_list
  760.     @enc_item = [-1,0,true,0]
  761.     super(x,y)
  762.     self.windowskin = Cache.system(Window_Setup[:item][:skin])
  763.   end
  764.  
  765.   def window_width
  766.     Window_Setup[:item][:size][0]
  767.   end
  768.  
  769.   def window_height
  770.     Window_Setup[:item][:size][1]
  771.   end
  772.  
  773.   def item_height
  774.     Item_Req == true ? line_height*2 : line_height
  775.   end
  776.  
  777.   def update_padding_bottom
  778.     self.padding_bottom = padding
  779.   end
  780.  
  781.   def make_command_list
  782.     @suff_list.clear
  783.     @enc_list.each do |id|
  784.       next if AFFIXES[id].nil? || AFFIXES[id][:enc_info].nil?
  785.       @suff_list.push(id) if !@suff_list.include?(id) && current_item_for_enc(id)
  786.       add_command(AFFIXES[id][:enc_info][:name],:suffix,can_add(id),id) if current_item_for_enc(id)
  787.     end
  788.     add_command(Rand_Enc_Suff[:name],:suffix,can_add_random,-10) if random_enchant_enabled
  789.   end
  790.  
  791.   def can_add(id)
  792.     return false if id == No_Enchant[1] && @enc_item[2] == false
  793.     if Item_Req == true && !AFFIXES[id][:enc_info][:item].nil?
  794.       return false if $game_party.item_number($data_items[AFFIXES[id][:enc_info][:item]]) <= 0
  795.     end
  796.     return true if AFFIXES[id][:enc_info][:price] <= @enc_item[1]
  797.     return false
  798.   end
  799.  
  800.   def current_item_for_enc(id)
  801.     if Item_Req == true && Show_All == false && !AFFIXES[id][:enc_info][:item].nil?
  802.       return false if $game_party.item_number($data_items[AFFIXES[id][:enc_info][:item]]) <= 0
  803.     end
  804.     return true if AFFIXES[id][:enc_info][:category].include?(@enc_item[0])
  805.     return false
  806.   end
  807.  
  808.   def can_add_random
  809.     return false if !Rand_Enc_Suff[:item].nil? && $game_party.item_number($data_items[Rand_Enc_Suff[:item]]) <= 0 && Item_Req == true
  810.     return true if @enc_item[3] <= @enc_item[1]
  811.     return false
  812.   end
  813.  
  814.   def random_enchant_enabled
  815.     if Item_Req == true && Show_All == false && !Rand_Enc_Suff[:item].nil?
  816.       return false if $game_party.item_number($data_items[Rand_Enc_Suff[:item]]) <= 0
  817.     end
  818.     return true if @random == true
  819.     return false
  820.   end
  821.    
  822.   def update_help
  823.     @help_window.contents.clear
  824.     return if current_ext.nil?
  825.     return if self.active == false
  826.     if current_ext == -10
  827.       @help_window.draw_random_enc_info(1,0,0,contents.width)
  828.       @help_window.draw_text_ex(0,line_height,Rand_Enc_Suff[:description])
  829.     else
  830.       id = AFFIXES[current_ext]
  831.       @help_window.draw_affix_info(id,0,0,contents.width)
  832.       @help_window.draw_text_ex(0,line_height,id[:enc_info][:description]) if !id[:enc_info][:description].nil?
  833.     end
  834.   end  
  835.  
  836.   def draw_item_number(rect, item, enable)
  837.     return if item.nil?
  838.     change_color(system_color, enable)
  839.     draw_text(rect.x+contents.width/2+4,rect.y,contents.width/2-8,line_height,IOwned_Text)
  840.     change_color(normal_color, enable)
  841.     draw_text(rect.x+contents.width/2+4,rect.y,contents.width/2-8,line_height,$game_party.item_number(item),2)
  842.   end
  843.  
  844.   def draw_item_enc_price(rect, price, enable)
  845.     change_color(system_color, enable)
  846.     draw_text(rect.x+4,rect.y,contents.width/2-8,line_height,IPrice_Text)
  847.     change_color(normal_color, enable)
  848.     draw_text(rect.x+4,rect.y,contents.width/2-8,line_height,price,2)
  849.   end
  850.  
  851.   def draw_item(index)
  852.     contents.font.name = Text_Options[:item_win][0]
  853.     contents.font.size = Text_Options[:item_win][1]
  854.     rect = item_rect(index)
  855.     contents.fill_rect(rect.x,rect.y+1,contents.width,rect.height-2,Color.new(*BackGrdColor))
  856.     if Item_Req == true
  857.       if @list[index][:ext] == -10
  858.         price = @enc_item[3]
  859.         enabled = can_add_random
  860.         draw_random_enc_info(1,rect.x,rect.y,contents.width,enabled)
  861.         rect.y += line_height
  862.         item = $data_items[Rand_Enc_Suff[:item]] if !Rand_Enc_Suff[:item].nil?
  863.         draw_item_number(rect, item, enabled)
  864.         draw_item_enc_price(rect, price, enabled)
  865.       else
  866.         id = AFFIXES[@list[index][:ext]]
  867.         price = id[:enc_info][:price]
  868.         enabled = can_add(@list[index][:ext])
  869.         draw_affix_info(id,rect.x,rect.y,rect.width,enabled)
  870.         rect.y += line_height
  871.         if !id[:enc_info][:item].nil?
  872.           item = $data_items[id[:enc_info][:item]]
  873.           draw_item_number(rect, item, enabled)
  874.         end
  875.         draw_item_enc_price(rect, price, enabled)
  876.       end
  877.     else
  878.       if @list[index][:ext] == -10
  879.         price = @enc_item[2]
  880.         enabled = can_add_random
  881.         draw_random_enc_info(1,rect.x,rect.y,contents.width,enabled)
  882.       else
  883.         id = AFFIXES[@list[index][:ext]]
  884.         price = id[:enc_info][:price]
  885.         enabled = can_add(@list[index][:ext])
  886.         draw_affix_info(id,rect.x,rect.y,rect.width,enabled)
  887.       end
  888.       contents.font.color.alpha = translucent_alpha unless enabled
  889.       draw_text(rect.x,rect.y,rect.width,rect.height,price,2)
  890.     end
  891.   end
  892.  
  893.   def process_ok
  894.     if current_item_enabled?
  895.       Input.update
  896.       deactivate
  897.       call_ok_handler
  898.     else
  899.       Sound.play_buzzer
  900.     end
  901.   end
  902.  
  903. end
  904.  
  905. class Enchy_Details < Window_Base
  906.   include Sixth_Enchant_Scene
  907.  
  908.   def initialize
  909.     x = Window_Setup[:detail][:pos][0]; y = Window_Setup[:detail][:pos][1]
  910.     w = Window_Setup[:detail][:size][0]; h = Window_Setup[:detail][:size][1]
  911.     super(x,y,w,h)
  912.     self.windowskin = Cache.system(Window_Setup[:detail][:skin])
  913.     refresh
  914.   end
  915.  
  916.   def refresh(decision=0,item=nil,prefix=nil,suffix=nil,random=nil)
  917.     contents.clear
  918.     @fillc = Color.new(*TextBoxColor)
  919.     3.times do |i|
  920.       contents.fill_rect(Detail_Info_X,Detail_Info_Y-1+i*(line_height*2+4),contents.width,line_height*2+2,@fillc)
  921.     end
  922.     if item.is_a?(RPG::Item)
  923.       bonus = $game_system.enchant_bonus[0]
  924.     elsif item.is_a?(RPG::Weapon)
  925.       bonus = $game_system.enchant_bonus[1]
  926.     elsif item.is_a?(RPG::Armor)
  927.       bonus = $game_system.enchant_bonus[2]
  928.     end
  929.     contents.fill_rect(Total_Price_X,Total_Price_Y-1,contents.width,line_height+2,@fillc)
  930.     color1 = Color.new(*Line_Colors[:item_up])
  931.     color2 = Color.new(*Line_Colors[:item_dw])
  932.     color3 = Color.new(*Line_Colors[:pref_up])
  933.     color4 = Color.new(*Line_Colors[:pref_dw])
  934.     color5 = Color.new(*Line_Colors[:suff_up])
  935.     color6 = Color.new(*Line_Colors[:suff_dw])
  936.     color7 = Color.new(*Line_Colors[:titl_up])
  937.     color8 = Color.new(*Line_Colors[:titl_dw])
  938.     contents.font.name = Text_Options[:titl_opt][0]
  939.     contents.font.size = Text_Options[:titl_opt][1]
  940.     tlw = text_size(Title_Text).width
  941.     tlx = (contents.width-tlw)/2
  942.     contents.fill_rect(tlx-8,TitleLine_Y,tlw+16,2,color7)
  943.     contents.fill_rect(tlx-8,TitleLine_Y+2,tlw+16,1,color8)
  944.     offy = -6 + Line_Offset_Y
  945.     contents.fill_rect(Detail_Info_X+4,Detail_Info_Y+line_height+offy,contents.width-8,2,color1)
  946.     contents.fill_rect(Detail_Info_X+4,Detail_Info_Y+line_height+2+offy,contents.width-8,1,color2)
  947.     contents.fill_rect(Detail_Info_X+4,Detail_Info_Y+line_height*3+offy+4,contents.width-8,2,color3)
  948.     contents.fill_rect(Detail_Info_X+4,Detail_Info_Y+line_height*3+2+offy+4,contents.width-8,1,color4)
  949.     contents.fill_rect(Detail_Info_X+4,Detail_Info_Y+line_height*5+offy+8,contents.width-8,2,color5)
  950.     contents.fill_rect(Detail_Info_X+4,Detail_Info_Y+line_height*5+2+offy+8,contents.width-8,1,color6)
  951.     change_color(Color.new(*TitleColor))
  952.     draw_text(0,0,contents.width,[contents.font.size, 24].max,Title_Text,1)
  953.     contents.font.name = Text_Options[:dtls_win][0]
  954.     contents.font.size = Text_Options[:dtls_win][1]
  955.     change_color(system_color)
  956.     py = text_size("000%").width
  957.     draw_text(Detail_Info_X+4,Detail_Info_Y,contents.width-8,line_height,Sel_Item)
  958.     draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*2+4,contents.width-8,line_height,Sel_Pref)
  959.     draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*4+8,contents.width-8,line_height,Sel_Suff)        
  960.     draw_text(Total_Price_X+4,Total_Price_Y,contents.width-8,line_height,Total_Price)
  961.     if Show_Chance == true
  962.       draw_text(Detail_Info_X+4,Detail_Info_Y,contents.width-8-py,line_height,SuccessChanceTxt,2) if Show_Item_Chance == true
  963.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*2+4,contents.width-8-py,line_height,SuccessChanceTxt,2)
  964.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*4+8,contents.width-8-py,line_height,SuccessChanceTxt,2)
  965.     end
  966.     change_color(normal_color)
  967.     if decision == 0
  968.       no_text1 = no_text2 = no_text3 = Not_Selected
  969.     elsif decision == 1
  970.       no_text1 = Current_Sele
  971.       no_text2 = no_text3 = Not_Selected
  972.     elsif decision == 2
  973.       no_text2 = Current_Sele
  974.       no_text3 = Not_Selected
  975.     elsif decision == 3
  976.       no_text3 = Current_Sele
  977.     end
  978.     if item.nil?
  979.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height,contents.width-8,line_height,no_text1)
  980.       draw_text(Detail_Info_X+4,Detail_Info_Y,contents.width-8,line_height,No_ChanceTxt,2) if Show_Chance == true && Show_Item_Chance == true
  981.     else
  982.       chancei = [[0,item.enchant_chance+bonus].max,100].min
  983.       draw_text(Detail_Info_X+4,Detail_Info_Y,contents.width-8,line_height,chancei.round.to_s+"%",2) if Show_Chance == true && Show_Item_Chance == true
  984.       draw_item_name(item,Detail_Info_X+4,Detail_Info_Y+line_height,true,contents.width-8)
  985.     end
  986.     if prefix.nil?
  987.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*3+4,contents.width-8,line_height,no_text2)
  988.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*2+4,contents.width-8,line_height,No_ChanceTxt,2) if Show_Chance == true
  989.     else
  990.       if prefix == -10
  991.         draw_random_enc_info(0,Detail_Info_X+4,Detail_Info_Y+line_height*3+4,contents.width-8)
  992.         price1 = random[0]
  993.         if Rand_Enc_Pref[:bonus] == false
  994.           chance1 = Rand_Enc_Pref[:chance]
  995.         else
  996.           chance1 = [[0,Rand_Enc_Pref[:chance]*((item.enchant_chance+bonus)*0.01)].max,100].min
  997.         end
  998.       else
  999.         id1 = AFFIXES[prefix]
  1000.         price1 = id1[:enc_info][:price]
  1001.         if id1[:enc_info][:bonus] == false
  1002.           chance1 = id1[:enc_info][:chance]
  1003.         else
  1004.           chance1 = [[0,id1[:enc_info][:chance]*((item.enchant_chance+bonus)*0.01)].max,100].min
  1005.         end
  1006.         draw_affix_info(id1,Detail_Info_X+4,Detail_Info_Y+line_height*3+4,contents.width-8)
  1007.       end
  1008.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*2+4,contents.width-8,line_height,chance1.round.to_s+"%",2) if Show_Chance == true
  1009.     end
  1010.     if suffix.nil?
  1011.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*5+8,contents.width-8,line_height,no_text3)
  1012.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*4+8,contents.width-8,line_height,No_ChanceTxt,2) if Show_Chance == true
  1013.     else
  1014.       if suffix == -10
  1015.         draw_random_enc_info(1,Detail_Info_X+4,Detail_Info_Y+line_height*5+8,contents.width-8)
  1016.         price2 = random[1]
  1017.         if Rand_Enc_Suff[:bonus] == false
  1018.           chance2 = Rand_Enc_Suff[:chance]
  1019.         else
  1020.           chance2 = [[0,Rand_Enc_Suff[:chance]*((item.enchant_chance+bonus)*0.01)].max,100].min
  1021.         end
  1022.       else
  1023.         id2 = AFFIXES[suffix]
  1024.         price2 = id2[:enc_info][:price]
  1025.         if id2[:enc_info][:bonus] == false
  1026.           chance2 = id2[:enc_info][:chance]
  1027.         else
  1028.           chance2 = [[0,id2[:enc_info][:chance]*((item.enchant_chance+bonus)*0.01)].max,100].min
  1029.         end        
  1030.         draw_affix_info(id2,Detail_Info_X+4,Detail_Info_Y+line_height*5+8,contents.width-8)
  1031.       end
  1032.       draw_text(Detail_Info_X+4,Detail_Info_Y+line_height*4+8,contents.width-8,line_height,chance2.round.to_s+"%",2) if Show_Chance == true
  1033.     end
  1034.     price = 0
  1035.     price += item.enchant_price if !item.nil?
  1036.     price += price1 if !price1.nil?
  1037.     price += price2 if !price2.nil?
  1038.     draw_text(Total_Price_X+4,Total_Price_Y,contents.width-8,line_height,price,2)
  1039.   end
  1040.  
  1041. end
  1042.  
  1043. class Enchy_Gold < Window_Base
  1044.   include Sixth_Enchant_Scene
  1045.  
  1046.   def initialize
  1047.     x = Window_Setup[:gold][:pos][0]; y = Window_Setup[:gold][:pos][1]
  1048.     w = Window_Setup[:gold][:size][0]; h = Window_Setup[:gold][:size][1]
  1049.     super(x,y,w,h)
  1050.     self.windowskin = Cache.system(Window_Setup[:gold][:skin])
  1051.     contents.font.name = Text_Options[:gold_win][0]
  1052.     contents.font.size = Text_Options[:gold_win][1]
  1053.     refresh
  1054.   end
  1055.  
  1056.   def refresh
  1057.     contents.clear
  1058.     change_color(system_color)
  1059.     draw_text(0,0,contents.width,line_height,Gold_Text)
  1060.     change_color(normal_color)
  1061.     draw_text(0,0,contents.width,line_height,$game_party.gold,2)
  1062.   end
  1063.  
  1064. end
  1065.  
  1066. class Enchy_Finish < Window_Command
  1067.   include Sixth_Enchant_Scene
  1068.  
  1069.   def initialize
  1070.     x = Window_Setup[:finish][:pos][0]; y = Window_Setup[:finish][:pos][1]
  1071.     super(x,y)
  1072.     self.windowskin = Cache.system(Window_Setup[:finish][:skin])
  1073.   end
  1074.  
  1075.   def window_width
  1076.     return 100
  1077.   end
  1078.  
  1079.   def window_height
  1080.     return 96
  1081.   end
  1082.  
  1083.   def alignment
  1084.     return 1
  1085.   end
  1086.  
  1087.   def make_command_list
  1088.     add_command(Start_Cmd,:finish)
  1089.     add_command(Cancl_Cmd,:cancel)
  1090.   end
  1091.  
  1092.   def item_rect(index)
  1093.     rect = Rect.new
  1094.     rect.width = item_width
  1095.     rect.height = item_height
  1096.     rect.x = index % col_max * (item_width + spacing)
  1097.     rect.y = (index / col_max * item_height) + 24
  1098.     rect
  1099.   end
  1100.  
  1101.   def draw_finish_text
  1102.     draw_text(0,0,contents.width,line_height,Finsh_Txt,1)
  1103.   end
  1104.  
  1105.   def draw_item(index)
  1106.     contents.font.name = Text_Options[:fnsh_win][0]
  1107.     contents.font.size = Text_Options[:fnsh_win][1]
  1108.     super
  1109.   end
  1110.  
  1111.   def refresh
  1112.     textw = text_size(Finsh_Txt).width + 30 + Window_Setup[:finish][:add_width]
  1113.     self.width = textw
  1114.     self.x = self.x+((Graphics.width-self.x)-self.width)/2
  1115.     super
  1116.     draw_finish_text
  1117.   end
  1118.  
  1119.   def process_ok
  1120.     if current_item_enabled?
  1121.       Input.update
  1122.       deactivate
  1123.       call_ok_handler
  1124.     else
  1125.       Sound.play_buzzer
  1126.     end
  1127.   end
  1128.  
  1129. end
  1130. #==============================================================================
  1131. # !!END OF SCRIPT!!
  1132. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement