Completed
Push — master ( 259c93...d87c9a )
by Andres
01:28
created

supernova.js ➔ ... ➔ ct.exoticPrestige   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 32

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
c 0
b 0
f 0
nc 32
dl 32
loc 32
rs 8.439
nop 0
1 View Code Duplication
'use strict';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
3
angular.module('game').component('supernova', {
4
  templateUrl: 'views/supernova.html',
5
  controller: ['state', 'format', 'visibility', 'data', 'util', supernova],
6
  controllerAs: 'ct'
7
});
8
9
function supernova(state, format, visibility, 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
    for (let resource of data.elements[state.currentElement].includes) {
62
      resources[resource].number = 0;
63
    }
64
65
    let upgrades = state.player.elements[state.currentElement].upgrades;
66
    for (let upgrade in upgrades) {
67
      upgrades[upgrade] = false;
68
    }
69
70
    let generators = state.player.elements[state.currentElement].generators;
71
    for (let generator in generators) {
72
      generators[generator] = 0;
73
    }
74
75
    let syntheses = data.elements[state.currentElement].syntheses;
76
    for (let synthesis of syntheses) {
77
      state.player.syntheses[synthesis].active = 0;
78
    }
79
    delete generators['0'];
80
    let first = Object.keys(generators)[0];
81
82
    state.player.elements[state.currentElement].generators[first] = 1;
83
  };
84
85
  ct.buyExoticUpgrade = function(name, element) {
86
    if (state.player.elements[element].exotic_upgrades[name]) {
87
      return;
88
    }
89
    let price = data.exotic_upgrades[name].price;
90
    let currency = data.elements[element].exotic;
91
92
    if (state.player.resources[currency].number >= price) {
93
      state.player.resources[currency].number -= price;
94
      state.player.elements[element].exotic_upgrades[name] = true;
95
    }
96
  };
97
}
98