1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <sproto.h> |
26 | #include <sproto.h> |
27 | #include <spells.h> |
27 | #include <spells.h> |
28 | |
28 | |
29 | static partylist *firstparty = NULL; /* Keeps track of first party in list */ |
29 | static partylist *firstparty; |
30 | static partylist *lastparty = NULL; /*Keeps track of last party in list */ |
|
|
31 | |
30 | |
32 | partylist * |
31 | partylist * |
33 | get_firstparty (void) |
32 | get_firstparty () |
34 | { |
33 | { |
35 | return firstparty; |
34 | return firstparty; |
36 | } |
35 | } |
37 | |
36 | |
38 | void remove_party (partylist *target_party); |
37 | static void |
39 | |
|
|
40 | /* Forms the party struct for a party called 'params'. it is the responsibility |
|
|
41 | * of the caller to ensure that the name is unique, and that it is placed in the |
|
|
42 | * main party list correctly */ |
|
|
43 | static partylist * |
|
|
44 | form_party (object *op, const char *params) |
|
|
45 | { |
|
|
46 | partylist *newparty; |
|
|
47 | |
|
|
48 | newparty = (partylist *) malloc (sizeof (partylist)); |
|
|
49 | newparty->partyname = strdup (params); |
|
|
50 | newparty->total_exp = 0; |
|
|
51 | newparty->kills = 0; |
|
|
52 | newparty->passwd[0] = '\0'; |
|
|
53 | newparty->next = NULL; |
|
|
54 | newparty->partyleader = strdup (op->name); |
|
|
55 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have formed party: %s", newparty->partyname); |
|
|
56 | op->contr->party = newparty; |
|
|
57 | |
|
|
58 | return newparty; |
|
|
59 | } |
|
|
60 | |
|
|
61 | void |
|
|
62 | remove_party (partylist *target_party) |
38 | remove_party (partylist *target_party) |
63 | { |
39 | { |
64 | partylist *tmpparty; |
|
|
65 | partylist *previousparty; |
|
|
66 | partylist *nextparty; |
|
|
67 | |
|
|
68 | if (firstparty == NULL) |
40 | if (firstparty == NULL) |
69 | { |
41 | { |
70 | LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); |
42 | LOG (llevError, "remove_party(): I was asked to remove party %s, but no parties are defined", target_party->partyname); |
71 | return; |
43 | return; |
72 | } |
44 | } |
73 | |
45 | |
74 | for_all_players (pl) |
46 | for_all_players (pl) |
75 | if (pl->party == target_party) |
47 | if (pl->party == target_party) |
76 | pl->party = NULL; |
48 | pl->party = NULL; |
77 | |
49 | |
78 | /* special case-ism for parties at the beginning and end of the list */ |
50 | partylist **prevlink = &firstparty; |
79 | if (target_party == firstparty) |
|
|
80 | { |
|
|
81 | firstparty = firstparty->next; |
|
|
82 | |
51 | |
83 | if (target_party->partyleader) |
52 | for (partylist *p = firstparty; p; p = p->next) |
84 | free (target_party->partyleader); |
|
|
85 | |
|
|
86 | if (target_party->partyname) |
|
|
87 | free (target_party->partyname); |
|
|
88 | |
|
|
89 | free (target_party); |
|
|
90 | return; |
|
|
91 | } |
|
|
92 | else if (target_party == lastparty) |
|
|
93 | { |
|
|
94 | for (tmpparty = firstparty; tmpparty->next != NULL; tmpparty = tmpparty->next) |
|
|
95 | { |
|
|
96 | if (tmpparty->next == target_party) |
|
|
97 | { |
|
|
98 | lastparty = tmpparty; |
|
|
99 | |
|
|
100 | if (target_party->partyleader) |
|
|
101 | free (target_party->partyleader); |
|
|
102 | |
|
|
103 | if (target_party->partyname) |
|
|
104 | free (target_party->partyname); |
|
|
105 | |
|
|
106 | free (target_party); |
|
|
107 | lastparty->next = NULL; |
|
|
108 | return; |
|
|
109 | } |
|
|
110 | } |
|
|
111 | } |
|
|
112 | for (tmpparty = firstparty; tmpparty->next != NULL; tmpparty = tmpparty->next) |
|
|
113 | if (tmpparty->next == target_party) |
53 | if (p->next == target_party) |
114 | { |
54 | { |
115 | previousparty = tmpparty; |
55 | prevlink = &p->next; |
116 | nextparty = tmpparty->next->next; |
|
|
117 | /* this should be safe, because we already dealt with the lastparty case */ |
|
|
118 | |
|
|
119 | previousparty->next = nextparty; |
|
|
120 | if (target_party->partyleader) |
|
|
121 | free (target_party->partyleader); |
|
|
122 | if (target_party->partyname) |
|
|
123 | free (target_party->partyname); |
|
|
124 | free (target_party); |
|
|
125 | return; |
56 | break; |
126 | } |
57 | } |
|
|
58 | |
|
|
59 | *prevlink = target_party->next; |
|
|
60 | |
|
|
61 | free (target_party->partyleader); |
|
|
62 | free (target_party->partyname); |
|
|
63 | sfree (target_party); |
127 | } |
64 | } |
128 | |
65 | |
129 | /* Remove unused parties, this could be made to scale a lot better. */ |
66 | /* Remove unused parties, this could be made to scale a lot better. */ |
130 | void |
67 | void |
131 | obsolete_parties (void) |
68 | obsolete_parties () |
132 | { |
69 | { |
133 | int player_count; |
70 | int player_count; |
134 | partylist *party; |
71 | partylist *party; |
135 | partylist *next = NULL; |
72 | partylist *next = NULL; |
136 | |
73 | |
137 | if (!firstparty) |
74 | if (!firstparty) |
138 | return; /* we can't obsolete parties if there aren't any */ |
75 | return; /* we can't obsolete parties if there aren't any */ |
|
|
76 | |
139 | for (party = firstparty; party != NULL; party = next) |
77 | for (party = firstparty; party != NULL; party = next) |
140 | { |
78 | { |
141 | next = party->next; |
79 | next = party->next; |
142 | player_count = 0; |
80 | player_count = 0; |
143 | for_all_players (pl) |
81 | for_all_players (pl) |
… | |
… | |
172 | assign (party->party_kills[pos].dead, dead); |
110 | assign (party->party_kills[pos].dead, dead); |
173 | party->party_kills[pos].killer[MAX_NAME] = 0; |
111 | party->party_kills[pos].killer[MAX_NAME] = 0; |
174 | party->party_kills[pos].dead[MAX_NAME] = 0; |
112 | party->party_kills[pos].dead[MAX_NAME] = 0; |
175 | } |
113 | } |
176 | |
114 | |
177 | int |
115 | static int |
178 | confirm_party_password (object *op) |
116 | confirm_party_password (object *op) |
179 | { |
117 | { |
180 | partylist *tmppartylist; |
118 | partylist *tmppartylist; |
181 | |
119 | |
182 | for (tmppartylist = firstparty; tmppartylist != NULL; tmppartylist = tmppartylist->next) |
120 | for (tmppartylist = firstparty; tmppartylist != NULL; tmppartylist = tmppartylist->next) |
… | |
… | |
188 | else |
126 | else |
189 | return 1; |
127 | return 1; |
190 | } |
128 | } |
191 | } |
129 | } |
192 | return 1; |
130 | return 1; |
|
|
131 | } |
|
|
132 | |
|
|
133 | static void |
|
|
134 | send_party_message (object *op, const char *msg) |
|
|
135 | { |
|
|
136 | for_all_players (pl) |
|
|
137 | if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
|
|
138 | pl->send_msg (NDI_UNIQUE, MSG_CHANNEL ("party"), msg); |
193 | } |
139 | } |
194 | |
140 | |
195 | void |
141 | void |
196 | receive_party_password (object *op, char k) |
142 | receive_party_password (object *op, char k) |
197 | { |
143 | { |
… | |
… | |
216 | op->contr->ns->state = ST_PLAYING; |
162 | op->contr->ns->state = ST_PLAYING; |
217 | return; |
163 | return; |
218 | } |
164 | } |
219 | } |
165 | } |
220 | |
166 | |
221 | void |
|
|
222 | send_party_message (object *op, char *msg) |
|
|
223 | { |
|
|
224 | for_all_players (pl) |
|
|
225 | if (pl->ob->contr->party == op->contr->party && pl->ob != op) |
|
|
226 | new_draw_info (NDI_WHITE, 0, pl->ob, msg); |
|
|
227 | } |
|
|
228 | |
|
|
229 | int |
167 | int |
230 | command_gsay (object *op, char *params) |
168 | command_gsay (object *op, char *params) |
231 | { |
169 | { |
232 | char party_params[MAX_BUF]; |
|
|
233 | |
|
|
234 | if (!params) |
170 | if (!params) |
235 | return 0; |
171 | return 0; |
236 | |
172 | |
237 | strcpy (party_params, "say "); |
|
|
238 | strcat (party_params, params); |
|
|
239 | command_party (op, party_params); |
173 | command_party (op, format ("say %s", params)); |
|
|
174 | |
240 | return 0; |
175 | return 0; |
241 | } |
176 | } |
242 | |
177 | |
243 | int |
178 | int |
244 | command_party (object *op, char *params) |
179 | command_party (object *op, char *params) |
245 | { |
180 | { |
246 | char buf[MAX_BUF]; |
181 | dynbuf_text &buf = msg_dynbuf; buf.clear (); |
247 | partylist *tmpparty, *oldparty; /* For iterating over linked list */ |
|
|
248 | char *currentparty; /* For iterating over linked list */ |
|
|
249 | |
182 | |
250 | if (params == NULL) |
183 | partylist *party = op->contr->party; |
251 | { |
|
|
252 | if (op->contr->party == NULL) |
|
|
253 | { |
|
|
254 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
255 | new_draw_info (NDI_UNIQUE, 0, op, "For help try: party help"); |
|
|
256 | } |
|
|
257 | else |
|
|
258 | { |
|
|
259 | currentparty = op->contr->party->partyname; |
|
|
260 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are a member of party %s.", currentparty); |
|
|
261 | } |
|
|
262 | return 1; |
|
|
263 | } |
|
|
264 | |
184 | |
|
|
185 | if (!params) |
|
|
186 | params = (char *)""; |
|
|
187 | |
265 | if (strcmp (params, "help") == 0) |
188 | if (!strcmp (params, "help")) |
266 | { |
189 | buf << "\n" |
267 | new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>"); |
190 | " - To form a party type: C<party form> <partyname>\n" |
268 | new_draw_info (NDI_UNIQUE, 0, op, "To join a party type: party join <partyname>"); |
191 | " - To join a party type: C<party join> <partyname>\n" |
269 | new_draw_info (NDI_UNIQUE, 0, op, "If the party has a passwd, it will you prompt you for it."); |
192 | " - If the party has a passwd, it will you prompt you for it.\n" |
270 | new_draw_info (NDI_UNIQUE, 0, op, "For a list of current parties type: party list"); |
193 | " - For a list of current parties type: C<party list>\n" |
271 | new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); |
194 | " - To leave a party type: C<party leave>\n" |
272 | new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>"); |
195 | " - To change a passwd for a party type: C<party passwd> <password>\n" |
273 | new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max"); |
196 | " - There is an 8 character max\n" |
274 | new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>"); |
197 | " - To talk to party members type: C<party say> <msg>\n" |
275 | new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who"); |
198 | " - To see who is in your party: C<party who>\n" |
276 | new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); |
199 | " - To see what you've killed, type: C<party kills>\n"; |
277 | return 1; |
|
|
278 | } |
|
|
279 | |
|
|
280 | if (!strncmp (params, "kills", 5)) |
|
|
281 | { |
|
|
282 | int i, max; |
|
|
283 | char chr; |
|
|
284 | char buffer[80]; |
|
|
285 | float exp; |
|
|
286 | |
|
|
287 | if (op->contr->party == NULL) |
|
|
288 | { |
|
|
289 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
290 | return 1; |
|
|
291 | } |
|
|
292 | tmpparty = op->contr->party; |
|
|
293 | if (!tmpparty->kills) |
|
|
294 | { |
|
|
295 | new_draw_info (NDI_UNIQUE, 0, op, "You haven't killed anything yet."); |
|
|
296 | return 1; |
|
|
297 | } |
|
|
298 | max = tmpparty->kills - 1; |
|
|
299 | if (max > PARTY_KILL_LOG - 1) |
|
|
300 | max = PARTY_KILL_LOG - 1; |
|
|
301 | new_draw_info (NDI_UNIQUE, 0, op, "Killed | Killer| Exp"); |
|
|
302 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
|
|
303 | for (i = 0; i <= max; i++) |
|
|
304 | { |
|
|
305 | exp = tmpparty->party_kills[i].exp; |
|
|
306 | chr = ' '; |
|
|
307 | if (exp > 1000000) |
|
|
308 | { |
|
|
309 | exp /= 1000000; |
|
|
310 | chr = 'M'; |
|
|
311 | } |
|
|
312 | else if (exp > 1000) |
|
|
313 | { |
|
|
314 | exp /= 1000; |
|
|
315 | chr = 'k'; |
|
|
316 | } |
|
|
317 | sprintf (buffer, "%16s|%16s|%6.1f%c", tmpparty->party_kills[i].dead, tmpparty->party_kills[i].killer, exp, chr); |
|
|
318 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
|
|
319 | } |
|
|
320 | exp = tmpparty->total_exp; |
|
|
321 | chr = ' '; |
|
|
322 | if (exp > 1000000) |
|
|
323 | { |
|
|
324 | exp /= 1000000; |
|
|
325 | chr = 'M'; |
|
|
326 | } |
|
|
327 | else if (exp > 1000) |
|
|
328 | { |
|
|
329 | exp /= 1000; |
|
|
330 | chr = 'k'; |
|
|
331 | } |
|
|
332 | new_draw_info (NDI_UNIQUE, 0, op, "----------------+----------------+--------"); |
|
|
333 | sprintf (buffer, "Totals: %d kills, %.1f%c exp", tmpparty->kills, exp, chr); |
|
|
334 | new_draw_info (NDI_UNIQUE, 0, op, buffer); |
|
|
335 | return 1; |
|
|
336 | } |
|
|
337 | |
|
|
338 | if (strncmp (params, "say ", 4) == 0) |
|
|
339 | { |
|
|
340 | if (op->contr->party == NULL) |
|
|
341 | { |
|
|
342 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
343 | return 1; |
|
|
344 | } |
|
|
345 | params += 4; |
|
|
346 | currentparty = op->contr->party->partyname; |
|
|
347 | snprintf (buf, MAX_BUF - 1, "[%s] %s says: %s", currentparty, &op->name, params); |
|
|
348 | send_party_message (op, buf); |
|
|
349 | new_draw_info_format (NDI_LT_GREEN | NDI_UNIQUE, 0, op, "[%s] You say: %s", currentparty, params); |
|
|
350 | return 1; |
|
|
351 | } |
|
|
352 | |
|
|
353 | if (strncmp (params, "form ", 5) == 0) |
200 | else if (strncmp (params, "form ", 5) == 0) |
354 | { |
201 | { |
355 | int player_count; |
|
|
356 | |
|
|
357 | params += 5; |
202 | params += 5; |
358 | if (op->contr->party) |
|
|
359 | oldparty = op->contr->party; |
|
|
360 | else |
|
|
361 | oldparty = NULL; |
|
|
362 | |
203 | |
363 | if (firstparty) |
204 | if (party) |
|
|
205 | buf << "You are already a member of party " << party->partyname << ". You must leave it first."; |
|
|
206 | else |
364 | { |
207 | { |
365 | for (tmpparty = firstparty; tmpparty != NULL; tmpparty = tmpparty->next) |
208 | for (partylist *tmpparty = firstparty; tmpparty; tmpparty = tmpparty->next) |
366 | { |
209 | { |
367 | if (!strcmp (tmpparty->partyname, params)) |
210 | if (!strcmp (tmpparty->partyname, params)) |
368 | { |
211 | { |
369 | new_draw_info_format (NDI_UNIQUE, 0, op, "The party %s already exists, pick another name", params); |
212 | buf << "The party " << tmpparty->partyname << " already exists, pick another name"; |
370 | return 1; |
213 | goto reply; |
371 | } |
214 | } |
372 | } |
215 | } |
373 | lastparty->next = form_party (op, params); |
216 | |
374 | lastparty = lastparty->next; |
217 | /* Forms the party struct for a party called 'params'. it is the responsibility |
375 | } |
218 | * of the caller to ensure that the name is unique, and that it is placed in the |
376 | else |
219 | * main party list correctly */ |
377 | { |
220 | |
378 | firstparty = form_party (op, params); |
221 | party = salloc0<partylist> (); |
|
|
222 | party->partyname = strdup (params); |
|
|
223 | party->total_exp = 0; |
|
|
224 | party->kills = 0; |
|
|
225 | party->passwd[0] = '\0'; |
|
|
226 | party->next = NULL; |
|
|
227 | party->partyleader = strdup (op->name); |
|
|
228 | |
|
|
229 | buf << "You have formed party: " << party->partyname << "."; |
|
|
230 | |
379 | lastparty = firstparty; |
231 | party->next = firstparty; |
380 | } |
232 | op->contr->party = firstparty = party; |
381 | /* |
|
|
382 | * The player might have previously been a member of a party, if so, he will be leaving |
|
|
383 | * it, so check if there are any other members and if not, delete the party |
|
|
384 | */ |
|
|
385 | player_count = 0; |
|
|
386 | if (oldparty) |
|
|
387 | { |
|
|
388 | for_all_players (pl) |
|
|
389 | if (pl->party == oldparty) |
|
|
390 | player_count++; |
|
|
391 | |
|
|
392 | if (player_count == 0) |
|
|
393 | remove_party (oldparty); |
|
|
394 | } |
|
|
395 | |
|
|
396 | return 0; |
|
|
397 | } /* form */ |
|
|
398 | |
|
|
399 | if (strcmp (params, "leave") == 0) |
|
|
400 | { |
|
|
401 | if (op->contr->party == NULL) |
|
|
402 | { |
|
|
403 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
404 | return 1; |
|
|
405 | } |
|
|
406 | currentparty = op->contr->party->partyname; |
|
|
407 | new_draw_info_format (NDI_UNIQUE, 0, op, "You leave party %s.", currentparty); |
|
|
408 | sprintf (buf, "%s leaves party %s.", &op->name, currentparty); |
|
|
409 | send_party_message (op, buf); |
|
|
410 | op->contr->party = NULL; |
|
|
411 | return 1; |
|
|
412 | } |
|
|
413 | |
|
|
414 | if (strcmp (params, "who") == 0) |
|
|
415 | { |
|
|
416 | tmpparty = op->contr->party; |
|
|
417 | if (op->contr->party == NULL) |
|
|
418 | { |
|
|
419 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of any party."); |
|
|
420 | return 1; |
|
|
421 | } |
|
|
422 | new_draw_info_format (NDI_UNIQUE, 0, op, "Members of party: %s.", op->contr->party->partyname); |
|
|
423 | for_all_players (pl) |
|
|
424 | if (pl->ob->contr->party == op->contr->party) |
|
|
425 | { |
|
|
426 | if (settings.set_title == TRUE) |
|
|
427 | { |
|
|
428 | if (pl->ob->contr->own_title[0] != '\0') |
|
|
429 | sprintf (buf, "%3d %s the %s", pl->ob->level, &pl->ob->name, pl->ob->contr->own_title); |
|
|
430 | else |
|
|
431 | sprintf (buf, "%3d %s the %s", pl->ob->level, &pl->ob->name, pl->ob->contr->title); |
|
|
432 | } |
|
|
433 | else |
|
|
434 | sprintf (buf, "%3d %s the %s", pl->ob->level, &pl->ob->name, pl->ob->contr->title); |
|
|
435 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
436 | } |
233 | } |
437 | return 1; |
234 | } |
438 | } /* leave */ |
235 | else if (strcmp (params, "list") == 0) |
|
|
236 | { |
|
|
237 | if (!firstparty) |
|
|
238 | buf << "There are no parties active right now"; |
|
|
239 | else |
|
|
240 | { |
|
|
241 | buf << "Party name Leader\n\n" |
|
|
242 | "---------- ------\n\n"; |
439 | |
243 | |
|
|
244 | for (partylist *p = firstparty; p; p = p->next) |
|
|
245 | buf.printf ("%-32s %s\n\n", p->partyname, p->partyleader); |
|
|
246 | } |
|
|
247 | } |
440 | if (strncmp (params, "passwd ", 7) == 0) |
248 | else if (strncmp (params, "join ", 5) == 0) |
441 | { |
249 | { |
442 | partylist *tmplist; |
|
|
443 | |
|
|
444 | params += 7; |
250 | params += 5; |
445 | |
251 | |
446 | if (op->contr->party == NULL) |
252 | /* Can't join a party cause non exist */ |
447 | { |
253 | if (!firstparty) |
448 | new_draw_info (NDI_UNIQUE, 0, op, "You are not a member of a party"); |
254 | buf << "Party: " << params << " does not exist. You must form it first."; |
449 | return 1; |
255 | else if (party) |
450 | } |
256 | buf << "You are already a member of party " << party->partyname << ". You must leave it first."; |
451 | |
257 | else |
452 | if (strlen (params) > 8) |
258 | for (partylist *p = firstparty; p; p = p->next) |
453 | { |
259 | if (!strcmp (p->partyname, params)) |
454 | new_draw_info (NDI_UNIQUE, 0, op, "The password must not exceed 8 characters"); |
|
|
455 | return 1; |
|
|
456 | } |
|
|
457 | |
|
|
458 | tmplist = firstparty; |
|
|
459 | while (tmplist != NULL) |
|
|
460 | { |
|
|
461 | if (tmplist == op->contr->party) |
|
|
462 | { |
260 | { |
463 | strcpy (tmplist->passwd, params); |
261 | if (!*p->passwd) |
464 | new_draw_info_format (NDI_UNIQUE, 0, op, "The password for party %s is %s", tmplist->partyname, tmplist->passwd); |
262 | { |
465 | snprintf (buf, MAX_BUF, "Password for party %s is now %s, changed by %s", tmplist->partyname, tmplist->passwd, &op->name); |
263 | op->contr->party = p; |
|
|
264 | |
|
|
265 | buf << op->name << " joins party " << p->partyname << "."; |
466 | send_party_message (op, buf); |
266 | send_party_message (op, buf); |
467 | return 0; |
267 | buf.clear (); |
|
|
268 | |
|
|
269 | buf << "You have joined party: " << p->partyname << "."; |
468 | } |
270 | } |
469 | tmplist = tmplist->next; |
|
|
470 | } |
|
|
471 | return 0; |
|
|
472 | } /* passwd */ |
|
|
473 | |
|
|
474 | if (strcmp (params, "list") == 0) |
|
|
475 | { |
|
|
476 | partylist *tmplist; |
|
|
477 | |
|
|
478 | tmplist = firstparty; |
|
|
479 | |
|
|
480 | if (firstparty == NULL) |
|
|
481 | { |
|
|
482 | new_draw_info (NDI_UNIQUE, 0, op, "There are no parties active right now"); |
|
|
483 | return 1; |
|
|
484 | } |
|
|
485 | |
|
|
486 | new_draw_info (NDI_UNIQUE, 0, op, "Party name Leader"); |
|
|
487 | new_draw_info (NDI_UNIQUE, 0, op, "---------- ------"); |
|
|
488 | |
|
|
489 | while (tmplist != NULL) |
|
|
490 | { |
|
|
491 | new_draw_info_format (NDI_UNIQUE, 0, op, "%-32s %s", tmplist->partyname, tmplist->partyleader); |
|
|
492 | tmplist = tmplist->next; |
|
|
493 | } |
|
|
494 | return 0; |
|
|
495 | } /* list */ |
|
|
496 | |
|
|
497 | if (strncmp (params, "join ", 5) == 0) |
|
|
498 | { |
|
|
499 | |
|
|
500 | params += 5; |
|
|
501 | |
|
|
502 | /* Can't join a party cause non exist */ |
|
|
503 | if (firstparty == NULL) |
|
|
504 | { |
|
|
505 | new_draw_info_format (NDI_UNIQUE, 0, op, "Party: %s does not exist. You must form it first", params); |
|
|
506 | return 1; |
|
|
507 | } |
|
|
508 | |
|
|
509 | /* Special case if thier is only one party */ |
|
|
510 | if (firstparty->next == NULL) |
|
|
511 | { |
|
|
512 | if (strcmp (firstparty->partyname, params) != 0) |
|
|
513 | { |
271 | else |
514 | new_draw_info_format (NDI_UNIQUE, 0, op, "Party: %s does not exist. You must form it first", params); |
272 | get_party_password (op, p); |
515 | return 1; |
273 | |
|
|
274 | goto reply; |
516 | } |
275 | } |
517 | else |
276 | else |
|
|
277 | buf << "Party " << params << " does not exist. You must form it first."; |
|
|
278 | } |
|
|
279 | else if (!party) |
|
|
280 | buf << "You are not a member of any party.\n\n" |
|
|
281 | "For help try: C<party help>"; |
|
|
282 | else if (!*params) |
|
|
283 | buf << "You are a member of party " << party->partyname << "."; |
|
|
284 | else if (!strncmp (params, "kills", 5)) |
|
|
285 | { |
|
|
286 | if (!party->kills) |
|
|
287 | buf << "You haven't killed anything yet."; |
|
|
288 | else |
|
|
289 | { |
|
|
290 | int max = min (party->kills - 1, PARTY_KILL_LOG - 1); |
|
|
291 | |
|
|
292 | buf << " Killed | Killer| Exp\n" |
|
|
293 | << " ----------------+----------------+--------\n"; |
|
|
294 | |
|
|
295 | for (int i = 0; i <= max; i++) |
518 | { |
296 | { |
519 | if (op->contr->party == firstparty) |
297 | sint64 exp = party->party_kills[i].exp; |
|
|
298 | char suffix = ' '; |
|
|
299 | if (exp > 1000000) |
520 | { |
300 | { |
521 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are already in party: %s", firstparty->partyname); |
301 | exp /= 1000000; |
522 | return 1; |
302 | suffix = 'M'; |
523 | } |
303 | } |
524 | /* found party player wants to join */ |
304 | else if (exp > 1000) |
525 | if (firstparty->passwd[0] == '\0') |
|
|
526 | { |
305 | { |
527 | op->contr->party = firstparty; |
306 | exp /= 1000; |
528 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s", firstparty->partyname); |
307 | suffix = 'k'; |
529 | snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, firstparty->partyname); |
|
|
530 | send_party_message (op, buf); |
|
|
531 | return 0; |
|
|
532 | } |
308 | } |
533 | else |
309 | |
534 | { |
310 | buf.printf (" %16s|%16s|%6.1f%c\n", party->party_kills[i].dead, party->party_kills[i].killer, (double)exp, suffix); |
535 | get_party_password (op, firstparty); |
|
|
536 | return 0; |
|
|
537 | } |
|
|
538 | } |
311 | } |
539 | } |
|
|
540 | |
312 | |
541 | tmpparty = firstparty; |
313 | buf << " ----------------+----------------+--------\n"; |
542 | while (tmpparty != NULL) |
314 | |
543 | { |
|
|
544 | if (strcmp (tmpparty->partyname, params) == 0) |
|
|
545 | { |
315 | { |
546 | if (op->contr->party == tmpparty) |
316 | sint64 exp = party->total_exp; |
|
|
317 | char suffix = ' '; |
|
|
318 | |
|
|
319 | if (exp > 1000000) |
547 | { |
320 | { |
548 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are already a member of party: %s", tmpparty->partyname); |
321 | exp /= 1000000; |
549 | return 1; |
322 | suffix = 'M'; |
550 | } |
323 | } |
551 | else |
324 | else if (exp > 1000) |
552 | { |
325 | { |
553 | if (tmpparty->passwd[0] == '\0') |
326 | exp /= 1000; |
554 | { |
327 | suffix = 'k'; |
555 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have joined party: %s", tmpparty->partyname); |
|
|
556 | op->contr->party = tmpparty; |
|
|
557 | snprintf (buf, MAX_BUF, "%s joins party %s", &op->name, tmpparty->partyname); |
|
|
558 | send_party_message (op, buf); |
|
|
559 | return 0; |
|
|
560 | } |
|
|
561 | else |
|
|
562 | { |
|
|
563 | get_party_password (op, tmpparty); |
|
|
564 | return 0; |
|
|
565 | } |
|
|
566 | } |
328 | } |
|
|
329 | |
|
|
330 | buf.printf (" Totals: %d kills, %.1f%c exp", party->kills, (double)exp, suffix); |
567 | } |
331 | } |
|
|
332 | } |
|
|
333 | } |
|
|
334 | else if (strncmp (params, "say ", 4) == 0) |
|
|
335 | { |
|
|
336 | params += 4; |
|
|
337 | |
|
|
338 | buf << "[" << party->partyname << "] " << op->name << " says: " << params; |
|
|
339 | send_party_message (op, buf); |
|
|
340 | buf.clear (); |
|
|
341 | |
|
|
342 | buf << "[" << party->partyname << "] You say: " << params; |
|
|
343 | } |
|
|
344 | else if (strcmp (params, "leave") == 0) |
|
|
345 | { |
|
|
346 | buf << op->name << " leaves party " << party->partyname << "."; |
|
|
347 | send_party_message (op, buf); |
|
|
348 | buf.clear (); |
|
|
349 | |
|
|
350 | buf << "You leave party " << party->partyname << "."; |
|
|
351 | |
|
|
352 | op->contr->party = 0; |
|
|
353 | obsolete_parties (); |
|
|
354 | } |
|
|
355 | else if (strcmp (params, "who") == 0) |
|
|
356 | { |
|
|
357 | buf << "Members of party " << party->partyname << ".\n"; |
|
|
358 | |
|
|
359 | for_all_players (pl) |
|
|
360 | if (pl->ob->contr->party == party) |
|
|
361 | buf.printf (" - %s/%d %s\n\n", &pl->ob->name, pl->ob->level, |
|
|
362 | *pl->ob->contr->own_title ? pl->ob->contr->own_title : pl->ob->contr->title); |
|
|
363 | } |
|
|
364 | else if (strncmp (params, "passwd ", 7) == 0) |
|
|
365 | { |
|
|
366 | params += 7; |
|
|
367 | |
|
|
368 | if (strlen (params) > 8) |
|
|
369 | buf << "The password must not exceed 8 characters"; |
568 | else |
370 | else |
569 | tmpparty = tmpparty->next; |
|
|
570 | } |
371 | { |
|
|
372 | strcpy (party->passwd, params); |
|
|
373 | buf << "The password for party " << party->partyname << " is set to B<" << params << "> by " << &op->name; |
|
|
374 | } |
|
|
375 | } |
|
|
376 | else |
|
|
377 | buf << "I did not understand your command. For help try: C<party help>"; |
571 | |
378 | |
572 | new_draw_info_format (NDI_UNIQUE, 0, op, "Party %s does not exist. You must form it first.", params); |
379 | reply: |
573 | return 1; |
380 | op->contr->send_msg (NDI_UNIQUE | NDI_REPLY, MSG_CHANNEL ("party"), buf); |
574 | } /* join */ |
|
|
575 | |
381 | |
576 | new_draw_info (NDI_UNIQUE, 0, op, "To form a party type: party form <partyname>"); |
|
|
577 | new_draw_info (NDI_UNIQUE, 0, op, "To join a party type: party join <partyname>"); |
|
|
578 | new_draw_info (NDI_UNIQUE, 0, op, "If the party has a passwd, it will you prompt you for it."); |
|
|
579 | new_draw_info (NDI_UNIQUE, 0, op, "For a list of current parties type: party list"); |
|
|
580 | new_draw_info (NDI_UNIQUE, 0, op, "To leave a party type: party leave"); |
|
|
581 | new_draw_info (NDI_UNIQUE, 0, op, "To change a passwd for a party type: party passwd <password>"); |
|
|
582 | new_draw_info (NDI_UNIQUE, 0, op, "There is an 8 character max"); |
|
|
583 | new_draw_info (NDI_UNIQUE, 0, op, "To talk to party members type: party say <msg>"); |
|
|
584 | new_draw_info (NDI_UNIQUE, 0, op, "To see who is in your party: party who"); |
|
|
585 | new_draw_info (NDI_UNIQUE, 0, op, "To see what you've killed, type: party kills"); |
|
|
586 | return 1; |
382 | return 1; |
587 | } |
383 | } |