Skip to content

Commit 3e90285

Browse files
author
Phil Behreberg
committed
copying script files to version folder
1 parent 76e5aef commit 3e90285

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//Ars Magica 5e Automated Stress Die, v1.0
2+
//by Chris Lankford, May 26, 2016
3+
//
4+
//This allows players to enter "!st <n1>" or "!st <n1>, <n2>" to roll a stress
5+
//die with modifier n1 and optional botch dice count n2.
6+
//Botch dice count defaults to 1 when used with one argument.
7+
//Can also be used with a push-button macro, as in:
8+
//!st ?{Modifier|0}, ?{Botch Dice|1}
9+
//
10+
//A 1 in the code is the 0 described in the text, and a 10 in the code is a 1
11+
//described in the corebook's text. This does not bias the results, as they
12+
//are both special cases.
13+
14+
on("chat:message", function(msg) {
15+
if(msg.type == "api" && msg.content.indexOf("!st ") !== -1) {
16+
var noPrefix = msg.content.replace("!st ", "");
17+
if (noPrefix.indexOf(",")==-1){ //This segment just deals with the default case
18+
rollStress(msg.who,noPrefix,"1");
19+
} else {
20+
var splitString = noPrefix.split(",");
21+
rollStress(msg.who,splitString[0].replace(" ",""),splitString[1].replace(" ",""));
22+
}
23+
}
24+
});
25+
26+
27+
function rollStress(speaker,modifier,botchDice) {
28+
//inputs are strings!
29+
sendChat(speaker,"/roll 1d10",function(ops){
30+
var rollResult=JSON.parse(ops[0].content);
31+
32+
if (rollResult.total===1){
33+
sendChat(speaker,"Potential Botch...!");
34+
var rollString="/roll "+botchDice+"d10=1";
35+
36+
sendChat(speaker,rollString,function (ops){
37+
var rollResult=JSON.parse(ops[0].content);
38+
var returnString;
39+
if (rollResult.total>0){
40+
returnString="BOTCHED x "+rollResult.total+"!";
41+
} else {
42+
returnString="No botch. Stress Die Result: "+modifier;
43+
};
44+
sendChat(speaker,returnString);
45+
});
46+
47+
48+
} else if (rollResult.total===10){
49+
sendChat(speaker,"/roll 1d10!",function (ops){
50+
var rollResult=JSON.parse(ops[0].content);
51+
var exponent = rollResult.rolls[0].results.length;//number of 10s is length - 1, but we already hit a 10, so the multiplier is 2^length.
52+
//For example, if we rolled a ten on the first die, then a 10 and 3 here, we should have 3*2^2 = 3*4 = 12, then + modifier.
53+
var multiplier = Math.pow(2,exponent);
54+
var finalRoll=Number(rollResult.rolls[0].results[exponent-1].v);
55+
if (finalRoll===1){//Note that a roll of 1 (0 in the book) is a ten on rolls after the first die.
56+
finalRoll=10;
57+
}
58+
var rollTotal=multiplier*finalRoll + Number(modifier);
59+
60+
sendChat(speaker,multiplier+"x Multiplier!");
61+
sendChat(speaker,"Stress Die Result: "+rollTotal);
62+
});
63+
} else {
64+
var rollTotal=Number(rollResult.total)+Number(modifier);
65+
sendChat(speaker,"Stress Die Result: "+rollTotal);
66+
}
67+
68+
});
69+
70+
}

TotalRolled/1.0.0/TotalRolled.js

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
on('chat:message', function (msg)
2+
{
3+
if(msg.inlinerolls)
4+
{
5+
var characterName = msg.who;
6+
var hasTest = (msg.content.search("Test") > -1);
7+
var hasAbility = (msg.content.search("Ability") > -1);
8+
var hasFocus = (msg.content.search("Focus") > -1);
9+
var hasAttack = (msg.content.search("Attack") > -1);
10+
var hasAbilityMod = (msg.content.search("Ability mod") > -1);
11+
var hasAim = (msg.content.search("Aim") > -1);
12+
var hasIntelligence = (msg.content.search("Intelligence") > -1);
13+
var hasArcaneFocus = (msg.content.search("Arcana Focus") > -1);
14+
var isSkillRoll = (hasTest && hasAbility && hasFocus);
15+
var isAttackRoll = (hasAttack && hasAbilityMod && hasAim);
16+
var isMagicRoll = (hasIntelligence && hasArcaneFocus);
17+
18+
if(isSkillRoll || isAttackRoll || isMagicRoll){
19+
var totalRolled = getTotalRolled(msg.inlinerolls);
20+
var stuntPoints = getStuntPoint(msg.inlinerolls);
21+
22+
var rollSummary = getContentProperty ("character_name", msg) + " : " + getContentProperty ("name", msg) + " Summary";
23+
24+
var summaryTable = [rollSummary];
25+
summaryTable.push("Total", createRollHtml(totalRolled));
26+
27+
if (stuntPoints > 0) {
28+
summaryTable.push("Stunt Points", createRollHtml(stuntPoints));
29+
}
30+
31+
// add success/failure if a target number is defined
32+
var tnStr = getContentProperty("tn", msg);
33+
var hasTn = tnStr !== null;
34+
if (hasTn) {
35+
var tn = parseInt(tnStr);
36+
var isSuccess = totalRolled >= tn;
37+
if (isSuccess) {
38+
summaryTable.push("<span style='color:green'>Success!</span>", "");
39+
}
40+
else if((stuntPoints > 0) && !isSuccess){
41+
var temp = summaryTable.pop();
42+
var temp2 = summaryTable.pop();
43+
summaryTable.push("<span style='color:red'>Failure!</span>", "");
44+
}
45+
else {
46+
summaryTable.push("<span style='color:red'>Failure!</span>", "");
47+
}
48+
}
49+
50+
var htmlString = createHtmlTable.apply(this, summaryTable);
51+
52+
var chatOutput = htmlString;
53+
sendChat(characterName, chatOutput);
54+
}
55+
}
56+
});
57+
58+
function getTotalRolled(inlineRolls){
59+
var total = 0;
60+
for (var i = 0; inlineRolls.length > i; i ++) {
61+
total += inlineRolls[i].results.total;
62+
}
63+
return total;
64+
}
65+
66+
function getStuntPoint(inlineRolls){
67+
var firstSet = (inlineRolls[0].results.total == inlineRolls[1].results.total);
68+
var secondSet = (inlineRolls[0].results.total == inlineRolls[2].results.total);
69+
var thirdSet = (inlineRolls[1].results.total == inlineRolls[2].results.total);
70+
71+
if( firstSet || secondSet || thirdSet)
72+
return inlineRolls[2].results.total;
73+
else
74+
return 0
75+
}
76+
77+
var createRollHtml = function(value) {
78+
return "[[" + value + "]]";
79+
};
80+
81+
var createHtmlTable = function(header) {
82+
var html = "";
83+
84+
html += "<div class='sheet-rolltemplate-fantasyage_generic'><table><tbody>";
85+
html += "<tr><td colspan='2' class='sheet-header'>" + header + "</td></tr>";
86+
87+
for (var i = 1; i < arguments.length; i += 2) {
88+
var name = arguments[i];
89+
var value = arguments[i + 1] || "";
90+
91+
html += "<tr>";
92+
html += "<td>" + name + "</td>";
93+
html += "<td>"+ value + "</td>";
94+
html += "</tr>";
95+
}
96+
97+
html += "</tbody></table></div>";
98+
99+
return html;
100+
};
101+
102+
var getContentProperty = function(property, msg) {
103+
var regex = new RegExp("\\{\\{" + property + "=([^\\}]+)\\}\\}");
104+
var results = msg.content.match(regex);
105+
if (results == null) {
106+
return null;
107+
}
108+
return results[1];
109+
};
110+
111+
var getRollName = function(msg) {
112+
var regex = new RegExp("\\{\\{name=([^\\}]+)\\}\\}");
113+
var results = msg.content.match(regex);
114+
if (results == null) {
115+
return "";
116+
}
117+
return results[1];
118+
};

0 commit comments

Comments
 (0)