1/*
2 *
3 *  Copyright (C) 2006  The Exult Team
4 *
5 *  This program is free software; you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation; either version 2 of the License, or
8 *  (at your option) any later version.
9 *
10 *  This program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with this program; if not, write to the Free Software
17 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 *
20 *	This source file contains some reimplementations of almost all
21 *	eighth circle spells. The exception is 'Armaggedon'.
22 *
23 *	Author: Marzo Junior
24 *	Last Modified: 2006-02-27
25 */
26
27/*
28	Eighth circle Spells
29
30	extern void spellDeathVortex (var target);
31	extern void spellInvisibilityAll ();
32	extern void spellMassDeath ();
33	extern void spellResurrect (var target);
34	extern void spellSummon ();
35	extern void spellSwordStrike (var target);
36	extern void spellTimeStop ();
37	extern void spellMassResurrect ();
38*/
39
40enum eighth_circle_spells
41{
42	SPELL_DEATH_VORTEX				= 0,
43	SPELL_INVISIBILITY_ALL			= 1,
44	SPELL_MASS_DEATH				= 2,
45	SPELL_RESURRECT					= 3,
46	SPELL_SUMMON					= 4,
47	SPELL_SWORDSTRIKE				= 5,
48	SPELL_TIME_STOP					= 6,			//NPC-only spell
49	SPELL_MASS_RESURRECT			= 7			//Special NPC-only spell
50};
51
52void spellDeathVortex (var target)
53{
54	if (event == DOUBLECLICK)
55	{
56		//var target = UI_click_on_item();
57		var dir = direction_from(target);
58		halt_scheduled();
59		item_say("@Vas Corp Hur@");
60		if (inMagicStorm())
61		{
62			set_to_attack(target, SHAPE_DEATH_VORTEX);
63			script item
64			{	nohalt;						face dir;
65				sfx 65;						actor frame cast_up;
66				actor frame strike_1h;		attack;}
67		}
68		else
69		{
70			script item
71			{	nohalt;						face dir;
72				actor frame cast_up;			actor frame strike_1h;
73				call spellFails;}
74		}
75	}
76}
77
78void spellInvisibilityAll ()
79{
80	if (event == DOUBLECLICK)
81	{
82		halt_scheduled();
83		item_say("@Vas Sact Lor@");
84		if (inMagicStorm())
85		{
86			var pos = get_object_position();
87			UI_sprite_effect(7, (pos[X] - 2), (pos[Y] - 2), 0, 0, 0, -1);
88			script item
89			{	nohalt;						actor frame raise_1h;
90				sfx 67;						actor frame standing;
91				actor frame cast_up;			actor frame standing;
92				actor frame strike_2h;}
93			var targets = getFriendlyTargetList(item, 25);
94			for (npc in targets)
95			{
96				var delay = ((get_distance(npc) / 3) + 5);
97				script npc after delay ticks
98				{	nohalt;			call spellSetFlag, INVISIBLE;}
99			}
100		}
101		else
102		{
103			script item
104			{	nohalt;						actor frame raise_1h;
105				actor frame standing;			actor frame cast_up;
106				actor frame standing;			actor frame strike_2h;
107				call spellFails;}
108		}
109	}
110}
111
112void spellMassDeath ()
113{
114	if (event == DOUBLECLICK)
115	{
116		halt_scheduled();
117		item_say("@Vas Corp@");
118		if (inMagicStorm())
119		{
120			var pos = get_object_position();
121			UI_sprite_effect(7, (pos[X] - 2), (pos[Y] - 2), 0, 0, 0, -1);
122			script item
123			{	nohalt;						sfx 65;
124				actor frame kneeling;			actor frame standing;
125				actor frame cast_up;			actor frame cast_out;
126				sfx 67;}
127			var nearby_npcs = find_nearby(-1, 25, MASK_NPC);
128			var safenpcs = [UI_get_party_list2(), LORD_BRITISH->get_npc_object(),
129							BATLIN->get_npc_object()];
130			var killed_anyone = false;
131			for (npc in nearby_npcs)
132			{
133				if (!(npc in safenpcs))
134				{
135					var delay = ((get_distance(npc) / 3) + 5);
136					npc->halt_scheduled();
137					script npc after delay ticks
138					{	nohalt;					call spellCauseDeath;}
139					killed_anyone = true;
140				}
141			}
142
143			if (killed_anyone == true)
144			{
145				var party = UI_get_party_list();
146				for (npc in party)
147				{
148					var hps = npc->get_npc_prop(HEALTH);
149					hurtNPC(npc, (hps - 2));
150				}
151			}
152		}
153		else
154		{
155			script item
156			{	nohalt;						actor frame kneeling;
157				actor frame standing;			actor frame cast_up;
158				actor frame cast_out;			call spellFails;}
159		}
160	}
161}
162
163void spellResurrect (var target)
164{
165	if (event == DOUBLECLICK)
166	{
167		//var target = UI_click_on_item();
168		var target_shape = target->get_item_shape();
169		var pos = target->get_object_position();
170		var dir = direction_from(target);
171		target->halt_scheduled();
172		halt_scheduled();
173		var canresurrect = false;
174		if (target->get_item_shape() in [SHAPE_BODIES_1, SHAPE_BODIES_2, SHAPE_LARGE_BODIES, SHAPE_NEW_BODIES])
175		{
176			var target_quality = target->get_item_quality();
177			var quant = target->get_item_quantity(target_shape);
178			if ((target_quality == 0) && (quant == 0))
179				canresurrect = false;
180
181			else
182				canresurrect = target->resurrect();
183		}
184		else
185			canresurrect = false;
186
187		item_say("@In Mani Corp@");
188		if (inMagicStorm() && canresurrect)
189		{
190			script item
191			{	nohalt;						face dir;
192				sfx 64;						actor frame kneeling;
193				actor frame standing;			actor frame cast_up;}
194			UI_play_music(15, 0);
195			UI_sprite_effect(17, pos[X], pos[Y], 0, 0, 0, -1);
196			UI_sprite_effect(13, (pos[X] - 2), (pos[Y] - 2), 0, 0, 0, -1);
197		}
198		else
199		{
200			script item
201			{	nohalt;						face dir;
202				actor frame kneeling;			actor frame standing;
203				actor frame cast_up;			call spellFails;}
204		}
205	}
206}
207
208void spellSummon ()
209{
210	if (event == DOUBLECLICK)
211	{
212		halt_scheduled();
213		item_say("@Kal Vas Xen@");
214		if (inMagicStorm())
215		{
216			script item
217			{	nohalt;						actor frame kneeling;
218				actor frame standing;			actor frame cast_up;
219				actor frame cast_out;			actor frame strike_2h;
220				sfx 65;						call spellSummonEffect;}
221		}
222		else
223		{
224			script item
225			{	nohalt;						actor frame kneeling;
226				actor frame standing;			actor frame cast_up;
227				actor frame cast_out;			actor frame strike_2h;
228				call spellFails;}
229		}
230	}
231}
232
233void spellSwordStrike (var target)
234{
235	if ((event == DOUBLECLICK) || (event == WEAPON))
236	{
237		//var target = UI_click_on_item();
238		halt_scheduled();
239		var dir = direction_from(target);
240		item_say("@In Jux Por Ylem@");
241		if (inMagicStorm())
242		{
243			set_to_attack(target, SHAPE_SWORDSTRIKE);
244			script item
245			{	nohalt;						face dir;
246				sfx 65;						actor frame raise_1h;
247				actor frame standing;			actor frame cast_up;
248				actor frame standing;			actor frame strike_1h;
249				actor frame strike_2h;		attack;
250				actor frame standing;}
251		}
252		else
253		{
254			script item
255			{	nohalt;						face dir;
256				actor frame raise_1h;		actor frame standing;
257				actor frame cast_up;			actor frame standing;
258				actor frame strike_2h;		call spellFails;}
259		}
260	}
261}
262
263void spellTimeStop ()
264{
265	if (event == DOUBLECLICK)
266	{
267		halt_scheduled();
268		item_say("@An Tym@");
269		if (inMagicStorm())
270		{
271			script item
272			{	nohalt;						sfx 67;
273				actor frame strike_2h;		actor frame cast_out;
274				call spellStopTime, 100;}
275		}
276		else
277		{
278			script item
279			{	nohalt;						actor frame strike_2h;
280				actor frame cast_out;			call spellFails;}
281		}
282	}
283}
284
285void spellMassResurrect ()
286{
287	var bodyshapes = [SHAPE_BODIES_1, SHAPE_BODIES_2, SHAPE_LARGE_BODIES, SHAPE_NEW_BODIES];
288	var bodies = [];
289	for (shnum in bodyshapes)
290		bodies = [bodies, find_nearby(shnum, 25, MASK_NONE)];
291
292	if (event == DOUBLECLICK)
293	{
294		item_say("@Vas Mani Corp Hur@");
295
296		var have_resurrectables = false;
297		for (body in bodies)
298		{
299			var qual = body->get_item_quality();
300			var quant = body->get_item_quantity(1);
301			if ((qual != 0) || (quant != 0))
302			{
303				have_resurrectables = true;
304				break;
305			}
306		}
307
308		if (inMagicStorm() && have_resurrectables)
309		{
310			script item
311			{	nohalt;						sfx 64;
312				actor frame kneeling;			actor frame standing;
313				actor frame cast_up;			call spellMassResurrectEffect;}
314			UI_play_music(15, 0);
315		}
316		else
317		{
318			script item
319			{	nohalt;						actor frame kneeling;
320				actor frame standing;			actor frame cast_up;
321				call spellFails;}
322		}
323	}
324}
325