-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathstory.php
235 lines (192 loc) · 9.9 KB
/
story.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
<?php // story.php :: Storyline handling.
// Dragon Scourge
//
// Program authors: Jamin Blount
// Copyright (C) 2007 by renderse7en
// Script Version 1.0 Beta 5 Build 20
// You may not distribute this program in any manner, modified or
// otherwise, without the express, written consent from
// renderse7en.
//
// You may make modifications, but only for your own use and
// within the confines of the Dragon Scourge License Agreement
// (see our website for that).
include("lib.php");
include("globals.php");
$story = dorow(doquery("SELECT * FROM <<story>> WHERE id='".$userrow["story"]."' LIMIT 1"));
// Decide which type of story to run.
if ($story["targetmonster"] != "0") { storymonster(); }
if ($story["targetitem"] != "") { storyitem(); }
storyteleport();
function storyteleport() { // Sends to a new location, or just displays a chunk of the story with no associated action.
global $userrow, $story;
if (isset($_POST["submit"])) {
if ($story["nextstory"] != "0") {
$nextstory = dorow(doquery("SELECT * FROM <<story>> WHERE id='".$story["nextstory"]."' LIMIT 1"));
$userrow["story"] = $nextstory["id"];
$userrow["storylat"] = $nextstory["latitude"];
$userrow["storylon"] = $nextstory["longitude"];
}
if ($story["targetworld"] != "0") {
$userrow["world"] = $story["targetworld"];
$userrow["latitude"] = $story["targetlat"];
$userrow["longitude"] = $story["targetlon"];
// Get first town from new world.
$newtown = dorow(doquery("SELECT * FROM <<towns>> WHERE world='".$userrow["world"]."' ORDER BY id LIMIT 1"));
$towns = explode(",",$userrow["townslist"]);
$towns[] = $newtown["id"];
$userrow["townslist"] = implode(",",$towns);
}
if ($story["targetaction"] != "") {
$userrow["currentaction"] = $story["targetaction"];
}
if ($story["rewardname"] != "") {
$userrow[$story["rewardname"]] += $story["rewardattr"];
}
updateuserrow();
die(header("Location: index.php"));
}
$story["reward"] = "";
if ($story["rewardname"] != "") {
$premodrow = dorow(doquery("SELECT * FROM <<itemmodnames>> ORDER BY id"));
foreach($premodrow as $a=>$b) {
$modrow[$b["fieldname"]] = $b;
}
$story["reward"] .= "<hr />You've gained a permanent reward from this quest:<br />";
$story["reward"] .= $modrow[$story["rewardname"]]["prettyname"] . ": +" . $story["rewardattr"];
if ($modrow[$story["rewardname"]]["percent"] == 1) { $story["reward"] .= "%"; }
$story["reward"] .= "<br />This reward will be applied when you continue on your adventure.";
}
$story["story"] = nl2br($story["story"]);
display($story["title"], parsetemplate(gettemplate("story_teleport"), $story));
}
function storymonster() {
global $userrow, $story;
if (isset($_POST["submit"])) {
$monster = dorow(doquery("SELECT * FROM <<monsters>> WHERE id='".$story["targetmonster"]."' LIMIT 1"));
$querystring = "currentmonsterid='".$monster["id"]."', currentmonsterhp='".(ceil(rand($monster["maxhp"] * .75, $monster["maxhp"]) * $userrow["difficulty"]))."', currentaction='Fighting'";
$update = doquery("UPDATE <<users>> SET $querystring WHERE id='".$userrow["id"]."' LIMIT 1");
die(header("Location: fight.php"));
}
$story["story"] = nl2br($story["story"]);
display($story["title"], parsetemplate(gettemplate("story_monster"), $story));
}
function storyitem() {
global $userrow, $story;
$modrow = dorow(doquery("SELECT * FROM <<itemmodnames>> ORDER BY id"), "fieldname");
$thenewitem = explode(",",$story["targetitem"]);
$newitem = dorow(doquery("SELECT * FROM <<itembase>> WHERE id='".$thenewitem[1]."' LIMIT 1"));
$newprefix = dorow(doquery("SELECT * FROM <<itemprefixes>> WHERE id='".$thenewitem[0]."' LIMIT 1"));
$newsuffix = dorow(doquery("SELECT * FROM <<itemsuffixes>> WHERE id='".$thenewitem[2]."' LIMIT 1"));
$newfullitem = builditem($newprefix, $newitem, $newsuffix, $modrow);
$story["itemtable"] = parsetemplate(gettemplate("explore_drop_itemrow"), $newfullitem);
if ($userrow["item".$newitem["slotnumber"]."idstring"] != "0") {
$theolditem = explode(",",$userrow["item".$newitem["slotnumber"]."idstring"]);
$olditem = dorow(doquery("SELECT * FROM <<itembase>> WHERE id='".$theolditem[1]."' LIMIT 1"));
$oldprefix = dorow(doquery("SELECT * FROM <<itemprefixes>> WHERE id='".$theolditem[0]."' LIMIT 1"));
$oldsuffix = dorow(doquery("SELECT * FROM <<itemsuffixes>> WHERE id='".$theolditem[2]."' LIMIT 1"));
$oldfullitem = builditem($oldprefix, $olditem, $oldsuffix, $modrow);
$story["olditems"] = parsetemplate(gettemplate("town_buy_olditemrow"), $oldfullitem);
} else {
$oldfullitem = false; $oldprefix = false; $oldsuffix = false;
$story["olditems"] = "You don't have any item in this slot.";
}
if (isset($_POST["takeitem"])) {
// Requirements check.
if ($newfullitem["requirements"] == false) { err("You do not meet one or more of the requirements for this item. Please <a href=\"index.php\">go back</a> and try again."); }
// Now do stuff to userrow (new item only).
$userrow["item" . $newfullitem["slotnumber"] . "idstring"] = $newfullitem["fullid"];
$userrow["item" . $newfullitem["slotnumber"] . "name"] = $newfullitem["name"];
$userrow[$newfullitem["basename"]] += $newfullitem["baseattr"];
for($j=1; $j<7; $j++) {
if ($newfullitem["mod".$j."name"] != "") {
$userrow[$newfullitem["mod".$j."name"]] += $newfullitem["mod".$j."attr"];
}
}
if ($newprefix != false) {
$userrow[$newprefix["basename"]] += $newprefix["baseattr"];
}
if ($newsuffix != false) {
$userrow[$newsuffix["basename"]] += $newsuffix["baseattr"];
}
// Do more stuff to userrow (old item only).
if ($oldfullitem != false) {
$userrow[$oldfullitem["basename"]] -= $oldfullitem["baseattr"];
for($j=1; $j<7; $j++) {
if ($oldfullitem["mod".$j."name"] != "") {
$userrow[$oldfullitem["mod".$j."name"]] -= $oldfullitem["mod".$j."attr"];
}
}
if ($oldprefix != false) {
$userrow[$oldprefix["basename"]] -= $oldprefix["baseattr"];
}
if ($oldsuffix != false) {
$userrow[$oldsuffix["basename"]] -= $oldsuffix["baseattr"];
}
}
if ($story["nextstory"] != "0") {
$nextstory = dorow(doquery("SELECT * FROM <<story>> WHERE id='".$story["nextstory"]."' LIMIT 1"));
$userrow["story"] = $nextstory["id"];
$userrow["storylat"] = $nextstory["latitude"];
$userrow["storylon"] = $nextstory["longitude"];
}
if ($story["targetworld"] != "0") {
$userrow["world"] = $story["targetworld"];
$userrow["latitude"] = $story["targetlat"];
$userrow["longitude"] = $story["targetlon"];
// Get first town from new world.
$newtown = dorow(doquery("SELECT * FROM <<towns>> WHERE world='".$userrow["world"]."' ORDER BY id LIMIT 1"));
$towns = explode(",",$userrow["townslist"]);
$towns[] = $newtown["id"];
$userrow["townslist"] = implode(",",$towns);
}
if ($story["targetaction"] != "") {
$userrow["currentaction"] = $story["targetaction"];
}
if ($story["rewardname"] != "") {
$userrow[$story["rewardname"]] += $story["rewardattr"];
}
updateuserrow();
die(header("Location: index.php"));
}
if (isset($_POST["noitem"])) {
if ($story["nextstory"] != "0") {
$nextstory = dorow(doquery("SELECT * FROM <<story>> WHERE id='".$story["nextstory"]."' LIMIT 1"));
$userrow["story"] = $nextstory["id"];
$userrow["storylat"] = $nextstory["latitude"];
$userrow["storylon"] = $nextstory["longitude"];
}
if ($story["targetworld"] != "0") {
$userrow["world"] = $story["targetworld"];
$userrow["latitude"] = $story["targetlat"];
$userrow["longitude"] = $story["targetlon"];
// Get first town from new world.
$newtown = dorow(doquery("SELECT * FROM <<towns>> WHERE world='".$userrow["world"]."' ORDER BY id LIMIT 1"));
$towns = explode(",",$userrow["townslist"]);
$towns[] = $newtown["id"];
$userrow["townslist"] = implode(",",$towns);
}
if ($story["targetaction"] != "") {
$userrow["currentaction"] = $story["targetaction"];
}
if ($story["rewardname"] != "") {
$userrow[$story["rewardname"]] += $story["rewardattr"];
}
updateuserrow();
die(header("Location: index.php"));
}
$story["reward"] = "";
if ($story["rewardname"] != "") {
$premodrow = dorow(doquery("SELECT * FROM <<itemmodnames>> ORDER BY id"));
foreach($premodrow as $a=>$b) {
$modrow[$b["fieldname"]] = $b;
}
$story["reward"] .= "<hr />You've gained a permanent reward from this quest:<br />";
$story["reward"] .= $modrow[$story["rewardname"]]["prettyname"] . ": +" . $story["rewardattr"];
if ($modrow[$story["rewardname"]]["percent"] == 1) { $story["reward"] .= "%"; }
$story["reward"] .= "<br />This reward will be applied when you continue on your adventure.";
}
$story["story"] = nl2br($story["story"]);
display($story["title"], parsetemplate(gettemplate("story_item"), $story));
}
?>