diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/defines.h | 2 | ||||
-rw-r--r-- | src/gamehandler.cpp | 9 | ||||
-rw-r--r-- | src/object.h | 7 | ||||
-rw-r--r-- | src/player.cpp | 16 | ||||
-rw-r--r-- | src/player.h | 9 | ||||
-rw-r--r-- | src/state.cpp | 27 |
7 files changed, 72 insertions, 6 deletions
@@ -1,3 +1,9 @@ +2006-12-27 Philipp Sehmisch <tmw@crushnet.org> + + * src/defines.h, src/gamehandler.cpp, src/object.h, src/player.cpp, + src/player.h src/state.cpp: + Clients are now notified when other clients near them perform attacks. + 2006-10-20 Yohann Ferreira <bertram@cegetel.net> * src/item.h, src/player.cpp, src/inventory.h, src/inventory.cpp: @@ -23,7 +29,7 @@ 2006-10-03 Eugenio Favalli <elvenprogrammer@gmail.com> - * src/itemhandler.h, tmwserv.cbp, tmwserv.dev: Updated project files + * src/itemhandler.h, tmwserv.cbp, tmwserv.dev: Updated project files and fixed a compilation issue. 2006-10-03 Yohann Ferreira <bertram@cegetel.net> 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. |