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

angular.service(ꞌgeneratorꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
dl 0
loc 36
rs 8.8571
nop 2

5 Functions

Rating   Name   Duplication   Size   Complexity  
A ��) 0 11 3
A ��) 0 5 1
A ��) 0 3 1
A ��) 0 7 2
A ��) 0 4 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