summaryrefslogtreecommitdiff
path: root/src/game-server/gamehandler.cpp
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2012-04-03 13:29:05 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2012-04-04 16:22:11 +0200
commitf8e816d9185c09d1c17d921b775e483d132982e5 (patch)
tree3ab299ab6057db3bfd8feb24130a6fcb7e64a60d /src/game-server/gamehandler.cpp
parente4baa92aae537921dd17873328a95ab17afcfdfc (diff)
downloadmanaserv-f8e816d9185c09d1c17d921b775e483d132982e5.tar.gz
manaserv-f8e816d9185c09d1c17d921b775e483d132982e5.tar.bz2
manaserv-f8e816d9185c09d1c17d921b775e483d132982e5.tar.xz
manaserv-f8e816d9185c09d1c17d921b775e483d132982e5.zip
Enhanced special support
- Made the current charge being saved. - Added script binds: - chr_set_special_recharge_speed - chr_get_special_recharge_speed - chr_set_special_mana - chr_get_special_mana - get_special_info - Added special info lua class. Functions: - name - needed_mana - rechargeable - on_use - on_recharged - category Further the engine no longer sets charge to 0 after using of specials this allows more flexbilillity (like failing specials). Changes on the xml database: - recharge renamed to rechargeable (needed by client and server) - needed - the needed mana to trigger a special (server only) - rechargespeed - the defailt recharge speed in mana per tick (server only) - target - the type of target (either being or point) (server and client) I also made the lua engine pushing nil instead of a 0 light userdata when the pointer was 0. Database update needed. Change is tested. Mana-Mantis: #167, #156 Reviewed-by: bjorn.
Diffstat (limited to 'src/game-server/gamehandler.cpp')
-rw-r--r--src/game-server/gamehandler.cpp48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index be8e2455..b65d64ad 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -147,6 +147,22 @@ static Actor *findActorNear(Actor *p, int id)
return 0;
}
+static Being *findBeingNear(Actor *p, int id)
+{
+ MapComposite *map = p->getMap();
+ const Point &ppos = p->getPosition();
+ // See map.h for tiles constants
+ const int pixelDist = DEFAULT_TILE_LENGTH * TILES_TO_BE_NEAR;
+ for (BeingIterator i(map->getAroundPointIterator(ppos, pixelDist)); i; ++i)
+ {
+ Being *b = *i;
+ if (b->getPublicID() != id)
+ continue;
+ return ppos.inRangeOf(b->getPosition(), pixelDist) ? b : 0;
+ }
+ return 0;
+}
+
static Character *findCharacterNear(Actor *p, int id)
{
MapComposite *map = p->getMap();
@@ -229,8 +245,12 @@ void GameHandler::processMessage(NetComputer *computer, MessageIn &message)
handleAttack(client, message);
break;
- case PGMSG_USE_SPECIAL:
- handleUseSpecial(client, message);
+ case PGMSG_USE_SPECIAL_ON_BEING:
+ handleUseSpecialOnBeing(client, message);
+ break;
+
+ case PGMSG_USE_SPECIAL_ON_POINT:
+ handleUseSpecialOnPoint(client, message);
break;
case PGMSG_ACTION_CHANGE:
@@ -615,21 +635,35 @@ void GameHandler::handleAttack(GameClient &client, MessageIn &message)
LOG_DEBUG("Character " << client.character->getPublicID()
<< " attacked being " << id);
- Actor *o = findActorNear(client.character, id);
- if (o && o->getType() != OBJECT_NPC)
+ Being *being = findBeingNear(client.character, id);
+ if (being && being->getType() != OBJECT_NPC)
{
- Being *being = static_cast<Being*>(o);
client.character->setTarget(being);
client.character->setAction(ATTACK);
}
}
-void GameHandler::handleUseSpecial(GameClient &client, MessageIn &message)
+void GameHandler::handleUseSpecialOnBeing(GameClient &client, MessageIn &message)
{
const int specialID = message.readInt8();
+ const int targetID = message.readInt16(); // 0 when no target is selected
+ Being *being = 0;
+ if (targetID != 0)
+ being = findBeingNear(client.character, targetID);
+ LOG_DEBUG("Character " << client.character->getPublicID()
+ << " tries to use his special attack " << specialID);
+ client.character->useSpecialOnBeing(specialID, being);
+}
+
+void GameHandler::handleUseSpecialOnPoint(GameClient &client, MessageIn &message)
+{
+ const int specialID = message.readInt8();
+ const int x = message.readInt16();
+ const int y = message.readInt16();
+
LOG_DEBUG("Character " << client.character->getPublicID()
<< " tries to use his special attack " << specialID);
- client.character->useSpecial(specialID);
+ client.character->useSpecialOnPoint(specialID, x, y);
}
void GameHandler::handleActionChange(GameClient &client, MessageIn &message)