summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-09-08 19:14:33 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-09-08 19:18:08 +0200
commit05fc955a3f8a03539088fa7569395434e29d90e8 (patch)
tree48a35f8f3bc68651bbe82cb15cc8488746334e64 /src
parentf1b7570131c328fcf549835a435ea6bfb4721721 (diff)
downloadmanaserv-05fc955a3f8a03539088fa7569395434e29d90e8.tar.gz
manaserv-05fc955a3f8a03539088fa7569395434e29d90e8.tar.bz2
manaserv-05fc955a3f8a03539088fa7569395434e29d90e8.tar.xz
manaserv-05fc955a3f8a03539088fa7569395434e29d90e8.zip
Added support for direction based ability targets
I had to rearrange the protocol a bit in order to allow to keep the related things together.
Diffstat (limited to 'src')
-rw-r--r--src/common/manaserv_protocol.h67
-rw-r--r--src/game-server/abilitycomponent.cpp29
-rw-r--r--src/game-server/abilitycomponent.h7
-rw-r--r--src/game-server/abilitymanager.cpp2
-rw-r--r--src/game-server/abilitymanager.h3
-rw-r--r--src/game-server/actor.h3
-rw-r--r--src/game-server/gamehandler.cpp22
-rw-r--r--src/game-server/gamehandler.h2
8 files changed, 99 insertions, 36 deletions
diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h
index 1d5c7e56..312fdb59 100644
--- a/src/common/manaserv_protocol.h
+++ b/src/common/manaserv_protocol.h
@@ -29,7 +29,7 @@
namespace ManaServ {
enum {
- PROTOCOL_VERSION = 6,
+ PROTOCOL_VERSION = 7,
SUPPORTED_DB_VERSION = 25
};
@@ -145,23 +145,24 @@ enum {
GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }*
GPMSG_BEING_ABILITY_POINT = 0x0282, // W being id, B abilityId, W*2 point
GPMSG_BEING_ABILITY_BEING = 0x0283, // W being id, B abilityId, W target being id
- PGMSG_USE_ABILITY_ON_BEING = 0x0292, // B abilityID, W being id
- GPMSG_ABILITY_STATUS = 0x0293, // { B abilityID, D remainingTicks }
- PGMSG_USE_ABILITY_ON_POINT = 0x0294, // B abilityID, W*2 position
- GPMSG_ABILITY_REMOVED = 0x0295, // B abilityID
- GPMSG_ABILITY_COOLDOWN = 0x0296, // W ticks to wait
- PGMSG_SAY = 0x02A0, // S text
- GPMSG_SAY = 0x02A1, // W being id, S text
- GPMSG_NPC_CHOICE = 0x02B0, // W being id, { S text }*
- GPMSG_NPC_MESSAGE = 0x02B1, // W being id, B* text
- PGMSG_NPC_TALK = 0x02B2, // W being id
- PGMSG_NPC_TALK_NEXT = 0x02B3, // W being id
- PGMSG_NPC_SELECT = 0x02B4, // W being id, B choice
- GPMSG_NPC_BUY = 0x02B5, // W being id, { W item id, W amount, W cost }*
- GPMSG_NPC_SELL = 0x02B6, // W being id, { W item id, W amount, W cost }*
- PGMSG_NPC_BUYSELL = 0x02B7, // W item id, W amount
- GPMSG_NPC_ERROR = 0x02B8, // B error
- GPMSG_NPC_CLOSE = 0x02B9, // W being id
+ PGMSG_USE_ABILITY_ON_BEING = 0x0290, // B abilityID, W being id
+ PGMSG_USE_ABILITY_ON_POINT = 0x0291, // B abilityID, W*2 position
+ PGMSG_USE_ABILITY_ON_DIRECTION = 0x0292, // B abilityID, B direction
+ GPMSG_ABILITY_STATUS = 0x02A0, // { B abilityID, D remainingTicks }
+ GPMSG_ABILITY_REMOVED = 0x02A1, // B abilityID
+ GPMSG_ABILITY_COOLDOWN = 0x02A2, // W ticks to wait
+ PGMSG_SAY = 0x02B0, // S text
+ GPMSG_SAY = 0x02B1, // W being id, S text
+ GPMSG_NPC_CHOICE = 0x02C0, // W being id, { S text }*
+ GPMSG_NPC_MESSAGE = 0x02C1, // W being id, B* text
+ PGMSG_NPC_TALK = 0x02C2, // W being id
+ PGMSG_NPC_TALK_NEXT = 0x02C3, // W being id
+ PGMSG_NPC_SELECT = 0x02C4, // W being id, B choice
+ GPMSG_NPC_BUY = 0x02C5, // W being id, { W item id, W amount, W cost }*
+ GPMSG_NPC_SELL = 0x02C6, // W being id, { W item id, W amount, W cost }*
+ PGMSG_NPC_BUYSELL = 0x02C7, // W item id, W amount
+ GPMSG_NPC_ERROR = 0x02C8, // B error
+ GPMSG_NPC_CLOSE = 0x02C9, // W being id
GPMSG_NPC_POST = 0x02D0, // W being id
PGMSG_NPC_POST_SEND = 0x02D1, // W being id, { S name, S text, W item id }
GPMSG_NPC_POST_GET = 0x02D2, // W being id, { S name, S text, W item id }
@@ -169,21 +170,21 @@ enum {
PGMSG_NPC_STRING = 0x02D4, // W being id, S string
GPMSG_NPC_NUMBER = 0x02D5, // W being id, D max, D min, D default
GPMSG_NPC_STRING = 0x02D6, // W being id
- PGMSG_TRADE_REQUEST = 0x02C0, // W being id
- GPMSG_TRADE_REQUEST = 0x02C1, // W being id
- GPMSG_TRADE_START = 0x02C2, // -
- GPMSG_TRADE_COMPLETE = 0x02C3, // -
- PGMSG_TRADE_CANCEL = 0x02C4, // -
- GPMSG_TRADE_CANCEL = 0x02C5, // -
- PGMSG_TRADE_AGREED = 0x02C6, // -
- GPMSG_TRADE_AGREED = 0x02C7, // -
- PGMSG_TRADE_CONFIRM = 0x02C8, // -
- GPMSG_TRADE_CONFIRM = 0x02C9, // -
- PGMSG_TRADE_ADD_ITEM = 0x02CA, // B slot, B amount
- GPMSG_TRADE_ADD_ITEM = 0x02CB, // W item id, B amount
- PGMSG_TRADE_SET_MONEY = 0x02CC, // D amount
- GPMSG_TRADE_SET_MONEY = 0x02CD, // D amount
- GPMSG_TRADE_BOTH_CONFIRM = 0x02CE, // -
+ PGMSG_TRADE_REQUEST = 0x02E0, // W being id
+ GPMSG_TRADE_REQUEST = 0x02E1, // W being id
+ GPMSG_TRADE_START = 0x02E2, // -
+ GPMSG_TRADE_COMPLETE = 0x02E3, // -
+ PGMSG_TRADE_CANCEL = 0x02E4, // -
+ GPMSG_TRADE_CANCEL = 0x02E5, // -
+ PGMSG_TRADE_AGREED = 0x02E6, // -
+ GPMSG_TRADE_AGREED = 0x02E7, // -
+ PGMSG_TRADE_CONFIRM = 0x02E8, // -
+ GPMSG_TRADE_CONFIRM = 0x02E9, // -
+ PGMSG_TRADE_ADD_ITEM = 0x02EA, // B slot, B amount
+ GPMSG_TRADE_ADD_ITEM = 0x02EB, // W item id, B amount
+ PGMSG_TRADE_SET_MONEY = 0x02EC, // D amount
+ GPMSG_TRADE_SET_MONEY = 0x02ED, // D amount
+ GPMSG_TRADE_BOTH_CONFIRM = 0x02EE, // -
PGMSG_USE_ITEM = 0x0300, // B slot
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
diff --git a/src/game-server/abilitycomponent.cpp b/src/game-server/abilitycomponent.cpp
index c005635a..1ac82cdf 100644
--- a/src/game-server/abilitycomponent.cpp
+++ b/src/game-server/abilitycomponent.cpp
@@ -109,6 +109,7 @@ bool AbilityComponent::useAbilityOnBeing(Entity &user, int id, Entity *b)
AbilityMap::iterator it = mAbilities.find(id);
if (!abilityUseCheck(it))
return false;
+
AbilityValue &ability = it->second;
if (ability.abilityInfo->target != AbilityManager::TARGET_BEING)
@@ -141,6 +142,7 @@ bool AbilityComponent::useAbilityOnPoint(Entity &user, int id, int x, int y)
AbilityMap::iterator it = mAbilities.find(id);
if (!abilityUseCheck(it))
return false;
+
AbilityValue &ability = it->second;
if (ability.abilityInfo->target != AbilityManager::TARGET_POINT)
@@ -162,6 +164,33 @@ bool AbilityComponent::useAbilityOnPoint(Entity &user, int id, int x, int y)
return true;
}
+bool AbilityComponent::useAbilityOnDirection(Entity &user, int id,
+ ManaServ::BeingDirection direction)
+{
+ AbilityMap::iterator it = mAbilities.find(id);
+ if (!abilityUseCheck(it))
+ return false;
+
+ AbilityValue &ability = it->second;
+
+ if (ability.abilityInfo->target != AbilityManager::TARGET_DIRECTION)
+ return false;
+
+ //tell script engine to cast the spell
+ Script *script = ScriptManager::currentState();
+ script->prepare(ability.abilityInfo->useCallback);
+ script->push(&user);
+ script->push(direction);
+ script->push(ability.abilityInfo->id);
+ script->execute(user.getMap());
+
+ mLastUsedAbilityId = id;
+ mLastTargetDirection = direction;
+ user.getComponent<ActorComponent>()->raiseUpdateFlags(
+ UPDATEFLAG_ABILITY_ON_DIRECTION);
+ return true;
+}
+
/**
* Allows a character to perform a ability
*/
diff --git a/src/game-server/abilitycomponent.h b/src/game-server/abilitycomponent.h
index 948d5ed3..5814a4ae 100644
--- a/src/game-server/abilitycomponent.h
+++ b/src/game-server/abilitycomponent.h
@@ -58,6 +58,8 @@ public:
bool useAbilityOnBeing(Entity &user, int id, Entity *b);
bool useAbilityOnPoint(Entity &user, int id, int x, int y);
+ bool useAbilityOnDirection(Entity &user, int id,
+ ManaServ::BeingDirection direction);
bool giveAbility(int id, int currentMana = 0);
bool giveAbility(const AbilityManager::AbilityInfo *info,
@@ -80,8 +82,10 @@ public:
// For informing clients
int getLastUsedAbilityId() const;
- const Point &getLastTargetPoint() const;
+
int getLastTargetBeingId() const;
+ const Point &getLastTargetPoint() const;
+ ManaServ::BeingDirection getLastUsedTargetDirection() const;
private:
bool abilityUseCheck(AbilityMap::iterator it);
@@ -93,6 +97,7 @@ private:
// Variables required for informing clients
int mLastUsedAbilityId;
Point mLastTargetPoint;
+ ManaServ::BeingDirection mLastTargetDirection;
int mLastTargetBeingId;
};
diff --git a/src/game-server/abilitymanager.cpp b/src/game-server/abilitymanager.cpp
index 3e923800..c1401284 100644
--- a/src/game-server/abilitymanager.cpp
+++ b/src/game-server/abilitymanager.cpp
@@ -31,6 +31,8 @@ static AbilityManager::TargetMode getTargetByString(const std::string &str)
return AbilityManager::TARGET_BEING;
else if (strLower == "point")
return AbilityManager::TARGET_POINT;
+ else if (strLower == "direction")
+ return AbilityManager::TARGET_DIRECTION;
LOG_WARN("Unknown targetmode " << str << " assuming being.");
return AbilityManager::TARGET_BEING;
diff --git a/src/game-server/abilitymanager.h b/src/game-server/abilitymanager.h
index 573db415..66249a40 100644
--- a/src/game-server/abilitymanager.h
+++ b/src/game-server/abilitymanager.h
@@ -35,7 +35,8 @@ public:
enum TargetMode
{
TARGET_BEING,
- TARGET_POINT
+ TARGET_POINT,
+ TARGET_DIRECTION,
};
struct AbilityInfo
diff --git a/src/game-server/actor.h b/src/game-server/actor.h
index 80f6bbb0..e1110a17 100644
--- a/src/game-server/actor.h
+++ b/src/game-server/actor.h
@@ -39,7 +39,8 @@ enum
UPDATEFLAG_HEALTHCHANGE = 32,
UPDATEFLAG_EMOTE = 64,
UPDATEFLAG_ABILITY_ON_POINT = 128,
- UPDATEFLAG_ABILITY_ON_BEING = 256
+ UPDATEFLAG_ABILITY_ON_BEING = 256,
+ UPDATEFLAG_ABILITY_ON_DIRECTION = 512,
};
/**
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index fe274ace..913abf80 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -257,6 +257,10 @@ void GameHandler::processMessage(NetComputer *computer, MessageIn &message)
handleUseAbilityOnPoint(client, message);
break;
+ case PGMSG_USE_ABILITY_ON_DIRECTION:
+ handleUseAbilityOnDirection(client, message);
+ break;
+
case PGMSG_ACTION_CHANGE:
handleActionChange(client, message);
break;
@@ -683,6 +687,24 @@ void GameHandler::handleUseAbilityOnPoint(GameClient &client, MessageIn &message
abilityComponent->useAbilityOnPoint(*client.character, abilityID, x, y);
}
+void GameHandler::handleUseAbilityOnDirection(GameClient &client, MessageIn &message)
+{
+ if (client.character->getComponent<BeingComponent>()->getAction() == DEAD)
+ return;
+
+ const int abilityID = message.readInt8();
+ const BeingDirection direction = (BeingDirection)message.readInt8();
+
+ const int publicId =
+ client.character->getComponent<ActorComponent>()->getPublicID();
+ LOG_DEBUG("Character " << publicId
+ << " tries to use his ability " << abilityID);
+ auto *abilityComponent = client.character
+ ->getComponent<AbilityComponent>();
+ abilityComponent->useAbilityOnDirection(*client.character, abilityID,
+ direction);
+}
+
void GameHandler::handleActionChange(GameClient &client, MessageIn &message)
{
auto *beingComponent = client.character->getComponent<BeingComponent>();
diff --git a/src/game-server/gamehandler.h b/src/game-server/gamehandler.h
index f4995497..fea40398 100644
--- a/src/game-server/gamehandler.h
+++ b/src/game-server/gamehandler.h
@@ -135,6 +135,8 @@ class GameHandler: public ConnectionHandler
void handleUseAbilityOnBeing(GameClient &client, MessageIn &message);
void handleUseAbilityOnPoint(GameClient &client, MessageIn &message);
+ void handleUseAbilityOnDirection(GameClient &client, MessageIn &message);
+
void handleActionChange(GameClient &client, MessageIn &message);
void handleDirectionChange(GameClient &client, MessageIn &message);