Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Golden Cookie percentage calculation to cdf #921 #1190

Merged
merged 3 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/CookieMonster.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonster.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonsterDev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonsterDev.js.map

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/Disp/InfoBars/TimerBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import {
LastNumberOfTimers,
} from '../VariablesAndData';
import { CreateTimer } from './CreateDOMElements';
import {
updateChanceTotal,
getChanceFinalDeer,
getChanceFinal,
updateChanceTotalDeer,
} from '../../Main/CheckStates/Probability';

/**
* This function creates the TimerBar and appends it to l('wrapper')
Expand Down Expand Up @@ -124,9 +130,10 @@ export function UpdateTimerBar() {
(Game.shimmerTypes.golden.time - Game.shimmerTypes.golden.minTime) /
(Game.shimmerTypes.golden.maxTime - Game.shimmerTypes.golden.minTime),
) ** 5;
updateChanceTotal(chanceToSpawn);
l('CMTimerBarGCTime').textContent = `${Math.ceil(
(Game.shimmerTypes.golden.maxTime - Game.shimmerTypes.golden.time) / Game.fps,
)} ${chanceToSpawn < 0.01 ? '<' : ''}${chanceToSpawn.toLocaleString('en', {
)} ${getChanceFinal() < 0.01 ? '<' : ''}${getChanceFinal().toLocaleString('en', {
style: 'percent',
})}`;
numberOfTimers += 1;
Expand Down Expand Up @@ -167,9 +174,10 @@ export function UpdateTimerBar() {
(Game.shimmerTypes.reindeer.time - Game.shimmerTypes.reindeer.minTime) /
(Game.shimmerTypes.reindeer.maxTime - Game.shimmerTypes.reindeer.minTime),
) ** 5;
updateChanceTotalDeer(chanceToSpawn);
l('CMTimerBarRenTime').textContent = `${Math.ceil(
(Game.shimmerTypes.reindeer.maxTime - Game.shimmerTypes.reindeer.time) / Game.fps,
)} ${chanceToSpawn < 0.01 ? '<' : ''}${chanceToSpawn.toLocaleString('en', {
)} ${getChanceFinalDeer() < 0.01 ? '<' : ''}${getChanceFinalDeer().toLocaleString('en', {
style: 'percent',
})}`;
numberOfTimers += 1;
Expand Down
3 changes: 3 additions & 0 deletions src/Main/CheckStates/GoldenCookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
LastGoldenCookieState,
LastSpawnedGoldenCookieState,
} from '../VariablesAndData';
import { resetChanceTotal } from './Probability';

/**
* Auxilirary function that finds all currently spawned shimmers.
Expand Down Expand Up @@ -56,6 +57,8 @@ export default function CheckGoldenCookie() {
'Golden Cookie Spawned',
'A Golden Cookie has spawned. Click it now!',
);
// Reset the cumulative probability when a GC has spawned
resetChanceTotal();
}

Object.keys(Game.shimmers).forEach((i) => {
Expand Down
50 changes: 50 additions & 0 deletions src/Main/CheckStates/Probability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* The probability that a GC or reindeer has NOT spawned
*/
let chanceTotal = 1.0;
let chanceTotalDeer = 1.0;

export function resetChanceTotal() {
chanceTotal = 1.0;
}

export function resetChanceTotalDeer() {
chanceTotalDeer = 1.0;
}

export function getChanceTotal() {
return chanceTotal;
}

export function getChanceTotalDeer() {
return chanceTotalDeer;
}
/**
* Update the probability that a cookie has not spawned
* @param {number} chanceToSpawn The probablity that a GC appears
*/
export function updateChanceTotal(chanceToSpawn) {
chanceTotal *= 1 - chanceToSpawn;
}

/**
* Update the probability that a reindeer has not spawned
* @param {number} chanceToSpawn The probablity that a reindeer appears
*/
export function updateChanceTotalDeer(chanceToSpawn) {
chanceTotalDeer *= 1 - chanceToSpawn;
}
/**
*
* @returns the cummulative probability that a GC has appeared from beginning to now
*/
export function getChanceFinal() {
return 1 - chanceTotal;
}
/**
*
* @returns the cummulative probability that a reindeer has appeared from beginning to now
*/
export function getChanceFinalDeer() {
return 1 - chanceTotalDeer;
}
3 changes: 3 additions & 0 deletions src/Main/CheckStates/Season.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notificationsFunctions as nF } from '@cookiemonsterteam/cookiemonsterframework/src/index';
import { CacheSeasonPopShimmer } from '../../Cache/VariablesAndData'; // eslint-disable-line no-unused-vars
import { LastSeasonPopupState } from '../VariablesAndData';
import { resetChanceTotalDeer } from './Probability';

/**
* This function checks if there is reindeer that has spawned
Expand Down Expand Up @@ -28,5 +29,7 @@ export default function CheckSeasonPopup() {
'Reindeer sighted!',
'A Reindeer has spawned. Click it now!',
);
// Reset the cumulative probability when a deer is spawned
resetChanceTotalDeer();
}
}
Loading