I'm working on a battle script that'll take the character's position, as determined by their class, into account in the battle. Now, while I have the variable pulling just fine, the script only works half right.
What works is the defender's position. If they're in the middle or rear position, they take the lowered damage (80% or 60%, respectively). However, they still deal normal damage, not the desired 80%/60%.
Here's what I've got for my damage calculation snippet (I marked where the position damage correction starts and ends):
def attack_effect(attacker)
# Clear critical flag
self.critical = false
# First hit detection
hit_result = (rand(100) < (attacker.hit + (attacker.dex / self.agi) * 40))
# If hit occurs
if hit_result == true
# Calculate basic damage
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (2 + attacker.str) / 2
# Element correction
self.damage *= elements_correct(attacker.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Critical correction
if rand(100) < 4 * attacker.dex / self.agi
self.damage *= 2
self.critical = true
end
# Guard correction
if self.guarding?
self.damage /= 2
end
# Attacker position correction // This is the start of the position correction
if attacker.position == 1 //
self.damage *= 80 //
self.damage /= 100 //
elsif attacker.position == 2 //
self.damage *= 60 //
self.damage /= 100 //
end //
# Defender position correction //
if self.position == 1 //
self.damage *= 80 //
self.damage /= 100 //
elsif self.position == 2 //
self.damage *= 60 //
self.damage /= 100 //
end // This is the end of the position correction
end
# Dispersion
if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
# Second hit detection
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 occurs
if hit_result == true
# State Removed by Shock
remove_states_shock
# Substract damage from HP
self.hp -= self.damage
# State change
@state_changed = false
states_plus(attacker.plus_state_set)
states_minus(attacker.minus_state_set)
# When missing
else
# Set damage to "Miss"
self.damage = "Miss"
# Clear critical flag
self.critical = false
end
# End Method
return true
end
Any help as to why the damage portion of the snippet isn't working would be greatly appreciated. Oh, and in case it helps, here's how I pulled the position variable:
def position
n = @position
return n
end
Thanks in advance!