Fix incorrect glyph count when purging

Add missing options for some purge modes
This commit is contained in:
SpectralFlame 2023-04-30 21:08:54 -05:00 committed by cyip92
parent 53b956080b
commit 469b3ad608
7 changed files with 86 additions and 24 deletions

View File

@ -8,8 +8,6 @@ export default {
},
data() {
return {
glyphsTotal: 0,
glyphsDeleted: 0,
isRefining: false,
};
},
@ -33,12 +31,18 @@ export default {
if (this.glyphsDeleted === 0) return `This will remove no Glyphs.`;
if (this.glyphsDeleted === this.glyphsTotal) return `This will remove all your Glyphs.`;
return `This process will remove ${this.glyphsDeleted}/${this.glyphsTotal} Glyphs.`;
}
},
// These two don't need to be reactive since the modal force-closes itself whenever glyphs change
glyphsTotal() {
return Glyphs.inventory.filter(slot => slot !== null).length;
},
glyphsDeleted() {
return Glyphs.deleteAllRejected(false);
},
},
methods: {
update() {
this.glyphsTotal = Glyphs.inventory.filter(slot => slot !== null).length;
this.glyphsDeleted = Glyphs.deleteAllRejected(false);
this.isRefining = GlyphSacrificeHandler.isRefining;
},
handleYesClick() {
@ -49,13 +53,17 @@ export default {
</script>
<template>
<ModalWrapperChoice @confirm="handleYesClick">
<ModalWrapperChoice
option="sacrificeAll"
@confirm="handleYesClick"
>
<template #header>
{{ topLabel }}
</template>
<div class="c-modal-message__text">
{{ message }}
</div>
<br>
<div class="c-modal-hard-reset-danger">
{{ extraMessage }}
</div>

View File

@ -24,7 +24,23 @@ export default {
message() {
return `Are you sure you want to ${this.refiningSacrificingOrDeleting} all unprotected Glyphs
in your inventory?`;
}
},
extraMessage() {
if (this.glyphsDeleted === 0) return `This will ${this.refiningSacrificingOrDeleting} no Glyphs.`;
if (this.glyphsDeleted === this.glyphsTotal) {
return `This will ${this.refiningSacrificingOrDeleting} all your Glyphs.`;
}
return `This will ${this.refiningSacrificingOrDeleting}
${formatInt(this.glyphsDeleted)}/${formatInt(this.glyphsTotal)} of your Glyphs.`;
},
// These two don't need to be reactive since the modal force-closes itself whenever glyphs change
glyphsTotal() {
return Glyphs.inventory.filter(slot => slot !== null).length;
},
glyphsDeleted() {
return Glyphs.autoClean(0, false);
},
},
methods: {
update() {
@ -39,12 +55,19 @@ export default {
</script>
<template>
<ModalWrapperChoice @confirm="handleYesClick">
<ModalWrapperChoice
option="sacrificeAll"
@confirm="handleYesClick"
>
<template #header>
{{ topLabel }}
</template>
<div class="c-modal-hard-reset-danger">
{{ message }}
</div>
<br>
<div class="c-modal-hard-reset-danger">
{{ extraMessage }}
</div>
</ModalWrapperChoice>
</template>

View File

@ -12,12 +12,6 @@ export default {
required: true
}
},
data() {
return {
glyphsTotal: 0,
glyphsDeleted: 0,
};
},
computed: {
threshold() {
return this.harsh ? 1 : 5;
@ -40,12 +34,16 @@ export default {
topLabel() {
return `You are about to ${this.harsh ? `Harsh Purge` : `Purge`} your Glyphs`;
},
// These two don't need to be reactive since the modal force-closes itself whenever glyphs change
glyphsTotal() {
return Glyphs.inventory.filter(slot => slot !== null).length;
},
glyphsDeleted() {
return Glyphs.autoClean(this.threshold, false);
},
},
methods: {
update() {
this.glyphsTotal = Glyphs.inventory.filter(slot => slot !== null).length;
this.glyphsDeleted = Glyphs.autoClean(this.threshold, false);
},
handleYesClick() {
Glyphs.autoClean(this.threshold, true);
},

View File

@ -61,10 +61,18 @@ export default {
}
},
deleteAllUnprotected() {
Modal.deleteAllUnprotectedGlyphs.show();
if (player.options.confirmations.sacrificeAll) {
Modal.deleteAllUnprotectedGlyphs.show();
} else {
Glyphs.autoClean(0);
}
},
deleteAllRejected() {
Modal.deleteAllRejectedGlyphs.show();
if (player.options.confirmations.sacrificeAll) {
Modal.deleteAllRejectedGlyphs.show();
} else {
Glyphs.deleteAllRejected(true);
}
},
slotClass(index) {
return index < Glyphs.protectedSlots ? "c-glyph-inventory__protected-slot" : "c-glyph-inventory__slot";

View File

@ -468,7 +468,7 @@ export const Glyphs = {
},
// If there are enough glyphs that are better than the specified glyph, in every way, then
// the glyph is objectively a useless piece of garbage.
isObjectivelyUseless(glyph, threshold) {
isObjectivelyUseless(glyph, threshold, inventoryIn) {
if (player.reality.applyFilterToPurge && AutoGlyphProcessor.wouldKeep(glyph)) return false;
function hasSomeBetterEffects(glyphA, glyphB, comparedEffects) {
for (const effect of comparedEffects) {
@ -480,7 +480,7 @@ export const Glyphs = {
}
return false;
}
const toCompare = this.inventory.concat(this.active)
const toCompare = (inventoryIn ?? this.inventory).concat(this.active)
.filter(g => g !== null &&
g.type === glyph.type &&
g.id !== glyph.id &&
@ -494,14 +494,18 @@ export const Glyphs = {
return betterCount >= compareThreshold;
},
// Note that this same function is called with different parameters for purge (5), harsh purge (1), and sac all (0)
// If deleteGlyphs === false, we are running this from the modal and are doing so purely to *count* the number of
// removed glyphs. In this case, we copy the inventory and run the purge on the copy - we need to be able to remove
// glyphs as we go, or else the purge logic will be wrong (eg. 7 identical glyphs will all be "worse than 5 others")
autoClean(threshold = 5, deleteGlyphs = true) {
const isHarsh = threshold < 5;
let toBeDeleted = 0;
const inventoryCopy = deleteGlyphs ? undefined : this.fakePurgeIngentory();
// If the player hasn't unlocked sacrifice yet, prevent them from removing any glyphs.
if (!GlyphSacrificeHandler.canSacrifice) return toBeDeleted;
// We look in backwards order so that later glyphs get cleaned up first
for (let inventoryIndex = this.totalSlots - 1; inventoryIndex >= this.protectedSlots; --inventoryIndex) {
const glyph = this.inventory[inventoryIndex];
const glyph = (inventoryCopy ?? this.inventory)[inventoryIndex];
// Never clean companion, and only clean cursed if we choose to sacrifice all
if (glyph === null || glyph.type === "companion" || (glyph.type === "cursed" && threshold !== 0)) continue;
// Don't auto-clean custom glyphs (eg. music glyphs) unless it's harsh or delete all
@ -509,14 +513,30 @@ export const Glyphs = {
if (isCustomGlyph && !isHarsh) continue;
// If the threshold for better glyphs needed is zero, the glyph is definitely getting deleted
// no matter what (well, unless it can't be gotten rid of in current glyph removal mode).
if (threshold === 0 || this.isObjectivelyUseless(glyph, threshold)) {
if (threshold === 0 || this.isObjectivelyUseless(glyph, threshold, inventoryCopy)) {
if (deleteGlyphs) AutoGlyphProcessor.getRidOfGlyph(glyph);
else inventoryCopy.splice(inventoryCopy.indexOf(glyph), 1);
toBeDeleted++;
}
}
if (player.reality.autoCollapse) this.collapseEmptySlots();
return toBeDeleted;
},
// Similar to copyForRecords, except that it also preserves null entries, passes on the IDs, and doesn't
// sort the glyphs; these are all necessary for the purge logic to work correctly
fakePurgeIngentory() {
return this.inventory.map(g => (g === null
? null
: {
id: g.id,
type: g.type,
level: g.level,
strength: g.strength,
effects: g.effects,
color: g.color,
symbol: g.symbol
}));
},
harshAutoClean() {
this.autoClean(1);
},

View File

@ -832,6 +832,7 @@ window.player = {
glyphReplace: true,
glyphSacrifice: true,
autoClean: true,
sacrificeAll: true,
glyphSelection: true,
glyphUndo: true,
deleteGlyphSetSave: true,

View File

@ -53,6 +53,10 @@ GameDatabase.confirmationTypes = [
name: "Glyph Purge",
option: "autoClean",
isUnlocked: () => GlyphSacrificeHandler.canSacrifice,
}, {
name: "Sacrifice All Glyphs",
option: "sacrificeAll",
isUnlocked: () => GlyphSacrificeHandler.canSacrifice,
}, {
name: "Glyph Selection",
option: "glyphSelection",