1 |
root |
1.6 |
/* |
2 |
root |
1.8 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
root |
1.21 |
* |
4 |
root |
1.22 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.15 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
7 |
root |
1.21 |
* |
8 |
root |
1.11 |
* 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 |
root |
1.21 |
* |
13 |
root |
1.7 |
* 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 |
root |
1.21 |
* |
18 |
root |
1.11 |
* 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 |
root |
1.21 |
* |
22 |
root |
1.8 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
root |
1.6 |
*/ |
24 |
|
|
|
25 |
elmex |
1.1 |
#include <global.h> |
26 |
root |
1.4 |
#include <sproto.h> |
27 |
elmex |
1.1 |
|
28 |
|
|
/* peterm: do_power_crystal |
29 |
|
|
|
30 |
|
|
object *op, object *crystal |
31 |
|
|
|
32 |
|
|
This function handles the application of power crystals. |
33 |
|
|
Power crystals, when applied, either suck power from the applier, |
34 |
|
|
if he's at full spellpoints, or gives him power, if it's got |
35 |
|
|
spellpoins stored. |
36 |
|
|
|
37 |
|
|
*/ |
38 |
root |
1.2 |
int |
39 |
|
|
apply_power_crystal (object *op, object *crystal) |
40 |
|
|
{ |
41 |
root |
1.17 |
int available_power = op->stats.sp - op->stats.maxsp; |
42 |
|
|
int power_space = crystal->stats.maxsp - crystal->stats.sp; |
43 |
elmex |
1.1 |
int power_grab; |
44 |
|
|
|
45 |
root |
1.2 |
if (available_power >= 0 && power_space > 0) |
46 |
root |
1.17 |
{ |
47 |
root |
1.19 |
power_grab = min (power_space, op->stats.sp / 2); |
48 |
root |
1.17 |
op->statusmsg (format ("The %s takes some of your mana.", query_name (crystal))); |
49 |
|
|
} |
50 |
|
|
else if (available_power < 0 && crystal->stats.sp > 0) |
51 |
|
|
{ |
52 |
|
|
power_grab = -min (-available_power, crystal->stats.sp); |
53 |
|
|
op->statusmsg (format ("Mana from the %s is entering your body.", query_name (crystal))); |
54 |
|
|
} |
55 |
|
|
else |
56 |
|
|
{ |
57 |
|
|
power_grab = 0; |
58 |
|
|
op->statusmsg (format ("You touch the %s, but nothing happens.", query_name (crystal))); |
59 |
|
|
} |
60 |
root |
1.2 |
|
61 |
|
|
op->stats.sp -= power_grab; |
62 |
|
|
crystal->stats.sp += power_grab; |
63 |
root |
1.4 |
crystal->set_speed ((float) crystal->stats.sp / (float) crystal->stats.maxsp); |
64 |
root |
1.9 |
|
65 |
|
|
if (object *pl = op->visible_to ()) |
66 |
|
|
esrv_update_item (UPD_ANIMSPEED, pl, crystal); |
67 |
elmex |
1.1 |
|
68 |
|
|
return 1; |
69 |
|
|
} |