@anonymous/

SuperficialPiercingVariable

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function randomizePointBuy(primaryAbility, secondaryAbility) {

  var abilities = {
    'STR' : 0,
    'DEX' : 0,
    'CON' : 0,
    'INT' : 0,
    'WIS' : 0,
    'CHA' : 0
  };

  abilitiesToDo = ['STR','DEX','CON','INT','WIS','CHA'];

  var index = abilitiesToDo.indexOf(primaryAbility);
  abilitiesToDo.splice(index, 1);

  var index = abilitiesToDo.indexOf(secondaryAbility);
  abilitiesToDo.splice(index, 1);

  var points = 27;

  var randNum = Math.random();

  if (randNum < 0.2) {
    abilities[primaryAbility] = 7;
    points -= 7;
  }
  else if (randNum < 0.8) {
    abilities[primaryAbility] = 9;
    points -= 9;
  }
  else {
    abilities[primaryAbility] = 12;
    points -= 12;
  }

  if (randNum < 0.2) {
    abilities[secondaryAbility] = 7;
    points -= 7;
  }
  else if (randNum < 0.8) {
    abilities[secondaryAbility] = 9;
    points -= 9;
  }
  else {
    abilities[secondaryAbility] = 12;
    points -= 12;
  }

  while (points > 0) {

    var index = Math.floor(Math.random() * abilitiesToDo.length);

    ability = abilitiesToDo[index];

    if (abilities[ability] < 5) {

      abilities[ability] = abilities[ability] + 1;
      points -= 1;

    }

  }

  // convert points to scores

  var conversion = {
    0 : 8,
    1 : 9,
    2 : 10,
    3 : 11,
    4 : 12,
    5 : 13,
    7 : 14,
    9 : 15,
    12 : 16

  }

  for (var property in abilities) {
    if (abilities.hasOwnProperty(property)) {
      console.log(property);
      abilities[property] = conversion[abilities[property]];
    }
  }

  return abilities;

}


console.log(randomizePointBuy('DEX','INT'));
node v10.16.0