-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parser Changes #19
base: master
Are you sure you want to change the base?
Parser Changes #19
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable no-plusplus */ | ||
/* eslint-disable camelcase,no-param-reassign */ | ||
const util = require('../util'); | ||
const constants = require('../constants'); | ||
|
@@ -26,6 +27,7 @@ const baseStats = { | |
mining_fortune: 0, | ||
farming_fortune: 0, | ||
foraging_fortune: 0, | ||
pristine: 0, | ||
}; | ||
|
||
async function getInventory({ data = '' }, active = false) { | ||
|
@@ -145,7 +147,6 @@ class Player { | |
slayer_bosses = {}, | ||
unlocked_coll_tiers = [], | ||
collection = {}, | ||
// Inventories | ||
inv_armor = {}, | ||
inv_contents = {}, | ||
fishing_bag = {}, | ||
|
@@ -162,6 +163,25 @@ class Player { | |
fairy_souls_collected = 0, | ||
fairy_souls = 0, | ||
fairy_exchanges = 0, | ||
// dungeons data for layout | ||
dungeons = {}, | ||
essence_undead = 0, | ||
essence_diamond = 0, | ||
essence_dragon = 0, | ||
essence_gold = 0, | ||
essence_ice = 0, | ||
essence_wither = 0, | ||
essence_spider = 0, | ||
perks = {}, | ||
// potion data | ||
active_effects: active_potions = [], | ||
paused_effects: paused_potions = [], | ||
disabled_potion_effects: disabled_potions = [], | ||
temp_stat_buffs: cake_soul_buffs = [], | ||
// mining data | ||
mining_core = {}, | ||
forge = {}, | ||
|
||
...rest | ||
} = data; | ||
|
||
|
@@ -188,7 +208,26 @@ class Player { | |
.map(async (slot) => getInventory(backpack_contents[slot]))); | ||
this.backpack_icons = await Promise.all(Object.keys(backpack_icons) | ||
.map(async (slot) => getInventory(backpack_icons[slot]))); | ||
// relocate bag types to new key | ||
this.player_inventories = { | ||
inventory: this.inventory, | ||
armor: this.armor, | ||
ender_chest: this.ender_chest, | ||
personal_vault: this.personal_vault, | ||
backpack_data: { | ||
backpacks: this.backpack, | ||
backpack_icons: this.backpack_icons, | ||
}, | ||
}; | ||
// relocate player inventory types to new key | ||
|
||
this.player_bags = { | ||
talisman_bag: this.talisman_bag, | ||
fishing_bag: this.fishing_bag, | ||
potion_bag: this.potion_bag, | ||
candy_bag: this.candy_bag, | ||
quiver: this.quiver, | ||
}; | ||
const getUnlockedTier = (array) => { | ||
const o = {}; | ||
array.forEach((gen) => { | ||
|
@@ -243,6 +282,29 @@ class Player { | |
}); | ||
|
||
this.last_save = last_save; | ||
dungeons.essence_unlocks = perks; | ||
dungeons.essences = { | ||
essence_undead, | ||
essence_diamond, | ||
essence_dragon, | ||
essence_gold, | ||
essence_ice, | ||
essence_wither, | ||
essence_spider, | ||
}; | ||
this.dungeons = dungeons; | ||
this.appendDungeonData(); | ||
this.potion_data = { | ||
active_potions, | ||
paused_potions, | ||
disabled_potions, | ||
cake_buffs: cake_soul_buffs, | ||
}; | ||
this.HOTM_Data = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change this to all lowercase |
||
mining_core, | ||
forge, | ||
}; | ||
|
||
this.first_join = first_join; | ||
this.coin_purse = Math.round(coin_purse); | ||
this.fairy_souls_collected = fairy_souls_collected; | ||
|
@@ -252,9 +314,11 @@ class Player { | |
this.skills = skills; | ||
this.average_skill_level = parseFloat((averageSkillLevel / 8).toFixed(2)); | ||
// add average_skill_level to 'this' while also getting the average to 2 decimal places | ||
this.collection = collection; | ||
this.collection_tiers = collection_tiers; | ||
this.collections_unlocked = Object.keys(collection_tiers).length; | ||
this.collection_data = { | ||
collection_totals: collection, | ||
collection_tiers, | ||
collections_unlocked: Object.keys(collection_tiers).length, | ||
}; | ||
this.minions = getUnlockedTier(crafted_generators); | ||
this.slayer = { | ||
zombie: getSlayer(slayer_bosses.zombie || {}, 'zombie'), | ||
|
@@ -277,11 +341,102 @@ class Player { | |
|
||
this.bonuses = this.getBonuses(); | ||
this.applyBonuses(); | ||
this.getPristineStats(); | ||
this.attributes.effective_health = this.getEHP(); | ||
|
||
// cleanup of relocated keys: | ||
this.deleteObjectKeys(this, { | ||
player_bags: ['quiver', 'fishing_bag', 'potion_bag', 'talisman_bag', 'candy_bag'], | ||
player_inventories: ['inventory', 'armor', 'ender_chest', 'personal_vault', 'backpack', 'backpack_icons'], | ||
}); | ||
|
||
return this; | ||
})(); | ||
} | ||
|
||
getPristineStats() { | ||
// check if actibe armour has any gems that are topaz | ||
if (this.armor.length < 1) return; | ||
const gemstones = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably meant to use the values from constants here |
||
TOPAZ: { | ||
ROUGH: 0.4, FLAWED: 0.8, FINE: 1.2, FLAWLESS: 1.6, PERFECT: 2, | ||
}, | ||
}; | ||
for (let i = 0; i < this.armor.length; i++) { | ||
const armour_Piece = this.armor[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The general style guide applies here as well, variables should use camelCase aside the values appearing in the API that use snake_case |
||
|
||
const hasGems = armour_Piece.attributes?.gems; | ||
if (hasGems) { | ||
const gem_Keys = Object.keys(hasGems); | ||
for (let t = 0; t < gem_Keys.length; t++) { | ||
if (gem_Keys[t].includes('TOPAZ_')) { | ||
this.attributes.pristine += gemstones.TOPAZ[hasGems[gem_Keys[t]]]; | ||
} else if (gem_Keys[t].match(/UNIVERSAL_\d_gem/g) && hasGems[gem_Keys[t]].includes('TOPAZ')) { | ||
this.attributes.pristine += gemstones.TOPAZ[`${hasGems[gem_Keys[t].replace(/_gem/, '')]}`]; | ||
} | ||
} | ||
} | ||
} | ||
// check for mining tools with pristine stat on hotbar | ||
|
||
let pristine_values = []; | ||
const temp_inv = this.inventory; | ||
for (let i = 0; i < 8; i++) { | ||
if (['pickaxe', 'drill', 'gauntlet'].includes(temp_inv[`${i}`].type)) { | ||
const item_json = temp_inv[i]; | ||
item_json.pristine = 0; | ||
if (item_json?.attributes?.gems && item_json?.attributes?.enchantments) { | ||
const gem_location = item_json.attributes?.gems; | ||
const enchants_locations = item_json.attributes?.enchantments; | ||
const gem_Keys = Object.keys(gem_location); | ||
for (let t = 0; t < gem_Keys.length; t++) { | ||
if (gem_Keys[t].includes('TOPAZ_')) { | ||
item_json.pristine += gemstones.TOPAZ[gem_location[gem_Keys[t]]]; | ||
} else if (gem_Keys[t].match(/UNIVERSAL_\d_gem/g) && gem_location[gem_Keys[t]].includes('TOPAZ')) { | ||
item_json.pristine += gemstones.TOPAZ[`${gem_location[gem_Keys[t].replace(/_gem/, '')]}`]; | ||
} | ||
} | ||
if (enchants_locations.pristine) { | ||
item_json.pristine += enchants_locations.pristine; | ||
} | ||
pristine_values.push(item_json.pristine); | ||
} | ||
} | ||
} | ||
if (pristine_values.length > 1) { | ||
pristine_values.sort((a, b) => a - b); | ||
this.attributes.pristine += pristine_values[0]; | ||
} | ||
|
||
// reset array | ||
pristine_values = []; | ||
// check if player has power artifact | ||
this.active_accessories.forEach((object) => { | ||
if (object.attributes.id === 'POWER_ARTIFACT') { | ||
const gemstonevalue = gemstones.TOPAZ[object.attributes?.gems?.TOPAZ_0]; | ||
if (gemstonevalue) { | ||
pristine_values.push(gemstonevalue); | ||
} else { | ||
pristine_values.push(0); | ||
} | ||
} | ||
}); | ||
if (pristine_values.length > 1) { | ||
pristine_values.sort((a, b) => a - b); | ||
this.attributes.pristine += pristine_values[0]; | ||
} else { | ||
this.attributes.pristine += pristine_values[0]; | ||
} | ||
|
||
if (this.active_pet?.name === 'Bal' && this.active_pet?.rarity === 'LEGENDARY') { | ||
const { level } = this.active_pet; | ||
const multiplier = 0.15; | ||
const pristineMulti = 1 + Math.floor(level * multiplier); | ||
const newPristine = this.attributes.pristine * pristineMulti; | ||
this.attributes.pristine = newPristine; | ||
} | ||
} | ||
|
||
getSkillBonus(skill) { | ||
const bonus = { ...constants.statTemplate }; | ||
const skillStats = constants.bonusStats[`${skill}_skill`]; | ||
|
@@ -532,6 +687,67 @@ class Player { | |
if (this.attributes.defense <= 0) return this.attributes.health; | ||
return Math.round(this.attributes.health * (1 + this.attributes.defense / 100)); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
deleteObjectKeys(object_location, key_object) { | ||
Object.keys(key_object).forEach((key) => { | ||
const key_array = key_object[key]; | ||
for (let i = 0; i < key_array.length; i++) { | ||
try { | ||
delete object_location[key_array[i]]; | ||
// eslint-disable-next-line no-empty | ||
} catch (err) { | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
calculateLevel(experience) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be moved to utils with a more descriptive name |
||
let level = 0; | ||
const XpValues = [ | ||
50, 75, 110, 160, 230, 330, 470, 670, 950, 1340, 1890, 2665, 3760, 5260, 7380, 10300, 14400, | ||
20000, 27600, 38000, 52500, 71500, 97000, 132000, 180000, 243000, 328000, 445000, 600000, | ||
800000, 1065000, 1410000, 1900000, 2500000, 3300000, 4300000, 5600000, 7200000, 9200000, | ||
12000000, 15000000, 19000000, 24000000, 30000000, 38000000, 48000000, 60000000, 75000000, | ||
93000000, 116250000, | ||
]; | ||
for (let i = 0; i < XpValues.length; i++) { | ||
experience -= XpValues[i]; | ||
if (experience < 0) { | ||
level += (1 - (experience * -1) / XpValues[i]); | ||
break; | ||
} | ||
level++; | ||
} | ||
|
||
return Math.min(level, 50); | ||
} | ||
|
||
addLevelsToLocation(directive) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could also be more descriptive |
||
const location = directive; | ||
const location_keys = Object.keys(location); | ||
|
||
for (let i = 0; i < location_keys.length; i++) { | ||
const key = location[location_keys[i]]; | ||
if (key?.experience) { | ||
const floatLevel = this.calculateLevel(key.experience); | ||
const level = Math.floor(floatLevel); | ||
|
||
key.floatLevel = floatLevel; | ||
key.level = level; | ||
} | ||
} | ||
} | ||
|
||
appendDungeonData() { | ||
if (this.dungeons?.dungeon_types) { | ||
this.addLevelsToLocation(this.dungeons.dungeon_types); | ||
} | ||
if (this.dungeons?.player_classes) { | ||
this.addLevelsToLocation(this.dungeons.player_classes); | ||
} | ||
} | ||
} | ||
|
||
module.exports = Player; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidentally a property of 3