Completed
Push — master ( 614e02...3b7e3a )
by Andres
01:16
created

src/scripts/services/generator.js   A

Complexity

Total Complexity 9
Complexity/F 1.5

Size

Lines of Code 43
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
wmc 9
c 2
b 0
f 0
nc 1
mnd 2
bc 9
fnc 6
dl 0
loc 43
rs 10
bpm 1.5
cpm 1.5
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B angular.service(ꞌgeneratorꞌ) 0 36 1
1
'use strict';
2
3
angular
4
  .module('game')
5
  .service('generator', ['state',
6
    'data',
7
    function(state, data) {
8
      this.generatorProduction = function(name, element) {
9
        let baseProduction = data.generators[name].power;
10
        return upgradedProduction(baseProduction, name, element);
11
      };
12
13
      this.tierProduction = function(name, element) {
14
        let baseProduction = data.generators[name].power *
15
          state.player.elements[element].generators[name];
16
        return upgradedProduction(baseProduction, name, element);
17
      };
18
19
      function upgradedProduction(production, name, element) {
20
        for (let up in data.generators[name].upgrades) {
21
          if (state.player.elements[element].upgrades[data.generators[name].upgrades[up]]) {
22
            let power = data.upgrades[data.generators[name].upgrades[up]].power;
23
            production = upgradeApply(production, power);
24
          }
25
        }
26
        let exotic = data.elements[element].exotic;
27
        production += production * state.player.resources[exotic].number * data.constants.EXOTIC_POWER;
28
        return Math.floor(production);
29
      }
30
31
      function upgradeApply(resource, power) {
32
        return resource * power;
33
      }
34
35
      this.elementProduction = function(element) {
36
        let total = 0;
37
        for (let tier in data.generators) {
38
          total += this.tierProduction(tier, element);
39
        }
40
        return total;
41
      };
42
    }
43
  ]);
44