Advertisement
QuasiXi

Quasi Skill Type Equip

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