Skip to content

Commit 61baefe

Browse files
committed
Bug Fixes in Add Ability Success Calculation And Wish List
Addresses malulleybovo#41 - Fixes bug causing innacurate success rate to show on abilities affixed via Add Ability Item. - Fixes bug causing wish list (button below the + icon) not to list success rate boost items nor Add Ability Items. - Fixes bug in wish list causing formulas that do not use special ability transplant to crash the wish list screen.
1 parent 86ccce0 commit 61baefe

File tree

3 files changed

+93
-39
lines changed

3 files changed

+93
-39
lines changed

js/affixingassistant.js

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,46 +1791,49 @@ class Assistant {
17911791
let choice = Assistant.affixDB[affix.code].choices[m];
17921792
// set flag true
17931793
let isMatch = true;
1794-
// Check if Add Ability
1795-
if (choice.isAddAbilityItem || affix.noEx) {
1794+
// Check if SSA.
1795+
if (affix.noEx) {
1796+
// Force 100% success regardless of upslot.
17961797
abilitySuccessRates[k] = Math.min(Math.max(choice.transferRate, minRate), maxRate);
1797-
if (affix.noEx) {
1798-
abilitySuccessRates.length++;
1799-
if (fodderSuccessRate < 0) fodderSuccessRate = (abilitySuccessRates[k] - minRate) / (maxRate - minRate);
1800-
else fodderSuccessRate *= (abilitySuccessRates[k] - minRate) / (maxRate - minRate);
1801-
break;
1798+
abilitySuccessRates.length++;
1799+
if (fodderSuccessRate < 0) fodderSuccessRate = (abilitySuccessRates[k] - minRate) / (maxRate - minRate);
1800+
else fodderSuccessRate *= (abilitySuccessRates[k] - minRate) / (maxRate - minRate);
1801+
break;
1802+
}
1803+
// Check if Add Ability.
1804+
else if (choice.isAddAbilityItem) {
1805+
if (fodder.addAbilityItemInUse === undefined
1806+
|| fodder.addAbilityItemInUse === null
1807+
|| fodder.addAbilityItemInUse.ref !== choice.ref) {
1808+
isMatch = false;
18021809
}
18031810
}
1804-
else {
1805-
// Check if affix in this fodder comes from some fodder with Special Ability Factor
1806-
if (!fodder.affixIndicesFromFactor.includes(k)) {
1807-
// If affix is not from factor, but choice is for factors, it is not a match
1808-
if (choice.isAbilityFactor) {
1809-
isMatch = false;
1810-
}
1811-
else {
1812-
// count occurrences of each ability in choice
1813-
let choiceCount = countOccurrences(choice.materials);
1814-
// count occurrences of each ability in all abilities in page
1815-
let abilityCount = countOccurrences(abilities);
1816-
// for each different occurence in choice
1817-
for (var code in choiceCount) {
1818-
// if all bilities have less than count
1819-
if (!abilityCount[code] || abilityCount[code] < choiceCount[code]) {
1820-
// does not match, so set flag false and break
1821-
isMatch = false;
1822-
break;
1823-
}
1824-
}
1825-
}
1811+
// Check if affix in this fodder does not come from some fodder with Special Ability Factor
1812+
else if (!fodder.affixIndicesFromFactor.includes(k)) {
1813+
// If affix is not from factor, but choice is for factors, it is not a match
1814+
if (choice.isAbilityFactor) {
1815+
isMatch = false;
18261816
}
18271817
else {
1828-
// If affix is from factor, but choice is not for factors, it is not a match
1829-
if (!choice.isAbilityFactor) {
1830-
isMatch = false;
1818+
// count occurrences of each ability in choice
1819+
let choiceCount = countOccurrences(choice.materials);
1820+
// count occurrences of each ability in all abilities in page
1821+
let abilityCount = countOccurrences(abilities);
1822+
// for each different occurence in choice
1823+
for (var code in choiceCount) {
1824+
// if all bilities have less than count
1825+
if (!abilityCount[code] || abilityCount[code] < choiceCount[code]) {
1826+
// does not match, so set flag false and break
1827+
isMatch = false;
1828+
break;
1829+
}
18311830
}
18321831
}
18331832
}
1833+
// If affix is from factor, but choice is not for factors, it is not a match
1834+
else if (!choice.isAbilityFactor) {
1835+
isMatch = false;
1836+
}
18341837
if (isMatch) {
18351838
// match was found, so save the success rate for affixA
18361839
abilitySuccessRates[k] = Math.min(Math.max(Math.round(choice.transferRate), minRate), maxRate);
@@ -2513,6 +2516,47 @@ class Assistant {
25132516
});
25142517
}
25152518

2519+
/**
2520+
* Gets the quantity of each extra item needed to
2521+
* achieve the goal (such as success rate boost
2522+
* items, and Add Ability Items).
2523+
*
2524+
* @returns {Object} Containing the name of each
2525+
* item needed in its keys, and each respective
2526+
* quantity in its values.
2527+
*/
2528+
getExtraItemCart() {
2529+
let fodders = ASSISTANT.query({
2530+
dataClass: Fodder
2531+
});
2532+
let result = {};
2533+
fodders.forEach(fodder => {
2534+
let i = fodder.rateBoostIdx;
2535+
if (i > 0 && i < Assistant.rateBoostOptions.length) {
2536+
let name = Assistant.rateBoostOptions[fodder.rateBoostIdx].id;
2537+
if (result[name]) {
2538+
result[name] += 1;
2539+
} else {
2540+
result[name] = 1;
2541+
}
2542+
}
2543+
});
2544+
fodders.forEach(fodder => {
2545+
if (fodder.addAbilityItemInUse !== undefined
2546+
&& fodder.addAbilityItemInUse !== null
2547+
&& fodder.addAbilityItemInUse.name !== undefined
2548+
&& fodder.addAbilityItemInUse.name !== null) {
2549+
let name = fodder.addAbilityItemInUse.name;
2550+
if (result[name]) {
2551+
result[name] += 1;
2552+
} else {
2553+
result[name] = 1;
2554+
}
2555+
}
2556+
});
2557+
return result;
2558+
}
2559+
25162560
/**
25172561
* Gets the total transplant cost to complete the affixing formula.
25182562
* @returns {Number} The cost.
@@ -2524,6 +2568,7 @@ class Assistant {
25242568
transplantable: true
25252569
}
25262570
});
2571+
if (transpPages.length === 0) return 0;
25272572
return transpPages.map(a => a.transplantCost).reduce((tot, a) => a > 0 ? tot + a : tot);
25282573
}
25292574

js/templates.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ const TRANSPLANT_PANEL = ({ fodders, addAbilityChosen, langCode }) => {
484484
return panel;
485485
};
486486

487-
const SELECTION_MENU_TEMPLATE = ({ type, affixesSelected, categories, datalist, addAbilityChosen, transplantCost, isGlobalSearch, shouldUpslot, shouldSpread, shouldUseTrainer, langCode }) => {
487+
const SELECTION_MENU_TEMPLATE = ({ type, affixesSelected, categories, datalist, successRateItems, addAbilityChosen, transplantCost, isGlobalSearch, shouldUpslot, shouldSpread, shouldUseTrainer, langCode }) => {
488488
let isAffixSelection = type == 'affixSelection';
489489
let isChoiceSelection = type == 'choiceSelection';
490490
let isReviewTweak = type == 'reviewTweak';
@@ -570,6 +570,7 @@ const SELECTION_MENU_TEMPLATE = ({ type, affixesSelected, categories, datalist,
570570
else if (isWishList) {
571571
layoutTemplate += WISH_LIST_TEMPLATE({
572572
fodderList: datalist,
573+
successRateItems: successRateItems,
573574
transplantCost: transplantCost,
574575
langCode: langCode
575576
});
@@ -644,22 +645,20 @@ const FORMULA_SHEET_VIEW_TEMPLATE = ({ categories, abilityList, isGlobalSearch,
644645
});
645646
};
646647

647-
const WISH_LIST_VIEW_TEMPLATE = ({ fodderList, transplantCost, langCode }) => {
648+
const WISH_LIST_VIEW_TEMPLATE = ({ fodderList, successRateItems, transplantCost, langCode }) => {
648649
return SELECTION_MENU_TEMPLATE({
649650
type: 'wishList',
650651
datalist: fodderList,
652+
successRateItems: successRateItems,
651653
transplantCost: transplantCost,
652654
langCode: langCode
653655
});
654656
};
655657

656-
const WISH_LIST_TEMPLATE = ({ fodderList, transplantCost, langCode }) => {
658+
const WISH_LIST_TEMPLATE = ({ fodderList, successRateItems, transplantCost, langCode }) => {
657659
if (!fodderList || !Array.isArray(fodderList)) return '';
658660
let affixLists = [];
659661
let counts = [];
660-
if (transplantCost > 0) {
661-
affixLists.push(lang.app.wishListTransplantCostDescr[langCode](transplantCost));
662-
}
663662
for (var i = 0; i < fodderList.length; i++) {
664663
if (!fodderList[i] || !(fodderList[i] instanceof Fodder)
665664
|| fodderList[i].size() <= 0) continue;
@@ -677,6 +676,15 @@ const WISH_LIST_TEMPLATE = ({ fodderList, transplantCost, langCode }) => {
677676
for (var i = 0; i < affixLists.length; i++) {
678677
affixLists[i] = lang.app.wishListAbilityDescription[langCode](counts[i], affixLists[i]);
679678
}
679+
if (transplantCost > 0) {
680+
let descr = lang.app.wishListTransplantCostDescr[langCode](transplantCost);
681+
affixLists = [descr, ...affixLists];
682+
}
683+
if (successRateItems !== undefined) {
684+
for (var descr in successRateItems) {
685+
affixLists.push(lang.app.wishListAbilityDescription[langCode](successRateItems[descr], descr));
686+
}
687+
}
680688
return FILTER_SEARCH_TEMPLATE({
681689
datalist: affixLists,
682690
langCode: langCode

js/viewcontroller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ViewController {
8484

8585
setup() {
8686
$("#malulleybovo").text(lang.app.malulleybovo[this.langCode]);
87-
$("#ver").text("v1.2.0");
87+
$("#ver").text("v1.2.1");
8888
$("#editor").children().first().panzoom({
8989
which: 1,
9090
minScale: 0.1,
@@ -1793,6 +1793,7 @@ class ViewController {
17931793
$('body').append(
17941794
WISH_LIST_VIEW_TEMPLATE({
17951795
fodderList: this.assistant.getToBuyList(),
1796+
successRateItems: this.assistant.getExtraItemCart(),
17961797
transplantCost: this.assistant.getTotalTransplantCost(),
17971798
langCode: this.langCode
17981799
}));

0 commit comments

Comments
 (0)