This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
faction.js
135 lines (132 loc) · 5.47 KB
/
faction.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* Copyright (c) 2017 Steve Simenic <[email protected]>
*
* This file is part of the SWN Toolbox.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var types = {
Minor: {
stats: [4, 3, 1],
assets: [1, 1],
hitPoints: 15
},
Major: {
stats: [6, 5, 3],
assets: [2, 2],
hitPoints: 29
},
Hegemon: {
stats: [8, 7, 5],
assets: [4, 4],
hitPoints: 49
}
};
var tags = [
"Colonists",
"Deep Rooted",
"Eugenics Cult",
"Exchange Consulate",
"Fanatical",
"Imperialists",
"Machiavellian",
"Mercenary Group",
"Perimeter Agency",
"Pirates",
"Planetary Government",
"Plutocratic",
"Preceptor Archive",
"Psychic Academy",
"Savage",
"Scavengers",
"Secretive",
"Technical Expertise",
"Theocratic",
"Warlike"
];
var assets = {
Force: {
1: ["Security Personnel", "Hitmen", "Militia Unit"],
2: ["Heavy Drop Assets", "Elite Skirmishers", "Hardened Personnel", "Guerilla Populace"],
3: ["Zealots", "Cunning Trap", "Counterintel Unit"],
4: ["Beachhead Landers", "Extended Theater", "Strike Fleet", "Postech Infantry"],
5: ["Blockade Fleet", "Pretech Logistics", "Psychic Assassins"],
6: ["Pretech Infantry", "Planetary Defenses", "Gravtank Formation"],
7: ["Deep Strike Landers", "Integral Protocols", "Space Marines"],
8: ["Capital Fleet"]
},
Cunning: {
1: ["Smugglers", "Informers", "False Front"],
2: ["Lobbyists", "Saboteurs", "Blackmail", "Seductress"],
3: ["Cyberninjas", "Stealth", "Covert Shipping"],
4: ["Party Machine", "Vanguard Cadres", "Tripwire Cells", "Seditionists"],
5: ["Organization Moles", "Cracked Comms", "Boltholes"],
6: ["Transport Lockdown", "Covert Transit Net", "Demagogue"],
7: ["Popular Movement", "Book of Secrets", "Treachery"],
8: ["Panopticon Matrix"]
},
Wealth: {
1: ["Franchise","Harvesters","Local Investments"],
2: ["Freighter Contract","Lawyers","Union Toughs","Surveyors"],
3: ["Postech Industry","Laboratory","Mercenaries"],
4: ["Shipping Combine","Monopoly","Medical Center","Bank"],
5: ["Marketers","Pretech Researchers","Blockade Runners"],
6: ["Venture Capital","R&D Department","Commodities Broker"],
7: ["Pretech Manufactory","Hostile Takeover","Transit Web"],
8: ["Scavenger Fleet"]
}
};
function generateFaction() {
var type = ["Minor", "Major", "Hegemon"][Math.floor(Math.random() * 3)];
var hitPoints = types[type].hitPoints;
let typeStats = types[type].stats.slice(); // copy the original array so we don't alter it
var stats = [];
for (let index = typeStats.length; index > 0; index--) {
stats.push(parseInt(typeStats.splice(Math.floor(Math.random() * typeStats.length), 1))); // force into int type, otherwise it returns object
}
var numTags = [1, 1, 1, 1, 2][Math.floor(Math.random() * 5)];
var tag = [];
for (let index = 0; index < numTags; index++) {
tag.push(tags[Math.floor(Math.random() * tags.length)]);
}
tag = tag.join(", ");
// generate assets - types[type][assets] is (X,Y) - X is biggest stat, Y is randomly amongst others
var asset = [];
let bigStat = stats.indexOf(Math.max(...stats));
stats = {
0: ["Force", stats[0]],
1: ["Cunning", stats[1]],
2: ["Wealth", stats[2]]
};
for (let index = 0; index < types[type].assets[0]; index++) { // biggest stat
let number = Math.floor(Math.random() * stats[bigStat][1]) + 1;
let assetList = assets[stats[bigStat][0]][number]; // for code clarity next:
asset.push(assetList[Math.floor(Math.random() * assetList.length)] + "/" + stats[bigStat][0] + " " + number);
}
for (let index = 0; index < types[type].assets[1]; index++) { // other stats
let stat = Object.keys(stats); // get stats
stat.splice(bigStat, 1); // remove bigStat
stat = stat[Math.floor(Math.random() * stat.length)]; // pick randomly which stat to use
let number = Math.floor(Math.random() * stats[stat][1]) + 1;
let assetList = assets[stats[stat][0]][number]; // for code clarity next:
asset.push(assetList[Math.floor(Math.random() * assetList.length)] + "/" + stats[stat][0] + " " + number);
}
asset = asset.join(", "); // format for output
return [type, hitPoints, stats[0][1], stats[1][1], stats[2][1], tag, asset];
}