Fixed Golden Cookie percentage calculation to cdf #921 (#1190)

* Added cummulative probability handling

* executed build-dev command

* executed build-final command
This commit is contained in:
Numbernaut
2024-09-08 11:17:00 +02:00
committed by GitHub
parent ca1c28d1fc
commit 9e98208c19
8 changed files with 70 additions and 6 deletions

View File

@@ -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')
@@ -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;
@@ -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;

View File

@@ -8,6 +8,7 @@ import {
LastGoldenCookieState,
LastSpawnedGoldenCookieState,
} from '../VariablesAndData';
import { resetChanceTotal } from './Probability';
/**
* Auxilirary function that finds all currently spawned shimmers.
@@ -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) => {

View File

@@ -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;
}

View File

@@ -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
@@ -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();
}
}