#==============================================================================
#
# D&D Core Rules Engine Ace v1.0
# Written by Kyutaru
# -- Last Updated: 2014.01.15
# -- Level: Easy, Normal
# -- Requires: n/a
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This is the core engine for D&D Core Rules, made for RPG Maker VX Ace.
# This script changes the core battle mechanics to the standard d20 system.
# All the core rules will be in this document. Rules that are overwritten by
# certain class abilities will be in the Class document for that class.
#
# -----------------------------------------------------------------------------
# Hit Rate and Evasion Rate (+Magical Evasion Rate)
# -----------------------------------------------------------------------------
# - In order to accomodate all of the D&D stats, hit rate and evasion rate will
# substitute for Attack Bonus and Armor Class. Effects that boost Strength or
# Dexterity will automatically boost hit chance depending on class. Magical
# Evasion Rate is also used here for ranged or melee touch attacks. Hit rate
# can now exceed 100% so if you are planning on making something immune to
# magic, give it at least three magic evasion features and ensure no magical
# attacks are set to Certain Hit or have perfect hit symphonies. Reflect still
# works as a magic barrier and Counterattack has been replaced with miss chance.
#
# -----------------------------------------------------------------------------
# THAC0 (To Hit Armor Class 0)
# -----------------------------------------------------------------------------
# - Chance to hit is no longer a definite value. It is a comparison of the
# difference between your Hit Rate and the target's Evasion Rate (or for magic
# attacks, the target's Magical Evasion Rate). This value is balanced around
# Armor Class 0, the point at which you have a guaranteed chance to hit (except
# for critical misses). All battlers are assumed to have an armor class of 10
# unless their evasion is adjusted so there will be a 50% chance of hitting an
# enemy with no Hit Rate or Evasion Rate modifications. For creatures with
# negative Attack Bonuses or Armor Class lower than 10, use negative rates.
# Note: by default, Hit Rate is only added to PHYSICAL attacks. Magical attacks
# will only benefit from the ability modifier and proficiency of the user. This
# means any custom effects that boost hit rate directly will NOT affect magical
# hit abilities. This allows you to bless your weapons with improved hit chance
# that doesn't suddenly make your fireball more accurate.
#
# -----------------------------------------------------------------------------
# Critical Miss
# -----------------------------------------------------------------------------
# - Critical misses are represented accurately. No matter how high your chance
# to land a hit becomes, you will always have a 5% chance to miss. For skills
# that have 100% hit rates, use perfect hit symphonies or Certain Hit.
#
# -----------------------------------------------------------------------------
# Critical Hits / Damage
# -----------------------------------------------------------------------------
# - Critical hits are also represented accurately. If you land a hit, the roll
# will be compared to your Critical Chance, which represents your threat range.
# Critical damage is determined by weapon type. You may add more weapon types,
# just copy the scripting and edit the values. Unlike hit and evasion, there is
# no default value for critical chance so make sure all actors are given at
# least 5% crit chance or they will not be able to critically hit. I left this
# feature in case you wanted to disable critical hits entirely.
#
# -----------------------------------------------------------------------------
# Counterattack (CNT) and Ethereal Effects
# -----------------------------------------------------------------------------
# - With Evasion Rate no longer controlling evading, counterattack has been
# removed and now controls ethereal effects (blur, displacement, ghost, etc).
# Simply enter the miss chance into the CNT parameter and it will operate just
# like the old Evasion Rate/Magical Evasion Rate. This will have no effect on
# perfect hit symphonies. Accuracy must be a factor for miss chance to apply.
#
# -----------------------------------------------------------------------------
# Ability Checks and Saving Throws
# -----------------------------------------------------------------------------
# - Abilities are stored in a hash referenced by keys, along with their strings
# and numerical paramater id. You can add more abilities to the hash if you
# want more than six stats. Just ensure each one has its own key and parameter
# reference or you might see weird math occurring. You can use rolld20 to
# perform the roll and add whatever modifiers (including ability) that you see
# fit to add. The method rolld20 also has a built in Advantage and Disadvantage
# mechanic which is optional to use and allows you to grant the user a reroll
# to either keep the higher or lower number. Saving Throws automatically add
# the class proficiency bonus to the GOOD saves of that class as determined by
# the CLASS_TYPE hash (see Class Attributes below). Like rolld20, saving throws
# may have Advantage or Disadvantage. The proper format for saving throws is:
# -- saving_throw(user, item, ability, dc, type="NONE", adv=false, disad=false)
# Where: user = the attacker
# item = the skill or item
# ability = the hash key (colon plus first three letters of ability)
# dc = the Difficulty Class
# Type exists for custom saving throw types such as Mind Affecting, however this
# requires custom scripting within this method to use. There are an infinite
# number of types you can choose so implement your own effects here. To add
# advantage or disadvantage to the check, replace adv or disad with true.
#
# -----------------------------------------------------------------------------
# Class Attributes
# -----------------------------------------------------------------------------
# Special class properties are also defined within the Dragons module. You can
# add new classes by adding more keys, more class id references, and whatever
# attributes you see fit (just add them after existing ones for compability).
# By default, the class attributes given are as follows:
# -- class_id => key, save1, save2, skill mod, attack mod
# Where: class_id = the id number of the class, used as the hash key
# key = the class identification key, used as an identifier
# save1 = the first good save of the class, proficiency is added
# save2 = the second good save of the class, proficiency is added
# skill mod = the modifier used for magical attack hit calculations
# attack mod = the modifier used for physical attack hit calculations
# You can give a class one or none good saves by entering a blank string. The
# skill and attack mods are for skills that use Physical Hit or Magical Hit and
# will not apply to Certain Hit skills. You can also override the attribute
# used for any skill using the note box tag <hit calc: x> where x is the string
# version of the hash key tied to the ability score.
# Example: <hit calc: dex> would make that skill use Dexterity to calculate hit
# chance instead of whatever the class skill/attack mods were. Since weapons
# can also have custom skills for their normal attack using Yanfly's WAR script,
# you can give individual weapons their own attribute for hit chance.
#
# -----------------------------------------------------------------------------
# Weapon and Skill Attacks
# -----------------------------------------------------------------------------
# By default, weapon and skill attacks will use the modifiers associated with
# the class of the attacking actor, one for physical hits and one for magical
# hits. Enemies by default will use Strength to calculate physical hits and
# Intelligence to calculate magical hits. These can all be customized using
# <hit calc: x> tags in the skill or enemy note box. Weapons can be customized
# by first creating a weapon attack skill replacement using Yanfly Engine's
# Weapon Attack Replace script (see script for details). Damage is never
# directly modified for obvious reasons. To modify damage by ability, have the
# attacker object call the mod method with a hash key reference to the ability
# you want to use for damage. This goes into the custom damage formula box.
# Example: a.mod(:str) will add the attacker's strength modifier to the damage.
#
# -----------------------------------------------------------------------------
# Constitution and Hitpoints
# -----------------------------------------------------------------------------
# By default, Constitution will boost or lower the actor's maximum hitpoints.
# Note that this is maximum hitpoints only! You will still need to restore the
# difference with a healing spell. If you do not want Constitution to boost
# hitpoints, search below for the mhp method and comment it out or delete it.
#
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
#
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
# it will run with RPG Maker VX without adjusting.
#
# To make this script work correctly with YEA - Battle Engine Ace, you have to
# put this script before YEA - Battle Engine Ace.
#
#==============================================================================
module Dragons
# Controls the ability checks including saving throws
# Usage = :ability => ["Ability String", paramID]
# Saving throws and ability checks will reference the check variable
# and return the string to be parsed with class saves.
ABILITY_CHECK ={
:str => ["STR", 2], # Strength checks
:ref => ["REF", 6], # Dexterity checks -> Reflexes Checks
:bod => ["BOD", 3], # Constitution checks -> Body Checks
:int => ["INT", 4], # Intelligence checks
:wil => ["WIL", 5], # Wisdom checks -> Willpower Checks
:cha => ["CHA", 7], # Charisma checks
} # Do not remove this.
# This defines the classes and their characteristics, more can be added.
# Saving throws and other checks where class is pertinent will reference
# class_id and return the class array. The array contains all basic stat
# modifiers of the class including the two good saves, the primary ability
# score used for skill DCs, and the score that affects hit chance/damage.
CLASS_TYPE ={
# ID => [ Type, Save1, Save2, Skill, Attack ]
1 => [:wanderer, "REF", "BOD", :int, :ref],
2 => [:streetwarrior, "STR", "BOD", :int, :str],
3 => [:techhead, "REF", "BOD", :int, :ref],
9 => [:securityrobot,"REF", "BOD", :int, :ref],
10 => [:streetwarrior, "STR", "BOD", :int, :str],
12 => [:techhead, "REF", "BOD", :int, :ref],
} # Do not remove this.
# Do not remove this, it's for parsing notetags
HIT_CALC = /<(?:HIT_CALC|hit calc):[ ]*(.*)>/i
#HIT_BONUS = /<(?:HIT_BONUS|hit bonus):[ ](\d+)>/i
end # Dragons
#==============================================================================
# ¡ Game_BattlerBase
#==============================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# * Constants (Starting Number of Buff/Debuff Icons)
#--------------------------------------------------------------------------
ICON_BUFF_START = 10096 # buff (16 icons)
ICON_DEBUFF_START = 10112 # debuff (16 icons)
end # Game_BattlerBase
#==============================================================================
# ¡ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
# This defines the d20 roll mechanic. A separate method is used in order
# to enable special modifiers including Advantage and Disadvantage that
# would be tedious to replicate over and over again. Since this is for
# battlers only, it is located in the Game_Battler class. Attempts to call
# this method from outside of battle may fail.
#--------------------------------------------------------------------------
# * new method: rolld20
#--------------------------------------------------------------------------
def rolld20(advantage=false, disadvantage=false)
roll = 1+rand(20)
# Advantages and Disadvantages cancel each other out
if advantage && disadvantage
return roll
# Advantages are rolled again, keep the higher roll
elsif advantage
roll2 = 1+rand(20)
roll = roll2 if roll2 > roll
# Disadvantages are rolled again, keep the lower roll
elsif disadvantage
roll2 = 1+rand(20)
roll = roll2 if roll2 < roll
end
return roll
end # NEVER remove this!!!
# What would Dungeons and Dragons be without the ability to roll a horde of
# different dice with different numbers of sides and max values?
# Comes with the ability to maximize the dice total, which you can set to a
# variable for custom on-off switching. Returns the total.
#--------------------------------------------------------------------------
# * new method: roll
#--------------------------------------------------------------------------
def roll(quantity=1, sides=100, maximize=false)
total = 0
return quantity * sides if maximize
while quantity > 0
total += 1+rand(sides)
quantity -= 1
end
return total
end
# Returns whether or not the target made its saving throw. The target is
# whatever object called this method. The user is the one attacking the
# target. The ability is the hash key tied to the ability score being saved
# against. The dc is the Difficulty Class of the check, the goal for success.
# Optional saving throw types can be submitted for check customization.
# This facilitates being able to modify the saving throw result according
# to its type (example: if you have +4 vs mind-affecting skills). It also
# allows you to render certain mobs immune to certain types of skills.
# Example: skills of type MIND_AFFECTING might be ineffective vs Undead.
#--------------------------------------------------------------------------
# * new method: saving_throw
#--------------------------------------------------------------------------
def saving_throw(user, ability, dc, type="NONE", adv=false, disad=false)
score = Dragons::ABILITY_CHECK[ability]
roll = rolld20(adv, disad) + mod(ability)
if actor?
save = Dragons::CLASS_TYPE[class_id]
if (save[1]==score[0] or save[2]==score[0]); roll += proficiency; end
end
result = roll >= dc
return result
end
# Sets the difficulty class automatically for typical class skills and spells.
# The default formula is Skill Attribute + Proficiency + 8. You can modify
# the formula here to affect all standard DCs or just use custom DCs when
# calling saving_throw. This is mostly for spellcasting classes. Custom DC
# calls are easily done with a base plus the mod method. This script is ONLY
# intended for Actors. Enemies tend to have set Difficulty Classes that are
# independent of level and gear scaling, use mod for them. If you happen to
# submit an enemy to this method, such as if the skill is used by both actors
# and enemies, the method will calculate the DC as 10 + the enemy's skillmod.
# Note: It is assumed that only skills will call a skillDC method so this
# method will call current_action to get the attacker's skill. Items are
# the other usable base item and they tend to have fixed DC checks.
#--------------------------------------------------------------------------
# * new method: skillDC
#--------------------------------------------------------------------------
def skillDC(user)
item = user.current_action.item
bonus = user.mod(user.skillmod(user.get_hit_calc(user, item)))
if user.enemy? # If it's an enemy, get rid of it with the default calc
dc = 10 + bonus
else # It should be an actor at this point, see below if it fails
dc = 8 + user.proficiency + bonus
end
# The DC will be set at this point. If you have skillDC in the damage
# formula and nothing happens or it comes back as NULL, an error occured.
# Errors in the damage formula will not crash the game so be sure your
# syntax is correct when entering these methods into the damage formula.
return dc
end
# Returns the ability score modifier equivalent to the hash key passed as
# an argument. Hash are defined in the Dragons module. They're simply a
# colon (:) followed by the first three letters of the ability score.
# Example -- :str, :dex, :con, :int, :wis, :cha
#--------------------------------------------------------------------------
# * new method: mod - short for ability modifier
#--------------------------------------------------------------------------
def mod(key)
return (param(Dragons::ABILITY_CHECK[key][1])-10)/2
end
# Returns the key tied to the ability score used by this actor's class for
# physical attacks. This is used in conjuction with the mod(key) method.
# Enemies have no class so they will return a default of Strength as their
# hit modifier. You can override the default modifiers and select your own
# by passing any of the hash keys as an argument. This exists for custom
# scripts that don't use the standard method of calculating hit chance.
# Be warned that the default modifier will affect the hit rate of all enemies.
# To override hitmods by enemy OR by skill, see get_hit_calc below.
#--------------------------------------------------------------------------
# * new method: hitmod - short for ability score that applies to Physical Hit
#--------------------------------------------------------------------------
def hitmod(override=nil)
modifier = :ref
modifier = Dragons::CLASS_TYPE[class_id][4] if actor?
modifier = override unless override==nil
return modifier
end
# Returns the key tied to the ability score used by this actor's class for
# magical attacks. This is used in conjuction with the mod(key) method.
# Enemies have no class so they will return a default of Intelligence as their
# hit modifier. You can override the default modifiers and select your own
# by passing any of the hash keys as an argument. This exists for custom
# scripts that don't use the standard method of calculating hit chance.
# Currently, the skillmod REPLACES the normal hit bonus for magical attacks.
# As magical attacks can be reflected, it is recommended to only use this for
# actual magical attacks that require a chance to hit (not certain hit).
# Instead of normal Armor Class, the defense of the target will be equal to
# a base of 10 plus their magic evasion, making most targets easier to hit.
# To override hitmods by enemy OR by skill, see get_hit_calc below.
#--------------------------------------------------------------------------
# * new method: skillmod - short for ability score that applies to Magic Hit
#--------------------------------------------------------------------------
def skillmod(override=nil)
modifier = :int
modifier = Dragons::CLASS_TYPE[class_id][3] if actor?
modifier = override unless override==nil
return modifier
end
# Default attack bonus is calculated according to one of two attributes.
# Each class has two attributes defined for physical and magical attacks.
# For more complicated attacks or for special attacks that use different
# rulings, use a Certain Hit skill with a custom damage formula with a
# conditional and assign an override. Alternatively, to override individual
# enemies or skills to use a different ability score, see get_hit_calc below.
#--------------------------------------------------------------------------
# * new method: attack_bonus
#--------------------------------------------------------------------------
def attack_bonus(user, item, override=nil)
base = (item_hit(user, item)*20).to_i
base += user.mod(user.hitmod(override)) if item.physical?
base += user.mod(user.skillmod(override)) if item.magical?
if user.actor?; base += user.proficiency; end
return base
end
#--------------------------------------------------------------------------
# * new method: armor_class
#--------------------------------------------------------------------------
def armor_class(user, item)
base = 10 + (item_eva(user, item)*20).to_i
return base
end
#--------------------------------------------------------------------------
# * new method: critical_hit
#--------------------------------------------------------------------------
def critical_hit(user, item)
base = 20 - (item_cri(user, item)*20).to_i
return base
end
# This governs the overrides seen in attack_bonus, hitmod, and skillmod.
# In order to use it, place the following string into the note box of any
# enemy or skill. Actors can already have custom hit formulas by class.
# <hit calc: x> where x = str, dex, con, int, wis, or cha.
# Example: <hit calc: dex> would change the hit modifier to dex for a skill.
# To change the hit modifier for an individual weapon, use the Yanfly Engine
# script Weapon Attack Replace to create a unique skill for that weapon.
# Then you can force that skill to use a different ability modifier.
# Note: this method eventually leads to ABILITY_CHECK in the Dragons module
# so the string key entered into notes must exist as a key there. You can
# add your own custom stats and calculations by adding new keys to the hash.
# Returns the symbol (i.e :dex) associated with the ability modifier.
#--------------------------------------------------------------------------
# * new method: get_hit_calc
#--------------------------------------------------------------------------
def get_hit_calc(user, item)
type = nil
if user.enemy?
type = user.enemy.hit_calc.to_sym unless user.enemy.hit_calc==nil
end
type = item.hit_calc.to_sym unless item.hit_calc==nil
return type
end
#--------------------------------------------------------------------------
# * new method: item_thaco
#--------------------------------------------------------------------------
def item_thaco(user, item, d20)
# New hit formula breaks Certain Hit abilities, this corrects that.
return false if item.hit_type==0
# New hit formula breaks item success rates, this corrects that.
return true if item.success_rate<(rand(100)+1)
if d20 == 20
return false
elsif d20 == 1
return true
return true
end # Simulates critical successes and failures
attackbonus = attack_bonus(user, item, get_hit_calc(user, item))
armorclass = armor_class(user, item)
thaco = d20 + attackbonus
didattackmiss = thaco < armorclass
hit = didattackmiss ? " MISS!" : " HIT!"
return didattackmiss
end
#--------------------------------------------------------------------------
# * overwrite method: item_apply
#--------------------------------------------------------------------------
def item_apply(user, item)
roll = rolld20
@result.clear
@result.used = item_test(user, item)
@result.missed = (@result.used && item_thaco(user, item, roll))
@result.evaded = ([email protected] && rand < cnt)
if @result.hit?
unless item.damage.none?
@result.critical = (roll > critical_hit(user, item))
make_damage_value(user, item)
execute_damage(user)
end
item.effects.each {|effect| item_effect_apply(user, item, effect) }
item_user_effect(user, item)
end
end
#--------------------------------------------------------------------------
# * overwrite method: apply_critical
#--------------------------------------------------------------------------
def apply_critical(damage, user)
type = [0]
if user.actor?; type = user.weapons.collect{|wep| wep.wtype_id}; end
case type[0]
when 8 # These are the weapon types with x3 damage multiplier
damage * 3; else; damage * 2; end
end
#--------------------------------------------------------------------------
# * overwrite method: make_damage_value
#--------------------------------------------------------------------------
def make_damage_value(user, item)
value = item.damage.eval(user, self, $game_variables)
value *= item_element_rate(user, item)
value *= pdr if item.physical?
value *= mdr if item.magical?
value *= rec if item.damage.recover?
value = apply_variance(value, item.damage.variance)
value = apply_guard(value)
@result.make_damage(value.to_i, item)
end
#--------------------------------------------------------------------------
# * overwrite method: item_hit
#--------------------------------------------------------------------------
def item_hit(user, item)
rate = 0.0 # Success rate is now part of thaco
rate += user.hit if item.physical? # Physical Attack Modifier
return rate # Return calculated hit rate
end
#--------------------------------------------------------------------------
# * overwrite method: item_cnt
#--------------------------------------------------------------------------
def item_cnt(user, item)
return 0 # Disables counterattacks, CNT is now used for ethereal effects
end
end # Game_Battler
#==============================================================================
# ¡ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
# Returns the default proficiency calculation for the actor. This is used
# in chance to hit, class saving throws, setting skill DCs, skill checks,
# and calculating the hit bonus on the status screen. If you don't want
# characters to have a proficiency bonus or you want it to be different by
# class, modify this method. Since it's located in Game_Actor, you can pull
# class and level information directly from self.
#--------------------------------------------------------------------------
# * new method: proficiency
#--------------------------------------------------------------------------
def proficiency
return (level+1)/4+1
end
# Behold the Power of Constitution
#--------------------------------------------------------------------------
# * overwrite method: mhp
#--------------------------------------------------------------------------
def mhp; param(0)+(((self.def-10)/2)*5).to_i; end # MHP
end # Game_Actor
#==============================================================================
# ¡ DataManager
#==============================================================================
module DataManager
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
class <<self; alias load_database_hit_calc load_database; end
def self.load_database
load_database_hit_calc
load_notetags_hit_calc
end
#--------------------------------------------------------------------------
# new method: load_notetags_hit_calc
#--------------------------------------------------------------------------
def self.load_notetags_hit_calc
groups = [$data_enemies, $data_skills]
for group in groups
for obj in group
next if obj.nil?
obj.load_notetags_hit_calc
end
end
end
end # DataManager
#==============================================================================
# ¡ RPG::BaseItem
#==============================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :hit_calc
#--------------------------------------------------------------------------
# common cache: load_notetags_war
#--------------------------------------------------------------------------
def load_notetags_hit_calc
#@hit_calc = nil
self.note.split(/[\r\n]+/).each { |line|
case line
when Dragons::HIT_CALC
@hit_calc = $1.to_s
end
}
end
end # RPG::BaseItem