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