-
Notifications
You must be signed in to change notification settings - Fork 0
/
potion_machine.js
140 lines (112 loc) · 3.98 KB
/
potion_machine.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
136
137
138
139
140
rpg_data = {};
function loadData() {
//https://rpg.rigden.us/seeds_of_infinity/resources/json/all.json
//all.json
$.getJSON("https://rpg.rigden.us/seeds_of_infinity/resources/json/all.json", function(json_response) {
rpg_data = json_response.data;
setModeDeluxePotion()
});
}
function getAlignment() {
var index = Math.floor(Math.random()*rpg_data.alignments.length)
var alignment = rpg_data.alignments[index];
return alignment;
}
function getCreature() {
var index = Math.floor(Math.random()*rpg_data.creatures.length)
var creature = rpg_data.creatures[index];
return creature;
}
function getColor() {
var index = Math.floor(Math.random()*rpg_data.colors.length)
var color = rpg_data.colors[index];
return color;
}
function getLiquidType() {
var index = Math.floor(Math.random()*rpg_data.liquid_types.length)
var liquid_type = rpg_data.liquid_types[index];
return liquid_type;
}
function getPersonality() {
var index = Math.floor(Math.random()*rpg_data.personalities.length)
var personality = rpg_data.personalities[index];
return personality;
}
function getSmell() {
var index = Math.floor(Math.random()*rpg_data.smells.length)
var smell = rpg_data.smells[index];
return smell;
}
function getTrait() {
var index = Math.floor(Math.random()*rpg_data.traits.length)
var trait = rpg_data.traits[index];
return trait;
}
function getNumberOfBasicPotions() {
combinations = rpg_data.colors.length * rpg_data.liquid_types.length * rpg_data.smells.length
return combinations
}
function generateBasicPotion() {
var color = getColor();
var smell = getSmell();
var liquid_type = getLiquidType();
var article = "A ";
var first_letter = liquid_type[0].toLowerCase()
if (first_letter == 'a' || first_letter == 'e' || first_letter == 'i' || first_letter == 'o' || first_letter == 'u' || first_letter == 'y') {
article = "An ";
}
var potion = article + liquid_type + " " + color + " potion that smells " + smell + ". ";
return potion;
}
function generateDeluxPotion() {
var alignment = getAlignment();
var creature = getCreature();
var personality = getPersonality()
var trait = getTrait();
var basic = generateBasicPotion();
var deluxe = basic + "<br><br><strong>Effect:</strong> You become a " + trait + " " + alignment + " " + creature + " with a " + personality + " personality."
return deluxe;
}
function getNumberOfDeluxePotions() {
combinations = getNumberOfBasicPotions() * rpg_data.traits.length * rpg_data.alignments.length * rpg_data.creatures.length * rpg_data.personalities.length
return combinations
}
function renderDeluxePotion() {
var potion = generateDeluxPotion();
$("#generated_potion").html(potion);
ga('send', 'event', 'PotionMachine', 'click', 'DeluxePotion()');
}
function renderBasicPotion() {
var potion = generateBasicPotion();
$("#generated_potion").html(potion);
ga('send', 'event', 'PotionMachine', 'click', 'BasicPotion()');
}
function setModeBasicPotion() {
var combinations = getNumberOfBasicPotions()
renderBasicPotion()
$("#potion_mode").text("Basic Potion Mode");
$("#switch_mode_button").text("Switch to Deluxe Mode");
$("#potion_combinations").text(numeral(combinations).format('0,0'));
$( "#potion_button" ).click(function() {
renderBasicPotion();
});
$( "#switch_mode_button" ).click(function() {
setModeDeluxePotion();
});
}
function setModeDeluxePotion() {
var combinations = getNumberOfDeluxePotions()
renderDeluxePotion()
$("#potion_mode").text("Deluxe Potion Mode");
$("#switch_mode_button").text("Switch to Basic Mode");
$("#potion_combinations").text(numeral(combinations).format('0,0'));
$( "#potion_button" ).click(function() {
renderDeluxePotion();
});
$( "#switch_mode_button" ).click(function() {
setModeBasicPotion();
});
}
$( document ).ready(function() {
loadData();
});