wynnbuilder-forked-for-changes/js/build.js

318 lines
12 KiB
JavaScript
Raw Normal View History

2021-01-10 10:02:23 +00:00
const classDefenseMultipliers = new Map([ ["relik",0.50], ["bow",0.60], ["wand", 0.80], ["dagger", 1.0], ["spear",1.20], ["sword", 1.10]]);
2021-01-10 10:02:23 +00:00
2021-01-17 21:01:20 +00:00
/**
* @description Error to catch items that don't exist.
* @module ItemNotFound
*/
class ItemNotFound {
/**
* @class
* @param {String} item the item name entered
* @param {String} type the type of item
* @param {Boolean} genElement whether to generate an element from inputs
* @param {String} override override for item type
*/
constructor(item, type, genElement, override) {
/**
* @public
* @type {String}
*/
this.message = `Cannot find ${override||type} named ${item}`;
if (genElement)
/**
* @public
* @type {Element}
*/
this.element = document.getElementById(`${type}-choice`).parentElement.querySelectorAll("p.error")[0];
else
this.element = document.createElement("div");
}
2021-01-07 00:08:19 +00:00
}
2021-01-17 21:01:20 +00:00
/**
* @description Error to catch incorrect input.
* @module IncorrectInput
*/
class IncorrectInput {
/**
* @class
* @param {String} input the inputted text
* @param {String} format the correct format
* @param {String} sibling the id of the error node's sibling
*/
constructor(input, format, sibling) {
/**
* @public
* @type {String}
*/
this.message = `${input} is incorrect. Example: ${format}`;
/**
* @public
* @type {String}
*/
this.id = sibling;
2021-01-07 00:08:19 +00:00
}
}
2021-01-17 21:01:20 +00:00
/**
* @description Error that inputs an array of items to generate errors of.
* @module ListError
* @extends Error
*/
class ListError extends Error {
/**
* @class
* @param {Array} errors array of errors
*/
constructor(errors) {
let ret = [];
if (typeof errors[0] == "string") {
super(errors[0]);
} else {
super(errors[0].message);
}
for (let i of errors) {
if (typeof i == "string") {
ret.push(new Error(i));
} else {
ret.push(i);
}
}
/**
* @public
* @type {Object[]}
*/
this.errors = ret;
2021-01-07 00:08:19 +00:00
}
}
2021-01-07 00:02:10 +00:00
/*Class that represents a wynn player's build.
*/
class Build{
2021-01-17 21:01:20 +00:00
/**
* @description Construct a build.
* @param {Number} level : Level of the player.
* @param {String[]} equipment : List of equipment names that make up the build.
* In order: boots, Chestplate, Leggings, Boots, Ring1, Ring2, Brace, Neck, Weapon.
2021-01-17 21:01:20 +00:00
* @param {Number[]} powders : Powder application. List of lists of integers (powder IDs).
* In order: boots, Chestplate, Leggings, Boots, Weapon.
2021-01-17 21:01:20 +00:00
* @param {Object[]} inputerrors : List of instances of error-like classes.
*
* @param {Object[]} tomes: List of tomes.
* In order: 2x Weapon Mastery Tome, 4x Armor Mastery Tome, 1x Guild Tome.
* 2x Slaying Mastery Tome, 2x Dungeoneering Mastery Tome, 2x Gathering Mastery Tome are in game, but do not have "useful" stats (those that affect damage calculations or building)
2021-01-09 08:52:58 +00:00
*/
constructor(level, items, tomes, weapon){
2021-01-17 21:01:20 +00:00
if (level < 1) { //Should these be constants?
2021-01-07 00:02:10 +00:00
this.level = 1;
2021-01-17 21:01:20 +00:00
} else if (level > 106) {
2021-01-07 00:02:10 +00:00
this.level = 106;
2021-01-17 21:01:20 +00:00
} else if (level <= 106 && level >= 1) {
2021-01-07 00:02:10 +00:00
this.level = level;
2021-01-17 21:01:20 +00:00
} else if (typeof level === "string") {
this.level = level;
errors.push(new IncorrectInput(level, "a number", "level-choice"));
} else {
errors.push("Level is not a string or number.");
2021-01-07 00:02:10 +00:00
}
2021-01-17 21:01:20 +00:00
document.getElementById("level-choice").value = this.level;
2021-01-07 06:41:41 +00:00
this.availableSkillpoints = levelToSkillPoints(this.level);
this.equipment = items;
this.tomes = tomes;
this.weapon = weapon;
this.items = this.equipment.concat([this.weapon]).concat(this.tomes);
2021-01-07 06:41:41 +00:00
// return [equip_order, best_skillpoints, final_skillpoints, best_total];
let result = calculate_skillpoints(this.equipment.concat(this.tomes), this.weapon);
console.log(result);
2021-01-07 06:41:41 +00:00
this.equip_order = result[0];
// How many skillpoints the player had to assign (5 number)
2021-01-07 06:41:41 +00:00
this.base_skillpoints = result[1];
// How many skillpoints the build ended up with (5 number)
2021-01-07 06:41:41 +00:00
this.total_skillpoints = result[2];
// How many skillpoints assigned (1 number, sum of base_skillpoints)
2021-01-07 06:41:41 +00:00
this.assigned_skillpoints = result[3];
this.activeSetCounts = result[4];
2021-01-08 04:31:29 +00:00
this.initBuildStats();
2021-01-07 00:02:10 +00:00
}
/*Returns build in string format
2021-01-07 06:41:41 +00:00
*/
2021-01-07 00:02:10 +00:00
toString(){
return [this.equipment,this.weapon,this.tomes].flat();
2021-01-07 00:02:10 +00:00
}
2021-01-07 06:41:41 +00:00
/* Getters */
2021-01-07 21:32:36 +00:00
2021-01-09 08:52:58 +00:00
getSpellCost(spellIdx, cost) {
2021-09-13 19:31:43 +00:00
return Math.max(1, this.getBaseSpellCost(spellIdx, cost));
2021-09-13 19:29:15 +00:00
}
getBaseSpellCost(spellIdx, cost) {
// old intelligence: cost = Math.ceil(cost * (1 - skillPointsToPercentage(this.total_skillpoints[2])));
2021-01-09 08:52:58 +00:00
cost += this.statMap.get("spRaw"+spellIdx);
2021-09-13 19:29:15 +00:00
return Math.floor(cost * (1 + this.statMap.get("spPct"+spellIdx) / 100));
2021-01-09 08:52:58 +00:00
}
/* Get melee stats for build.
Returns an array in the order:
2021-01-07 21:32:36 +00:00
*/
getMeleeStats(){
2021-01-08 05:36:57 +00:00
const stats = this.statMap;
if (this.weapon.get("tier") === "Crafted") {
stats.set("damageBases", [this.weapon.get("nDamBaseHigh"),this.weapon.get("eDamBaseHigh"),this.weapon.get("tDamBaseHigh"),this.weapon.get("wDamBaseHigh"),this.weapon.get("fDamBaseHigh"),this.weapon.get("aDamBaseHigh")]);
}
2021-01-08 05:36:57 +00:00
let adjAtkSpd = attackSpeeds.indexOf(stats.get("atkSpd")) + stats.get("atkTier");
if(adjAtkSpd > 6){
adjAtkSpd = 6;
}else if(adjAtkSpd < 0){
adjAtkSpd = 0;
}
2021-03-25 07:18:33 +00:00
let damage_mult = 1;
if (this.weapon.get("type") === "relik") {
damage_mult = 0.99; // CURSE YOU WYNNCRAFT
//One day we will create WynnWynn and no longer have shaman 99% melee injustice.
//In all seriousness 99% is because wynn uses 0.33 to estimate dividing the damage by 3 to split damage between 3 beams.
2021-03-25 07:18:33 +00:00
}
// 0spellmult for melee damage.
let results = calculateSpellDamage(stats, [100, 0, 0, 0, 0, 0], stats.get("mdRaw"), stats.get("mdPct") + this.externalStats.get("mdPct"), 0, this.weapon, this.total_skillpoints, damage_mult * this.damageMultiplier, this.externalStats);
2021-01-11 02:58:39 +00:00
let dex = this.total_skillpoints[1];
let totalDamNorm = results[0];
let totalDamCrit = results[1];
2021-01-11 02:58:39 +00:00
totalDamNorm.push(1-skillPointsToPercentage(dex));
totalDamCrit.push(skillPointsToPercentage(dex));
let damages_results = results[2];
2021-01-11 02:58:39 +00:00
2021-01-12 22:49:57 +00:00
let singleHitTotal = ((totalDamNorm[0]+totalDamNorm[1])*(totalDamNorm[2])
+(totalDamCrit[0]+totalDamCrit[1])*(totalDamCrit[2]))/2;
2021-01-08 04:31:29 +00:00
//Now do math
2021-01-08 05:36:57 +00:00
let normDPS = (totalDamNorm[0]+totalDamNorm[1])/2 * baseDamageMultiplier[adjAtkSpd];
let critDPS = (totalDamCrit[0]+totalDamCrit[1])/2 * baseDamageMultiplier[adjAtkSpd];
let avgDPS = (normDPS * (1 - skillPointsToPercentage(dex))) + (critDPS * (skillPointsToPercentage(dex)));
2021-01-12 22:49:57 +00:00
//[[n n n n] [e e e e] [t t t t] [w w w w] [f f f f] [a a a a] [lowtotal hightotal normalChance] [critlowtotal crithightotal critChance] normalDPS critCPS averageDPS adjAttackSpeed, singleHit]
return damages_results.concat([totalDamNorm,totalDamCrit,normDPS,critDPS,avgDPS,adjAtkSpd, singleHitTotal]).concat(results[3]);
2021-01-07 21:32:36 +00:00
}
2021-01-10 10:02:23 +00:00
/*
Get all defensive stats for this build.
*/
getDefenseStats(){
const stats = this.statMap;
let defenseStats = [];
let def_pct = skillPointsToPercentage(this.total_skillpoints[3]);
let agi_pct = skillPointsToPercentage(this.total_skillpoints[4]);
//total hp
let totalHp = stats.get("hp") + stats.get("hpBonus");
2021-01-10 12:54:25 +00:00
if (totalHp < 5) totalHp = 5;
2021-01-10 10:02:23 +00:00
defenseStats.push(totalHp);
//EHP
2021-01-11 00:46:30 +00:00
let ehp = [totalHp, totalHp];
2021-01-10 10:02:23 +00:00
let defMult = classDefenseMultipliers.get(this.weapon.get("type"));
ehp[0] /= ((1-def_pct)*(1-agi_pct)*(2-defMult)*(2-this.defenseMultiplier));
ehp[1] /= ((1-def_pct)*(2-defMult)*(2-this.defenseMultiplier));
2021-01-10 10:02:23 +00:00
defenseStats.push(ehp);
//HPR
let totalHpr = rawToPct(stats.get("hprRaw"), stats.get("hprPct")/100.);
defenseStats.push(totalHpr);
//EHPR
2021-01-11 00:46:30 +00:00
let ehpr = [totalHpr, totalHpr];
ehpr[0] /= ((1-def_pct)*(1-agi_pct)*(2-defMult)*(2-this.defenseMultiplier));
ehpr[1] /= ((1-def_pct)*(2-defMult)*(2-this.defenseMultiplier));
2021-01-10 10:02:23 +00:00
defenseStats.push(ehpr);
//skp stats
defenseStats.push([ (1 - ((1-def_pct) * (2 - this.defenseMultiplier)))*100, agi_pct*100]);
2021-01-10 10:02:23 +00:00
//eledefs - TODO POWDERS
let eledefs = [0, 0, 0, 0, 0];
for(const i in skp_elements){ //kinda jank but ok
eledefs[i] = rawToPct(stats.get(skp_elements[i] + "Def"), stats.get(skp_elements[i] + "DefPct")/100.);
}
defenseStats.push(eledefs);
2021-01-11 00:46:30 +00:00
//[total hp, [ehp w/ agi, ehp w/o agi], total hpr, [ehpr w/ agi, ehpr w/o agi], [def%, agi%], [edef,tdef,wdef,fdef,adef]]
2021-01-10 10:02:23 +00:00
return defenseStats;
}
2021-01-08 05:36:57 +00:00
/* Get all stats for this build. Stores in this.statMap.
2021-01-07 21:32:36 +00:00
@pre The build itself should be valid. No checking of validity of pieces is done here.
*/
2021-01-08 04:31:29 +00:00
initBuildStats(){
let staticIDs = ["hp", "eDef", "tDef", "wDef", "fDef", "aDef", "str", "dex", "int", "def", "agi"];
2021-01-08 04:31:29 +00:00
2021-01-07 21:32:36 +00:00
//Create a map of this build's stats
let statMap = new Map();
2021-01-08 04:31:29 +00:00
for (const staticID of staticIDs) {
statMap.set(staticID, 0);
2021-01-07 21:32:36 +00:00
}
statMap.set("hp", levelToHPBase(this.level));
2021-01-30 12:03:40 +00:00
let major_ids = new Set();
for (const item of this.items){
2021-01-08 04:31:29 +00:00
for (let [id, value] of item.get("maxRolls")) {
if (staticIDs.includes(id)) {
continue;
}
2021-01-08 04:31:29 +00:00
statMap.set(id,(statMap.get(id) || 0)+value);
}
for (const staticID of staticIDs) {
if (item.get(staticID)) {
statMap.set(staticID, statMap.get(staticID) + item.get(staticID));
}
2021-01-07 21:32:36 +00:00
}
2021-01-30 12:03:40 +00:00
if (item.get("majorIds")) {
2021-07-23 07:47:13 +00:00
for (const major_id of item.get("majorIds")) {
major_ids.add(major_id);
}
2021-01-30 12:03:40 +00:00
}
2021-01-07 21:32:36 +00:00
}
2021-01-30 12:03:40 +00:00
statMap.set("activeMajorIDs", major_ids);
for (const [setName, count] of this.activeSetCounts) {
2021-01-10 03:40:15 +00:00
const bonus = sets[setName].bonuses[count-1];
for (const id in bonus) {
if (skp_order.includes(id)) {
// pass. Don't include skillpoints in ids
}
else {
statMap.set(id,(statMap.get(id) || 0)+bonus[id]);
}
2021-01-10 03:40:15 +00:00
}
}
statMap.set("poisonPct", 100);
2021-01-07 06:41:41 +00:00
2021-01-08 04:31:29 +00:00
// The stuff relevant for damage calculation!!! @ferricles
statMap.set("atkSpd", this.weapon.get("atkSpd"));
for (const x of skp_elements) {
this.externalStats.set(x + "DamPct", 0);
}
this.externalStats.set("mdPct", 0);
this.externalStats.set("sdPct", 0);
this.externalStats.set("damageBonus", [0, 0, 0, 0, 0]);
this.externalStats.set("defBonus",[0, 0, 0, 0, 0]);
this.externalStats.set("poisonPct", 0);
2021-01-08 04:31:29 +00:00
this.statMap = statMap;
this.aggregateStats();
2021-01-08 04:31:29 +00:00
}
2021-01-07 00:02:10 +00:00
aggregateStats() {
let statMap = this.statMap;
statMap.set("damageRaw", [this.weapon.get("nDam"), this.weapon.get("eDam"), this.weapon.get("tDam"), this.weapon.get("wDam"), this.weapon.get("fDam"), this.weapon.get("aDam")]);
statMap.set("damageBonus", [statMap.get("eDamPct"), statMap.get("tDamPct"), statMap.get("wDamPct"), statMap.get("fDamPct"), statMap.get("aDamPct")]);
statMap.set("defRaw", [statMap.get("eDef"), statMap.get("tDef"), statMap.get("wDef"), statMap.get("fDef"), statMap.get("aDef")]);
statMap.set("defBonus", [statMap.get("eDefPct"), statMap.get("tDefPct"), statMap.get("wDefPct"), statMap.get("fDefPct"), statMap.get("aDefPct")]);
statMap.set("defMult", classDefenseMultipliers.get(this.weapon.get("type")));
}
2021-01-07 00:02:10 +00:00
}