-
Notifications
You must be signed in to change notification settings - Fork 261
/
perkypokeruspandemic.user.js
95 lines (88 loc) · 4.62 KB
/
perkypokeruspandemic.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ==UserScript==
// @name [Pokeclicker] Perky Pokerus Pandemic
// @namespace Pokeclicker Scripts
// @author Ephenia
// @description This script makes it so that Pokérus will spread from any contagious Pokémon (egg) in the Hatchery, regardless of types. It still will not spread from or to eggs with a Hatchery Helper.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 2.0.2
// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
// @downloadURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/custom/perkypokeruspandemic.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/custom/perkypokeruspandemic.user.js
// @match https://www.pokeclicker.com/
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant unsafeWindow
// @run-at document-idle
// ==/UserScript==
function initPokerusPandemic() {
const progressEggsOld = App.game.breeding.progressEggs;
App.game.breeding.progressEggs = function(...args) {
// Spread pokerus before applying egg progress
if (App.game.keyItems.hasKeyItem(KeyItemType.Pokerus_virus)) {
const hasContagious = App.game.breeding.eggList.some((egg, i) => {
return !egg()?.isNone() && !egg().canHatch() && egg().partyPokemon()?.pokerus >= GameConstants.Pokerus.Contagious && (i > App.game.breeding.hatcheryHelpers.hired().length - 1);
});
if (hasContagious) {
for (let i = App.game.breeding.hatcheryHelpers.hired().length; i < App.game.breeding.eggList.length; i++) {
let egg = App.game.breeding.eggList[i]();
if (!egg?.isNone() && egg.partyPokemon()?.pokerus == GameConstants.Pokerus.Uninfected) {
egg.partyPokemon().pokerus = GameConstants.Pokerus.Infected;
}
}
}
}
return progressEggsOld.apply(this, args);
}
}
function loadEpheniaScript(scriptName, initFunction) {
const windowObject = !App.isUsingClient ? unsafeWindow : window;
// Inject handlers if they don't exist yet
if (windowObject.epheniaScriptInitializers === undefined) {
windowObject.epheniaScriptInitializers = {};
const oldInit = Preload.hideSplashScreen;
var hasInitialized = false;
// Initializes scripts once enough of the game has loaded
Preload.hideSplashScreen = function (...args) {
var result = oldInit.apply(this, args);
if (App.game && !hasInitialized) {
// Initialize all attached userscripts
Object.entries(windowObject.epheniaScriptInitializers).forEach(([scriptName, initFunction]) => {
try {
initFunction();
} catch (e) {
console.error(`Error while initializing '${scriptName}' userscript:\n${e}`);
Notifier.notify({
type: NotificationConstants.NotificationOption.warning,
title: scriptName,
message: `The '${scriptName}' userscript crashed while loading. Check for updates or disable the script, then restart the game.\n\nReport script issues to the script developer, not to the Pokéclicker team.`,
timeout: GameConstants.DAY,
});
}
});
hasInitialized = true;
}
return result;
}
}
// Prevent issues with duplicate script names
if (windowObject.epheniaScriptInitializers[scriptName] !== undefined) {
console.warn(`Duplicate '${scriptName}' userscripts found!`);
Notifier.notify({
type: NotificationConstants.NotificationOption.warning,
title: scriptName,
message: `Duplicate '${scriptName}' userscripts detected. This could cause unpredictable behavior and is not recommended.`,
timeout: GameConstants.DAY,
});
let number = 2;
while (windowObject.epheniaScriptInitializers[`${scriptName} ${number}`] !== undefined) {
number++;
}
scriptName = `${scriptName} ${number}`;
}
// Add initializer for this particular script
windowObject.epheniaScriptInitializers[scriptName] = initFunction;
}
if (!App.isUsingClient || localStorage.getItem('perkypokeruspandemic') === 'true') {
loadEpheniaScript('perkypokeruspandemic', initPokerusPandemic);
}