summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--src/being.cpp2
-rw-r--r--src/being.h9
-rw-r--r--src/localplayer.cpp14
-rw-r--r--src/monster.cpp4
-rw-r--r--src/monster.h2
-rw-r--r--src/net/beinghandler.cpp72
-rw-r--r--src/net/beinghandler.h1
-rw-r--r--src/net/gameserver/player.cpp7
-rw-r--r--src/net/gameserver/player.h3
-rw-r--r--src/net/protocol.h5
11 files changed, 86 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index 92f41866..bd752762 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,11 @@
-2007-02-27 Philipp Sehmisch <tmw@crushnet.org>
+2007-03-01 Philipp Sehmisch <tmw@crushnet.org>
+
+ * src/being.cpp, src/being.h, src/localplayer.cpp, src/monster.cpp,
+ src/monster.h, src/net/beinghandler.cpp, src/net/beinghandler.h,
+ src/net/gameserver/player.cpp, src/net/gameserver/player.h,
+ src/net/protocol.h: Implemented communication of being action changes.
+
+2007-02-27 Philipp Sehmisch <tmw@crushnet.org>
* gui/button.cpp, src/guibutton.h,
src/gui/tabbedcontainer.cpp, src/gui/tabbedcontainer.h:: Tabbed
diff --git a/src/being.cpp b/src/being.cpp
index 68b85832..33ee7e7a 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -300,7 +300,7 @@ Being::setMap(Map *map)
}
void
-Being::setAction(Uint8 action)
+Being::setAction(Action action)
{
SpriteAction currentAction = ACTION_INVALID;
switch (action)
diff --git a/src/being.h b/src/being.h
index b87cacbe..3c6b14c6 100644
--- a/src/being.h
+++ b/src/being.h
@@ -67,6 +67,11 @@ class Being : public Sprite
MONSTER
};
+ /**
+ * Action the being is currently performing
+ * WARNING: Has to be in sync with the same enum in the Being class
+ * of the server!
+ */
enum Action {
STAND,
WALK,
@@ -96,7 +101,7 @@ class Being : public Sprite
std::string mName; /**< Name of character */
Uint16 mJob; /**< Job (player job, npc, monster, ) */
Uint16 mX, mY; /**< Pixel coordinates (tile center) */
- Uint8 mAction; /**< Action the being is performing */
+ Action mAction; /**< Action the being is performing */
Uint16 mWalkTime;
Uint8 mEmotion; /**< Currently showing emotion */
Uint8 mEmotionTime; /**< Time until emotion disappears */
@@ -296,7 +301,7 @@ class Being : public Sprite
* Sets the current action.
*/
virtual void
- setAction(Uint8 action);
+ setAction(Action action);
/**
* Returns the direction the being is facing.
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 1dd8bdf2..16d5b191 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -289,20 +289,16 @@ void LocalPlayer::toggleSit()
return;
mLastAction = tick_time;
- char type;
+ Being::Action newAction;
switch (mAction)
{
- case STAND: type = 2; break;
- case SIT: type = 3; break;
+ case Being::STAND: newAction = Being::SIT; break;
+ case Being::SIT: newAction = Being::STAND; break;
default: return;
}
- // XXX Convert for new server
- /*
- MessageOut outMsg(0x0089);
- outMsg.writeLong(0);
- outMsg.writeByte(type);
- */
+ setAction(newAction);
+ Net::GameServer::Player::changeAction(newAction);
}
void LocalPlayer::emote(Uint8 emotion)
diff --git a/src/monster.cpp b/src/monster.cpp
index f2e4d93d..dd4a321c 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -46,7 +46,7 @@ Monster::getType() const
}
void
-Monster::setAction(Uint8 action)
+Monster::setAction(Action action)
{
SpriteAction currentAction = ACTION_INVALID;
@@ -70,6 +70,8 @@ Monster::setAction(Uint8 action)
case HURT:
// Not implemented yet
break;
+ default:
+ break;
}
if (currentAction != ACTION_INVALID)
diff --git a/src/monster.h b/src/monster.h
index 7f129e14..3e9cdb05 100644
--- a/src/monster.h
+++ b/src/monster.h
@@ -31,7 +31,7 @@ class Monster : public Being
public:
Monster(Uint16 id, Uint16 job, Map *map);
- virtual void setAction(Uint8 action);
+ virtual void setAction(Action action);
virtual Type getType() const;
};
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp
index 08d47f01..32c78b39 100644
--- a/src/net/beinghandler.cpp
+++ b/src/net/beinghandler.cpp
@@ -58,6 +58,7 @@ BeingHandler::BeingHandler()
GPMSG_BEING_LEAVE,
GPMSG_BEINGS_MOVE,
GPMSG_BEINGS_DAMAGE,
+ GPMSG_BEING_ACTION_CHANGE,
0
};
handledMessages = _messages;
@@ -79,11 +80,9 @@ void BeingHandler::handleMessage(MessageIn &msg)
case GPMSG_BEING_ENTER:
handleBeingEnterMessage(msg);
break;
-
case GPMSG_BEING_LEAVE:
handleBeingLeaveMessage(msg);
break;
-
case GPMSG_BEINGS_MOVE:
handleBeingsMoveMessage(msg);
break;
@@ -93,6 +92,9 @@ void BeingHandler::handleMessage(MessageIn &msg)
case GPMSG_BEINGS_DAMAGE:
handleBeingsDamageMessage(msg);
break;
+ case GPMSG_BEING_ACTION_CHANGE:
+ handleBeingActionChangeMessage(msg);
+ break;
/*
case SMSG_BEING_VISIBLE:
@@ -406,33 +408,45 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg)
{
int type = msg.readByte(); // type
int id = msg.readShort();
+ Being::Action action = (Being::Action)msg.readByte();
+ Uint16 px = msg.readShort();
+ Uint16 py = msg.readShort();
- switch (type) {
- case OBJECT_PLAYER:
+ switch (type)
{
- std::string name = msg.readString();
- Being *being;
- if (player_node->getName() == name)
+ case OBJECT_PLAYER:
{
- being = player_node;
- being->setId(id);
- }
- else
+ std::string name = msg.readString();
+ Being *being;
+ if (player_node->getName() == name)
+ {
+ being = player_node;
+ being->setId(id);
+ }
+ else
+ {
+ being = beingManager->createBeing(id, 0);
+ being->setName(name);
+ }
+ being->setHairStyle(msg.readByte());
+ being->setHairColor(msg.readByte());
+ being->setSex(msg.readByte());
+ being->mX = px;
+ being->mY = py;
+ being->setDestination(px, py);
+ being->setAction(action);
+ } break;
+ case OBJECT_MONSTER:
{
- being = beingManager->createBeing(id, 0);
- being->setName(name);
- }
- being->setHairStyle(msg.readByte());
- being->setHairColor(msg.readByte());
- being->setSex(msg.readByte());
- } break;
- case OBJECT_MONSTER:
- {
- int monsterId = msg.readShort();
- Being *being;
- being = beingManager->createBeing(id, 1002 + monsterId);
- being->setWalkSpeed(150); // TODO
- } break;
+ int monsterId = msg.readShort();
+ Being *being;
+ being = beingManager->createBeing(id, 1002 + monsterId);
+ being->setWalkSpeed(150); // TODO
+ being->mX = px;
+ being->mY = py;
+ being->setDestination(px, py);
+ being->setAction(action);
+ } break;
}
}
@@ -515,3 +529,11 @@ void BeingHandler::handleBeingsDamageMessage(MessageIn &msg)
}
}
}
+
+void BeingHandler::handleBeingActionChangeMessage(MessageIn &msg)
+{
+ Being* being = beingManager->findBeing(msg.readShort());
+ if (!being) return;
+
+ being->setAction((Being::Action)msg.readByte());
+}
diff --git a/src/net/beinghandler.h b/src/net/beinghandler.h
index 2cf0e743..7a018950 100644
--- a/src/net/beinghandler.h
+++ b/src/net/beinghandler.h
@@ -39,6 +39,7 @@ class BeingHandler : public MessageHandler
void handleBeingLeaveMessage(MessageIn &msg);
void handleBeingsMoveMessage(MessageIn &msg);
void handleBeingsDamageMessage(MessageIn &msg);
+ void handleBeingActionChangeMessage(MessageIn &msg);
};
#endif
diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp
index 033327c9..9af0c238 100644
--- a/src/net/gameserver/player.cpp
+++ b/src/net/gameserver/player.cpp
@@ -73,3 +73,10 @@ void Net::GameServer::Player::attack(unsigned char direction)
msg.writeByte(direction);
Net::GameServer::connection->send(msg);
}
+
+void Net::GameServer::Player::changeAction(Being::Action action)
+{
+ MessageOut msg(PGMSG_ACTION_CHANGE);
+ msg.writeByte(action);
+ Net::GameServer::connection->send(msg);
+}
diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h
index 73a533d5..7cc45486 100644
--- a/src/net/gameserver/player.h
+++ b/src/net/gameserver/player.h
@@ -24,6 +24,8 @@
#ifndef _TMW_NET_GAMESERVER_PLAYER_H
#define _TMW_NET_GAMESERVER_PLAYER_H
+#include "../../being.h"
+
#include <iosfwd>
namespace Net
@@ -38,6 +40,7 @@ namespace Net
void drop(int slot, int amount);
void equip(int slot);
void attack(unsigned char direction);
+ void changeAction(Being::Action action);
}
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index eb27af7d..a5205dba 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -160,12 +160,14 @@ enum {
PGMSG_EQUIP = 0x0112, // B slot
GPMSG_INVENTORY = 0x0120, // { B slot, W item id [, B amount] }*
GPMSG_INVENTORY_FULL = 0x0121, // { B slot, W item id [, B amount] }*
- GPMSG_BEING_ENTER = 0x0200, // B type, W being id
+ GPMSG_BEING_ENTER = 0x0200, // B type, W being id, B action, W*2 position
// player: S name, B hair style, B hair color, B gender
// monster: W type id
GPMSG_BEING_LEAVE = 0x0201, // W being id
GPMSG_ITEM_APPEAR = 0x0202, // W item id, W*2 position
PGMSG_WALK = 0x0260, // W*2 destination
+ PGMSG_ACTION_CHANGE = 0x0270, // B Action
+ GPMSG_BEING_ACTION_CHANGE = 0x0271, // W being id, B action
GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position] [, W*2 destination] }*
GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }*
PGMSG_ATTACK = 0x0290, // B direction
@@ -175,7 +177,6 @@ enum {
PGMSG_USE_ITEM = 0x0300, // L item id
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
- GPMSG_BEING_DEAD = 0xDEAD, // W being id
// Chat
CPMSG_ERROR = 0x0401, // B error