Reworked getItemLevel to filter all equip slots
This commit is contained in:
parent
a677d723cb
commit
52a8960f71
1 changed files with 28 additions and 33 deletions
|
@ -236,48 +236,43 @@ class CardCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
getItemLevel(gearset) {
|
getItemLevel(gearset) {
|
||||||
let ilvl = 0;
|
let itemLevelSum = 0;
|
||||||
let cnt = 0;
|
|
||||||
let mainHandLvl = 0;
|
|
||||||
let hasOffHand = false;
|
|
||||||
|
|
||||||
for (const [key, piece] of Object.entries(gearset)) {
|
for (const [key, piece] of Object.entries(gearset)) {
|
||||||
if (key == 'SoulCrystal')
|
|
||||||
continue;
|
// Exclude SoulCrystal from item level sum
|
||||||
|
if (key !== 'SoulCrystal') {
|
||||||
if (key == 'MainHand')
|
|
||||||
mainHandLvl = piece.Item.LevelItem;
|
// If this item is a special one, increase the total item level by only 1
|
||||||
|
if (this.ilvlFilterIds.includes(piece.Item.ID) == true) {
|
||||||
if (key == 'OffHand')
|
itemLevelSum += 1;
|
||||||
hasOffHand = true;
|
} else {
|
||||||
|
itemLevelSum += piece.Item.LevelItem;
|
||||||
if (this.ilvlFilterIds.includes(piece.Item.ID) == true) {
|
}
|
||||||
ilvl += 1;
|
|
||||||
} else {
|
|
||||||
ilvl += piece.Item.LevelItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasOffHand) {
|
// If there is no OffHand, the MainHand item level counts twice
|
||||||
ilvl += mainHandLvl;
|
if (gearset.Offhand != null && typeof gearset.MainHand != 'number') {
|
||||||
cnt++;
|
const piece = gearset.MainHand;
|
||||||
|
|
||||||
|
// If this item is a special one, increase the total item level by only 1
|
||||||
|
if (this.ilvlFilterIds.includes(piece.Item.ID) == true) {
|
||||||
|
itemLevelSum += 1;
|
||||||
|
} else {
|
||||||
|
itemLevelSum += piece.Item.LevelItem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cnt == 0)
|
// Average item level computation is always for 13 items
|
||||||
return 0;
|
// Job stones are ignored
|
||||||
|
return this.pad(Math.floor(itemLevelSum / 13), 4);
|
||||||
// ilvl division is always out of 13 items
|
|
||||||
// mainhand counts twice if there's no offhand
|
|
||||||
// job stones are ignored
|
|
||||||
return this.pad(Math.floor(ilvl / 13), 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pad(num, size) {
|
pad(number, size) {
|
||||||
num = num.toString();
|
const string = String(number);
|
||||||
while (num.length < size) num = '0' + num;
|
const paddingCount = Math.max(size - string.length, 0);
|
||||||
return num;
|
return '0'.repeat(paddingCount) + string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue