/
bleeding.php
385 lines (358 loc) · 15.4 KB
/
bleeding.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
<?php
/* Update Bleeding .. Durrrr */
function update_bleeding($character_id) {
$attacking = get_victim($character_id);
/* Load Player Info */
$query = "SELECT * FROM characters WHERE (id='$character_id')";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$head = $row['head'];
$torso = $row['torso'];
$upper_left = $row['upper_left'];
$upper_right = $row['upper_right'];
$lower_left = $row['lower_left'];
$lower_right = $row['lower_right'];
$armor = $row['equippedArmor'];
$health = $row['totalHealth'];
$current_health = $row['cur_health'];
}
/* Calculate Damage */
/* Get Max Bleed */
$max_bleed = round($health * 0.1);
$offset = round($health * 0.05);
if ($head <= $offset) { $head = 0; } else { $head = $head - $offset; }
if ($torso <= $offset) { $torso = 0; } else { $torso = $torso - $offset; }
if ($upper_right <= $offset) { $upper_right = 0; } else { $upper_right = $upper_right - $offset; }
if ($upper_left <= $offset) { $upper_left = 0; } else { $upper_left = $upper_left - $offset; }
if ($lower_right <= $offset) { $lower_right = 0; } else { $lower_right = $lower_right - $offset; }
if ($lower_left <= $offset) { $lower_left = 0; } else { $lower_left = $lower_left - $offset; }
if ($health > 0) {
/* Get Head Damage */
$head_damage = round(($head / $health) * ($max_bleed * 0.4));
/* Get Torso Damage */
$torso_damage = round(($torso / $health) * ($max_bleed * 0.3));
/* Get Right Arm */
$upper_right_damage = round(($upper_right / $health) * ($max_bleed * 0.2));
/* Get Left Arm */
$upper_left_damage = round(($upper_left / $health) * ($max_bleed * 0.2));
/* Get Right Leg */
$lower_right_damage = round(($lower_right / $health) * ($max_bleed * 0.1));
/* Get Left Left */
$lower_left_damage = round(($lower_left / $health) * ($max_bleed * 0.1));
}
$damage = $head_damage + $torso_damage + $upper_left_damage + $upper_right_damage + $lower_left_damage + $lower_right_damage;
if ($damage > $max_bleed) { $damage = $max_bleed; }
/* Write To Character */
if ($damage > 0) {
$query = "UPDATE characters SET cur_health=cur_health-$damage WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
/* If In Battle, Log Bleeding To Battlelog */
if ($attacking > 0 && $damage > 0) {
/* Determine severity Of Bleed */
$bleed_percent = $damage / $current_health;
if ($current_health == 0) { $current_health = 1;}
if ($bleed_percent > .00) { $bleed_amount = "You\'re bleeding a tiny amount"; }
if ($bleed_percent > .02) { $bleed_amount = "You\'re bleeding a small amount"; }
if ($bleed_percent > .04) { $bleed_amount = "You\'re bleeding a good amount"; }
if ($bleed_percent > .065) { $bleed_amount = "You\'re bleeding quite a bit"; }
if ($bleed_percent > .10) { $bleed_amount = "You\'re bleeding quite a lot"; }
if ($bleed_percent > .25) { $bleed_amount = "Your wounds are grievous"; }
if ($bleed_percent > .35) { $bleed_amount = "You will certainly bleed to death soon"; }
$turns = num_of_turns($character_id);
$history = "".$bleed_amount.".";
write_battle_history($history,$attacking,$character_id,'cbleed',$turns,$bleed_percent,'you');
}
}
/* Update Bleeding for Mobs */
function update_bleeding_mob($character_id) {
$attacking = get_victim($character_id);
/* Load Mobs With Damage Info */
$query = "SELECT * FROM mobs WHERE (characterid='$character_id') AND ((head>0) OR (torso>0) OR (upper_left>0) OR (upper_right>0) OR (lower_left>0) OR (lower_right>0)) AND (corpse<1)";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$id = $row['id'];
$name = $row['kind'];
$head = $row['head'];
$torso = $row['torso'];
$upper_left = $row['upper_left'];
$upper_right = $row['upper_right'];
$lower_left = $row['lower_left'];
$lower_right = $row['lower_right'];
$armor = $row['equipped_armor'];
$health = $row['total_health'];
$current_health = $row['cur_health'];
/* Get Max Bleed */
$max_bleed = round($health * 0.6);
/* Get Head Damage */
$head_damage = round(($head / $health) * ($max_bleed * 0.5));
/* Get Torso Damage */
$torso_damage = round(($torso / $health) * ($max_bleed * 0.4));
/* Get Right Arm */
$upper_right_damage = round(($upper_right / $health) * ($max_bleed * 0.3));
/* Get Left Arm */
$upper_left_damage = round(($upper_left / $health) * ($max_bleed * 0.3));
/* Get Right Leg */
$lower_right_damage = round(($lower_right / $health) * ($max_bleed * 0.2));
/* Get Left Left */
$lower_left_damage = round(($lower_left / $health) * ($max_bleed * 0.2));
$damage = $head_damage + $torso_damage + $upper_left_damage + $upper_right_damage + $lower_left_damage + $lower_right_damage;
/* Write To Mob */
$query = "UPDATE mobs SET cur_health=cur_health-$damage WHERE id='$id'";
mysql_query($query) or die(mysql_error());
/* If Mob Is The One You're Attacking ... */
if ($attacking == $id && $damage > 0) {
$turns = num_of_turns($character_id);
if ($current_health == 0) { $current_health = 1;}
$bleed_percent = $damage / $current_health;
if ($bleed_percent > .00) { $bleed_amount = "The ".$name." is bleeding a tiny amount"; }
if ($bleed_percent > .02) { $bleed_amount = "The ".$name." is bleeding a small amount"; }
if ($bleed_percent > .04) { $bleed_amount = "The ".$name." is bleeding a good amount"; }
if ($bleed_percent > .065) { $bleed_amount = "The ".$name." is bleeding quite a bit"; }
if ($bleed_percent > .10) { $bleed_amount = "The ".$name." is bleeding quite a lot"; }
if ($bleed_percent > .25) { $bleed_amount = "The ".$name."\'s wounds are grievous"; }
if ($bleed_percent > .35) { $bleed_amount = "The ".$name." will certainly bleed to death soon"; }
$history = "".$bleed_amount.".";
write_battle_history($history,$attacking,$character_id,'ebleed',$turns,$bleed_percent,$name);
}
}
}
/* Check for Player Death */
function is_player_dead($character_id) {
$attacking = get_victim($character_id);
/* Load Player Info */
$query = "SELECT cur_health FROM characters WHERE (id='$character_id')";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$health = $row['cur_health'];
}
if ($health < 1) {
/* Player is dead */
/* If in battle, log death to battle log. */
if ($attacking > 0) {
$history = "You\'ve died from your wounds.";
write_battle_history($history,$attacking,$character_id,'alert',0,0,0);
}
/* Set "player dead" flag */
$query = "UPDATE characters SET dead=1 WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
} else {
/* Player is not dead */
}
}
/* Return player death */
function death($character_id) {
/* Load Player Info */
$query = "SELECT dead FROM characters WHERE (id='$character_id')";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$dead = $row['dead'];
}
return $dead;
}
/* Check for enemy Death */
function is_mob_dead($character_id) {
$attacking = get_victim($character_id);
/* Find Dead Mobs */
$query = "SELECT * FROM `mobs` WHERE `characterid`='$character_id' AND `cur_health`<1 AND `corpse`<1";
$result = mysql_query($query) or die(mysql_error());
while($row = @mysql_fetch_array($result,MYSQL_ASSOC)) {
$experience = $row['experience'];
$name = $row['kind'];
$id = $row['id'];
$room = $row['inRoom'];
$weapon = $row['equipped_weapon'];
$armor = $row['equipped_armor'];
$boss = $row['boss'];
/* Update Battlelog */
if ($attacking == $id) {
$turns = num_of_turns($character_id);
$history = "You killed the ".$name.", and gained ".$experience." experience.";
write_battle_history($history,$attacking,$character_id,'alert',$turns,'killed',$mob_name);
}
/* Update Room History */
$history = "You killed the ".$name.", and gained ".$experience." experience.";
write_room_history($history,$room,$character_id);
/* Drop Mob Items In Room */
$weapon_rand = rand(0,2);
$armor_rand = rand(0,2);
if ($boss > 0) {
$weapon_rand = rand(0,3);
$armor_rand = rand(0,3);
}
if ($weapon_rand == 1) {
$query = "UPDATE weapons SET inRoom='$room' WHERE id='$weapon'";
$result = mysql_query($query) or die(mysql_error());
}
if ($armor_rand == 1) {
$query = "UPDATE armors SET inRoom='$room' WHERE id='$armor'";
$result = mysql_query($query) or die(mysql_error());
}
// Have mob drop a healing item randomly
$bandages_total = count_bandages($character_id);
if ($boss == 0) {
if (rand(0,2) == 1) { place_item_in_room(generate_item($character_id),$room);}
if (rand(0,4) == 1) { place_item_in_room(generate_item($character_id),$room);}
} else if ($boss > 0) {
place_item_in_room(generate_item($character_id),$room);
if (rand(0,5) == 1) { place_item_in_room(generate_item($character_id),$room);}
if (rand(0,1) == 1) { place_tome_in_room(generate_tome($character_id,0),$room);}
if (rand(0,3) == 1) { place_tome_in_room(generate_tome($character_id,0),$room);}
}
if (rand(0,100) == 1) { place_item_in_room(generate_item($character_id),$room);}
if (rand(0,700) == 1) { place_item_in_room(generate_item($character_id),$room);}
if (rand(0,2) == 1) { place_tome_in_room(generate_tome($character_id,0),$room);}
if (rand(0,6) == 1) { place_tome_in_room(generate_tome($character_id,0),$room);}
/* If attacking, unset attacking flag */
if ($attacking == $id) {
$query = "UPDATE characters SET attacking='0' WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
/* Add experience to character */
$query = "UPDATE characters SET experience=experience+$experience WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
/* Delete Mob */
$query = "UPDATE mobs SET corpse='1' WHERE (id='$id')";
$result = mysql_query($query) or die(mysql_error());
}
return 1;
}
/* Return 1 if Character Bleeding */
function is_bleeding($character_id) {
if ($character_id > 0) {
/* Load Player Info */
$query = "SELECT * FROM characters WHERE (id='$character_id')";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$head = $row['head'];
$torso = $row['torso'];
$upper_left = $row['upper_left'];
$upper_right = $row['upper_right'];
$lower_left = $row['lower_left'];
$lower_right = $row['lower_right'];
$armor = $row['equippedArmor'];
$health = $row['totalHealth'];
}
$max_bleed = round($health * 0.1);
$offset = round($health * 0.05);
if ($head <= $offset) { $head = 0; } else { $head = $head - $offset; }
if ($torso <= $offset) { $torso = 0; } else { $torso = $torso - $offset; }
if ($upper_right <= $offset) { $upper_right = 0; } else { $upper_right = $upper_right - $offset; }
if ($upper_left <= $offset) { $upper_left = 0; } else { $upper_left = $upper_left - $offset; }
if ($lower_right <= $offset) { $lower_right = 0; } else { $lower_right = $lower_right - $offset; }
if ($lower_left <= $offset) { $lower_left = 0; } else { $lower_left = $lower_left - $offset; }
/* Get Head Damage */
$head_damage = round(($head / $health) * ($max_bleed * 0.4));
/* Get Torso Damage */
$torso_damage = round(($torso / $health) * ($max_bleed * 0.3));
/* Get Right Arm */
$upper_right_damage = round(($upper_right / $health) * ($max_bleed * 0.2));
/* Get Left Arm */
$upper_left_damage = round(($upper_left / $health) * ($max_bleed * 0.2));
/* Get Right Leg */
$lower_right_damage = round(($lower_right / $health) * ($max_bleed * 0.1));
/* Get Left Left */
$lower_left_damage = round(($lower_left / $health) * ($max_bleed * 0.1));
$damage = $head_damage + $torso_damage + $upper_left_damage + $upper_right_damage + $lower_left_damage + $lower_right_damage;
if ($damage > $max_bleed) { $damage = $max_bleed; }
return $damage;
} else { return 0; }
}
/* Return 1 if mob Bleeding */
function is_victim_bleeding($mob_id) {
if ($mob_id > 0) {
/* Load Player Info */
$query = "SELECT * FROM mobs WHERE (id='$mob_id')";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$id = $row['id'];
$name = $row['kind'];
$head = $row['head'];
$torso = $row['torso'];
$upper_left = $row['upper_left'];
$upper_right = $row['upper_right'];
$lower_left = $row['lower_left'];
$lower_right = $row['lower_right'];
$armor = $row['equipped_armor'];
$health = $row['total_health'];
$current_health = $row['cur_health'];
}
/* Get Max Bleed */
$max_bleed = round($health * 0.6);
/* Get Head Damage */
$head_damage = round(($head / $health) * ($max_bleed * 0.5));
/* Get Torso Damage */
$torso_damage = round(($torso / $health) * ($max_bleed * 0.4));
/* Get Right Arm */
$upper_right_damage = round(($upper_right / $health) * ($max_bleed * 0.3));
/* Get Left Arm */
$upper_left_damage = round(($upper_left / $health) * ($max_bleed * 0.3));
/* Get Right Leg */
$lower_right_damage = round(($lower_right / $health) * ($max_bleed * 0.2));
/* Get Left Left */
$lower_left_damage = round(($lower_left / $health) * ($max_bleed * 0.2));
$damage = $head_damage + $torso_damage + $upper_left_damage + $upper_right_damage + $lower_left_damage + $lower_right_damage;
return $damage;
} else { return 0; }
}
/* Heal Wounds */
function auto_heal($character_id) {
$query = "SELECT * FROM characters WHERE (id='$character_id')";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$head = $row['head'];
$torso = $row['torso'];
$upper_left = $row['upper_left'];
$upper_right = $row['upper_right'];
$lower_left = $row['lower_left'];
$lower_right = $row['lower_right'];
$armor = $row['equippedArmor'];
$health = $row['totalHealth'];
$current_health = $row['cur_health'];
$player_level = $row['level'];
}
$heal_amount = 1; //round($health * .01);
if ($head >= $heal_amount) {
$query = "UPDATE characters SET head=head-$heal_amount WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
} else {
$query = "UPDATE characters SET head=0 WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
if ($torso >= $heal_amount) {
$query = "UPDATE characters SET torso=torso-$heal_amount WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
} else {
$query = "UPDATE characters SET torso=0 WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
if ($upper_left >= $heal_amount) {
$query = "UPDATE characters SET upper_left=upper_left-$heal_amount WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
} else {
$query = "UPDATE characters SET upper_left=0 WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
if ($upper_right >= $heal_amount) {
$query = "UPDATE characters SET upper_right=upper_right-$heal_amount WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
} else {
$query = "UPDATE characters SET upper_right=0 WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
if ($lower_left >= $heal_amount) {
$query = "UPDATE characters SET lower_left=lower_left-$heal_amount WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
} else {
$query = "UPDATE characters SET lower_left=0 WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
if ($lower_right >= $heal_amount) {
$query = "UPDATE characters SET lower_right=lower_right-$heal_amount WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
} else {
$query = "UPDATE characters SET lower_right=0 WHERE id='$character_id'";
mysql_query($query) or die(mysql_error());
}
}
?>