# SETTINGS BEGIN
# Skill ID to perform swap
TAG_SKILL_ID = 1
# Define buddy for each actor
# in format:
#
# actor_id => buddy_actor_id
#
# You don't need to define for all actors, just those who have one.
# You also don't need to define closed loops as exampled below:
# 1 => 7,
# 7 => 1
# as 1 will exclusively swapped with 7 and vice versa.
#
# MAKE SURE an actor has exclusively only one buddy
# so DON'T do this:
# 1 => 5,
# 2 => 6,
# 7 => 1 --> invalid, 1's buddy is 5
# When 5 and 7 is in party, 7 can swap with 1,
# so 1 can join party along with 5!!!
# Also, 5 can no longer be swapped with 1 if they're in one party.
ACTOR_TAG =
{
1 => 5,
2 => 6,
}
# SETTINGS END
class Game_Party
attr_accessor :reserved_actors
alias tag_initialize initialize
def initialize
tag_initialize
@reserved_actors = []
end
def tag_change(actor, skill_cost)
# Buddy will be defined by this point...
buddy = actor.buddy
# Find the position of current actor
for i in 0 ... @actors.size
current_actor = @actors[i]
if current_actor.id == actor.id
actor_index = i
break
end
end
# Now swap actor with buddy
temp_actor = @actors[actor_index]
@actors[actor_index] = buddy
# Delete buddy from reserved actors list
@reserved_actors.delete(buddy)
# Add current actor to reserved actors list
@reserved_actors.push(temp_actor)
# calling from menu?
if $scene.is_a?(Scene_Skill)
$scene = Scene_Menu.new(1)
end
# Refresh player
$game_player.refresh
end
end
class Game_Battler
#--------------------------------------------------------------------------
# * Apply Skill Effects
# user : the one using skills (battler)
# skill : skill
#--------------------------------------------------------------------------
def skill_effect(user, skill)
# Clear critical flag
self.critical = false
# If skill scope is for ally with 1 or more HP, and your own HP = 0,
# or skill scope is for ally with 0, and your own HP = 1 or more
if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
# End Method
return false
end
# Clear effective flag
effective = false
# Set effective flag if common ID is effective
effective |= skill.common_event_id > 0
# First hit detection
hit = skill.hit
if skill.atk_f > 0
hit *= user.hit / 100
end
hit_result = (rand(100) < hit)
# Set effective flag if skill is uncertain
effective |= hit < 100
# If hit occurs
if hit_result == true
# Calculate power
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
# Calculate rate
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)
# Calculate basic damage
self.damage = power * rate / 20
# Element correction
self.damage *= elements_correct(skill.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# Dispersion
if skill.variance > 0 and self.damage.abs > 0
amp = [self.damage.abs * skill.variance / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
# Second hit detection
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)
# Set effective flag if skill is uncertain
effective |= hit < 100
end
# If hit occurs
if hit_result == true
# If physical attack has power other than 0
if skill.power != 0 and skill.atk_f > 0
# State Removed by Shock
remove_states_shock
# Set to effective flag
effective = true
end
# Tag skill performed?
if skill.id == TAG_SKILL_ID
self.damage = 0
$game_party.tag_change(user, skill.sp_cost)
else
# Substract damage from HP
last_hp = self.hp
self.hp -= self.damage
end
effective |= self.hp != last_hp
# State change
@state_changed = false
effective |= states_plus(skill.plus_state_set)
effective |= states_minus(skill.minus_state_set)
# If power is 0
if skill.power == 0
# Set damage to an empty string
self.damage = ""
# If state is unchanged
unless @state_changed
# Set damage to "Miss"
self.damage = "Miss"
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 Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Determine if Skill can be Used
# skill_id : skill ID
#--------------------------------------------------------------------------
def skill_can_use?(skill_id)
if not skill_learn?(skill_id)
return false
elsif skill_id == TAG_SKILL_ID
if buddy == nil
return false
else
# There is any chance that buddy is in party
# Can't use skill if buddy is already in party
for i in 0 ... $game_party.actors.size
if $game_party.actors[i].id == buddy.id
return false
end
end
# Buddy not found, continue
end
end
return super
end
# Return buddy
def buddy
# Has buddy?
if ACTOR_TAG.include?(id)
buddy_id = ACTOR_TAG[id]
elsif ACTOR_TAG.has_value?(id)
buddy_id = ACTOR_TAG.index(id)
else
return nil
end
# Find buddy position
for i in 0 ... $game_party.reserved_actors.size
if $game_party.reserved_actors[i].id == buddy_id
return $game_party.reserved_actors[i]
end
end # end for
# Not found, initialize a new one
return Game_Actor.new(buddy_id)
end
end