Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #======================#
- # Z-Systems by: Zetu #
- #===========================#======================#===========================#
- # * * * Aggro System v1.01 * * * #
- #=#==========================================================================#=#
- # OVERWRITES #
- # Game_Enemy::make_action #
- # Game_Interpretor::command_339 #
- # SEMI-OVERWRITES #
- # Game_BattleAction::decide_random_target #
- #--------------------------------------------------------------------------#
- # Introduction: What is Aggro? #
- # Aggro (or Aggression) is a statistical value that helps determine the #
- # percent chance an enemy will attack a specific actor. #
- # What is this good for? #
- # In many RPGs, there are strong characters that can take a hit, also #
- # called "Tanks", and weaker ones that cannot take much damage. By #
- # manipulating these statistical values, you can control which actors #
- # will take damage, and which ones will not. #
- # How to increase Aggro? #
- # In this system, Aggro can be gained/lost by Attacks, Skills, and by #
- # guarding. The default values are defined by the module below. Inside #
- # note tags of skills, you may add tags to change its default amount. #
- # #
- # <aggro: X> #
- # Increases aggro by a rating of X. Keep this value between #
- # 0.0 and 1 OR 0 and 100. Does not perfectly increase aggro by the #
- # amount given. #
- # <pro aggro: X> #
- # This sets aggro to an amount, reducing all other aggro to match. Only #
- # use in hard aggro skills, such as a provoke (gain all aggro) or fade #
- # (remove all aggro). This tag is still in testing and not guarenteed #
- # to be bug free. #
- #--------------------------------------------------------------------------#
- # Version History: #
- # v1.01 ALPHA (Please Report all bugs related to this script) #
- #--------------------------------------------------------------------------#
- # * * * FOR SCRIPTERS WANTING TO CREATE A HUD! * * * #
- # The aggro values are stored in $scene.aggro and is a two dimensional #
- # array. @aggro[enemy.index][actor.index] returns the percent value of #
- # aggro, and will be between 0.0 and 1.0. #
- #==========================================================================#
- module Z_Systems
- module Aggro
- NORMAL_ATTACK = 0.06
- SKILL_DEFAULT = 0.06
- GUARD = -0.06
- end
- end
- #========#======================#====#================================#========#
- #--------# #----# DO NOT EDIT PAST THIS POINT!!! #--------#
- #--------# End of Customization #----# Editing will cause death by #--------#
- #--------# #----# brain asplosions. #--------#
- #========#======================#====#================================#========#
- class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end
- class Scene_Battle < Scene_Base
- alias zs_aggro_start start
- def start
- zs_aggro_start
- @aggro = []
- for e in 0...$game_troop.members.size
- array = []
- for actor in $game_party.members
- array.push(1.0/$game_party.members.size)
- end
- @aggro[e] = array
- end
- end
- def aggro
- return @aggro
- end
- def normalize_aggro
- for e in 0...$game_troop.members.size
- value = @aggro[e].sum
- for a in 0...$game_party.members.size
- @aggro[e][a] /= value
- end
- end
- end
- def inc_aggro(e, a, value)
- return if $game_party.members.size <= 1
- @aggro[e][a] += value
- @aggro[e][a] = [[@aggro[e][a], 0.0].max, 1.0].min
- return if @aggro[e][a] == 1.0
- div = (@aggro[e].sum - @aggro[e][a])/(1.0-@aggro[e][a])
- for aindex in 0...$game_party.members.size
- unless a == aindex
- @aggro[e][aindex] /= div
- end
- end
- end
- def set_aggro(e, a, value)
- return if $game_party.members.size <= 1
- @aggro[e][a] = value
- @aggro[e][a] = [[@aggro[e][a], 0.0].max, 1.0].min
- if @aggro[e][a] == 1.0
- for aindex in 0...$game_party.members.size
- unless a == aindex
- @aggro[e][aindex] = 0
- end
- end
- else
- div = (@aggro[e].sum - @aggro[e][a])/(1.0-@aggro[e][a])
- for aindex in 0...$game_party.members.size
- unless a == aindex
- @aggro[e][aindex] /= div
- end
- end
- end
- end
- alias zs_aggro_execute_action_attack execute_action_attack
- def execute_action_attack
- zs_aggro_execute_action_attack
- return if @active_battler.action.make_targets[0].actor?
- for target in @active_battler.action.make_targets
- inc_aggro(target.index, @active_battler.index, Z_Systems::Aggro::NORMAL_ATTACK)
- end
- normalize_aggro
- end
- alias zs_aggro_execute_action_skill execute_action_skill
- def execute_action_skill
- zs_aggro_execute_action_skill
- return if @active_battler.action.make_targets[0].actor?
- value = Z_Systems::Aggro::SKILL_DEFAULT
- for line in @active_battler.action.skill.note.split(//)
- case line
- when /<aggro:[ ](.*)>/i
- value = $1.to_f
- if value > 1.0
- value /= 100.0
- end
- for target in @active_battler.action.make_targets
- inc_aggro(target.index, @active_battler.index, value)
- end
- return
- when /<pro[ ][_]aggro:[ ](.*)>/i
- value = $1.to_f
- if value > 1.0
- value /= 100.0
- end
- for target in @active_battler.action.make_targets
- set_aggro(target.index, @active_battler.index, value)
- end
- return
- end
- end
- for target in @active_battler.action.make_targets
- inc_aggro(target.index, @active_battler.index, value)
- end
- end
- alias zs_aggro_execute_action_guard execute_action_guard
- def execute_action_guard
- zs_aggro_execute_action_guard
- for enemy in $game_troop.members
- inc_aggro(enemy.index, @active_battler.index, Z_Systems::Aggro::GUARD)
- end
- normalize_aggro
- end
- end
- class Game_Unit
- def random_target_aggro(enemy)
- $scene.normalize_aggro
- rref = rand(101).to_f/100.0
- #~ print $scene.aggro[enemy.index].inspect
- for a in 0...$game_party.members.size
- if rref <= $scene.aggro[enemy.index][0..a].sum and !$game_party.members[a].dead?
- #~ print $scene.aggro[enemy.index][0..a].inspect
- return $game_party.members[a]
- end
- end
- return random_target_aggro(enemy)
- end
- end
- class Game_BattleAction
- alias zs_aggro_decide_random_target decide_random_target
- def decide_random_target(attacker = nil) #SEMI-OVERWRITE
- if !friends_unit.members[0].actor? or attacker != nil
- if for_friend?
- target = friends_unit.random_target
- elsif for_dead_friend?
- target = friends_unit.random_dead_target
- else
- target = opponents_unit.random_target_aggro(attacker)
- end
- if target == nil
- clear
- else
- @target_index = target.index
- end
- else
- zs_aggro_decide_random_target
- end
- end
- end
- class Game_Enemy < Game_Battler
- def make_action
- @action.clear
- return unless movable?
- available_actions = []
- rating_max = 0
- for action in enemy.actions
- next unless conditions_met?(action)
- if action.kind == 1
- next unless skill_can_use?($data_skills[action.skill_id])
- end
- available_actions.push(action)
- rating_max = [rating_max, action.rating].max
- end
- ratings_total = 0
- rating_zero = rating_max - 3
- for action in available_actions
- next if action.rating <= rating_zero
- ratings_total += action.rating - rating_zero
- end
- return if ratings_total == 0
- value = rand(ratings_total)
- for action in available_actions
- next if action.rating <= rating_zero
- if value < action.rating - rating_zero
- @action.kind = action.kind
- @action.basic = action.basic
- @action.skill_id = action.skill_id
- @action.decide_random_target(self)
- return
- else
- value -= action.rating - rating_zero
- end
- end
- end
- end
- class Game_Interpretor
- def command_339
- iterate_battler(@params[0], @params[1]) do |battler|
- next unless battler.exist?
- battler.action.kind = @params[2]
- if battler.action.kind == 0
- battler.action.basic = @params[3]
- else
- battler.action.skill_id = @params[3]
- end
- if @params[4] == -2 # Last target
- battler.action.decide_last_target
- elsif @params[4] == -1 # Random
- battler.action.decide_random_target(battler)
- elsif @params[4] >= 0 # Index designation
- battler.action.target_index = @params[4]
- end
- battler.action.forcing = true
- $game_troop.forcing_battler = battler
- @index += 1
- return false
- end
- return true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement