-
Notifications
You must be signed in to change notification settings - Fork 0
/
automatic_kittens.js
251 lines (229 loc) · 8.79 KB
/
automatic_kittens.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
customConsole = function(message) {
console.log('%c' + message, 'color: #e2861d;');
}
utility = {
getResource: function(name) {
return gamePage.resPool.get(name);
},
isAlmostFull: function(resourceName) {
var resource = utility.getResource(resourceName);
return resource.value / resource.maxValue > 0.95;
},
craftAll: function(craftName) {
if(!automaticKittens.options.autocraft) {
return;
}
// If the craft is enable and unlocked, let's craft it
if (automaticKittens.options.crafting[craftName] && gamePage.workshop.getCraft(craftName).unlocked) {
customConsole('Crafting ' + craftName);
gamePage.craftAll(craftName);
}
},
transformAll: function(resourceName, craftName) {
if (utility.isAlmostFull(resourceName)) {
utility.craftAll(craftName);
}
}
}
function addAutoBuildBtn() {
//gamePage.tabs[0].buttons.forEach(function(button) { if(button.opts.building === 'biolab') { console.log('click on : ', button); /*button.buttonContent.click();*/ } })
//gamePage.bld.getPrices('observatory')
automaticKittens.autoBuildList = [];
gamePage.tabs.forEach(function(tab) {
if(tab.tabId === 'Bonfire') {
tab.buttons.forEach(function(button) {
var autoBuildButton = $('<a href="#" style="padding-left: 2px; float: right; cursor: pointer;">Auto OFF</a>');
var separator = $('<span class="linkBreak" style="float: right; padding-left: 2px;">|</span>');
autoBuildButton.click(function(event) {
if($(this).text().includes('OFF')) {
$(this).text('Auto ON');
automaticKittens.autoBuildList.push(button.opts.building);
} else {
$(this.text('Auto OFF'));
var index = automaticKittens.autoBuildList.indexOf(button.opts.building);
if(index > -1) {
automaticKittens.autoBuildList.splice(index, 1);
}
}
event.stopPropagation();
});
$(button.buttonContent).append(separator);
$(button.buttonContent).append(autoBuildButton);
});
}
});
}
handler = null;
function addCheckBox(element, property) {
var id = property + 'Chkbox';
var checkbox = $('<input id="' + id + '" type="checkbox" />');
checkbox.click(function() {
automaticKittens.options[property] = $('#' + id)[0].checked;
customConsole(automaticKittens);
});
element.append(checkbox);
element.append($('<label for="' + id + '">Activate or not the ' + property + '</label>'));
element.append($('<br />'));
}
function addCraftingCheckBox(element, property) {
var id = "crafting" + property + 'Chkbox';
var checkbox = $('<input id="' + id + '" type="checkbox" />');
checkbox.click(function() {
automaticKittens.options.crafting[property] = $('#' + id)[0].checked;
});
element.append(checkbox);
element.append($('<label for="' + id + '">Activate or not the crafting of ' + property + '</label>'));
element.append($('<br />'));
}
function addHtmlFunctionnality() {
var parametersDiv = $('<div id="automationParameters" class="dialog help"></div>');
parametersDiv.css('height', '380px').css('margin-top', '-190px').css('display', 'none');
var closeParametersLink = $('<a href="#" class="close" style="position: absolute; top: 10px; right: 15px;">close</a>');
closeParametersLink.click(function() {
$('#automationParameters').hide();
});
parametersDiv.append(closeParametersLink);
addCheckBox(parametersDiv, 'enable');
addCheckBox(parametersDiv, 'hunt');
addCheckBox(parametersDiv, 'pray');
addCheckBox(parametersDiv, 'promote');
addCheckBox(parametersDiv, 'autocraft');
addCheckBox(parametersDiv, 'autobuild');
addCraftingCheckBox(parametersDiv, 'parchment');
addCraftingCheckBox(parametersDiv, 'manuscript');
addCraftingCheckBox(parametersDiv, 'compedium');
addCraftingCheckBox(parametersDiv, 'blueprint');
addCraftingCheckBox(parametersDiv, 'wood');
addCraftingCheckBox(parametersDiv, 'beam');
addCraftingCheckBox(parametersDiv, 'slab');
addCraftingCheckBox(parametersDiv, 'plate');
addCraftingCheckBox(parametersDiv, 'steel');
addCraftingCheckBox(parametersDiv, 'kerosene');
addAutoBuildBtn();
parametersDiv.append('<br/>');
$('#importDiv').after(parametersDiv);
var automationLink = $('<a href="#">Automation</a>');
automationLink.click(function() {
$('#automationParameters').toggle();
});
automationLink.after(' | ');
$("#headerLinks .links-block > a:first-child").before(automationLink);
}
/*function addHtmlFunctionnality() {
var linkAutomation = $('<a id="kittensAutomation" href="#">Automation</a>');
linkAutomation.click(function() {
var focusIndex = null;
gamePage.timer.handlers.forEach(function(installedHandler, index) {
if(installedHandler.handler === handler) {
focusIndex = index;
customConsole("findIndex" + focusIndex);
}
});
if(focusIndex) {
gamePage.timer.handlers.splice(focusIndex, 1);
customConsole("uninstall the automation... it's a cheat");
}
});
$('#topBar').after(linkAutomation);
}*/
function launchAutomate() {
window.automaticKittens = {
/**
* Options of the automation
* Basicaly all the options are disable
* Can be enable by the Automation panel
*/
options: {
enable: false,
hunt: false,
pray: false,
promote: false,
autocraft: false,
autobuild: false,
crafting: {
parchment: false,
manuscript: false,
compedium: false,
blueprint: false,
wood: false,
beam: false,
slab: false,
plate: false,
steel: false,
kerosene: false,
gear: false,
concrate: false,
alloy: false,
scaffold: false,
ship: false
}
},
observeSky: function() {
if($('#observeBtn')[0]) {
$('#observeBtn').click();
customConsole('Observing the sky...');
}
},
hunt: function() {
if(utility.isAlmostFull('manpower')) {
customConsole('Let go of the dogs after the rabbits... Or just maybe cat after unicorns !!!');
$("a:contains('Send hunters')").click();
utility.craftAll('parchment');
utility.craftAll('manuscript');
utility.craftAll('compedium');
utility.craftAll('blueprint');
}
},
pray: function() {
if(utility.isAlmostFull('faith')) {
customConsole('PRAISE THE SUN !');
gamePage.religion.praise();
}
},
promote: function() {
if(utility.isAlmostFull('gold')) {
customConsole('Kitten promoted !!!')
gamePage.village.promoteKittens();
}
},
craft: function() {
utility.transformAll('catnip', 'wood');
utility.transformAll('wood', 'beam');
utility.transformAll('minerals', 'slab');
utility.transformAll('coal', 'steel');
utility.transformAll('iron', 'plate');
utility.transformAll('oil', 'kerosene');
},
build: function() {
console.log(automaticKittens.autoBuildList);
}
};
handler = dojo.hitch(this, function() {
if(!automaticKittens.options.enable) {
return;
}
automaticKittens.observeSky();
if(automaticKittens.options.hunt) {
automaticKittens.hunt();
}
if(automaticKittens.options.pray) {
automaticKittens.pray();
}
if(automaticKittens.options.promote) {
automaticKittens.promote();
}
if(automaticKittens.options.autocraft) {
automaticKittens.craft();
}
if(automaticKittens.options.autobuild) {
automaticKittens.build();
}
});
gamePage.timer.addEvent(handler, 3); // Once per 3 ticks
customConsole("automation activated - please update config to enable automation");
}
if(window.automaticKittens === undefined) {
launchAutomate();
addHtmlFunctionnality();
setInterval(function() { $("div.btnContent:contains('Gather catnip')").click(); }, 1);
}