1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
* Copyright (©) 1992 Frank Tore Johansen |
7 |
* |
8 |
* Deliantra is free software: you can redistribute it and/or modify it under |
9 |
* the terms of the Affero GNU General Public License as published by the |
10 |
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
* option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the Affero GNU General Public License |
19 |
* and the GNU General Public License along with this program. If not, see |
20 |
* <http://www.gnu.org/licenses/>. |
21 |
* |
22 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
*/ |
24 |
|
25 |
#include <global.h> |
26 |
#include <sproto.h> |
27 |
|
28 |
/* Handles misc. input request - things like hash table, malloc, maps, etc */ |
29 |
|
30 |
typedef struct |
31 |
{ |
32 |
char namebuf[MAX_BUF]; |
33 |
int login_order; |
34 |
} chars_names; |
35 |
|
36 |
int |
37 |
command_time (object *op, char *params) |
38 |
{ |
39 |
print_tod (op); |
40 |
return 1; |
41 |
} |
42 |
|
43 |
int |
44 |
command_debug (object *op, char *params) |
45 |
{ |
46 |
int i; |
47 |
char buf[MAX_BUF]; |
48 |
|
49 |
if (params == NULL || !sscanf (params, "%d", &i)) |
50 |
{ |
51 |
sprintf (buf, "Global debug level is %d.", settings.debug); |
52 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
53 |
return 1; |
54 |
} |
55 |
|
56 |
settings.debug = i; |
57 |
|
58 |
sprintf (buf, "Set debug level to %d.", i); |
59 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
60 |
return 1; |
61 |
} |
62 |
|
63 |
/* |
64 |
* Those dumps should be just one dump with good parser |
65 |
*/ |
66 |
|
67 |
int |
68 |
command_dumpbelow (object *op, char *params) |
69 |
{ |
70 |
if (op && op->below) |
71 |
{ |
72 |
char *dump = dump_object (op->below); |
73 |
new_draw_info (NDI_UNIQUE, 0, op, dump); |
74 |
free (dump); |
75 |
/* Let's push that item on the dm's stack */ |
76 |
dm_stack_push (op->contr, op->below->count); |
77 |
} |
78 |
return 0; |
79 |
} |
80 |
|
81 |
int |
82 |
command_version (object *op, char *params) |
83 |
{ |
84 |
version (op); |
85 |
return 0; |
86 |
} |
87 |
|
88 |
/* Prints out some useful information for the character. Everything we print |
89 |
* out can be determined by the docs, so we aren't revealing anything extra - |
90 |
* rather, we are making it convenient to find the values. params have |
91 |
* no meaning here. |
92 |
*/ |
93 |
int |
94 |
command_statistics (object *pl, char *params) |
95 |
{ |
96 |
if (!pl->contr) |
97 |
return 1; |
98 |
|
99 |
dynbuf_text &msg = msg_dynbuf; msg.clear (); |
100 |
|
101 |
msg << " Experience: " << pl->stats.exp << '\n' |
102 |
<< " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n' |
103 |
<< "\n Stat Nat/Real/Max\n"; |
104 |
|
105 |
for (int i = 0; i < NUM_STATS; ++i) |
106 |
msg.printf (" %s %2d/ %3d/%3d\n", short_stat_name [i], pl->contr->orig_stats.stat (i), pl->stats.stat (i), 20 + pl->arch->stats.stat (i)); |
107 |
|
108 |
msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.'; |
109 |
|
110 |
pl->contr->infobox (MSG_CHANNEL ("statistics"), msg); |
111 |
|
112 |
/* Can't think of anything else to print right now */ |
113 |
return 0; |
114 |
} |
115 |
|
116 |
int |
117 |
command_fix_me (object *op, char *params) |
118 |
{ |
119 |
op->update_weight (); |
120 |
op->update_stats (); |
121 |
new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
122 |
|
123 |
return 1; |
124 |
} |
125 |
|
126 |
int |
127 |
command_bowmode (object *op, char *params) |
128 |
{ |
129 |
bowtype_t oldtype = op->contr->bowtype; |
130 |
static const char *const types[] = { |
131 |
"normal", "threewide", "spreadshot", "firenorth", |
132 |
"firene", "fireeast", "firese", "firesouth", |
133 |
"firesw", "firewest", "firenw", "bestarrow" |
134 |
}; |
135 |
char buf[MAX_BUF]; |
136 |
int i, found; |
137 |
|
138 |
if (!params) |
139 |
{ |
140 |
new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]); |
141 |
return 1; |
142 |
} |
143 |
|
144 |
for (i = 0, found = 0; i <= bow_bestarrow; i++) |
145 |
{ |
146 |
if (!strcmp (params, types[i])) |
147 |
{ |
148 |
found++; |
149 |
op->contr->bowtype = (bowtype_t) i; |
150 |
break; |
151 |
} |
152 |
} |
153 |
|
154 |
if (!found) |
155 |
{ |
156 |
sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
157 |
|
158 |
for (i = 0; i <= bow_bestarrow; i++) |
159 |
{ |
160 |
strcat (buf, " "); |
161 |
strcat (buf, types[i]); |
162 |
if (i < bow_nw) |
163 |
strcat (buf, ","); |
164 |
else |
165 |
strcat (buf, "."); |
166 |
} |
167 |
new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
168 |
return 0; |
169 |
} |
170 |
|
171 |
new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
172 |
return 1; |
173 |
} |
174 |
|
175 |
int |
176 |
command_showpets (object *op, char *params) |
177 |
{ |
178 |
int counter = 0, target = 0; |
179 |
int have_shown_pet = 0; |
180 |
|
181 |
dynbuf_text &msg = msg_dynbuf; msg.clear (); |
182 |
|
183 |
if (params) |
184 |
target = atoi (params); |
185 |
|
186 |
for (objectlink *obl = first_friendly_object; obl; obl = obl->next) |
187 |
{ |
188 |
object *ob = obl->ob; |
189 |
|
190 |
if (ob->owner == op) |
191 |
{ |
192 |
if (target == 0) |
193 |
{ |
194 |
if (counter == 0) |
195 |
msg << "T<Pets>\n\n"; |
196 |
|
197 |
msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level); |
198 |
} |
199 |
else if (!have_shown_pet && ++counter == target) |
200 |
{ |
201 |
msg.printf ("T<%s>\n\n" |
202 |
" level %d\n" |
203 |
" %d/%d HP, %d/%d SP\n" |
204 |
" Str %2d\n" |
205 |
" Dex %2d\n" |
206 |
" Con %2d\n" |
207 |
" Int %2d\n" |
208 |
" Wis %2d\n" |
209 |
" Cha %2d\n" |
210 |
" Pow %2d\n" |
211 |
" wc %d damage %d ac %d\n", |
212 |
&ob->name, |
213 |
ob->level, |
214 |
ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp, |
215 |
ob->stats.Str, |
216 |
ob->stats.Dex, |
217 |
ob->stats.Con, |
218 |
ob->stats.Int, |
219 |
ob->stats.Wis, |
220 |
ob->stats.Cha, |
221 |
ob->stats.Pow, |
222 |
ob->stats.wc, ob->stats.dam, ob->stats.ac); |
223 |
|
224 |
have_shown_pet = 1; |
225 |
} |
226 |
} |
227 |
} |
228 |
|
229 |
if (counter == 0) |
230 |
msg << "you have no pets."; |
231 |
else if (target != 0 && have_shown_pet == 0) |
232 |
msg << "no such pet."; |
233 |
|
234 |
op->contr->infobox (MSG_CHANNEL ("pets"), msg); |
235 |
|
236 |
return 0; |
237 |
} |
238 |
|
239 |
int |
240 |
command_resistances (object *op, char *params) |
241 |
{ |
242 |
dynbuf_text &msg = msg_dynbuf; msg.clear (); |
243 |
|
244 |
msg << "Resistances:\n\n"; |
245 |
|
246 |
for (int i = 0; i < NROFATTACKS; i++) |
247 |
if (i != ATNR_INTERNAL) |
248 |
msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]); |
249 |
|
250 |
/* If dragon player, let's display natural resistances */ |
251 |
if (op->is_dragon ()) |
252 |
for (object *tmp = op->inv; tmp; tmp = tmp->below) |
253 |
if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force) |
254 |
{ |
255 |
msg << "\nOf those, these are natural skin resistances:\n\n"; |
256 |
|
257 |
for (int attack = 0; attack < NROFATTACKS; attack++) |
258 |
if (atnr_is_dragon_enabled (attack)) |
259 |
msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]); |
260 |
|
261 |
break; |
262 |
} |
263 |
|
264 |
op->contr->infobox (MSG_CHANNEL ("resistances"), msg); |
265 |
|
266 |
return 0; |
267 |
} |
268 |
|
269 |
int |
270 |
command_title (object *op, char *params) |
271 |
{ |
272 |
char buf[MAX_BUF]; |
273 |
|
274 |
if (settings.set_title == FALSE) |
275 |
{ |
276 |
new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title."); |
277 |
return 1; |
278 |
} |
279 |
|
280 |
/* dragon players cannot change titles */ |
281 |
if (op->is_dragon ()) |
282 |
{ |
283 |
new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles."); |
284 |
return 1; |
285 |
} |
286 |
|
287 |
if (params == NULL) |
288 |
{ |
289 |
if (op->contr->own_title[0] == '\0') |
290 |
sprintf (buf, "Your title is '%s'.", op->contr->title); |
291 |
else |
292 |
sprintf (buf, "Your title is '%s'.", op->contr->own_title); |
293 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
294 |
return 1; |
295 |
} |
296 |
if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0) |
297 |
{ |
298 |
if (op->contr->own_title[0] == '\0') |
299 |
new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title."); |
300 |
else |
301 |
new_draw_info (NDI_UNIQUE, 0, op, "Title set to default."); |
302 |
op->contr->own_title[0] = '\0'; |
303 |
return 1; |
304 |
} |
305 |
|
306 |
if ((int) strlen (params) >= MAX_NAME) |
307 |
{ |
308 |
new_draw_info (NDI_UNIQUE, 0, op, "Title too long."); |
309 |
return 1; |
310 |
} |
311 |
strcpy (op->contr->own_title, params); |
312 |
return 1; |
313 |
} |
314 |
|
315 |
int |
316 |
command_kill_pets (object *op, char *params) |
317 |
{ |
318 |
objectlink *obl, *next; |
319 |
int counter = 0, removecount = 0; |
320 |
|
321 |
if (!params) |
322 |
{ |
323 |
terminate_all_pets (op); |
324 |
new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
325 |
} |
326 |
else |
327 |
{ |
328 |
int target = atoi (params); |
329 |
|
330 |
for (obl = first_friendly_object; obl; obl = next) |
331 |
{ |
332 |
object *ob = obl->ob; |
333 |
|
334 |
next = obl->next; |
335 |
|
336 |
if (ob->owner == op) |
337 |
if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
338 |
{ |
339 |
ob->destroy (); |
340 |
removecount++; |
341 |
} |
342 |
} |
343 |
|
344 |
if (removecount != 0) |
345 |
new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
346 |
else |
347 |
new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
348 |
} |
349 |
|
350 |
return 0; |
351 |
} |