Advertisement
Fomar0153

Fomar0153 - Weapon Master Class 1.1

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