class Game_Battler
#--------------------------------------------------------------------------
# * Get Maximum SP
#--------------------------------------------------------------------------
def maxsp
return 100
end
#--------------------------------------------------------------------------
# * Set Maximum SP
# maxsp : new maximum SP
#--------------------------------------------------------------------------
def maxsp=(maxsp)
@maxsp = 100
end
#--------------------------------------------------------------------------
# * Decide Incapacitation
#--------------------------------------------------------------------------
def dead?
return ((@hp == 0 or @sp == 0) and not @immortal)
end
#--------------------------------------------------------------------------
# * Decide Existance
#--------------------------------------------------------------------------
def exist?
return (not @hidden and (@hp > 0 and @sp > 0 or @immortal))
end
#--------------------------------------------------------------------------
# * Decide HP 0
#--------------------------------------------------------------------------
def hp0?
return (not @hidden and (@hp == 0))
end
#--------------------------------------------------------------------------
# * Decide SP 0
#--------------------------------------------------------------------------
def sp0?
return (not @hidden and (@sp == 0))
end
#--------------------------------------------------------------------------
# * Change SP
# sp : new SP
#--------------------------------------------------------------------------
def sp=(sp)
@sp = [[sp, maxsp].min, 0].max
# add or exclude incapacitation
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
#--------------------------------------------------------------------------
# * Add State
# state_id : state ID
# force : forcefully added flag (used to deal with auto state)
#--------------------------------------------------------------------------
def add_state(state_id, force = false)
# For an ineffective state
if $data_states[state_id] == nil
# End Method
return
end
# If not forcefully added
unless force
# A state loop already in existance
for i in @states
# If a new state is included in the state change (-) of an existing
# state, and that state is not included in the state change (-) of
# a new state (example: an attempt to add poison during dead)
if $data_states[i].minus_state_set.include?(state_id) and
not $data_states[state_id].minus_state_set.include?(i)
# End Method
return
end
end
end
# If this state is not added
unless state?(state_id)
# Add state ID to @states array
@states.push(state_id)
# If option [regarded as HP 0]is effective
if $data_states[state_id].zero_hp
# Change HP to 0
@hp = 0 if self.hp0?
@sp = 0 if self.sp0?
end
# All state loops
for i in 1...$data_states.size
# Dealing with a state change (+)
if $data_states[state_id].plus_state_set.include?(i)
add_state(i)
end
# Dealing with a state change (-)
if $data_states[state_id].minus_state_set.include?(i)
remove_state(i)
end
end
# line change to a large rating order (if value is the same, then a
# strong restriction order)
@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 added forcefully
if force
# Set the natural removal's lowest number of turns to -1
@states_turn[state_id] = -1
end
# If not added forcefully
unless @states_turn[state_id] == -1
# Set the natural removal's lowest number of turns
@states_turn[state_id] = $data_states[state_id].hold_turn
end
# If unable to move
unless movable?
# Clear action
@current_action.clear
end
# Check the maximum value of HP and SP
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
#--------------------------------------------------------------------------
# * Remove State
# state_id : state ID
# force : forcefully removed flag (used to deal with auto state)
#--------------------------------------------------------------------------
def remove_state(state_id, force = false)
# If this state is added
if state?(state_id)
# If a forcefully added state is not forcefully removed
if @states_turn[state_id] == -1 and not force
# End Method
return
end
# If current HP is at 0 and options are effective [regarded as HP 0]
if (@hp == 0 or @sp == 0) and $data_states[state_id].zero_hp
# Determine if there's another state [regarded as HP 0] or not
zero_hp = false
for i in @states
if i != state_id and $data_states[i].zero_hp
zero_hp = true
end
end
# Change HP to 1 if OK to remove incapacitation.
if zero_hp == false
@hp = 1 if self.hp0?
@sp = 1 if self.sp0?
end
end
# Delete state ID from @states and @states_turn hash array
@states.delete(state_id)
@states_turn.delete(state_id)
end
# Check maximum value for HP and SP
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
#--------------------------------------------------------------------------
# * Determine Usable Skills
# skill_id : skill ID
#--------------------------------------------------------------------------
def skill_can_use?(skill_id)
# Unusable if incapacitated
if dead?
return false
end
# If silent, only physical skills can be used
if $data_skills[skill_id].atk_f == 0 and self.restriction == 1
return false
end
# Get usable time
occasion = $data_skills[skill_id].occasion
# If in battle
if $game_temp.in_battle
# Usable with [Normal] and [Only Battle]
return (occasion == 0 or occasion == 1)
# If not in battle
else
# Usable with [Normal] and [Only Menu]
return (occasion == 0 or occasion == 2)
end
end
alias fp_attack_effect attack_effect
def attack_effect(attacker)
fp_attack_effect(attacker)
attacker.sp -= 1
end
#--------------------------------------------------------------------------
# * Application of Item Effects
# item : item
#--------------------------------------------------------------------------
def item_effect(item)
# Clear critical flag
self.critical = false
# If item scope is for ally with 1 or more HP, and your own HP = 0,
# or item scope is for ally with 0 HP, and your own HP = 1 or more
if ((item.scope == 3 or item.scope == 4) and (self.hp == 0 or self.sp == 0)) or
((item.scope == 5 or item.scope == 6) and (self.hp >= 1 and self.sp >= 1))
# End Method
return false
end
# Clear effective flag
effective = false
# Set effective flag if common ID is effective
effective |= item.common_event_id > 0
# Determine hit
hit_result = (rand(100) < item.hit)
# Set effective flag is skill is uncertain
effective |= item.hit < 100
# If hit occurs
if hit_result == true
# Calculate amount of recovery
recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
if recover_hp < 0
recover_hp += self.pdef * item.pdef_f / 20
recover_hp += self.mdef * item.mdef_f / 20
recover_hp = [recover_hp, 0].min
end
# Element correction
recover_hp *= elements_correct(item.element_set)
recover_hp /= 100
recover_sp *= elements_correct(item.element_set)
recover_sp /= 100
# Dispersion
if item.variance > 0 and recover_hp.abs > 0
amp = [recover_hp.abs * item.variance / 100, 1].max
recover_hp += rand(amp+1) + rand(amp+1) - amp
end
if item.variance > 0 and recover_sp.abs > 0
amp = [recover_sp.abs * item.variance / 100, 1].max
recover_sp += rand(amp+1) + rand(amp+1) - amp
end
# If recovery code is negative
if recover_hp < 0
# Guard correction
if self.guarding?
recover_hp /= 2
end
end
# Set damage value and reverse HP recovery amount
self.damage = -recover_hp
# HP and SP recovery
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 change
@state_changed = false
effective |= states_plus(item.plus_state_set)
effective |= states_minus(item.minus_state_set)
# If parameter value increase is effective
if item.parameter_type > 0 and item.parameter_points != 0
# Branch by parameter
case item.parameter_type
when 1 # Max HP
@maxhp_plus += item.parameter_points
when 2 # Max SP
@maxsp_plus += item.parameter_points
when 3 # Strength
@str_plus += item.parameter_points
when 4 # Dexterity
@dex_plus += item.parameter_points
when 5 # Agility
@agi_plus += item.parameter_points
when 6 # Intelligence
@int_plus += item.parameter_points
end
# Set to effective flag
effective = true
end
# If HP recovery rate and recovery amount are 0
if item.recover_hp_rate == 0 and item.recover_hp == 0
# Set damage to empty string
self.damage = ""
# If SP recovery rate / recovery amount are 0, and parameter increase
# value is ineffective.
if item.recover_sp_rate == 0 and item.recover_sp == 0 and
(item.parameter_type == 0 or item.parameter_points == 0)
# If state is unchanged
unless @state_changed
# Set damage to "Miss"
self.damage = "Miss"
end
end
end
# If miss occurs
else
# Set damage to "Miss"
self.damage = "Miss"
end
# If not in battle
unless $game_temp.in_battle
# Set damage to nil
self.damage = nil
end
# End Method
return effective
end
end
class Scene_Battle
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Initialize each kind of temporary battle data
$game_temp.in_battle = true
$game_temp.battle_turn = 0
$game_temp.battle_event_flags.clear
$game_temp.battle_abort = false
$game_temp.battle_main_phase = false
$game_temp.battleback_name = $game_map.battleback_name
$game_temp.forcing_battler = nil
# Initialize battle event interpreter
$game_system.battle_interpreter.setup(nil, 0)
# Prepare troop
@troop_id = $game_temp.battle_troop_id
$game_troop.setup(@troop_id)
# Make actor command window
s1 = $data_system.words.attack
s2 = $data_system.words.skill
s3 = $data_system.words.guard
s4 = $data_system.words.item
s5 = "Rest"
@actor_command_window = Window_Command.new(160, [s1, s2, s3, s5, s4])
@actor_command_window.y = 128
@actor_command_window.back_opacity = 160
@actor_command_window.active = false
@actor_command_window.visible = false
# Make other windows
@party_command_window = Window_PartyCommand.new
@help_window = Window_Help.new
@help_window.back_opacity = 160
@help_window.visible = false
@status_window = Window_BattleStatus.new
@message_window = Window_Message.new
# Make sprite set
@spriteset = Spriteset_Battle.new
# Initialize wait count
@wait_count = 0
# Execute transition
if $data_system.battle_transition == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$data_system.battle_transition)
end
# Start pre-battle phase
start_phase1
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Refresh map
$game_map.refresh
# Prepare for transition
Graphics.freeze
# Dispose of windows
@actor_command_window.dispose
@party_command_window.dispose
@help_window.dispose
@status_window.dispose
@message_window.dispose
if @skill_window != nil
@skill_window.dispose
end
if @item_window != nil
@item_window.dispose
end
if @result_window != nil
@result_window.dispose
end
# Dispose of sprite set
@spriteset.dispose
# If switching to title screen
if $scene.is_a?(Scene_Title)
# Fade out screen
Graphics.transition
Graphics.freeze
end
# If switching from battle test to any screen other than game over screen
if $BTEST and not $scene.is_a?(Scene_Gameover)
$scene = nil
end
end
def update_phase3_basic_command
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Go to command input for previous actor
phase3_prior_actor
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by actor command window cursor position
case @actor_command_window.index
when 0 # attack
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Set action
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
# Start enemy selection
start_enemy_select
when 1 # skill
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Set action
@active_battler.current_action.kind = 1
# Start skill selection
start_skill_select
when 2 # guard
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Set action
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 1
# Go to command input for next actor
phase3_next_actor
when 3 # rest
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Set action
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 4
# Go to command input for next actor
phase3_next_actor
when 4 # item
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Set action
@active_battler.current_action.kind = 2
# Start item selection
start_item_select
end
return
end
end
alias fp_make_basic_action_result make_basic_action_result
def make_basic_action_result
# If guard
if @active_battler.current_action.basic == 4
# Display "Guard" in help window
@help_window.set_text("Resting", 1)
@active_battler.damage = -50
@active_battler.white_flash = true
@active_battler.damage_pop = true
@active_battler.sp += 50
@phase4_step = 1
return
end
fp_make_basic_action_result
end
#--------------------------------------------------------------------------
# * Set Targeted Battler for Skill or Item
# scope : effect scope for skill or item
#--------------------------------------------------------------------------
def set_target_battlers(scope)
# If battler performing action is enemy
if @active_battler.is_a?(Game_Enemy)
# Branch by effect scope
case scope
when 1 # single enemy
index = @active_battler.current_action.target_index
@target_battlers.push($game_party.smooth_target_actor(index))
when 2 # all enemies
for actor in $game_party.actors
if actor.exist?
@target_battlers.push(actor)
end
end
when 3 # single ally
index = @active_battler.current_action.target_index
@target_battlers.push($game_troop.smooth_target_enemy(index))
when 4 # all allies
for enemy in $game_troop.enemies
if enemy.exist?
@target_battlers.push(enemy)
end
end
when 5 # single ally (HP 0)
index = @active_battler.current_action.target_index
enemy = $game_troop.enemies[index]
if enemy != nil and enemy.hp0?
@target_battlers.push(enemy)
end
when 6 # all allies (HP 0)
for enemy in $game_troop.enemies
if enemy != nil and enemy.hp0?
@target_battlers.push(enemy)
end
end
when 7 # user
@target_battlers.push(@active_battler)
end
end
# If battler performing action is actor
if @active_battler.is_a?(Game_Actor)
# Branch by effect scope
case scope
when 1 # single enemy
index = @active_battler.current_action.target_index
@target_battlers.push($game_troop.smooth_target_enemy(index))
when 2 # all enemies
for enemy in $game_troop.enemies
if enemy.exist?
@target_battlers.push(enemy)
end
end
when 3 # single ally
index = @active_battler.current_action.target_index
@target_battlers.push($game_party.smooth_target_actor(index))
when 4 # all allies
for actor in $game_party.actors
if actor.exist?
@target_battlers.push(actor)
end
end
when 5 # single ally (HP 0)
index = @active_battler.current_action.target_index
actor = $game_party.actors[index]
if actor != nil and actor.hp0? or actor.sp0?
@target_battlers.push(actor)
end
when 6 # all allies (HP 0)
for actor in $game_party.actors
if actor != nil and actor.hp0? or actor.sp0?
@target_battlers.push(actor)
end
end
when 7 # user
@target_battlers.push(@active_battler)
end
end
end
end