The full script for reference.
Code:
#RogueDeus 15_0131
#Last Updated: 15_0206
#RDeus - Mostly Dead (COMA)
=begin
Fixes screen flash on state damage in game map.
Creates COMA state that is a slightly more complex version of DEATH.
Instead of simple DEATH, when an actors HP reaches ZERO, they fall into
COMA, during which they can die, but its unlikely.
COMA is supposed to be easier to cure than DEATH.
- Such as with tonic's or simple spells.
DEATH is supposed to be semi-permanent or require more work to remove.
- Such as a trip to a Church or a Resurrection quest.
Instant Death is possible if enabled. But its meant to be rare and easily
avoided.
- Such as taking mass damage, should only be possible if attempting to
fight enemies FAR outside the players power range. Dieing from such
damage will cause DEATH rather than COMA.
- Such as dieing from a critical hit. This is incentive to keep an actors
CEV (an often overlooked stat) as high as possible.
OVERWRITES!!
Game_BattlerBase.refresh
Game_BattlerBase.dead?
Game_BattlerBase.alive?
Game_BattlerBase.escape
BattleManager.revive_battle_members
=end
$imported = {} if $imported.nil?
$imported["RDeus - Mostly Dead"] = true
puts("#{$imported.size}~ RDeus - Mostly Dead") if $TEST
module RDeus
module MostlyDead
#============================================
# COMA BASICS
#============================================
COMA_STATE_ID = 2 #RDeus::MostlyDead::COMA_STATE_ID
#--------------------------------------------
#Set actor MP to ZERO when revived from COMA or DEATH.
ZERO_MP = true #RDeus::MostlyDead::ZERO_MP
#============================================
# INSTANT DEATH?
#============================================
#Allows for a incapacitating blow that deals enough damage to cause DEATH
#instead of COMA.
MASSDAMAGE_DEATH = true #RDeus::MostlyDead::MASSDAMAGE_DEATH
#--------------------------------------------
#Percentage of MHP that must be dealt on the incapacitating blow to qualify
#as massive damage.
MASSDAMAGE = 0.25 #Default 25% #RDeus::MostlyDead::MASSDAMAGE
#--------------------------------------------
#Allows for a CRITICAL HIT incapacitating blow to cause DEATH instead of COMA.
CRITICAL_DEATH = true
#============================================
# COMA STASIS?
#============================================
#To keep states/buffs/debuffs active on COMA actors, set this true.
#Intended to prevent COMA from being a means of wiping negative states.
COMA_STASIS = true #RDeus::MostlyDead::COMA_STASIS
#--------------------------------------------
#Continues to process actors states even while COMA when true.
# Note: This must be TRUE for DAMAGE_IN_COMA to risk Death.
UPDATE_STASIS = true #RDeus::MostlyDead::UPDATE_STASIS
#--------------------------------------------
#If during UPDATE_STASIS a state deals damage, there is a chance
#the actor may die, if this is set true. Otherwise to suffer a DEATH
#state, it must be applied directly, such as with a instant death option.
DAMAGE_IN_COMA = true #RDeus::MostlyDead::DAMAGE_IN_COMA
#--------------------------------------------
#This is the base chance of death from DAMAGE_IN_COMA
#Normally chance is the ratio of the damage to the actors MHP/MMP
MINIMUM_CHANCE = 0.10 #RDeus::MostlyDead::MINIMUM_CHANCE
end
end
#===============================================================================
#
#===============================================================================
class Game_BattlerBase
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def coma_state_id
return RDeus::MostlyDead::COMA_STATE_ID
end
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def coma_state?
# value = state?(RDeus::MostlyDead::COMA_STATE_ID)
# puts("\n #{self.name} is in COMA.\n") if value
# return value
return state?(RDeus::MostlyDead::COMA_STATE_ID)
end
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def coma?
exist? && coma_state?
end
#-----------------------------------------------------------------------------
# overwrite:
# For BattleManager(ReviveIf), ItemTest, CheckGameover
#-----------------------------------------------------------------------------
def dead?
(exist? && death_state?) || (exist? && coma_state?)
end
#-----------------------------------------------------------------------------
# overwrite:
# BattleManager(Next & Victory?), Add/Remove (De)Buff, StateAddable?, RegenAll
#-----------------------------------------------------------------------------
def alive?
exist? && !death_state? && !coma_state?
end
#-----------------------------------------------------------------------------
# override:
#
# !!DANGEROUS!! This can break a LOT of scripts if not above them!!
# --ALIASES--
# RDeus - Equipment Skills & Passive Aura States
# Victor - State Aura
# Yanfly - Enemy HP Bars
# Yanfly - State Animations
#-----------------------------------------------------------------------------
def refresh
state_resist_set.each {|state_id| erase_state(state_id) }
@hp = [[@hp, mhp].min, 0].max
@mp = [[@mp, mmp].min, 0].max
if @hp == 0
return if state?(coma_state_id) || state?(death_state_id)
if massive_damage? || critical_damage?
puts("\n<MostlyDead> Applying DEATH\n")
add_state(death_state_id)
else
puts("<MostlyDead> Applying COMA")
add_state(coma_state_id)
end
else #hp must be greater than 0
remove_state(death_state_id)
end
end
end
#===============================================================================
#
#===============================================================================
class Game_Battler < Game_BattlerBase
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def massive_damage?
return false unless RDeus::MostlyDead::MASSDAMAGE_DEATH
return false unless @result.hp_damage > 0 #Can't be Healing.
value = (@result.hp_damage.to_f / self.mhp)
result = value >= RDeus::MostlyDead::MASSDAMAGE
puts("<MostlyDead> MASSDAMAGE? (#{@result.hp_damage}/#{self.mhp}) #{value.round(2)} >= #{RDeus::MostlyDead::MASSDAMAGE} ?#{result}?")
return result
end
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def critical_damage?
return false unless RDeus::MostlyDead::CRITICAL_DEATH
return false unless @result.hp_damage > 0 #Can't be Healing.
return @result.critical
end
#-----------------------------------------------------------------------------
# die clears states, so even if COMA exists, it will be removed here.
#-----------------------------------------------------------------------------
alias :rd_mostlydead_die :die
def die
@mp = 0 if RDeus::MostlyDead::ZERO_MP
rd_mostlydead_die
end
#-----------------------------------------------------------------------------
# new:
# Be sure to set death state to 'resist' the COMA state so they don't stack.
#-----------------------------------------------------------------------------
def coma
@hp = 0
@mp = 0 if RDeus::MostlyDead::ZERO_MP
unless RDeus::MostlyDead::COMA_STASIS
clear_states
clear_buffs
end
end
#-----------------------------------------------------------------------------
alias :rd_mostlydead_state_addable? :state_addable?
def state_addable?(state_id)
value = rd_mostlydead_state_addable?(state_id)
puts("<MostlyDead> #{$data_states[state_id].name} Added? #{value}")
return value
end
#-----------------------------------------------------------------------------
alias :rd_mostlydead_add_new_state :add_new_state
def add_new_state(state_id)
coma if coma_state_id == state_id && !state?(death_state_id) #COMA if not already DEAD.
rd_mostlydead_add_new_state(state_id)
end
#-----------------------------------------------------------------------------
alias :rd_mostlydead_remove_state :remove_state
def remove_state(state_id)
#Revive me if removing COMA, I'm in COMA, and I'm not DEAD...
#While it shouldn't be made possible for enemies to target a COMA actor
#to apply DEATH, we check to be sure...
revive if state_id == coma_state_id && state?(state_id) && !state?(death_state_id)
rd_mostlydead_remove_state(state_id)
end
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def coma_damage_chance
# puts("[#{(@result.hp_damage.to_f / self.mhp).round(1)}, #{RDeus::MostlyDead::MINIMUM_CHANCE}] )")
return [(@result.hp_damage.to_f / self.mhp), RDeus::MostlyDead::MINIMUM_CHANCE].max
end
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def coma_damage_death?
r = rand.round(2)
print("... ( #{@result.hp_damage} > 0 ) && ( #{r} <= #{coma_damage_chance.round(3)} )")
return false unless @result.hp_damage > 0 #Result wasn't healing.
return false unless r <= coma_damage_chance #Chance succeeded.
return true
end
#-----------------------------------------------------------------------------
# new:
# Need to add 'effect_over_time' support to this.
#-----------------------------------------------------------------------------
def calculate_coma_damage
damage = (mhp * hrg).to_i
if damage > 0
perform_map_damage_effect
@result.hp_damage = damage
else
@result.clear
end
end
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def is_damage_over_time?
return (mhp * hrg) < 0
end
#-----------------------------------------------------------------------------
# new:
#-----------------------------------------------------------------------------
def process_coma_damage
return unless coma_state? && RDeus::MostlyDead::UPDATE_STASIS
#We are in COMA and we are UPDATING it.
puts("... process_coma_damage #{self.name}")
calculate_coma_damage if @result.hp_damage == 0
#@result.hp_damage will be 0 if regenerate_hp last touched it, and self.dead? (includes COMA)
#Thus if State Effect Over Time, applied damage BEFORE this, it wouldn't be 0.
if RDeus::MostlyDead::DAMAGE_IN_COMA && coma_damage_death?
print("... DIED!!!")
add_new_state(death_state_id) unless state?(death_state_id)
reset_state_counts(death_state_id)
@result.added_states.push(death_state_id).uniq!
end
puts
end
#-----------------------------------------------------------------------------
alias :rd_mostlydead_regenerate_all :regenerate_all
def regenerate_all
# if alive? #False if COMA
# regenerate_hp
# regenerate_mp
# regenerate_tp
# end
rd_mostlydead_regenerate_all
perform_map_damage_effect if alive? && @result.hp_damage > 0
process_coma_damage
end
#-----------------------------------------------------------------------------
alias :rd_mostlydead_update_state_turns :update_state_turns
def update_state_turns
return if coma_state? && !RDeus::MostlyDead::UPDATE_STASIS
rd_mostlydead_update_state_turns
end
end
#===============================================================================
#
#===============================================================================
class Game_Actor < Game_Battler
#-----------------------------------------------------------------------------
alias :rd_mostlydead_update_state_steps :update_state_steps
def update_state_steps(state)
return if coma_state? && !RDeus::MostlyDead::UPDATE_STASIS
rd_mostlydead_update_state_steps(state)
end
end
#===============================================================================
#
#===============================================================================
module BattleManager
#-----------------------------------------------------------------------------
# overwrite:
#-----------------------------------------------------------------------------
def self.revive_battle_members
$game_party.battle_members.each do |actor|
actor.hp = 1 if actor.dead? || actor.coma?
end
end
end
#===============================================================================
#
#===============================================================================
class Window_BattleLog < Window_Selectable
#-----------------------------------------------------------------------------
# Needed to allow collapse as if died.
#-----------------------------------------------------------------------------
alias :rd_mostlydead_display_added_states :display_added_states
def display_added_states(target)
rd_mostlydead_display_added_states(target)
return unless target.coma?
target.result.added_state_objects.each do |state|
state_msg = target.actor? ? state.message1 : state.message2
target.perform_collapse_effect if state.id == target.coma_state_id
next if state_msg.empty?
replace_text(target.name + state_msg)
wait
wait_for_effect
end
end
end