roninator2

Theoallen Simply Upgrade your Weapon addon - Sockets

Dec 9th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 58.84 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Weapon Upgrade - Sockets               ║  Version: 1.06     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║   Add sockets to upgraded weapons             ║    28 Jan 2024     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: Smithing -- Simply Upgrade Your Weapon                   ║
  11. # ╚════════════════════════════════════════════════════════════════════╝
  12. # ╔════════════════════════════════════════════════════════════════════╗
  13. # ║ Brief Description:                                                 ║
  14. # ║   Adds sockets to upgraded weapons which can then have             ║
  15. # ║   armour marked as socket items attached                           ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║   Configure settings below to preferences                          ║
  20. # ║     Theo Smith                                                     ║
  21. # ║        W_Socket_Table                                              ║
  22. # ║     R2_Socket_Config                                               ║
  23. # ║        Slot_Icon_Nothing                                           ║
  24. # ║        Use_Menu_Command                                            ║
  25. # ║        Max_Socket_Items                                            ║
  26. # ║        Elements - element names in terms database                  ║
  27. # ║     Vocab                                                          ║
  28. # ║        Socket_Menu                                                 ║
  29. # ║        Cur_Socket_Text                                             ║
  30. # ║        New_Socket_Text                                             ║
  31. # ║                                                                    ║
  32. # ║   Socketed items are Armours                                       ║
  33. # ║                                                                    ║
  34. # ║   Call scene by using menu command or script call                  ║
  35. # ║    SceneManager.call(Scene_Socket_System)                          ║
  36. # ║                                                                    ║
  37. # ║   Mark armour to be used as socketing items                        ║
  38. # ║     <SOCKET ITEM>                                                  ║
  39. # ║                                                                    ║
  40. # ║   The features of the armour will be added to the actor            ║
  41. # ║                                                                    ║
  42. # ║   Supports:                                                        ║
  43. # ║             Added Skills                                           ║
  44. # ║             Elements Changes                                       ║
  45. # ║               add an element and set the rate e.g. 110%            ║
  46. # ║             Stats                                                  ║
  47. # ║               Those added to the armour in the database            ║
  48. # ╚════════════════════════════════════════════════════════════════════╝
  49. # ╔════════════════════════════════════════════════════════════════════╗
  50. # ║ Updates:                                                           ║
  51. # ║ 1.00 - 28 Jan 2024 - Script finished                               ║
  52. # ║ 1.01 - 28 Jan 2024 - Did stuff                                     ║
  53. # ║ 1.02 - 28 Jan 2024 - Fixed stuff                                   ║
  54. # ║ 1.03 - 30 Jan 2024 - Made improvements                             ║
  55. # ║ 1.04 - 06 Feb 2024 - Fixed bugs                                    ║
  56. # ║ 1.05 - 16 Feb 2024 - Found bug with transferring sockets           ║
  57. # ║ 1.06 - 24 Feb 2024 - Bug found with weapons socket empty           ║
  58. # ║                      and window update issue                       ║
  59. # ╚════════════════════════════════════════════════════════════════════╝
  60. # ╔════════════════════════════════════════════════════════════════════╗
  61. # ║ Credits and Thanks:                                                ║
  62. # ║   Roninator2                                                       ║
  63. # ║   Victor Sant - borrowed code - Materia                            ║
  64. # ║   TheoAllen - weapon upgrade script                                ║
  65. # ╚════════════════════════════════════════════════════════════════════╝
  66. # ╔════════════════════════════════════════════════════════════════════╗
  67. # ║ Terms of use:                                                      ║
  68. # ║  Follow the original Authors terms of use where applicable         ║
  69. # ║    - When not made by me (Roninator2)                              ║
  70. # ║  Free for all uses in RPG Maker except nudity                      ║
  71. # ║  Anyone using this script in their project before these terms      ║
  72. # ║  were changed are allowed to use this script even if it conflicts  ║
  73. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  74. # ║  No part of this code can be used with AI programs or tools        ║
  75. # ║  Credit must be given                                              ║
  76. # ╚════════════════════════════════════════════════════════════════════╝
  77.  
  78. # ╔════════════════════════════════════════════════════════════════════╗
  79. # ║                         Edit Below                                 ║
  80. # ╚════════════════════════════════════════════════════════════════════╝
  81. module THEO
  82.   module Smith
  83.   #==========================================================================
  84.   # Weapon Socket Table
  85.   #==========================================================================
  86.    
  87.     W_Socket_Table = { # <-- Do not touch this at all cost!
  88.     #------------------------------------------------------------------------
  89.     # Socket addition design
  90.     #------------------------------------------------------------------------
  91.     # ID => [ <-- opening
  92.     #
  93.     #       [level, num},  # Level 2
  94.     #       [level, num},  # Level 3
  95.     #       [ <add more here for the next level> ], # Level 4
  96.     #
  97.     #       ], <-- ending (do not forget to add comma!)
  98.     #------------------------------------------------------------------------
  99.     # Just a quick guide won't kill yourself :)
  100.     #------------------------------------------------------------------------
  101.     # ID                = Weapon ID in database.
  102.     #
  103.     # {level} = At what level the change is to be applied
  104.     #           Weapons start at level 1 and first upgrade to level 2
  105.     #           so using level 0 or 1 doesn't do anything
  106.     #
  107.     # {num} = Once you've upgrade your weapon, the parameter will
  108.     #              change whether it's up or down. Here's how:
  109.     #            ---------------------------------------------------
  110.     #            num = 1 # then you can attach 1 accessory to the weapon socket
  111.     #            num = 2 # then you can attach 2 accessory to the weapon socket
  112.     #
  113.     # Here's the example :
  114.     #------------------------------------------------------------------------
  115.       1  => [
  116.             [2,2], # dont forget comma
  117.             [3,3], # one socket
  118.             [4,4], # two sockets
  119.             ], # dont forget comma
  120.            
  121.      13  => [
  122.             [2,0],
  123.             [3,2],
  124.             ],
  125.            
  126.      19  => [
  127.             [2,0],
  128.             [3,1],
  129.             [4,4],
  130.             ],
  131.            
  132.     # add more here if it's necessary
  133.    
  134.     #------------------------------------------------------------------------
  135.     } # <-- Must be here!
  136.   end
  137. end
  138.  
  139. module R2_Socket_Config
  140.   # Default icons for Socket slots
  141.   Slot_Icon_Nothing  = 16
  142.  
  143.   # Specify if using Menu commands
  144.   Use_Menu_Command = true
  145.  
  146.   # Specify maximum number of socket item that can be carried
  147.   Max_Socket_Items = 250
  148.  
  149.   # Specify maximum number of socket item that can be carried
  150.   Elements = {
  151.               1 => "Physical",
  152.               2 => "Absorb",
  153.               3 => "Fire",
  154.               4 => "Ice",
  155.               5 => "Thunder",
  156.               6 => "Water",
  157.               7 => "Earth",
  158.               8 => "Wind",
  159.               9 => "Holy",
  160.               10 => "Dark",
  161.             }
  162.   # position for the Vertical line
  163.   Vertical_Line_X = 260
  164. end
  165.  
  166. module Vocab
  167.  
  168.   # Socket menu text
  169.   Socket_Menu = "Socket Weapon"
  170.   # Display the text for current sockets
  171.   Cur_Socket_Text = "Current Sockets Available"
  172.   # Display the text for new sockets to acquire
  173.   New_Socket_Text = "New Sockets Upon Upgrade"
  174.  
  175. end
  176.  
  177. # ╔════════════════════════════════════════════════════════════════════╗
  178. # ║                      End of editable region                        ║
  179. # ╚════════════════════════════════════════════════════════════════════╝
  180.  
  181. #==============================================================================
  182. # ** Object
  183. #------------------------------------------------------------------------------
  184. #  This class is the superclass of all other classes.
  185. #==============================================================================
  186.  
  187. class Object
  188.   #--------------------------------------------------------------------------
  189.   # * New method: make_symbol
  190.   #--------------------------------------------------------------------------
  191.   def make_symbol(string)
  192.     string.downcase.gsub(" ", "_").to_sym
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # * New method: get_param_id
  196.   #--------------------------------------------------------------------------
  197.   def get_param_id(text)
  198.     case text.upcase
  199.     when "MAXHP", "HP" then 0
  200.     when "MAXMP", "MP" then 1
  201.     when "ATK" then 2
  202.     when "DEF" then 3
  203.     when "MAT" then 4
  204.     when "MDF" then 5
  205.     when "AGI" then 6
  206.     when "LUK" then 7
  207.     end
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # * New method: get_param_text
  211.   #--------------------------------------------------------------------------
  212.   def get_param_text(id)
  213.     case id
  214.     when 0 then "HP"
  215.     when 1 then "MP"
  216.     when 2 then "ATK"
  217.     when 3 then "DEF"
  218.     when 4 then "MAT"
  219.     when 5 then "MDF"
  220.     when 6 then "AGI"
  221.     when 7 then "LUK"
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * New method: get_xparam_id
  226.   #--------------------------------------------------------------------------
  227.   def get_xparam_id(text)
  228.     case text.upcase
  229.     when "HIT" then 0
  230.     when "EVA" then 1
  231.     when "CRI" then 2
  232.     when "CEV" then 3
  233.     when "MEV" then 4
  234.     when "MRF" then 5
  235.     when "CNT" then 6
  236.     when "HRG" then 7
  237.     when "MRG" then 8
  238.     when "TRG" then 9
  239.     end
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # * New method: get_xparam_text
  243.   #--------------------------------------------------------------------------
  244.   def get_xparam_text(id)
  245.     case id
  246.     when 0 then "HIT"
  247.     when 1 then "EVA"
  248.     when 2 then "CRI"
  249.     when 3 then "CEV"
  250.     when 4 then "MEV"
  251.     when 5 then "MRF"
  252.     when 6 then "CNT"
  253.     when 7 then "HRG"
  254.     when 8 then "MRG"
  255.     when 9 then "TRG"
  256.     end
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * New method: get_sparam_id
  260.   #--------------------------------------------------------------------------
  261.   def get_sparam_id(text)
  262.     case text.upcase
  263.     when "TGR" then 0
  264.     when "GRD" then 1
  265.     when "REC" then 2
  266.     when "PHA" then 3
  267.     when "MCR" then 4
  268.     when "TCR" then 5
  269.     when "PDR" then 6
  270.     when "MDR" then 7
  271.     when "FDR" then 8
  272.     when "EXR" then 9
  273.     end
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # * New method: get_sparam_text
  277.   #--------------------------------------------------------------------------
  278.   def get_sparam_text(id)
  279.     case id
  280.     when 0 then "TGR"
  281.     when 1 then "GRD"
  282.     when 2 then "REC"
  283.     when 3 then "PHA"
  284.     when 4 then "MCR"
  285.     when 5 then "TCR"
  286.     when 6 then "PDR"
  287.     when 7 then "MDR"
  288.     when 8 then "FDR"
  289.     when 9 then "EXR"
  290.     end
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # * New method: get_feature_text
  294.   #--------------------------------------------------------------------------
  295.   def get_feature_text(id)
  296.     case id
  297.     when 11 then "Element"
  298.     when 32 then "State"
  299.     when 43 then "Skill"
  300.     end
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # * effect_name
  304.   #--------------------------------------------------------------------------
  305.   def get_element_name(id)
  306.     return R2_Socket_Config::Elements[id]
  307.   end
  308. end
  309.  
  310. class RPG::UpgradedWeapon < RPG::Weapon
  311.   attr_accessor :sockets
  312.   alias r2_socket_insert_init initialize
  313.   def initialize
  314.     r2_socket_insert_init
  315.     @sockets = {}
  316.   end
  317.   def socket_item?
  318.     return false
  319.   end
  320.   def ori_id?
  321.     @ori_id != nil
  322.   end
  323. end
  324.  
  325. class RPG::Weapon < RPG::EquipItem
  326.   def sockets?
  327.     @sockets != nil
  328.   end
  329.   def ori_id?
  330.     false
  331.   end
  332. end
  333.  
  334. class RPG::Item < RPG::UsableItem
  335.   def sockets?
  336.     false
  337.   end
  338.   def socket_item?
  339.     return false
  340.   end
  341.   def ori_id?
  342.     false
  343.   end
  344. end
  345.  
  346. class RPG::UsableItem < RPG::BaseItem
  347.   def sockets?
  348.     false
  349.   end
  350.   def socket_item?
  351.     return false
  352.   end
  353.   def ori_id?
  354.     false
  355.   end
  356. end
  357.  
  358. class Window_SocketResult < Window_SmithResult
  359.  
  360.   def refresh
  361.     contents.clear
  362.     @weapon = $game_party.members[@menu_actor.index].equips[0]
  363.     return unless @weapon
  364.     if @weapon.is_a?(RPG::UpgradedWeapon)
  365.       return unless THEO::Smith::W_Socket_Table[@weapon.ori_id]
  366.     else
  367.       return unless THEO::Smith::W_Socket_Table[@weapon.id]
  368.     end
  369.     reset_font_settings
  370.     draw_socket_info
  371.   end
  372.  
  373.   def draw_socket_info
  374.     rect = Rect.new(0,0,contents.width,line_height)
  375.     contents.font.size -= 4
  376.     draw_text(rect,Vocab::Cur_Socket_Text,0)
  377.     cur = nil
  378.     new = nil
  379.     if @weapon.ori_id?
  380.       lvls = THEO::Smith::W_Socket_Table[@weapon.ori_id]
  381.       lvls.each { |itm| if itm[0] == @weapon.level; cur = itm[1];  end }
  382.       cur = 0 if cur == nil
  383.     else
  384.       lvls = THEO::Smith::W_Socket_Table[@weapon.id]
  385.       lvls.each { |itm| if itm[0] == @weapon.level; cur = itm[1];  end }
  386.       cur = 0 if cur == nil
  387.     end
  388.     draw_text(rect,cur,2)
  389.     rect.y += 24
  390.     draw_text(rect,Vocab::New_Socket_Text,0)
  391.     if @weapon.ori_id?
  392.       lvls = THEO::Smith::W_Socket_Table[@weapon.ori_id]
  393.       lvls.each { |itm| if itm[0] == (@weapon.level + 1); new = itm[1];  end }
  394.       new = cur if new == nil
  395.     else
  396.       lvls = THEO::Smith::W_Socket_Table[@weapon.id]
  397.       lvls.each { |itm| if itm[0] == (@weapon.level + 1); new = itm[1];  end }
  398.       new = cur if new == nil
  399.     end
  400.     draw_text(rect,new,2)
  401.   end
  402.  
  403.   def actor_window=(window)
  404.     @menu_actor = window
  405.   end
  406. end
  407.  
  408. class Window_SmithMenu < Window_Selectable
  409.  
  410.   def socket_window=(window)
  411.     @socket_window = window
  412.   end
  413.  
  414.   def update_help
  415.     @help_window.refresh(weapon)
  416.     @socket_window.refresh if @socket_window
  417.   end
  418.  
  419. end
  420.  
  421. class Scene_Smith < Scene_MenuBase
  422.  
  423.   alias r2_start_socket_window  start
  424.   def start
  425.     r2_start_socket_window
  426.     create_socket_result
  427.   end
  428.  
  429.   def create_socket_result
  430.     x = @smith_result.x
  431.     y = @smith_result.height + @smith_result.y
  432.     w = Graphics.width - @menu_actor.width - @gold_window.width
  433.     h = 24 * 3 + 4
  434.     @socket_result = Window_SocketResult.new(x,y,w,h)
  435.     @socket_result.z = 1
  436.     @socket_result.actor_window = @menu_actor
  437.     @menu_actor.socket_window = @socket_result
  438.     @socket_result.refresh
  439.   end
  440.  
  441.   alias r2_weapon_assign_sockets_smith_weapon craft_weapon
  442.   def craft_weapon
  443.     itm = item_to_lose
  444.     r2_weapon_assign_sockets_smith_weapon
  445.     assign_sockets(actor.equips[0], itm)
  446.     @socket_result.refresh
  447.   end
  448.  
  449.   def assign_sockets(wpn, old)
  450.     $upgraded_weapons.each do |uw|
  451.       if uw[1].id == wpn.id
  452.         if old.sockets?
  453.           old.sockets.each_with_index do |sk, i|
  454.             uw[1].sockets[i] = sk[1]
  455.           end
  456.         end
  457.         lvl = uw[1].level
  458.         sock = 0
  459.         THEO::Smith::W_Socket_Table[uw[1].ori_id].each do |lv|
  460.           sock = lv[1].to_i if lv[0] == lvl
  461.         end
  462.         sock.times do |ws|
  463.           uw[1].sockets[ws] = [] if uw[1].sockets[ws] == nil
  464.         end
  465.       end
  466.     end
  467.   end
  468. end
  469.  
  470. class RPG::EquipItem < RPG::BaseItem
  471.   #--------------------------------------------------------------------------
  472.   # * New method: socket_item?
  473.   #--------------------------------------------------------------------------
  474.   def socket_item?
  475.     return false
  476.   end
  477. end
  478.  
  479. class RPG::Armor < RPG::EquipItem
  480.   #--------------------------------------------------------------------------
  481.   # * Public Instance Variables
  482.   #--------------------------------------------------------------------------
  483.   attr_reader   :stats
  484.   #--------------------------------------------------------------------------
  485.   # * New method: materia?
  486.   #--------------------------------------------------------------------------
  487.   def socket_item?
  488.     note =~ /<SOCKET ITEM>/i
  489.   end
  490.   #--------------------------------------------------------------------------
  491.   # * New method: sockets?
  492.   #--------------------------------------------------------------------------
  493.   def sockets?
  494.     @sockets != nil
  495.   end
  496.   #--------------------------------------------------------------------------
  497.   # * New method: setup_item_stats
  498.   #--------------------------------------------------------------------------
  499.   def setup_item_stats
  500.     setup_stats
  501.     setup_effects
  502.     self
  503.   end
  504.   #--------------------------------------------------------------------------
  505.   # * New method: setup_stats
  506.   #--------------------------------------------------------------------------
  507.   def setup_stats
  508.     @stats = {}
  509.     values = note =~ /<STATS:\s([\w\s\+\-:%,;]+)>/i ? $1.dup : ""
  510.     regexp = /(\w+):\s*([+-]?\d+)%/i
  511.     values.scan(regexp).each {|x, y| @stats[get_param_id(x)] = y.to_i }
  512.   end
  513.   #--------------------------------------------------------------------------
  514.   # * New method: setup_effects
  515.   #--------------------------------------------------------------------------
  516.   def setup_effects
  517.     values   = note =~ /<EFFECTS:\s([\w\s\+\-:%,;]+)>/i ? $1.dup : ""
  518.     @effects = values.scan(/[\w\s\+\-\:\%]*/i).inject({}) do |r, i|
  519.       if i =~ /([\w\s]+)(?:: *([+-]?\d+)%?)?/i
  520.         r[make_symbol($1)] = $2 ? $2.to_i / 100.0 : true
  521.       end
  522.       r
  523.     end
  524.     @effects.default = 0
  525.   end
  526.   #--------------------------------------------------------------------------
  527.   # * New method: effect?
  528.   #--------------------------------------------------------------------------
  529.   def effect?(effect)
  530.     @effects.keys.include?(effect)
  531.   end
  532.   #--------------------------------------------------------------------------
  533.   # * New method: effect
  534.   #--------------------------------------------------------------------------
  535.   def effect(value)
  536.     @effects[value]
  537.   end
  538. end
  539.  
  540. class Game_Interpreter
  541.   #--------------------------------------------------------------------------
  542.   # * New method: call_materia_shop
  543.   #--------------------------------------------------------------------------
  544.   def call_socket_scene
  545.     return if $game_party.in_battle
  546.     SceneManager.call(Scene_Socket_System)
  547.   end
  548. end
  549.  
  550. class Window_MenuCommand < Window_Command
  551.   #--------------------------------------------------------------------------
  552.   # * Alias method: add_main_commands
  553.   #--------------------------------------------------------------------------
  554.   alias :add_main_commands_r2_socket_system :add_main_commands
  555.   def add_main_commands
  556.     add_main_commands_r2_socket_system
  557.     add_command(Vocab::Socket_Menu, :socket, main_commands_enabled)
  558.   end
  559. end
  560.  
  561. class Scene_Menu < Scene_MenuBase
  562.   #--------------------------------------------------------------------------
  563.   # * Alias method: create_command_window
  564.   #--------------------------------------------------------------------------
  565.   alias :socket_system_create_command_window :create_command_window
  566.   def create_command_window
  567.     socket_system_create_command_window
  568.     @command_window.set_handler(:socket,   method(:command_personal))
  569.   end
  570.   #--------------------------------------------------------------------------
  571.   # * Alias method: on_personal_ok
  572.   #--------------------------------------------------------------------------
  573.   alias :socket_system_on_personal_ok :on_personal_ok
  574.   def on_personal_ok
  575.     socket_system_on_personal_ok
  576.     if @command_window.current_symbol == :socket
  577.       SceneManager.call(Scene_Socket_System)
  578.     end
  579.   end
  580. end
  581.  
  582. #==============================================================================
  583. # ** Game_Actor
  584. #==============================================================================
  585.  
  586. class Game_Actor < Game_Battler
  587.   #--------------------------------------------------------------------------
  588.   # * Alias method: param_plus
  589.   #--------------------------------------------------------------------------
  590.   alias :param_plus_r2_socket_system :param_plus
  591.   def param_plus(param_id)
  592.     result = param_plus_r2_socket_system(param_id)
  593.     all_socket_items.inject(result) {|r, item| r += item.params[param_id] }
  594.   end
  595.   #--------------------------------------------------------------------------
  596.   # * Alias method: param_rate
  597.   #--------------------------------------------------------------------------
  598.   alias :param_rate_r2_socket_system :param_rate
  599.   def param_rate(param_id)
  600.     result = param_rate_r2_socket_system(param_id)
  601.     result + socket_item_param(param_id)
  602.   end
  603.   #--------------------------------------------------------------------------
  604.   # * Alias method: xparam
  605.   #--------------------------------------------------------------------------
  606.   alias :xparam_r2_socket_system :xparam
  607.   def xparam(param_id)
  608.     result = xparam_r2_socket_system(param_id)
  609.     result + socket_item_xparam(param_id)
  610.   end
  611.   #--------------------------------------------------------------------------
  612.   # * Alias method: sparam
  613.   #--------------------------------------------------------------------------
  614.   alias :sparam_r2_socket_system :sparam
  615.   def sparam(param_id)
  616.     result = sparam_r2_socket_system(param_id)
  617.     result + socket_item_sparam(param_id)
  618.   end  
  619.   #--------------------------------------------------------------------------
  620.   # * Alias method: feature_objects
  621.   #--------------------------------------------------------------------------
  622.   alias :feature_objects_r2_socket_system :feature_objects
  623.   def feature_objects
  624.     feature_objects_r2_socket_system + all_socket_items
  625.   end
  626.   #--------------------------------------------------------------------------
  627.   # * New method: all_socket_items
  628.   #--------------------------------------------------------------------------
  629.   def all_socket_items
  630.     return [] if self.equips[0].nil?
  631.     return [] if self.equips[0].sockets? == false
  632.     self.equips[0].sockets.values.inject([]) {|r, i| r += i }
  633.   end
  634.   #--------------------------------------------------------------------------
  635.   # * New method: socket_item_param
  636.   #--------------------------------------------------------------------------
  637.   def socket_item_param(id)
  638.     all_socket_items.inject(0.0) do |r, m|
  639.       r += socket_item_param_plus(m, id)
  640.     end
  641.   end
  642.   #--------------------------------------------------------------------------
  643.   # * New method: socket_item_param_plus
  644.   #--------------------------------------------------------------------------
  645.   def socket_item_param_plus(m, id)
  646.     m.effect(make_symbol(get_param_text(id)))
  647.   end
  648.   #--------------------------------------------------------------------------
  649.   # * New method: socket_item_xparam
  650.   #--------------------------------------------------------------------------
  651.   def socket_item_xparam(id)
  652.     all_socket_items.inject(0.0) do |r, m|
  653.       r += socket_item_xparam_plus(m, id)
  654.     end
  655.   end
  656.   #--------------------------------------------------------------------------
  657.   # * New method: socket_item_xparam_plus
  658.   #--------------------------------------------------------------------------
  659.   def socket_item_xparam_plus(m, id)
  660.     m.effect(make_symbol(get_xparam_text(id)))
  661.   end
  662.   #--------------------------------------------------------------------------
  663.   # * New method: socket_item_sparam
  664.   #--------------------------------------------------------------------------
  665.   def socket_item_sparam(id)
  666.     all_socket_items.inject(0.0) do |r, m|
  667.       r += socket_item_sparam_plus(m, id)
  668.     end
  669.   end
  670.   #--------------------------------------------------------------------------
  671.   # * New method: socket_item_sparam_plus
  672.   #--------------------------------------------------------------------------
  673.   def socket_item_sparam_plus(m, id)
  674.     m.effect(make_symbol(get_sparam_text(id)))
  675.   end
  676.   #--------------------------------------------------------------------------
  677.   # * New method: equip_socket_item
  678.   #--------------------------------------------------------------------------
  679.   def equip_socket_item(slot, id)
  680.     old = self.equips[0].sockets[slot][0]
  681.     self.equips[0].sockets[slot] = [$game_party.socket_items[id]]
  682.     $game_party.lose_socket_item(id)
  683.     $game_party.gain_item(old, 1) if old != []
  684.     refresh
  685.   end
  686.   #--------------------------------------------------------------------------
  687.   # * New method: unequip_materia
  688.   #--------------------------------------------------------------------------
  689.   def unequip_socket_item(slot)
  690.     $game_party.gain_item(self.equips[0].sockets[slot][0], 1)
  691.     self.equips[0].sockets[slot] = []
  692.     refresh
  693.   end
  694. end
  695.  
  696. #==============================================================================
  697. # ** Game_Party
  698. #==============================================================================
  699.  
  700. class Game_Party < Game_Unit
  701.   #--------------------------------------------------------------------------
  702.   # *
  703.   #--------------------------------------------------------------------------
  704.   attr_reader   :socket_items
  705.   #--------------------------------------------------------------------------
  706.   # * Alias method: init_all_items
  707.   #--------------------------------------------------------------------------
  708.   alias :init_all_items_r2_socket_system :init_all_items
  709.   def init_all_items
  710.     init_all_items_r2_socket_system
  711.     @socket_items = []
  712.   end
  713.   #--------------------------------------------------------------------------
  714.   # * Alias method: gain_item
  715.   #--------------------------------------------------------------------------
  716.   alias :gain_item_r2_socket_system :gain_item
  717.   def gain_item(item, amount, include_equip = false)
  718.     if item && item.socket_item?
  719.       gain_socket_item(item, amount)
  720.     else
  721.       gain_item_r2_socket_system(item, amount, include_equip)
  722.     end
  723.   end
  724.   #--------------------------------------------------------------------------
  725.   # * New method: gain_socket_item
  726.   #--------------------------------------------------------------------------
  727.   def gain_socket_item(item, amount = 1)
  728.     if amount > 0
  729.       socket_item = item.clone.setup_item_stats
  730.       amount.times { @socket_items.push(socket_item) if !socket_items_max?}
  731.     elsif amount < 0
  732.       remove_socket_item(item, amount.abs)
  733.     end
  734.     @socket_items.sort! {|a, b| a.id <=> b.id }
  735.     $game_map.need_refresh = true
  736.   end
  737.   #--------------------------------------------------------------------------
  738.   # * New method: remove_socket_item
  739.   #--------------------------------------------------------------------------
  740.   def remove_socket_item(item, amount = 1)
  741.     amount.times do
  742.       removed = false
  743.       @socket_items.each_with_index do |m, i|
  744.         if m.id == item.id && !removed
  745.           removed = true
  746.           break @socket_items.delete_at(i)
  747.         end
  748.       end
  749.     end
  750.   end
  751.   #--------------------------------------------------------------------------
  752.   # * New method: lose_materia
  753.   #--------------------------------------------------------------------------
  754.   def lose_socket_item(index)
  755.     @socket_items.delete_at(index)
  756.     @socket_items.sort! {|a, b| a.id <=> b.id }
  757.   end
  758.   #--------------------------------------------------------------------------
  759.   # * New method: max_materia?
  760.   #--------------------------------------------------------------------------
  761.   def socket_items_max?
  762.     @socket_items.size >= R2_Socket_Config::Max_Socket_Items
  763.   end
  764. end
  765.  
  766. #==============================================================================
  767. # ** Scene_Shop
  768. #------------------------------------------------------------------------------
  769. #  This class performs shop screen processing.
  770. #==============================================================================
  771. class Scene_Shop < Scene_MenuBase
  772.   #--------------------------------------------------------------------------
  773.   # * Execute Sale
  774.   #--------------------------------------------------------------------------
  775.   alias r2_shop_sell_sockets      do_sell
  776.   def do_sell(number)
  777.     if @item.sockets?
  778.       @item.sockets.each do |i, itm|
  779.         next if itm == []
  780.         $game_party.gain_socket_item(itm[0], 1)
  781.       end
  782.     end
  783.     r2_shop_sell_sockets(number)
  784.   end
  785. end
  786.  
  787. #==============================================================================
  788. # ** Window_SocketInfo
  789. #------------------------------------------------------------------------------
  790. #  This window shows the socket item information.
  791. #==============================================================================
  792.  
  793. class Window_SocketInfo < Window_Base
  794.   #--------------------------------------------------------------------------
  795.   # * initialize
  796.   #--------------------------------------------------------------------------
  797.   def initialize(width, height)
  798.     super(0, 200, width, height)
  799.   end
  800.   #--------------------------------------------------------------------------
  801.   # * socket_item
  802.   #--------------------------------------------------------------------------
  803.   def socket_item=(socket_item)
  804.     @socket_item = socket_item
  805.     refresh
  806.   end
  807.   #--------------------------------------------------------------------------
  808.   # * refresh
  809.   #--------------------------------------------------------------------------
  810.   def refresh
  811.     contents.clear
  812.     return if @socket_item.nil?
  813.     contents.font.size = Font.default_size
  814.     return if @socket_item == []
  815.     @socket_item = @socket_item[0] if @socket_item.is_a?(Array)
  816.     draw_item_name(@socket_item, 0, 0, true, width)
  817.     contents.font.size = 19
  818.     draw_socket_item_stats
  819.   end
  820.   #--------------------------------------------------------------------------
  821.   # * draw_item_name
  822.   #--------------------------------------------------------------------------
  823.   def draw_item_name(item, x, y, enabled = true, width = 172)
  824.     return unless item
  825.     draw_icon(item.icon_index, x, y - 2, enabled)
  826.     change_color(normal_color, enabled)
  827.     draw_text(x + 24, y, width, line_height, item.name)
  828.   end
  829.   #--------------------------------------------------------------------------
  830.   # * draw_icon
  831.   #--------------------------------------------------------------------------
  832.   def draw_icon(icon_index, x, y, enabled = true)
  833.     bitmap = Cache.system("Iconset")
  834.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  835.     contents.blt(x, y, bitmap, rect, enabled ? 255 : 120)
  836.   end
  837.   #--------------------------------------------------------------------------
  838.   # * draw_socket_item_stats
  839.   #--------------------------------------------------------------------------
  840.   def draw_socket_item_stats
  841.     list1 = get_params_values
  842.     list2 = get_stats_values
  843.     list3 = get_feature_values
  844.     list1.each_with_index {|param, i| draw_param_value(param, i, false) }
  845.     list2.each_with_index {|param, i| draw_param_value(param, i + list1.size) }
  846.     list3.each_with_index {|ft, i| draw_feature_value(ft, i) }
  847.     draw_vertical_line_ex(R2_Socket_Config::Vertical_Line_X, 0, Color.new(255,255,255,128), Color.new(0,0,0,64))
  848.   end
  849.   #--------------------------------------------------------------------------
  850.   # * get_params_values
  851.   #--------------------------------------------------------------------------
  852.   def get_params_values
  853.     list = []
  854.     @socket_item.params.size.times do |i|
  855.       next if @socket_item.params[i] == 0
  856.       list.push({name: Vocab::param(i), value: @socket_item.params[i]})
  857.     end
  858.     list
  859.   end
  860.   #--------------------------------------------------------------------------
  861.   # * get_stats_values
  862.   #--------------------------------------------------------------------------
  863.   def get_stats_values
  864.     list = []
  865.     @socket_item.stats.keys.each do |i|
  866.       next if @socket_item.stats[i] == 0
  867.       list.push({name: Vocab::param(i), value: @socket_item.stats[i]})
  868.     end
  869.     list
  870.   end
  871.   #--------------------------------------------------------------------------
  872.   # * get_params_values
  873.   #--------------------------------------------------------------------------
  874.   def get_feature_values
  875.     list = []
  876.     @socket_item.features.each_with_index do |ft, i|
  877.       next if ft.data_id == 0
  878.       list.push({name: feature_type(ft), value: @socket_item.features[i]})
  879.     end
  880.     list
  881.   end
  882.   #--------------------------------------------------------------------------
  883.   # * feature_type
  884.   #--------------------------------------------------------------------------
  885.   def feature_type(ft)
  886.     code = get_feature_text(ft.code)
  887.     id = ft.data_id
  888.     return "#{code}-#{id}"
  889.   end
  890.   #--------------------------------------------------------------------------
  891.   # * draw_param_value
  892.   #--------------------------------------------------------------------------
  893.   def draw_param_value(param, i, rate = true)
  894.     name  = param[:name]
  895.     plus  = param[:value] < 0 ? "-" : "+"
  896.     value = sprintf("%02d", param[:value].abs)
  897.     rate  = rate ? "%" : ""
  898.     draw_param_info(name, plus, value, rate, i, width - 176, 108)
  899.   end
  900.   #--------------------------------------------------------------------------
  901.   # * draw_param_info
  902.   #--------------------------------------------------------------------------
  903.   def draw_param_info(name, plus, value, rate, i, x, y)
  904.     z = 88
  905.     contents.draw_text(x + 40, z + i * 18, 172, 24, name)
  906.     contents.draw_text(x + y, z + i * 18, 172, 24, plus)
  907.     change_color(plus == "-" ? knockout_color : crisis_color)
  908.     wid = text_size(plus).width
  909.     contents.draw_text(x + y + wid, z + i * 15, 172, 24, value)
  910.     change_color(normal_color)
  911.     wid += text_size(value).width
  912.     contents.draw_text(x + y + wid, z + i * 15, 172, 24, rate)
  913.   end
  914.   #--------------------------------------------------------------------------
  915.   # * draw_feature_value
  916.   #--------------------------------------------------------------------------
  917.   def draw_feature_value(ft, i)
  918.     title = ""
  919.     data  = ft[:name].split("-")
  920.     name = data[0]
  921.     value = (ft[:value].value * 100).to_i
  922.     id = ft[:value].data_id
  923.     draw_feature_info(name, value, id, i, 0, 108)
  924.   end
  925.   #--------------------------------------------------------------------------
  926.   # * draw_feature_info
  927.   #--------------------------------------------------------------------------
  928.   def draw_feature_info(name, value, id, i, x, y)
  929.     z = 88
  930.     contents.draw_text(x, z + i * 15, 172, 24, name)
  931.     case name
  932.     when "Skill"
  933.       skill = $data_skills[id]
  934.       skname = skill.name
  935.       wid = text_size(skname).width
  936.       change_color(system_color)
  937.       contents.draw_text(70, z + i * 15, 172, 24, skname)
  938.       change_color(normal_color)
  939.     when "Element"
  940.       ele = get_element_name(id)
  941.       wid = text_size(ele).width
  942.       change_color(system_color)
  943.       contents.draw_text(70, z + i * 15, 172, 24, ele)
  944.       change_color(crisis_color)
  945.       wid += text_size(value).width
  946.       contents.draw_text(160, z + i * 15, 172, 24, "#{value}%")
  947.     end
  948.   end
  949.   #--------------------------------------------------------------------------
  950.   # * draw_vertical_line
  951.   #--------------------------------------------------------------------------
  952.   def draw_vertical_line_ex(x, y, color, shadow)
  953.     # // Method to draw a vertical line with a shadow.
  954.     line_x = x + line_height / 2 - 1
  955.     contents.fill_rect(line_x, y, 2, contents_height, color)
  956.     line_x += 1
  957.     contents.fill_rect(line_x, y, 2, contents_height, shadow)
  958.   end
  959. end
  960.  
  961. #==============================================================================
  962. # ** Window_SocketList
  963. #------------------------------------------------------------------------------
  964. #  This window shows the socket list.
  965. #==============================================================================
  966.  
  967. class Window_SocketList < Window_Selectable
  968.   #--------------------------------------------------------------------------
  969.   # * Public Instance Variables
  970.   #--------------------------------------------------------------------------
  971.   attr_reader   :socket_window
  972.   #--------------------------------------------------------------------------
  973.   # * item_max
  974.   #--------------------------------------------------------------------------
  975.   def item_max
  976.     @data ? @data.size : 1
  977.   end
  978.   #--------------------------------------------------------------------------
  979.   # * socket_item
  980.   #--------------------------------------------------------------------------
  981.   def socket_item
  982.     @data[index]
  983.   end
  984.   #--------------------------------------------------------------------------
  985.   # * draw_item
  986.   #--------------------------------------------------------------------------
  987.   def draw_item(index)
  988.     item = @data[index]
  989.     if item
  990.       rect = item_rect(index)
  991.       rect.width -= 4
  992.       draw_item_name(item, rect.x, rect.y)
  993.     end
  994.   end
  995.   #--------------------------------------------------------------------------
  996.   # * draw_item_name
  997.   #--------------------------------------------------------------------------
  998.   def draw_item_name(item, x, y, enabled = true, width = 172)
  999.     return unless item
  1000.     draw_icon(item.icon_index, x, y, enabled, item)
  1001.     change_color(normal_color, enabled)
  1002.     draw_text(x + 24, y, width, line_height, item.name)
  1003.   end
  1004.   #--------------------------------------------------------------------------
  1005.   # * draw_icon
  1006.   #--------------------------------------------------------------------------
  1007.   def draw_icon(icon_index, x, y, enabled = true, item)
  1008.     bitmap = Cache.system("Iconset")
  1009.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  1010.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  1011.   end
  1012.   #--------------------------------------------------------------------------
  1013.   # * refresh
  1014.   #--------------------------------------------------------------------------
  1015.   def refresh
  1016.     make_item_list
  1017.     create_contents
  1018.     draw_all_items
  1019.   end
  1020.   #--------------------------------------------------------------------------
  1021.   # * materia_window
  1022.   #--------------------------------------------------------------------------
  1023.   def socket_window=(socket_window)
  1024.     @socket_window = socket_window
  1025.     call_update_help
  1026.   end
  1027.   #--------------------------------------------------------------------------
  1028.   # * update_help
  1029.   #--------------------------------------------------------------------------
  1030.   def update_help
  1031.     super
  1032.     @socket_window.socket_item = socket_item if @socket_window
  1033.     return if socket_item.nil? || socket_item == []
  1034.     @help_window.set_item(socket_item)
  1035.   end
  1036.  
  1037. end
  1038.  
  1039. #==============================================================================
  1040. # ** Window_SocketStatus
  1041. #------------------------------------------------------------------------------
  1042. #  This window shows the materias on the socket equip screen.
  1043. #==============================================================================
  1044.  
  1045. class Window_SocketStatus < Window_SocketList
  1046.   #--------------------------------------------------------------------------
  1047.   # * initialize
  1048.   #--------------------------------------------------------------------------
  1049.   def initialize
  1050.     super(window_x, 200, 192, window_height)
  1051.     @data = []
  1052.   end
  1053.   #--------------------------------------------------------------------------
  1054.   # * window_x
  1055.   #--------------------------------------------------------------------------
  1056.   def window_x
  1057.     352 + [Graphics.width - 544, 0].max
  1058.   end
  1059.   #--------------------------------------------------------------------------
  1060.   # * window_height
  1061.   #--------------------------------------------------------------------------
  1062.   def window_height
  1063.     216 + [Graphics.height - 416, 0].max
  1064.   end
  1065.   #--------------------------------------------------------------------------
  1066.   # * make_item_list
  1067.   #--------------------------------------------------------------------------
  1068.   def make_item_list
  1069.     @data = $game_party.socket_items.collect {|socket_item| socket_item }
  1070.     @data.push(nil)
  1071.   end
  1072. end
  1073.  
  1074. #==============================================================================
  1075. # ** Window_SocketActor
  1076. #------------------------------------------------------------------------------
  1077. #  This window shows the actor status on the socket equip screen.
  1078. #==============================================================================
  1079.  
  1080. class Window_SocketActor < Window_Selectable
  1081.   #--------------------------------------------------------------------------
  1082.   # * Public Instance Variables
  1083.   #--------------------------------------------------------------------------
  1084.   attr_reader   :actor
  1085.   #--------------------------------------------------------------------------
  1086.   # * initialize
  1087.   #--------------------------------------------------------------------------
  1088.   def initialize
  1089.     @equip = 0
  1090.     super(0, 0, Graphics.width, 128)
  1091.     @index = 0
  1092.   end
  1093.   #--------------------------------------------------------------------------
  1094.   # * actor
  1095.   #--------------------------------------------------------------------------
  1096.   def actor=(actor)
  1097.     @actor = actor
  1098.     refresh
  1099.   end
  1100.   #--------------------------------------------------------------------------
  1101.   # * refresh
  1102.   #--------------------------------------------------------------------------
  1103.   def refresh
  1104.     super
  1105.     draw_face(actor.face_name, actor.face_index, 4, 4)
  1106.     draw_actor_name(actor, 104, line_height * 0)
  1107.     draw_actor_level(actor, 104, line_height * 1)
  1108.     draw_actor_hp(actor, 104, line_height * 2)
  1109.     draw_actor_mp(actor, 104, line_height * 3)
  1110.   end
  1111. end
  1112.  
  1113. #==============================================================================
  1114. # ** Window_Socket_Item_Equip
  1115. #------------------------------------------------------------------------------
  1116. #  This window shows the actor equipe sockets. Do not show the window frame.
  1117. #==============================================================================
  1118.  
  1119. class Window_Socket_Item_Equip < Window_Selectable
  1120.   #--------------------------------------------------------------------------
  1121.   # * Public Instance Variables
  1122.   #--------------------------------------------------------------------------
  1123.   attr_accessor :equip  
  1124.   attr_reader   :actor
  1125.   attr_reader   :socket_window
  1126.   #--------------------------------------------------------------------------
  1127.   # * initialize
  1128.   #--------------------------------------------------------------------------
  1129.   def initialize
  1130.     @equip = 0
  1131.     super(window_x, 0, Graphics.width - window_x, 128)
  1132.     @index = 0
  1133.   end
  1134.   #--------------------------------------------------------------------------
  1135.   # * item_max
  1136.   #--------------------------------------------------------------------------
  1137.   def item_max
  1138.     return 1
  1139.   end
  1140.   #--------------------------------------------------------------------------
  1141.   # * contents_width
  1142.   #--------------------------------------------------------------------------
  1143.   def contents_width
  1144.     width - standard_padding * 2
  1145.   end
  1146.   #--------------------------------------------------------------------------
  1147.   # * contents_height
  1148.   #--------------------------------------------------------------------------
  1149.   def contents_height
  1150.     48
  1151.   end
  1152.   #--------------------------------------------------------------------------
  1153.   # * update_padding_bottom
  1154.   #--------------------------------------------------------------------------
  1155.   def update_padding_bottom
  1156.   end
  1157.   #--------------------------------------------------------------------------
  1158.   # * actor
  1159.   #--------------------------------------------------------------------------
  1160.   def actor=(actor)
  1161.     @actor = actor
  1162.     refresh
  1163.   end
  1164.   #--------------------------------------------------------------------------
  1165.   # * socket_item
  1166.   #--------------------------------------------------------------------------
  1167.   def socket_item
  1168.     return [] if @actor.equips[0].nil?
  1169.     slots = actor.equips[0].sockets? ? actor.equips[0].sockets : []
  1170.     slots ? slots[index] : slots
  1171.   end
  1172.   #--------------------------------------------------------------------------
  1173.   # * slot_width
  1174.   #--------------------------------------------------------------------------
  1175.   def slot_width
  1176.     max_slots * 32
  1177.   end
  1178.   #--------------------------------------------------------------------------
  1179.   # * max_slots
  1180.   #--------------------------------------------------------------------------
  1181.   def max_slots
  1182.     return 0 if @actor.nil?
  1183.     return 0 if @actor.equips[0].nil?
  1184.     @actor.equips[0].sockets? ? actor.equips[0].sockets.size : 0
  1185.   end
  1186.   #--------------------------------------------------------------------------
  1187.   # * window_x
  1188.   #--------------------------------------------------------------------------
  1189.   def window_x
  1190.     return 160
  1191.   end
  1192.   #--------------------------------------------------------------------------
  1193.   # * refresh
  1194.   #--------------------------------------------------------------------------
  1195.   def refresh
  1196.     super
  1197.     create_contents
  1198.     self.opacity = 0
  1199.     draw_equipments(8 + window_x)
  1200.     draw_socket_items(28 + window_x)
  1201.   end
  1202.   #------------------------------------------------------------------------------
  1203.   # * draw_equipments
  1204.   #------------------------------------------------------------------------------
  1205.   def draw_equipments(x)
  1206.     item = actor.equips[0]
  1207.     draw_item_name(item, x, y)
  1208.   end
  1209.   #------------------------------------------------------------------------------
  1210.   # * draw_socket_items
  1211.   #------------------------------------------------------------------------------
  1212.   def draw_socket_items(x)
  1213.     draw_background(x)
  1214.     draw_slots(x)
  1215.     draw_socket_item_icons(x)
  1216.   end
  1217.   #------------------------------------------------------------------------------
  1218.   # * draw_background
  1219.   #------------------------------------------------------------------------------
  1220.   def draw_background(x)
  1221.     color = Color.new(0, 0, 0, 50)
  1222.     actor.equip_slots.size.times do |i|
  1223.       contents.fill_rect(x - 4, i * 50 + 26, slot_width, 22, color)
  1224.     end
  1225.   end
  1226.   #------------------------------------------------------------------------------
  1227.   # * draw_slots
  1228.   #------------------------------------------------------------------------------
  1229.   def draw_slots(x)
  1230.     return unless actor.equips[0]
  1231.     return unless actor.equips[0].sockets?
  1232.     icon1 = R2_Socket_Config::Slot_Icon_Nothing
  1233.     actor.equips[0].sockets.each {|y, i| draw_icon(icon1, x + y * 32, 24) }
  1234.   end
  1235.   #------------------------------------------------------------------------------
  1236.   # * draw_socket_item_icons
  1237.   #------------------------------------------------------------------------------
  1238.   def draw_socket_item_icons(x)
  1239.     return unless actor.equips[0]
  1240.     return unless actor.equips[0].sockets?
  1241.     actor.equips[0].sockets.each do |y, m|
  1242.       next if m == []
  1243.       draw_socketed_item(m[0].icon_index, x + y * 32, 24, m, 200) if m
  1244.     end
  1245.   end
  1246.   #--------------------------------------------------------------------------
  1247.   # * draw_socketed_items
  1248.   #--------------------------------------------------------------------------
  1249.   def draw_socketed_item(icon_index, x, y, item, opacity = 255)
  1250.     bitmap = Cache.system("Iconset")
  1251.     rect   = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  1252.     contents.blt(x, y, bitmap, rect, opacity)
  1253.   end
  1254.   #--------------------------------------------------------------------------
  1255.   # * equip
  1256.   #--------------------------------------------------------------------------
  1257.   def equip=(equip)
  1258.     @equip = equip
  1259.     update_cursor
  1260.     call_update_help
  1261.   end
  1262.   #--------------------------------------------------------------------------
  1263.   # * update_cursor
  1264.   #--------------------------------------------------------------------------
  1265.   def update_cursor
  1266.     ensure_cursor_visible
  1267.     cursor_rect.set(item_rect(@index, @equip))
  1268.   end
  1269.   #--------------------------------------------------------------------------
  1270.   # * item_rect
  1271.   #--------------------------------------------------------------------------
  1272.   def item_rect(index, equip)
  1273.     rect = Rect.new
  1274.     rect.width  = 26
  1275.     rect.height = 26
  1276.     rect.x  = index * 32 + 27 + window_x
  1277.     rect.y  = equip * 50 + 24
  1278.     self.oy = (equip - equip % 2) * 50
  1279.     rect
  1280.   end
  1281.   #--------------------------------------------------------------------------
  1282.   # * cursor_down
  1283.   #--------------------------------------------------------------------------
  1284.   def cursor_down(wrap = false)
  1285.     return if max_slots == 0
  1286.     self.index += 1
  1287.     self.index %= max_slots
  1288.   end
  1289.   #--------------------------------------------------------------------------
  1290.   # * cursor_up
  1291.   #--------------------------------------------------------------------------
  1292.   def cursor_up(wrap = false)
  1293.     return if max_slots == 0
  1294.     self.index -= 1
  1295.     self.index %= max_slots
  1296.   end
  1297.   #--------------------------------------------------------------------------
  1298.   # * cursor_right
  1299.   #--------------------------------------------------------------------------
  1300.   def cursor_right(wrap = false)
  1301.     return if max_slots == 0
  1302.     self.index += 1
  1303.     self.index %= max_slots
  1304.   end
  1305.   #--------------------------------------------------------------------------
  1306.   # * cursor_left
  1307.   #--------------------------------------------------------------------------
  1308.   def cursor_left(wrap = false)
  1309.     return if max_slots == 0
  1310.     self.index -= 1
  1311.     self.index %= max_slots
  1312.   end
  1313.   #--------------------------------------------------------------------------
  1314.   # * current_item_enabled?
  1315.   #--------------------------------------------------------------------------
  1316.   def current_item_enabled?
  1317.     return false if actor.equips[0].nil?
  1318.     return false unless actor.equips[0].sockets?
  1319.     index < actor.equips[0].sockets.size
  1320.   end
  1321.   #--------------------------------------------------------------------------
  1322.   # * process_handling
  1323.   #--------------------------------------------------------------------------
  1324.   def process_handling
  1325.     return unless open? && active
  1326.     return process_clear  if Input.trigger?(:A)
  1327.     super
  1328.   end
  1329.   #--------------------------------------------------------------------------
  1330.   # * socket_window=
  1331.   #--------------------------------------------------------------------------
  1332.   def socket_window=(socket_window)
  1333.     @socket_window = socket_window
  1334.     call_update_help
  1335.   end
  1336.   #--------------------------------------------------------------------------
  1337.   # * update_help
  1338.   #--------------------------------------------------------------------------
  1339.   def update_help
  1340.     super
  1341.     @socket_window.socket_item = socket_item if @socket_window
  1342.     return if @socket_item.nil? || @socket_item == []
  1343.     @help_window.set_item(socket_item)
  1344.   end
  1345. end
  1346.  
  1347. #==============================================================================
  1348. # ** Scene_Socket_System
  1349. #------------------------------------------------------------------------------
  1350. #  This class performs the materia equip screen processing.
  1351. #==============================================================================
  1352.  
  1353. class Scene_Socket_System < Scene_MenuBase
  1354.   #--------------------------------------------------------------------------
  1355.   # * start
  1356.   #--------------------------------------------------------------------------
  1357.   def start
  1358.     super
  1359.     create_help_window
  1360.     create_socket_item_window
  1361.     create_status_window
  1362.     create_equip_window
  1363.     create_item_window
  1364.   end
  1365.   #--------------------------------------------------------------------------
  1366.   # * create_help_window
  1367.   #--------------------------------------------------------------------------
  1368.   def create_help_window
  1369.     @help_window = Window_Help.new(2)
  1370.     @help_window.viewport = @viewport
  1371.     @help_window.y = 128
  1372.   end
  1373.   #--------------------------------------------------------------------------
  1374.   # * create_materia_window
  1375.   #--------------------------------------------------------------------------
  1376.   def create_socket_item_window
  1377.     ww = 352 + [Graphics.width - 544, 0].max
  1378.     wh = 216 + [Graphics.height - 416, 0].max
  1379.     @socket_item_window = Window_SocketInfo.new(ww, wh)
  1380.     @socket_item_window.viewport = @viewport
  1381.   end
  1382.   #--------------------------------------------------------------------------
  1383.   # * create_status_window
  1384.   #--------------------------------------------------------------------------
  1385.   def create_status_window
  1386.     @status_window = Window_SocketActor.new
  1387.     @status_window.actor = @actor
  1388.     @status_window.viewport = @viewport
  1389.   end
  1390.   #--------------------------------------------------------------------------
  1391.   # * create_equip_window
  1392.   #--------------------------------------------------------------------------
  1393.   def create_equip_window
  1394.     @equip_window = Window_Socket_Item_Equip.new
  1395.     @equip_window.actor = @actor
  1396.     @equip_window.viewport = @viewport
  1397.     @equip_window.help_window = @help_window
  1398.     @equip_window.socket_window = @socket_item_window
  1399.     @equip_window.set_handler(:ok,       method(:command_equip))
  1400.     @equip_window.set_handler(:cancel,   method(:return_scene))
  1401.     @equip_window.set_handler(:pagedown, method(:next_actor))
  1402.     @equip_window.set_handler(:pageup,   method(:prev_actor))
  1403.     @equip_window.activate
  1404.   end
  1405.   #--------------------------------------------------------------------------
  1406.   # * create_item_window
  1407.   #--------------------------------------------------------------------------
  1408.   def create_item_window
  1409.     @item_window = Window_SocketStatus.new
  1410.     @item_window.viewport = @viewport
  1411.     @item_window.help_window = @help_window
  1412.     @item_window.socket_window = @socket_item_window
  1413.     @item_window.set_handler(:ok,     method(:on_item_ok))
  1414.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  1415.     @item_window.refresh
  1416.   end
  1417.   #--------------------------------------------------------------------------
  1418.   # * command_equip
  1419.   #--------------------------------------------------------------------------
  1420.   def command_equip
  1421.     @item_window.activate
  1422.     @item_window.select(0)
  1423.   end
  1424.   #--------------------------------------------------------------------------
  1425.   # * on_actor_change
  1426.   #--------------------------------------------------------------------------
  1427.   def on_actor_change
  1428.     @equip_window.actor  = @actor
  1429.     @status_window.actor = @actor
  1430.     @item_window.refresh
  1431.     @socket_item_window.refresh
  1432.     @equip_window.activate
  1433.   end
  1434.   #--------------------------------------------------------------------------
  1435.   # * on_item_ok
  1436.   #--------------------------------------------------------------------------
  1437.   def on_item_ok
  1438.     Sound.play_equip
  1439.     if @item_window.socket_item
  1440.       @actor.equip_socket_item(@equip_window.index, @item_window.index)
  1441.     else
  1442.       @actor.unequip_socket_item(@equip_window.index)
  1443.     end
  1444.     @item_window.refresh
  1445.     @equip_window.refresh
  1446.     @status_window.refresh
  1447.     @socket_item_window.refresh
  1448.     @equip_window.activate
  1449.     @item_window.unselect
  1450.   end
  1451.   #--------------------------------------------------------------------------
  1452.   # * on_item_cancel
  1453.   #--------------------------------------------------------------------------
  1454.   def on_item_cancel
  1455.     @equip_window.activate
  1456.     @item_window.unselect
  1457.   end
  1458. end
Add Comment
Please, Sign In to add comment