summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/server.txt6
-rw-r--r--src/being.cpp27
-rw-r--r--src/being.h22
-rw-r--r--src/dalstorage.cpp2
-rw-r--r--src/dalstoragesql.h3
-rw-r--r--src/defines.h21
-rw-r--r--src/gamehandler.cpp25
-rw-r--r--src/state.cpp2
-rw-r--r--src/state.h11
9 files changed, 110 insertions, 9 deletions
diff --git a/docs/server.txt b/docs/server.txt
index e2d506af..5fd61b85 100644
--- a/docs/server.txt
+++ b/docs/server.txt
@@ -170,3 +170,9 @@ being(s) are to be controlled.
MSG_CHAR_CREATE { ... }
The character creation process will need to be thought out.
+
+8. MISCLELLANEOUS
+
+ Server to client:
+
+ SMSG_LOAD_MAP { A mapName, L x, L y} // Change map & update player X and Y
diff --git a/src/being.cpp b/src/being.cpp
index 0aa3d456..eba5b7c0 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -273,8 +273,7 @@ Being::getRawStatistics(void)
/**
* Update the internal status.
*/
-void
-Being::update(void)
+void Being::update(void)
{
// computed stats.
mStats.health = 20 + (20 * mRawStats.vitality);
@@ -287,5 +286,29 @@ Being::update(void)
mNeedUpdate = false;
}
+void Being::setInventory(const std::vector<unsigned int> &inven)
+{
+ inventory = inven;
+}
+
+bool Being::addInventory(unsigned int itemId)
+{
+ // If required weight could be tallied to see if player can pick up more.
+ inventory.push_back(itemId);
+ return true;
+}
+
+bool Being::delInventory(unsigned int itemId)
+{
+ for (std::vector<unsigned int>::iterator i = inventory.begin();
+ i != inventory.end(); i++) {
+ if (*i == itemId) {
+ inventory.erase(i);
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace tmwserv
diff --git a/src/being.h b/src/being.h
index 47766eaa..8a3adb94 100644
--- a/src/being.h
+++ b/src/being.h
@@ -32,6 +32,7 @@
#include "object.h"
#include "utils/countedptr.h"
+const unsigned int MAX_EQUIP_SLOTS = 5; /**< Maximum number of equipped slots */
namespace tmwserv
{
@@ -270,6 +271,24 @@ class Being: public Object
void
update(void);
+ /**
+ * Set inventory
+ */
+ void setInventory(const std::vector<unsigned int> &inven);
+
+ /**
+ * Add item with ID to inventory
+ *
+ * @return Item add success/failure
+ */
+ bool addInventory(unsigned int itemId);
+
+ /**
+ * Remove item with ID from inventory
+ *
+ * @return Item delete success/failure
+ */
+ bool delInventory(unsigned int itemId);
private:
/**
@@ -291,6 +310,9 @@ class Being: public Object
unsigned short mLevel; /**< level of the being */
unsigned int mMoney; /**< wealth of the being */
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) */
};
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index 1bc71dab..bc166358 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -446,7 +446,7 @@ DALStorage::_addAccount(const AccountPtr& account)
RawStatistics& stats = (*it)->getRawStatistics();
std::ostringstream sql3;
sql3 << "insert into " << CHARACTERS_TBL_NAME
- << " (name, gender, level, money, x, y, map_id, str, agi, vit, int, dex luck)"
+ << " (name, gender, level, money, x, y, map_id, str, agi, vit, int, dex, luck)"
<< " values ("
<< (account_it->second).id << ", '"
<< (*it)->getName() << "', '"
diff --git a/src/dalstoragesql.h b/src/dalstoragesql.h
index 3d1ffc05..077b7b0a 100644
--- a/src/dalstoragesql.h
+++ b/src/dalstoragesql.h
@@ -244,6 +244,7 @@ const std::string SQL_ITEMS_TABLE(
* - store items on the ground in the game world.
*/
const std::string WORLD_ITEMS_TBL_NAME("tmw_world_items");
+// NOTE: Problem here with primary key (only one type of item is allowed on the same map at one time).
const std::string SQL_WORLD_ITEMS_TABLE(
"CREATE TABLE tmw_world_items ("
#if defined (MYSQL_SUPPORT)
@@ -254,7 +255,7 @@ const std::string SQL_WORLD_ITEMS_TABLE(
"map_id TINYINT NOT NULL,"
// time to die (UNIX time)
"deathtime INTEGER UNSIGNED NOT NULL,"
- "PRIMARY KEY (id, map_id),"
+ "PRIMARY KEY (id, map_id),"
"FOREIGN KEY (id) REFERENCES tmw_items(id),"
"FOREIGN KEY (map_id) REFERENCES tmw_maps(id)"
#elif defined (SQLITE_SUPPORT)
diff --git a/src/defines.h b/src/defines.h
index 571a96be..09b1cd04 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -77,7 +77,9 @@ enum {
SMSG_REMOVE_OBJECT = 0x0101,
SMSG_CHANGE_OBJECT = 0x0102,
CMSG_PICKUP = 0x0110,
+ SMSG_PICKUP_RESPONSE = 0x0111,
CMSG_USE_OBJECT = 0x0120,
+ SMSG_USE_RESPONSE = 0x0121,
// Beings
SMSG_NEW_BEING = 0x0200,
@@ -101,7 +103,10 @@ enum {
SMSG_SYSTEM = 0x0401,
SMSG_ANNOUNCEMENT = 0x0402,
CMSG_SAY = 0x0410,
- CMSG_ANNOUNCE = 0x0411
+ CMSG_ANNOUNCE = 0x0411,
+
+ // Other
+ SMSG_LOAD_MAP = 0x0500,
// NOTE: We will need more messages for in-game control (eg. moving a client to a new map/position etc.). Currently the protocol only caters for the bare basics.
};
@@ -118,6 +123,7 @@ enum {
LOGIN_UNKNOWN
};
+// Account register return values
enum {
REGISTER_OK = 0,
REGISTER_INVALID_USERNAME,
@@ -151,5 +157,18 @@ enum {
OBJECT_MONSTER
};
+// Pickup response enumeration
+enum {
+ PICKUP_OK = 0,
+ PICKUP_OVERWEIGHT,
+ PICKUP_FAIL
+};
+
+// Object use response enumeration
+enum {
+ USE_OK = 0,
+ USE_FAIL
+};
+
#endif // _TMWSERV_DEFINES_H_
diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp
index 340e8690..568c7866 100644
--- a/src/gamehandler.cpp
+++ b/src/gamehandler.cpp
@@ -22,20 +22,37 @@
*/
#include "gamehandler.h"
+#include "messageout.h"
#include <iostream>
void GameHandler::receiveMessage(NetComputer &computer, MessageIn &message)
{
- if (computer.getAccount() == NULL)
+ if (computer.getCharacter() == NULL)
return;
+ MessageOut result;
+
switch (message.getId())
{
case CMSG_PICKUP:
- break;
+ {
+ // add item to inventory (this is too simplistic atm)
+ unsigned int itemId = message.readLong();
+
+ // remove the item from world map
+ // send feedback
+ computer.getCharacter()->addInventory(itemId);
+ result.writeShort(SMSG_PICKUP_RESPONSE);
+ result.writeByte(PICKUP_OK);
+ } break;
+
case CMSG_USE_OBJECT:
- break;
+ {
+ unsigned int itemId = message.readLong();
+ result.writeShort(SMSG_USE_RESPONSE);
+ result.writeByte(USE_OK);
+ } break;
case CMSG_TARGET:
break;
@@ -63,4 +80,6 @@ void GameHandler::receiveMessage(NetComputer &computer, MessageIn &message)
<< " (" << message.getId() << ")" << std::endl;
break;
}
+
+ computer.send(result.getPacket());
}
diff --git a/src/state.cpp b/src/state.cpp
index 86c7e1aa..f605016d 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -32,7 +32,7 @@ void State::update(ConnectionHandler &connectionHandler)
{
// update game state (update AI, etc.)
- // notify clients about changes in the game world
+ // notify clients about changes in the game world (only on their maps)
// NOTE: This isn't finished ;)
for (std::map<std::string, Beings>::iterator i = beings.begin();
i != beings.end();
diff --git a/src/state.h b/src/state.h
index 31142d11..21bb7566 100644
--- a/src/state.h
+++ b/src/state.h
@@ -47,6 +47,8 @@ class State : public utils::Singleton<State>
public:
/**
+ * Beings on map
+ *
* The key/value pair conforms to:
* First - map name
* Second - list of beings/players on the map
@@ -56,6 +58,15 @@ class State : public utils::Singleton<State>
std::map<std::string, Beings> beings;
/**
+ * Items on map
+ *
+ * The key/value pair conforms to:
+ * First - map name
+ * Second - Item ID
+ */
+ std::map<std::string, int> items;
+
+ /**
* Container for loaded maps.
*/
std::map<std::string, Map*> maps;