=begin
#===============================================================================
Title: Skill Formulas
Author: Hime
Date: Mar 9, 2013
--------------------------------------------------------------------------------
** Change log
Mar 9, 2013
- Initial release
--------------------------------------------------------------------------------
** Terms of Use
* Free to use in non-commercial projects
* Contact me for commercial use
* No real support. The script is provided as-is
* Will do bug fixes, but no compatibility patches
* Features may be requested but no guarantees, especially if it is non-trivial
* Credits to Hime Works in your project
* Preserve this header
--------------------------------------------------------------------------------
** Description
This script provides support for many different custom formulas related
to skills/items
--------------------------------------------------------------------------------
** Usage
All formulas are ruby strings. They must evaluate to a number.
The following variables are available for the formulas
a - the user
b - the target
base - some base value calculated from other scripts
v - the game variables
Note: the final hit-rate of a skill is calculated as the chance to hit,
multiplied by the chance of the target not evading. Mathematically, this
is given by P(Hit) * (1 - P(Evade)). keep this in mind when fine-tuning
your skill's hit rate
-- Hit formula --
The hit formula gives the chance that the user will successfully hit the target.
To specify a hit formula, use the notetag
<hit formula: FORMULA>
-- Evade formula --
The evade formula gives the chance that the target will successfully dodge
the attack. Keep in mind that physical attacks use the `eva` xstat, while
magical attacks use the `mev` xstat.
To specify an evade formula, use the notetag
<eva formula: FORMULA>
#===============================================================================
=end
$imported = {} if $imported.nil?
$imported["TH_SkillFormulas"] = true
#===============================================================================
# ** Configuration
#===============================================================================
module TH
module Skill_Formulas
# The default hit formula to use. Just the base hit rate
Default_Hit_Formula = "base"
# The default evade formula to use. Just the base evade rate.
Default_Eva_Formula = "base"
Hit_Rate_Regex = /<hit formula: (.*)>/im
Eva_Rate_Regex = /<eva formula: (.*)>/im
end
end
module RPG
class UsableItem < BaseItem
def hit_rate_formula
return @hit_rate_formula unless @hit_rate_formula.nil?
@hit_rate_formula = self.note =~ TH::Skill_Formulas::Hit_Rate_Regex ? $1.gsub("\r\n", "") : TH::Skill_Formulas::Default_Hit_Formula
return @hit_rate_formula
end
def eva_rate_formula
return @eva_rate_formula unless @eva_rate_formula.nil?
@eva_rate_formula = self.note =~ TH::Skill_Formulas::Eva_Rate_Regex ? $1 : TH::Skill_Formulas::Default_Eva_Formula
return @eva_rate_formula
end
end
end
class Game_Battler < Game_BattlerBase
#-----------------------------------------------------------------------------
# The old method returns the base hit rate, which is the chance to hit
# the target. You can then add modifiers to the evade hit rate.
#-----------------------------------------------------------------------------
alias :th_skill_formulas_item_hit :item_hit
def item_hit(user, item)
base_hitrate = th_skill_formulas_item_hit(user, item)
rate = eval_hit_formula(item.hit_rate_formula, user, self, base_hitrate, $game_variables)
end
#-----------------------------------------------------------------------------
# The old method returns the base evade rate, which is the chance to
# evade an skill/item. You can add modifiers to the base evade rate.
#-----------------------------------------------------------------------------
alias :th_skill_formulas_item_eva :item_eva
def item_eva(user, item)
base_evarate = th_skill_formulas_item_eva(user, item)
return eval_eva_formula(item.eva_rate_formula, user, self, base_evarate, $game_variables)
end
#-----------------------------------------------------------------------------
# Evaluates hit rate using hit rate formula. The base hit-rate is given by
# the success to hit and the user's hit rate.
#-----------------------------------------------------------------------------
def eval_hit_formula(formula, a, b, base, v)
Kernel.eval(formula)
end
#-----------------------------------------------------------------------------
# Evaluates evade rate using evade rate formula. The base evade rate is given
# by the user's evade rate based on the type of damage (physical or magical)
#-----------------------------------------------------------------------------
def eval_eva_formula(formula, a, b, base, v)
Kernel.eval(formula)
end
end