#=============================================================================== # # Yanfly Engine RD - Battler Stat Aggro # Last Date Updated: 2009.05.04 # Level: Normal # # For those who have played MMORPG's or certain RPG's, you may have noticed # something called aggro or hatred. Aggro and hatred causes the enemies to # target specific party members more depending on their actions. For instance, # if a healer casts "Cure" or "Life" on your party members, that healer will # become the target of follow up attacks from the enemies. RPG VX originally # lacks this type of statistic and it's a shame it does since this can help # create "better" enemy A.I. for your RPG's battles. # # This script uses a unique and lesser known stat in RPG VX called "odds" and # combines a new stat this script calls "aggro." Odds determines the chances of # random targetting selecting a particular individual. The new aggro stat is # merely an extension of the odds stat to keep odds intact with the way it's # originally supposed to be. # # In addition to the aggro stat, there is a more personal stat called "grudge" # included with this script. This works like aggro in a way where it causes the # monster to attack a particular actor but on a more individual basis. # #=============================================================================== # Updates: # ---------------------------------------------------------------------------- # o 2009.05.04 - Fixing return nil problems. # o 2009.04.18 - Improved REGEXP cache. # o 2009.04.14 - Compatibility update with KGC Guard Recover. # o 2009.04.12 - Bugfix and efficiency update. # o 2009.04.11 - Bugfix and now has standalone compatibility. # o 2009.04.10 - Added grudge stat. # o 2009.04.09 - Started script. #=============================================================================== # Instructions #=============================================================================== # # Input these tags into your skill's notebox. Different tags do different things # as listed below. If you decide to use more than one tag, the aggro value will # be modified through the order of operations starting with aggro_set first. # # where x is the exact value aggro will be set as. # where x is the value which aggro will multiply with. # where x is the value which aggro will divide by. # where x is the value which aggro will add to. # where x is the value which aggro will subtract from. # where x is the exact value grudge will be set as. # where x is the value which grudge will multiply with. # where x is the value which grudge will divide by. # where x is the value which grudge will add to. # where x is the value which grudge will subtract from. # # That said, change the values below in the module to reflect the setup you'd # wish for the aggro system to have in your own RPG. # #=============================================================================== # Notes #=============================================================================== # # If you're using the default battle system's script or similar, changes to any # party member's aggro doesn't reflect until next turn. Or rather, it takes # effect the current turn, but because targets are made before the turn starts, # the enemies don't react to new changes in aggro until the next turn starts. # # In case you're wondering what's the point of giving enemies an aggro stat, it # is because using random targetting skills will also base off of their aggro # statistic. Though, the way it works for enemies is a bit odd, no pun intended. # #=============================================================================== # # Compatibility # - Works With: YE Custom Skill Effects # - Works With: YE Custom Skill Properties # - Alias: Game_Actor, setup, odds # - Alias: Game_Battler, execute_damage # - Alias: Game_BattleAction, decide_random_target # - Alias: Game_Enemy, initialize, odds # - Alias: Scene_Battle, process_battle_start, execute_action # #=============================================================================== $imported = {} if $imported == nil $imported["BattlerStatAggro"] = true module YE module BATTLE module STAT # This is the default aggro value when starting a new character or if # you decide to reset aggro at the start of each battle. AGGRO_DEFAULT = 1 # This allows you to set what the maximum and minimum possible aggro # is for a character. AGGRO_MIN = 1 AGGRO_MAX = 100 # Reset aggro each battle? AGGRO_RESET = true # This sets whether or not skills and/or items can or cannot cause aggro. AGGRO_SKILL = true AGGRO_ITEM = false # This is the default grudge value when starting a new battle if the # enemy doesn't already hold a grudge against a character. GRUDGE_DEFAULT = 1 # This is the rate of growth every single time the actor damages the # enemy. Set to 0 if you don't want any growth. GRUDGE_GROWTH = 1 # This allows you to set what the maximum and minimum possible aggro # is for a character. GRUDGE_MIN = 1 GRUDGE_MAX = 100 end end # module BATTLE end # module YE #=============================================================================== # Editting anything past this point may potentially result in causing computer # damage, incontinence, explosion of user's head, coma, death, and/or halitosis. # Therefore, edit at your own risk. #=============================================================================== module YE module REGEXP module BASEITEM # Aggro set of tags. AGGRO_SET = /<(?:AGGRO_SET|aggro set)[ ]*(\d+)>/i AGGRO_ADD = /<(?:AGGRO_ADD|aggro add)[ ]*(\d+)>/i AGGRO_SUB = /<(?:AGGRO_SUB|aggro sub)[ ]*(\d+)>/i AGGRO_MUL = /<(?:AGGRO_MUL|aggro mul)[ ]*(\d+)>/i AGGRO_DIV = /<(?:AGGRO_DIV|aggro div)[ ]*(\d+)>/i # Grudge set of tags. GRUDGE_SET = /<(?:GRUDGE_SET|grudge set)[ ]*(\d+)>/i GRUDGE_ADD = /<(?:GRUDGE_ADD|grudge add)[ ]*(\d+)>/i GRUDGE_SUB = /<(?:GRUDGE_SUB|grudge sub)[ ]*(\d+)>/i GRUDGE_MUL = /<(?:GRUDGE_MUL|grudge mul)[ ]*(\d+)>/i GRUDGE_DIV = /<(?:GRUDGE_DIV|grudge div)[ ]*(\d+)>/i end end end #=============================================================================== # RPG::BaseItem #=============================================================================== class RPG::BaseItem #-------------------------------------------------------------------------- # Yanfly_Cache_BSA #-------------------------------------------------------------------------- def yanfly_cache_bsa @aggro_set = 0; @aggro_add = 0; @aggro_sub = 0; @aggro_mul = 0 @aggro_div = 0; @grudge_set = 0; @grudge_add = 0; @grudge_sub = 0 @grudge_mul = 0; @grudge_div = 0 self.note.split(/[\r\n]+/).each { |line| case line when YE::REGEXP::BASEITEM::AGGRO_SET @aggro_set = $1.to_i when YE::REGEXP::BASEITEM::AGGRO_ADD @aggro_add = $1.to_i when YE::REGEXP::BASEITEM::AGGRO_SUB @aggro_sub = $1.to_i when YE::REGEXP::BASEITEM::AGGRO_MUL @aggro_mul = $1.to_i when YE::REGEXP::BASEITEM::AGGRO_DIV @aggro_div = $1.to_i when YE::REGEXP::BASEITEM::GRUDGE_SET @grudge_set = $1.to_i when YE::REGEXP::BASEITEM::GRUDGE_ADD @grudge_add = $1.to_i when YE::REGEXP::BASEITEM::GRUDGE_SUB @grudge_sub = $1.to_i when YE::REGEXP::BASEITEM::GRUDGE_MUL @grudge_mul = $1.to_i when YE::REGEXP::BASEITEM::GRUDGE_DIV @grudge_div = $1.to_i end } end # end yanfly_cache_bsa #-------------------------------------------------------------------------- # aggro #-------------------------------------------------------------------------- def aggro_set yanfly_cache_bsa if @aggro_set == nil return @aggro_set end def aggro_add yanfly_cache_bsa if @aggro_add == nil return @aggro_add end def aggro_sub yanfly_cache_bsa if @aggro_sub == nil return @aggro_sub end def aggro_mul yanfly_cache_bsa if @aggro_mul == nil return @aggro_mul end def aggro_div yanfly_cache_bsa if @aggro_div == nil return @aggro_div end #-------------------------------------------------------------------------- # grudge #-------------------------------------------------------------------------- def grudge_set yanfly_cache_bsa if @grudge_set == nil return @grudge_set end def grudge_add yanfly_cache_bsa if @grudge_add == nil return @grudge_add end def grudge_sub yanfly_cache_bsa if @grudge_sub == nil return @grudge_sub end def grudge_mul yanfly_cache_bsa if @grudge_mul == nil return @grudge_mul end def grudge_div yanfly_cache_bsa if @grudge_div == nil return @grudge_div end end #RPG::BaseItem #=============================================================================== # Game_Actor #=============================================================================== class Game_Actor < Game_Battler #-------------------------------------------------------------------------- # alias setup #-------------------------------------------------------------------------- alias setup_aggro setup unless $@ def setup(actor_id) setup_aggro(actor_id) @aggro = YE::BATTLE::STAT::AGGRO_DEFAULT end #-------------------------------------------------------------------------- # alias odds #-------------------------------------------------------------------------- alias odds_aggro odds unless $@ def odds x = odds_aggro + @aggro if $aggrobattler.is_a?(Game_Enemy) and $aggrobattler != nil member = $aggrobattler zo = YE::BATTLE::STAT::GRUDGE_DEFAULT member.set_grudge(self.id, zo) if member.grudge (self.id) == nil x += member.grudge(self.id) end return x end #-------------------------------------------------------------------------- # aggro definitions #-------------------------------------------------------------------------- def aggro return @aggro end def aggro=(new_aggro) @aggro = new_aggro small = YE::BATTLE::STAT::AGGRO_MIN large = YE::BATTLE::STAT::AGGRO_MAX @aggro = [[@aggro, small].max, large].min end end # class Game_Actor #=============================================================================== # Game_Battler #=============================================================================== class Game_Battler #-------------------------------------------------------------------------- # grudge_setup #-------------------------------------------------------------------------- def grudge_setup @gl = {} for member in $game_party.members @gl[member.id] = YE::BATTLE::STAT::GRUDGE_DEFAULT end end #-------------------------------------------------------------------------- # grudge definitions #-------------------------------------------------------------------------- def grudge(actor_id) @gl[actor_id] = YE::BATTLE::STAT::GRUDGE_DEFAULT if @gl[actor_id] == nil return @gl[actor_id] end def set_grudge(actor, newgrudge) if actor.is_a?(Game_Actor) and self.is_a?(Game_Enemy) @gl[actor_id] = YE::BATTLE::STAT::GRUDGE_DEFAULT if @gl[actor_id] == nil @gl[actor.id] = newgrudge small = YE::BATTLE::STAT::GRUDGE_MIN large = YE::BATTLE::STAT::GRUDGE_MAX @gl[actor.id] = [[@gl[actor.id], small].max, large].min end end def add_grudge(actor, newgrudge) if actor.is_a?(Game_Actor) and self.is_a?(Game_Enemy) @gl[actor.id] = YE::BATTLE::STAT::GRUDGE_DEFAULT if @gl[actor.id] == nil @gl[actor.id] += newgrudge small = YE::BATTLE::STAT::GRUDGE_MIN large = YE::BATTLE::STAT::GRUDGE_MAX @gl[actor.id] = [[@gl[actor.id], small].max, large].min end end def sub_grudge(actor, newgrudge) if actor.is_a?(Game_Actor) and self.is_a?(Game_Enemy) @gl[actor.id] = YE::BATTLE::STAT::GRUDGE_DEFAULT if @gl[actor.id] == nil @gl[actor.id] -= newgrudge small = YE::BATTLE::STAT::GRUDGE_MIN large = YE::BATTLE::STAT::GRUDGE_MAX @gl[actor.id] = [[@gl[actor.id], small].max, large].min end end def mul_grudge(actor, newgrudge) if actor.is_a?(Game_Actor) and self.is_a?(Game_Enemy) @gl[actor.id] = YE::BATTLE::STAT::GRUDGE_DEFAULT if @gl[actor.id] == nil @gl[actor.id] *= newgrudge small = YE::BATTLE::STAT::GRUDGE_MIN large = YE::BATTLE::STAT::GRUDGE_MAX @gl[actor.id] = [[@gl[actor.id], small].max, large].min end end def div_grudge(actor, newgrudge) if actor.is_a?(Game_Actor) and self.is_a?(Game_Enemy) @gl[actor.id] = YE::BATTLE::STAT::GRUDGE_DEFAULT if @gl[actor.id] == nil @gl[actor.id] /= newgrudge small = YE::BATTLE::STAT::GRUDGE_MIN large = YE::BATTLE::STAT::GRUDGE_MAX @gl[actor.id] = [[@gl[actor.id], small].max, large].min end end #-------------------------------------------------------------------------- # alias execute_damage #-------------------------------------------------------------------------- alias execute_damage_aggro execute_damage unless $@ def execute_damage(user) if user != nil and user.action.kind == 1 obj = user.action.skill unless self.is_a?(Game_Actor) set_grudge(user, obj.grudge_set) if obj.grudge_set > 0 mul_grudge(user, obj.grudge_mul) if obj.grudge_mul > 0 div_grudge(user, obj.grudge_div) if obj.grudge_div > 0 add_grudge(user, obj.grudge_add) if obj.grudge_add > 0 sub_grudge(user, obj.grudge_sub) if obj.grudge_sub > 0 end end if @hp_damage > 0 add_grudge(user, YE::BATTLE::STAT::GRUDGE_GROWTH) end execute_damage_aggro(user) end end #=============================================================================== # Game_BattleAction #=============================================================================== class Game_BattleAction #-------------------------------------------------------------------------- # alias decide_random_target #-------------------------------------------------------------------------- alias decide_random_target_aggro decide_random_target unless $@ def decide_random_target $aggrobattler = battler decide_random_target_aggro end end #=============================================================================== # Game_Enemy #=============================================================================== class Game_Enemy < Game_Battler #-------------------------------------------------------------------------- # alias initialize #-------------------------------------------------------------------------- alias initialize_aggro initialize unless $@ def initialize(index, enemy_id) initialize_aggro(index, enemy_id) @aggro = YE::BATTLE::STAT::AGGRO_DEFAULT grudge_setup end #-------------------------------------------------------------------------- # alias odds #-------------------------------------------------------------------------- alias odds_aggro odds unless $@ def odds x = odds_aggro + @aggro return x end #-------------------------------------------------------------------------- # aggro definitions #-------------------------------------------------------------------------- def aggro return @aggro end def aggro=(new_aggro) @aggro = new_aggro small = YE::BATTLE::STAT::AGGRO_MIN large = YE::BATTLE::STAT::AGGRO_MAX @aggro = [[@aggro, small].max, large].min end end # class Game_Enemy #=============================================================================== # class Scene_Battle #=============================================================================== class Scene_Battle #-------------------------------------------------------------------------- # alias process_battle_start #-------------------------------------------------------------------------- alias process_battle_start_aggro process_battle_start unless $@ def process_battle_start if YE::BATTLE::STAT::AGGRO_RESET for actor in $game_party.members actor.aggro = YE::BATTLE::STAT::AGGRO_DEFAULT end end process_battle_start_aggro end #-------------------------------------------------------------------------- # alias execute_action #-------------------------------------------------------------------------- alias execute_action_aggro execute_action unless $@ def execute_action case @active_battler.action.kind when 1 obj = @active_battler.action.skill create_aggro(obj) if YE::BATTLE::STAT::AGGRO_SKILL when 2 obj = @active_battler.action.item create_aggro(obj) if YE::BATTLE::STAT::AGGRO_ITEM end execute_action_aggro end #-------------------------------------------------------------------------- # def create_aggro #-------------------------------------------------------------------------- def create_aggro(obj) @active_battler.aggro = obj.aggro_set if obj.aggro_set > 0 @active_battler.aggro *= obj.aggro_mul if obj.aggro_mul > 0 @active_battler.aggro /= obj.aggro_div if obj.aggro_div > 0 @active_battler.aggro += obj.aggro_add if obj.aggro_add > 0 @active_battler.aggro -= obj.aggro_sub if obj.aggro_sub > 0 end end #scene_battle #=============================================================================== # # END OF FILE # #===============================================================================