From 3556885ee1027b79c8151e3fb2aeb5906483d3d3 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 19 Aug 2024 16:03:09 +0200 Subject: Support triggering attacks and play use ability animations For now, PlayerHandler::attack just tries to trigger the "Strike" ability. Adjusted the AbilityDB to the removal of ability categories and the addition of the useaction attribute (mana/manaserv@81f126ae001b1446dc0be37341f133dca5ab2923) --- src/net/manaserv/beinghandler.cpp | 19 ++++++++++++++----- src/net/manaserv/playerhandler.cpp | 29 ++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) (limited to 'src/net') diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index d8f47297..7f16ae19 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -36,6 +36,7 @@ #include "net/manaserv/manaserv_protocol.h" #include "playerrelations.h" +#include "resources/abilitydb.h" #include "resources/emotedb.h" #include "resources/hairdb.h" @@ -281,7 +282,10 @@ void BeingHandler::handleBeingAbilityPointMessage(MessageIn &msg) const int x = msg.readInt16(); const int y = msg.readInt16(); - std::cout << "GPMSG_BEING_ABILITY_POINT(" << abilityId << ", " << x << ", " << y << ")" << std::endl; + being->lookAt(Vector(x, y)); + + if (auto ability = AbilityDB::get(abilityId)) + being->setAction(ability->useAction); } void BeingHandler::handleBeingAbilityBeingMessage(MessageIn &msg) @@ -293,7 +297,11 @@ void BeingHandler::handleBeingAbilityBeingMessage(MessageIn &msg) const int abilityId = msg.readInt8(); const int targetId = msg.readInt16(); - std::cout << "GPMSG_BEING_ABILITY_BEING(" << abilityId << ", " << targetId << ")" << std::endl; + if (Being *target = actorSpriteManager->findBeing(targetId)) + being->lookAt(target->getPosition()); + + if (auto ability = AbilityDB::get(abilityId)) + being->setAction(ability->useAction); } void BeingHandler::handleBeingAbilityDirectionMessage(MessageIn &msg) @@ -305,7 +313,10 @@ void BeingHandler::handleBeingAbilityDirectionMessage(MessageIn &msg) const int abilityId = msg.readInt8(); const int direction = msg.readInt8(); - std::cout << "GPMSG_BEING_ABILITY_DIRECTION(" << abilityId << ", " << direction << ")" << std::endl; + being->setDirection(direction); + + if (auto ability = AbilityDB::get(abilityId)) + being->setAction(ability->useAction); } void BeingHandler::handleBeingsDamageMessage(MessageIn &msg) @@ -315,9 +326,7 @@ void BeingHandler::handleBeingsDamageMessage(MessageIn &msg) Being *being = actorSpriteManager->findBeing(msg.readInt16()); int damage = msg.readInt16(); if (being) - { being->takeDamage(nullptr, damage, Being::HIT); - } } } diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 02712214..8ee9ed80 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -29,17 +29,18 @@ #include "log.h" #include "particle.h" #include "playerinfo.h" -#include "configuration.h" #include "gui/viewport.h" #include "net/net.h" +#include "net/abilityhandler.h" #include "net/manaserv/connection.h" #include "net/manaserv/messagein.h" #include "net/manaserv/messageout.h" #include "net/manaserv/manaserv_protocol.h" +#include "resources/abilitydb.h" #include "resources/attributes.h" /** @@ -50,6 +51,7 @@ const int MAP_TELEPORT_SCROLL_DISTANCE = 256; extern Net::PlayerHandler *playerHandler; +extern Net::AbilityHandler *abilityHandler; namespace ManaServ { @@ -290,14 +292,31 @@ void PlayerHandler::handleMapChangeMessage(MessageIn &msg) void PlayerHandler::attack(int id) { - // MessageOut msg(PGMSG_ATTACK); - // msg.writeInt16(id); - // gameServerConnection->send(msg); + auto ability = AbilityDB::find("Strike"); + if (!ability) + { + logger->log("PlayerHandler::attack: 'Strike' ability not found."); + return; + } + + switch (ability->targetMode) { + case AbilityInfo::TARGET_BEING: + abilityHandler->useOn(ability->id, id); + break; + case AbilityInfo::TARGET_POINT: + logger->log("PlayerHandler::attack: Unsupported target mode 'point' for 'Strike' ability."); + break; + case AbilityInfo::TARGET_DIRECTION: + abilityHandler->useInDirection(ability->id, local_player->getDirection()); + break; + } } void PlayerHandler::emote(int emoteId) { - // TODO + MessageOut msg(PGMSG_BEING_EMOTE); + msg.writeInt8(emoteId); + gameServerConnection->send(msg); } void PlayerHandler::increaseAttribute(int attr) -- cgit v1.2.3-70-g09d2