Skip to content

Commit

Permalink
Added cummulative probability handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Numbernaut committed Sep 2, 2024
1 parent ca1c28d commit e083c4a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
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();
}
}

0 comments on commit e083c4a

Please sign in to comment.