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

- #1188

Closed
wants to merge 28 commits into from
Closed

- #1188

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.

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)}`;
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
Loading