summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2006-12-27 20:33:16 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2006-12-27 20:33:16 +0000
commit4bfa5b213257416f997d01b087c9e8bbb91cb3b9 (patch)
tree89e6e3dcb328994cc9fd21604b61c1544dc972ba /src
parent896901986a1d6ad0e93f494fba0b39b066c2aabf (diff)
downloadmanaserv-4bfa5b213257416f997d01b087c9e8bbb91cb3b9.tar.gz
manaserv-4bfa5b213257416f997d01b087c9e8bbb91cb3b9.tar.bz2
manaserv-4bfa5b213257416f997d01b087c9e8bbb91cb3b9.tar.xz
manaserv-4bfa5b213257416f997d01b087c9e8bbb91cb3b9.zip
Clients are now notified when other clients near them perform attacks.
Diffstat (limited to 'src')
-rw-r--r--src/defines.h2
-rw-r--r--src/gamehandler.cpp9
-rw-r--r--src/object.h7
-rw-r--r--src/player.cpp16
-rw-r--r--src/player.h9
-rw-r--r--src/state.cpp27
6 files changed, 65 insertions, 5 deletions
diff --git a/src/defines.h b/src/defines.h
index 86367813..dc594311 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -153,6 +153,8 @@ enum {
GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position] [, W*2 destination] }*
PGMSG_SAY = 0x02A0, // S text
GPMSG_SAY = 0x02A1, // W being id, S text
+ PGMSG_ATTACK = 0x0290, // -
+ GPMSG_BEING_ATTACK = 0x0291, // W being id
PGMSG_USE_ITEM = 0x0300, // L item id
GPMSG_USE_RESPONSE = 0x0301, // B error
PGMSG_EQUIP = 0x0302, // L item id, B slot
diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp
index 968325a7..e2a37e32 100644
--- a/src/gamehandler.cpp
+++ b/src/gamehandler.cpp
@@ -219,6 +219,15 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
ERRMSG_OK : ERRMSG_FAILURE);
} break;
+ case PGMSG_ATTACK:
+ {
+ LOG_DEBUG ( "Player " <<
+ computer.getCharacter()->getPublicID() <<
+ " attacks",
+ 0);
+ computer.getCharacter()->setAttacking(true);
+ } break;
+
default:
LOG_WARN("Invalid message type", 0);
result.writeShort(XXMSG_INVALID);
diff --git a/src/object.h b/src/object.h
index 8c771aa2..63d6c115 100644
--- a/src/object.h
+++ b/src/object.h
@@ -33,7 +33,8 @@
enum
{
NEW_ON_MAP = 1,
- NEW_DESTINATION = 2
+ NEW_DESTINATION = 2,
+ ATTACK = 4
};
/**
@@ -183,12 +184,14 @@ class MovingObject: public Object
void setPublicID(int id)
{ mPublicID = id; }
+ protected:
+ unsigned short mActionTime; /**< delay until next action */
+
private:
unsigned short mPublicID; /**< Object ID sent to clients (unique with respect to the map) */
Point mDst; /**< target coordinates */
Point mOld; /**< old coordinates */
unsigned short mSpeed; /**< speed */
- unsigned short mActionTime; /**< delay until next action */
};
/**
diff --git a/src/player.cpp b/src/player.cpp
index 40650157..14882712 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -22,6 +22,8 @@
#include "player.h"
+#include "defines.h"
+
#include <cassert>
void Player::setDatabaseID(int id)
@@ -42,6 +44,20 @@ void Player::update()
setStat(STAT_MAGIC, 10 + mRawStats.stats[STAT_INTELLIGENCE]);
setStat(STAT_ACCURACY, 50 + mRawStats.stats[STAT_DEXTERITY]);
setStat(STAT_SPEED, mRawStats.stats[STAT_DEXTERITY]);
+
+ // attacking
+ if (mIsAttacking)
+ {
+ // plausibility check of attack command
+ if (mActionTime <= 0)
+ {
+ // perform attack
+ mActionTime = 1000;
+ mIsAttacking = false;
+ raiseUpdateFlags (ATTACK);
+ //TODO: attack mechanics
+ }
+ }
}
void Player::setInventory(const Inventory &inven)
diff --git a/src/player.h b/src/player.h
index 83f5fee1..f3d1c35e 100644
--- a/src/player.h
+++ b/src/player.h
@@ -42,6 +42,7 @@ class Player : public Being
: Being(OBJECT_PLAYER, 65535),
mDatabaseID(id),
mName(name),
+ mIsAttacking(false),
mClient(NULL)
{}
@@ -203,6 +204,12 @@ class Player : public Being
unequip(unsigned char slot);
/**
+ * Set attacking state
+ **/
+ void setAttacking(bool isAttacking)
+ { mIsAttacking = isAttacking; }
+
+ /**
* Gets database ID.
*
* @return the database ID, a negative number if none yet.
@@ -238,6 +245,8 @@ class Player : public Being
Inventory inventory; /**< Player inventory and Equipment */
+ bool mIsAttacking; /**< attacking state */
+
friend class GameClient;
};
diff --git a/src/state.cpp b/src/state.cpp
index 9da71adc..b4853f68 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -88,18 +88,39 @@ State::update()
for (MovingObjectIterator o(map->getAroundPlayerIterator(*p)); o; ++o)
{
+
Point os = (*o)->getOldPosition();
Point on = (*o)->getPosition();
+ int flags = 0;
+
+ // Handle attacking
+ if ( (*o)->getUpdateFlags() & ATTACK
+ && (*o)->getPublicID() != (*p)->getPublicID()
+ && (*p)->getPosition().inRangeOf(on)
+ )
+ {
+ MessageOut AttackMsg (GPMSG_BEING_ATTACK);
+ AttackMsg.writeShort((*o)->getPublicID());
+
+ LOG_DEBUG( "Sending attack packet from " <<
+ (*o)->getPublicID() <<
+ " to " <<
+ (*p)->getPublicID(),
+ 0
+ );
+
+ gameHandler->sendTo(*p, AttackMsg);
+ }
+
+ // Handle moving
+
/* Check whether this player and this moving object were around
* the last time and whether they will be around the next time.
*/
bool wereInRange = (*p)->getOldPosition().inRangeOf(os) &&
!(((*p)->getUpdateFlags() | (*o)->getUpdateFlags()) & NEW_ON_MAP);
bool willBeInRange = (*p)->getPosition().inRangeOf(on);
-
- int flags = 0;
-
if (!wereInRange)
{
// o was outside p's range.