Szyu

ThornSkills

Jul 26th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.45 KB | None | 0 0
  1. #==============================================================================
  2. # ** ThornSkills
  3. #
  4. # * Author:   Szyu
  5. # * Version:  1.0
  6. # * Pastebin: http://adf.ly/4920670/thornskills
  7. # * Description:
  8. #     Adds the ability to define thorn-effects, which trigger certain skills on
  9. #     damage, if specific state conditions are met.
  10. #
  11. # * Requirements:
  12. #   - Szyu's StateConditions
  13. #
  14. # * How To Use:
  15. #   "<thorn_skill: id>" in states notes where id represents the skill id
  16. #
  17. #==============================================================================
  18. $imported = {} if $imported.nil?
  19. $imported["Szyu_ThornSkills"] = true
  20. if $imported["Szyu_StateConditions"]
  21. #==============================================================================
  22. # ** Game_Battler
  23. #==============================================================================
  24. class Game_Battler < Game_BattlerBase
  25.   alias szstco_execute_damage execute_damage
  26.   #--------------------------------------------------------------------------
  27.   # * state_conditions_met
  28.   #--------------------------------------------------------------------------
  29.   def state_conditions_met(state_conditions, target)
  30.     state_conditions.each do |sid|
  31.       return false if not target.states.any?{|s| s.id == sid}
  32.     end
  33.     return true
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   # * actor_battle_index
  37.   #--------------------------------------------------------------------------
  38.   def actor_battle_index(actor_id)
  39.     return $game_party.battle_members.index{|a| a.id == actor_id}
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # * execute_damage
  43.   #--------------------------------------------------------------------------
  44.   def execute_damage(user)
  45.     szstco_execute_damage(user)
  46.     return if user == self
  47.     state_conditions = []
  48.     thorn_skills= []
  49.     states.select{|s| s!= nil }.each do |x|
  50.       if x.thorn_skill
  51.         state_conditions.concat(x.state_conditions) if x.state_conditions.size > 0
  52.         thorn_skills.concat(x.thorn_skill).uniq!
  53.       end
  54.     end
  55.     if state_conditions.size == 0 || state_conditions_met(state_conditions, self)
  56.       thorn_skills.each do |tsid|
  57.         action = Game_Action.new(self, true)
  58.         action.set_skill(tsid)
  59.         action.target_index = actor_battle_index(user.id) if user.is_a?(Game_Actor)
  60.         action.target_index = user.index if user.is_a?(Game_Enemy)
  61.         action.target_index = self.index if self.is_a?(Game_Enemy) && action.item.scope >= 7
  62.         action.target_index = actor_battle_index(self.id) if self.is_a?(Game_Actor) && action.item.scope >= 7
  63.         @actions.insert(0, action)
  64.       end
  65.     end
  66.   end
  67. end
  68.  
  69. #==============================================================================
  70. # ** Scene_Battle
  71. #==============================================================================
  72. class Scene_Battle < Scene_Base
  73.   alias szstco_process_action_end process_action_end
  74.   #--------------------------------------------------------------------------
  75.   # * process_action_end
  76.   #--------------------------------------------------------------------------
  77.   def process_action_end
  78.     if check_actors_thorns.size > 0
  79.       check_actors_thorns.each do |sub|
  80.         @subject = sub
  81.         @subject.actions.each do |act|
  82.           act.prepare
  83.           if act.valid?
  84.             @status_window.open
  85.             execute_action
  86.           end
  87.           @subject.remove_current_action
  88.         end
  89.       end
  90.     end
  91.     szstco_process_action_end
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # * check_actors_thorns
  95.   #--------------------------------------------------------------------------
  96.   def check_actors_thorns
  97.     return $game_party.battle_members.select{|a| a.dead? == false && a.actions.size > 0}
  98.   end
  99. end
  100.  
  101. #==============================================================================
  102. # ** RPG::State
  103. #==============================================================================
  104. class RPG::State < RPG::BaseItem
  105.   #--------------------------------------------------------------------------
  106.   # * thorn_skill
  107.   #--------------------------------------------------------------------------
  108.   def thorn_skill
  109.     ts = []
  110.     self.note.downcase.each_line do |line|
  111.       if line =~ /<thorn_skill:\s*(\d+)>/i
  112.         ts.push($1.to_i)
  113.       end
  114.     end
  115.     return ts.size > 0 ? ts : nil
  116.   end
  117. end
  118.  
  119. end
Add Comment
Please, Sign In to add comment