Advertisement
Szyu

EquipmentEnhancements

Jul 26th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 30.05 KB | None | 0 0
  1. #==============================================================================
  2. # ** EquipmentEnhancements
  3. #
  4. # * Author:   Szyu
  5. # * Version:  1.2
  6. # * Pastebin: http://adf.ly/4920670/equipmentenhancements
  7. # * Description:
  8. #     This script allows to enhance weapons and armors with defined
  9. #     "Enhancement Items".
  10. #
  11. # * How To Use:
  12. #   1. Create Items which will be used as "Enhancement Items"
  13. #   2. Flag the created items as enhancement with beginning tag
  14. #     "<enhancement_item>" (Without "")
  15. #   3. Flag end of definition in item notes with
  16. #     "</enhancement_item>"
  17. #   4. Set the type the enhancement is for (weapon or armor)
  18. #     "type: w"
  19. #     "type: a"
  20. #   5. You can set prefix and suffix for enhanced equipment with
  21. #     "prefix: """
  22. #     "suffix: """
  23. #   6. Add parameter or feature enhancements to this item with
  24. #     "p: attr val"
  25. #       -> p indicates that a parameter will be enhanced
  26. #       -> attr indicates which parameter will be enhanced:
  27. #         str - strength          def - defense             agi - agility
  28. #         mat - magic attack      mdf - magic defense       luk - luck
  29. #         hp - max hp             mp - max mp
  30. #       -> val indicates the value the parameter will be enhanced by
  31. #
  32. #     "f: code data val"
  33. #       -> f indicates that a feature will be added
  34. #       -> code indicates which feature will be added (since it will be declared
  35. #           as an integer, you should that a look an the features which can be
  36. #           added to an equipment item. The number is designed as xy, where x
  37. #           is the index of the tab and y is the index of the parameter.
  38. #           i.e. code = 22 would be tab "parameters" with feature "ex-parameter")
  39. #       -> data indicates the id of the dropdown list in the database features
  40. #           i.e. with code = 22, data = 6 would be parameter mrf
  41. #       -> val indicates the value like it would be stated in the database features.
  42. #           if a state would be added, this number has to be 0
  43. #           if a skill would be added, this number has to be 1
  44. #           (With features which do not allow number input in the database, you
  45. #           will have to test if the stated number would work. But it will either
  46. #           be 0 or 1!)
  47. #
  48. #
  49. # * Exclude equipment from enhancement list:
  50. #     <no_enhancing> in equipments notes
  51. #
  52. #
  53. # * Create Diminish Item Example:
  54. #   Use an item just like for enhancement_item, but with following syntax:
  55. #  
  56. #   <enhancement_item>
  57. #   diminish
  58. #   type: w       or type: a
  59. #   </enhancement_item>
  60. #
  61. #
  62. #------------------------------------------------------------------------------
  63. #
  64. # * Example of an Enhancement Item's note:
  65. #
  66. #   <enhancement_item>
  67. #   type: w
  68. #   suffix: " [Enh]"
  69. #   p: str 5
  70. #   p: hp 200
  71. #   f: 43 28 1
  72. #   </enhancement_item>
  73. #
  74. #
  75. #   This example would enhance a weapon with
  76. #   +5 strength,
  77. #   +200 max hp and
  78. #   the feature: Tab "skills", Data "Add Skill", Value: Skill[28]
  79. #
  80. #------------------------------------------------------------------------------
  81. #
  82. # * Changelog:
  83. #   - Weapons and Armors are now ordered by name
  84. #   - Added Diminishing Items
  85. #   - Added Possibility of exlcuding equipment from enhancing list
  86. #   - Fixed a bug where prefix and suffix are always lowercase
  87. #  
  88. #
  89. #==============================================================================
  90. $imported = {} if $imported.nil?
  91. $imported["Szyu_EquipmentEnhancements"] = true
  92. #==============================================================================
  93. # ** Configuration
  94. #==============================================================================
  95. SIE_CONFIG = {
  96.  
  97.   # Allows the player to access enhancer menu from main menu
  98.   :show_in_menu => false,
  99.  
  100.   # Term shown in main menu
  101.   :menu_term => "EQ Enhancing",
  102.  
  103.   # mapping for notes to param [do not change!]
  104.   :param_map => { :hp => 0, :mp => 1, :str => 2, :def => 3, :mat => 4, :mdf => 5, :agi => 6, :luk => 7},
  105. }
  106.  
  107. #==============================================================================
  108. # ** DataManager
  109. #==============================================================================
  110. class << DataManager
  111.   alias sie_make_save_contents make_save_contents
  112.   alias sie_extract_save_contents extract_save_contents
  113.   #--------------------------------------------------------------------------
  114.   # * Create Save Contents
  115.   #--------------------------------------------------------------------------
  116.   def make_save_contents
  117.     contents = sie_make_save_contents
  118.     contents[:see_db]        = db_enhancement_difference
  119.     contents
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # * Extract Save Contents
  123.   #--------------------------------------------------------------------------
  124.   def extract_save_contents(contents)
  125.     sie_extract_save_contents(contents)
  126.     extract_enhancement_db(contents[:see_db])
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Create Enhancement Database
  130.   #--------------------------------------------------------------------------
  131.   def create_save_database(index)
  132.     File.open(sprintf("SEEDB%02d.rvdata2", index + 1), "wb") do |file|
  133.       Marshal.dump(db_enhancement_difference, file)
  134.     end
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Load Enhancement Database
  138.   #--------------------------------------------------------------------------
  139.   def load_save_database(index)
  140.     File.open(sprintf("SEEDB%02d.rvdata2", index + 1), "rb") do |file|
  141.       extract_enhancement_db(Marshal.load(file))
  142.     end
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # * Create Database Differences
  146.   #--------------------------------------------------------------------------
  147.   def db_enhancement_difference
  148.     tmp_weapons = load_data("Data/Weapons.rvdata2")
  149.     tmp_armors = load_data("Data/Armors.rvdata2")
  150.     w = sie_diff(tmp_weapons, $data_weapons)
  151.     a = sie_diff(tmp_armors, $data_armors)
  152.     dif = {:weapons => w, :armors => a}
  153.     return dif
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # * Create Array Differences
  157.   #--------------------------------------------------------------------------
  158.   def sie_diff(x,y)
  159.     r = []
  160.     for i in x.size..y.size-1
  161.       r.push(y[i])
  162.     end
  163.     r.uniq.sort_by{|o| o.id}
  164.     return r
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Extrace Enhancement Database
  168.   #--------------------------------------------------------------------------
  169.   def extract_enhancement_db(contents)
  170.     $data_weapons = ($data_weapons+contents[:weapons]).uniq.sort{|a,b|( a and b ) ? a.id <=> b.id : ( a ? 1 : -1 ) }
  171.     $data_armors = ($data_armors+contents[:armors]).uniq.sort{|a,b|( a and b ) ? a.id <=> b.id : ( a ? 1 : -1 ) }
  172.   end
  173. end
  174.  
  175. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176.  
  177. #==============================================================================
  178. # ** RPG::Item
  179. #==============================================================================
  180. class RPG::Item < RPG::UsableItem
  181.   #--------------------------------------------------------------------------
  182.   # * Return Enhancements from Notes
  183.   #--------------------------------------------------------------------------
  184.   def enhancements
  185.     enhs = { :type => :none, :suffix => "", :prefix => "", :data => [], :diminish => false}
  186.     @note.each_line do |line|
  187.       if line =~ /<enhancement_item>/i
  188.         @scan_enh = true
  189.       elsif line =~ /<\/enhancement_item>/i
  190.         @scan_enh = false
  191.       elsif line =~ /diminish/i
  192.         enhs[:diminish] = true
  193.       elsif line =~ /type:\s*(\w)/i
  194.         enhs[:type] = $1.to_sym
  195.       elsif line =~ /suffix:\s*"([\w\W]+)"/i
  196.         enhs[:suffix] = $1.to_s
  197.       elsif line =~ /prefix:\s*"([\w\W]+)"/i
  198.         enhs[:prefix] = $1.to_s
  199.       elsif @scan_enh
  200.         enh = scan_enh_param_line(line) || scan_enh_feat_line(line)
  201.         enhs[:data].push(enh) if enh != nil
  202.       end
  203.     end
  204.       @scan_enh = nil
  205.       return enhs[:type] != :none && (enhs[:data].size > 0 || enhs[:diminish]) ? enhs : nil
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # * Scan Enhancement Parameter Line
  209.   #--------------------------------------------------------------------------
  210.   def scan_enh_param_line(line)
  211.     return nil unless line =~ /(p):\s*(\w+)\s*(\d+)/i
  212.     enh = [$1.to_sym, $2.to_sym, $3.to_i]
  213.     return enh
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * Scan Enhancement Feature Line
  217.   #--------------------------------------------------------------------------
  218.   def scan_enh_feat_line(line)
  219.     return nil unless line =~ /(f):\s*(\d+)\s*(\d+)\s*(\d+[.]\d+|\d+)/i
  220.     enh = [$1.to_sym, $2.to_i, $3.to_i, $4.to_f]
  221.     return enh
  222.   end
  223. end
  224.  
  225. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226.  
  227. #==============================================================================
  228. # ** RPG:EquipItem
  229. #==============================================================================
  230. class RPG::EquipItem < RPG::BaseItem
  231.   attr_accessor :enhanced_with
  232.   attr_accessor :original_id
  233.   #--------------------------------------------------------------------------
  234.   # * no_enhancing
  235.   #--------------------------------------------------------------------------
  236.   def no_enhancing
  237.     @note.downcase.each_line do |line|
  238.       return true if line =~ /<no_enhancing>/i
  239.     end
  240.     return false
  241.   end
  242. end
  243.  
  244. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  245.  
  246. #==============================================================================
  247. # ** Scene_Menu
  248. #==============================================================================
  249. class Scene_Menu < Scene_MenuBase
  250.   alias sie_create_command_window create_command_window
  251.   #--------------------------------------------------------------------------
  252.   # * Create Command Window
  253.   #--------------------------------------------------------------------------
  254.   def create_command_window
  255.     sie_create_command_window
  256.     @command_window.set_handler(:equipment_enhancer,    method(:on_equipment_enhancer))
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * On Equipment Enhancer
  260.   #--------------------------------------------------------------------------
  261.   def on_equipment_enhancer
  262.     SceneManager.call(Scene_EquipmentEnhancement)
  263.   end
  264. end
  265.  
  266. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  267.  
  268. #==============================================================================
  269. # ** Scene_EquipmentEnhancement
  270. #==============================================================================
  271. class Scene_EquipmentEnhancement < Scene_Item
  272.   #--------------------------------------------------------------------------
  273.   # * Start Processing
  274.   #--------------------------------------------------------------------------
  275.   def start
  276.     super
  277.     create_help_window
  278.     create_category_window
  279.     create_item_window
  280.     create_enhancement_window
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # * Create Category Window
  284.   #--------------------------------------------------------------------------
  285.   def create_category_window
  286.     @category_window = Window_EquipmentEnhancement_Category.new
  287.     @category_window.viewport = @viewport
  288.     @category_window.help_window = @help_window
  289.     @category_window.y = @help_window.height
  290.     @category_window.set_handler(:ok,     method(:on_category_ok))
  291.     @category_window.set_handler(:cancel, method(:return_scene))
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # * Create Item Window
  295.   #--------------------------------------------------------------------------
  296.   def create_item_window
  297.     wy = @category_window.y + @category_window.height
  298.     wh = Graphics.height - wy
  299.     @item_window = Window_EquipmentEnhancement_List.new(0, wy, Graphics.width/2, wh)
  300.     @item_window.viewport = @viewport
  301.     @item_window.help_window = @help_window
  302.     @item_window.set_handler(:ok,     method(:on_item_ok))
  303.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  304.     @category_window.item_window = @item_window
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * Create Enhancement Window
  308.   #--------------------------------------------------------------------------
  309.   def create_enhancement_window
  310.     wx = @item_window.width
  311.     wy = @category_window.y + @category_window.height
  312.     ww = Graphics.width - wx
  313.     wh = Graphics.height - wy
  314.     @enhancement_list_window = Window_EnhancementItem_List.new(wx,wy,ww,wh)
  315.     @enhancement_list_window.viewport = @viewport
  316.     @enhancement_list_window.help_window = @help_window
  317.     @enhancement_list_window.set_handler(:ok, method(:on_enhancement_ok))
  318.     @enhancement_list_window.set_handler(:cancel, method(:on_enhancement_cancel))
  319.     @item_window.enhancement_window = @enhancement_list_window
  320.     @enhancement_list_window.item_window = @item_window
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # * Category [OK]
  324.   #--------------------------------------------------------------------------
  325.   def on_category_ok
  326.     @item_window.activate
  327.     @item_window.select_last
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Item [Cancel]
  331.   #--------------------------------------------------------------------------
  332.   def on_item_cancel
  333.     @item_window.unselect
  334.     @category_window.activate
  335.   end
  336.   #--------------------------------------------------------------------------
  337.   # * Enhancement [Cancel]
  338.   #--------------------------------------------------------------------------
  339.   def on_enhancement_cancel
  340.     @enhancement_list_window.unselect
  341.     @item_window.activate
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # * Play SE When Using Item
  345.   #--------------------------------------------------------------------------
  346.   def play_se_for_item
  347.     Sound.play_use_item
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Use Item
  351.   #--------------------------------------------------------------------------
  352.   def use_item
  353.     super
  354.     @item_window.redraw_current_item
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # * Item [OK]
  358.   #--------------------------------------------------------------------------
  359.   def on_item_ok
  360.     @enhancement_list_window.activate.select(0)
  361.   end
  362.   #--------------------------------------------------------------------------
  363.   # * Enhancement [OK]
  364.   #--------------------------------------------------------------------------
  365.   def on_enhancement_ok
  366.     ehancement_item = @enhancement_list_window.item
  367.     if (ehancement_item.enhancements[:diminish] == false)
  368.       enhance_item(@item_window.item, ehancement_item)
  369.     else
  370.       diminish_item(@item_window.item, ehancement_item)
  371.     end
  372.     @enhancement_list_window.refresh
  373.     @enhancement_list_window.unselect
  374.     @item_window.refresh
  375.     @item_window.activate
  376.   end
  377.   #--------------------------------------------------------------------------
  378.   # * Enhance Item
  379.   #--------------------------------------------------------------------------
  380.   def enhance_item(item, enh_item)
  381.     return if item.original_id
  382.     db = item.is_a?(RPG::Weapon) ? $data_weapons : $data_armors
  383.     eid = check_item_existence(item, enh_item, db)
  384.     if eid == 0
  385.       new_item = Marshal.load(Marshal.dump(item))
  386.       new_item.original_id = item.original_id || item.id
  387.       new_item.id = db.size
  388.       new_item.name = enh_item.enhancements[:prefix]+item.name+@enhancement_list_window.item.enhancements[:suffix]
  389.       apply_enhancements(new_item, enh_item)
  390.       db.push(new_item)
  391.     else
  392.       new_item = db[eid]
  393.     end
  394.     $game_party.lose_item(enh_item, 1)
  395.     $game_party.gain_item(new_item,1)
  396.     $game_party.gain_item(@item_window.item,-1)
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # * Diminish Item
  400.   #--------------------------------------------------------------------------
  401.   def diminish_item(item, enh_item)
  402.     return unless item.original_id
  403.     db = item.is_a?(RPG::Weapon) ? $data_weapons : $data_armors
  404.     $game_party.gain_item(db[item.original_id], 1)
  405.     $game_party.gain_item(item,-1)
  406.     $game_party.lose_item(enh_item, 1)
  407.   end
  408.   #--------------------------------------------------------------------------
  409.   # * Apply Diminishing
  410.   #--------------------------------------------------------------------------
  411.   def apply_enhancements(item, enhancement_item)
  412.     enhancement_item.enhancements[:data].each do |enh|
  413.       case enh[0]
  414.       when :p
  415.         item.params[SIE_CONFIG[:param_map][enh[1]]] = enh[2]
  416.       when :f
  417.         item.features.push(RPG::BaseItem::Feature.new(enh[1], enh[2], enh[3]))
  418.       end
  419.     end
  420.     item.enhanced_with = enhancement_item.id
  421.     return item
  422.   end
  423.   #--------------------------------------------------------------------------
  424.   # * Check if enhanced item already exists
  425.   #--------------------------------------------------------------------------
  426.   def check_item_existence(item, enhanced_with, db)
  427.     for i in 1..db.size-1
  428.       return i if db[i].enhanced_with == enhanced_with.id && db[i].name == enhanced_with.enhancements[:prefix]+item.name+enhanced_with.enhancements[:suffix]
  429.     end
  430.     return 0
  431.   end
  432. end
  433.  
  434. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  435.  
  436. #==============================================================================
  437. # ** Window_MenuCommand
  438. #==============================================================================
  439. class Window_MenuCommand < Window_Command
  440.   alias sie_add_original_commands add_original_commands
  441.   #--------------------------------------------------------------------------
  442.   # * add_original_commands
  443.   #--------------------------------------------------------------------------
  444.   def add_original_commands
  445.     sie_add_original_commands
  446.     add_command(SIE_CONFIG[:menu_term],   :equipment_enhancer,   main_commands_enabled) if SIE_CONFIG[:show_in_menu]
  447.   end
  448. end
  449.  
  450. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  451.  
  452. #==============================================================================
  453. # ** Window_ItemEnhancement_Category
  454. #==============================================================================
  455. class Window_EquipmentEnhancement_Category < Window_HorzCommand
  456.   #--------------------------------------------------------------------------
  457.   # * Public Instance Variables
  458.   #--------------------------------------------------------------------------
  459.   attr_reader   :item_window
  460.   #--------------------------------------------------------------------------
  461.   # * Object Initialization
  462.   #--------------------------------------------------------------------------
  463.   def initialize
  464.     super(0, 0)
  465.   end
  466.   #--------------------------------------------------------------------------
  467.   # * Get Window Width
  468.   #--------------------------------------------------------------------------
  469.   def window_width
  470.     Graphics.width
  471.   end
  472.   #--------------------------------------------------------------------------
  473.   # * Get Digit Count
  474.   #--------------------------------------------------------------------------
  475.   def col_max
  476.     return 2
  477.   end
  478.   #--------------------------------------------------------------------------
  479.   # * Frame Update
  480.   #--------------------------------------------------------------------------
  481.   def update
  482.     super
  483.     @item_window.category = current_symbol if @item_window
  484.   end
  485.   #--------------------------------------------------------------------------
  486.   # * Create Command List
  487.   #--------------------------------------------------------------------------
  488.   def make_command_list
  489.     add_command(Vocab::weapon,   :weapon)
  490.     add_command(Vocab::armor,    :armor)
  491.   end
  492.   #--------------------------------------------------------------------------
  493.   # * Set Item Window
  494.   #--------------------------------------------------------------------------
  495.   def item_window=(item_window)
  496.     @item_window = item_window
  497.     update
  498.   end
  499. end
  500.  
  501. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  502.  
  503. #==============================================================================
  504. # ** Window_ItemEnhancement_List
  505. #==============================================================================
  506. class Window_EquipmentEnhancement_List < Window_Selectable
  507.   attr_reader :enhancement_window
  508.   #--------------------------------------------------------------------------
  509.   # * Object Initialization
  510.   #--------------------------------------------------------------------------
  511.   def initialize(x, y, width, height)
  512.     super
  513.     @category = :none
  514.     @data = []
  515.   end
  516.   #--------------------------------------------------------------------------
  517.   # * Enhancement Window setter
  518.   #--------------------------------------------------------------------------
  519.   def enhancement_window=(ew)
  520.     @enhancement_window = ew
  521.     update
  522.   end
  523.   #--------------------------------------------------------------------------
  524.   # * Update
  525.   #--------------------------------------------------------------------------
  526.   def update
  527.     super
  528.     @enhancement_window.category = @category if @enhancement_window
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # * Set Category
  532.   #--------------------------------------------------------------------------
  533.   def category=(category)
  534.     return if @category == category
  535.     @category = category
  536.     refresh
  537.     self.oy = 0
  538.   end
  539.   #--------------------------------------------------------------------------
  540.   # * Get Number of Items
  541.   #--------------------------------------------------------------------------
  542.   def item_max
  543.     @data ? @data.size : 1
  544.   end
  545.   #--------------------------------------------------------------------------
  546.   # * Get Item
  547.   #--------------------------------------------------------------------------
  548.   def item
  549.     @data && index >= 0 ? @data[index] : nil
  550.   end
  551.   #--------------------------------------------------------------------------
  552.   # * Get Activation State of Selection Item
  553.   #--------------------------------------------------------------------------
  554.   def current_item_enabled?
  555.     return @data[index] != nil
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # * Include in Item List?
  559.   #--------------------------------------------------------------------------
  560.   def include?(item)
  561.     case @category
  562.     when :item
  563.       item.is_a?(RPG::Item) && !item.key_item?
  564.     when :weapon
  565.       item.is_a?(RPG::Weapon)
  566.     when :armor
  567.       item.is_a?(RPG::Armor)
  568.     when :key_item
  569.       item.is_a?(RPG::Item) && item.key_item?
  570.     else
  571.       false
  572.     end
  573.   end
  574.   #--------------------------------------------------------------------------
  575.   # * Display in Enabled State?
  576.   #--------------------------------------------------------------------------
  577.   def enable?(item)
  578.     item != nil
  579.   end
  580.   #--------------------------------------------------------------------------
  581.   # * Create Item List
  582.   #--------------------------------------------------------------------------
  583.   def make_item_list
  584.     @data = $game_party.all_items.select {|item| include?(item) && !item.no_enhancing }
  585.     @data.push(nil) if include?(nil)
  586.     @data.sort! {|x,y| x.name <=> y.name }
  587.   end
  588.   #--------------------------------------------------------------------------
  589.   # * Restore Previous Selection Position
  590.   #--------------------------------------------------------------------------
  591.   def select_last
  592.     select(@data.index($game_party.last_item.object) || 0)
  593.   end
  594.   #--------------------------------------------------------------------------
  595.   # * Draw Item
  596.   #--------------------------------------------------------------------------
  597.   def draw_item(index)
  598.     item = @data[index]
  599.     if item
  600.       rect = item_rect(index)
  601.       rect.width -= 4
  602.       draw_item_name(item, rect.x, rect.y, enable?(item))
  603.       draw_item_number(rect, item)
  604.     end
  605.   end
  606.   #--------------------------------------------------------------------------
  607.   # * Draw Number of Items
  608.   #--------------------------------------------------------------------------
  609.   def draw_item_number(rect, item)
  610.     draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  611.   end
  612.   #--------------------------------------------------------------------------
  613.   # * Update Help Text
  614.   #--------------------------------------------------------------------------
  615.   def update_help
  616.     @help_window.set_item(item)
  617.   end
  618.   #--------------------------------------------------------------------------
  619.   # * Refresh
  620.   #--------------------------------------------------------------------------
  621.   def refresh
  622.     make_item_list
  623.     create_contents
  624.     draw_all_items
  625.   end
  626. end
  627.  
  628. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  629.  
  630. #==============================================================================
  631. # ** Window_Enhancement_List
  632. #==============================================================================
  633. class Window_EnhancementItem_List < Window_Selectable
  634.   attr_reader :item_window
  635.   #--------------------------------------------------------------------------
  636.   # * Object Initialization
  637.   #--------------------------------------------------------------------------
  638.   def initialize(x, y, width, height)
  639.     super
  640.     @category = :none
  641.     @data = []
  642.   end
  643.   #--------------------------------------------------------------------------
  644.   # * Set Category
  645.   #--------------------------------------------------------------------------
  646.   def category=(category)
  647.     return if @category == category
  648.     @category = category
  649.     refresh
  650.     self.oy = 0
  651.   end
  652.   #--------------------------------------------------------------------------
  653.   # * Set Item window
  654.   #--------------------------------------------------------------------------
  655.   def item_window=(item_window)
  656.     @item_window = item_window
  657.   end
  658.   #--------------------------------------------------------------------------
  659.   # * Get Number of Items
  660.   #--------------------------------------------------------------------------
  661.   def item_max
  662.     @data ? @data.size : 1
  663.   end
  664.   #--------------------------------------------------------------------------
  665.   # * Get Item
  666.   #--------------------------------------------------------------------------
  667.   def item
  668.     @data && index >= 0 ? @data[index] : nil
  669.   end
  670.   #--------------------------------------------------------------------------
  671.   # * Get Activation State of Selection Item
  672.   #--------------------------------------------------------------------------
  673.   def current_item_enabled?
  674.     return false if @data[index] == nil
  675.     return false if @item_window == nil
  676.     enh = item.enhancements
  677.     return true if enh[:diminish] == false && @item_window.item.original_id == nil
  678.     return true if enh[:diminish] && @item_window.item.original_id != nil
  679.   end
  680.   #--------------------------------------------------------------------------
  681.   # * Display in Enabled State?
  682.   #--------------------------------------------------------------------------
  683.   def enable?(item)
  684.     $game_party.usable?(item)
  685.   end
  686.   #--------------------------------------------------------------------------
  687.   # * Create Item List
  688.   #--------------------------------------------------------------------------
  689.   def make_item_list
  690.     @data = $game_party.all_items.select {|item| item.is_a?(RPG::Item) && enhancement_cat(item) }
  691.     @data.push(nil) if @data.size == 0
  692.   end
  693.   #--------------------------------------------------------------------------
  694.   # * Enhancement Category
  695.   #--------------------------------------------------------------------------
  696.   def enhancement_cat(item)
  697.     enh = item.enhancements
  698.     return false if enh == nil
  699.     case @category
  700.     when :weapon; return enh[:type] == :w
  701.     when :armor; return enh[:type] == :a
  702.     else; return false
  703.     end
  704.   end
  705.   #--------------------------------------------------------------------------
  706.   # * Restore Previous Selection Position
  707.   #--------------------------------------------------------------------------
  708.   def select_last
  709.     select(@data.index($game_party.last_item.object) || 0)
  710.   end
  711.   #--------------------------------------------------------------------------
  712.   # * Draw Item
  713.   #--------------------------------------------------------------------------
  714.   def draw_item(index)
  715.     item = @data[index]
  716.     if item
  717.       rect = item_rect(index)
  718.       rect.width -= 4
  719.       draw_item_name(item, rect.x, rect.y)
  720.       draw_item_number(rect, item)
  721.     end
  722.   end
  723.   #--------------------------------------------------------------------------
  724.   # * Draw Number of Items
  725.   #--------------------------------------------------------------------------
  726.   def draw_item_number(rect, item)
  727.     draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  728.   end
  729.   #--------------------------------------------------------------------------
  730.   # * Update Help Text
  731.   #--------------------------------------------------------------------------
  732.   def update_help
  733.     @help_window.set_item(item)
  734.   end
  735.   #--------------------------------------------------------------------------
  736.   # * Refresh
  737.   #--------------------------------------------------------------------------
  738.   def refresh
  739.     make_item_list
  740.     create_contents
  741.     draw_all_items
  742.   end
  743.   #--------------------------------------------------------------------------
  744.   # * Processing When OK Button Is Pressed
  745.   #--------------------------------------------------------------------------
  746.   def process_ok
  747.     if current_item_enabled?
  748.       Sound.play_use_item
  749.       Input.update
  750.       deactivate
  751.       call_ok_handler
  752.     else
  753.       Sound.play_buzzer
  754.     end
  755.   end
  756. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement