Update state-checking code
This commit is contained in:
185
src/Main.js
185
src/Main.js
@@ -185,23 +185,13 @@ CM.Loop = function() {
|
||||
CM.Disp.RefreshMenu();
|
||||
}
|
||||
|
||||
// Check Golden Cookies
|
||||
CM.Disp.CheckGoldenCookie();
|
||||
|
||||
// Check Fortune Cookies
|
||||
CM.Disp.CheckTickerFortune();
|
||||
|
||||
// Check Season Popup
|
||||
CM.Disp.CheckSeasonPopup();
|
||||
|
||||
// Check Garden Tick
|
||||
CM.Disp.CheckGardenTick();
|
||||
|
||||
// Check Grimoire Meter
|
||||
CM.Disp.CheckMagicMeter();
|
||||
|
||||
// Check Wrinklers
|
||||
CM.Disp.CheckWrinklerCount();
|
||||
// Check all changing minigames and game-states
|
||||
CM.Main.CheckGoldenCookie();
|
||||
CM.Main.CheckTickerFortune();
|
||||
CM.Main.CheckSeasonPopup();
|
||||
CM.Main.CheckGardenTick();
|
||||
CM.Main.CheckMagicMeter();
|
||||
CM.Main.CheckWrinklerCount();
|
||||
|
||||
// Update Average CPS (might need to move)
|
||||
CM.Cache.UpdateAvgCPS()
|
||||
@@ -257,6 +247,167 @@ CM.DelayInit = function() {
|
||||
Game.Win('Third-party');
|
||||
}
|
||||
|
||||
/********
|
||||
* Section: Functions related to checking for changes in Minigames/GC's/Ticker
|
||||
* TODO: Annotate functions
|
||||
* TODO: Possibly move this section */
|
||||
|
||||
/**
|
||||
* Auxilirary function that finds all currently spawned shimmers.
|
||||
* CM.Cache.spawnedGoldenShimmer stores the non-user spawned cookie to later determine data for the favicon and tab-title
|
||||
* It is called by CM.CM.Main.CheckGoldenCookie
|
||||
*/
|
||||
CM.Main.FindShimmer = function() {
|
||||
CM.Main.currSpawnedGoldenCookieState = 0;
|
||||
CM.Cache.goldenShimmersByID = {}
|
||||
for (var i in Game.shimmers) {
|
||||
CM.Cache.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i]
|
||||
if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') {
|
||||
CM.Cache.spawnedGoldenShimmer = Game.shimmers[i];
|
||||
CM.Main.currSpawnedGoldenCookieState += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks for changes in the amount of Golden Cookies
|
||||
* It is called by CM.Loop
|
||||
* TODO: Remove the delete function, as it does not delete correctly and crowds CM.Disp.GCTimers
|
||||
*/
|
||||
CM.Main.CheckGoldenCookie = function() {
|
||||
CM.Main.FindShimmer();
|
||||
for (var i in CM.Disp.GCTimers) {
|
||||
if (typeof CM.Cache.goldenShimmersByID[i] == "undefined") {
|
||||
CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]);
|
||||
// TODO remove delete here
|
||||
delete CM.Disp.GCTimers[i];
|
||||
}
|
||||
}
|
||||
if (CM.Main.lastGoldenCookieState != Game.shimmerTypes['golden'].n) {
|
||||
CM.Main.lastGoldenCookieState = Game.shimmerTypes['golden'].n;
|
||||
if (CM.Main.lastGoldenCookieState) {
|
||||
if (CM.Main.lastSpawnedGoldenCookieState < CM.Main.currSpawnedGoldenCookieState) {
|
||||
CM.Disp.Flash(3, 'GCFlash');
|
||||
CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume');
|
||||
CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!")
|
||||
}
|
||||
CM.Disp.UpdateFavicon();
|
||||
|
||||
for (var i in Game.shimmers) {
|
||||
if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") {
|
||||
CM.Disp.CreateGCTimer(Game.shimmers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState
|
||||
}
|
||||
else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) {
|
||||
for (var i in CM.Disp.GCTimers) {
|
||||
CM.Disp.GCTimers[i].style.opacity = CM.Cache.goldenShimmersByID[i].l.style.opacity;
|
||||
CM.Disp.GCTimers[i].style.transform = CM.Cache.goldenShimmersByID[i].l.style.transform;
|
||||
CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Cache.goldenShimmersByID[i].life / Game.fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if there is reindeer that has spawned
|
||||
* It is called by CM.Loop
|
||||
*/
|
||||
CM.Main.CheckSeasonPopup = function() {
|
||||
if (CM.Main.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) {
|
||||
CM.Main.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned;
|
||||
for (var i in Game.shimmers) {
|
||||
if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'reindeer') {
|
||||
CM.Cache.seasonPopShimmer = Game.shimmers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
CM.Disp.Flash(3, 'SeaFlash');
|
||||
CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume');
|
||||
CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if there is a fortune cookie on the ticker
|
||||
* It is called by CM.Loop
|
||||
*/
|
||||
CM.Main.CheckTickerFortune = function() {
|
||||
if (CM.Main.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type == 'fortune')) {
|
||||
CM.Main.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune');
|
||||
if (CM.Main.lastTickerFortuneState) {
|
||||
CM.Disp.Flash(3, 'FortuneFlash');
|
||||
CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume');
|
||||
CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if a garden tick has happened
|
||||
* It is called by CM.Loop
|
||||
*/
|
||||
CM.Main.CheckGardenTick = function() {
|
||||
if (Game.Objects['Farm'].minigameLoaded && CM.Main.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) {
|
||||
if (CM.Main.lastGardenNextStep != 0 && CM.Main.lastGardenNextStep < Date.now()) {
|
||||
CM.Disp.Flash(3, 'GardFlash');
|
||||
CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume');
|
||||
}
|
||||
CM.Main.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if the magic meter is full
|
||||
* It is called by CM.Loop
|
||||
*/
|
||||
CM.Main.CheckMagicMeter = function() {
|
||||
if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) {
|
||||
var minigame = Game.Objects['Wizard tower'].minigame;
|
||||
if (minigame.magic < minigame.magicM) CM.Main.lastMagicBarFull = false;
|
||||
else if (!CM.Main.lastMagicBarFull) {
|
||||
CM.Main.lastMagicBarFull = true;
|
||||
CM.Disp.Flash(3, 'MagicFlash');
|
||||
CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume');
|
||||
CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if any new Wrinklers have popped up
|
||||
* It is called by CM.Loop
|
||||
*/
|
||||
CM.Main.CheckWrinklerCount = function() {
|
||||
if (Game.elderWrath > 0) {
|
||||
var CurrentWrinklers = 0;
|
||||
for (var i in Game.wrinklers) {
|
||||
if (Game.wrinklers[i].phase == 2) CurrentWrinklers++;
|
||||
}
|
||||
if (CurrentWrinklers > CM.Main.lastWrinklerCount) {
|
||||
CM.Main.lastWrinklerCount = CurrentWrinklers
|
||||
if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) {
|
||||
CM.Disp.Flash(3, 'WrinklerMaxFlash');
|
||||
} else {
|
||||
CM.Disp.Flash(3, 'WrinklerFlash');
|
||||
}
|
||||
if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) {
|
||||
CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume');
|
||||
} else {
|
||||
CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume');
|
||||
}
|
||||
if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxNotification) {
|
||||
CM.Disp.Notification('WrinklerMaxNotification', "Maximum Wrinklers Reached", "You have reached your maximum ammount of wrinklers")
|
||||
} else {
|
||||
CM.Disp.Notification('WrinklerNotification', "A Wrinkler appeared", "A new wrinkler has appeared")
|
||||
}
|
||||
} else {
|
||||
CM.Main.lastWrinklerCount = CurrentWrinklers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CM.HasReplaceNativeGrimoireLaunch = false;
|
||||
CM.HasReplaceNativeGrimoireDraw = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user