Advertisement
Fomar0153

Fomar0153 - Equipment Skills

Jan 10th, 2012
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.38 KB | None | 0 0
  1. =begin
  2. Equipment Skills System Script
  3. by Fomar0153
  4. Version 1.0
  5. ----------------------
  6. Notes
  7. ----------------------
  8. Requires an AP System if you want characters to
  9. learn skills pernamently.
  10. If using my Custom Equipment Slots script then
  11. make sure this script is above the Equipment Slots Script
  12. and make sure you have the compatability patch.
  13. Allows learning of skills by equipment with the
  14. option to learn skills pernamently.
  15. ----------------------
  16. Instructions
  17. ----------------------
  18. Set Learn_Skills to false if you want the skills to
  19. only be temporary.
  20. If you can learn skills then you need to set up AP for
  21. each skill you put on an item.
  22. In the notes section put:
  23. AP:n
  24. where n is the ap required to learn pernamently.
  25. Then follow the instructions below about how to add skills
  26. to weapons and armor.
  27. ----------------------
  28. Known bugs
  29. ----------------------
  30. None
  31. =end
  32.  
  33.  
  34. module Equipment_Skills
  35.  
  36.   # If set to false then characters will not
  37.   # learn the skills pernamently and you will
  38.   # not need an ap system
  39.   Learn_Skills = true
  40.  
  41.   Weapons = []
  42.   # Add weapon skills in this format
  43.   # Weapons[weapon_id] = [skillid1, skillid2]
  44.   Weapons[1] = [7,8]
  45.  
  46.   Armors = []
  47.   # Add weapon skills in this format
  48.   # Armors[armor_id] = [skillid1, skillid2]
  49.   Armors[3] = [5]
  50.  
  51.   def self.get_ap_cost(skill_id)
  52.     t = $data_skills[skill_id].note
  53.     if t.include?("AP:")
  54.       ap = /AP:(\d+)/.match(t)
  55.       ap = ap[0].split(":")
  56.       return ap[1].to_i
  57.     end
  58.     return 999
  59.   end
  60.  
  61. end
  62.  
  63. class Game_Actor < Game_Battler
  64.   attr_reader   :ap
  65.   #--------------------------------------------------------------------------
  66.   # ● Aliases setup
  67.   #--------------------------------------------------------------------------
  68.   alias eqskills_setup setup
  69.   def setup(actor_id)
  70.     eqskills_setup(actor_id)
  71.     if Equipment_Skills::Learn_Skills
  72.       @ap = []
  73.     end
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● Rewrites change_equip
  77.   #--------------------------------------------------------------------------
  78.   def change_equip(slot_id, item)
  79.     return unless trade_item_with_party(item, equips[slot_id])
  80.     if equips[slot_id].is_a?(RPG::Weapon)
  81.       unless Equipment_Skills::Weapons[equips[slot_id].id] == nil
  82.         for skill in Equipment_Skills::Weapons[equips[slot_id].id]
  83.           if Equipment_Skills::Learn_Skills
  84.             if @ap[skill] == nil
  85.               @ap[skill] = 0
  86.             end
  87.             unless @ap[skill] >= Equipment_Skills.get_ap_cost(skill)
  88.               forget_skill(skill)
  89.             end
  90.           else
  91.             forget_skill(skill)
  92.           end
  93.         end
  94.       end
  95.     end
  96.     if equips[slot_id].is_a?(RPG::Armor)
  97.       unless Equipment_Skills::Armors[equips[slot_id].id] == nil
  98.         for skill in Equipment_Skills::Armors[equips[slot_id].id]
  99.           if Equipment_Skills::Learn_Skills
  100.             if @ap[skill] == nil
  101.               @ap[skill] = 0
  102.             end
  103.             unless @ap[skill] >= Equipment_Skills.get_ap_cost(skill)
  104.               forget_skill(skill)
  105.             end
  106.           else
  107.             forget_skill(skill)
  108.           end
  109.         end
  110.       end
  111.     end
  112.     return if item && equip_slots[slot_id] != item.etype_id
  113.     @equips[slot_id].object = item
  114.     refresh
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● New Method or Rewrites gain_ap
  118.   #--------------------------------------------------------------------------
  119.   def gain_ap(ap)
  120.     if Equipment_Skills::Learn_Skills
  121.       for item in self.equips
  122.         if item.is_a?(RPG::Weapon)
  123.           unless Equipment_Skills::Weapons[item.id] == nil
  124.             for skill in Equipment_Skills::Weapons[item.id]
  125.               if @ap[skill] == nil
  126.                 @ap[skill] = 0
  127.               end
  128.               last_ap = @ap[skill]
  129.               @ap[skill] += ap
  130.               if last_ap < Equipment_Skills.get_ap_cost(skill) and Equipment_Skills.get_ap_cost(skill) <= @ap[skill]
  131.                 SceneManager.scene.add_message(actor.name + " learns " + $data_skills[skill].name + ".")
  132.               end
  133.             end
  134.           end
  135.         end
  136.         if item.is_a?(RPG::Armor)
  137.           unless Equipment_Skills::Armors[item.id] == nil
  138.             for skill in Equipment_Skills::Armors[item.id]
  139.               if @ap[skill] == nil
  140.                 @ap[skill] = 0
  141.               end
  142.               @ap[skill] += ap
  143.             end
  144.           end
  145.         end
  146.       end
  147.     end
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ● Aliases refresh
  151.   #--------------------------------------------------------------------------
  152.   alias eqskills_refresh refresh
  153.   def refresh
  154.     eqskills_refresh
  155.     for item in self.equips
  156.       if item.is_a?(RPG::Weapon)
  157.         unless Equipment_Skills::Weapons[item.id] == nil
  158.           for skill in Equipment_Skills::Weapons[item.id]
  159.             learn_skill(skill)
  160.           end
  161.         end
  162.       end
  163.       if item.is_a?(RPG::Armor)
  164.         unless Equipment_Skills::Armors[item.id] == nil
  165.           for skill in Equipment_Skills::Armors[item.id]
  166.             learn_skill(skill)
  167.           end
  168.         end
  169.       end
  170.     end
  171.     # relearn any class skills you may have forgotten
  172.     self.class.learnings.each do |learning|
  173.       learn_skill(learning.skill_id) if learning.level <= @level
  174.     end
  175.   end
  176. end
  177.  
  178.  
  179. class Window_EquipItem < Window_ItemList
  180.   #--------------------------------------------------------------------------
  181.   # ● Rewrites col_max
  182.   #--------------------------------------------------------------------------
  183.   def col_max
  184.     return 1
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ● Aliases update_help
  188.   #--------------------------------------------------------------------------
  189.   alias eqskills_update_help update_help
  190.   def update_help
  191.     eqskills_update_help
  192.     if @actor && @status_window
  193.       @status_window.refresh(item)
  194.     end
  195.   end
  196. end
  197.  
  198. class Scene_Equip < Scene_MenuBase
  199.   #--------------------------------------------------------------------------
  200.   # ● Rewrites create_item_window
  201.   #--------------------------------------------------------------------------
  202.   alias eqskills_create_item_window create_item_window
  203.   def create_item_window
  204.     wx = @status_window.width # Edited line if you need to merge
  205.     wy = @slot_window.y + @slot_window.height
  206.     ww = @slot_window.width  # Edited line if you need to merge
  207.     wh = Graphics.height - wy
  208.     @item_window = Window_EquipItem.new(wx, wy, ww, wh)
  209.     @item_window.viewport = @viewport
  210.     @item_window.help_window = @help_window
  211.     @item_window.status_window = @status_window
  212.     @item_window.actor = @actor
  213.     @item_window.set_handler(:ok,    method(:on_item_ok))
  214.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  215.     @slot_window.item_window = @item_window
  216.   end
  217. end
  218.  
  219.  
  220. class Window_EquipStatus < Window_Base
  221.   #--------------------------------------------------------------------------
  222.   # ● Rewrites window_height
  223.   #--------------------------------------------------------------------------
  224.   def window_height
  225.     Graphics.height - (2 * line_height + standard_padding * 2)#fitting_height(visible_line_number)
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # ● Aliases refresh
  229.   #--------------------------------------------------------------------------
  230.   alias eqskills_refresh refresh
  231.   def refresh(item = nil)
  232.     eqskills_refresh
  233.     contents.clear
  234.     draw_actor_name(@actor, 4, 0) if @actor
  235.     6.times {|i| draw_item(0, line_height * (1 + i), 2 + i) }
  236.       unless item == nil
  237.       if item.is_a?(RPG::Weapon)
  238.         unless Equipment_Skills::Weapons[item.id] == nil
  239.           skills = Equipment_Skills::Weapons[item.id]
  240.         end
  241.       end
  242.       if item.is_a?(RPG::Armor)
  243.         unless Equipment_Skills::Armors[item.id] == nil
  244.           skills = Equipment_Skills::Armors[item.id]
  245.         end
  246.       end
  247.       unless skills == nil
  248.         change_color(normal_color)
  249.         draw_text(4, 168, width, line_height, "Equipment Skills")
  250.         change_color(system_color)
  251.         i = 1
  252.         for skill in skills
  253.           draw_text(4, 168 + 24 * i, width, line_height, $data_skills[skill].name)
  254.           if @actor.ap[skill] == nil
  255.             @actor.ap[skill] = 0
  256.           end
  257.           i = i + 1
  258.           if Equipment_Skills::Learn_Skills
  259.             draw_current_and_max_values(4, 168 + 24 * i, width - 50, [@actor.ap[skill],Equipment_Skills.get_ap_cost(skill)].min, Equipment_Skills.get_ap_cost(skill), system_color, system_color)
  260.             i = i + 1
  261.           end
  262.         end
  263.       end
  264.     end
  265.   end
  266. end
  267.  
  268.  
  269. class Window_EquipSlot < Window_Selectable
  270.   #--------------------------------------------------------------------------
  271.   # ● Aliases update
  272.   #--------------------------------------------------------------------------
  273.   alias eqskills_update update
  274.   def update
  275.     eqskills_update
  276.     @status_window.refresh(self.item) if self.active == true
  277.   end
  278. end
  279.  
  280.  
  281. class Scene_Battle < Scene_Base
  282.   #--------------------------------------------------------------------------
  283.   # ● New method add_text
  284.   #--------------------------------------------------------------------------
  285.   def add_message(text)
  286.     $game_message.add('\.' + text)
  287.   end
  288. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement