Home > RGSS Script Reference > Game_Battler
Game_Battler
Inherits from: None
Description: This class describes a "battler", that is, either an actor or a monster, and everything that could happen to it in battle. Note that "battler" objects that represent party members are distinct from their parent actors. This makes it easier to apply temporary effects.
class Game_Battler
# ------------------------------------
attr_reader :battler_name
attr_reader :battler_hue
attr_reader :hp
attr_reader :sp
attr_reader :states
attr_accessor :hidden
attr_accessor :immortal
attr_accessor :damage_pop
attr_accessor :damage
attr_accessor :critical
attr_accessor :animation_id
attr_accessor :animation_hit
attr_accessor :white_flush
attr_accessor :blink
# ------------------------------------
def initialize
@battler_name = ""
@battler_hue = 0
@hp = 0
@sp = 0
@states = []
@states_turn = {}
@maxhp_plus = 0
@maxsp_plus = 0
@str_plus = 0
@dex_plus = 0
@agi_plus = 0
@int_plus = 0
@hidden = false
@immortal = false
@damage_pop = false
@damage = nil
@critical = false
@animation_id = 0
@animation_hit = false
@white_flush = false
@blink = false
@current_action = Game_BattleAction.new
end
# ------------------------------------
def maxhp
n = [[base_maxhp + @maxhp_plus, 1].max, 999999].min
for i in @states
n *= $data_states[i].maxhp_rate / 100.0
end
n = [[Integer(n), 1].max, 999999].min
return n
end
# ------------------------------------
def maxsp
n = [[base_maxsp + @maxsp_plus, 0].max, 9999].min
for i in @states
n *= $data_states[i].maxsp_rate / 100.0
end
n = [[Integer(n), 0].max, 9999].min
return n
end
# ------------------------------------
def str
n = [[base_str + @str_plus, 1].max, 999].min
for i in @states
n *= $data_states[i].str_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def dex
n = [[base_dex + @dex_plus, 1].max, 999].min
for i in @states
n *= $data_states[i].dex_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def agi
n = [[base_agi + @agi_plus, 1].max, 999].min
for i in @states
n *= $data_states[i].agi_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def int
n = [[base_int + @int_plus, 1].max, 999].min
for i in @states
n *= $data_states[i].int_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def maxhp=(maxhp)
@maxhp_plus += maxhp - self.maxhp
@maxhp_plus = [[@maxhp_plus, -9999].max, 9999].min
@hp = [@hp, self.maxhp].min
end
# ------------------------------------
def maxsp=(maxsp)
@maxsp_plus += maxsp - self.maxsp
@maxsp_plus = [[@maxsp_plus, -9999].max, 9999].min
end
# ------------------------------------
def str=(str)
@str_plus += str - self.str
@str_plus = [[@str_plus, -999].max, 999].min
end
# ------------------------------------
def dex=(dex)
@dex_plus += dex - self.dex
@dex_plus = [[@dex_plus, -999].max, 999].min
end
# ------------------------------------
def agi=(agi)
@agi_plus += agi - self.agi
@agi_plus = [[@agi_plus, -999].max, 999].min
end
# ------------------------------------
def int=(int)
@int_plus += int - self.int
@int_plus = [[@int_plus, -999].max, 999].min
end
# ------------------------------------
def hit
n = 100
for i in @states
n *= $data_states[i].hit_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def atk
n = base_atk
for i in @states
n *= $data_states[i].atk_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def pdef
n = base_pdef
for i in @states
n *= $data_states[i].pdef_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def mdef
n = base_mdef
for i in @states
n *= $data_states[i].mdef_rate / 100.0
end
return Integer(n)
end
# ------------------------------------
def eva
n = base_eva
return n
end
# ------------------------------------
def hp=(hp)
@hp = [[hp, maxhp].min, 0].max
for i in 1...$data_states.size
if $data_states[i].zero_hp
if self.dead?
add_state(i)
else
remove_state(i)
end
end
end
end
# ------------------------------------
def sp=(sp)
@sp = [[sp, maxsp].min, 0].max
end
# ------------------------------------
def recover_all
@hp = maxhp
@sp = maxsp
for i in @states.clone
remove_state(i)
end
end
# ------------------------------------
def current_action
return @current_action
end
# ------------------------------------
def make_action_speed
@current_action.speed = agi + rand(10 + agi / 4)
end
# ------------------------------------
def dead?
return (@hp == 0 and not @immortal)
end
# ------------------------------------
def exist?
return (not @hidden and (@hp > 0 or @immortal))
end
# ------------------------------------
def hp0?
return (not @hidden and @hp == 0)
end
# ------------------------------------
def inputable?
return (not @hidden and restriction <= 1)
end
# ------------------------------------
def movable?
return (not @hidden and restriction < 4)
end
# ------------------------------------
def guarding?
return (@current_action.kind == 0 and @current_action.basic == 1)
end
# ------------------------------------
def resting?
return (@current_action.kind == 0 and @current_action.basic == 3)
end
end
# ------------------------------------
def state?(state_id)
return @states.include?(state_id)
end
# ------------------------------------
def state_full?(state_id)
unless self.state?(state_id)
return false
end
if @states_turn[state_id] == -1
return true
end
return @states_turn[state_id] == $data_states[state_id].hold_turn
end
# ------------------------------------
def add_state(state_id, force = false)
unless force
for i in @states
if $data_states[i].minus_state_set.include?(state_id) and
not $data_states[state_id].minus_state_set.include?(i)
return
end
end
end
unless state?(state_id)
@states.push(state_id)
if $data_states[state_id].zero_hp
@hp = 0
end
for i in 1...$data_states.size
if $data_states[state_id].plus_state_set.include?(i)
add_state(i)
end
if $data_states[state_id].minus_state_set.include?(i)
remove_state(i)
end
end
@states.sort! do |a, b|
state_a = $data_states[a]
state_b = $data_states[b]
if state_a.rating > state_b.rating
-1
elsif state_a.rating < state_b.rating
+1
elsif state_a.restriction > state_b.restriction
-1
elsif state_a.restriction < state_b.restriction
+1
else
a <=> b
end
end
end
if force
@states_turn[state_id] = -1
end
unless @states_turn[state_id] == -1
@states_turn[state_id] = $data_states[state_id].hold_turn
end
unless movable?
@current_action.clear
end
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
# ------------------------------------
def remove_state(state_id, force = false)
if state?(state_id)
if @states_turn[state_id] == -1 and not force
return
end
if @hp == 0 and $data_states[state_id].zero_hp
@hp = 1
end
@states.delete(state_id)
@states_turn.delete(state_id)
end
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
# ------------------------------------
def state_animation_id
if @states.size == 0
return 0
end
return $data_states[@states[0]].animation_id
end
# ------------------------------------
def restriction
restriction_max = 0
for i in @states
if $data_states[i].restriction >= restriction_max
restriction_max = $data_states[i].restriction
end
end
return restriction_max
end
# ------------------------------------
def cant_get_exp?
for i in @states
if $data_states[i].cant_get_exp
return true
end
end
return false
end
# ------------------------------------
def cant_evade?
for i in @states
if $data_states[i].cant_evade
return true
end
end
return false
end
# ------------------------------------
def slip_damage?
for i in @states
if $data_states[i].slip_damage
return true
end
end
return false
end
# ------------------------------------
def remove_states_battle
for i in @states.clone
if $data_states[i].battle_only
remove_state(i)
end
end
end
# ------------------------------------
def remove_states_auto
for i in @states_turn.keys.clone
if @states_turn[i] > 0
@states_turn[i] -= 1
elsif rand(100) < $data_states[i].auto_release_prob
remove_state(i)
end
end
end
# ------------------------------------
def remove_states_shock
for i in @states.clone
if rand(100) < $data_states[i].shock_release_prob
remove_state(i)
end
end
end
# ------------------------------------
def states_plus(plus_state_set)
effective = false
for i in plus_state_set
unless self.state_guard?(i)
effective |= self.state_full?(i) == false
if $data_states[i].nonresistance
@state_changed = true
add_state(i)
elsif self.state_full?(i) == false
if rand(100) < [0,100,80,60,40,20,0][self.state_ranks[i]]
@state_changed = true
add_state(i)
end
end
end
end
return effective
end
# ------------------------------------
def states_minus(minus_state_set)
effective = false
for i in minus_state_set
effective |= self.state?(i)
@state_changed = true
remove_state(i)
end
return effective
end
end
# ------------------------------------
def skill_can_use?(skill_id)
if $data_skills[skill_id].sp_cost > self.sp
return false
end
if $data_skills[skill_id].atk_f == 0 and self.restriction == 1
return false
end
occasion = $data_skills[skill_id].occasion
if $game_temp.in_battle
return (occasion == 0 or occasion == 1)
else
return (occasion == 0 or occasion == 2)
end
end
# ------------------------------------
def attack_effect(attacker)
self.critical = false
hit_result = (rand(100) < attacker.hit)
if hit_result == true
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (20 + attacker.str) / 20
self.damage *= elements_correct(attacker.element_set)
self.damage /= 100
if self.damage > 0
if rand(100) < 4 * attacker.dex / self.agi
self.damage *= 2
self.critical = true
end
if self.guarding?
self.damage /= 2
end
end
if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
eva = 8 * self.agi / attacker.dex + self.eva
hit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
end
if hit_result == true
remove_states_shock
self.hp -= self.damage
@state_changed = false
states_plus(attacker.plus_state_set)
states_minus(attacker.minus_state_set)
else
self.damage = "Miss"
self.critical = false
end
return true
end
# ------------------------------------
def skill_effect(user, skill)
self.critical = false
if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
return false
end
effective = false
effective |= skill.common_event_id > 0
hit = skill.hit
if skill.atk_f > 0
hit *= user.hit / 100
end
hit_result = (rand(100) < hit)
effective |= hit < 100
if hit_result == true
power = skill.power + user.atk * skill.atk_f / 100
if power > 0
power -= self.pdef * skill.pdef_f / 200
power -= self.mdef * skill.mdef_f / 200
power = [power, 0].max
end
rate = 20
rate += (user.str * skill.str_f / 100)
rate += (user.dex * skill.dex_f / 100)
rate += (user.agi * skill.agi_f / 100)
rate += (user.int * skill.int_f / 100)
self.damage = power * rate / 20
self.damage *= elements_correct(skill.element_set)
self.damage /= 100
if self.damage > 0
if self.guarding?
self.damage /= 2
end
end
if self.damage.abs > 0
amp = [self.damage.abs * skill.variance / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
eva = 8 * self.agi / user.dex + self.eva
hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
effective |= hit < 100
end
if hit_result == true
if skill.power != 0 and skill.atk_f > 0
remove_states_shock
effective = true
end
last_hp = self.hp
self.hp -= self.damage
effective |= self.hp != last_hp
@state_changed = false
effective |= states_plus(skill.plus_state_set)
effective |= states_minus(skill.minus_state_set)
if skill.power == 0
self.damage = ""
unless @state_changed
self.damage = "Miss"
end
end
else
self.damage = "Miss"
end
unless $game_temp.in_battle
self.damage = nil
end
return effective
end
# ------------------------------------
def item_effect(item)
self.critical = false
if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
((item.scope == 5 or item.scope == 6) and self.hp >= 1)
return false
end
effective = false
effective |= item.common_event_id > 0
recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
recover_hp *= elements_correct(item.element_set)
recover_hp /= 100
if recover_hp < 0
recover_hp /= 2
end
self.damage = -recover_hp
last_hp = self.hp
last_sp = self.sp
self.hp += recover_hp
self.sp += recover_sp
effective |= self.hp != last_hp
effective |= self.sp != last_sp
@state_changed = false
effective |= states_plus(item.plus_state_set)
effective |= states_minus(item.minus_state_set)
if item.parameter_type > 0 and item.parameter_points != 0
case item.parameter_type
when 1
@maxhp_plus += item.parameter_points
when 2
@maxsp_plus += item.parameter_points
when 3
@str_plus += item.parameter_points
when 4
@dex_plus += item.parameter_points
when 5
@agi_plus += item.parameter_points
when 6
@int_plus += item.parameter_points
end
effective = true
end
if item.recover_hp_rate == 0 and item.recover_hp == 0
self.damage = ""
if item.recover_sp_rate == 0 and item.recover_sp == 0 and
(item.parameter_type == 0 or item.parameter_points == 0)
unless @state_changed
self.damage = "Miss"
end
end
end
unless $game_temp.in_battle
self.damage = nil
end
return effective
end
# ------------------------------------
def slip_damage_effect
self.damage = self.maxhp / 10
if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
self.hp -= self.damage
return true
end
# ------------------------------------
def elements_correct(element_set)
if element_set == []
return 100
end
weakest = -100
for i in element_set
weakest = [weakest, self.element_rate(i)].max
end
return weakest
end
end
|
Battler_Name: The file name from which the battle image is drawn.
Battler_Hue: The hue modification of the battle image.
HP: The battler's current HP.
SP: The battler's current SP.
States: An array that holds the set of status ailments for the battler.
States_Turn: A hash table. The keys are state IDs, and the values are the number of turns remaining before there is a chance of automatic removal of the status ailment keyed to it each turn. This value is set to -1 if the status ailment keyed to the value is an auto-state inflicted by equipment.
MaxHP_Plus: The increase in the battler's Max HP relative to its base Max HP.
MaxSP_Plus: The increase in the battler's Max SP relative to its base Max SP.
Str_Plus: The increase in the battler's Strength relative to its base Strength.
Dex_Plus: The increase in the battler's Dexterity relative to its base Dexterity.
Agi_Plus: The increase in the battler's Agility relative to its base Agility.
Int_Plus: The increase in the battler's Intelligence relative to its base Intelligence.
Hidden: Describes whether or not the monster is hidden.
Immortal: Describes whether or not the monster can be killed.
Damage_Pop: This flag is set when damage is waiting to be resolved.
Damage: The amount of damage waiting to be resolved.
Critical: This flag is set when a battler has suffered a critical hit.
Animation_ID: The animation ID of the monster's basic attack.
Animation_Hit: If this flag is set, the "hit" variant of the attack or skill animation will be played. If not, then the "miss" variant will play.
White_Flash: This flag is set just before a battler executes an action, to give the player a visual indication of which battler is about to act.
Blink: This flag is set while the game waits for the player to input an actor's command, causing the actor to blink. This flag is never set for monsters.
Current_Action: Holds a Game_BattleAction object describing the battler's current action.
Initialize
Arguments: None
Local Variables: None
How it Works: Sets all the instance variables of the battler object to their default values.
MaxHP
Arguments: None
Local Variables:
n: The composite max HP value returned to the caller.
How it Works: First, this method sets n to the maximum of base_maxhp + @maxhp_plus and 1, and then sets it to the miniumum of that value and 999999. Next, it iterates through the battler's current list of status effects and multiplies n by the Max HP multiplier for that status effect. Finally, the first step is repeated. This result is returned to the caller.
MaxSP
Arguments: None
Local Variables:
n: The composite max SP value returned to the caller.
How it Works: First, this method sets n to the maximum of base_maxsp + @maxsp_plus and 1, and then sets it to the miniumum of that value and 9999. Next, it iterates through the battler's current list of status effects and multiplies n by the Max SP multiplier for that status effect. Finally, the first step is repeated. This result is returned to the caller.
Str
Arguments: None
Local Variables:
n: The composite Strength value returned to the caller.
How it Works: First, this method sets n to the maximum of base_str + @str_plus and 1, and then sets it to the miniumum of that value and 999. Next, it iterates through the battler's current list of status effects and multiplies n by the Strength multiplier for that status effect. Finally, the first step is repeated. This result is returned to the caller.
Dex
Arguments: None
Local Variables:
n: The composite Dexterity value returned to the caller.
How it Works: First, this method sets n to the maximum of base_dex + @dex_plus and 1, and then sets it to the miniumum of that value and 999. Next, it iterates through the battler's current list of status effects and multiplies n by the Dexterity multiplier for that status effect. Finally, the first step is repeated. This result is returned to the caller.
Agi
Arguments: None
Local Variables:
n: The composite Agility value returned to the caller.
How it Works: First, this method sets n to the maximum of base_agi + @agi_plus and 1, and then sets it to the miniumum of that value and 999. Next, it iterates through the battler's current list of status effects and multiplies n by the Agility multiplier for that status effect. Finally, the first step is repeated. This result is returned to the caller.
Int
Arguments: None
Local Variables:
n: The composite Intelligence value returned to the caller.
How it Works: First, this method sets n to the maximum of base_int + @int_plus and 1, and then sets it to the miniumum of that value and 999. Next, it iterates through the battler's current list of status effects and multiplies n by the Intelligence multiplier for that status effect. Finally, the first step is repeated. This result is returned to the caller.
MaxHP=
Arguments:
MaxHP: The new maximum HP value.
Local Variables: None
How it Works: This method indirectly sets the maximum HP value of the battler. The value of @maxhp_plus is set to the new Max HP value minus the battler's base Max HP value. The value of @maxhp_plus is then changed if it isn't between -9999 and 9999. The final step will change @hp if the new maximum HP is lower than the battler's current HP.
MaxSP=
Arguments:
MaxSP: The new maximum SP value.
Local Variables: None
How it Works: This method indirectly sets the maximum SP value of the battler. The value of @maxsp_plus is set to the new Max SP value minus the battler's base Max SP value. The value of @maxsp_plus is then changed if it isn't between -9999 and 9999.
Str=
Arguments:
Str: The new Strength value.
Local Variables: None
How it Works: This method indirectly sets the Strength value of the battler. The value of @str_plus is set to the new Strength value minus the battler's base Strength value. The value of @str_plus is then changed if it isn't between -999 and 999.
Dex=
Arguments:
Dex: The new Dexterity value.
Local Variables: None
How it Works: This method indirectly sets the Dexterity value of the battler. The value of @dex_plus is set to the new Dexterity value minus the battler's base Dexterity value. The value of @dex_plus is then changed if it isn't between -999 and 999.
Agi=
Arguments:
Agi: The new Agility value.
Local Variables: None
How it Works: This method indirectly sets the Agility value of the battler. The value of @agi_plus is set to the new Agility value minus the battler's base Agility value. The value of @agi_plus is then changed if it isn't between -999 and 999.
Int=
Arguments:
Int: The new Intelligence value.
Local Variables: None
How it Works: This method indirectly sets the Intelligence value of the battler. The value of @int_plus is set to the new Intelligence value minus the battler's base Intelligence value. The value of @int_plus is then changed if it isn't between -999 and 999.
Hit
Arguments: None
Local Variables:
n: The hit ratio result returned to the caller.
How it Works: Returns the hit ratio of the battler. n is first set to 100, the default unmodified hit ratio. By default, only status effects can modify this value, so the method iterates through the battler's current status effects and multiplies n by the hit modification of each. Note that the result is multiplicative, rather than additive, so if a battler has two status effects, one that has a 120% hit modifcation and one that has an 80% hit modification, the result will be a hit ratio of 96%.
Atk
Arguments: None
Local Variables:
n: The attack power result returned to the caller.
How it Works: Returns the attack power of the battler. n is first set to the battler's base attack power value. By default, only status effects can modify this value, so the method iterates through the battler's current status effects and multiplies n by the attack power modification of each. Note that the result is multiplicative, rather than additive, so if a battler has two status effects, one that has a 120% attack power modifcation and one that has an 80% attack power modification, the result will be that the battler has 96% of its base attack power.
Pdef
Arguments: None
Local Variables:
n: The physical defense result returned to the caller.
How it Works: Returns the physical defense of the battler. n is first set to the battler's base physical defense value. By default, only status effects can modify this value, so the method iterates through the battler's current status effects and multiplies n by the physical defense modification of each. Note that the result is multiplicative, rather than additive, so if a battler has two status effects, one that has a 120% physical defense modifcation and one that has an 80% physical defense modification, the result will be that the battler has 96% of its base physical defense.
Mdef
Arguments: None
Local Variables:
n: The magic defense result returned to the caller.
How it Works: Returns the magic defense of the battler. n is first set to the battler's base magic defense value. By default, only status effects can modify this value, so the method iterates through the battler's current status effects and multiplies n by the magic defense modification of each. Note that the result is multiplicative, rather than additive, so if a battler has two status effects, one that has a 120% magic defense modifcation and one that has an 80% magic defense modification, the result will be that the battler has 96% of its base magic defense.
Eva
Arguments: None
Local Variables:
n: The evasion result returned to the caller.
How it Works: Returns the evasion value of the battler. n is set to the battler's base evasion value. This value can't be modified by default, so the value is simply returned to the caller.
HP=
Arguments:
HP: The battler's new HP value.
Local Variables: None
How it Works: Changes the battler's current HP. To ensure the new HP value doesn't exceed the battler's max HP value, the HP value is set to the minimum of hp and the battler's max HP. Then, to make sure the result isn't negative, the HP value is set to the maximum of this value and 0. The next part of the method manages status effects that have the "auto-assign at 0 HP" property. If self.dead? returns true, then any status effects that have this property are assigned to the battler. Otherwise, any such status effects are removed from the battler.
SP=
Arguments:
SP: The battler's new SP value.
Local Variables: None
How it Works: Changes the battler's current SP. To ensure the new HP value doesn't exceed the battler's max SP value, the SP value is set to the minimum of sp and the battler's max SP. Then, to make sure the result isn't negative, the SP value is set to the maximum of this value and 0.
Recover_All
Arguments: None
Local Variables: None
How it Works: Completely restores the battler's HP and SP, then removes all status effects, both positive and negative.
Current_Action
Arguments: None
Local Variables: None
How it Works: Returns the Game_BattleAction object that describes the battler's current action.
Make_Action_Speed
Arguments: None
Local Variables: None
How it Works: Gives the action a speed value for determining the order in which actions occur during a turn. By default, the speed of an action can be between agi and agi + (9 + agi / 4). Note that the rand(n) function returns a value between 0 and (n-1).
Dead?
Arguments: None
Local Variables: None
How it Works: Checks whether the battler is dead. If the battler's HP is 0 and the battler's @immortal flag isn't set, then this method returns true.
Exist?
Arguments: None
Local Variables: None
How it Works: Checks whether or not the battler exists. This method returns true if the battler is both unhidden (@hidden == false) and alive hp > 0 or @immortal is true.
HP0?
Arguments: None
Local Variables: None
How it Works: Returns true if the battler is not hidden and its HP is 0.
Inputable?
Arguments: None
Local Variables: None
How it Works: Returns true if the battler can enter commands. This is true if the battler isn't hidden and the battler's restriction from status ailments is either 0 (none) or 1 (magic unusable).
Movable?
Arguments: None
Local Variables: None
How it Works: Returns true if the battler can act at all. This is true if the battler isn't hidden and the battler's restriction from status ailments is not 4 (no action allowed).
Guarding?
Arguments: None
Local Variables: None
How it Works: Returns true if the battler is defending. This is done by referencing the battler's Game_BattleAction object. The battler is defending if both @current_action.kind is 0 (basic action) and @current_action.basic is 1 (defending).
Resting?
Arguments: None
Local Variables: None
How it Works: Returns true if the battler is taking no action. This is done by referencing the battler's Game_BattleAction object. The battler is taking no action if both @current_action.kind is 0 (basic action) and @current_action.basic is 3 (no action).
State?
Arguments:
State_ID: The status ailment to be checked.
Local Variables: None
How it Works: Returns true if the array containing the battler's status ailments contains the status ailment passed to this method.
State_Full?
Arguments:
State_ID: The status ailment to be checked.
Local Variables: None
How it Works: This method checks to see if the battler has the status ailment passed to it AND that status ailment is either an auto-state (the if @states_turn[state_id] == -1 clause) OR the turn count for the status ailment's auto-removal is equal to
$data_states[state_id].hold_turn, the minimum number of turns the status ailment must persist before it has a chance of being automatically removed. If the turn counter is lower than this minimum number of turns (@states_turn counts backwards), then the status ailment can be reinflicted, despite being present, in order to reset the turn count.
Add_State
Arguments:
State_ID: The status ailment to be added.
Force: If this flag is set, then the state being added is an auto-state.
Local Variables: None
How it Works: This method adds a status ailment and attends to all the constituant details associated with adding a status ailment. The first for loop checks to make sure that the state being added wouldn't just be removed by another state that's already present. If it would, then the state won't be added unless the state to be added would remove the offending state(s). Next, if the status ailment isn't already present, it is added with the @states.push(state_id) statement. Once the status ailment is added, the battler's HP is set to 0 if the status ailment has the "auto-assign at HP 0" property. The next for loop takes care of any additional states that need to be added or removed due to the main state's addition. The @states.sort! do |a, b| statement sorts the status ailments by their ratings. Status ailments of the same rating are sorted by greatest restriction (Restriction order: 4 = No action allowed, 3 = Attack Allies Randomly, 2 = Attack Enemies Randomly, 1 = Magic cannot be used, 0 = none) first. The if force clause sets the @states_turn value keyed to the status ailment being added to -1, meaning this status ailment is being automatically added, and can't be removed regardless of the number of turns declared in the status ailment definition. Otherwise, the @states_turn value keyed to the status ailment being added is set equal to $data_states[state_id].hold_turn, which is the mimimum number of turns the status ailment must persist before having a chance of being removed automatically each turn. The unless movable? clause clears the battler's action if the new status has paralyzed the battler. The final statements ensure that the battler's HP and SP are set to legal values given that the battler's Max HP and Max SP may have changed.
Remove_State
Arguments:
State_ID: The status ailment to be removed.
Force: If this flag is set, then the state being removed is an auto-state.
Local Variables: None
How it Works: This method removes a status ailment. If the state is in fact set, then the if @states_turn[state_id] == -1 and not force statement checks to see if the status ailment is an auto-state inflicted by equipment. If it is, then the return statement says that the method should ignore attempts to remove the status ailment by means other than removing the equipment that inflicted it. If the status ailment has the "auto-assign at HP 0" property, the battler's HP is set to 1. Once all that housekeeping is complete, the status ailment itself and its accompanying @states_turn key are deleted from their respective arrays. Because the removal of a status ailment may have changed the battler's Max HP and/or Max SP, the battler's HP and SP are set to legal values.
Animation_ID
Arguments: None
Local Variables: None
How it Works: This method returns the animation ID of the highest-rated status ailment inflicted on this battler. Note that it can return $data_states[@states[0]].animation_id with confidence because the status ailments are sorted by rating each time a new one is added.
Restriction
Arguments: None
Local Variables: None
How it Works: This method returns the strongest restriction of all status ailments inflicted on the battler. The for loop in the body of this method checks each status ailment in @states and compares it to restriction_max. If it is, then the value of the battler's restriction is set to that status ailment's restriction value. The restriction is then returned to the caller.
Cant_Get_Exp?
Arguments: None
Local Variables: None
How it Works: This method returns true if any status ailment in the set of the battler's current status ailment set has the "cannot gain EXP" property.
Cant_Evade?
Arguments: None
Local Variables: None
How it Works: This method returns true if any status ailment in the set of the battler's current status ailment set has the "no evasion allowed" property.
Slip_Damage?
Arguments: None
Local Variables: None
How it Works: This method returns true if any status ailment in the set of the battler's current status ailment set has the "slip damage" property.
Remove_States_Battle
Arguments: None
Local Variables: None
How it Works: This method removes all status ailments which have the "ends after battle" property.
Remove_States_Auto
Arguments: None
Local Variables: None
How it Works: This method first decrements the value of @states_turn[i] for each status ailment in the set of status ailments with which the battler has, unless that value is either 0 (the number of turns before allowing for automatic removal has expired) or -1 (this status ailment is an auto-state). The elsif clause processes that chance for automatic removal by comparing a random number between 0 and 99 to the probability of automatic removal declared in the database. If the number is less than the automatic removal probability, then the status ailment is removed. Note that this comparison will be made even for auto-states, but the remove_state method has code that ignores this, even if the result of the random roll would normally remove the state.
Remove_States_Shock
Arguments: None
Local Variables: None
How it Works: This method processes the chance to remove status ailments that allow for removal by damage. If the random roll is lower than the probability declared in the database, the status ailment is removed.
States_Plus
Arguments:
Plus_State_Set: The status ailment(s) to attempt to add.
Local Variables:
Effective : This flag is set as long as the battler doesn't already have this status ailment. An attempt to add a status ailment can still be "effective", even if none of the status ailments are actually added.
How it Works: While add_state actually adds a status ailment, states_plus merely attempts to add a status ailment. The value of effective is first set to false, then a set of conditions are evaluated in turn. If self.state_guard? is true, due to either a piece of equipment or status ailment protecting the battler from the status ailment, the attempt to add that status ailment fails. If this test is passed, then self.state_full?(i) is evaluated, to see if the battler already has this status ailment. If it does, then the attempt to add this status ailment fails. The innermost if statement
first checks to see whether the status ailment is unresistable. If it is, then the status ailment is inflicted. Otherwise, a random number between 0 and 99 is compared to the battler's status resistance to that status ailment. If the random roll is greater than the resistance value, the status ailment is inflicted. The calls to add_state actually handle the addition of the status ailment.
States_Minus
Arguments:
Minus_State_Set: The status ailment(s) to attempt to remove.
Local Variables:
Effective : This flag is set as long as the battler doesn't already have at least one of the status ailments this method is attempting to remove.
How it Works: While remove_state actually adds a status ailment, states_minus merely attempts to remove a status ailment. The value of effective is first set to false. The method iterates through each status ailment in minus_state_set. If the battler has the status ailment in question, the status ailment is removed with a call to remove_state.
Skill_Can_Use?
Arguments:
Skill_ID: The ID of the skill to check.
Local Variables: None
How it Works: This method checks to see if the battler can use the skill passed to this method. First, the method checks to see if the battler has enough SP available. If the battler does have enough SP, the value of the skill's occasion is checked. The "occasion" of a skill is the value set in the skill declaration which determines when the skill can be used (0 = Both menu and battle, 1 = Battle only, 2 = Menu only, 3 = Unusable). If the occasion matches the current game state, the method returns true.
Attack_Effect
Arguments:
Attacker: The attacking battler.
Local Variables:
Hit_Result: A boolean value that tells whether the attacker hits or not.
Amp: A variable used to randomize the damage dealt.
How it Works: This method processes the effect of an attack. The first thing this method does is see whether the attack hits or not. If hit_result is false, the damage value is set to "Miss" and that's that. The interesting stuff happens when hit_result is true. The first statement, atk = [attacker.atk - self.pdef / 2, 0].max uses the defender's physical defense to mitgate the attacker's attack power directly, which reduces the damage dealt. The next line computes the damage based on the attacker's modified attack power. The algorithm takes 20 plus the attacker's modified attack power and divides it by 20 to get the damage subtotal. The call to elements_correct(attacker.element_set) corrects the damage for the defender's elemental resistances. After that, if the damage is still above zero, the algorithm checks to see if a critical hit has been scored. By default, the chance to get a critical hit is 4% times the ratio of the attacker's dexterity and the defender's agility. If a critical hit is scored, the damage value is doubled and the critical flag is set. Next, if the defender is guarding, the damage is halved. Finally, the damage total is randomized. By default, the damage variance is 15% in either direction.
The next part of the algorithm decides again whether or not a hit occurs, this time based on evasion rather than the attack's hit probability. The basic value of the defender's evasion is 8% times the ratio of the defender's agility to the attacker's dexterity, plus the defender's raw evasion value. The statement hit = self.damage < 0 ? 100 : 100 - eva means that if the damage value is less than 0 (absorption), then the attack will always hit. Otherwise, the chance is 100 - evasion value. The next line addresses whether or not the defender is afflicted with a status ailment that prevents evasion. If so, then the attack automatically hits. A random roll is then made to see if evasion is possible. The if hit_result == true clause processes the actual dealing of damage, removal of status ailments that allow for removal by damage, and the addition or removal of any status ailments that the attacker's weapon causes.
Skill_Effect
Arguments:
User: The user of the skill.
Skill: The skill ID of the skill.
Local Variables:
Effective: A boolean value that determines if the skill is effective.
Hit: The chance for the skill to hit a given target.
Power: The skill's effect rating.
Rate: An aggregate representation of the damage multiplier of the skill based on its Strength, Dexterity, Agility, and Intelligence Influences.
How it Works: The long line that checks the scope of the skill and the HP of the target makes sure that the target of the skill is valid. If the scope of the skill is 3 (One ally of HP 1 or more) or 4 (All allies of HP 1 or more) and the target's HP is 0, or the scope of the skill is 5 (One ally with HP 0) or 6 (All allies with HP 0), the method returns without doing any further processing. The statement effective |= skill.common_event_id > 0 makes it so that the skill will work no matter what if there's a common event associated with its execution. The next part of the method is the first determination of whether the skill hits or not. If the Attack Influence of the skill is 0, then the hit probability of the skill is simply the Accuracy value for the skill. If the Attack Influence is at least 1, the Accuracy value is multiplied by the user's hit percentage. Then, a random roll is compared with the modified hit result. If the hit roll fails, no further processing is done and the skill misses. Otherwise, the skill's effect is processed. If the skill hits, the value of power is first set to the skill's Effect Rating. If the skill has an Attack Influence of more than zero, then x% of the user's attack power is added to power, where x is the Attack Influence of the skill. The next lines mitigate the effects of the skill using Physical and Magical defense, if the skill definition permits. In both cases, the power level of the skill is reduced by one half of one percent of the target's physical/magical defense per point of Physical/Magical Defense Influence of the skill. The final line of this clause makes sure that power level of the skill is no less than 0. The next portion of the method sets the value of rate. The base value is 20. x% of the user's strength is added to rate, where x is the value of the Stength Influence of the skill. This process is repeated for the Dexterity, Agility, and Intelligence Influences. The actual damage the skill deals is then computed as power * rate / 20 and then corrected for the target's elemental resistance, and whether or not the target is defending. The next two sections are identical to their counterparts in the computation of the effect of an attack, except that for skills, the damage randomization procedure uses the variance actually set in the skill declaration rather than a fixed variance of 15%, and the probability of evasion is modified by the skill's Evasion Influence. The second if hit_result == true clause first checks to see if the skill actually dealt damage and the skill's Attack Influence is at least 1. If both of these conditions are true, then the engine processes the chance to remove status ailments by physical damage. The next part of the method checks to see if any status ailments defined in the skill are inflcted and/or removed. The if skill.power == 0 clause checks to see whether the target's status ailment list changed. If it did and the skill's power is 0, no damage value is reported. Otherwise, the damage reported is the string "Miss".
Item_Effect
Arguments:
Item: The item ID of the item.
Local Variables:
Effective: A boolean value that determines if the item is effective.
Recover_HP: The amount of HP recovered.
Recover_SP: The amount of SP recovered.
How it Works: The long line that checks the scope of the item and the HP of the target makes sure that the target of the item is valid. If the scope of the item is 3 (One ally of HP 1 or more) or 4 (All allies of HP 1 or more) and the target's HP is 0, or the scope of the item is 5 (One ally with HP 0) or 6 (All allies with HP 0), the method returns without doing any further processing. The statement effective |= item.common_event_id > 0 makes it so that the item will work no matter what if there's a common event associated with its execution. The next part of this method processes HP and SP recovery from the item. Both statements set the values of their respective recovery varaibles equal to the target's max HP/SP times the percentage recovery declared plus the absolute HP/SP recovery value of the item. Note that HP recovery is affected by elemental resistance if at least one element is set for the item. If the elemental resistance correction makes it so that the item will damage the target instead of heal it, the amount of damage is only half what it normally would be. The next portion of the statement is identical to its counterpart in the skill effect method. It attempts to add and/or remove status ailments declared in the item definition. The if item.parameter_type > 0 and item.parameter_points != 0 clause is unique to items. If the value of item.parameter_type is at least 1 and the value of the increase is at least 0, the appropriate parameter is increased by the value of parameter_points. Values for the parameter are (1 = Max HP, 2 = Max SP, 3 = Strength, 4 = Dexterity, 5 = Agility, 6 = Intelligence). last major clause of the item effect method checks to see what damage value should be reported. If a recovery or damage effect occured, then the damage is reported. If a parameter or status ailment change occured but no damage was dealt, then no damage value is reported. Otherwise, the damage reported is the string "Miss".
Slip_Damage_Effect
Arguments: None
Local Variables: None
How it Works: This method processes the effect of slip damage caused by a status ailment. By default, the amount of this damage is a random amount of HP between 8.5% and 11.5% of the battler's maximum HP per turn. The randomization procedure is the same as for computing the attack effect.
Elements_Correct
Arguments:
Element_Set: An array of the assigned elements of the weapon, skill, or item to be evaluated.
Local Variables:
Weakest: The weakest element in the group. By default, if there are multiple elements in the element set being evaluated, the resistance value that will be used for element correction is the one that will yield the largest damage multiplier.
How it Works: Returns the damage multiplier to be used for elemental resistance correction, expressed as a percentage. If the element set is empty, the method returns 100. Otherwise, the damage multiplier for the element in the set for which the battler has the least resistance will be returned.
|
|