mirror of
https://github.com/IvarK/AntimatterDimensionsSourceCode.git
synced 2024-11-22 04:05:42 +00:00
Merge pull request #2762 from IvarK/separate-ics-and-popup
Separate ics and popup
This commit is contained in:
commit
0562839fcd
@ -35,6 +35,7 @@ export const notify = (function() {
|
||||
success: (text, duration) => showNotification(text, "o-notification--success", duration),
|
||||
error: (text, duration) => showNotification(text, "o-notification--error", duration),
|
||||
info: (text, duration) => showNotification(text, "o-notification--info", duration),
|
||||
infinity: (text, duration) => showNotification(text, "o-notification--infinity", duration),
|
||||
eternity: (text, duration) => showNotification(text, "o-notification--eternity", duration),
|
||||
reality: (text, duration) => showNotification(text, "o-notification--reality", duration),
|
||||
blackHole: (text, duration) => showNotification(text, "o-notification--black-hole", duration),
|
||||
|
@ -200,6 +200,7 @@ Currency.antimatter = new class extends DecimalCurrency {
|
||||
get value() { return player.antimatter; }
|
||||
|
||||
set value(value) {
|
||||
if (InfinityChallenges.nextIC) InfinityChallenges.notifyICUnlock(value);
|
||||
player.antimatter = value;
|
||||
player.records.thisInfinity.maxAM = player.records.thisInfinity.maxAM.max(value);
|
||||
player.records.thisEternity.maxAM = player.records.thisEternity.maxAM.max(value);
|
||||
|
@ -70,7 +70,8 @@ export * from "./sacrifice";
|
||||
export * from "./big_crunch";
|
||||
export * from "./infinity-upgrades";
|
||||
export * from "./break-infinity-upgrades";
|
||||
export * from "./challenge";
|
||||
export * from "./normal-challenges";
|
||||
export * from "./infinity-challenges";
|
||||
export * from "./eternity";
|
||||
export * from "./eternity_challenge";
|
||||
export * from "./reality";
|
||||
|
169
javascripts/core/infinity-challenges.js
Normal file
169
javascripts/core/infinity-challenges.js
Normal file
@ -0,0 +1,169 @@
|
||||
import { GameMechanicState } from "./game-mechanics/index";
|
||||
|
||||
// This function does *not* reset anything. Only call it when you've already
|
||||
// done all the non-UI stuff. Right now the only UI thing to do is switch to
|
||||
// the AD tab.
|
||||
function startChallengeUI() {
|
||||
if (!Enslaved.isRunning) Tab.dimensions.antimatter.show();
|
||||
}
|
||||
|
||||
export function tryCompleteInfinityChallenges() {
|
||||
if (EternityMilestone.autoIC.isReached) {
|
||||
const toComplete = InfinityChallenges.all.filter(x => x.isUnlocked && !x.isCompleted);
|
||||
for (const challenge of toComplete) challenge.complete();
|
||||
}
|
||||
}
|
||||
|
||||
class InfinityChallengeRewardState extends GameMechanicState {
|
||||
constructor(config, challenge) {
|
||||
super(config);
|
||||
this._challenge = challenge;
|
||||
}
|
||||
|
||||
get isEffectActive() {
|
||||
return this._challenge.isCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
class InfinityChallengeState extends GameMechanicState {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
this._reward = new InfinityChallengeRewardState(config.reward, this);
|
||||
}
|
||||
|
||||
get unlockAM() {
|
||||
return this.config.unlockAM;
|
||||
}
|
||||
|
||||
get isUnlocked() {
|
||||
return player.records.thisEternity.maxAM.gte(this.unlockAM) || (Achievement(133).isUnlocked && !Pelle.isDoomed) ||
|
||||
(PelleUpgrade.keepInfinityChallenges.canBeApplied && Pelle.cel.records.totalAntimatter.gte(this.unlockAM));
|
||||
}
|
||||
|
||||
get isRunning() {
|
||||
return player.challenge.infinity.current === this.id;
|
||||
}
|
||||
|
||||
requestStart() {
|
||||
if (!this.isUnlocked) return;
|
||||
if (!player.options.confirmations.challenges) {
|
||||
this.start();
|
||||
return;
|
||||
}
|
||||
Modal.startInfinityChallenge.show(this.id);
|
||||
}
|
||||
|
||||
start() {
|
||||
if (!this.isUnlocked || this.isRunning) return;
|
||||
player.challenge.normal.current = 0;
|
||||
player.challenge.infinity.current = this.id;
|
||||
bigCrunchResetValues();
|
||||
startChallengeUI();
|
||||
player.break = true;
|
||||
if (EternityChallenge.isRunning) Achievement(115).unlock();
|
||||
}
|
||||
|
||||
get isCompleted() {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
return (player.challenge.infinity.completedBits & (1 << this.id)) !== 0;
|
||||
}
|
||||
|
||||
complete() {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
player.challenge.infinity.completedBits |= 1 << this.id;
|
||||
EventHub.dispatch(GAME_EVENT.INFINITY_CHALLENGE_COMPLETED);
|
||||
}
|
||||
|
||||
get isEffectActive() {
|
||||
return this.isRunning;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {InfinityChallengeRewardState}
|
||||
*/
|
||||
get reward() {
|
||||
return this._reward;
|
||||
}
|
||||
|
||||
get isQuickResettable() {
|
||||
return this.config.isQuickResettable;
|
||||
}
|
||||
|
||||
get goal() {
|
||||
return this.config.goal;
|
||||
}
|
||||
|
||||
updateChallengeTime() {
|
||||
const bestTimes = player.challenge.infinity.bestTimes;
|
||||
if (bestTimes[this.id - 1] <= player.records.thisInfinity.time) {
|
||||
return;
|
||||
}
|
||||
// TODO: remove splice once player.challenge.infinity.bestTimes is not reactive
|
||||
bestTimes.splice(this.id - 1, 1, player.records.thisInfinity.time);
|
||||
GameCache.infinityChallengeTimeSum.invalidate();
|
||||
}
|
||||
|
||||
exit() {
|
||||
player.challenge.infinity.current = 0;
|
||||
bigCrunchResetValues();
|
||||
if (!Enslaved.isRunning) Tab.dimensions.antimatter.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} id
|
||||
* @return {InfinityChallengeState}
|
||||
*/
|
||||
export const InfinityChallenge = InfinityChallengeState.createAccessor(GameDatabase.challenges.infinity);
|
||||
|
||||
/**
|
||||
* @returns {InfinityChallengeState}
|
||||
*/
|
||||
Object.defineProperty(InfinityChallenge, "current", {
|
||||
get: () => (player.challenge.infinity.current > 0
|
||||
? InfinityChallenge(player.challenge.infinity.current)
|
||||
: undefined),
|
||||
});
|
||||
|
||||
Object.defineProperty(InfinityChallenge, "isRunning", {
|
||||
get: () => InfinityChallenge.current !== undefined,
|
||||
});
|
||||
|
||||
export const InfinityChallenges = {
|
||||
/**
|
||||
* @type {InfinityChallengeState[]}
|
||||
*/
|
||||
all: InfinityChallenge.index.compact(),
|
||||
completeAll() {
|
||||
for (const challenge of InfinityChallenges.all) challenge.complete();
|
||||
},
|
||||
clearCompletions() {
|
||||
player.challenge.infinity.completedBits = 0;
|
||||
},
|
||||
get nextIC() {
|
||||
return InfinityChallenges.all.find(x => !x.isUnlocked);
|
||||
},
|
||||
get nextICUnlockAM() {
|
||||
return this.nextIC?.unlockAM;
|
||||
},
|
||||
/**
|
||||
* Displays a notification if the antimatter gained will surpass the next unlockAM requirement.
|
||||
* @param value {Decimal} - total antimatter
|
||||
*/
|
||||
notifyICUnlock(value) {
|
||||
// Disable the popup if the user will automatically complete the IC.
|
||||
if (EternityMilestone.autoIC.isReached) return;
|
||||
if (InfinityChallenges.nextIC === undefined) return;
|
||||
for (const ic of InfinityChallenges.all) {
|
||||
if (ic.isUnlocked || ic.isCompleted) continue;
|
||||
if (value.lt(ic.unlockAM)) break;
|
||||
GameUI.notify.infinity(`You have unlocked Infinity Challenge ${ic.id}`);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @returns {InfinityChallengeState[]}
|
||||
*/
|
||||
get completed() {
|
||||
return InfinityChallenges.all.filter(ic => ic.isCompleted);
|
||||
}
|
||||
};
|
@ -8,13 +8,6 @@ function startChallengeUI() {
|
||||
if (!Enslaved.isRunning) Tab.dimensions.antimatter.show();
|
||||
}
|
||||
|
||||
export function tryCompleteInfinityChallenges() {
|
||||
if (EternityMilestone.autoIC.isReached) {
|
||||
const toComplete = InfinityChallenges.all.filter(x => x.isUnlocked && !x.isCompleted);
|
||||
for (const challenge of toComplete) challenge.complete();
|
||||
}
|
||||
}
|
||||
|
||||
export function updateNormalAndInfinityChallenges(diff) {
|
||||
if (NormalChallenge(11).isRunning || InfinityChallenge(6).isRunning) {
|
||||
if (AntimatterDimension(2).amount.neq(0)) {
|
||||
@ -167,143 +160,3 @@ export const NormalChallenges = {
|
||||
player.challenge.normal.completedBits = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class InfinityChallengeRewardState extends GameMechanicState {
|
||||
constructor(config, challenge) {
|
||||
super(config);
|
||||
this._challenge = challenge;
|
||||
}
|
||||
|
||||
get isEffectActive() {
|
||||
return this._challenge.isCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
class InfinityChallengeState extends GameMechanicState {
|
||||
constructor(config) {
|
||||
super(config);
|
||||
this._reward = new InfinityChallengeRewardState(config.reward, this);
|
||||
}
|
||||
|
||||
get unlockAM() {
|
||||
return this.config.unlockAM;
|
||||
}
|
||||
|
||||
get isUnlocked() {
|
||||
return player.records.thisEternity.maxAM.gte(this.unlockAM) || (Achievement(133).isUnlocked && !Pelle.isDoomed) ||
|
||||
(PelleUpgrade.keepInfinityChallenges.canBeApplied && Pelle.cel.records.totalAntimatter.gte(this.unlockAM));
|
||||
}
|
||||
|
||||
get isRunning() {
|
||||
return player.challenge.infinity.current === this.id;
|
||||
}
|
||||
|
||||
requestStart() {
|
||||
if (!this.isUnlocked) return;
|
||||
if (!player.options.confirmations.challenges) {
|
||||
this.start();
|
||||
return;
|
||||
}
|
||||
Modal.startInfinityChallenge.show(this.id);
|
||||
}
|
||||
|
||||
start() {
|
||||
if (!this.isUnlocked || this.isRunning) return;
|
||||
player.challenge.normal.current = 0;
|
||||
player.challenge.infinity.current = this.id;
|
||||
bigCrunchResetValues();
|
||||
startChallengeUI();
|
||||
player.break = true;
|
||||
if (EternityChallenge.isRunning) Achievement(115).unlock();
|
||||
}
|
||||
|
||||
get isCompleted() {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
return (player.challenge.infinity.completedBits & (1 << this.id)) !== 0;
|
||||
}
|
||||
|
||||
complete() {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
player.challenge.infinity.completedBits |= 1 << this.id;
|
||||
EventHub.dispatch(GAME_EVENT.INFINITY_CHALLENGE_COMPLETED);
|
||||
}
|
||||
|
||||
get isEffectActive() {
|
||||
return this.isRunning;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {InfinityChallengeRewardState}
|
||||
*/
|
||||
get reward() {
|
||||
return this._reward;
|
||||
}
|
||||
|
||||
get isQuickResettable() {
|
||||
return this.config.isQuickResettable;
|
||||
}
|
||||
|
||||
get goal() {
|
||||
return this.config.goal;
|
||||
}
|
||||
|
||||
updateChallengeTime() {
|
||||
const bestTimes = player.challenge.infinity.bestTimes;
|
||||
if (bestTimes[this.id - 1] <= player.records.thisInfinity.time) {
|
||||
return;
|
||||
}
|
||||
// TODO: remove splice once player.challenge.infinity.bestTimes is not reactive
|
||||
bestTimes.splice(this.id - 1, 1, player.records.thisInfinity.time);
|
||||
GameCache.infinityChallengeTimeSum.invalidate();
|
||||
}
|
||||
|
||||
exit() {
|
||||
player.challenge.infinity.current = 0;
|
||||
bigCrunchResetValues();
|
||||
if (!Enslaved.isRunning) Tab.dimensions.antimatter.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} id
|
||||
* @return {InfinityChallengeState}
|
||||
*/
|
||||
export const InfinityChallenge = InfinityChallengeState.createAccessor(GameDatabase.challenges.infinity);
|
||||
|
||||
/**
|
||||
* @returns {InfinityChallengeState}
|
||||
*/
|
||||
Object.defineProperty(InfinityChallenge, "current", {
|
||||
get: () => (player.challenge.infinity.current > 0
|
||||
? InfinityChallenge(player.challenge.infinity.current)
|
||||
: undefined),
|
||||
});
|
||||
|
||||
Object.defineProperty(InfinityChallenge, "isRunning", {
|
||||
get: () => InfinityChallenge.current !== undefined,
|
||||
});
|
||||
|
||||
export const InfinityChallenges = {
|
||||
/**
|
||||
* @type {InfinityChallengeState[]}
|
||||
*/
|
||||
all: InfinityChallenge.index.compact(),
|
||||
completeAll() {
|
||||
for (const challenge of InfinityChallenges.all) challenge.complete();
|
||||
},
|
||||
clearCompletions() {
|
||||
player.challenge.infinity.completedBits = 0;
|
||||
},
|
||||
get nextIC() {
|
||||
return InfinityChallenges.all.find(x => !x.isUnlocked);
|
||||
},
|
||||
get nextICUnlockAM() {
|
||||
return this.nextIC?.unlockAM;
|
||||
},
|
||||
/**
|
||||
* @returns {InfinityChallengeState[]}
|
||||
*/
|
||||
get completed() {
|
||||
return InfinityChallenges.all.filter(ic => ic.isCompleted);
|
||||
}
|
||||
};
|
@ -5914,6 +5914,11 @@ kbd {
|
||||
border-color: #4980cc;
|
||||
}
|
||||
|
||||
.o-notification--infinity {
|
||||
background-color: var(--color-infinity);
|
||||
border-color: var(--color-infinity);
|
||||
}
|
||||
|
||||
.o-notification--eternity {
|
||||
background-color: var(--color-eternity);
|
||||
border-color: var(--color-eternity);
|
||||
|
Loading…
Reference in New Issue
Block a user