Allow STD respec after 3 days

This commit is contained in:
SpectralFlame 2022-12-01 06:16:59 -06:00
parent 5e426adda1
commit 98f3b44a75
2 changed files with 25 additions and 6 deletions

View File

@ -8,6 +8,7 @@ export const ShopPurchaseData = {
totalSTD: 0,
spentSTD: 0,
respecAvailable: false,
lastRespec: "",
get availableSTD() {
return this.totalSTD - this.spentSTD;
@ -17,10 +18,21 @@ export const ShopPurchaseData = {
return Cloud.loggedIn && this.availableSTD >= 0 && player.IAP.enabled;
},
// We also allow for respecs if it's been at least 3 days since the last one
get timeUntilRespec() {
const msSinceLast = Date.now() - new Date(ShopPurchaseData.lastRespec).getTime();
return TimeSpan.fromMilliseconds(3 * 86400 * 1000 - msSinceLast);
},
get canRespec() {
return this.respecAvailable || this.timeUntilRespec.totalDays <= 0;
},
updateLocalSTD(newData) {
this.totalSTD = newData.totalSTD;
this.spentSTD = newData.spentSTD;
this.respecAvailable = newData.respecAvailable;
this.lastRespec = newData.lastRespec ?? 0;
for (const key of Object.keys(GameDatabase.shopPurchases)) this[key] = newData[key] ?? 0;
GameStorage.save();
},
@ -53,7 +65,7 @@ export const ShopPurchaseData = {
},
async respecAll() {
if (!this.respecAvailable) {
if (!this.canRespec) {
Modal.message.show(`You do not have a respec available. Making an STD purchase allows you to respec your upgrades
once. You can only have at most one of these respecs, and they do not refund offline production purchases.`);
return;

View File

@ -24,7 +24,8 @@ export default {
creditsClosed: false,
loggedIn: false,
username: "",
respecAvailable: false,
canRespec: false,
respecTimeStr: "",
};
},
computed: {
@ -36,7 +37,7 @@ export default {
},
respecText() {
if (!this.loggedIn) return "Not logged in!";
if (!this.respecAvailable) return "No respec available! (Purchase STDs to gain a respec)";
if (!this.canRespec) return "No respec available! (Purchase STDs or wait 3 days since your last one)";
return null;
}
},
@ -49,7 +50,10 @@ export default {
this.creditsClosed = GameEnd.creditsEverClosed;
this.loggedIn = Cloud.loggedIn;
this.username = Cloud.user?.displayName;
this.respecAvailable = ShopPurchaseData.respecAvailable;
this.canRespec = ShopPurchaseData.canRespec;
if (!ShopPurchaseData.respecAvailable && !this.canRespec) {
this.respecTimeStr = ShopPurchaseData.timeUntilRespec.toStringShort();
}
},
showStore() {
if (this.creditsClosed) return;
@ -61,7 +65,7 @@ export default {
Payments.cancelPurchase(false);
},
respec() {
if (this.creditsClosed || !this.loggedIn || !this.respecAvailable) return;
if (this.creditsClosed || !this.loggedIn || !this.canRespec) return;
ShopPurchaseData.respecRequest();
},
toggleEnable() {
@ -73,7 +77,7 @@ export default {
return {
"o-primary-btn--subtab-option": true,
"o-pelle-disabled-pointer": this.creditsClosed,
"o-primary-btn--disabled": !this.loggedIn || !this.respecAvailable
"o-primary-btn--disabled": !this.loggedIn || !this.canRespec
};
}
},
@ -107,6 +111,9 @@ export default {
Respec Shop
</PrimaryButton>
</div>
<div v-if="!canRespec">
Time until respec available: {{ respecTimeStr }}
</div>
<div
v-if="loggedIn"
class="c-login-info"