Advertisement
Vlue

Threat System

Mar 28th, 2015
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.01 KB | None | 0 0
  1. # Threat System v1.1
  2. #----------#
  3. #Features: Make enemies target the the most threatening person!
  4. #           Damage dealt/health restore adds to a actors threat level, while
  5. #           certain note tags can make skills/items modify threat levels.
  6. #
  7. #Usage:   Skill/Item Notetags: (Effects user)
  8. #           <THREAT_CLEAR>      - reduces threat to 0
  9. #           <THREAT_FULL>       - changes threat to highest + 1
  10. #           <THREAT_ADD value>  - adds value to threat
  11. #           <THREAT_SUB value>  - subtracts value from threat
  12. #           <THREAT_MUL float>  - multiplies threat by value
  13. #           <THREAT_DIV float>  - divides threat by value
  14. #
  15. #             value = whole number ( 1 ), float = decimal number ( 1.0 )
  16. #
  17. #         Actor/Class/Equip/State Notetags: (affect amount of threat added)
  18. #           <THREAD_MOD value>
  19. #          A value of 50 would increase the threat added by all abilities by 50%
  20. #           and a value of -50 would be a reduction of 50% in threat.
  21. #          The mod value stacks with actor, class, and all equips.
  22. #
  23. #
  24. #~ #----------#
  25. #-- Script by: V.M of D.T
  26. #
  27. #- Questions or comments can be:
  28. #    given by email: sumptuaryspade@live.ca
  29. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  30. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  31. #
  32. #--- Free to use in any project, commercial or non-commercial, with credit given
  33. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  34.  
  35. class Game_BattlerBase
  36.   attr_accessor :threat
  37.   alias threat_init initialize
  38.   def initialize(*args)
  39.     threat_init(*args)
  40.     @threat = starting_threat
  41.   end
  42.   def add_threat(amount)
  43.     @threat += amount * threat_modifier
  44.   end
  45.   def sub_threat(amount)
  46.     @threat -= amount
  47.   end
  48.   def div_threat(amount)
  49.     @threat /= amount
  50.   end
  51.   def mul_threat(amount)
  52.     @threat *= amount
  53.   end
  54.   def clear_threat
  55.     @threat = 0
  56.   end
  57.   def starting_threat
  58.     0
  59.   end
  60.   def threat_modifier
  61.     1
  62.   end
  63.   def skill_threat(item)
  64.   end
  65.   def full_threat
  66.   end
  67. end
  68.  
  69. class Game_Actor
  70.   def threat_modifier
  71.     mod = 100
  72.     mod *= self.class.threat_mod
  73.     mod *= actor.threat_mod
  74.     @equips.each do |equip|
  75.       next unless equip.object
  76.       mod *= equip.object.threat_mod
  77.     end
  78.     states.each do |state|
  79.       mod *= state.threat_mod
  80.     end
  81.     mod / 100
  82.   end
  83.   def skill_threat(item)
  84.     full_threat if item.full_threat?
  85.     div_threat(item.div_threat?) if item.div_threat?
  86.     mul_threat(item.mul_threat?) if item.mul_threat?
  87.     sub_threat(item.sub_threat?) if item.sub_threat?
  88.     add_threat(item.add_threat?) if item.add_threat?
  89.     clear_threat if item.clear_threat?
  90.   end
  91.   def full_threat
  92.     $game_party.members.each do |actor|
  93.       @threat = [actor.threat, @threat].max
  94.     end
  95.     @threat += 1
  96.   end
  97. end
  98.  
  99. class RPG::UsableItem
  100.   def clear_threat?
  101.     self.note =~ /<THREAT_CLEAR>/ ? true : false
  102.   end
  103.   def full_threat?
  104.     self.note =~ /<THREAT_FULL>/ ? true : false
  105.   end
  106.   def add_threat?
  107.     self.note =~ /<THREAT_ADD (\d+)>/ ? $1.to_i : false
  108.   end
  109.   def sub_threat?
  110.     self.note =~ /<THREAT_SUB (\d+)>/ ? $1.to_i : false
  111.   end
  112.   def mul_threat?
  113.     self.note =~ /<THREAT_MUL (\d+\.\d)>/ ? $1.to_i : false
  114.   end
  115.   def div_threat?
  116.     self.note =~ /<THREAT_DIV (\d+\.\d)>/ ? $1.to_i : false
  117.   end
  118. end
  119.  
  120.  
  121. class RPG::BaseItem
  122.   def threat_mod
  123.     self.note =~ /<THREAT_MOD (\d+|-\d+)>/ ? 1 + ($1.to_f / 100) : 1
  124.   end
  125. end
  126.  
  127. class Game_Unit
  128.   def random_target
  129.     alive_members.sort { |a,b| b.threat <=> a.threat }[0]
  130.   end
  131. end
  132.  
  133. class Game_Battler
  134.   alias threat_ed execute_damage
  135.   alias threat_obs on_battle_start
  136.   alias threat_iue item_user_effect
  137.   def execute_damage(user)
  138.     threat_ed(user)
  139.     user.add_threat(@result.hp_damage.abs)
  140.   end
  141.   def on_battle_start
  142.     threat_obs
  143.     @threat = starting_threat
  144.   end
  145.   def item_user_effect(user, item)
  146.     threat_iue(user, item)
  147.     user.skill_threat(item)
  148.   end
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement