Last active
June 12, 2016 09:02
-
-
Save StevenLeonCooper/b00c63d798a10ce6d94d1edaecc3ee1f to your computer and use it in GitHub Desktop.
Z_Core & Z_BattleMath Plugins for RMMV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../libs/jquery.js" /> | |
/// <reference path="../libs/pixi.js" /> | |
/// <reference path="../libs/fpsmeter.js" /> | |
/// <reference path="../libs/lz-string.js" /> | |
/// <reference path="../rpg_core.js" /> | |
/// <reference path="../rpg_managers.js" /> | |
/// <reference path="../rpg_objects.js" /> | |
/// <reference path="../rpg_scenes.js" /> | |
/// <reference path="../rpg_sprites.js" /> | |
/// <reference path="../rpg_windows.js" /> | |
/// <reference path="Z_Core.js" /> | |
//============================================================================= | |
// SLC Z_ Plugin: Battle Math | |
// Z_BattleMath.js | |
//============================================================================= | |
var Imported = Imported || {}; | |
var Z = Z || {}; | |
var ZBM = {}; | |
var Z$ = Z$ || window.jQuery; | |
Z.ExtendedFunctions = Z.ExtendedFunctions || []; | |
Z.BattleMath = ZBM; | |
Imported.Z_BattleMath = true; | |
//============================================================================= | |
/*: | |
* @plugindesc v0.1 Integrate more HTML Events | |
* parameters: | |
* @author SLC | |
* @description Requires Z_Core! | |
* | |
* | |
* @param Use Zodiac System | |
* @desc Use the Zodiac multiplier system from FF Tactics. Only applies to Z_BattleMath Damage Formulas. | |
* Default: ON (ON|YES|TRUE|1) | |
* @default on | |
* | |
* | |
* @param Global Zodiac System | |
* @desc Use the Zodiac multiplier system for ALL Damage, regardless of formula. | |
* Default: OFF (OFF|NO|FALSE|0) | |
* @default off | |
* | |
* | |
* @param Use Chinese Zodiac | |
* @desc A fun alternative to the "normal" Zodiac lineup. | |
* Default: OFF (OFF|FALSE|NO|0) | |
* @default off | |
* | |
* | |
* @param Zodiac Good Multiplier | |
* @desc How much extra damage for "good" compatability? (e.g. 0.10 or +10% for an extra 10%.) | |
* @default 0.25 | |
* | |
* | |
* @param Zodiac Bad Multiplier | |
* @desc The damage penalty for "bad" compatability? (e.g. -0.10 = -10%) | |
* @default -0.25 | |
* | |
* | |
* @param Zodiac Best Multiplier | |
* @desc The damage bonus for "best" compatability? (e.g. 0.10 = +10%) | |
* @default 0.5 | |
* | |
* | |
* @param Zodiac Worst Multiplier | |
* @desc The damage penalty for "worst" compatability? (e.g. -0.10 = -10%) | |
* @default -0.5 | |
* | |
* @param Use Comparative Bonus | |
* @desc Provide a bonus to Damage/Healing by comparing 2 values from a & b | |
* Default: ON (ON|YES|TRUE|1) | |
* @default on | |
* | |
* @param CB Stat | |
* @desc Choose a stat for the comparative bonus OR use an a/b formula that returns true/false | |
* Default: LUK | |
* @default luk | |
* | |
* @param CB Multiplier | |
* @desc How big will the comparative bonus be? Use a decimal (e.g. 0.1 = +10% bonus damage). | |
* Default: 0.1 (+10%) | |
* @default 0.1 | |
* | |
* @param Global Map-Based Damage | |
* @desc Apply Map-Based Boost/Supress/Nullify Regardless of Damage Formula (overrides some formulas). | |
* Default: OFF (OFF|FALSE|NO|0) | |
* @default false | |
* | |
* @param Map Boost Multiplier | |
* @desc Multiplier used when the map "Boosts" an element (for Map-based Damage) | |
* Default: +25% | |
* @default 0.25 | |
* | |
* @param Map Supress Multiplier | |
* @desc Multiplier used when the map "Supresses" an element (for Map-based Damage). | |
* Default: -25% | |
* @default -0.25 | |
* | |
* @param Physical Offense Stat | |
* @desc Stat (or a/b formula) used for default Physical Attacks | |
* Default: ATK | |
* @default atk | |
* | |
* | |
* @param Magical Offense Stat | |
* @desc Stat (or a/b formula) used for default Magical Attacks | |
* Default: MAT | |
* @default mat | |
* | |
* | |
* @param Special Offense Stat | |
* @desc Stat (or a/b formula) used for default Finesse/Agility Attacks | |
* Default: AGI | |
* @default agi | |
* | |
* | |
* @param Alternate Offense Stat | |
* @desc Stat (or a/b formula) used for default Alternate Attacks (Just an extra for you) | |
* Default: LUK | |
* @default luk | |
* | |
* | |
* @param Physical Defense Stat | |
* @desc Stat (or a/b formula) used for default Physical Attacks | |
* Default: DEF | |
* @default def | |
* | |
* | |
* @param Magical Defense Stat | |
* @desc Stat (or a/b formula) used for default Magical Attacks | |
* Default: MDF | |
* @default mdf | |
* | |
* | |
* @param Special Defense Stat | |
* @desc Stat (or a/b formula) used for default Finesse/Agility Attacks | |
* Default: LUK | |
* @default luk | |
* | |
* | |
* @param Alternate Defense Stat | |
* @desc Stat (or formula) used for default Alternate Attacks (Just an extra.) | |
* Default: AGI | |
* @default agi | |
* | |
* @param Use Innate Element Boost | |
* @desc If the caster has an "element" property, it can be used to boost damage. | |
* Default: OFF (OFF|FALSE|NO|0) | |
* @default off | |
* | |
* @param Innate Element Boost | |
* @desc If the caster has an "element" property, it can be used to boost damage. | |
* Default: 50% (0.5|50%|+0.5|+50%) | |
* @default 0.5 | |
* | |
* | |
* @param Custom Formula 1 | |
* @desc Use ZBM_Custom1(dmg, power); in your Damage Formula. See Help for Details | |
* Default: (a.atk - (b.def/3)) * p | |
* @default (a.atk - (b.def/3)) * p | |
* | |
* | |
* @param Custom Formula 2 | |
* @desc Use ZBM_Custom2(dmg, power); in your Damage Formula. See Help for Details | |
* Default: (a.atk - (b.def/3)) * p | |
* @default (a.atk - (b.def/3)) * p | |
* | |
* | |
* @param Custom Formula 3 | |
* @desc Use ZBM_Custom3(dmg, power); in your Damage Formula. See Help for Details | |
* Default: (a.atk - (b.def/3)) * p | |
* @default (a.atk - (b.def/3)) * p | |
* | |
* | |
* @help | |
* ============================================================================ | |
* REQUIREMENTS | |
* ============================================================================ | |
* | |
* This Plugin Requires Z_Core.js to function! | |
* | |
* Though not explicitly required, I highly recommend BOB_CustomStats.js | |
* to really make use of the custom formulas. Agility and Luck don't make | |
* sense for damage calculation most of the time so custom stats would be nice. | |
* | |
* ============================================================================ | |
* Introduction | |
* ============================================================================ | |
* | |
* This is a generic plugin for customizing battle damage/healing formulas. | |
* The main purpose is to provide some built-in formulas for damage calculation. | |
* | |
* You can also customize it to suit your needs. It's meant for beginners who just | |
* Want to "set it and forget it" as well as advanced users. | |
* | |
* ============================================================================ | |
* KEY FEATURES | |
* ============================================================================ | |
* | |
* DICE ROLL DAMAGE (D&D/PATHFINDER) | |
* | |
* There are two dice roll methods, basic and advanced. Each damage calculation | |
* requires a basic formula in classic D&D Style: | |
* | |
* DiceRoll("2d6+10") | |
* | |
* This will automaticall roll 2 virtual 6-sided die, add the results and then | |
* add 10 to that number and return it. | |
* | |
* The advanced method allows you to add another bonus based on caster or | |
* target stats (classic a/b variables like any other RMMV formula). | |
* | |
* SuperDiceRoll(a, b, "3d20+4 + <a.atk - b.def>") | |
* | |
* That example rolls 3 virtual D20 dice, adds 4 to the result and further adds | |
* the user's ATK minus the target's DEF (or subtract if the number is negative!) | |
* | |
* The minus symbol does work. The following equations are also valid: | |
* | |
* DiceRoll("3d4-1") | |
* SuperDiceRoll(a, b, "10d3+1 - <b.charisma - a.charisma>") | |
* | |
* The Dice Roll system is best when used with a custom stat plugin like | |
* BOB_CustomStats.js so you can implement real D&D stats and modifiers | |
* to use in these formulas. | |
* | |
* Just paste the method into your damage formula box to use. It must be | |
* formatted as a JavaScript function call with your custom formula in quotes | |
* just like the examples. The SuperDiceRoll() function REQUIRES you to put | |
* the a and b parameters first so they becom accessible to the code. | |
* | |
* ZODIAC SYSTEM | |
* | |
* If you're using a custom stat plugin like BOB_CustomStats.js, you can use | |
* the built-in Zodiac feature. This provides a bonus to damage/healing based | |
* on the users Zodiac sign. Add a sign by giving the enemy or character a | |
* stat called "zodiac". You can use the traditional zodiac signs as seen in | |
* Final Fantasy Tactics or you can switch to Chinese zodiac mode! | |
* | |
* Tradtional: scorpio, virgo, leo, cancer, sagittarius, virgo, aquarius, | |
* taurus, gemini, libra, aries & capricorn. | |
* Chinese: dragon, rabbit, tiger, ox, rat, pig, dog, rooster, | |
* monkey, goat, horse & snake. | |
* | |
* Signs have "good", "bad", "best" and "worst" compatability. When the | |
* script determines the compatibility, a multiplier is used to add or remove | |
* a percentage of the damage. For example, by default, a "good" | |
* compatibility will result in +25% damage. An attack That normally | |
* does 100 damage would now do 125 damage. | |
* | |
* You can modify these multiplier values in the plugin manager. | |
* Use decimals (+0.25 for +25%) or use percentages (+25% for +25%). | |
* You can add a + or - symbol at the beginning. | |
* | |
* | |
* MAP-BASED DAMAGE | |
* | |
* You can boost, supress or totally nullify skill damage depending | |
* on the map you're on. | |
* First add a note to your map in one of the following formats: | |
* | |
* <boost: 2> | |
* <supress: 3> | |
* <nullify: 5> | |
* | |
* A map with that note will boost damage for element #2. It will also | |
* reduce damage for the element #3. Element #5 will do 0 damage! | |
* For now, only element ID's are supported. | |
* Check back later for a version that supports names. | |
* | |
* INNATE ELEMENTAL BONUS | |
* | |
* Want your Ice Spectre and Flame Mage to share from the same pool of magic | |
* but it doesn't make sense for the Ice Spectre to deal more damage with | |
* Fire spells than the Flame Mage? | |
* Add a custom stat to your Flame Mage class called "element" and set it | |
* to "fire" or the element ID of your fire spell (e.g. 3 or 4). | |
* Now your Flame Mage will innately get a bonus to damage with Fire spells. | |
* | |
* Turn the option on and set the bonus amount inthe plugin manager. | |
* | |
* FOUR DEFAULT DAMAGE TYPES | |
* | |
* There are four default formulas you can use that are stat-based. | |
* These can be used in the damage formula of your skills. Simply use the | |
* following format: | |
* | |
* PhysicalDamage(dmg, <power>,[kind], [usemap]); | |
* | |
* Always start off the method call with "dmg" as your first parameter. | |
* Replace <power> with a number. This is the power level of your skill. | |
* Feel free to use an arbitrary number or any stat available in the eval | |
* like a.level for the caster's level. | |
* | |
* [kind] is an optional parameter. It should cotain a string | |
* (words surrounded in quotation marks) and can be one of the following: | |
* | |
* "fixed" - Ignores 99% of the damage formula and just uses the <power> | |
* number for a fixed amount of damage. | |
* "stat" - Uses the standard formula. Not really necessary to use. | |
* "scaled" - Uses a special formula that scales damage/healing based | |
* on the level of the user or enemy (requires enemy levels) | |
* "percent" - Uses the <power> value as a percentage of the target's | |
HP, like the Demi/Gravity spells from Final Fantasy. | |
* | |
* You can also skipp this parameter entirely and just set it to true/false | |
* The code will automatically assume it is reading the [usemap] parameter. | |
* | |
* [usemap] is another optional parameter. By default it is set to false. | |
* This parameter tells the damage formula to use the Map-Based Damage feature. | |
* If you have Map-Damage set to "global" from the plugin manager, this | |
* parameter does nothing & all damage will use the map-based formula. | |
* | |
* Here are the 4 main functions to use in your damage formulas: | |
* | |
* PhysicalDamage(dmg,<power>,[kind],[usemap]); | |
* MagicalDamage(dmg,<power>,[kind],[usemap]); | |
* SpecialDamage(dmg,<power>,[kind],[usemap]); | |
* AlternateDamage(dmg,<power>,[kind],[usemap]); | |
* | |
* Each formula is based on an offense number and a defense number. | |
* By default these are just based on a single stat. You can adjust | |
* each function's offense and defense stat in the plugin manager. | |
* | |
* For example, Physical Damage uses the caster's ATK stat for offense. | |
* It uses the target's DEF stat for defense. | |
* | |
* You can use a single stat name or a whole formula when customizing these | |
* in the plugin manager. For example, you can change the default offensive | |
* stat for PhysicalDamage() to be "a.atk * a.level" if you want. | |
* | |
* EXPOSES NEW PARAMETERS | |
* | |
* Whether you use the built-in damage formulas or not, I have exposed more | |
* data to the evaluation of any damage formula. Here are some new values: | |
* | |
* • e - Now you can find out the skill's element ID with the "e" attribute. | |
* | |
* • dmg - The dmg variable is a complex object with all the properties | |
* needed for my advanced formulas. You can use it to build your own. | |
* - | |
* - dmg.source = the same as the "a" variable, the attacker object. | |
* - | |
* - dmg.target = the same as the "b" variable, the defender object. | |
* - | |
* - dmg.offense = the calculated value of the attackers attack power | |
* - | |
* - dmg.defense = the calculated value of the defenders defensive power | |
* - | |
* - dmg.power = the attack power, provided by you on the skill's page | |
* - | |
* - dmg.element = the element ID for the skill being used | |
* - | |
* - dmg.multi = the combined multipliers for damage. Default is 1. | |
* - | |
* - dmg.mapBonus() = Decimal number of the map-based bonus. | |
* - | |
* - dmg.zodiacBonus() = Decimal number of the zodiac-based bonus. | |
* - | |
* - dmg.innateBonus() = Decimal number of the innate element bonus. | |
* | |
* - The last 3 are run as functions. They return small numbers like 0.5 or 0.10. | |
* - You can add 1 to them and use them to multiply for more damage, if not | |
- already using them in the standard formulas. | |
* | |
* CUSTOM REUSABLE FORMULAS | |
* | |
* There are 3 default custom formulas. You can specify the entire formula | |
* and then quickly paste the shorthand into your damage formula boxes. | |
* This is nice for when you have a kind of complex calculation and | |
* don't want a bunch of confusing stuff in your skill formula entries. | |
* | |
* Just always make your call with the dmg object and (optional) a power level. | |
* | |
* Example: ZBM_Custom1(dmg,100) | |
* | |
* This will evaluate your custom function. It will assign the "p" variable | |
* a value of 100. | |
* | |
* All the normal variables are available to use in your custom function: | |
* | |
* • a - the attacking character object. Access stats like ATK with a.atk | |
* | |
* • b - the defending character object. Access stats like DEF with b.def | |
* | |
* • dmg - the DMG Object. Access ZBM values you offense, defense, etc. | |
* | |
* • p - the power level. This is the second parameter of your function. | |
* | |
* ============================================================================ | |
*/ | |
/* | |
* ============= | |
* SETUP | |
* ============= | |
*/ | |
ZBM.Params = PluginManager.parameters('Z_BattleMath'); | |
ZBM.Formulas = {}; | |
ZBM.Settings = { | |
useCB: Z.toBool(ZBM.Params["Use Comparative Bonus"]), | |
cbSource: String(ZBM.Params["CB Stat"]), | |
cbBonus: String(ZBM.Params["CB Multiplier"]), | |
physicalOffense: String(ZBM.Params["Physical Offense Stat"]), | |
magicalOffense: String(ZBM.Params["Magical Offense Stat"]), | |
specialOffense: String(ZBM.Params["Special Offense Stat"]), | |
alternateOffense: String(ZBM.Params["Alternate Offense Stat"]), | |
physicalDefense: String(ZBM.Params["Physical Defense Stat"]), | |
magicalDefense: String(ZBM.Params["Magical Defense Stat"]), | |
specialDefense: String(ZBM.Params["Special Defense Stat"]), | |
alternateDefense: String(ZBM.Params["Alternate Defense Stat"]), | |
innateBoost: Z.toBool(ZBM.Params["Use Innate Element Boost"]), | |
innateBoostAmount: Z.PercentToDecimal(ZBM.Params["Innate Element Boost"]), | |
mapDamage: { | |
global: Z.toBool(ZBM.Params["Global Map-Based Damage"]), | |
boost: Z.PercentToDecimal(ZBM.Params["Map Boost Multiplier"]), | |
supress: Z.PercentToDecimal(ZBM.Params["Map Supress Multiplier"]) | |
}, | |
zodiac: { | |
good: Z.PercentToDecimal(ZBM.Params["Zodiac Good Multiplier"]), | |
bad: Z.PercentToDecimal(ZBM.Params["Zodiac Bad Multiplier"]), | |
best: Z.PercentToDecimal(ZBM.Params["Zodiac Best Multiplier"]), | |
worst: Z.PercentToDecimal(ZBM.Params["Zodiac Worst Multiplier"]), | |
enabled: Z.toBool(ZBM.Params["Use Zodiac System"]), | |
chinese: Z.toBool(ZBM.Params["Use Chinese Zodiac"]), | |
compatability: { | |
remap: true, | |
map: { info: "initialized later, or by you!" }, | |
compat: function (gd1, gd2, bd1, bd2, bst, wst) { | |
var result = {}; | |
result[gd1] = ZBM.Settings.zodiac.good; | |
result[gd2] = ZBM.Settings.zodiac.good; | |
result[bd1] = ZBM.Settings.zodiac.bad; | |
result[bd2] = ZBM.Settings.zodiac.bad; | |
result[bst] = ZBM.Settings.zodiac.best; | |
result[wst] = ZBM.Settings.zodiac.worst; | |
return result; | |
}, | |
setMap: function (mapObject) { this.map = mapObject; }, | |
getMap: function () { return this.map; } | |
} | |
} | |
}; | |
var DMG = function (a, as, b, bs, p, m, e) { | |
a = a || { atk: 1 }; | |
b = b || { def: 1 }; | |
as = as || "atk"; | |
bs = bs || "def"; | |
p = p || 1; | |
m = m || 1; | |
return { | |
source: a, | |
target: b, | |
offense: a[as], | |
defense: b[bs], | |
power: p, | |
multi: m, | |
element: e, | |
nullified: false, | |
applied: [], | |
mapBonus: function () { return ZBM.Formulas.MapBasedMultiplier(this).multi; }, | |
zodiacBonus: function () { return ZBM.Formulas.MapBasedMultiplier(this).multi; }, | |
innateBonus: function () { return ZBM.Formulas.CharacterElementMultiplier(this).multi; } | |
}; | |
}; | |
/* | |
* ============= | |
* EXTENSIONS | |
* ============= | |
*/ | |
// This function can't be simply extended since it relies on Eval. | |
// So we'll take the traditional approach and just re-write the function. | |
Game_Action.prototype.evalDamageFormula = function (target) { | |
try { | |
var item = this.item(); | |
var a = this.subject(); | |
var b = target; | |
var v = $gameVariables._data; | |
var e = -1; | |
if (this.isSkill()) { | |
e = Number($dataSkills[this._item._itemId].damage.elementId); | |
} | |
var sign = ([3, 4].contains(item.damage.type) ? -1 : 1); | |
var dmg = DMG(a, "", b, "", 1, 1, e); | |
if (ZBM.Settings.mapDamage.global === true) { | |
dmg = ZBM.Formulas.MapBasedMultiplier(dmg); | |
} | |
if (ZBM.Settings.zodiac.enabled === true) { | |
dmg = ZBM.Formulas.ZodiacMultiplier(dmg); | |
} | |
if (ZBM.Settings.innateBoost === true) { | |
dmg = ZBM.Formulas.CharacterElementMultiplier(dmg); | |
} | |
var output = Math.max(eval(item.damage.formula), 0) * sign; | |
if (dmg.nullified === true) { | |
output = 0; | |
} | |
else { | |
output = Math.max(output * dmg.multi); | |
} | |
return output; | |
} catch (er) { | |
return 0; | |
} | |
}; | |
/* | |
* ============= | |
* FORMULAS | |
* ============= | |
*/ | |
ZBM.Formulas.DefaultCore = function (dmg) { | |
dmg = dmg || DMG(); | |
if (dmg.nullified === true) { | |
return 0; | |
} | |
var a, b, o, d; | |
if (dmg.offense.toString().contains(".")) { | |
a = dmg.source; | |
b = dmg.target; | |
o = Number(eval(dmg.offense)); | |
} | |
else { | |
o = Number(dmg.source[dmg.offense]); | |
} | |
if (dmg.defense.toString().contains(".")) { | |
a = dmg.source; | |
b = dmg.target; | |
d = Number(eval(dmg.defense)); | |
} else { | |
d = Number(dmg.target[dmg.defense]); | |
} | |
var mitigation = d / (o * 3); | |
var damage = 0; | |
if (mitigation > 0.5) { mitigation = 0.5; } | |
if (mitigation < 0) { mitigation = 0; } | |
damage = o * dmg.power * dmg.multi; | |
return Math.floor(damage - (damage * mitigation)); | |
}; | |
ZBM.Formulas.StatBased = function (dmg) { | |
dmg = dmg || DMG(); | |
var a, b, m = 1, as, bs, cbs = ZBM.Settings.cbSource; | |
if (cbs.contains(".")) { | |
a = dmg.source; | |
b = dmg.target; | |
if (eval(cbs)) { | |
m = 1 + ZBM.Settings.cbBonus; | |
} | |
} | |
else { | |
a = dmg.source; | |
b = dmg.target; | |
as = a[cbs]; | |
bs = b[cbs]; | |
if (as > bs) { | |
m = 1 + ZBM.Settings.cbBonus; | |
} | |
} | |
var result = Math.floor(ZBM.Formulas.DefaultCore(dmg) * m); | |
return result; | |
}; | |
ZBM.Formulas.ScaleBased = function (dmg) { | |
dmg = dmg || DMG(); | |
var casterMagic = dmg.offense; | |
var targetMaxHP = dmg.target.mhp || 10; | |
var targetMdef = dmg.defense || 10; | |
var maxResult = dmg.power < 1 ? dmg.power : dmg.power / 100; | |
var targetLevel = dmg.target._level || 1; | |
var casterLevel = dmg.source._level || 1; | |
var result = (casterMagic * casterLevel) / (targetLevel * targetMdef); | |
result = result < maxResult ? result : maxResult; | |
return Math.floor(result * targetMaxHP); | |
}; | |
ZBM.Formulas.PercentageBased = function (dmg) { | |
dmg = dmg || DMG(); | |
var targetHP = dmg.target.hp; | |
var percent = Z.PercentToDecimal(dmg.power < 1 ? dmg.power : (dmg.power / 100)); | |
var damage = targetHP * percent; | |
return Math.floor(damage); | |
}; | |
ZBM.Formulas.FixedBased = function (dmg) { | |
dmg = dmg || DMG(); | |
dmg.offense = "a.atk-a.atk + 1"; | |
dmg.defense = "b.def * 0"; | |
return ZBM.Formulas.DefaultCore(dmg); | |
}; | |
ZBM.Formulas.getZodiac = function (dmg) { | |
dmg = dmg || DMG(); | |
var sourceNote, targetNote; | |
if (dmg.source.isEnemy()) { | |
sourceNote = $dataEnemies[dmg.source._enemyId].note + ""; | |
} else { | |
sourceNote = $dataActors[dmg.source._actorId].note + ""; | |
} | |
if (dmg.target.isEnemy()) { | |
targetNote = $dataEnemies[dmg.target._enemyId].note + ""; | |
} | |
else { | |
targetNote = $dataActors[dmg.target._actorId].note + ""; | |
} | |
var zodiacRegX = /<zodiac:\s*(.+)?>/im; | |
var sourceSign = zodiacRegX.exec(sourceNote); | |
var targetSign = zodiacRegX.exec(targetNote); | |
if (sourceSign[1]) { | |
sourceSign = sourceSign[1]; | |
} | |
if (targetSign[1]) { | |
targetSign = targetSign[1]; | |
} | |
dmg.source.zodiac = sourceSign; | |
dmg.target.zodiac = targetSign; | |
return dmg; | |
} | |
ZBM.Formulas.MapBasedMultiplier = function (dmg) { | |
dmg = dmg || DMG(); | |
if (dmg.applied.indexOf("map-based") >= 0) { | |
return dmg; | |
} | |
var mapNote = $dataMap.note || ""; | |
var boostRegX = /<boost:\s*(.+)?>/im; | |
var supressRegX = /<supress:\s*(.+)?>/im; | |
var nullRegX = /<nullify:\s*(.+)?>/im; | |
var boost = boostRegX.exec(mapNote); | |
var supress = supressRegX.exec(mapNote); | |
var nullify = nullRegX.exec(mapNote); | |
if (boost.index === boostRegX.lastIndex) { boostRegX.lastIndex++; } | |
if (supress.index === supressRegX.lastIndex) { supressRegX.lastIndex++; } | |
if (nullify.index === nullRegX.lastIndex) { nullRegX.lastIndex++; } | |
if (boost[1] && dmg.element === Z.getElementId(boost[1])) { | |
dmg.multi = dmg.multi + ZBM.Settings.mapDamage.boost; | |
} | |
if (supress[1] && dmg.element === Z.getElementId(supress[1])) { | |
dmg.multi = dmg.multi + ZBM.Settings.mapDamage.supress; | |
} | |
if (nullify[1] && dmg.element === Z.getElementId(nullify[1])) { | |
dmg.multi = 0; | |
dmg.nullified = true; | |
} | |
debugger; | |
dmg.applied.push("map-based"); | |
return dmg; | |
}; | |
ZBM.Formulas.CharacterElementMultiplier = function (dmg) { | |
dmg = dmg || DMG(); | |
if (dmg.applied.indexOf("innate-element-boost") >= 0) { | |
return dmg; | |
} | |
if (typeof dmg.source.element !== 'undefined') { | |
var playerElm = Z.getElementId(dmg.source.element); | |
var skillElm = dmg.element; | |
if (playerElm === skillElm) { | |
dmg.multi = dmg.multi + ZBM.Settings.innateBoostAmount; | |
dmg.applied.push("innate-element-boost"); | |
} | |
} | |
return dmg; | |
}; | |
ZBM.Formulas.ZodiacMultiplier = function (dmg) { | |
dmg = dmg || DMG(); | |
dmg = ZBM.Formulas.getZodiac(dmg); | |
if (dmg.applied.indexOf("zodiac-based") >= 0) { | |
return dmg; | |
} | |
var aSign = dmg.source.zodiac || "scorpio", | |
bSign = dmg.target.zodiac || "libra"; | |
if (typeof dmg.source.ignorezodiac !== 'undefined' && Z.toBool(dmg.source.ignorezodiac)) { | |
return dmg; | |
} | |
if (typeof dmg.target.ignorezodiac !== 'undefined' && Z.toBool(dmg.target.ignorezodiac)) { | |
return dmg; | |
} | |
// Initialize the Zodiac Compatability Map if no map exists. | |
if (ZBM.Settings.zodiac.compatability.remap === true) { | |
var zc = ZBM.Settings.zodiac.compatability; | |
if (ZBM.Settings.zodiac.chinese === true) { | |
ZBM.Settings.zodiac.compatability.setMap.call(ZBM.Settings.zodiac.compatability, { | |
dragon: zc.compat("rat", "monkey", "ox", "goat", "dog", "dragon"), | |
rabbit: zc.compat("pig", "goat", "rat", "horse", "rooster", "rabbit"), | |
tiger: zc.compat("dog", "horse", "pig", "snake", "monkey", "tiger"), | |
ox: zc.compat("rooster", "snake", "dog", "dragon", "goat", "ox"), | |
rat: zc.compat("monkey", "dragon", "rooster", "rabbit", "horse", "rat"), | |
pig: zc.compat("goat", "rabbit", "monkey", "tiger", "snake", "pig"), | |
dog: zc.compat("horse", "tiger", "goat", "ox", "dragon", "dog"), | |
rooster: zc.compat("snake", "ox", "horse", "rat", "rabbit", "rooster"), | |
monkey: zc.compat("dragon", "rat", "snake", "pig", "tiger", "monkey"), | |
goat: zc.compat("rabbit", "pig", "dragon", "dog", "ox", "goat"), | |
horse: zc.compat("tiger", "dog", "rabbit", "rooster", "rat", "horse"), | |
snake: zc.compat("ox", "rooster", "tiger", "monkey", "pig", "snake"), | |
}); | |
} | |
else { | |
ZBM.Settings.zodiac.compatability.setMap.call(ZBM.Settings.zodiac.compatability, { | |
capricorn: zc.compat("taurus", "virgo", "aries", "libra", "cancer", "capricorn"), | |
aquarius: zc.compat("gemini", "libra", "taurus", "scorpio", "leo", "aquarius"), | |
pisces: zc.compat("cancer", "scorpio", "gemini", "sagittarius", "virgo", "pisces"), | |
aries: zc.compat("leo", "sagittarius", "cancer", "capricorn", "libra", "aries"), | |
taurus: zc.compat("virgo", "capricorn", "leo", "aquarius", "scorpio", "taurus"), | |
gemini: zc.compat("libra", "aquarius", "virgo", "pisces", "sagittarius", "gemini"), | |
cancer: zc.compat("scorpio", "pisces", "libra", "aries", "capricorn", "cancer"), | |
leo: zc.compat("sagittarius", "aries", "scorpio", "taurus", "aquarius", "leo"), | |
virgo: zc.compat("capricorn", "taurus", "sagittarius", "gemini", "pisces", "virgo"), | |
libra: zc.compat("aquarius", "gemini", "capricorn", "cancer", "aries", "libra"), | |
scorpio: zc.compat("pisces", "cancer", "aquarius", "leo", "taurus", "scorpio"), | |
sagittarius: zc.compat("aries", "leo", "pisces", "virgo", "gemini", "sagittarius") | |
}); | |
} | |
} | |
var multiplier = ZBM.Settings.zodiac.compatability.getMap()[aSign][bSign] || 1.0; | |
if (multiplier == -1) { | |
dmg.nullified = true; | |
} | |
dmg.multi = dmg.multi + multiplier; | |
dmg.applied.push("zodiac-based"); | |
return dmg; | |
}; | |
ZBM.Formulas.DiceRoll = function (formula, exBonus) { | |
formula = (formula || "0d0+0").toLowerCase(); | |
exBonus = exBonus || 0; | |
var diceReg = /(\d{1,3})d(\d{1,2})(\+|-)(\d{1,3})/i, | |
diceInfo = diceReg.exec(formula), | |
dice = diceInfo[1] || 0, | |
dieType = diceInfo[2] || 0, | |
sign = diceInfo[3] || "+", | |
bonus = diceInfo[4] || 0; | |
bonus = Number(sign + bonus); | |
var i, | |
rolls = [], | |
roll = 0, | |
total = 0; | |
for (i = 0; i < dice; i++) { | |
roll = Math.randomInt(dieType) + 1; | |
rolls.push(roll); | |
total = total + roll; | |
} | |
total = total + bonus + exBonus; | |
return Number(total); | |
}; | |
ZBM.Formulas.DiceRollAdvanced = function (a, b, formula) { | |
var bonusReg, bonusInfo, sign, bonus, result = 0; | |
try { | |
formula = formula || "0"; | |
bonusReg = /(\+|\-)\D*<(.*)>/i; | |
bonusInfo = bonusReg.exec(formula); | |
sign = bonusInfo[1] || "+"; | |
bonus = bonusInfo[2] || 0; | |
result = Number(sign + eval(bonus)); | |
} catch (er) { | |
result = 0; | |
} | |
return ZBM.Formulas.DiceRoll(formula, result); | |
}; | |
ZBM.Kinds = { | |
stat: "StatBased", | |
percent: "PercentageBased", | |
fixed: "FixedBased", | |
scaled: "ScaledBased" | |
}; | |
// Shorthand Damage Functions | |
function GenericDamage(dmg, offense, defense, power, kind, usemap) { | |
if (kind === true && typeof usemap === 'undefined') { | |
kind = "stat"; | |
usemap = true; | |
} | |
dmg = dmg || DMG(); | |
kind = kind || "stat"; | |
kind = ZBM.Kinds[kind]; | |
usemap = usemap || false; | |
dmg.offense = offense; | |
dmg.defense = defense; | |
dmg.power = power; | |
if (usemap) { | |
dmg = ZBM.Formulas.MapBasedMultiplier(dmg); | |
} | |
if (ZBM.Settings.zodiac.enabled === true) { | |
dmg = ZBM.Formulas.ZodiacMultiplier(dmg); | |
} | |
return ZBM.Formulas[kind](dmg); | |
} | |
function FixedDamage(dmg, power, usemap) { | |
return GenericDamage(dmg, "", "", power, "fixed", usemap); | |
} | |
function DiceRoll(formula, extra) { | |
return ZBM.Formulas.DiceRoll(formula, extra); | |
} | |
function SuperDiceRoll(a, b, formula) { | |
return ZBM.Formulas.DiceRollAdvanced(a, b, formula); | |
} | |
function PhysicalDamage(dmg, power, kind, usemap) { | |
return GenericDamage(dmg, ZBM.Settings.physicalOffense, ZBM.Settings.physicalDefense, power, kind, usemap); | |
} | |
function MagicalDamage(dmg, power, kind, usemap) { | |
return GenericDamage(dmg, ZBM.Settings.magicalOffense, ZBM.Settings.magicalDefense, power, kind, usemap); | |
} | |
function SpecialDamage(dmg, power, kind, usemap) { | |
return GenericDamage(dmg, ZBM.Settings.specialOffense, ZBM.Settings.specialDefense, power, kind, usemap); | |
} | |
function AlternateDamage(dmg, power, kind, usemap) { | |
return GenericDamage(dmg, ZBM.Settings.alternateOffense, ZBM.Settings.alternateDefense, power, kind, usemap); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../libs/jquery.js" /> | |
/// <reference path="../libs/pixi.js" /> | |
/// <reference path="../libs/fpsmeter.js" /> | |
/// <reference path="../libs/lz-string.js" /> | |
/// <reference path="../rpg_core.js" /> | |
/// <reference path="../rpg_managers.js" /> | |
/// <reference path="../rpg_objects.js" /> | |
/// <reference path="../rpg_scenes.js" /> | |
/// <reference path="../rpg_sprites.js" /> | |
/// <reference path="../rpg_windows.js" /> | |
//============================================================================= | |
// SLC Z Plugin: Core Plugin | |
// Z_Core.js | |
//============================================================================= | |
var Imported = Imported || {}; | |
var Z = Z || {}; | |
var Z$ = window.jQuery; | |
Z.ExtendedFunctions = []; | |
Imported.Z_Core = true; | |
//============================================================================= | |
/*: | |
* @plugindesc v0.1 Integrate more HTML Events | |
* parameters: | |
* @author SLC | |
* | |
* | |
* @param Enable Touch Input | |
* @desc Disable Touch Input on Startup (Toggle via Z.Settings.TouchEnabled true/false) | |
* @default true | |
* | |
* @help | |
* ============================================================================ | |
* Introduction | |
* ============================================================================ | |
* | |
* This is a generic plugin with utility functions like prototype extensions, etc. | |
* The formatting was derrived from Yanfly's awesome YEP Plugins, thanks for inspiring! | |
* | |
* | |
* ============================================================================ | |
* FEATURES | |
* ============================================================================ | |
* | |
* Most of this plugin's current features are really just to provide extensions | |
* and special methods for my other plugins. But there are a few options you can | |
* play with and probably more coming in the future. | |
* | |
* DYNAMIC TOUCH ENABLE/DISABLE | |
* | |
* You can set the default touch to be enabled/disabled by default by adjusting | |
* that parameter in the Plugin Manager. You can also, however, change it later | |
* in-game! Simply use an event to run a script that changes the value of the | |
* Z.Settings.TouchEnabled variable. | |
* | |
* Example 1: Z.Settings.TouchEnabled = true; | |
* | |
* Example 2: Z.Settings.TouchEnabled = !Z.Settings.TouchEnabled; | |
* | |
* Example 1 directly enables touch input. Example 2 toggles it, making it | |
* whatever it wasn't before! | |
* | |
* DEVELOPER FEATURES | |
* | |
* I tried to write some useful functions for plugin developers to use. | |
* This plugin includes some syntactical sugar functions like | |
* Z.toBool which converts strings into booleans and can convert things like | |
* "yes" or "on" to true. Z.PercentageToDecimal converts stuff like "+50%" to 0.5. | |
* | |
* The most complex are Z.ExtendFunction and Z.ConditionFunction. These are meant | |
* for adding functionality to RPG Maker's Core Component prototypes. | |
* The main thing they do is allow you to add functionality without having to | |
* rewrite the native code you don't want to change. | |
* | |
* Z.ExtendFunction(base,extra) takes the string name of the prototype you want to | |
* extend as the first parameter. Then it takes your custom function. Your custom | |
* function is ran first and then the original function runs. It can be stacked | |
* several times if necessary. | |
* | |
* Z.ConditionFunction is essentially the same except your custom function is intended | |
* to return true or false. If your custom function returns false, the original function | |
* does NOT execute. If your custom function returns true, the original function | |
* executes normally. This is the technique I used to make the touch input dynamic. | |
*/ | |
/* | |
* ============= | |
* UTILITIES | |
* ============= | |
*/ | |
// This utility allows you to run extra functions before the function | |
// you're extending. It's mostly useful for making the extended function trigger | |
// events as it does not modify the extended function directly. | |
Z.ExtendFunction = function (base, extra) { | |
Z.ExtendedFunctions.push(base); | |
var clone = eval(base + ";"); | |
eval(base + "=function(){extra.apply(this,[this].concat(arguments)); return clone.apply(this,arguments);};"); | |
}; | |
// This utility is for providing a function extension that returns true or false | |
// The extended function only runs if your extension evaluates to true. | |
Z.ConditionFunction = function (base, condition) { | |
Z.ExtendedFunctions.push(base); | |
var clone = eval(base + ";"); | |
var es = base + "=function(){if(condition.apply(this,[this].concat(arguments))){return clone.apply(this,arguments);}};"; | |
eval(es); | |
}; | |
// A simple method to convert values into booleans (true|false). | |
// Mostly unique as it errs on the side of false instead of true. | |
Z.toBool = function (input) { | |
input = (input + "").toLowerCase(); | |
if (input === "yes") { return true; } | |
if (input === "1") { return true; } | |
if (input === "true") { return true; } | |
if (input === "on") { return true; } | |
return false; | |
} | |
Z.PercentToDecimal = function(input) | |
{ | |
input = input + ""; | |
var result = Number(input); | |
if (input.contains("%")) { | |
result = input.replace("%", ""); | |
result = Number(result); | |
if(!isNaN(result)) | |
{ | |
result = result / 100; | |
} | |
} | |
if (!isNaN(result)) | |
{ | |
return result; | |
} | |
return -1; | |
} | |
Z.getElementId = function(name){ | |
var quick = Number(name); | |
if (!isNaN(quick) && quick in $dataSystem.elements) | |
{ | |
return quick; | |
} | |
var result = $dataSystem.elements.indexOf(name); | |
if(result >= 0) | |
{ | |
return result; | |
} | |
return -1; | |
}; | |
Z.getElementName = function (id) { | |
if (id in $dataSystem.elements) { | |
return $dataSystem.elements[id]; | |
} | |
return "NULL"; | |
}; | |
/* | |
* ============= | |
* SETUP | |
* ============= | |
*/ | |
Z.Params = PluginManager.parameters("Z_Core"); | |
Z.Settings = {}; | |
Z.Settings.TouchEnabled = Z.toBool(Z.Params["Enable Touch Input"]); | |
/* | |
* ============= | |
* EXTENSIONS | |
* ============= | |
*/ | |
Z.ConditionFunction("TouchInput._onMouseDown", function (context) { | |
context = context || window.Event; | |
return (function (context) { | |
return Z.Settings.TouchEnabled; | |
})(context); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment