Ещё один скрипт, реализующий возможности Эйса в XP. Позволяет задать произвольные формулы для расчёта эффективности атак и навыков. Все эти формулы прописываются в шапке скрипта в виде текстовых строк.
=begin
Скрипт, позволяющий задать произвольные формулы для расчёта
эффективности атаки и умений.
Автор - Cerberus
=end
module CustomFormula
=begin
Настройка скрипта: формулы записываются как строки.
Для простой атаки attacker - атакующий, self - атакуемый.
Для умения user - применяющий, self - цель.
=end
# Урон простой атаки
ATTACK_DAMAGE = "attacker.atk"
# Модификатор урона от силы (atk - результат вычислений по прошлой формуле)
ATTACK_STRENGTH_MODIFIER = "atk * attacker.str / 100"
# Вероятность критического удара (в процентах)
CRITICAL_RATE = "attacker.dex / self.agi"
# Эффективность критического удара (self.damage - исходный урон)
CRITICAL_POWER = "self.damage * 2"
# Величина разброса урона (self.damage.abs - исходный урон)
ATTACK_DISPERSION = "self.damage.abs * attacker.str / (attacker.dex * 10)"
# Вероятность уклонения от атаки (в процентах)
EVADE_RATE = "8 * self.agi / attacker.dex + self.eva"
# Базовая эффективность навыка
SKILL_POWER = "skill.power + user.atk * skill.atk_f / 100"
# Ослабление навыка защитой (power - результат вычислений по прошлой формуле)
# Влияет только на навыки, наносящие урон (не лечебные)
SKILL_DEFENCE = "power - self.pdef * skill.pdef_f / 200 - self.mdef * skill.mdef_f / 200"
# Множитель силы навыка (применяется к результату вычислений по прошлой формуле)
SKILL_RATE = "(20 + (user.str * skill.str_f / 100) + (user.dex * skill.dex_f / 100) + (user.agi * skill.agi_f / 100) + (user.int * skill.int_f / 100)) / 20"
# Вероятность уклониться от навыка (в процентах)
SKILL_EVADE_RATE = "8 * self.agi / user.dex + self.eva"
end
#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# This class deals with battlers. It's used as a superclass for the Game_Actor
# and Game_Enemy classes.
#==============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# * Applying Normal Attack Effects
# attacker : battler
#--------------------------------------------------------------------------
def attack_effect(attacker)
# Clear critical flag
self.critical = false
# First hit detection
hit_result = (rand(100) < attacker.hit)
# If hit occurs
if hit_result == true
# Calculate basic damage
atk = [eval(CustomFormula::ATTACK_DAMAGE), 0].max
self.damage = eval(CustomFormula::ATTACK_STRENGTH_MODIFIER)
# 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) < eval(CustomFormula::CRITICAL_RATE)
self.damage = eval(CustomFormula::CRITICAL_POWER)
self.critical = true
end
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# Dispersion
if self.damage.abs > 0
amp = eval(CustomFormula::ATTACK_DISPERSION)
# здесь мы добавили условие, чтобы избежать вызова rand(1)
self.damage += rand(amp+1) + rand(amp+1) - amp unless amp==0
end
# Second hit detection
eva = eval(CustomFormula::EVADE_RATE)
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
#--------------------------------------------------------------------------
# * 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 = eval(CustomFormula::SKILL_POWER)
if power > 0
power = eval(CustomFormula::SKILL_DEFENCE)
power = [power, 0].max
end
# Calculate rate
rate = eval(CustomFormula::SKILL_RATE)
# Calculate basic damage
self.damage = power * rate
# 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 = eval(CustomFormula::SKILL_EVADE_RATE)
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
# Substract damage from HP
last_hp = self.hp
self.hp -= self.damage
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