-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhunger.model.js
147 lines (141 loc) · 4.91 KB
/
hunger.model.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
141
142
143
144
145
146
147
// eslint-disable-next-line no-undef
Vue.component("rater", {
// props: ["title", "pool", "size"],
props: ["config", "value"],
template: `
<div>
<h3>{{config.title}}</h3>
<div class="btn-group btn-group-toggle">
<label v-for="(n, i) in config.maxsize" class="btn btn-secondary" v-bind:class="{ active: value==i}">
<input type="radio" v-bind:value="i" v-on:input="$emit('input', $event.target.value)" v-model="value"> {{i}}
</label>
</div>
</div>
`
});
// eslint-disable-next-line no-undef
var app = new Vue({
el: "#app",
data: {
hungerpool: "1",
attributepool: "1",
skillpool: "1",
willpowerpool: "3",
dicerolls: {},
successes: 0,
bestialFailure: false,
messyCritical: false,
willpowerAlreadyUsed: false,
permitReroll: true,
straightSuccesses: 0,
possibleCrits: 0,
critBonusSuccesses: 0,
possibleBloodCrit: 0,
lastSettings: {}
},
methods: {
forceShowDiceTray: function () {
// eslint-disable-next-line no-undef
$("#collapse-homepage").collapse("hide");
// eslint-disable-next-line no-undef
$("#collapse-results").collapse("show");
},
addDice: function (numDice, resetPools = true, includesBloodDice = true, isWillPowerDice = false, failureIncreasesHunger = false, offerRollAgain = false) {
app.lastSettings = {
"numDice": numDice,
"resetPools": resetPools,
"includesBloodDice": includesBloodDice,
"isWillPowerDice": isWillPowerDice,
"failureIncreasesHunger": failureIncreasesHunger,
"offerRollAgain": offerRollAgain
};
app.forceShowDiceTray();
if (resetPools) {
app.dicerolls = {};
app.successes = 0;
app.willpowerAlreadyUsed = false;
app.straightSuccesses = 0;
app.possibleCrits = 0;
app.critBonusSuccesses = 0;
app.possibleBloodCrit = 0;
app.bestialFailure = false;
app.messyCritical = false;
app.permitReroll = true;
}
app.permitReroll = offerRollAgain;
if (failureIncreasesHunger) {
app.willpowerAlreadyUsed = true;
}
var startingDiceSize = Object.keys(app.dicerolls).length;
for (var die = startingDiceSize; die < startingDiceSize + numDice; die++) {
var hunger = parseInt(app.hungerpool);
app.dicerolls[die] = {};
if (die >= numDice - hunger && includesBloodDice) {
app.dicerolls[die]["blood"] = true;
}
app.dicerolls[die]["willpower"] = isWillPowerDice;
app.dicerolls[die]["result"] = Math.ceil(Math.random() * 10);
app.dicerolls[die]["success"] = app.dicerolls[die]["result"] > 5;
app.dicerolls[die]["failure"] = app.dicerolls[die]["result"] < 6;
app.dicerolls[die]["crit"] = app.dicerolls[die]["result"] == 10;
app.dicerolls[die]["bonus"] = false;
if (app.dicerolls[die]["success"]) {
app.straightSuccesses += 1;
}
if (app.dicerolls[die]["crit"]) {
app.possibleCrits += 1;
}
if (app.dicerolls[die]["blood"] && app.dicerolls[die]["result"] == 1) {
app.bestialFailure = true;
app.dicerolls[die]["bestial"] = true;
}
if (app.dicerolls[die]["blood"] && app.dicerolls[die]["crit"]) {
app.possibleBloodCrit++;
}
app.dicerolls[die]["summary"] = "Failure";
app.dicerolls[die]["summary"] = app.dicerolls[die]["blood"] ? "Blood Die" : app.dicerolls[die]["summary"];
app.dicerolls[die]["summary"] = app.dicerolls[die]["result"] > 5 ? "Success!" : app.dicerolls[die]["summary"];
app.dicerolls[die]["summary"] = app.dicerolls[die]["crit"] ? "Critical!" : app.dicerolls[die]["summary"];
app.dicerolls[die]["summary"] = app.dicerolls[die]["bestial"] && app.dicerolls[die]["blood"] ? "Bestial!" : app.dicerolls[die]["summary"];
}
app.successes = app.straightSuccesses;
app.critBonusSuccesses += Math.floor(app.possibleCrits / 2) * 2;
app.successes += app.critBonusSuccesses;
if (app.possibleBloodCrit > 1 || (app.possibleBloodCrit > 0 && app.possibleCrits > 1)) {
app.messyCritical = true;
}
if (failureIncreasesHunger && app.successes < 1) {
app.hungerpool++;
}
for (die = startingDiceSize + numDice; die < app.critBonusSuccesses + startingDiceSize + numDice; die++) {
app.dicerolls[die] = {};
app.dicerolls[die]["result"] = 10;
app.dicerolls[die]["success"] = true;
app.dicerolls[die]["failure"] = false;
app.dicerolls[die]["crit"] = false;
app.dicerolls[die]["bonus"] = true;
app.dicerolls[die]["willpower"] = false;
app.dicerolls[die]["blood"] = false;
}
},
rollDice: function () {
var poolsize = parseInt(app.attributepool) + parseInt(app.skillpool);
app.addDice(poolsize, true, true, false, false, true);
},
useWillpower: function () {
app.willpowerpool--;
app.willpowerAlreadyUsed = true;
app.addDice(3, false, false, true);
},
rouseCheck: function () {
app.forceShowDiceTray();
app.willpowerAlreadyUsed = true;
app.addDice(1, true, true, false, true);
},
willpowerCheck: function () {
app.forceShowDiceTray();
app.willpowerAlreadyUsed = true;
app.addDice(app.willpowerpool, true, true, false, true);
}
}
});