-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.user.js
221 lines (200 loc) · 8.05 KB
/
Extensions.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
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
// ==UserScript==
// @name Spacom.Addons.Design.Extensions
// @version 0.1.1
// @namespace http://dimio.org/
// @description Extends the functions of a ships constructor
// @author dimio ([email protected])
// @license MIT
// @homepage https://github.com/dimio/userscripts-spacom.ru-addons
// @supportURL https://github.com/dimio/userscripts-spacom.ru-addons/issues
// @supportURL https://spacom.ru/forum/discussion/47/polzovatelskie-skripty
// @encoding utf-8
// @match http*://spacom.ru/?act=game/design*
// @include http*://spacom.ru/?act=game/design*
// @run-at document-end
// ==/UserScript==
// An "All levels" addon - developed by segray (https://greasyfork.org/ru/scripts/27897-spacom-addons)
console.log(GM_info.script.name, 'booted v.', GM_info.script.version);
const homePage = GM_info.scriptMetaStr.split('\n')[6].split(' ')[6];
const ERR_MSG = {
NO_LIB: `Для работы ${GM_info.script.name} необходимо установить и включить последние версии следующих дополнений:
<ul>
<li>Spacom.Addons</li>
</ul>
<a href="${homePage}">${homePage}</a>`,
};
(function (window) {
'use strict';
window.unsafeWindow = window.unsafeWindow || window;
const w = unsafeWindow;
const Addons = w.Addons;
if (w.self !== w.top) {
return;
}
if (!Addons) {
w.showSmallMessage(ERR_MSG.NO_LIB);
return;
}
Addons.Design.OPT = {
COMPONENT_MAX_LEVEL: 30,
};
Addons.Design.ExtraInfo = {
makeDesignInfoTemplate() {
let designInfoTemplate = document.getElementById(
'design_info_template').innerHTML;
designInfoTemplate = designInfoTemplate.replace(
"lazer_shots'] + ' ' : '' %>",
"lazer_shots'] + ' <span class=\"lazer_attack\" title=\"Суммарная атака лазеров\">∑ </span>' + params['laser_power_sum'] + ' ' : '' %>");
designInfoTemplate = designInfoTemplate.replace(
"lazer_defence'] + '% ' : '' %>",
"lazer_defence'] + '% (' + params['laser_defence_hp'] + ' hp) <i class=\"fa fa-heart lazer_attack\" title=\"Очки прочности с учётом защиты от лазеров\"></i> ' + params['laser_eq_hp'] + '­' : '' %>");
designInfoTemplate = designInfoTemplate.replace(
"cannon_defence'] + ' ' : '' %>",
"cannon_defence'] + ' <i class=\"fa fa-heart cannon_attack\" title=\"Очки прочности с учётом защиты от пушек\"></i> ' + params['cannon_hp'] + ' ' : '' %>");
designInfoTemplate = designInfoTemplate.replace(
"cannon_targets'] + ' ' : '' %>",
"cannon_targets'] + ' <span class=\"cannon_attack\" title=\"Суммарная атака пушек\">∑ </span>' + params['cannon_power_sum'] + ' ' : '' %>");
const designInfoTemplateTail = `'' %>
<%= ( params['ship_power'] > '0' ) ?
'<i class="fa fa-hand-rock-o" title="Примерная боевая эффективность корабля"></i> ' + params['ship_power']
+ ' '
: '' %>
<%= ( params['ship_damage_per_rent'] > '0' ) ?
'<i class="fa fa-money" title="Повреждений на единицу поддержки"></i> ' + params['ship_damage_per_rent']
: '' %>
</div>`;
designInfoTemplate = designInfoTemplate.replace(/'' %>\s*<\/div>/,
designInfoTemplateTail);
document.getElementById(
'design_info_template').innerHTML = designInfoTemplate;
},
calcLaserPowerSum(params) {
return params.lazer_power * params.lazer_shots;
},
calcLaserEqHp(params) {
return Math.round(params.hp / (1 - (params.lazer_defence / 100)));
},
calcLaserHp(hp, laser_eq_hp) {
return laser_eq_hp - hp;
},
calcCannonHp(params) {
return params.hp + params.cannon_defence;
},
calcCannonPower(params) {
return Math.round(params.cannon_power_sum / params.cannon_targets);
},
calcShipStatsTotal(...args) {
return args.reduce((total, current) => total + current, 0);
},
calcShipPower(params) {
// Если считать приближенно (точность 95%), то мощь корабля -
// это корень из произведения его живучести и суммарного урона.
let shipPower = Math.sqrt(params.hp *
this.calcShipStatsTotal(params.laser_power_sum,
params.cannon_power_sum, params.rocket_power)
);
return Math.round(shipPower);
},
calcShipDpR(params) {
return +(this.calcShipStatsTotal(
params.laser_power_sum, params.cannon_power_sum, params.rocket_power)
/ params.money_rent).toFixed(2);
},
init() {
const self = this;
const design = w.design;
this.makeDesignInfoTemplate();
const _designCalc = design.calc;
design.calc = function () {
_designCalc.apply(this);
design.params.laser_power_sum = self.calcLaserPowerSum(design.params);
design.params.laser_eq_hp = self.calcLaserEqHp(design.params);
design.params.laser_defence_hp = self.calcLaserHp(
design.params.hp,
design.params.laser_eq_hp
);
design.params.cannon_power_sum = design.params.cannon_power;
design.params.cannon_power = self.calcCannonPower(design.params);
design.params.cannon_hp = self.calcCannonHp(design.params);
design.params.ship_power = self.calcShipPower(design.params);
design.params.ship_damage_per_rent = self.calcShipDpR(design.params);
};
const _designDraw = design.draw;
design.draw = function () {
_designDraw.apply(this);
$('#design_info').html(
w.tmpl(document.getElementById('design_info_template').innerHTML,
this));
};
design.calc();
design.draw();
},
};
//FIXME: known levels not show for non-new designs
Addons.Design.DetailKnownLevel = {
makeDetailInstanceTemplate() {
let detailInstanceTemplate = document.getElementById(
'detail_instance').innerHTML;
detailInstanceTemplate = detailInstanceTemplate.replace(/<%=level%>\n/,
'<%=level%><div title="Изученный уровень детали">(<%=known_level%>)</div>');
document.getElementById(
'detail_instance').innerHTML = detailInstanceTemplate;
},
init() {
this.makeDetailInstanceTemplate();
const tc = w.design.template_components;
for (const i in tc) {
if (tc.hasOwnProperty(i)) {
tc[i].known_level = tc[i].max_level;
}
}
const _Component = w.Component;
w.Component = function () {
_Component.apply(this, arguments);
const id = parseInt(this.component_id, 10);
this.known_level = w.design.template_components[id].known_level;
};
},
};
Addons.Design.AllLevels = {
// Based on AllLevels by segray (https://greasyfork.org/ru/scripts/27897-spacom-addons)
enable() {
w.design.template_components.forEach(c => {
c.max_level = Addons.Design.OPT.COMPONENT_MAX_LEVEL;
});
w.design.draw();
},
disable() {
w.design.template_components.forEach(c => {
c.max_level = c._max_level
});
w.design.draw();
},
init() {
const self = this;
$('#details_list').prepend(
'<span><input id="all_levels" type="checkbox"> все уровни</span>');
$('#all_levels').on('change', function () {
if ($(this).is(':checked')) {
self.enable();
}
else {
self.disable();
}
});
w.design.template_components.forEach(c => {
c._max_level = c.max_level
});
},
};
if (w.Design) {
Addons.Common.waitFor(w, 'design', () => {
Addons.Design.ExtraInfo.init();
Addons.Design.DetailKnownLevel.init();
// be backwards-compatible with "spacom-addons" userscript by segrey
if (!Addons.AllLevels) {
Addons.Design.AllLevels.init();
}
});
}
})(window);