Advertisement
QuasiXi

Quasi Passive Equip

Sep 2nd, 2014
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.68 KB | None | 0 0
  1. #==============================================================================
  2. #** Quasi Passive Skills Equip v 2.2
  3. #==============================================================================
  4. # Allows players to equip passive skills inside the skill menu.
  5. #==============================================================================
  6. # Instructions:
  7. # Very simple to use, mostly plug and play.
  8. #
  9. # For the Passive Equips you will need my Passive Scripts
  10. # - Passive Skills ( State based )
  11. # http://quasixi.wordpress.com/2014/03/23/quasi-passive/
  12. #
  13. # or
  14. #
  15. # - Fixed Passive Skills
  16. # http://quasixi.wordpress.com/2014/03/26/quasi-fixed-passive/
  17. #
  18. # Can work with both, or just one.  This needs to be placed BELOW those scripts.
  19. #
  20. # If used with Quasi Skill Type Equip, place this BELOW it.
  21. #------------------------------------------------------------------------------
  22. # * Note Tag
  23. #------------------------------------------------------------------------------
  24. # <passive_slots: #>
  25. # Can be placed in actors note box, or weapons/armor.  Default is 0
  26. #
  27. # If an actor has 2 passive slots, and equips a weapon with 2 more slots.  You
  28. # will be able to equip 4 passive skills.  If you unequip the weapon, the last
  29. # 2 passive skills equipped, will be unequipped.
  30. #------------------------------------------------------------------------------
  31. # * Log
  32. #------------------------------------------------------------------------------
  33. # v 2.1-2.2 9/4/14
  34. #  - Fixed a bug that caused game to freeze
  35. #  - Fixed a bug where fixed passives didn't list when used with state passive
  36. #  - Fixed a bug with passive learn
  37. #-----------------------------------------------------------------------------
  38. module Quasi
  39.   module PassiveEquip
  40.     # Title to appear in the command window.
  41.     # Only matters if one of my passive scripts is installed.
  42.     NAMEPASSIVE = "Passive"
  43.     # What to show in the help window.
  44.     HELP        = "Passives Equiped" # shows "Passive Equiped: total/max"
  45.   end
  46. end
  47. #==============================================================================#
  48. # By Quasi (http://quasixi.wordpress.com/)
  49. #  - 9/1/14
  50. #==============================================================================#
  51. #   ** Stop! Do not edit anything below, unless you know what you      **
  52. #   ** are doing!                                                      **
  53. #==============================================================================#
  54. $imported = {} if $imported.nil?
  55. $imported["Quasi_PassiveEquip"] = 2.0
  56.  
  57. #==============================================================================
  58. # ** Game_BattlerBase
  59. #------------------------------------------------------------------------------
  60. #  This base class handles battlers. It mainly contains methods for calculating
  61. # parameters. It is used as a super class of the Game_Battler class.
  62. #==============================================================================
  63.  
  64. class Game_BattlerBase
  65.   alias qepinit initialize
  66.   attr_accessor   :equipped_passive
  67.   #--------------------------------------------------------------------------
  68.   # * Object Initialization
  69.   # ** ALIAS **
  70.   #--------------------------------------------------------------------------
  71.   def initialize
  72.     qepinit
  73.     @equipped_passive = [] # Only used if [Quasi Passive] is installed
  74.   end
  75. end
  76.  
  77. #==============================================================================
  78. # ** Game_Actor
  79. #------------------------------------------------------------------------------
  80. #  This class handles actors. It is used within the Game_Actors class
  81. # ($game_actors) and is also referenced from the Game_Party class ($game_party).
  82. #==============================================================================
  83.  
  84. class Game_Actor < Game_Battler
  85.   alias qepce change_equip
  86.   #--------------------------------------------------------------------------
  87.   # * Change Equipment
  88.   #     slot_id:  Equipment slot ID
  89.   #     item:    Weapon/armor (remove equipment if nil)
  90.   # ** ALIAS **
  91.   #--------------------------------------------------------------------------
  92.   def change_equip(slot_id, item)
  93.     qepce(slot_id, item)
  94.     check_passive_slots
  95.   end
  96.  
  97.   def passive_slots
  98.     pslots = actor.passive_slots
  99.     @equips.each {|e| next if e.object.nil? ; pslots += e.object.passive_slots}
  100.     pslots
  101.   end
  102.  
  103.   def check_passive_slots
  104.     if equipped_passive.size > passive_slots
  105.       equipped_passive.each_with_index do |p, i|
  106.         next if i < passive_slots
  107.         forget_passive(p) if $imported["Quasi_Passive"]
  108.         remove_fixed_passive(p) if $imported["Quasi_Fixed_Passive"]
  109.       end
  110.     end
  111.   end
  112.  
  113.   #--------------------------------------------------------------------------
  114.   # * Patch for Passive
  115.   #--------------------------------------------------------------------------
  116.  
  117.   def learn_passive(skill_id)
  118.     return unless equipped_passive.include?(skill_id)
  119.     return unless skill_learn?($data_skills[skill_id])
  120.     passive = $data_skills[skill_id].passive
  121.     add_new_state(passive.to_i) if passive
  122.     reset_state_counts(passive.to_i) if passive
  123.   end
  124.  
  125.   def forget_passive(skill_id)
  126.     if equipped_passive.include?(skill_id)
  127.       passive = $data_skills[skill_id].passive
  128.       remove_passive(passive.to_i) if passive
  129.       equipped_passive.delete(skill_id) if !$imported["Quasi_Fixed_Passive"]
  130.     end
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Patch for Fixed Passive
  134.   #--------------------------------------------------------------------------
  135.   alias qepafp add_fixed_passive if $imported["Quasi_Fixed_Passive"]
  136.  
  137.   def add_fixed_passive(skill_id)
  138.     return unless equipped_passive.include?(skill_id)
  139.     return unless skill_learn?($data_skills[skill_id])
  140.     passive = $data_skills[skill_id].quasi_passive
  141.     passive.each {|p| passive_list(p, 1)} if passive
  142.   end
  143.  
  144.   def remove_fixed_passive(skill_id)
  145.     if equipped_passive.include?(skill_id)
  146.       passive = $data_skills[skill_id].quasi_passive
  147.       passive.each {|p| passive_list(p, -1)} if passive
  148.       equipped_passive.delete(skill_id)
  149.     end
  150.   end
  151. end
  152.  
  153. #==============================================================================
  154. # ** Scene_Skill
  155. #------------------------------------------------------------------------------
  156. #  This class performs skill screen processing. Skills are handled as items for
  157. # the sake of process sharing.
  158. #==============================================================================
  159.  
  160. class Scene_Skill < Scene_ItemBase
  161.   alias qepccw create_command_window
  162.   alias qepciw create_item_window
  163.   #--------------------------------------------------------------------------
  164.   # * Update Method
  165.   # ~ Don't really like this, but needed to fix visibility issue.
  166.   #--------------------------------------------------------------------------
  167.   def update
  168.     super
  169.     if $imported["Quasi_STypeEquip"] && $imported["Quasi_SkillEquip"]
  170.       update_with_both
  171.     elsif $imported["Quasi_SkillEquip"]
  172.       update_with_sequip
  173.     elsif $imported["Quasi_STypeEquip"]
  174.       update_with_stype
  175.     else
  176.       update_solo
  177.     end
  178.   end
  179.   def update_solo
  180.     case @command_window.command_name(@command_window.index)
  181.     when Quasi::PassiveEquip::NAMEPASSIVE
  182.       @passive_window.show if !@passive_window.visible
  183.       @item_window.hide if @item_window.visible
  184.     else
  185.       @item_window.show if !@item_window.visible
  186.       @passive_window.hide if @passive_window.visible
  187.     end
  188.   end
  189.   def update_with_sequip
  190.     case @command_window.command_name(@command_window.index)
  191.     when Quasi::SkillEquip::NAMESKILL
  192.       @skill_equip_window.show if !@skill_equip_window.visible
  193.       @item_window.hide if @item_window.visible
  194.       @passive_window.hide if @passive_window.visible
  195.     when Quasi::PassiveEquip::NAMEPASSIVE
  196.       @passive_window.show if !@passive_window.visible
  197.       @skill_equip_window.hide if @skill_equip_window.visible
  198.       @item_window.hide if @item_window.visible
  199.     else
  200.       @item_window.show if !@item_window.visible
  201.       @passive_window.hide if @passive_window.visible
  202.       @skill_equip_window.hide if @skill_equip_window.visible
  203.     end
  204.   end
  205.   def update_with_stype
  206.     case @command_window.command_name(@command_window.index)
  207.     when Quasi::PassiveEquip::NAMEPASSIVE
  208.       @passive_window.show if !@passive_window.visible
  209.       @item_window.hide if @item_window.visible
  210.       @stype_window.hide if @stype_window.visible
  211.     when Quasi::STypeEquip::NAME
  212.       @stype_window.show if !@stype_window.visible
  213.       @passive_window.hide if @passive_window.visible
  214.       @item_window.hide if @item_window.visible
  215.     else
  216.       @item_window.show if !@item_window.visible
  217.       @passive_window.hide if @passive_window.visible
  218.       @stype_window.hide if @stype_window.visible
  219.     end
  220.   end
  221.   def update_with_both
  222.     case @command_window.command_name(@command_window.index)
  223.     when Quasi::SkillEquip::NAMESKILL
  224.       @skill_equip_window.show if !@skill_equip_window.visible
  225.       @item_window.hide if @item_window.visible
  226.       @stype_window.hide if @stype_window.visible
  227.       @passive_window.hide if @passive_window.visible
  228.     when Quasi::STypeEquip::NAME
  229.       @stype_window.show if !@stype_window.visible
  230.       @skill_equip_window.hide if @skill_equip_window.visible
  231.       @item_window.hide if @item_window.visible
  232.       @passive_window.hide if @passive_window.visible
  233.     when Quasi::PassiveEquip::NAMEPASSIVE
  234.       @passive_window.show if !@passive_window.visible
  235.       @skill_equip_window.hide if @skill_equip_window.visible
  236.       @stype_window.hide if @stype_window.visible
  237.       @item_window.hide if @item_window.visible
  238.     else
  239.       @item_window.show if !@item_window.visible
  240.       @passive_window.hide if @passive_window.visible
  241.       @stype_window.hide if @stype_window.visible
  242.       @skill_equip_window.hide if @skill_equip_window.visible
  243.     end
  244.     return
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # * Create Command Window
  248.   # ** ALIAS **
  249.   #--------------------------------------------------------------------------
  250.   def create_command_window
  251.     qepccw
  252.     @command_window.set_handler(:passive,   method(:command_passive))
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * Create Skill type Window
  256.   # ** ALIAS **
  257.   #--------------------------------------------------------------------------
  258.   def create_item_window
  259.     qepciw
  260.     create_passive_window
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # * Create Passive Window
  264.   # ** NEW **
  265.   #--------------------------------------------------------------------------
  266.   def create_passive_window
  267.     wx = @item_window.x
  268.     wy = @item_window.y
  269.     ww = @item_window.width
  270.     wh = @item_window.height
  271.     @passive_window = Window_PassiveList.new(wx, wy, ww, wh)
  272.     @passive_window.actor = @actor
  273.     @passive_window.viewport = @viewport
  274.     @passive_window.help_window = @help_window
  275.     @passive_window.set_handler(:ok,     method(:on_passive_ok))
  276.     @passive_window.set_handler(:cancel, method(:on_passive_cancel))
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * Passive Command
  280.   # ** NEW **
  281.   #--------------------------------------------------------------------------
  282.   def command_passive
  283.     @passive_window.activate
  284.     @passive_window.select(0)
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # * Passive [OK]
  288.   # ** NEW **
  289.   #--------------------------------------------------------------------------
  290.   def on_passive_ok
  291.     if @passive_window.item
  292.       if @actor.equipped_passive.include?(@passive_window.item.id)
  293.         Sound.play_ok
  294.         @actor.forget_passive(@passive_window.item.id) if $imported["Quasi_Passive"]
  295.         @actor.remove_fixed_passive(@passive_window.item.id)  if $imported["Quasi_Fixed_Passive"]
  296.       else
  297.         if @actor.equipped_passive.size >= @actor.passive_slots
  298.           Sound.play_buzzer
  299.         else
  300.           Sound.play_ok
  301.           @actor.equipped_passive.push(@passive_window.item.id)
  302.           @actor.learn_passive(@passive_window.item.id)  if $imported["Quasi_Passive"]
  303.           @actor.add_fixed_passive(@passive_window.item.id) if $imported["Quasi_Fixed_Passive"]
  304.         end
  305.       end
  306.     end
  307.     @status_window.refresh
  308.     @passive_window.refresh
  309.     @passive_window.activate
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # * Passive [Cancel]
  313.   # ** NEW **
  314.   #--------------------------------------------------------------------------
  315.   def on_passive_cancel
  316.     @passive_window.unselect
  317.     @command_window.activate
  318.   end
  319. end
  320.  
  321. #==============================================================================
  322. # ** Window_SkillCommand
  323. #------------------------------------------------------------------------------
  324. #  This window is for selecting commands (special attacks, magic, etc.) on the
  325. # skill screen.
  326. #==============================================================================
  327. class Window_SkillCommand < Window_Command
  328.   alias qpemcl make_command_list
  329.   #--------------------------------------------------------------------------
  330.   # * Create Command List
  331.   # ** REWRITE **
  332.   #--------------------------------------------------------------------------
  333.   def make_command_list
  334.     add_command(Quasi::PassiveEquip::NAMEPASSIVE, :passive, true)
  335.     qpemcl
  336.   end
  337. end
  338.  
  339. #==============================================================================
  340. # ** Window_PassiveList (NEW)
  341. #------------------------------------------------------------------------------
  342. #  This window is for displaying a list of available passive skills
  343. #  on the skill window.
  344. #==============================================================================
  345.  
  346. class Window_PassiveList < Window_Selectable
  347.   #--------------------------------------------------------------------------
  348.   # * Object Initialization
  349.   #--------------------------------------------------------------------------
  350.   def initialize(x, y, width, height)
  351.     super
  352.     @actor = nil
  353.     @data = []
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Set Actor
  357.   #--------------------------------------------------------------------------
  358.   def actor=(actor)
  359.     return if @actor == actor
  360.     @actor = actor
  361.     refresh
  362.     self.oy = 0
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * Get Digit Count
  366.   #--------------------------------------------------------------------------
  367.   def col_max
  368.     return 2
  369.   end
  370.   #--------------------------------------------------------------------------
  371.   # * Get Number of Items
  372.   #--------------------------------------------------------------------------
  373.   def item_max
  374.     @data ? @data.size : 1
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # * Get Skill
  378.   #--------------------------------------------------------------------------
  379.   def item
  380.     @data && index >= 0 ? @data[index] : nil
  381.   end
  382.   #--------------------------------------------------------------------------
  383.   # * Processing When OK Button Is Pressed
  384.   #--------------------------------------------------------------------------
  385.   def process_ok
  386.     Input.update
  387.     deactivate
  388.     call_ok_handler
  389.   end
  390.   #--------------------------------------------------------------------------
  391.   # * Restore Previous Selection Position
  392.   #--------------------------------------------------------------------------
  393.   def select_last
  394.   end
  395.   #--------------------------------------------------------------------------
  396.   # * Create Skill List
  397.   #--------------------------------------------------------------------------
  398.   def make_item_list
  399.     return if !@actor
  400.     @data = []
  401.     @actor.skills.each do |skill|
  402.       if $imported["Quasi_Passive"] && $imported["Quasi_Fixed_Passive"]
  403.         next unless skill.passive || skill.quasi_passive
  404.       elsif $imported["Quasi_Passive"]
  405.         next unless skill.passive
  406.       elsif $imported["Quasi_Fixed_Passive"]
  407.         next unless skill.quasi_passive
  408.       end
  409.       @data.push(skill)
  410.     end
  411.   end
  412.   #--------------------------------------------------------------------------
  413.   # * Draw Item
  414.   #--------------------------------------------------------------------------
  415.   def draw_item(index)
  416.     skill = @data[index]
  417.     if skill
  418.       rect = item_rect(index)
  419.       rect.width -= 4
  420.       enable = @actor.equipped_passive.include?(skill.id)
  421.       draw_item_name(skill, rect.x, rect.y, enable)
  422.     end
  423.   end
  424.   #--------------------------------------------------------------------------
  425.   # * Update Help Text
  426.   #--------------------------------------------------------------------------
  427.   def update_help
  428.     text = item ? item.description : ""
  429.     pl = @actor.equipped_passive.size
  430.     pt = @actor.passive_slots
  431.     text += "\n#{Quasi::PassiveEquip::HELP}: #{pl}/#{pt}"
  432.     @help_window.set_text(text)
  433.   end
  434.   #--------------------------------------------------------------------------
  435.   # * Refresh
  436.   #--------------------------------------------------------------------------
  437.   def refresh
  438.     make_item_list
  439.     create_contents
  440.     draw_all_items
  441.   end
  442. end
  443.  
  444. #==============================================================================
  445. # ** RPG::BaseItem
  446. #==============================================================================
  447. class RPG::BaseItem
  448.   def passive_slots
  449.     if @passive_slots.nil?
  450.       if @note =~ /<(?:passive_slots):(.*)>/i
  451.         @passive_slots = $1.to_i
  452.       else
  453.         @passive_slots = 0
  454.       end
  455.     end
  456.     @passive_slots
  457.   end
  458. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement