Advertisement
Fomar0153

Fomar0153 - Weapon Master Class Class

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