Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,023 changes: 2,846 additions & 177 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.4.0",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jsx-a11y": "^6.3.0",
Expand Down
10 changes: 9 additions & 1 deletion src/constants/bonuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,15 @@ module.exports = {
intelligence: 4,
},
},

gemstones: {
TOPAZ: {
ROUGH: 0.4,
FLAWED: 0.8,
FINE: 1.2,
FLAWLESS: 1.6,
PERFECT: 2,
},
},
enchantments: {
sharpness: {
1: {
Expand Down
8 changes: 8 additions & 0 deletions src/constants/leveling.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = {
taming: 50,
carpentry: 50,
runecrafting: 25,
social: 25,
},

// XP required for each level of Runecrafting
Expand Down Expand Up @@ -160,4 +161,11 @@ module.exports = {
4: 500,
5: 1500,
},
catacombsXP: [
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,
],
};
38 changes: 38 additions & 0 deletions src/constants/pets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,44 @@ module.exports = {
}],
},
},
BAL: {
name: 'Bal',
statModifiers: {
strength: 0.25,
ferocity: 0.1,
},
abilityModifiers: {
0: {},
1: {},
2: {
ability: [0.1, 0.1],
},
3: {
ability: [0.15],
4: {},
Copy link
Member

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

},
abilities: {
0: [{
name: 'Protective Skin',
desc: ['§7Gives Heat immunity'],
}],
1: [],
2: [{
name: 'Fire Whip',
desc: ['§7Every 5s while in combat the Balrog will strike nearby enemies with his fire whip dealing §a%ability%% of your damage as True Damage'],
descFn: (level, multiplier) => Math.floor(level * multiplier),
func: () => ([]), // TODO
}],
3: [{
name: 'Made of Lava',
desc: ['§7Gain §a%ability%% on ALL stats when inside the Magma Fields'],
descFn: (level, multiplier) => Math.floor(level * multiplier),
func: () => ([]), // TODO
}],
4: [],
},
},
},
},

petData: {
Expand Down
1 change: 1 addition & 0 deletions src/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const attributeSchema = {
modifier: 'tag.ExtraAttributes.modifier',
enchantments: 'tag.ExtraAttributes.enchantments',
hot_potato_count: 'tag.ExtraAttributes.hot_potato_count',
gems: 'tag.ExtraAttributes.gems',
origin: 'tag.ExtraAttributes.originTag',
id: 'tag.ExtraAttributes.id',
uuid: 'tag.ExtraAttributes.uuid',
Expand Down
224 changes: 220 additions & 4 deletions src/player/Player.js
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');
Expand Down Expand Up @@ -26,6 +27,7 @@ const baseStats = {
mining_fortune: 0,
farming_fortune: 0,
foraging_fortune: 0,
pristine: 0,
};

async function getInventory({ data = '' }, active = false) {
Expand Down Expand Up @@ -145,7 +147,6 @@ class Player {
slayer_bosses = {},
unlocked_coll_tiers = [],
collection = {},
// Inventories
inv_armor = {},
inv_contents = {},
fishing_bag = {},
Expand All @@ -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;

Expand All @@ -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) => {
Expand Down Expand Up @@ -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 = {
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand All @@ -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'),
Expand All @@ -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 = {
Copy link
Member

Choose a reason for hiding this comment

The 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];
Copy link
Member

Choose a reason for hiding this comment

The 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`];
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The 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) {
Copy link
Member

Choose a reason for hiding this comment

The 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;
Loading