summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Marks <nymacro@gmail.com>2005-08-08 10:12:45 +0000
committerAaron Marks <nymacro@gmail.com>2005-08-08 10:12:45 +0000
commite4936a090b3b8f4611d10eb86e11856cbd27cf0a (patch)
treed3c8aa4d0c9ef8772cc5a5e60f970597f11f6d20 /src
parentca4fec29828b55ea66c5835ab20d2287bb1eb4ff (diff)
downloadmanaserv-e4936a090b3b8f4611d10eb86e11856cbd27cf0a.tar.gz
manaserv-e4936a090b3b8f4611d10eb86e11856cbd27cf0a.tar.bz2
manaserv-e4936a090b3b8f4611d10eb86e11856cbd27cf0a.tar.xz
manaserv-e4936a090b3b8f4611d10eb86e11856cbd27cf0a.zip
Just some changes I forgot to commit -- I probably wont be able to work on tmwserv for a few days :(
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp18
-rw-r--r--src/being.h16
-rw-r--r--src/defines.h7
-rw-r--r--src/gamehandler.cpp32
-rw-r--r--src/state.cpp6
5 files changed, 71 insertions, 8 deletions
diff --git a/src/being.cpp b/src/being.cpp
index eba5b7c0..6c97fa98 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -310,5 +310,23 @@ bool Being::delInventory(unsigned int itemId)
return false;
}
+bool Being::equip(unsigned int itemId, unsigned char slot)
+{
+ // currently this is too simplistic and doesn't check enough
+ // but until further functionality is implemented in the
+ // server it will suffice
+ if (slot < MAX_EQUIP_SLOTS) {
+ equipment[slot] = itemId;
+ return true;
+ } else
+ return false;
+}
+
+bool Being::unequip(unsigned char slot)
+{
+ // NOTE: 0 will be invalid item id (or we could use key/value pairs)
+ equipment[slot] = 0;
+ return true;
+}
} // namespace tmwserv
diff --git a/src/being.h b/src/being.h
index 8a3adb94..b8e53010 100644
--- a/src/being.h
+++ b/src/being.h
@@ -290,6 +290,20 @@ class Being: public Object
*/
bool delInventory(unsigned int itemId);
+ /**
+ * Equip item with ID in equipment slot
+ *
+ * @return Equip success/failure
+ */
+ bool equip(unsigned int itemId, unsigned char slot);
+
+ /**
+ * Un-equip item
+ *
+ * bool Un-equip success/failure
+ */
+ bool unequip(unsigned char slot);
+
private:
/**
* Copy constructor.
@@ -312,7 +326,7 @@ class Being: public Object
RawStatistics mRawStats; /**< raw stats of the being */
std::vector<unsigned int> inventory; /**< Player inventory */
- unsigned int equipped[MAX_EQUIP_SLOTS]; /**< Equipped item ID's (from inventory) */
+ unsigned int equipment[MAX_EQUIP_SLOTS]; /**< Equipped item ID's (from inventory) */
};
diff --git a/src/defines.h b/src/defines.h
index 09b1cd04..32fb6cf5 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -97,6 +97,7 @@ enum {
// Items
CMSG_USE_ITEM = 0x0300,
CMSG_EQUIP = 0x0301,
+ SMSG_EQUIP_RESPONSE = 0x0302,
// Chat
SMSG_CHAT = 0x0400,
@@ -170,5 +171,11 @@ enum {
USE_FAIL
};
+// Equip responses
+enum {
+ EQUIP_OK = 0,
+ EQUIP_FAIL
+};
+
#endif // _TMWSERV_DEFINES_H_
diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp
index 568c7866..cfeda536 100644
--- a/src/gamehandler.cpp
+++ b/src/gamehandler.cpp
@@ -50,15 +50,31 @@ void GameHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_USE_OBJECT:
{
unsigned int itemId = message.readLong();
+
+ // use item
+ // this should execute a script which will do the appropriate action
+
+ // respond
result.writeShort(SMSG_USE_RESPONSE);
result.writeByte(USE_OK);
} break;
case CMSG_TARGET:
- break;
+ {
+
+ } break;
case CMSG_WALK:
- break;
+ {
+ int x = message.readLong();
+ int y = message.readLong();
+
+ // simplistic "teleport" walk
+ computer.getCharacter()->setX(x);
+ computer.getCharacter()->setY(y);
+
+ // no response should be required
+ } break;
case CMSG_START_TRADE:
break;
@@ -73,7 +89,14 @@ void GameHandler::receiveMessage(NetComputer &computer, MessageIn &message)
break;
case CMSG_EQUIP:
- break;
+ {
+ int itemId = message.readLong();
+ char slot = message.readByte();
+
+ result.writeShort(SMSG_EQUIP_RESPONSE);
+ result.writeByte(computer.getCharacter()->equip(itemId, slot) ?
+ EQUIP_OK : EQUIP_FAIL);
+ } break;
default:
std::cerr << "Warning: GameHandler received message of unkown type"
@@ -81,5 +104,6 @@ void GameHandler::receiveMessage(NetComputer &computer, MessageIn &message)
break;
}
- computer.send(result.getPacket());
+ if (result.getPacket()->length > 0)
+ computer.send(result.getPacket());
}
diff --git a/src/state.cpp b/src/state.cpp
index f605016d..72448eab 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -47,11 +47,11 @@ void State::update(ConnectionHandler &connectionHandler)
b2++) {
if (b != b2) {
MessageOut msg;
- msg.writeShort(SMSG_NEW_OBJECT);
+ msg.writeShort(SMSG_NEW_OBJECT); // of course this wont be send _all_ the time ;)
msg.writeLong(OBJECT_PLAYER); // type
msg.writeLong((int)b2->get()); // id
- msg.writeLong(0); // x
- msg.writeLong(0); // y
+ msg.writeLong(b2->get()->getX());// x
+ msg.writeLong(b2->get()->getY());// y
connectionHandler.sendTo(b->get(), msg);
}