#==============================================================================
# ** Animated Battlers - Enhanced ver. 7.7 (03-29-2007)
#
#------------------------------------------------------------------------------
# * (3) Sprite System: The Sprite Battler Class
#==============================================================================
#==============================================================================
# ** Sprite_Battler
#------------------------------------------------------------------------------
# This sprite is used to display the battler.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Battler < RPG::Sprite
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias mnk_update update
def update
return unless @battler
if @battler.battler_name != @battler_name
@started = false
end
# Regular Update
mnk_update
# Set Translucency
if @battler.is_a?(Game_Actor) and @battler_visible
if @translucent_actor.include?(@battler.id)
if @battler.hidden
self.opacity = 0
else
self.opacity = @translucency
end
end
end
if @battler.is_a?(Game_Enemy) and @battler_visible
if @translucent_enemy.include?(@battler.id)
if @battler.hidden
self.opacity = 0
else
self.opacity = @translucency
end
end
end
# Reset hash for Advanced Pose/Frames
pose_temp = {}
# Start Routine
unless @started
@pose = state
if @battler.is_a?(Game_Enemy)
if not $default_enemy
if $default_enemy_id == nil
# Set up Spritesheet Standards
frametmp = @frames
if @frames_enemy != nil
if @frames_enemy.include?(@battler.id)
frametmp = @frames_enemy[@battler.id] if @frames_enemy[@battler.id] != nil
end
end
@width = @width / frametmp
posetmp = @poses
if @poses_enemy != nil
if @poses_enemy.include?(@battler.id)
posetmp = @poses_enemy[@battler.id] if @poses_enemy[@battler.id] != nil
end
end
@height = @height / posetmp
else
if not $default_enemy_id.include?(@battler.id)
frametmp = @frames
if @frames_enemy != nil
if @frames_enemy.include?(@battler.id)
frametmp = @frames_enemy[@battler.id] if @frames_enemy[@battler.id] != nil
end
end
@width = @width / frametmp
posetmp = @poses
if @poses_enemy != nil
if @poses_enemy.include?(@battler.id)
posetmp = @poses_enemy[@battler.id] if @poses_enemy[@battler.id] != nil
end
end
@height = @height / posetmp
end
end
end
end
# Turn off Casting pose
@battler.casted = false
@battler.casting = false
if @battler.is_a?(Game_Actor)
if not $default_actor
if $default_actor_id == nil
# Set up Spritesheet Standards
frametmp = @frames
if @frames_actor != nil
if @frames_actor.include?(@battler.id)
frametmp = @frames_actor[@battler.id] if @frames_actor[@battler.id] != nil
end
end
@width = @width / frametmp
posetmp = @poses
if @poses_actor != nil
if @poses_actor.include?(@battler.id)
posetmp = @poses_actor[@battler.id] if @poses_actor[@battler.id] != nil
end
end
@height = @height / posetmp
else
if not $default_actor_id.include?(@battler.id)
frametmp = @frames
if @frames_actor != nil
if @frames_actor.include?(@battler.id)
frametmp = @frames_actor[@battler.id] if @frames_actor[@battler.id] != nil
end
end
@width = @width / frametmp
posetmp = @poses
if @poses_actor != nil
if @poses_actor.include?(@battler.id)
posetmp = @poses_actor[@battler.id] if @poses_actor[@battler.id] != nil
end
end
@height = @height / posetmp
end
end
end
end
@battler_offset = @width * 0.75
@display_x = @battler.screen_x
@display_y = @battler.screen_y
@display_z = @battler.screen_z
@destination_x = @display_x
@destination_y = @display_y
@destination_z = @display_z
if @fade_in
self.opacity = 0
end
@started = true
end
if @pose == nil
@pose = state
end
# Cut Out Frame
# Enemy Battler Routine
if @battler.is_a?(Game_Enemy)
if $default_enemy
self.src_rect.set(@width * 0, @height * 0, @width, @height)
else
if $default_enemy_id !=nil
if $default_enemy_id.include?(@battler.id)
self.src_rect.set(@width * 0, @height * 0, @width, @height)
else
if @pose != nil
if @frame != nil
self.src_rect.set(@width * @frame, @height * @pose, @width, @height)
end
end
end
else
if @pose != nil
if @frame != nil
self.src_rect.set(@width * @frame, @height * @pose, @width, @height)
end
end
end
end
end
# Actor Battler Routine
if @battler.is_a?(Game_Actor)
if $default_actor
self.src_rect.set(@width * 0, @height * 0, @width, @height)
else
if $default_actor_id !=nil
if $default_actor_id.include?(@battler.id)
self.src_rect.set(@width * 0, @height * 0, @width, @height)
else
if @pose != nil
if @frame != nil
self.src_rect.set(@width * @frame, @height * @pose, @width, @height)
end
end
end
else
if @pose != nil
if @frame != nil
self.src_rect.set(@width * @frame, @height * @pose, @width, @height)
end
end
end
end
end
# Position Sprite
self.x = @display_x
self.y = @display_y
self.z = @display_z
self.ox = @width / 2
self.oy = @height
# Adjust sprite direction if facing the other way...
if $sv_mirror == 1
if @battler.is_a?(Game_Actor)
self.mirror = !!battler
else
if not @mirror_enemies
self.mirror = !!battler
end
end
else
if @battler.is_a?(Game_Enemy)
if @mirror_enemies
self.mirror = !!battler
end
end
end
# Setup Frames per Pose
poseframe = @frames_standard
poseframe = @frames_per_pose[@pose] if @frames_per_pose.include?(@pose)
# Set Advanced Poses for Actors
if @battler.is_a?(Game_Actor)
pose_temp = $poses_actor[@battler.id] if $poses_actor.include?(@battler.id)
poseframe = pose_temp[@pose] if pose_temp.include?(@pose)
end
# Set Advanced Poses for Enemies
if @battler.is_a?(Game_Enemy)
pose_temp = $poses_enemy[@battler.id] if $poses_enemy.include?(@battler.id)
poseframe = pose_temp[@pose] if pose_temp.include?(@pose)
end
# Setup Animation
time = Graphics.frame_count / (Graphics.frame_rate / @speed)
if @last_time < time
@frame = (@frame + 1) % poseframe
if @frame == 0
if @freeze
@frame = poseframe - 1
return
end
@pose = state
end
end
@last_time = time
# Setup Dying Animation
if @battler.dead?
if @dying == true
@pose = state
@dying = false
end
else
# Setup/Ready for Battle (Let's get ready to RUMBLE!)
if @s_pose == false
tmp_pose = pose_obtain(@poses_setup, @poses_setup_a, @poses_setup_e)
if tmp_pose != nil
@pose = tmp_pose
@s_pose = true
end
end
if @battler.is_a?(Game_Actor)
if $victory == true
if @winning == true
@pose = state
@winning = false
end
end
end
end
# Move It
move if moving
end
#--------------------------------------------------------------------------
# * Current State
#--------------------------------------------------------------------------
def state
@statusd = false
unless @battler.dead?
if @battler.is_a?(Game_Enemy) and @translucent_enemy.include?(@battler.id)
if @battler.hidden
self.opacity = 0
else
self.opacity = @translucency
end
end
if @battler.is_a?(Game_Actor) and @translucent_actor.include?(@battler.id)
if @battler.hidden
self.opacity = 0
else
self.opacity = @translucency
end
end
end
# Damage State
if [nil,{}].include?(@battler.damage)
# Battler Fine
@state = pose_obtain($p1, $ap1, $ep1)
# Battler Wounded
temp_percentage = @low_hp_percentage
if @battler.is_a?(Game_Actor)
temp_percentage = @low_hp_actor[@battler.id] if @low_hp_actor[@battler.id] != nil
end
if @battler.is_a?(Game_Enemy)
temp_percentage = @low_hp_enemy[@battler.id] if @low_hp_enemy[@battler.id] != nil
end
if @battler.hp < @battler.maxhp * temp_percentage
@state = pose_obtain($p3, $ap3, $ep3)
@statusd = true
end
# Battler Status-Effect
for i in @battler.states
tmp_pose2 = pose_array_obtain(@poses_status, @poses_stat_a, @poses_stat_e, i)
@state = tmp_pose2 if tmp_pose2 != nil
@statusd = true if tmp_pose2 != nil
end
# If Battler Dead
if @battler.dead?
# If using default battlers or default collapse
if (@default_collapse_actor and @battler.is_a?(Game_Actor)) or
(@default_collapse_enemy and @battler.is_a?(Game_Enemy)) or
($default_actor and @battler.is_a?(Game_Actor)) or
($default_enemy and @battler.is_a?(Game_Enemy)) or
($default_enemy_id.include?(@battler.id) and @battler.is_a?(Game_Enemy)) or
($default_actor_id.include?(@battler.id) and @battler.is_a?(Game_Actor))
# Do absolutely nothing :)
else
# Dying Animation pose
if @dying == true
tmp_pose = pose_obtain(@poses_dying, @poses_dying_a, @poses_dying_e)
if tmp_pose != nil
@state = tmp_pose
else
@state = pose_obtain($p11, $ap11, $ep11)
end
else
@state = pose_obtain($p11, $ap11, $ep11)
end
# Fix Opacity
if @battler.is_a?(Game_Enemy)
if @translucent_enemy.include?(@battler.id)
if @battler.hidden
self.opacity = 0
else
self.opacity = @translucency
end
else
if @battler.hidden
self.opacity = 0
else
self.opacity = 255
end
end
else
if @translucent_actor.include?(@battler.id)
if @battler.hidden
self.opacity = 0
else
self.opacity = @translucency
end
else
if @battler.hidden
self.opacity = 0
else
self.opacity = 255
end
end
end
end
end
end
# Casting State
if @battler.casted
if $para_spell_detect
if @battler.spelling?
tmp_pose = pose_obtain(@poses_casting, @poses_casting_a, @poses_casting_e)
tmp_pose2 = pose_array_obtain(@p_skill_casted, @p_skill_casted_a, @p_skill_casted_e, @battler.skill_casted)
tmp_pose = tmp_pose2 if tmp_pose2 != nil
@state = tmp_pose if tmp_pose != nil
end
else
if $scd_detect
if @battler.sd_casting
tmp_pose = pose_obtain(@poses_casting, @poses_casting_a, @poses_casting_e)
tmp_pose2 = pose_array_obtain(@p_skill_casted, @p_skill_casted_a, @p_skill_casted_e, @battler.skill_casted)
tmp_pose = tmp_pose2 if tmp_pose2 != nil
@state = tmp_pose if tmp_pose != nil
end
end
if @battler.rtp != 0
tmp_pose = pose_obtain(@poses_casting, @poses_casting_a, @poses_casting_e)
tmp_pose2 = pose_array_obtain(@p_skill_casted,@p_skill_casted_a,@p_skill_casted_e,@battler.skill_casted)
tmp_pose = tmp_pose2 if tmp_pose2 != nil
@state = tmp_pose if tmp_pose != nil
end
end
end
# Victory State
if @battler.is_a?(Game_Actor)
if $victory
if not @battler.dead?
if @winning == true
if @poses_winning != nil
tmp_pose = pose_obtain(@poses_winning, @poses_winning_a, @poses_winning_e)
@state = tmp_pose if tmp_pose != nil
end
else
tmp_pose = $p10
tmp_pose = $ap10[@battler.id] if $ap10[@battler.id] != nil
@state = tmp_pose
if not @poses_winning_loops.include?(@battler.id)
@freeze = true
end
end
else
if not @battler.dead?
tmp_pose = $p10
tmp_pose = $ap10[@battler.id] if $ap10[@battler.id] != nil
@state = tmp_pose
if not @poses_winning_loops.include?(@battler.id)
@freeze = true
end
end
end
end
# Perform check for Enemies
else
if $defeat
if not @battler.dead?
if @winning == true
if @poses_winning != nil
tmp_pose = pose_obtain(@poses_winning, @poses_winning_a, @poses_winning_e)
@state = tmp_pose if tmp_pose != nil
end
else
tmp_pose = $p10
tmp_pose = $ap10[@battler.id] if $ap10[@battler.id] != nil
@state = tmp_pose
if not @poses_winning_loops.include?(@battler.id)
@freeze = true
end
end
else
if not @battler.dead?
tmp_pose = $p10
tmp_pose = $ap10[@battler.id] if $ap10[@battler.id] != nil
@state = tmp_pose
if not @poses_winning_loops.include?(@battler.id)
@freeze = true
end
end
end
end
end
# Guarding State (not if dead OR in victory)
if not @battler.dead?
if not $victory
if @statusd == false
@state = pose_obtain($p4, $ap4, $ep4) if @battler.guarding?
end
end
end
# Moving State
if moving
# Adjust sprite direction if facing the other way...
if $sv_mirror == 1
# If enemy battler moving
if @battler.is_a?(Game_Enemy)
# Battler Moving Left
@state = pose_obtain($p5, $ap5, $ep5) if moving.eql?(0)
# Battler Moving Right
@state = pose_obtain($p6, $ap6, $ep6) if moving.eql?(1)
# Else actor battler moving
else
# Battler Moving Left
@state = pose_obtain($p6, $ap6, $ep6) if moving.eql?(0)
# Battler Moving Right
@state = pose_obtain($p5, $ap5, $ep5) if moving.eql?(1)
end
else
# If enemy battler moving
if @battler.is_a?(Game_Enemy)
# Battler Moving Left
@state = pose_obtain($p6, $ap6, $ep6) if moving.eql?(0)
# Battler Moving Right
@state = pose_obtain($p5, $ap5, $ep5) if moving.eql?(1)
# Else actor battler moving
else
# Battler Moving Left
@state = pose_obtain($p5, $ap5, $ep5) if moving.eql?(0)
# Battler Moving Right
@state = pose_obtain($p6, $ap6, $ep6) if moving.eql?(1)
end
end
end
# Return State
return @state
end
#--------------------------------------------------------------------------
# * Move
#--------------------------------------------------------------------------
def move
time = Graphics.frame_count / (Graphics.frame_rate.to_f / (@speed * 5))
if @last_move_time < time
# Pause for Animation
return if @pose != state
opa = 255
if @battler.is_a?(Game_Enemy) and @translucent_enemy.include?(@battler.id)
opa = @translucency
end
if @battler.is_a?(Game_Actor) and @translucent_actor.include?(@battler.id)
opa = @translucency
end
# Phasing
if @phasing
d1 = (@display_x - @original_x).abs
d2 = (@display_y - @original_y).abs
d3 = (@display_x - @destination_x).abs
d4 = (@display_y - @destination_y).abs
self.opacity = [opa - ([d1 + d2, d3 + d4].min * 1.75).to_i, 0].max
end
# Phasing per Actor/Enemy
if @battler.is_a?(Game_Actor)
if @phasing_actor.include?(@battler.id)
d1 = (@display_x - @original_x).abs
d2 = (@display_y - @original_y).abs
d3 = (@display_x - @destination_x).abs
d4 = (@display_y - @destination_y).abs
self.opacity = [opa - ([d1 + d2, d3 + d4].min * 1.75).to_i, 0].max
end
else
if @phasing_enemy.include?(@battler.id)
d1 = (@display_x - @original_x).abs
d2 = (@display_y - @original_y).abs
d3 = (@display_x - @destination_x).abs
d4 = (@display_y - @destination_y).abs
self.opacity = [opa - ([d1 + d2, d3 + d4].min * 1.75).to_i, 0].max
end
end
# Calculate Difference
difference_x = (@display_x - @destination_x).abs
difference_y = (@display_y - @destination_y).abs
difference_z = (@display_z - @destination_z).abs
# Done? Reset, Stop
if [difference_x, difference_y].max.between?(0, 8)
@display_x = @destination_x
@display_y = @destination_y
@display_z = @destination_z
@pose = state
return
end
# Calculate Movement Increments
increment_x = increment_y = 1
if difference_x < difference_y
increment_x = 1.0 / (difference_y.to_f / difference_x)
elsif difference_y < difference_x
increment_y = 1.0 / (difference_x.to_f / difference_y)
end
increment_z = increment_y
# Calculate Movement Speed
if @calculate_speed
total = 0; $game_party.actors.each{ |actor| total += actor.agi }
speed = @battler.agi.to_f / (total / $game_party.actors.size)
increment_x *= speed
increment_y *= speed
increment_z *= speed
end
# Multiply and Move
multiplier_x = @rush_speed * (@destination_x - @display_x > 0 ? 8 : -8)
multiplier_y = @rush_speed * (@destination_y - @display_y > 0 ? 8 : -8)
multiplier_z = @rush_speed * (@destination_z - @display_z > 0 ? 8 : -8)
@display_x += (increment_x * multiplier_x).to_i
@display_y += (increment_y * multiplier_y).to_i
@display_z += (increment_z * multiplier_z).to_i
end
@last_move_time = time
end
#--------------------------------------------------------------------------
# * Set Movement
#--------------------------------------------------------------------------
def setmove(destination_x, destination_y, destination_z)
unless (@battler.is_a?(Game_Enemy) and @stationary_enemies) or
(@battler.is_a?(Game_Actor) and @stationary_actors)
unless @stationary_weapons.include?(@battler.weapon_id) or
@stationary_skills.include?(@skill_used) or
@stationary_items.include?(@item_used)
@original_x = @display_x
@original_y = @display_y
@original_z = @display_z
@destination_x = destination_x
@destination_y = destination_y
@destination_z = destination_z
end
end
end
#--------------------------------------------------------------------------
# * Movement Check
#--------------------------------------------------------------------------
def moving
if (@display_x != @destination_x and @display_y != @destination_y and !@battler.dead?)
return (@display_x > @destination_x ? 0 : 1)
end
end
#--------------------------------------------------------------------------
# * Set Pose
#--------------------------------------------------------------------------
def pose=(pose)
@pose = pose
@frame = 0
end
#--------------------------------------------------------------------------
# * Freeze
#--------------------------------------------------------------------------
def freeze
@freeze = true
end
#--------------------------------------------------------------------------
# * Fallen Pose
#--------------------------------------------------------------------------
if @derv_anim_bat_stack.nil?
@derv_anim_bat_stack = true
alias mnk_collapse collapse
def collapse
if @default_collapse_enemy
mnk_collapse if @battler.is_a?(Game_Enemy)
end
if @default_collapse_actor
mnk_collapse if @battler.is_a?(Game_Actor)
end
if $default_enemy
mnk_collapse if @battler.is_a?(Game_Enemy)
end
if $default_actor
mnk_collapse if @battler.is_a?(Game_Actor)
end
if $default_enemy_id != nil
if $default_enemy_id.include?(@battler.id)
mnk_collapse if @battler.is_a?(Game_Enemy)
end
end
if $defend_actor.id != nil
if $default_actor_id.include?(@battler.id)
mnk_collapse if @battler.is_a?(Game_Actor)
end
end
end
end
#--------------------------------------------------------------------------
# * Obtain Pose
# pose_base : default pose to return
# pose_actor : list of poses for actors
# pose_enemy : list of poses for enemies
#--------------------------------------------------------------------------
def pose_obtain(pose_base, pose_actor, pose_enemy)
# create Arrays
pos_a = {}
pos_e = {}
# fill created Arrays & Set pose
pos_a = pose_actor
pos_e = pose_enemy
pose_now = pose_base
# Obtain pose if not a standard pose
if @battler.is_a?(Game_Actor)
pose_now = pos_a[@battler.id] if pos_a[@battler.id] != nil
else
pose_now = pos_e[@battler.id] if pos_e[@battler.id] != nil
end
return pose_now
end
#--------------------------------------------------------------------------
# * Obtain Pose from hashes
# hash_base : hash with default poses
# hash_actor : advanced list of poses for actors
# hash_enemy : advanced list of poses for enemies
# condition : value determining where to get the final pose
#--------------------------------------------------------------------------
def pose_array_obtain(hash_base, hash_actor, hash_enemy, condition)
# create Arrays
hash_b = {}
hash_a = {}
hash_e = {}
pose_temp = {}
# fill created Arrays & Set pose
hash_b = hash_base
hash_a = hash_actor
hash_e = hash_enemy
# Setup the temp Array
if @battler.is_a?(Game_Actor)
pose_temp = hash_a[@battler.id] if hash_a.include?(@battler.id)
else
pose_temp = hash_e[@battler.id] if hash_e.include?(@battler.id)
end
# Obtain the base pose based on condition (or nil)
pose_now = hash_b[condition] if hash_b.include?(condition)
# Obtain the optional actor/enemy pose based on condition (unless nil)
pose_now = pose_temp[condition] if pose_temp.include?(condition)
# Return the final pose
return pose_now
end
end