|
1
|
|
|
'use strict'; |
|
2
|
|
|
|
|
3
|
|
|
angular.module('game').component('reactor', { |
|
4
|
|
|
templateUrl: 'views/reactor.html', |
|
5
|
|
|
controller: ['state', 'data', 'visibility', 'util', 'format', reactor], |
|
6
|
|
|
controllerAs: 'ct' |
|
7
|
|
|
}); |
|
8
|
|
|
|
|
9
|
|
|
function reactor(state, data, visibility, util, format) { |
|
10
|
|
|
let ct = this; |
|
11
|
|
|
ct.state = state; |
|
12
|
|
|
ct.data = data; |
|
13
|
|
|
ct.visibility = visibility; |
|
14
|
|
|
ct.util = util; |
|
15
|
|
|
ct.format = format; |
|
16
|
|
|
|
|
17
|
|
|
ct.synthesisMultiplier = function (synthesis) { |
|
18
|
|
|
let level = state.player.syntheses[synthesis].number; |
|
19
|
|
|
return Math.ceil(Math.pow(data.constants.SYNTH_PRICE_INCREASE, level)); |
|
20
|
|
|
}; |
|
21
|
|
|
|
|
22
|
|
|
function synthesisPrice(synthesis) { |
|
23
|
|
|
let multiplier = ct.synthesisMultiplier(synthesis); |
|
24
|
|
|
let price = {}; |
|
25
|
|
|
let reactant = data.syntheses[synthesis].reactant; |
|
26
|
|
|
for (let resource in reactant) { |
|
27
|
|
|
price[resource] = reactant[resource] * multiplier; |
|
28
|
|
|
} |
|
29
|
|
|
return price; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
ct.isSynthesisCostMet = function (synthesis) { |
|
33
|
|
|
let price = synthesisPrice(synthesis); |
|
34
|
|
|
for (let resource in price) { |
|
35
|
|
|
if (state.player.resources[resource].number < price[resource]) { |
|
36
|
|
|
return false; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
return true; |
|
40
|
|
|
}; |
|
41
|
|
|
|
|
42
|
|
|
ct.buySynthesis = function (synthesis, number) { |
|
43
|
|
|
let i = 0; |
|
44
|
|
|
// we need a loop since we use the ceil operator |
|
45
|
|
|
while (i < number && ct.isSynthesisCostMet(synthesis)) { |
|
46
|
|
|
let price = synthesisPrice(synthesis); |
|
47
|
|
|
for (let resource in price) { |
|
48
|
|
|
state.player.resources[resource].number -= price[resource]; |
|
49
|
|
|
} |
|
50
|
|
|
state.player.syntheses[synthesis].number += 1; |
|
51
|
|
|
i++; |
|
52
|
|
|
} |
|
53
|
|
|
}; |
|
54
|
|
|
} |
|
55
|
|
|
|