Skip to content

Commit

Permalink
Add stock market tooltip info (#1189)
Browse files Browse the repository at this point in the history
* Add info to stock market tooltips

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add up and down arrows to expected value

---------

Co-authored-by: srs42006 <45675882+srs42006@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent ce14fa6 commit ca1c28d
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 16 deletions.
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.

18 changes: 6 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Data/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,14 @@ const settings = {
'Shows a tooltip for plants that have a cookie reward.',
true,
),
TooltipStocks: new settingClasses.SettingStandard(
1,
'bool',
'Tooltip',
['Stock market tooltips OFF', 'Stock market tooltips ON'],
'Shows additional info in the stock market tooltips.',
true,
),
TooltipPantheon: new settingClasses.SettingStandard(
1,
'bool',
Expand Down
52 changes: 52 additions & 0 deletions src/Disp/HelperFunctions/CalculateStockNextExpectedValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* This function calculates a stock's next expected value
* @param {number} value The stock's current value
* @param {number} delta The stock's current delta
* @param {number} restingValue The stock's resting value
* @param {number} mode The stock's current mode
* @param {number} bankLevel The bank building level
* @param {number} dragonBoost The current aura multiplier from Supreme Intellect and Reality Bending
* @returns {number} value + delta The stock's next expected value
*/
export default function CalculateStockNextExpectedValue(
pValue,
pDelta,
restingValue,
mode,
bankLevel,
dragonBoost,
) {
let value = pValue;
let delta = pDelta;
delta *= 0.97 + 0.01 * dragonBoost;
switch (mode) {
case 0:
delta *= 0.95;
break;
case 1:
delta *= 0.99;
delta += 0.02;
break;
case 2:
delta *= 0.99;
delta -= 0.02;
break;
case 3:
delta += 0.06;
value += 2.5;
break;
case 4:
delta -= 0.06;
value -= 2.5;
break;
default:
break;
}
value += (restingValue - value) * 0.01;
if (mode === 3) value -= 0.582;
if (mode === 4) value += 0.6;
if (value > 100 + (bankLevel - 1) * 3 && delta > 0) delta *= 0.9;
if (value < 5) value += (5 - value) * 0.5;
if (value < 5 && delta < 0) delta *= 0.95;
return Math.max(value + delta, 1);
}
3 changes: 3 additions & 0 deletions src/Disp/Tooltips/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export function CreateTooltip(type, name) {
l('tooltip').innerHTML = Game.ObjectsById[2].minigame.tileTooltip(name[0], name[1])();
// Harvest all button in garden
else if (type === 'ha') l('tooltip').innerHTML = Game.ObjectsById[2].minigame.toolTooltip(1)();
// Stock market
else if (type === 'sm') l('tooltip').innerHTML = Game.Objects.Bank.minigame.goodTooltip(name)();
else if (type === 'wb') l('tooltip').innerHTML = '';
else if (type === 'pag') l('tooltip').innerHTML = Game.Objects.Temple.minigame.godTooltip(name)();
else if (type === 'pas')
Expand All @@ -111,6 +113,7 @@ export function CreateTooltip(type, name) {
type === 'g' ||
(type === 'p' && !Game.keys[16]) ||
type === 'ha' ||
type === 'sm' ||
type === 'wb' ||
type === 'pag' ||
(type === 'pas' && name[1] !== -1)
Expand Down
72 changes: 72 additions & 0 deletions src/Disp/Tooltips/TypesOfTooltips/StockMarket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Beautify from '../../BeautifyAndFormatting/Beautify';
import {
TooltipName,
ColourTextPre,
ColourGreen,
ColourYellow,
ColourOrange,
ColourRed,
ColourPurple,
ColourGray,
} from '../../VariablesAndData';
import CalculateStockNextExpectedValue from '../../HelperFunctions/CalculateStockNextExpectedValue';
import * as Create from '../CreateTooltip';

/**
* This function adds extra info to the stock market
* It adds to the additional information to l('CMTooltipArea')
*/
export default function StockMarket() {
const { minigame } = Game.Objects.Bank;
if (Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TooltipStocks) {
const tooltipBox = l('CMTooltipBorder');
const stock = minigame.goodsById[TooltipName];

// Current stock mode
tooltipBox.appendChild(Create.TooltipCreateHeader('Current Mode'));
const stockMode = document.createElement('div');
stockMode.id = 'CMTooltipMode';
tooltipBox.appendChild(stockMode);
const modeIndex = stock.mode;
const modes = ['Stable', 'Slow Rise', 'Slow Fall', 'Fast Rise', 'Fast Fall', 'Chaotic'];
stockMode.textContent = modes[modeIndex];
const colours = [ColourGray, ColourYellow, ColourOrange, ColourGreen, ColourRed, ColourPurple];
stockMode.className = ColourTextPre + colours[modeIndex];

// Current stock delta value
tooltipBox.appendChild(Create.TooltipCreateHeader('Delta'));
const delta = document.createElement('div');
delta.id = 'CMTooltipDelta';
tooltipBox.appendChild(delta);
delta.textContent = Beautify(stock.d);
const deltaColour = stock.d < 0 ? ColourRed : ColourGreen;
delta.className = ColourTextPre + deltaColour;

// Stock resting value
tooltipBox.appendChild(Create.TooltipCreateHeader('Resting Value'));
const restingValue = document.createElement('div');
restingValue.id = 'CMTooltipRestingValue';
tooltipBox.appendChild(restingValue);
restingValue.textContent = `$${Beautify(minigame.getRestingVal(stock.id))}`;
restingValue.style.color = 'white';

// Next expected value
tooltipBox.appendChild(Create.TooltipCreateHeader('Expected Next Value'));
const expectedNextValue = document.createElement('div');
expectedNextValue.id = 'CMTooltipExpectedValue';
tooltipBox.appendChild(expectedNextValue);
const expectedValue = CalculateStockNextExpectedValue(
stock.val,
stock.d,
minigame.getRestingVal(stock.id),
stock.mode,
Game.Objects.Bank.level,
Game.auraMult('Supreme Intellect'),
);
expectedNextValue.textContent = `$${Beautify(expectedValue) + (expectedValue < stock.val ? '\u25bc' : '\u25b2')}`;
const expectedNextValueColour = expectedValue < stock.val ? ColourRed : ColourGreen;
expectedNextValue.className = ColourTextPre + expectedNextValueColour;

l('CMTooltipArea').appendChild(tooltipBox);
} else l('CMTooltipArea').style.display = 'none';
}
3 changes: 3 additions & 0 deletions src/Disp/Tooltips/UpdateTooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TooltipName, TooltipType } from '../VariablesAndData';
import * as Create from './CreateTooltip';
import Building from './TypesOfTooltips/Building';
import GardenPlots from './TypesOfTooltips/GardenPlots';
import StockMarket from './TypesOfTooltips/StockMarket';
import Grimoire from './TypesOfTooltips/Grimoire';
import HarvestAll from './TypesOfTooltips/HarvestAll';
import PantheonGods from './TypesOfTooltips/PantheonGods';
Expand Down Expand Up @@ -33,6 +34,8 @@ export default function UpdateTooltips() {
GardenPlots();
} else if (TooltipType === 'ha') {
HarvestAll();
} else if (TooltipType === 'sm') {
StockMarket();
} else if (TooltipType === 'wb') {
WrinklerButton();
} else if (TooltipType === 'pag' || (TooltipType === 'pas' && TooltipName[1] !== -1)) {
Expand Down
16 changes: 16 additions & 0 deletions src/Main/ReplaceGameElements/Tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ function ReplaceTooltipGarden() {
}
}

/**
* This function replaces the original .onmouseover functions of all stocks
*/
function ReplaceTooltipMarket() {
if (Game.Objects.Bank.minigameLoaded) {
for (let i = 0; i < Game.Objects.Bank.minigame.goodsById.length; i++) {
l(`bankGood-${i}`).firstChild.onmouseover = function () {
Game.tooltip.dynamic = 1;
Game.tooltip.draw(this, () => CreateTooltip('sm', i), 'this');
Game.tooltip.wobble();
};
}
}
}

function ReplaceTooltipPantheon() {
if (Game.Objects.Temple.minigameLoaded) {
for (let i = 0; i < 11; i += 1) {
Expand Down Expand Up @@ -96,6 +111,7 @@ export default function ReplaceTooltips() {
LoadMinigames();
ReplaceTooltipGarden();
ReplaceTooltipGrimoire();
ReplaceTooltipMarket();
ReplaceTooltipPantheon();
ReplaceNativeGrimoire();
};
Expand Down

0 comments on commit ca1c28d

Please sign in to comment.