Advertisement
Fomar0153

Fomar0153 - Equipment Skills 1.1

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