-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
1413 lines (1171 loc) · 35.8 KB
/
index.php
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
ini_set( 'display_errors', 1 );
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Load composer's autoloader to load PHPMailer
require '../phpmailer/vendor/autoload.php';
// Load site's database settings
require "../../include/common.php";
$pagetitle = "Secure Dice";
$keywords = "secure,dice,roller,roleplaying,role-playing,game";
//$vars = array_merge($_GET, $_POST);
//$data = array();
//$data = moveTrimmedToArray($vars, $data);
if (!isset($data["op"]) || $data["op"] == '--')
{
$data["op"] = '';
}
// dice_quantity
if (!isset($data["dq"]) || $data["dq"] == '--')
{
$data["dq"] = '4';
}
// minus_dice_quantity
if (!isset($data["mdq"]) || $data["mdq"] == '--')
{
$data["mdq"] = '0';
}
// fudge_dice_quantity
if (!isset($data["fdq"]) || $data["fdq"] == '--')
{
$data["fdq"] = '0';
}
// dice_size
if (!isset($data["ds"]) || $data["ds"] == '--')
{
$data["ds"] = '6';
}
// minus_dice_size
if (!isset($data["mds"]) || $data["mds"] == '--')
{
$data["mds"] = '6';
}
// dice_modify
if (!isset($data["dm"]) || $data["dm"] == '--')
{
$data["dm"] = '0';
}
// minus_dice_modify
if (!isset($data["mdm"]) || $data["mdm"] == '--')
{
$data["mdm"] = '0';
}
// dice_deviation
if (!isset($data["dd"]) || $data["dd"] == '--')
{
$data["dd"] = 'none';
}
// minus_dice_deviation
if (!isset($data["mdd"]) || $data["mdd"] == '--')
{
$data["mdd"] = 'none';
}
// dice_sets
if (!isset($data["dt"]) || $data["dt"] == '--')
{
$data["dt"] = '7';
}
// sort dice_sets
if (!isset($data["sdt"]) || $data["sdt"] == '--')
{
$data["sdt"] = false;
}
// email to
if (!isset($data["to"]) || $data["to"] == '--')
{
$data["to"] = '';
}
// cc to
if (!isset($data["gm"]) || $data["gm"] == '--')
{
$data["gm"] = '';
}
// email subject
if (!isset($data["sub"]) || $data["sub"] == '--')
{
$data["sub"] = '';
}
/**
* Retrieves the current tally for dice rolled to date.
*
* @access public
* @return string $dice_rolled Dice rolled to date
*/
function getDiceRolled()
{
global $db;
$query = mysqli_query($db, "SELECT SUM(`dice_rolled`) FROM `secure_dice`;");
$dice_rolled = array_shift(mysqli_fetch_array($query));
$dice_rolled = number_format($dice_rolled);
return $dice_rolled;
}
/**
* Stores dice roll results in database.
*
* @access public
* @param string $message Dice roll message
*/
function storeDiceResults($message)
{
global $data, $db;
$query = mysqli_query($db, "INSERT INTO `secure_dice` SET `results` = \"" . mysqli_real_escape_string($db, $message) . "\";");
$data["roll_id"] = mysqli_insert_id($db);
}
/**
* Stores tally for dice rolled in database.
*
* @access public
* @param array $data Dice roll data
*/
function storeDiceRolled($data)
{
global $data, $db;
$current_dice = (($data["dice_quantity"] + $data["minus_dice_quantity"]) * $data["dice_sets"]);
$query = mysqli_query($db, "UPDATE `secure_dice` SET `dice_rolled` = " . intval($current_dice) . " WHERE `id` = \"" . intval($data["roll_id"]) . "\";");
}
/**
* Stores dice roll hash in database.
*
* @access public
* @param string $message Dice roll results
*/
function storeDiceHash($message)
{
global $data, $db;
$data["hash"] = md5($message);
$query = mysqli_query($db, "UPDATE `secure_dice` SET `hash` = \"" . mysqli_real_escape_string($db, $data["hash"]) . "\" WHERE `id` = \"" . intval($data["roll_id"]) . "\";");
}
/**
* Displays dice roll form.
*
* @access public
* @param array $data Dice roll data
*/
function displayDiceForm($data)
{
global $data;
global $webmaster, $webmaster_email, $sitetitle, $pagetitle, $siteurl, $webroot;
?>
<p>
<?php echo getDiceRolled(); ?> dice rolled since 2005-11-06.
</p>
<form method="post" action="index.php" onsubmit="return true;">
<table border="0" cellpadding="4">
<tr>
<td align="right" valign="top">
Roll
</td>
<td valign="top">
<select name="dice_quantity" id="dice_quantity">
<?php
for ($i = 1000; $i >= 1; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["dq"] == $i)
{
echo 'selected="selected"';
}
echo '>' . $i . '</option>' . "\n";
if ($i > 100)
{
$i = $i - 899;
}
else if ($i > 50)
{
$i = $i - 9;
}
else if ($i > 20)
{
$i = $i - 4;
}
}
?>
</select>
d<select name="dice_size" id="dice_size">
<?php
for ($i = 1000; $i >= 2; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["ds"] == $i)
{
echo 'selected="selected"';
}
echo '>' . $i . '</option>' . "\n";
if ($i > 100)
{
$i = $i - 899;
}
else if ($i > 50)
{
$i = $i - 9;
}
else if ($i > 20)
{
$i = $i - 4;
}
}
?>
</select>
<select name="dice_modify" id="dice_modify">
<?php
for ($i = 40; $i >= -40; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["dm"] == $i)
{
echo 'selected="selected"';
}
if ($i > -1)
{
$sign = '+';
}
else
{
$sign = '';
}
echo '>' . $sign . $i . '</option>' . "\n";
}
?>
</select>,
and <select name="dice_deviation" id="dice_deviation">
<option value="lowest" <?php if ($data["dd"] == "lowest") { echo 'selected="selected"'; } ?>>drop the lowest die.</option>
<option value="--" <?php if ($data["dd"] == "none") { echo 'selected="selected"'; } ?>>sum them all (normal roll).</option>
<option value="highest" <?php if ($data["dd"] == "highest") { echo 'selected="selected"'; } ?>>drop the highest die.</option>
<!-- <option value="expertise" <?php if ($data["dd"] == "expertise") { echo 'selected="selected"'; } ?>>use expertise rule from Bulletproof Blues.</option> -->
<option value="wild" <?php if ($data["dd"] == "wild") { echo 'selected="selected"'; } ?>>use one of them as a wild die.</option>
<option value="stunt" <?php if ($data["dd"] == "stunt") { echo 'selected="selected"'; } ?>>use one of them as a stunt die.</option>
</select>
</td>
</tr>
<tr>
<td align="right" valign="top">
then roll and subtract
</td>
<td valign="top">
<select name="minus_dice_quantity" id="minus_dice_quantity">
<?php
for ($i = 1000; $i >= 0; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["mdq"] == $i)
{
echo 'selected="selected"';
}
echo '>' . $i . '</option>' . "\n";
if ($i > 100)
{
$i = $i - 899;
}
else if ($i > 50)
{
$i = $i - 9;
}
else if ($i > 20)
{
$i = $i - 4;
}
}
?>
</select>
d<select name="minus_dice_size" id="minus_dice_size">
<?php
for ($i = 1000; $i >= 2; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["mds"] == $i)
{
echo 'selected="selected"';
}
echo '>' . $i . '</option>' . "\n";
if ($i > 100)
{
$i = $i - 899;
}
else if ($i > 50)
{
$i = $i - 9;
}
else if ($i > 20)
{
$i = $i - 4;
}
}
?>
</select>
<select name="minus_dice_modify" id="minus_dice_modify">
<?php
for ($i = 40; $i >= -40; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["mdm"] == $i)
{
echo 'selected="selected"';
}
if ($i > -1)
{
$sign = '+';
}
else
{
$sign = '';
}
echo '>' . $sign . $i . '</option>' . "\n";
}
?>
</select>,
and <select name="minus_dice_deviation" id="minus_dice_deviation">
<option value="lowest" <?php if ($data["mdd"] == "lowest") { echo 'selected="selected"'; } ?>>drop the lowest die.</option>
<option value="--" <?php if ($data["mdd"] == "none") { echo 'selected="selected"'; } ?>>sum them all (normal roll).</option>
<option value="highest" <?php if ($data["mdd"] == "highest") { echo 'selected="selected"'; } ?>>drop the highest die.</option>
<option value="wild" <?php if ($data["mdd"] == "wild") { echo 'selected="selected"'; } ?>>use one of them as a wild die.</option>
</select></p>
</td>
</tr>
<tr>
<td align="center" valign="top" colspan="2">
<b>OR...</b>
</td>
</tr>
<tr>
<td align="right" valign="top">
Roll
</td>
<td valign="top">
<select name="fudge_dice_quantity" id="fudge_dice_quantity">
<?php
for ($i = 5; $i >=0; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["fdq"] == $i)
{
echo 'selected="selected"';
}
echo '>' . $i . '</option>' . "\n";
}
?>
</select>
<a href="http://en.wikipedia.org/wiki/Fudge_%28role-playing_game_system%29#Fudge_dice">Fudge (or FATE) dice</a><br />
(If you select Fudge dice, the section above will be ignored.)
</td>
</tr>
<tr>
<td align="right" valign="top">
<p>Roll this set of dice </p>
</td>
<td valign="top">
<p><select name="dice_sets">
<?php
for ($i = 1000; $i >=1; $i--)
{
echo '<option value="' . $i . '" ';
if ($data["dt"] == $i)
{
echo 'selected="selected"';
}
echo '>' . $i . '</option>' . "\n";
if ($i > 100)
{
$i = $i - 899;
}
else if ($i > 50)
{
$i = $i - 9;
}
else if ($i > 20)
{
$i = $i - 4;
}
}
?>
</select> times.
<input type="checkbox" name="sort_dice_sets" id="sort_dice_sets" <?php if ($data["sdt"]) { echo 'checked="checked"'; } ?> /> Sort dice sets?</p>
</td>
</tr>
<tr>
<td align="right" valign="top">
Send the signed results of this roll to yourself:
</td>
<td valign="top">
<input type="text" name="dice_mailto" id="dice_mailto" size="30" maxlength="255" value="<?php echo (htmlspecialchars($data["to"])); ?>" />
</td>
</tr>
<tr>
<td align="right" valign="top">
and the GM:
</td>
<td valign="top">
<input type="text" name="dice_mailgm" id="dice_mailgm" size="30" maxlength="255" value="<?php echo (htmlspecialchars($data["gm"])); ?>" />
</td>
</tr>
<tr>
<td align="right" valign="top">
with this subject:
</td>
<td valign="top">
<input type="text" name="dice_subject" id="dice_subject" size="30" maxlength="255" value="<?php echo (htmlspecialchars($data["sub"])); ?>" />
</td>
</tr>
<tr>
<td align="right" valign="top">
</td>
<td valign="top">
<input type="hidden" name="op" value="roll" />
<input type="submit" name="submit" id="submit" value="Roll The Dice" />
<input type="button" name="verify_roll" value="Verify A Roll" onclick="location.href='verify.php<?php echo ((!empty($data['bypass']) && $data['bypass'] != '--') ? "?bypass=" . $data['bypass'] : ''); ?>';" />
<input type="button" name="restart" value="Start Over" onclick="location.href='<?php echo $siteurl; ?>/software/securedice/index.php<?php echo ((!empty($data['bypass']) && $data['bypass'] != '--') ? "?bypass=" . $data['bypass'] : ''); ?>';" />
</td>
</tr>
</table>
</form>
<p>You can pre-populate these values by adding them to the URL. The first value you set must be preceded with a question mark (?). Values after the first must be preceded by an ampersand (&). Here are permitted options, and their allowed values:</p>
<table border="0">
<tr>
<th>dq=
<td>dice quantity: any integer from 1 to 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 1000
</tr>
<tr>
<th>ds=
<td>dice sides: 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 18, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 1000
</tr>
<tr>
<th>dm=
<td>dice modifier: any integer from -40 to 40 (for numbers greater than -1, do <b>not</b> include a plus sign)
</tr>
<tr>
<th>dd=
<td>dice deviation: lowest, none, highest, <a href="http://en.wikipedia.org/wiki/D6_System#The_Wild_Die">wild</a>, <a href="https://www.blackgate.net/blog/fantasy-age-the-stunt-die/">stunt</a>
</tr>
<tr>
<th>mdq=
<td>minus dice quantity: any integer from 0 to 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 1000
</tr>
<tr>
<th>mds=
<td>minus dice sides: 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 18, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 1000
</tr>
<tr>
<th>mdm=
<td>minus dice modifier: any integer from -40 to 40 (for numbers greater than -1, do <b>not</b> include a plus sign)
</tr>
<tr>
<th>mdd=
<td>minus dice deviation: lowest, none, highest, <a href="http://en.wikipedia.org/wiki/D6_System#The_Wild_Die">wild</a>
</tr>
<tr>
<th>dt=
<td>dice sets: any integer from 1 to 20
</tr>
<tr>
<th>sdt=
<td>sort dice sets: 1 (sorts the rolls in each dice set from largest to smallest)
</tr>
<tr>
<th>to=
<td>Your email address: one valid email address
</tr>
<tr>
<th>gm=
<td>GM's email address: one valid email address
</tr>
<tr>
<th>sub=
<td>email subject: a brief message, with "%20" instead of spaces (example: This%20is%20a%20test)
</tr>
</table>
<p>Here is an example of a URL which pre-sets some of these values:</p>
<pre><a href="<?php echo $siteurl; ?>"/software/securedice/?dq=7&ds=4&dt=5&[email protected]&sub=This%20is%20a%20test"><?php echo $siteurl; ?>/software/securedice/?dq=7&ds=4&dt=5&[email protected]&sub=This%20is%20a%20test</a></pre>
<?php
}
/**
* Checks if email address is potentially valid.
*
* @access public
* @param string $email_address Email address of recipient
* @return boolean $validity True if potentially valid; otherwise false
*/
function isEmailValid($email_address = '')
{
$validity = false;
if (empty($email_address))
{
$validity = false;
}
else
{
list($mailName, $mailDomain) = preg_split("/@/", $email_address);
if (empty($mailName) || empty($mailDomain))
{
$validity = false;
}
else if (checkdnsrr($mailDomain, "MX"))
{
if (preg_match("/\r/i", $email_address) || preg_match("/\n/i", $email_address))
{
$validity = false;
}
else
{
$validity = true;
}
}
}
return $validity;
}
/**
* Checks if subject is potentially valid.
*
* @access public
* @param string $email_subject Email subject
* @return boolean $validity True if potentially valid; otherwise false
*/
function isSubjectValid($email_subject = '')
{
$validity = false;
if (preg_match("/\r/i", $email_subject) || preg_match("/\n/i", $email_subject))
{
$validity = false;
}
else
{
$validity = true;
}
return $validity;
}
/**
* Formats dice result email with appropriate header and footer.
*
* @access public
* @param string $email_message Email message
* @return string $formatted_message Formatted email message
*/
function formatEmailMessage($email_message = '')
{
global $data;
global $webmaster, $webmaster_email, $sitetitle, $pagetitle, $siteurl, $webroot;
$formatted_message = $sitetitle . " Secure Dice generated the following rolls";
if (isset($data["dice_mailto"]) && !empty($data["dice_mailto"]))
{
$formatted_message .= " for " . $data["dice_mailto"];
}
$formatted_message .= ".\n\n";
$formatted_message .= $data["message"];
$formatted_message .= "\n\n-- \n";
$formatted_message .= "Dice rolls generated by " . $sitetitle . " Secure Dice\n";
$formatted_message .= $siteurl . "/software/securedice/";
$data["formatted_message"] = $formatted_message;
$formatted_message = "--- verified message begins here ---\n" . $formatted_message;
$formatted_message .= "\n--- verified message ends here ---\n";
$formatted_message .= "Roll ID: " . $data["roll_id"] . "\n";
$formatted_message .= "MD5 checksum: " . $data["hash"] . "\n";
return $formatted_message;
}
/**
* Generates dice roll results.
*
* @access public
* @param array $data Dice roll data
*/
function generateDiceResults($data)
{
global $data;
global $webmaster, $webmaster_email, $sitetitle, $pagetitle, $siteurl, $webroot;
$data["message"] = $data["dice_quantity"] . "d" . $data["dice_size"];
if ($data["dice_modify"] >= 1)
{
$data["message"] .= "+" . $data["dice_modify"];
}
else if ($data["dice_modify"] <= -1)
{
$data["message"] .= $data["dice_modify"];
}
if (($data["dice_deviation"] == "highest") || ($data["dice_deviation"] == "lowest"))
{
$data["message"] .= ", with the " . $data["dice_deviation"] . " die dropped";
}
else if ($data["dice_deviation"] == "expertise")
{
$data["message"] .= ", with [expertise] (re-rolling 1s and 2s)";
}
else if ($data["dice_deviation"] == "wild")
{
$data["message"] .= ", with a [wild die]";
}
else if ($data["dice_deviation"] == "stunt")
{
$data["message"] .= ", using one of them as a [stunt die]";
}
if (!isset($data["minus_dice_quantity"]))
{
$data["minus_dice_quantity"] = 0;
}
if ($data["minus_dice_quantity"] > 0)
{
$data["message"] .= ', subtract ' . $data["minus_dice_quantity"] . "d" . $data["minus_dice_size"];
if ($data["minus_dice_modify"] >= 1)
{
$data["message"] .= "+" . $data["minus_dice_modify"];
}
else if ($data["minus_dice_modify"] <= -1)
{
$data["message"] .= $data["minus_dice_modify"];
}
if (($data["minus_dice_deviation"] == "highest") || ($data["minus_dice_deviation"] == "lowest"))
{
$data["message"] .= ", with the " . $data["minus_dice_deviation"] . " die dropped";
}
else if ($data["minus_dice_deviation"] == "wild")
{
$data["message"] .= ", with a [wild die]";
}
}
$data["message"] .= ", rolled ";
if ($data["dice_sets"] > 1)
{
$data["message"] .= $data["dice_sets"] . " times.\n";
}
else
{
$data["message"] .= " once.\n";
}
if (isset($data["sort_dice_sets"]) && $data["sort_dice_sets"])
{
$data["message"] .= "Each set of dice rolls is sorted from high to low.\n";
}
$data["message"] .= "\n";
for ($i = 1 ; $i <= $data["dice_sets"]; $i++)
{
$data["rawroll"] = array();
$data["roll"] = array();
$data["minus_roll"] = array();
$data["message"] .= "Roll set " . $i . "\n";
$data["message"] .= " Die rolls: ";
$data["rawroll"][0] = random_int(1, $data["dice_size"]);
$data["roll"][0] = $data["rawroll"][0];
$wild_roll = $data["roll"][0];
$wild_rolls = '';
$duplicates_message = '';
if ($data["dice_deviation"] == "expertise" && $data["roll"][0] < 3)
{
while ($data["roll"][0] < 3)
{
$data["roll"][0] = random_int(1, $data["dice_size"]);
}
$data["roll"][0] .= 'e';
}
if ($data["dice_deviation"] == "wild" && $wild_roll == $data["dice_size"])
{
$wild_rolls = $wild_roll;
while ($wild_roll == $data["dice_size"])
{
$wild_roll = random_int(1, $data["dice_size"]);
$data["rawroll"][0] += $wild_roll;
$data["roll"][0] = $data["rawroll"][0];
$wild_rolls .= '+' . $wild_roll;
}
$wild_rolls .= '=';
$data["roll"][0] .= 'w';
}
for ($j = 1 ; $j <= ($data["dice_quantity"] - 1); $j++)
{
$data["rawroll"][$j] = random_int(1, $data["dice_size"]);
$data["roll"][$j] = $data["rawroll"][$j];
if ($data["dice_deviation"] == "expertise" && $data["roll"][$j] < 3)
{
while ($data["roll"][$j] < 3)
{
$data["roll"][$j] = random_int(1, $data["dice_size"]);
}
$data["roll"][$j] .= 'e';
}
if ($j == ($data["dice_quantity"] - 1) && $data["dice_deviation"] == "stunt")
{
$data["roll"][$j] .= 's';
}
}
if (isset($data["sort_dice_sets"]) && $data["sort_dice_sets"])
{
rsort($data["roll"]);
}
$max_roll = max($data["rawroll"]);
$max_key = array_search($max_roll, $data["roll"]);
$min_roll = min($data["rawroll"]);
$min_key = array_search($min_roll, $data["roll"]);
$duplicates = array_count_values($data["rawroll"]);
sort($duplicates);
for ($k = 0 ; $k <= count($duplicates) - 1; $k++)
{
if ($duplicates[$k] > 1)
{
$duplicates_message = ' (Duplicates!)';
}
if ($duplicates[$k] == 2)
{
$duplicates_message = ' (Doubles!)';
}
if ($duplicates[$k] == 3)
{
$duplicates_message = ' (Triples!)';
}
}
for ($j = 0 ; $j <= $data["dice_quantity"] - 1; $j++)
{
if (($data["dice_deviation"] == "highest") && ($j == $max_key))
{
$data["message"] .= "[" . intval($data["roll"][$j]) . "]";
}
else if (($data["dice_deviation"] == "lowest") && ($j == $min_key))
{
$data["message"] .= "[" . intval($data["roll"][$j]) . "]";
}
else if (($data["dice_deviation"] == "expertise") && (substr($data["roll"][$j], -1) == 'e'))
{
$data["message"] .= "[" . intval($data["roll"][$j]) . "]";
}
else if (($data["dice_deviation"] == "wild") && (substr($data["roll"][$j], -1) == 'w'))
{
$data["message"] .= "[" . $wild_rolls . intval($data["roll"][$j]) . "]";
}
else if (($data["dice_deviation"] == "stunt") && (substr($data["roll"][$j], -1) == 's'))
{
$data["message"] .= "[" . intval($data["roll"][$j]) . "]";
}
else
{
$data["message"] .= intval($data["roll"][$j]);
}
if ($j < ($data["dice_quantity"] - 1))
{
$data["message"] .= ", ";
}
}
if ($data["dice_modify"] > 0)
{
$data["message"] .= ' + ' . $data["dice_modify"];
}
else if ($data["dice_modify"] < 0)
{
$data["message"] .= ' - ' . abs($data["dice_modify"]);
}
$data["message"] .= $duplicates_message . "\n";
$data["message"] .= " Roll subtotal: ";
for ($j = 0 ; $j <= ($data["dice_quantity"] - 1); $j++)
{
if (!(($data["dice_deviation"] == "highest") && ($j == $max_key))
&& !(($data["dice_deviation"] == "lowest") && ($j == $min_key)))
{
if (isset($data["roll"]["subtotal"]))
{
$data["roll"]["subtotal"] += intval($data["roll"][$j]);
} else {
$data["roll"]["subtotal"] = intval($data["roll"][$j]);
}
}
}
if (isset($data["roll"]["subtotal"]))
{
$data["roll"]["subtotal"] += intval($data["dice_modify"]);
} else {
$data["roll"]["subtotal"] = intval($data["dice_modify"]);
}
$data["message"] .= $data["roll"]["subtotal"] . "\n";
if ($data["minus_dice_quantity"] > 0)
{
$data["message"] .= " Minus die rolls: ";
$data["minus_roll"][0] = random_int(1, $data["minus_dice_size"]);
$wild_roll = $data["minus_roll"][0];
$wild_rolls = '';
if ($data["minus_dice_deviation"] == "wild" && $wild_roll == $data["minus_dice_size"])
{
$wild_rolls = $wild_roll;
while ($wild_roll == $data["minus_dice_size"])
{
$wild_roll = random_int(1, $data["minus_dice_size"]);
$data["minus_roll"][0] += $wild_roll;
$wild_rolls .= '+' . $wild_roll;
}
$wild_rolls .= '=';
}
$data["minus_roll"][0] .= 'w';
for ($j = 2 ; $j <= $data["minus_dice_quantity"]; $j++)
{
$data["minus_roll"][$j - 1] = random_int(1, $data["minus_dice_size"]);
}
if (isset($data["sort_dice_sets"]) && $data["sort_dice_sets"])
{
rsort($data["minus_roll"]);
}
$max_minus_roll = max($data["minus_roll"]);
$max_minus_key = array_search($max_roll, $data["minus_roll"]);
$min_minus_roll = min($data["minus_roll"]);
$min_minus_key = array_search($min_roll, $data["minus_roll"]);
for ($j = 0; $j <= ($data["minus_dice_quantity"] - 1); $j++)
{
if (($data["minus_dice_deviation"] == "highest") && ($j == $max_minus_key))
{
$data["message"] .= "[" . intval($data["minus_roll"][$j]) . "]";
}
else if (($data["minus_dice_deviation"] == "lowest") && ($j == $min_minus_key))
{
$data["message"] .= "[" . intval($data["minus_roll"][$j]) . "]";
}
else if (($data["minus_dice_deviation"] == "wild") && (substr($data["minus_roll"][$j], -1) == 'w'))
{
$data["message"] .= "[" . $wild_rolls . intval($data["minus_roll"][$j]) . "]";
}
else
{
$data["message"] .= intval($data["minus_roll"][$j]);
}
if ($j < ($data["minus_dice_quantity"] - 1))
{
$data["message"] .= ", ";
}
}
if ($data["minus_dice_modify"] > 0)
{
$data["message"] .= ' + ' . $data["minus_dice_modify"] . "\n";
}
else if ($data["minus_dice_modify"] < 0)
{
$data["message"] .= ' - ' . abs($data["minus_dice_modify"]) . "\n";
}
else
{
$data["message"] .= "\n";
}