1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
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 |
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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
29 | #include <global.h> |
29 | #include <global.h> |
30 | #include <sproto.h> |
30 | #include <sproto.h> |
31 | #include <spells.h> |
31 | #include <spells.h> |
32 | #include <skills.h> |
32 | #include <skills.h> |
33 | #include <commands.h> |
33 | #include <commands.h> |
34 | |
|
|
35 | int |
|
|
36 | command_invoke (object *op, char *params) |
|
|
37 | { |
|
|
38 | return command_cast_spell (op, params, 'i'); |
|
|
39 | } |
|
|
40 | |
|
|
41 | int |
|
|
42 | command_cast (object *op, char *params) |
|
|
43 | { |
|
|
44 | return command_cast_spell (op, params, 'c'); |
|
|
45 | } |
|
|
46 | |
|
|
47 | int |
|
|
48 | command_prepare (object *op, char *params) |
|
|
49 | { |
|
|
50 | return command_cast_spell (op, params, 'p'); |
|
|
51 | } |
|
|
52 | |
34 | |
53 | /* Shows all spells that op knows. If params is supplied, the must match |
35 | /* Shows all spells that op knows. If params is supplied, the must match |
54 | * that. Given there is more than one skill, we can't supply break |
36 | * that. Given there is more than one skill, we can't supply break |
55 | * them down to cleric/wizardry. |
37 | * them down to cleric/wizardry. |
56 | */ |
38 | */ |
… | |
… | |
126 | /* sets up to cast a spell. op is the caster, params is the spell name, |
108 | /* sets up to cast a spell. op is the caster, params is the spell name, |
127 | * and command is the first letter of the spell type (c=cast, i=invoke, |
109 | * and command is the first letter of the spell type (c=cast, i=invoke, |
128 | * p=prepare). Invoke casts a spell immediately, where as cast (and I believe |
110 | * p=prepare). Invoke casts a spell immediately, where as cast (and I believe |
129 | * prepare) just set up the range type. |
111 | * prepare) just set up the range type. |
130 | */ |
112 | */ |
131 | int |
113 | static int |
132 | command_cast_spell (object *op, char *params, char command) |
114 | command_cast_spell (object *op, char *params, char command) |
133 | { |
115 | { |
134 | int castnow = 0; |
116 | int castnow = 0; |
135 | char *cp; |
117 | char *cp; |
136 | object *spob; |
118 | object *spob; |
… | |
… | |
184 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is a weird spell, please report it to the dungeon master!", &spob->name); |
166 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is a weird spell, please report it to the dungeon master!", &spob->name); |
185 | LOG (llevError, "spell without skill found: %s", spob->debug_desc ()); |
167 | LOG (llevError, "spell without skill found: %s", spob->debug_desc ()); |
186 | return 1; |
168 | return 1; |
187 | } |
169 | } |
188 | |
170 | |
189 | object *skill = find_skill_by_name (op, spob->skill); |
|
|
190 | |
|
|
191 | if (!skill) |
|
|
192 | { |
|
|
193 | op->failmsg (format ("You need the skill %s to cast %s!", &spob->skill, &spob->name)); |
|
|
194 | return 1; |
|
|
195 | } |
|
|
196 | |
|
|
197 | splay (spob); |
|
|
198 | |
|
|
199 | if (castnow) |
171 | if (castnow) |
200 | cast_spell (op, op, op->facing, spob, cp); |
172 | cast_spell (op, op, op->facing, spob, cp); |
201 | else |
173 | else if (op->apply (spob)) |
202 | { |
|
|
203 | if (op->contr->ranged_ob) |
|
|
204 | if (op->contr->ranged_ob->flag [FLAG_APPLIED]) |
|
|
205 | apply_special (op, op->contr->ranged_ob, AP_UNAPPLY); |
|
|
206 | else |
|
|
207 | op->contr->ranged_ob = 0; |
|
|
208 | |
|
|
209 | if (op->contr->ranged_ob) |
|
|
210 | op->failmsg (format ("You have to unapply the %s first to ready a spell.", &op->contr->ranged_ob->name)); |
|
|
211 | else |
|
|
212 | { |
174 | { |
213 | op->change_weapon (op->contr->ranged_ob = spob); |
175 | splay (spob); |
214 | |
|
|
215 | assign (op->contr->spellparam, cp ? cp : ""); |
176 | assign (op->contr->spellparam, cp ? cp : ""); |
216 | op->statusmsg (format ("You ready the spell %s", &spob->name)); |
|
|
217 | } |
|
|
218 | } |
177 | } |
219 | |
178 | |
220 | return 0; |
179 | return 0; |
221 | } /* else fall through to below and print spells */ |
180 | } /* else fall through to below and print spells */ |
222 | } /* params supplied */ |
181 | } /* params supplied */ |
… | |
… | |
228 | show_matching_spells (op, params); |
187 | show_matching_spells (op, params); |
229 | |
188 | |
230 | return 1; |
189 | return 1; |
231 | } |
190 | } |
232 | |
191 | |
|
|
192 | int |
|
|
193 | command_invoke (object *op, char *params) |
|
|
194 | { |
|
|
195 | return command_cast_spell (op, params, 'i'); |
|
|
196 | } |
|
|
197 | |
|
|
198 | int |
|
|
199 | command_cast (object *op, char *params) |
|
|
200 | { |
|
|
201 | return command_cast_spell (op, params, 'c'); |
|
|
202 | } |
|
|
203 | |
|
|
204 | int |
|
|
205 | command_prepare (object *op, char *params) |
|
|
206 | { |
|
|
207 | return command_cast_spell (op, params, 'p'); |
|
|
208 | } |
|
|
209 | |
233 | /**************************************************************************/ |
210 | /**************************************************************************/ |
234 | |
211 | |
235 | void |
212 | static void |
236 | change_spell (object *op, char k) |
213 | change_spell (object *op, char k) |
237 | { |
214 | { |
238 | if (op->contr->combat_ob == op->current_weapon) |
215 | if (op->contr->combat_ob && op->contr->ranged_ob) |
239 | { |
216 | op->change_weapon ( |
|
|
217 | op->current_weapon == op->contr->combat_ob |
240 | if (op->contr->ranged_ob) |
218 | ? op->contr->ranged_ob |
241 | op->change_weapon (op->contr->ranged_ob); |
|
|
242 | } |
|
|
243 | else if (op->contr->ranged_ob == op->current_weapon) |
|
|
244 | { |
|
|
245 | if (op->contr->combat_ob) |
219 | : op->contr->combat_ob |
246 | op->change_weapon (op->contr->combat_ob); |
220 | ); |
247 | } |
|
|
248 | |
221 | |
249 | //TODO: maybe switch to golem, if any? |
222 | //TODO: maybe switch to golem, if any? |
250 | } |
223 | } |
251 | |
224 | |
252 | int |
225 | int |