forked from ensingm2/SteamMonsterGameScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslaveWindows.js
129 lines (104 loc) · 4.21 KB
/
slaveWindows.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//Slave Window Variables
var slaveWindowUICleanup = true; // Hide all UI and disable rendering for slaves. This will help on CPU and possibly RAM usage
var slaveWindowPeriodicRestart = true; // Periodically restarts slaves in attempts to free memory
var slaveWindowPeriodicRestartInterval = 5 * 60 * 1000; // Period to restart slaves (In milliseconds)
var slaveDelayBetweenSpawns = 1000; // Delay (in milliseconds) between when each slave will spawn.
//================= Adding slave windows =============================
// See: https://github.com/ags131/steamMinigameSlaveScript
function runMaster()
{
window.onbeforeunload = function(){ killAllSlaves(false); };
var slavesList = window.slaves = [];
function spawnSlave(){
var num = slavesList.length;
var slaveheight = screen.height / 10;
var params = 'left=0, top='+(num*100)+', width=220, height=100';
var slave = window.open("http://steamcommunity.com/minigame/towerattack/?slave",'slave'+num, params);
slavesList.push(slave);
$J('.slaveWindowCount').text(slavesList.length);
}
function spawnSlaves(cnt){
if(typeof cnt == 'object')
cnt = parseInt(prompt("How many slave windows would you like to open?\n(REMEMBER TO ALLOW POPUPS)", "2"));
if(cnt === 0 || typeof cnt === 'object')
return;
console.log("spawning " + cnt + " slave windows.");
//Mute Sounds
WebStorage.SetLocal('minigame_mute', true);
WebStorage.SetLocal('minigame_mutemusic', true);
g_AudioManager.m_eleMusic.pause();
//Set the local variable (for restarts)
WebStorage.SetLocal('minigame_slaveCount', cnt);
for(var i=0;i<cnt;i++)
setTimeout(spawnSlave, i * slaveDelayBetweenSpawns);
}
function killAllSlaves(deleteAutoSlaveCount){
var newSlaveCount = 0;
while(slavesList.length) {
var toKill = slavesList.pop();
if(toKill){
toKill.close();
//Only "save" slaves that haven't been manually closed. (NOT CURRENTLY WORKING)
newSlaveCount++;
}
}
$J('.slaveWindowCount').text(slavesList.length);
if(deleteAutoSlaveCount){
//Delete the local variable
WebStorage.SetLocal('minigame_slaveCount', 0);
}
else
WebStorage.SetLocal('minigame_slaveCount', newSlaveCount);
}
var cont = $J('<div>').addClass('slaveManager');
var counterStyle = {
'position': 'relative',
'font-weight': 'bold',
'top': '15px',
'color': '#FF8585',
"float": "right",
"margin-right": "40px"
};
$J("#settings").append('<div id="slaves"><div id="spawn_slaves" class="toggle toggle_btn" style="width:25%;margin-left: 25px;margin-right: 50px;"><span class="title">Spawn Slaves</span></div><div id="kill_slaves" class="toggle toggle_btn" style="width:25%;margin-right:50px;float:right"><span class="title">Kill Slaves</span></div><div class="slave_num"><span id="slaveCounter">Slaves: <span class="slaveWindowCount">0</span></span></div></div>');
$J("#spawn_slaves").click(function(e) { e.stopPropagation(); spawnSlaves(e); });
$J("#kill_slaves").click(function(e) { e.stopPropagation(); killAllSlaves(); });
$J('#slaveCounter').css(counterStyle);
var autoOpenSlaveCount = WebStorage.GetLocal('minigame_slaveCount');
if(autoOpenSlaveCount !== null && autoOpenSlaveCount !== 0)
spawnSlaves(autoOpenSlaveCount);
}
function runSlave()
{
if(slaveWindowUICleanup){
var cleanupPageInter = setInterval(function(){
if(window.CUI || g_Minigame.m_CurrentScene.m_bRunning)
{
clearInterval(cleanupPageInter);
$J('body > *').hide();
var cont = $J('body');
$J('<div>').css({
'padding-top': '20px',
'font-family': '"Press Start 2P"',
'font-size': '32pt'
})
.text('Slave')
.appendTo(cont);
g_Minigame.Renderer.render = function(){}; // Disable rendering. Completely.
}
},1000);
}
if(slaveWindowPeriodicRestart) {
var resetInterval = setInterval(function () {
// Only refresh if we're not on a boss / Treasure mob
var target = getTarget();
if(target && target.m_data.type != 2 && target.m_data.type != 4 ){
clearInterval(resetInterval); // Shouldn't need this but meh.
window.location.href = "./?slave";
}
}, slaveWindowPeriodicRestartInterval);
}
//Don't allow slaves to purchase upgrades or use abilities/items
stopAutoAbilityUser();
stopAutoItemUser();
stopAutoUpgradeManager();
}