Advertisement
roninator2

Yanfly Weapon Attack Replace addon

Dec 8th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.57 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Weapon Attack Replace Mod    ║  Version: 1.01     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║ Add on function to Yanfly's script  ║    18 Jan 2022     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Requires: Yanfly - Weapon Attack Replace                 ║
  11. # ╚══════════════════════════════════════════════════════════╝
  12. # ╔══════════════════════════════════════════════════════════╗
  13. # ║ Instructions: Put below Yanfly's script                  ║
  14. # ║                                                          ║
  15. # ║ Adds options to select a random skill in either          ║
  16. # ║ A range or from the list created in the note tags        ║
  17. # ║                                                          ║
  18. # ║ Also has the option to change the skill tp/mp cost       ║
  19. # ║ But will not change it if the skill tp/mp cost is lower  ║
  20. # ║ Does not have an affect on selecting skills              ║
  21. # ║ If the actor does not have enough TP/MP to start with    ║
  22. # ║ then the skill will not be selected.                     ║
  23. # ║                                                          ║
  24. # ║ Skill Range:                                             ║
  25. # ║   <skill range: 5, 9>                                    ║
  26. # ║    first skill, to last skill                            ║
  27. # ║   a random one will be picked (5, 6, 7, 8, 9)            ║
  28. # ║                                                          ║
  29. # ║ Skill List:                                              ║
  30. # ║   <skill list: 4, 8, 12, 22>                             ║
  31. # ║   Randomly select one of the skills in the list          ║
  32. # ║                                                          ║
  33. # ║ Skill TP Cost:                                           ║
  34. # ║   <skill tp: 5>                                          ║
  35. # ║   will set the new skill used 5 tp cost                  ║
  36. # ║   if the actor does not have enough tp or the skill tp   ║
  37. # ║   cost is lower, this will not have any effect           ║
  38. # ║                                                          ║
  39. # ║ Skill MP Cost:                                           ║
  40. # ║   <skill mp: 5>                                          ║
  41. # ║   will set the new skill used 5 mp cost                  ║
  42. # ║   if the actor does not have enough mp or the skill mp   ║
  43. # ║   cost is lower, this will not have any effect           ║
  44. # ╚══════════════════════════════════════════════════════════╝
  45. # ╔══════════════════════════════════════════════════════════╗
  46. # ║ Updates:                                                 ║
  47. # ║ 1.00 - 18 Jan 2022 - Initial publish                     ║
  48. # ╚══════════════════════════════════════════════════════════╝
  49. # ╔══════════════════════════════════════════════════════════╗
  50. # ║ Terms of use:                                            ║
  51. # ║ Follow the Original Authors terms                        ║
  52. # ╚══════════════════════════════════════════════════════════╝
  53.  
  54. module YEA
  55.   module REGEXP
  56.   module BASEITEM
  57.    
  58.     SKILL_RANGE = /<(?:SKILL_RANGE|skill range):[ ](\d+),[ ](\d+)>/i
  59.     SKILL_LIST = /<(?:SKILL_LIST|skill list):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  60.     SKILL_TP = /<(?:SKILL_TP|skill tp):[ ](\d+)>/i
  61.     SKILL_MP = /<(?:SKILL_MP|skill mp):[ ](\d+)>/i
  62.    
  63.   end # BASEITEM
  64.   module WEAPON
  65.    
  66.     SKILL_RANGE = /<(?:SKILL_RANGE|skill range):[ ](\d+),[ ](\d+)>/i
  67.     SKILL_LIST = /<(?:SKILL_LIST|skill list):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  68.     SKILL_TP = /<(?:SKILL_TP|skill tp):[ ](\d+)>/i
  69.     SKILL_MP = /<(?:SKILL_MP|skill mp):[ ](\d+)>/i
  70.    
  71.   end # WEAPON
  72.   end # REGEXP
  73. end # YEA
  74. class RPG::BaseItem
  75.  
  76.   #--------------------------------------------------------------------------
  77.   # public instance variables
  78.   #--------------------------------------------------------------------------
  79.   attr_accessor :skill_range_start
  80.   attr_accessor :skill_range_end
  81.   attr_accessor :skill_list_pick
  82.   attr_accessor :skill_tp_r2
  83.   attr_accessor :skill_mp_r2
  84.  
  85.   #--------------------------------------------------------------------------
  86.   # common cache: load_notetags_war
  87.   #--------------------------------------------------------------------------
  88.   alias r2_load_war_92347fhb  load_notetags_war
  89.   def load_notetags_war
  90.     #---
  91.     self.note.split(/[\r\n]+/).each { |line|
  92.       case line
  93.       #---
  94.       when YEA::REGEXP::BASEITEM::SKILL_RANGE
  95.         @skill_range_start = $1.to_i
  96.         @skill_range_end = $2.to_i
  97.       when YEA::REGEXP::BASEITEM::SKILL_LIST
  98.         list = $1
  99.         change = list.split(",")
  100.         @skill_list_pick = change.map(&:to_i)
  101.       when YEA::REGEXP::BASEITEM::SKILL_TP
  102.         @skill_tp_r2 = $1.to_i
  103.       when YEA::REGEXP::BASEITEM::SKILL_MP
  104.         @skill_mp_r2 = $1.to_i
  105.       #---
  106.       end
  107.     } # self.note.split
  108.     #---
  109.     r2_load_war_92347fhb
  110.   end
  111.  
  112. end # RPG::BaseItem
  113. class RPG::Weapon < RPG::EquipItem
  114.  
  115.   #--------------------------------------------------------------------------
  116.   # public instance variables
  117.   #--------------------------------------------------------------------------
  118.   attr_accessor :skill_range_start
  119.   attr_accessor :skill_range_end
  120.   attr_accessor :skill_list_pick
  121.   attr_accessor :skill_tp_r2
  122.   attr_accessor :skill_mp_r2
  123.  
  124.   #--------------------------------------------------------------------------
  125.   # common cache: load_notetags_war
  126.   #--------------------------------------------------------------------------
  127.   alias r2_load_notetags_war_9237u4bv   load_notetags_war
  128.   def load_notetags_war
  129.     #---
  130.     self.note.split(/[\r\n]+/).each { |line|
  131.       case line
  132.       #---
  133.       when YEA::REGEXP::BASEITEM::SKILL_RANGE
  134.         @skill_range_start = $1.to_i
  135.         @skill_range_end = $2.to_i
  136.       when YEA::REGEXP::BASEITEM::SKILL_LIST
  137.         list = $1
  138.         change = list.split(",")
  139.         @skill_list_pick = change.map(&:to_i)
  140.       when YEA::REGEXP::BASEITEM::SKILL_TP
  141.         @skill_tp_r2 = $1.to_i
  142.       when YEA::REGEXP::BASEITEM::SKILL_MP
  143.         @skill_mp_r2 = $1.to_i
  144.       #---
  145.       end
  146.     } # self.note.split
  147.     r2_load_notetags_war_9237u4bv
  148.     #---
  149.   end
  150.  
  151. end # RPG::Weapon
  152. class Game_BattlerBase
  153.  
  154.   #--------------------------------------------------------------------------
  155.   # new method: set_skill_tp_replace
  156.   #--------------------------------------------------------------------------
  157.   def set_skill_tp_replace
  158.     tp = skill_tp_replace if actor?
  159.     return tp
  160.   end
  161.  
  162.   #--------------------------------------------------------------------------
  163.   # new method: set_skill_mp_replace
  164.   #--------------------------------------------------------------------------
  165.   def set_skill_mp_replace
  166.     mp = skill_mp_replace if actor?
  167.     return mp
  168.   end
  169.  
  170.   #--------------------------------------------------------------------------
  171.   # overwrite method: attack_skill_id
  172.   #--------------------------------------------------------------------------
  173.   def attack_skill_id
  174.     skill = weapon_attack_skill_id if actor?
  175.     range = weapon_range_attack_id if actor?
  176.     sklist = weapon_list_skill_id if actor?
  177.     attack = sklist.nil? ? (range.nil? ? (skill.nil? ? nil : skill) : range) : sklist
  178.     if actor?
  179.       skl = attack if !attack.nil? && (attack > 0)
  180.       player = $game_actors[actor.id]
  181.       skltp = $data_skills[attack]
  182.       return skl if player.tp > skltp.tp_cost
  183.     end
  184.     return YEA::WEAPON_ATTACK_REPLACE::DEFAULT_ATTACK_SKILL_ID
  185.   end
  186.  
  187. end # Game_BattlerBase
  188. class Game_Actor < Game_Battler
  189.   attr_accessor :skill_range_r2
  190.   attr_accessor :skill_list_r2
  191.  
  192.   #--------------------------------------------------------------------------
  193.   # new method: skill_tp_replace
  194.   #--------------------------------------------------------------------------
  195.   def skill_tp_replace
  196.     for weapon in weapons
  197.       next if weapon.nil?
  198.       tp = weapon.skill_tp_r2
  199.       return tp if !tp.nil?
  200.       return nil
  201.     end
  202.   end
  203.  
  204.   #--------------------------------------------------------------------------
  205.   # new method: skill_mp_replace
  206.   #--------------------------------------------------------------------------
  207.   def skill_mp_replace
  208.     for weapon in weapons
  209.       next if weapon.nil?
  210.       mp = weapon.skill_mp_r2
  211.       return mp if !mp.nil?
  212.       return nil
  213.     end
  214.   end
  215.  
  216.   #--------------------------------------------------------------------------
  217.   # new method: weapon_list_skill_id
  218.   #--------------------------------------------------------------------------
  219.   def weapon_list_skill_id
  220.     @skill_list_r2 = false
  221.     for weapon in weapons
  222.       next if weapon.nil?
  223.       sklist = weapon.skill_list_pick
  224.       @skill_list_r2 = true if !sklist.nil?
  225.       return nil if sklist.nil?
  226.       num = sklist.size - 1
  227.       pick = rand(num)
  228.       skill = sklist[pick]
  229.       return skill unless skill.nil?
  230.       return nil
  231.     end
  232.   end
  233.  
  234.   #--------------------------------------------------------------------------
  235.   # new method: weapon_range_attack_id
  236.   #--------------------------------------------------------------------------
  237.   def weapon_range_attack_id
  238.     @skill_range_r2 = false
  239.     for weapon in weapons
  240.       next if weapon.nil?
  241.       skstart = weapon.skill_range_start
  242.       skend = weapon.skill_range_end
  243.       skrange = skend.to_i - skstart.to_i
  244.       sksel = rand(skrange) + skstart.to_i
  245.       @skill_range_r2 = true if !sksel.nil?
  246.       return sksel unless sksel.nil?
  247.       return nil
  248.     end
  249.   end
  250.  
  251. end # Game_Actor
  252.  
  253. class Scene_Battle < Scene_Base
  254.  
  255.   #--------------------------------------------------------------------------
  256.   # overwrite method: command_attack
  257.   #--------------------------------------------------------------------------
  258.   def command_attack
  259.     @skill = $data_skills[BattleManager.actor.attack_skill_id]
  260.     tp = BattleManager.actor.set_skill_tp_replace
  261.     mp = BattleManager.actor.set_skill_mp_replace
  262.     @skill.tp_cost = tp if !tp.nil? && (BattleManager.actor.tp > tp) &&
  263.     (@skill.tp_cost > tp) && (BattleManager.actor.skill_range_r2 == true ||
  264.     BattleManager.actor.skill_list_r2 == true)
  265.     @skill.mp_cost = mp if !mp.nil? && (BattleManager.actor.mp > mp) &&
  266.     (@skill.mp_cost > mp) && (BattleManager.actor.skill_range_r2 == true ||
  267.     BattleManager.actor.skill_list_r2 == true)
  268.     BattleManager.actor.input.set_skill(@skill.id)
  269.     if $imported["YEA-BattleEngine"]
  270.       status_redraw_target(BattleManager.actor)
  271.       $game_temp.battle_aid = @skill
  272.       if @skill.for_opponent?
  273.         select_enemy_selection
  274.       elsif @skill.for_friend?
  275.         select_actor_selection
  276.       else
  277.         next_command
  278.         $game_temp.battle_aid = nil
  279.       end
  280.     else
  281.       if !@skill.need_selection?
  282.         next_command
  283.       elsif @skill.for_opponent?
  284.         select_enemy_selection
  285.       else
  286.         select_actor_selection
  287.       end
  288.     end
  289.   end
  290. end
  291.  
  292.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement