25/03/08 - MGCaladtogel
#==============================================================================
# ** Game_Battler
#==============================================================================
class Game_Battler
attr_accessor :protectors
attr_accessor :protected
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias initialize_protect initialize
def initialize
initialize_protect
self.protectors = Array.new
self.protected = false
end
#--------------------------------------------------------------------------
# * add_protector
# member : Game_Battler (protector)
#--------------------------------------------------------------------------
def add_protector(battler)
self.protectors.push(battler)
end
#--------------------------------------------------------------------------
# * remove_protector
# member : Game_Enemy (protector)
#--------------------------------------------------------------------------
def remove_protector(battler)
self.protectors.delete(battler)
end
#--------------------------------------------------------------------------
# * protected?
#--------------------------------------------------------------------------
def protected?
result = false
if protectors.size > 0
for battler in protectors
battler.dead? ? remove_protector(battler) : result = true
end
end
return result
end
#--------------------------------------------------------------------------
# * select_protector
#--------------------------------------------------------------------------
def select_protector
protector = protectors[rand(protectors.size)]
end
#--------------------------------------------------------------------------
# * Add State
# state_id : state ID
# force : forcefully added flag (used to deal with auto state)
#--------------------------------------------------------------------------
alias add_state_protect add_state
def add_state(state_id, force = false)
add_state_protect(state_id, force)
if $data_states[state_id].name.include?("Protected")
self.protected = true
end
if $data_states[state_id].name.include?("Protection")
if self.is_a?(Game_Enemy)
for enemy in $game_troop.enemies
enemy.add_protector(self) if enemy.protected
end
else
for actor in $game_party.actors
actor.add_protector(self) if actor.protected
end
end
end
end
#--------------------------------------------------------------------------
# * Remove State
# state_id : state ID
# force : forcefully removed flag (used to deal with auto state)
#--------------------------------------------------------------------------
alias remove_state_protect remove_state
def remove_state(state_id, force = false)
remove_state_protect(state_id, force)
if $data_states[state_id].name.include?("Protected")
self.protected = false
end
if $data_states[state_id].name.include?("Protection")
if self.is_a?(Game_Enemy)
for enemy in $game_troop.enemies
enemy.remove_protector(self)
end
else
for actor in $game_party.actors
actor.remove_protector(self)
end
end
end
end
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Make Basic Action Results
#--------------------------------------------------------------------------
def make_basic_action_result
# If attack
if @active_battler.current_action.basic == 0
# Set anaimation ID
@animation1_id = @active_battler.animation1_id
@animation2_id = @active_battler.animation2_id
# If action battler is enemy
if @active_battler.is_a?(Game_Enemy)
if @active_battler.restriction == 3
target = $game_troop.random_target_enemy
elsif @active_battler.restriction == 2
target = $game_party.random_target_actor
else
index = @active_battler.current_action.target_index
target = $game_party.smooth_target_actor(index)
end
end
# If action battler is actor
if @active_battler.is_a?(Game_Actor)
if @active_battler.restriction == 3
target = $game_party.random_target_actor
elsif @active_battler.restriction == 2
target = $game_troop.random_target_enemy
else
index = @active_battler.current_action.target_index
target = $game_troop.smooth_target_enemy(index)
end
end
# Set array of targeted battlers
@target_battlers = [target]
# Apply normal attack results
for target in @target_battlers
if target.protected?
new_target = target.select_protector
@target_battlers.push(new_target) if !@target_battlers.include?(new_target)
@target_battlers.delete(target)
@help_window.set_text(new_target.name + " protected " + target.name, 1)
end
end
for target in @target_battlers
target.attack_effect(@active_battler)
end
return
end
# If guard
if @active_battler.current_action.basic == 1
# Display "Guard" in help window
@help_window.set_text($data_system.words.guard, 1)
return
end
# If escape
if @active_battler.is_a?(Game_Enemy) and
@active_battler.current_action.basic == 2
# Display "Escape" in help window
@help_window.set_text("Escape", 1)
# Escape
@active_battler.escape
return
end
# If doing nothing
if @active_battler.current_action.basic == 3
# Clear battler being forced into action
$game_temp.forcing_battler = nil
# Shift to step 1
@phase4_step = 1
return
end
end
#--------------------------------------------------------------------------
# * Make Skill Action Results
#--------------------------------------------------------------------------
def make_skill_action_result
# Get skill
@skill = $data_skills[@active_battler.current_action.skill_id]
# If not a forcing action
unless @active_battler.current_action.forcing
# If unable to use due to SP running out
unless @active_battler.skill_can_use?(@skill.id)
# Clear battler being forced into action
$game_temp.forcing_battler = nil
# Shift to step 1
@phase4_step = 1
return
end
end
# Use up SP
@active_battler.sp -= @skill.sp_cost
# Refresh status window
@status_window.refresh
# Show skill name on help window
@help_window.set_text(@skill.name, 1)
# Set animation ID
@animation1_id = @skill.animation1_id
@animation2_id = @skill.animation2_id
# Set command event ID
@common_event_id = @skill.common_event_id
# Set target battlers
set_target_battlers(@skill.scope)
# Apply skill effect
for target in @target_battlers
if target.protected?
new_target = target.select_protector
@target_battlers.push(new_target) if !@target_battlers.include?(new_target)
@target_battlers.delete(target)
@help_window.set_text(new_target.name + " protected " + target.name, 1)
end
end
for target in @target_battlers
target.skill_effect(@active_battler, @skill)
end
end
#--------------------------------------------------------------------------
# * Make Item Action Results
#--------------------------------------------------------------------------
def make_item_action_result
# Get item
@item = $data_items[@active_battler.current_action.item_id]
# If unable to use due to items running out
unless $game_party.item_can_use?(@item.id)
# Shift to step 1
@phase4_step = 1
return
end
# If consumable
if @item.consumable
# Decrease used item by 1
$game_party.lose_item(@item.id, 1)
end
# Display item name on help window
@help_window.set_text(@item.name, 1)
# Set animation ID
@animation1_id = @item.animation1_id
@animation2_id = @item.animation2_id
# Set common event ID
@common_event_id = @item.common_event_id
# Decide on target
index = @active_battler.current_action.target_index
target = $game_party.smooth_target_actor(index)
# Set targeted battlers
set_target_battlers(@item.scope)
# Apply item effect
for target in @target_battlers
if target.protected?
new_target = target.select_protector
@target_battlers.push(new_target) if !@target_battlers.include?(new_target)
@target_battlers.delete(target)
@help_window.set_text(new_target.name + " protected " + target.name, 1)
end
end
for target in @target_battlers
target.item_effect(@item)
end
end
end
#==============================================================================
# ** Window_Base
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Make State Text String for Drawing
# actor : actor
# width : draw spot width
# need_normal : Whether or not [normal] is needed (true / false)
#--------------------------------------------------------------------------
def make_battler_state_text(battler, width, need_normal)
# Get width of brackets
brackets_width = self.contents.text_size("[]").width
# Make text string for state names
text = ""
for i in battler.states
if $data_states[i].rating >= 1 and !$data_states[i].name.include?("Protection") and
!$data_states[i].name.include?("Protected")
if text == ""
text = $data_states[i].name
else
new_text = text + "/" + $data_states[i].name
text_width = self.contents.text_size(new_text).width
if text_width > width - brackets_width
break
end
text = new_text
end
end
end
# If text string for state names is empty, make it [normal]
if text == ""
if need_normal
text = "[Normal]"
end
else
# Attach brackets
text = "[" + text + "]"
end
# Return completed text string
return text
end
end