forked from NB-Core/lotgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mercenarycamp.php
246 lines (230 loc) · 9.94 KB
/
mercenarycamp.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
<?php
// translator ready
// addnews ready
// mail ready
require_once("common.php");
require_once("lib/http.php");
require_once("lib/villagenav.php");
tlschema("mercenarycamp");
checkday();
$name = stripslashes(rawurldecode(httpget('name')));
if (isset($companions[$name])) {
$displayname = $companions[$name]['name'];
} else {
$displayname = translate_inline("your companion");
}
$basetext=array(
"title" => "A Mercenary Camp",
"desc" => array(
"`n`QYou step out of the gates of the village and stand for a moment to take a look around.",
"A slight breeze in the air stirs the pennants mounted above your head before it touches your skin.",
"Sounds of dogs barking draw your attention to the makeshift camp which is set slightly apart from the village.",
"You walk towards the encampment trying to avoid muddy puddles left from the rainfall the prior night.",
"The odor of cooking fires permeates the air.`n`n",
"As you approach you notice two men seated on rough hewn logs in front of a tent.",
"Propped against one of the logs are a pair of long handled battle axes and a bastard sword.",
"One of the men turns his weatherbeaten face towards you.",
"You try to suppress a shudder as you recoil from the sight of his face.",
"A ragged scar marks his face from forehead to jaw, crossing an empty hole where his eye should be.",
"He spits into the campfire before him.`n`n",
"\"`4Are you looking for someone?`Q\", he asks in a gravelly voice that comes from deep within.`n`n",
"At that moment a slender elfin woman with her golden hair pulled back in a warrior's braid brushes past you.",
"Strapped across her back is a long bow and a leather quiver full of arrows fletched with turkey feathers.",
"She gives you a smirk as she passes.".
"You turn as the elfin archer continues on her way.",
"That is when you notice a large mangy dog in a tug-of-war with a troll.",
"Clenched in the dog's teeth is a very large bone with bits of flesh still clinging to it.",
"You can't tell if the troll is growling louder than the dog as it tries to wrest the bone from its jaw.",
"Hanging from the troll's wide belt is a gnarled club tht resets against filthy breeches of animal skins.",
"The sound of the man's voice brings your attention back to the matter at hand.`n`n",
"\"`PYes. As a matter of fact I am looking for someone,`Q\" you reply.",
"\"`PI have gold in my purse to pay for the best fighter willing to join me in ridding this realm of vermin.`Q\"`n`n",
"You look around to see if somebody is willing to join you.`n`n"
),
"buynav" => "Hire a mercenary",
"healnav" => "Heal a companion",
"healtext" => array(
"`QA surgeon takes a careful look at the many wounds of your companion.",
"After murmuring to himself as he makes the evaluation, he turns to you to name the price to care for the wounds.",
),
"healnotenough" => array(
"`QThe surgeon shakes his head then shrugs before turning away.",
"You are left standing with your empty purse.",
"No healing for someone who cannot pay.",
),
"healpaid" => array(
array("`QA surgeon is caring for the wounds of %s`Q and bandages them with learned skill.", $displayname),
"You gladly hand him the money owed for healing your companion and start heading back to the village.",
),
"toomanycompanions"=> array(
"It seems no one his willing to follow you.",
"You simply lead too many companions at the moment."
)
);
$schemas = array(
"title"=>"mercenarycamp",
"desc"=>"mercenarycamp",
"buynav"=>"mercenarycamp",
"healnav"=>"mercenarycamp",
"healtext"=>"mercenarycamp",
"healnotenough"=>"mercenarycamp",
"healpaid"=>"mercenarycamp",
"toomanycompanions"=>"mercenarycamp"
);
$basetext['schemas'] = $schemas;
$texts = modulehook("mercenarycamptext",$basetext);
$schemas = $texts['schemas'];
tlschema($schemas['title']);
page_header($texts['title']);
output("`c`b`&".$texts['title']."`0`b`c");
tlschema();
$op = httpget("op");
if ($op==""){
if (httpget('skip') != 1) {
tlschema($schemas['desc']);
if (is_array($texts['desc'])) {
foreach ($texts['desc'] as $description) {
output_notl(sprintf_translate($description));
}
} else {
output($texts['desc']);
}
tlschema();
}
$sql = "SELECT * FROM " . db_prefix("companions") . "
WHERE companioncostdks<={$session['user']['dragonkills']}
AND (companionlocation = '{$session['user']['location']}' OR companionlocation = 'all')
AND companionactive = 1";
$result = db_query($sql);
tlschema($schemas['buynav']);
addnav($texts['buynav']);
tlschema();
while ($row = db_fetch_assoc($result)) {
$row = modulehook("alter-companion", $row);
if ($row['companioncostgold'] && $row['companioncostgems']) {
if ($session['user']['gold'] >= $row['companioncostgold'] && $session['user']['gems'] >= $row['companioncostgems'] && !isset($companions[$row['name']])) {
addnav(array("%s`n`^%s Gold, `%%%s Gems`0",$row['name'], $row['companioncostgold'], $row['companioncostgems']), "mercenarycamp.php?op=buy&id={$row['companionid']}");
} else {
addnav(array("%s`n`^%s Gold, `%%%s Gems`0",$row['name'], $row['companioncostgold'], $row['companioncostgems']), "");
}
} else if ($row['companioncostgold']) {
if ($session['user']['gold'] >= $row['companioncostgold'] && !isset($companions[$row['name']])) {
addnav(array("%s`n`^%s Gold`0",$row['name'], $row['companioncostgold']), "mercenarycamp.php?op=buy&id={$row['companionid']}");
} else {
addnav(array("%s`n`^%s Gold`0",$row['name'], $row['companioncostgold']), "");
}
} else if ($row['companioncostgems']) {
if ($session['user']['gems'] >= $row['companioncostgems'] && !isset($companions[$row['name']])) {
addnav(array("%s`n`%%%s Gems`0",$row['name'], $row['companioncostgems']), "mercenarycamp.php?op=buy&id={$row['companionid']}");
} else {
addnav(array("%s`n`%%%s Gems`0",$row['name'], $row['companioncostgems']), "");
}
} else if (!isset($companions[$row['name']])) {
addnav(array("%s",$row['name']), "mercenarycamp.php?op=buy&id={$row['companionid']}");
}
output("`#%s`n`7%s`n`n",$row['name'], $row['description']);
}
healnav($companions, $texts, $schemas);
} else if ($op == "heal") {
$cost = httpget('cost');
if ($cost == 'notenough') {
tlschema($schemas['healpaid']);
if (is_array($texts['healnotenough'])) {
foreach ($texts['healnotenough'] as $healnotenough) {
output_notl(sprintf_translate($healnotenough));
}
} else {
output($texts['healnotenough']);
}
tlschema();
} else {
$companions[$name]['hitpoints'] = $companions[$name]['maxhitpoints'];
$session['user']['companions'] = serialize($companions);
$session['user']['gold'] -= $cost;
debuglog("spent $cost gold on healing a companion", false, false, "healcompanion", $cost);
tlschema($schemas['healpaid']);
if (is_array($texts['healpaid'])) {
foreach ($texts['healpaid'] as $healpaid) {
output_notl(sprintf_translate($healpaid));
}
} else {
output($texts['healpaid']);
}
tlschema();
}
healnav($companions, $texts, $schemas);
addnav("Navigation");
addnav("Return to the camp", "mercenarycamp.php?skip=1");
} else if ($op == "buy") {
$id = httpget('id');
$sql = "SELECT * FROM ".db_prefix("companions")." WHERE companionid = $id";
$result = db_query($sql);
if ($row = db_fetch_assoc($result)) {
$row['attack'] = $row['attack'] + $row['attackperlevel'] * $session['user']['level'];
$row['defense'] = $row['defense'] + $row['defenseperlevel'] * $session['user']['level'];
$row['maxhitpoints'] = $row['maxhitpoints'] + $row['maxhitpointsperlevel'] * $session['user']['level'];
$row['hitpoints'] = $row['maxhitpoints'];
$row = modulehook("alter-companion", $row);
$row['abilities'] = @unserialize($row['abilities']);
require_once("lib/buffs.php");
if (apply_companion($row['name'], $row)) {
output("`QYou hand over `^%s gold`Q and `%%s %s`Q.`n`n", (int)$row['companioncostgold'], (int)$row['companioncostgems'],translate_inline($row['companioncostgems'] == 1?"gem":"gems"));
if (isset($row['jointext']) && $row['jointext'] > "") {
output($row['jointext']);
}
$session['user']['gold'] -= $row['companioncostgold'];
$session['user']['gems'] -= $row['companioncostgems'];
debuglog("has spent {$row['companioncostgold']} gold and {$row['companioncostgems']} gems on hiring a mercenary ({$row['name']}).");
} else {
// applying the companion failed. Most likely they already have more than enough companions...
tlschema($schemas['toomanycompanions']);
if (is_array($texts['toomanycompanions'])) {
foreach ($texts['toomanycompanions'] as $toomanycompanions) {
output_notl(sprintf_translate($toomanycompanions));
}
} else {
output($texts['toomanycompanions']);
}
tlschema();
}
}
addnav("Navigation");
addnav("Return to the camp", "mercenarycamp.php?skip=1");
}
addnav("Navigation");
villagenav();
page_footer();
function healnav($companions, $texts, $schemas) {
global $session;
tlschema($schemas['healnav']);
addnav($texts['healnav']);
tlschema();
$healable = false;
foreach ($companions as $name => $companion) {
if (isset($companion['cannotbehealed']) && $companion['cannotbehealed'] == true) {
} else {
$pointstoheal = $companion['maxhitpoints'] - $companion['hitpoints'];
if ($pointstoheal > 0) {
$healable = true;
$costtoheal = round(log($session['user']['level']+1) * ($pointstoheal + 10)*1.33);
if ($session['user']['gold'] >= $costtoheal) {
addnav(array("%s`0 (`^%s Gold`0)", $companion['name'], $costtoheal), "mercenarycamp.php?op=heal&name=".rawurlencode($name)."&cost=$costtoheal");
} else {
addnav(array("%s`0 (`\$Not enough gold`0)", $companion['name']), "mercenarycamp.php?op=heal&name=".rawurlencode($name)."&cost=notenough");
}
}
}
}
if ($healable == true) {
tlschema($schemas['healtext']);
if (is_array($texts['healtext'])) {
foreach ($texts['healtext'] as $healtext) {
output_notl(sprintf_translate($healtext));
}
} else {
output($texts['healtext']);
}
tlschema();
}
}
?>