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