/* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the Affero GNU General Public License * and the GNU General Public License along with this program. If not, see * . * * The authors can be reached via e-mail to */ #include #include /* peterm: do_power_crystal object *op, object *crystal This function handles the application of power crystals. Power crystals, when applied, either suck power from the applier, if he's at full spellpoints, or gives him power, if it's got spellpoins stored. */ int apply_power_crystal (object *op, object *crystal) { int available_power = op->stats.sp - op->stats.maxsp; int power_space = crystal->stats.maxsp - crystal->stats.sp; int power_grab; if (available_power >= 0 && power_space > 0) { power_grab = min (power_space, op->stats.sp / 2); op->statusmsg (format ("The %s takes some of your mana.", query_name (crystal))); } else if (available_power < 0 && crystal->stats.sp > 0) { power_grab = -min (-available_power, crystal->stats.sp); op->statusmsg (format ("Mana from the %s is entering your body.", query_name (crystal))); } else { power_grab = 0; op->statusmsg (format ("You touch the %s, but nothing happens.", query_name (crystal))); } op->stats.sp -= power_grab; crystal->stats.sp += power_grab; crystal->set_speed ((float) crystal->stats.sp / (float) crystal->stats.maxsp); if (object *pl = op->visible_to ()) esrv_update_item (UPD_ANIMSPEED, pl, crystal); return 1; }