Completed
Push — master ( f991c2...b8dc7c )
by Andres
38s
created

supernova.js ➔ ... ➔ ct.exoticPrestige   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
dl 0
loc 11
rs 9.4285
nop 0
1
'use strict';
2
3
angular.module('game').component('supernova', {
4
  templateUrl: 'views/supernova.html',
5
  controller: ['state', 'format', 'visibility', 'upgrade', 'data', 'util', supernova],
6
  controllerAs: 'ct'
7
});
8
9
function supernova(state, format, visibility, upgrade, data, util) {
10
  let ct = this;
11
  ct.state = state;
12
  ct.visibility = visibility;
13
  ct.data = data;
14
  ct.util = util;
15
  ct.format = format;
16
17
  ct.exoticProduction = function() {
18
    let production = {};
19
    let exotic = data.elements[state.currentElement].exotic;
20
    production[exotic] = 0;
21
    for (let resource of data.elements[state.currentElement].includes) {
22
      if (!state.player.resources[resource].unlocked) {
23
        continue;
24
      }
25
      if (data.resources[resource].type.indexOf('molecule') !== -1) {
26
        let multiplier = 0;
27
        for (let key in data.resources[resource].elements) {
28
          let number = data.resources[resource].elements[key];
29
          multiplier += number;
30
        }
31
        for (let element in data.resources[resource].elements) {
32
          let newExotic = data.elements[element].exotic;
33
          production[newExotic] = production[newExotic] || 0;
34
          production[newExotic] += Math.floor(Math.max(0, Math.log(state.player.resources[resource].number))) * multiplier;
35
        }
36
      }else{
37
        production[exotic] += Math.floor(Math.max(0, Math.log(state.player.resources[resource].number)));
38
      }
39
    }
40
    for (let key in production) {
41
      // we adjust the production to start at 1e6 resources
42
      if (production[key] >= 13) {
43
        production[key] -= 13;
44
      } else {
45
        production[key] = 0;
46
      }
47
    }
48
49
    return production;
50
  };
51
52
  ct.exoticPrestige = function() {
53
    let resources = state.player.resources;
54
    let production = ct.exoticProduction();
55
56
    for (let key in production) {
57
      resources[key].number += production[key];
58
      resources[key].unlocked = true;
59
    }
60
61
    upgrade.resetElement(state.player, state.currentElement);
62
  };
63
64
  ct.buyExoticUpgrade = function(name, element) {
65
    let upgrades = state.player.elements[element].exotic_upgrades;
66
    let price = data.exotic_upgrades[name].price;
67
    let currency = data.elements[element].exotic;
68
    upgrade.buyUpgrade(state.player,
69
      upgrades,
70
      name,
71
      price,
72
      currency);
73
  };
74
}
75