~case/dbns

ref: 85d3c74215baa48cb2fd97d3c85ff6060e7c42b1 dbns/src/bounty.c -rw-r--r-- 16.4 KiB
85d3c742Zerhyn SBC oopsie 3 years ago
                                                                                
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
/****************************************************************************
 * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame      |   \\._.//   *
 * -----------------------------------------------------------|   (0...0)   *
 * SMAUG 1.4 (C) 1994, 1995, 1996, 1998  by Derek Snider      |    ).:.(    *
 * -----------------------------------------------------------|    {o o}    *
 * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,      |   / ' ' \   *
 * Scryn, Rennard, Swordbearer, Gorog, Grishnakh, Nivek,      |~'~.VxvxV.~'~*
 * Tricops and Fireblade                                      |             *
 * ------------------------------------------------------------------------ *
 * Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
 * Chastain, Michael Quan, and Mitchell Tse.                                *
 * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
 * Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.     *
 * ------------------------------------------------------------------------ *
 *                           Bounty Add-On                                  *
 ****************************************************************************/
/****************************************************************************
 * Bounty for ResortMUD 5.0 by Garinan                                      *
 *                                                                          *
 * A simple code which allows players to place a gold bounty on the head of *
 * a deadly player.                                                         *
 *                                                                          *
 * If you have any questions, comments, concerns or bugs to report which    *
 * are not resolved within the included readme.txt, please email me at:     *
 * garinan@hotmail.com, your support is greatly appreciated.                *
 *                                                                          *
 *                                                  - Garinan               *
 ****************************************************************************/
/****************************************************************************
 * Copyright (c) Andrew Brunelle 2000, All Rights Reserved                  *
 * This code, as well as this document is distributed to be used freely     *
 * provided that credit be given to myself, its author Andrew Brunelle      *
 * (Garinan Templar). If you wish to distribute this snippet via your own   *
 * website or any other means, please contact me first at the email address *
 * below, I will likely only ask that you add a link to UCMM in exchange,   *
 * thank you and good luck!                                                 *
 ****************************************************************************/
/****************************************************************************
 *********************************DISCLAIMER*********************************
 ****************************************************************************
 * By adding this code to your MUD you are doing so at your own risk.       *
 * Neither I (Andrew Brunelle), nor any organization with which i am        *
 * affiliated, will be held responsible for any damages to your MUD by      *
 * adding this code.                                                        *
 ****************************************************************************/

#include <sys/types.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
#include "mud.h"

CHAR_DATA *
find_bounty(CHAR_DATA * ch)
{
	CHAR_DATA *bounty;

	for (bounty = ch->in_room->first_person; bounty; bounty = bounty->next_in_room) {
		if (IS_NPC(bounty) && xIS_SET(bounty->act, ACT_BOUNTY))
			break;
	}

	return (bounty);
}

void 
do_bounty(CHAR_DATA * ch, char *argument)
{
	DESCRIPTOR_DATA *d;
	CHAR_DATA *vch;
	CHAR_DATA *bounty;
	CHAR_DATA *victim = NULL;
	char 	arg1[MAX_INPUT_LENGTH];
	char 	arg2[MAX_INPUT_LENGTH];
	char 	buf[MAX_STRING_LENGTH];
	int 	amount, bountymax;
	int 	count = 0;
	int 	cost = 0;

/* cost is the cost for a peaceful to become ineligable to be bountied *
 * bountymax is the maximum amount to be put on a player's head        *
 * alter below to suit your needs.                           - Garinan */

	bountymax = 2000000000;

	if (ch->exp < 250) {
		send_to_char("You can't use the bounty command until you are 100,000 PL.\n\r", ch);
		return;
	}
	if ((bounty = find_bounty(ch)) == NULL) {

/* Why should players need to be at a bounty officer to check *
 * the value of their bounty? They shouldn't :P - Garinan     */

		if (!str_cmp(argument, "check")) {
			if (IS_NPC(ch))
				ch_printf(ch, "&YMobiles can not have bounties.\n\r");
			else if (ch->pcdata->bounty > 0)
				ch_printf(ch, "&YYou have a bounty worth %s zeni on your head.\n\r", num_punct(ch->pcdata->bounty));
			else
				ch_printf(ch, "&YYou have no bounty on your head.\n\r");
			if (IS_NPC(ch))
				ch_printf(ch, "&YMobiles can not collect bounties.\n\r");
			else if (ch->pcdata->bowed > 0)
				ch_printf(ch, "&YYou are owed %s zeni in bounty earnings.\n\r", num_punct(ch->pcdata->bowed));
			else
				ch_printf(ch, "&YYou have not claimed any bounties.\n\r");
			return;
		}
		send_to_char("There is no bounty officer here!\n\r", ch);
		return;
	}
	act(AT_ACTION, "$n and $N whisper quietly to each other.", ch, ch, bounty, TO_ROOM);
	act(AT_ACTION, "You whisper your request to $N.", ch, bounty, bounty, TO_CHAR);

	if (IS_NPC(ch)) {
		sprintf(buf, "We don't deal with your kind %s.",
		    ch->short_descr);
		do_say(bounty, buf);
		return;
	}
	if (argument[0] == '\0') {
		sprintf(buf, "If you need help, see HELP BOUNTY.");
		do_say(bounty, buf);
		return;
	}
	argument = one_argument(argument, arg1);
	argument = one_argument(argument, arg2);

	if (arg1[0] == '\0') {
		sprintf(buf, "How much zeni do you want to place, and on who?");
		do_say(bounty, buf);
		return;
	}
/* Bounty check, players can check if they have a bounty on them *
 * and if so, how much its value is.                             *
 *                                         - Garinan             */

	if (!str_cmp(arg1, "check")) {

		if (arg2[0] == '\0') {
			if (IS_NPC(ch))
				ch_printf(ch, "&YMobiles can not have bounties.\n\r");
			else if (ch->pcdata->bounty > 0)
				ch_printf(ch, "&YYou have a bounty worth %s zeni on your head.\n\r", num_punct(ch->pcdata->bounty));
			else
				ch_printf(ch, "&YYou have no bounty on your head.\n\r");
			if (IS_NPC(ch))
				ch_printf(ch, "&YMobiles can not collect bounties.\n\r");
			else if (ch->pcdata->bowed > 0)
				ch_printf(ch, "&YYou are owed %s zeni in bounty earnings.\n\r", num_punct(ch->pcdata->bowed));
			else
				ch_printf(ch, "&YYou have not collected any bounties.\n\r");
			return;
		}
		if (!(victim = get_char_world(ch, arg2))) {
			do_say(bounty, "I don't know anyone by that name.");
			return;
		}
		if (IS_NPC(victim))
			do_say(bounty, "Mobiles cannot have bounties!");
		else if ((victim = get_char_world(ch, arg2))) {

			if (victim->pcdata->bounty > 0) {
				sprintf(buf, "%s %s's bounty is worth %s zeni.",
				    ch->name, victim->name, num_punct(victim->pcdata->bounty));
				do_tell(bounty, buf);
				return;
			}
			sprintf(buf, "%s That player has no bounty.", ch->name);
			do_tell(bounty, buf);
			return;
		}
		return;

	}
	if (!str_cmp(arg1, "buy")) {
		if ((bounty = find_bounty(ch)) == NULL) {
			ch_printf(ch, "There is no bounty officer here!\n\r");
			return;
		}
		if (ch->pcdata->bounty <= 0 || !xIS_SET(ch->act, PLR_BOUNTY)) {
			sprintf(buf, "%s You don't have a bounty on your head.", ch->name);
			do_tell(bounty, buf);
			if (xIS_SET(ch->act, PLR_BOUNTY))
				xREMOVE_BIT(ch->act, PLR_BOUNTY);
			if (ch->pcdata->bounty != 0)
				ch->pcdata->bounty = 0;
			if (ch->pcdata->bounty_by != str_dup("")) {
				DISPOSE(ch->pcdata->bounty_by);
				ch->pcdata->bounty_by = str_dup("");
			}
			return;
		}
		cost = ch->pcdata->bounty * 0.25;

		if (ch->gold < cost) {
			sprintf(buf, "%s I'm sorry, you can't afford this.", ch->name);
			do_tell(bounty, buf);
			return;
		}
		ch->gold -= cost;
		sprintf(buf, "%s You have bought the bounty that was put on your head.", ch->name);
		do_tell(bounty, buf);
		ch->pcdata->bounty = 0;
		ch->pcdata->b_timeleft = 1440;
		xREMOVE_BIT(ch->act, PLR_BOUNTY);
		DISPOSE(ch->pcdata->bounty_by);
		ch->pcdata->bounty_by = str_dup("");
		return;
	}
	if (!str_cmp(arg1, "who")) {

		if ((bounty = find_bounty(ch)) == NULL) {
			ch_printf(ch, "There is no bounty officer here!\n\r");
			return;
		}
		if (ch->pcdata->bounty <= 0 || !xIS_SET(ch->act, PLR_BOUNTY)) {
			sprintf(buf, "%s You don't have a bounty on your head.", ch->name);
			do_tell(bounty, buf);
			if (xIS_SET(ch->act, PLR_BOUNTY))
				xREMOVE_BIT(ch->act, PLR_BOUNTY);
			if (ch->pcdata->bounty != 0)
				ch->pcdata->bounty = 0;
			if (ch->pcdata->bounty_by != NULL) {
				DISPOSE(ch->pcdata->bounty_by);
				ch->pcdata->bounty_by = str_dup("");
			}
			return;
		}
		cost = ch->pcdata->bounty * 0.05;

		if (ch->gold < cost) {
			sprintf(buf, "%s I'm sorry, you can't afford this.", ch->name);
			do_tell(bounty, buf);
			return;
		}
		ch->gold -= cost;
		sprintf(buf, "%s It was %s who put the bounty on your head.", ch->name, ch->pcdata->bounty_by);
		do_tell(bounty, buf);
		return;
	}
	if (!str_cmp(arg1, "hunt")) {

		if ((bounty = find_bounty(ch)) == NULL) {
			ch_printf(ch, "There is no bounty officer here!\n\r");
			return;
		}
		if (!IS_HC(ch) && !IS_IMMORTAL(ch)) {
			sprintf(buf, "%s People like you don't have the skill or guts to hunt others.", ch->name);
			do_tell(bounty, buf);
			return;
		}
		if (arg2[0] == '\0') {

			pager_printf_color(ch, "The folowing people have a price on their head:\n\r");
			for (d = first_descriptor; d; d = d->next) {
				vch = d->character;

				if (!vch) {
					continue;
				}
				if (xIS_SET(vch->act, PLR_BOUNTY)) {
					pager_printf_color(ch, " &RWANTED: [&W%-16s&R]  REWARD:[&W%-10s&R]\n\r", vch->name, num_punct(vch->pcdata->bounty));
					count++;
				}
			}

			if (count <= 0)
				pager_printf_color(ch, "&w No one had a price on their head right now.\n\r");

			return;
		}
		if (!(victim = get_char_world(ch, arg2))) {
			do_say(bounty, "I don't know anyone by that name.");
			return;
		}
		if ((victim = get_char_world(ch, arg2)) && !IS_NPC(victim)) {
			cost = victim->pcdata->bounty * 0.25;

			if (victim->pcdata->bounty > 0 && xIS_SET(victim->act, PLR_BOUNTY)) {
				if (!str_cmp(argument, "pay")) {
					if (ch->gold < cost) {
						sprintf(buf, "%s You don't have enough zeni.",
						    ch->name);
						do_tell(bounty, buf);
						return;
					}
					if (!str_cmp(ch->name, victim->pcdata->bounty_by)) {
						sprintf(buf, "%s You can not clam your own bounty.",
						    ch->name);
						do_tell(bounty, buf);
						return;
					}
					sprintf(buf, "%s Very well, you may try to collect the bounty on %s's head.",
					    ch->name, victim->name);
					do_tell(bounty, buf);
					//ch->gold -= (ch->pcdata->bounty * 0.25);
					ch->gold -= cost;
					ch->pcdata->hunting = strdup(victim->name);
					return;
				}
				sprintf(buf, "%s You will have to pay a service fee of %s to collect that bounty.",
				    ch->name, num_punct(cost));
				do_tell(bounty, buf);
				return;
			}
		}
		sprintf(buf, "%s That player has no bounty.", ch->name);
		do_tell(bounty, buf);
		return;
	}
	if (!str_cmp(arg1, "collect")) {
		if (ch->pcdata->bowed <= 0) {
			sprintf(buf, "%s I owe you nothing %s!", ch->name, ch->name);
			do_tell(bounty, buf);
			return;
		}
		ch->gold += ch->pcdata->bowed;
		sprintf(buf, "&YYou collect %s zeni worth of bounties.\n\r", num_punct(ch->pcdata->bowed));
		send_to_char(buf, ch);
		ch->pcdata->bowed = 0;
		sprintf(buf, "%s A pleasure doing business with you.", ch->name);
		do_tell(bounty, buf);
		act(AT_ACTION, "$N hands a small sack of zeni to $n.", ch, ch, bounty, TO_ROOM);
		return;
	}
	if (!(victim = get_char_world(ch, arg2))) {
		do_say(bounty, "That player is not online.");
		return;
	}
	if (IS_NPC(victim)) {
		do_say(bounty, "A mobile? Kill it yourself!");
		return;
	}
	amount = 0;
	if (!IS_NPC(victim) && victim->pcdata->bounty > 0)
		cost = victim->pcdata->bounty * .5;
	else if (!IS_HC(victim))
		cost = get_rank_number(victim) * get_rank_number(victim) * get_rank_number(victim) * 10000;
	else
		cost = get_true_rank(ch) * get_true_rank(ch) * get_true_rank(victim) * 1750;

	if (cost == 0)
		cost = 1;

	if (!str_cmp(arg1, "all")) {
		amount = ch->gold;
	}
	if (amount == 0) {
		if (!is_number(arg1)) {
			sprintf(buf, "%s You must pay me in zeni!", ch->name);
			do_tell(bounty, buf);
			return;
		}
		amount = atoi(arg1);
	}
	if (amount > ch->gold) {
		sprintf(buf, "%s Check your pockets and try again, you don't have that much zeni!", ch->name);
		do_tell(bounty, buf);
		return;
	}
	if (amount <= 0) {
		sprintf(buf, "%s That amount is too frugal, try again!", ch->name);
		do_tell(bounty, buf);
		return;
	}
	if (victim->level >= LEVEL_IMMORTAL && ch != victim) {
		sprintf(buf, "%s You may not place a bounty on the head of an administrator!", ch->name);
		do_tell(bounty, buf);
		return;
	}
	if (victim->exp < 250 && ch != victim) {
		sprintf(buf, "%s you can not place a bounty on a player under 100,000 power level.", ch->name);
		do_tell(bounty, buf);
		return;
	}
/*  this shouldn't be here  -Goku
    if( !xIS_SET( victim->act, PLR_PK1 )
     && !xIS_SET( victim->act, PLR_PK2 ) )
    {
      sprintf( buf, "%s You may not place a bounty on those who don't have pkill on.", ch->name );
      do_tell( bounty, buf );
      return;
    }
*/
	if ((amount + victim->pcdata->bounty) > bountymax) {
		sprintf(buf, "%s That would exceed the maximum allowable bounty of %s zeni!", ch->name, num_punct(bountymax));
		do_tell(bounty, buf);
		return;
	}
	if (amount < cost) {
		sprintf(buf, "%s The minimum bounty you can place on %s is %s",
		    ch->name, victim->name, num_punct(cost));
		do_tell(bounty, buf);
		return;
	}
	if (ch == victim) {
		sprintf(buf, "%s Place a bounty on yourself? Ever considered suicide?", ch->name);
		do_tell(bounty, buf);
		return;
	}
	if (victim->pcdata->b_timeleft > 0 && victim->pcdata->bounty <= 0) {
		sprintf(buf, "%s I don't like spam killing, you must wait %d more %s to put another bounty on %s.", ch->name,
		    victim->pcdata->b_timeleft >= 60 ? victim->pcdata->b_timeleft / 60 : victim->pcdata->b_timeleft,
		    victim->pcdata->b_timeleft >= 60 ? "hours" : "minutes", himher(victim, false));
		do_tell(bounty, buf);
		return;
	}
	ch->gold -= amount;
	act(AT_ACTION, "You hand a small sack of zeni to $N.", ch, ch, bounty, TO_CHAR);
	act(AT_ACTION, "$n hands a small sack of zeni to $N.", ch, ch, bounty, TO_ROOM);
	if (victim->pcdata->bounty > 0) {
		sprintf(buf, "%s The bounty on %s has been increased by %s zeni!", ch->name, victim->name, num_punct(amount));
		do_tell(bounty, buf);
		sprintf(buf, "&RThe bounty on %s has been increased by %s zeni!", victim->name, num_punct(amount));
		do_info(bounty, buf);
		sprintf(buf, "&YThe bounty on your head has been increased by %s zeni!\n\r", num_punct(amount));
		send_to_char(buf, victim);
		if (victim->pcdata->bounty < 0)
			victim->pcdata->bounty = amount;
		else
			victim->pcdata->bounty += amount;
		return;
	}
	victim->pcdata->bounty = amount;
	xSET_BIT(victim->act, PLR_BOUNTY);
	if (victim->pcdata->bounty_by) {
		DISPOSE(victim->pcdata->bounty_by);
		victim->pcdata->bounty_by = str_dup("");
	}
	victim->pcdata->bounty_by = str_dup(ch->name);
	act(AT_SOCIAL, "$n nods in agreement with you.", bounty, NULL, ch, TO_VICT);
	act(AT_SOCIAL, "$n nods in agreement to $N.", bounty, NULL, ch, TO_NOTVICT);
	sprintf(buf, "&RA bounty worth %s zeni has been placed on the head of %s!", num_punct(amount), victim->name);
	do_info(bounty, buf);
	pager_printf_color(victim, "&RA bounty worth %s zeni has been placed on your head!\n\r", num_punct(amount));
}

void 
do_unbounty(CHAR_DATA * ch, char *argument)
{
	CHAR_DATA *victim;

	if (!(victim = get_char_world(ch, argument))) {
		ch_printf(ch, "&YNo such player online.\n\r");
		return;
	}
	if (victim->pcdata->bounty > 0) {
		ch_printf(ch, "&pRemoving Bounty...\n\rDone.\n\r");
		victim->pcdata->bounty = 0;
		xREMOVE_BIT(victim->act, PLR_BOUNTY);
		DISPOSE(victim->pcdata->bounty_by);
		victim->pcdata->bounty_by = str_dup("");
		return;
	}
	ch_printf(ch, "&YThat player has no bounty.\n\r");

	if (xIS_SET(victim->act, PLR_BOUNTY))
		xREMOVE_BIT(victim->act, PLR_BOUNTY);
	if (victim->pcdata->bounty != 0)
		victim->pcdata->bounty = 0;
	if (victim->pcdata->bounty_by != NULL) {
		DISPOSE(victim->pcdata->bounty_by);
		victim->pcdata->bounty_by = str_dup("");
	}
	return;
}