-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencounterview.php
163 lines (130 loc) · 4.46 KB
/
encounterview.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
<?php include "include.php" ?>
<html>
<head>
<title>Encounter Viewer</title>
</head>
<body>
<?
$gameid = mysql_real_escape_string($_GET['gameid']);
$eventid = mysql_real_escape_string($_GET['eventid']);
if (!$gameid) {
print "First off, please select which game you wish to view stats for ";
print "<form action=\"encounterview.php\"><br>";
print "<select name=\"gameid\">";
$game = mysql_query("SELECT * FROM game where active=\"1\" ORDER BY name ASC", $mysql);
while (list($gameid, $gamename) = mysql_fetch_row($game)) {
print "<option value=\"$gameid\">$gamename</option>";
}
print "</select><br>";
print "<input type=\"submit\" value=\"Go!\">";
print "</form>";
}
if ($gameid && !$eventid) {
print "Please select encounter to view: ";
print "<form action=\"encounterview.php\">";
print "<select name=\"eventid\">";
$eventidsql = mysql_query("SELECT DISTINCT st.eventid,g.name,st.date FROM stattally st JOIN game g USING(gameid) WHERE st.gameid = g.gameid AND st.gameid = \"$gameid\" GROUP BY st.eventid ASC",$mysql);
while (list($eventid,$gamename,$date) = mysql_fetch_row($eventidsql)) {
$roundnumbersql = mysql_query("SELECT COUNT(DISTINCT date) FROM stattally WHERE eventid=\"$eventid\"",$mysql);
$roundnumber = mysql_fetch_row($roundnumbersql);
// Yes, i'm that anal while drunk
if ($roundnumber[0] > 1) {
$roundword = "rounds";
} else {
$roundword = "round";
}
print "<option value=\"$eventid\">$gamename ($roundnumber[0] $roundword) @ $date</option>";
}
print "</select>";
print "<br>";
print "<input type=\"hidden\" name=\"gameid\" value=\"$gameid\">";
print "<input type=\"submit\" value=\"Show Me!\">";
print "</form>";
}
if ($gameid && $eventid) {
$eventsql = mysql_query("SELECT st.sourcetype,st.sourceid,st.desttype,st.destid,st.actionid,sp.name AS spell,it.name AS item,st.hpadj,st.sthrow,st.destkill,st.date,st.enterer,st.hpadjtype FROM stattally st LEFT JOIN spell sp ON st.spellid = sp.id LEFT JOIN item it ON st.itemid = it.id WHERE st.eventid=\"$eventid\"",$mysql);
// And it starts.. :\
$roundnumber = 1;
$rounddate = 0;
print "Results for $eventid";
while ($eventhash = mysql_fetch_assoc($eventsql)) {
// Sort out what tables to query against (pc vs monster)
if ($eventhash['sourcetype'] == "P") {
$sourcetype = "playercharacter";
$sid = "pcid";
} elseif ($eventhash['sourcetype'] == "M") {
$sourcetype = "monster";
$sid = "id";
}
if ($eventhash['desttype'] == "P") {
$desttype = "playercharacter";
$did = "pcid";
} elseif ($eventhash['desttype'] == "M") {
$desttype = "monster";
$did = "id";
}
// Source
$sourceid = $eventhash['sourceid'];
$sourcenamesql = mysql_query("SELECT name FROM $sourcetype WHERE $sid = \"$sourceid\"",$mysql);
$sourcenameres = mysql_fetch_row($sourcenamesql);
$sourcename = $sourcenameres[0];
// Destination
$destid = $eventhash['destid'];
$destnamesql = mysql_query("SELECT name FROM $desttype WHERE $did = \"$destid\"",$mysql);
$destnameres = mysql_fetch_row($destnamesql);
$destname = $destnameres[0];
// Action
if ($eventhash['actionid'] == 'A') {
$actionid = "Attack";
} elseif ($eventhash['actionid'] == 'H') {
$actionid = "Held Action";
} elseif ($eventhash['actionid'] == 'S') {
$actionid = "Spell";
} elseif ($eventhash['actionid'] == 'I') {
$actionid = "Item Used";
}
// Spell
$spellname = $eventhash['spell'];
// Item
$itemname = $eventhash['item'];
// HP Adjustment
$hpadj = $eventhash['hpadj'];
// HP Adjustment Type
if ($eventhash['hpadjtype'] == 'D') {
$hpadjtype = "Damage";
} elseif ($eventhash['hpadjtype'] == 'H') {
$hpadjtype = "Healed";
}
// Saving Throws
if ($eventhash['sthrow'] == 'M') {
$sthrow = "Made Save";
} elseif ($eventhash['sthrow'] == 'F') {
$sthrow = "Failed Save";
}
// Killed?
if ($eventhash['destkill'] == 'Y') {
$destkill = "->Killed<-";
}
// Date
$date = $eventhash['date'];
// Enterer
$enterer = $eventhash['enterer'];
// Round Number
$break = " ";
$roundannounce = "";
if ($date != $rounddate) {
$roundannounce = "Round $roundnumber @ $date by $enterer<br>";
$roundnumber++;
$break = "<hr>";
}
$rounddate = $date;
// Print this shit out
print "$break";
print "$roundannounce";
print "$sourcename does $actionid $spellname $itemname to $destname for $hpadj $hpadjtype <b>$sthrow $destkill</b><br>";
}
}
include "footer.php"
?>
</body>
</html>