summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-23 17:00:11 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-07-23 17:00:11 +0000
commit919bcd64912d88993b56e931b0eea880b466947b (patch)
tree23686fa6d5a0b5beccb536d9108358221b07f09d /src/game-server
parent091a57aca17453b08e2a912a6ed19c09131e2123 (diff)
downloadmanaserv-919bcd64912d88993b56e931b0eea880b466947b.tar.gz
manaserv-919bcd64912d88993b56e931b0eea880b466947b.tar.bz2
manaserv-919bcd64912d88993b56e931b0eea880b466947b.tar.xz
manaserv-919bcd64912d88993b56e931b0eea880b466947b.zip
Commented out code unavailable from client side. Added support for NPCs.
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/accountconnection.cpp7
-rw-r--r--src/game-server/accountconnection.hpp2
-rw-r--r--src/game-server/gamehandler.cpp38
-rw-r--r--src/game-server/gamehandler.hpp2
-rw-r--r--src/game-server/mapcomposite.hpp5
-rw-r--r--src/game-server/npc.hpp60
-rw-r--r--src/game-server/state.cpp7
-rw-r--r--src/game-server/testing.cpp50
8 files changed, 160 insertions, 11 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp
index 3bdd971c..89d19187 100644
--- a/src/game-server/accountconnection.cpp
+++ b/src/game-server/accountconnection.cpp
@@ -92,7 +92,9 @@ void AccountConnection::processMessage(MessageIn &msg)
int port = msg.readShort();
gameHandler->completeServerChange(id, token, address, port);
} break;
-
+
+// The client should directly talk with the chat server and not go through the game server.
+#if 0
case AGMSG_GUILD_CREATE_RESPONSE:
{
if(msg.readByte() == ERRMSG_OK)
@@ -205,6 +207,7 @@ void AccountConnection::processMessage(MessageIn &msg)
gameHandler->sendTo(player, result);
}
} break;
+#endif
default:
LOG_WARN("Invalid message type");
@@ -221,6 +224,7 @@ void AccountConnection::playerReconnectAccount(int id, const std::string magic_t
send(msg);
}
+#if 0
void AccountConnection::playerCreateGuild(int id, const std::string &guildName)
{
LOG_INFO("Send GAMSG_GUILD_CREATE");
@@ -266,3 +270,4 @@ void AccountConnection::quitGuild(int id, short guildId)
msg.writeShort(guildId);
send(msg);
}
+#endif
diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp
index e06966df..ba9abe06 100644
--- a/src/game-server/accountconnection.hpp
+++ b/src/game-server/accountconnection.hpp
@@ -50,6 +50,7 @@ class AccountConnection : public Connection
*/
void playerReconnectAccount(int id, const std::string magic_token);
+#if 0
/**
* Sends create guild message
*/
@@ -74,6 +75,7 @@ class AccountConnection : public Connection
* Sends quit guild message.
*/
void quitGuild(int id, short guildId);
+#endif
protected:
/**
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index e1257e71..8010374b 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -32,6 +32,7 @@
#include "game-server/itemmanager.hpp"
#include "game-server/map.hpp"
#include "game-server/mapcomposite.hpp"
+#include "game-server/npc.hpp"
#include "game-server/state.hpp"
#include "net/messagein.hpp"
#include "net/messageout.hpp"
@@ -142,6 +143,36 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
GameState::sayAround(computer.character, say);
} break;
+ case PGMSG_NPC_TALK:
+ case PGMSG_NPC_TALK_NEXT:
+ case PGMSG_NPC_SELECT:
+ {
+ int id = message.readShort();
+ MapComposite *map = computer.character->getMap();
+ MovingObject *o = NULL;
+ Point ppos = computer.character->getPosition();
+ // TODO: use a less arbitrary value.
+ for (MovingObjectIterator i(map->getAroundPointIterator(ppos, 48)); i; ++i)
+ {
+ if ((*i)->getPublicID() == id)
+ {
+ o = *i;
+ break;
+ }
+ }
+ if (!o || o->getType() != OBJECT_NPC) break;
+
+ NPC *q = static_cast< NPC * >(o);
+ if (message.getId() == PGMSG_NPC_SELECT)
+ {
+ q->select(computer.character, message.readByte());
+ }
+ else
+ {
+ q->prompt(computer.character, message.getId() == PGMSG_NPC_TALK);
+ }
+ } break;
+
case PGMSG_PICKUP:
{
int x = message.readShort();
@@ -258,7 +289,11 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
computer.character = NULL;
computer.status = CLIENT_LOGIN;
} break;
-
+
+
+// The following messages should be handled by the chat server, not the game server.
+#if 0
+
case PGMSG_GUILD_CREATE:
{
std::string name = message.readString();
@@ -299,6 +334,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
messageMap[characterId] = computer.character;
accountHandler->quitGuild(characterId, guildId);
} break;
+#endif
default:
LOG_WARN("Invalid message type");
diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp
index 85a38674..f07e1ac9 100644
--- a/src/game-server/gamehandler.hpp
+++ b/src/game-server/gamehandler.hpp
@@ -90,7 +90,7 @@ class GameHandler: public ConnectionHandler
* Map of character's and their id used for getting which character to
* forward account server messages back to.
*/
- std::map<int, Character*> messageMap;
+ // std::map<int, Character*> messageMap;
/**
* Combines a client with it's character.
diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp
index 880f4c12..00d52173 100644
--- a/src/game-server/mapcomposite.hpp
+++ b/src/game-server/mapcomposite.hpp
@@ -183,11 +183,6 @@ class MapComposite
void update();
/**
- * Gets an object given its ID.
- */
- MovingObject *getObjectByID(int) const;
-
- /**
* Gets an iterator on the objects of the whole map.
*/
ZoneIterator getWholeMapIterator() const
diff --git a/src/game-server/npc.hpp b/src/game-server/npc.hpp
new file mode 100644
index 00000000..44bbf4b8
--- /dev/null
+++ b/src/game-server/npc.hpp
@@ -0,0 +1,60 @@
+/*
+ * The Mana World Server
+ * Copyright 2007 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMWSERV_GAMESERVER_NPC_HPP_
+#define _TMWSERV_GAMESERVER_NPC_HPP_
+
+#include "game-server/being.hpp"
+
+/**
+ * Class describing a non-player character.
+ */
+class NPC : public Being
+{
+ public:
+ NPC(int id): Being(OBJECT_NPC, 65535), mID(id) {}
+
+ void update() {}
+
+ /**
+ * Prompts NPC.
+ * TODO: should not be virtual, should invoke a scripting engine instead.
+ */
+ virtual void prompt(Character *, bool restart) = 0;
+
+ /**
+ * Selects an NPC proposition.
+ * TODO: should not be virtual, should invoke a scripting engine instead.
+ */
+ virtual void select(Character *, int) = 0;
+
+ /**
+ * Gets NPC ID.
+ */
+ int getNPC() const
+ { return mID; }
+
+ private:
+ unsigned short mID; /**< ID of the NPC. */
+};
+
+#endif
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index d9922df7..bcb93962 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -36,6 +36,7 @@
#include "game-server/mapcomposite.hpp"
#include "game-server/mapmanager.hpp"
#include "game-server/monster.hpp"
+#include "game-server/npc.hpp"
#include "net/messageout.hpp"
#include "utils/logger.h"
@@ -271,6 +272,12 @@ static void informPlayer(MapComposite *map, Character *p)
enterMsg.writeShort(q->getSpecy()->getType());
} break;
+ case OBJECT_NPC:
+ {
+ NPC *q = static_cast< NPC * >(o);
+ enterMsg.writeShort(q->getNPC());
+ } break;
+
default:
assert(false); // TODO
}
diff --git a/src/game-server/testing.cpp b/src/game-server/testing.cpp
index 01cb4e4f..7b875eaf 100644
--- a/src/game-server/testing.cpp
+++ b/src/game-server/testing.cpp
@@ -5,14 +5,52 @@
#include <cassert>
#include "defines.h"
+#include "game-server/gamehandler.hpp"
#include "game-server/item.hpp"
#include "game-server/itemmanager.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/mapmanager.hpp"
-#include "game-server/monstermanager.hpp"
-#include "game-server/spawnarea.hpp"
+#include "game-server/npc.hpp"
#include "game-server/state.hpp"
-#include "game-server/trigger.hpp"
+#include "net/messageout.hpp"
+
+// For testing purpose only, the NPC class is not meant to be inherited!!
+struct DummyNPC: NPC
+{
+ DummyNPC(): NPC(110) {}
+
+ void prompt(Character *q, bool restart)
+ {
+ if (restart)
+ {
+ MessageOut msg(GPMSG_NPC_MESSAGE);
+ msg.writeShort(getPublicID());
+ std::string text = "What do you want?";
+ msg.writeString(text, text.length());
+ gameHandler->sendTo(q, msg);
+ }
+ else
+ {
+ MessageOut msg(GPMSG_NPC_CHOICE);
+ msg.writeShort(getPublicID());
+ std::string text = "Guns! Lots of guns!:Nothing";
+ msg.writeString(text, text.length());
+ gameHandler->sendTo(q, msg);
+ }
+ }
+
+ void select(Character *q, int c)
+ {
+ if (c == 1)
+ {
+ MessageOut msg(GPMSG_NPC_MESSAGE);
+ msg.writeShort(getPublicID());
+ std::string text = "Sorry, this is a heroic-fantasy game, I do not have any gun.";
+ msg.writeString(text, text.length());
+ gameHandler->sendTo(q, msg);
+ }
+ }
+};
static void dropItem(MapComposite *map, int x, int y, int type)
{
@@ -34,6 +72,12 @@ void testingMap(MapComposite *map)
// Drop some items
dropItem(map, 58 * 32 + 16, 20 * 32 + 16, 508);
dropItem(map, 58 * 32 + 16, 21 * 32 + 16, 524);
+
+ // Add an NPC
+ NPC *q = new DummyNPC;
+ q->setMap(map);
+ q->setPosition(Point(50 * 32 + 16, 19 * 32 + 16));
+ GameState::insert(q);
} break;
}
}