#==============================================================================
# ** Animated Battlers - Enhanced ver. 10.7 (06-17-2008)
#
#------------------------------------------------------------------------------
# * (2) 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
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :battler_offset # Degree of action forcing
attr_accessor :skill_used # Degree of action forcing
attr_accessor :item_used # Degree of action forcing
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias mnk_init initialize
def initialize(viewport, battler = nil)
# --Initialize poses
@frame, @pose, @last_time, @last_move_time = 0, 0, 0, 0
# --Initialize Battler placement and pose types
@battler_offset, @skill_used, @item_used = 0, 0, 0
# --Initialize Boolean values
@statusd = false
@dying = true
@s_pose = false
$game_system.victory = false
$game_system.defeat = false
@winning = true
# ORIGINAL Initialize call
mnk_init(viewport, battler)
# EVENT VALUE CALLS
# --Obtain the Sideview switch
$game_system.sv_angle = $sideview_mirror
$game_system.sv_angle = 0 if $sideview_mirror == nil
# -- Obtain the max party size
$game_system.max_member = $formation_max_member
$game_system.max_member = 4 if $formation_max_member == nil
# --Obtain the highest position for the formation
$game_system.form_top = $formation_max_height
$game_system.form_top = 220 if $formation_max_height == nil
# --Obtain the formation's width
$game_system.form_wd = $formation_max_width
$game_system.form_wd = 128 if $formation_max_width == nil
# --Obtain the height of the Battlestatus Window
$game_system.bstat_ht = $battlestatus_height
$game_system.bstat_ht = 160 if $battlestatus_height == nil
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias mnk_update update
def update
# Only perform sprite edit for valid battlers
return unless @battler
if @battler.battler_name != @battler_name
@started = false
end
# Regular Update
mnk_update
# Set Translucency
if @battler.is_a?(Game_Enemy)
battler_translucency(@battler, MNK_TRANSLUCENT_ENEMY)
else
battler_translucency(@battler, MNK_TRANSLUCENT_ACTOR)
end
# Reset hash for Advanced Pose/Frames
pose_temp = {}
# Start Routine (Performed at startup for each battler)
unless @started
# Set the pose based on battler's state
@pose = state
# Turn off Casting pose
@battler.casted = false
@battler.casting = false
# Configure Enemy Spritesheet
if @battler.is_a?(Game_Enemy)
# Use spritesheet unless specified
unless DEFAULT_ENEMY or DEFAULT_ENEMY_ID.include?(@battler.id)
@width = @width / cell_divider(MNK_FRAMES_ENEMY, MNK_FRAMES)
@height = @height / cell_divider(MNK_POSES_ENEMY, MNK_POSES)
end
# Or Configure Actor Spritesheet
else
# Use spritesheet unless specified
unless DEFAULT_ACTOR or DEFAULT_ACTOR_ID.include?(@battler.id)
@width = @width / cell_divider(MNK_FRAMES_ACTOR, MNK_FRAMES)
@height = @height / cell_divider(MNK_POSES_ACTOR, MNK_POSES)
end
end
# Distance the battlers
@battler_offset = @width * 0.75
# Obtain battler position (simulating 3-Dness)
@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
# Opacity fadein feature
self.opacity = 0 if MNK_FADE_IN
# Make invisible if dead at battle start
self.visible = false if @battler.dead?
# Set the started flag
@started = true
# End of Start Routine (for each battler)
end
# Again, ensure a pose is set
@pose = state if @pose == nil
# Obtain animation cell/frame from Enemy
if @battler.is_a?(Game_Enemy)
# Use spritesheet cell unless specified
unless DEFAULT_ENEMY or DEFAULT_ENEMY_ID.include?(@battler.id)
cell_obtain
else
self.src_rect.set(0, 0, @width, @height)
end
# Or get it from an actor
else
# Use spritesheet cell unless specified
unless DEFAULT_ACTOR or DEFAULT_ACTOR_ID.include?(@battler.id)
cell_obtain
else
self.src_rect.set(0, 0, @width, @height)
end
end
# Position Sprite
self.x = @display_x
self.y = @display_y
self.z = @display_z
self.ox = @width / 2
self.oy = @height
# Party Turned Around
# $game_temp.advantage_set == 6
# Adjust sprite direction if facing the other way...
if $game_system.sv_angle == 1
if @battler.is_a?(Game_Actor)
mirror_pose_unless(6)
else
if MNK_MIRROR_ENEMIES
mirror_pose_if(5)
else
mirror_pose_unless(5)
end
end
else
if @battler.is_a?(Game_Actor)
mirror_pose_if(6)
else
if MNK_MIRROR_ENEMIES
mirror_pose_unless(5)
else
mirror_pose_if(5)
end
end
end
# Setup Frames per Pose
poseframe = MNK_FRAMES_STANDARD
if @battler.is_a?(Game_Actor)
poseframe = cell_divider(MNK_FRAMES_ACTOR, MNK_FRAMES_STANDARD) if cell_divider(MNK_FRAMES_ACTOR, MNK_FRAMES_STANDARD) != nil
else
poseframe = cell_divider(MNK_FRAMES_ENEMY, MNK_FRAMES_STANDARD) if cell_divider(MNK_FRAMES_ENEMY, MNK_FRAMES_STANDARD) != nil
end
pose_chk = 0
pose_chk = @pose+1 if @pose != nil
poseframe = MNK_FRAMES_PER_POSE[pose_chk] if MNK_FRAMES_PER_POSE.include?(pose_chk)
# Set Advanced Poses for Actors
if @battler.is_a?(Game_Actor)
pose_temp = MNK_POSES_FR_ACTOR[@battler.id] if MNK_POSES_FR_ACTOR.include?(@battler.id)
poseframe = pose_temp[pose_chk] if pose_temp.include?(pose_chk)
end
# Set Advanced Poses for Enemies
if @battler.is_a?(Game_Enemy)
pose_temp = MNK_POSES_FR_ENEMY[@battler.id] if MNK_POSES_FR_ENEMY.include?(@battler.id)
poseframe = pose_temp[pose_chk] if pose_temp.include?(pose_chk)
end
# Make visible if returned to life
unless @battler.dead?
self.visible = true if @pose == pose_obtain(MNK_POSE1, MNK_APOSE1, MNK_EPOSE1)
@freeze = false unless $game_system.victory
end
# Setup Animation
time = Graphics.frame_count / (Graphics.frame_rate / MNK_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
# Otherwise, all non-dead actions...
else
# Setup/Ready for Battle (Let's get ready to RUMBLE!)
if @s_pose == false
tmp_pose = pose_obtain(MNK_POSES_SETUP, MNK_POSES_SETUP_A, MNK_POSES_SETUP_E)
if tmp_pose != nil
@pose = tmp_pose
@s_pose = true
end
end
# If Victory pose (Who's your daddy?)
if @battler.is_a?(Game_Actor)
if $game_system.victory == true
if @winning == true
@pose = state
@winning = false
end
end
end
end
# Move It
move if moving
end
#--------------------------------------------------------------------------
# * Current State
#--------------------------------------------------------------------------
def state
# Reset Statusd Flag
@statusd = false
# Set Translucency if not dead
unless @battler.dead?
if @battler.is_a?(Game_Actor)
battler_translucency(@battler, MNK_TRANSLUCENT_ACTOR)
else
battler_translucency(@battler, MNK_TRANSLUCENT_ENEMY)
end
end
# Damage State
if [nil,{}].include?(@battler.damage)
# Battler Fine
state = pose_obtain(MNK_POSE1, MNK_APOSE1, MNK_EPOSE1)
# Battler Wounded
temp_woozy = MNK_LOW_HP_PERCENTAGE
if @battler.is_a?(Game_Actor)
temp_woozy = MNK_LOW_HP_ACTOR[@battler.id] if MNK_LOW_HP_ACTOR[@battler.id] != nil
end
if @battler.is_a?(Game_Enemy)
temp_woozy = MNK_LOW_HP_ENEMY[@battler.id] if MNK_LOW_HP_ENEMY[@battler.id] != nil
end
# If Set to Flat Rate
if MNK_LOW_HP_FLAT
if @battler.hp < temp_woozy
state = pose_obtain(MNK_POSE3, MNK_APOSE3, MNK_EPOSE3)
@statusd = true
end
# Otherwise, use percentage of battler's health
else
if @battler.hp < @battler.maxhp * temp_woozy
state = pose_obtain(MNK_POSE3, MNK_APOSE3, MNK_EPOSE3)
@statusd = true
end
end
# Battler Status-Effect
for i in @battler.states
tmp_pose2 = pose_array_obtain(MNK_POSES_STATUS, MNK_POSES_STAT_A, MNK_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(MNK_POSES_DYING, MNK_POSES_DYING_a, MNK_POSES_DYING_E)
if tmp_pose != nil
state = tmp_pose
else
state = dying_pose
end
else
state = dying_pose
end
# Fix Opacity
if @battler.is_a?(Game_Enemy)
if MNK_TRANSLUCENT_ENEMY.include?(@battler.id)
set_translucency(@battler, MNK_TRANSLUCENCY)
else
set_translucency(@battler, 255)
end
else
if MNK_TRANSLUCENT_ACTOR.include?(@battler.id)
set_translucency(@battler, MNK_TRANSLUCENCY)
else
set_translucency(@battler, 255)
end
end
end
end
end
# Casting State
if @battler.casted
state = casting_pose if $game_system.mnk_det_para_spell and @battler.spelling?
state = casting_pose if $game_system.mnk_det_sd_casting and @battler.sd_casting
state = casting_pose if $game_system.mnk_det_rtab_systm and @battler.rtp != 0
end
# Victory State
if @battler.is_a?(Game_Actor)
if $game_system.victory
if not @battler.dead?
if @winning == true
# A Pre-Winning Pose display
if MNK_POSES_WINNING != nil
tmp_pose = pose_obtain(MNK_POSES_WINNING, MNK_POSES_WINNING_A, MNK_POSES_WINNING_E)
state = tmp_pose if tmp_pose != nil
end
else
# Final Pose
state = victory_pose
end
else
# Final Pose
state = victory_pose
end
end
# Perform check for Enemies
else
if $game_system.defeat
if not @battler.dead?
if @winning == true
if MNK_POSES_WINNING != nil
tmp_pose = pose_obtain(MNK_POSES_WINNING, MNK_POSES_WINNING_A, MNK_POSES_WINNING_E)
state = tmp_pose if tmp_pose != nil
end
else
# Final Pose
state = victory_pose
end
else
# Final Pose
state = victory_pose
end
end
end
# Guarding State (not if dead OR in victory)
if not @battler.dead?
if not $game_system.victory
if @statusd == false
state = pose_obtain(MNK_POSE4, MNK_APOSE4, MNK_EPOSE4) if @battler.guarding?
end
end
end
# Moving State
if moving
# Adjust sprite direction if facing the other way...
if $game_system.sv_angle == 1
# If enemy battler moving
if @battler.is_a?(Game_Enemy)
# Battler Moving Left
state = pose_obtain(MNK_POSE5, MNK_APOSE5, MNK_EPOSE5) if moving.eql?(0)
# Battler Moving Right
state = pose_obtain(MNK_POSE6, MNK_APOSE6, MNK_EPOSE6) if moving.eql?(1)
# Else actor battler moving
else
# Battler Moving Left
state = pose_obtain(MNK_POSE6, MNK_APOSE6, MNK_EPOSE6) if moving.eql?(0)
# Battler Moving Right
state = pose_obtain(MNK_POSE5, MNK_APOSE5, MNK_EPOSE5) if moving.eql?(1)
end
else
# If enemy battler moving
if @battler.is_a?(Game_Enemy)
# Battler Moving Left
state = pose_obtain(MNK_POSE6, MNK_APOSE6, MNK_EPOSE6) if moving.eql?(0)
# Battler Moving Right
state = pose_obtain(MNK_POSE5, MNK_APOSE5, MNK_EPOSE5) if moving.eql?(1)
# Else actor battler moving
else
# Battler Moving Left
state = pose_obtain(MNK_POSE5, MNK_APOSE5, MNK_EPOSE5) if moving.eql?(0)
# Battler Moving Right
state = pose_obtain(MNK_POSE6, MNK_APOSE6, MNK_EPOSE6) if moving.eql?(1)
end
end
end
# Return State
return state
end
#--------------------------------------------------------------------------
# * Move
#--------------------------------------------------------------------------
def move
time = Graphics.frame_count / (Graphics.frame_rate.to_f / (MNK_SPEED * 5))
if @last_move_time < time
# Pause for Animation
return if @pose != state
# The standard 'full' opacity
opa = 255
if @battler.is_a?(Game_Enemy) and MNK_TRANSLUCENT_ENEMY.include?(@battler.id)
opa = MNK_TRANSLUCENCY
end
if @battler.is_a?(Game_Actor) and MNK_TRANSLUCENT_ACTOR.include?(@battler.id)
opa = MNK_TRANSLUCENCY
end
# Phasing
self.opacity = phasing(opa) if MNK_PHASING
if @battler.is_a?(Game_Actor)
self.opacity = phasing(opa) if MNK_PHASING_ACTOR.include?(@battler.id)
else
self.opacity = phasing(opa) if MNK_PHASING_ENEMY.include?(@battler.id)
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 MNK_CALC_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 = MNK_RUSH_SPEED * (@destination_x - @display_x > 0 ? 8 : -8)
multiplier_y = MNK_RUSH_SPEED * (@destination_y - @display_y > 0 ? 8 : -8)
multiplier_z = MNK_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 MNK_STATIONARY_ENEMIES) or
(@battler.is_a?(Game_Actor) and MNK_STATIONARY_ACTORS)
unless MNK_STATIONARY_WEAPONS.include?(@battler.weapon_id) or
MNK_STATIONARY_SKILLS.include?(@skill_used) or
MNK_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 @battler.is_a?(Game_Actor)
mnk_collapse if DEFAULT_ACTOR
mnk_collapse if DEFAULT_COLLAPSE_ACTOR
if DEFAULT_ACTOR_ID != nil
mnk_collapse if DEFAULT_ACTOR_ID.include?(@battler.id)
end
else
mnk_collapse if DEFAULT_ENEMY
mnk_collapse if DEFAULT_COLLAPSE_ENEMY
if DEFAULT_ENEMY_ID != nil
mnk_collapse if DEFAULT_ENEMY_ID.include?(@battler.id)
end
end
end
end
#--------------------------------------------------------------------------
# * Phasing / Vanishing
#--------------------------------------------------------------------------
def phasing(opa)
d1 = (@display_x - @original_x).abs
d2 = (@display_y - @original_y).abs
d3 = (@display_x - @destination_x).abs
d4 = (@display_y - @destination_y).abs
return [opa - ([d1 + d2, d3 + d4].min * 1.75).to_i, 0].max
end
#--------------------------------------------------------------------------
# * Mirror Pose If...
#--------------------------------------------------------------------------
def mirror_pose_if(adv_value)
if $game_temp.advantage_set == adv_value
self.mirror = true
else
self.mirror = false
end
end
#--------------------------------------------------------------------------
# * Mirror Pose Unless...
#--------------------------------------------------------------------------
def mirror_pose_unless(adv_value)
unless $game_temp.advantage_set == adv_value
self.mirror = true
else
self.mirror = false
end
end
#--------------------------------------------------------------------------
# * Casting Pose
#--------------------------------------------------------------------------
def casting_pose
tmp_pose = pose_obtain(MNK_POSES_CASTPREP, MNK_POSES_CASTPREP_A, MNK_POSES_CASTPREP_E)
tmp_pose2 = pose_array_obtain(MNK_POSES_CASTED, MNK_POSES_CASTED_A, MNK_POSES_CASTED_E, @battler.skill_casted)
tmp_pose = tmp_pose2 if tmp_pose2 != nil
state = tmp_pose if tmp_pose != nil
return state
end
#--------------------------------------------------------------------------
# * Final Victory Pose
#--------------------------------------------------------------------------
def victory_pose
tmp_pose = MNK_POSE10-1
tmp_pose = MNK_APOSE10[@battler.id]-1 if MNK_APOSE10[@battler.id] != nil
if not MNK_LOOPS_WINNING.include?(@battler.id)
@freeze = true
end
return tmp_pose
end
#--------------------------------------------------------------------------
# * Final Victory Pose
#--------------------------------------------------------------------------
def dying_pose
state = pose_obtain(MNK_POSE11, MNK_APOSE11, MNK_EPOSE11)
if @battler.is_a?(Game_Actor)
@freeze = true if not MNK_LOOPS_DEFEATED_ACTOR.include?(@battler.id)
else
@freeze = true if not MNK_LOOPS_DEFEATED_ENEMY.include?(@battler.id)
end
return state
end
#--------------------------------------------------------------------------
# * Battler Translucency
# battler : actor or enemy battler
# battler_trans : translucency array for battler
#--------------------------------------------------------------------------
def battler_translucency(battler, battler_trans)
tcheck = {}
tcheck = battler_trans
set_translucency(battler, MNK_TRANSLUCENCY) if tcheck.include?(battler.id)
end
#--------------------------------------------------------------------------
# * Set Translucency
# battler : actor or enemy battler
# trans_level : translucency level
#--------------------------------------------------------------------------
def set_translucency(battler, trans_leve