summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYohann Ferreira <yohann.ferreira@orange.fr>2013-02-01 17:09:03 -0800
committerYohann Ferreira <yohann.ferreira@orange.fr>2013-02-01 17:09:03 -0800
commiteb6dfbbcd8091f645834d9076d07995b336dbfd1 (patch)
treecfac4bd22d13a7f99a8983d18d65018d1a5bb333
parent5c7bf62ca3204c6f8b91f1bd9178cb638e184f5a (diff)
parent05187cd8af0de4d3d50b8ffb9a0801e47cb00d34 (diff)
downloadmanaserv-eb6dfbbcd8091f645834d9076d07995b336dbfd1.tar.gz
manaserv-eb6dfbbcd8091f645834d9076d07995b336dbfd1.tar.xz
manaserv-eb6dfbbcd8091f645834d9076d07995b336dbfd1.zip
Merge pull request #11 from Bertram25/manaserv-emotes-support
Added emote support. Reviewed-by: Ablu
-rw-r--r--example/effects.xml2
-rw-r--r--example/emotes.xml37
-rw-r--r--gameserver.cbp2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/common/manaserv_protocol.h2
-rw-r--r--src/game-server/actor.h3
-rw-r--r--src/game-server/attribute.h2
-rw-r--r--src/game-server/being.cpp11
-rw-r--r--src/game-server/being.h14
-rw-r--r--src/game-server/emotemanager.cpp70
-rw-r--r--src/game-server/emotemanager.h64
-rw-r--r--src/game-server/gamehandler.cpp12
-rw-r--r--src/game-server/gamehandler.h2
-rw-r--r--src/game-server/main-game.cpp5
-rw-r--r--src/game-server/mapcomposite.cpp4
-rw-r--r--src/game-server/state.cpp13
16 files changed, 220 insertions, 25 deletions
diff --git a/example/effects.xml b/example/effects.xml
index 90de57e..57e1c75 100644
--- a/example/effects.xml
+++ b/example/effects.xml
@@ -12,7 +12,6 @@
<effect id="4" particle="graphics/particles/arrow-hail.xml" />
<!-- Emotion effects -->
- <effect id="10000" particle="graphics/particles/emotes/emote-disgust.particle.xml"/>
<effect id="10001" particle="graphics/particles/emotes/emote-surprise.particle.xml"/>
<effect id="10002" particle="graphics/particles/emotes/emote-happy.particle.xml"/>
<effect id="10003" particle="graphics/particles/emotes/emote-sad.particle.xml"/>
@@ -26,4 +25,5 @@
<effect id="10011" particle="graphics/particles/emotes/emote-perturbed.particle.xml"/>
<effect id="10012" particle="graphics/particles/emotes/emote-speech.particle.xml"/>
<effect id="10013" particle="graphics/particles/emotes/emote-blah.particle.xml"/>
+ <effect id="10014" particle="graphics/particles/emotes/emote-disgust.particle.xml"/>
</effects>
diff --git a/example/emotes.xml b/example/emotes.xml
index 0136b13..7b8ae73 100644
--- a/example/emotes.xml
+++ b/example/emotes.xml
@@ -1,101 +1,100 @@
<?xml version="1.0"?>
<emotes>
<emote id="0"
- name="Disgust"
- effectid="10000"
- image="graphics/particles/emotes/disgust.png"
- width="30" height="32">
- </emote>
-
- <emote id="1"
name="Surprise"
effectid="10001"
image="graphics/particles/emotes/surprise.png"
width="30" height="32">
</emote>
- <emote id="2"
+ <emote id="1"
name="Happy"
effectid="10002"
image="graphics/particles/emotes/happy.png"
width="30" height="32">
</emote>
- <emote id="3"
+ <emote id="2"
name="Sad"
effectid="10003"
image="graphics/particles/emotes/sad.png"
width="30" height="32">
</emote>
- <emote id="4"
+ <emote id="3"
name="Evil"
effectid="10004"
image="graphics/particles/emotes/evil.png"
width="30" height="32">
</emote>
- <emote id="5"
+ <emote id="4"
name="Wink"
effectid="10005"
image="graphics/particles/emotes/wink.png"
width="30" height="32">
</emote>
- <emote id="6"
+ <emote id="5"
name="Angel"
effectid="10006"
image="graphics/particles/emotes/angel.png"
width="30" height="32">
</emote>
- <emote id="7"
+ <emote id="6"
name="Blush"
effectid="10007"
image="graphics/particles/emotes/blush.png"
width="30" height="32">
</emote>
- <emote id="8"
+ <emote id="7"
name="Tongue"
effectid="10008"
image="graphics/particles/emotes/tongue.png"
width="30" height="32">
</emote>
- <emote id="9"
+ <emote id="8"
name="Grin"
effectid="10009"
image="graphics/particles/emotes/grin.png"
width="30" height="32">
</emote>
- <emote id="10"
+ <emote id="9"
name="Upset"
effectid="10010"
image="graphics/particles/emotes/upset.png"
width="30" height="32">
</emote>
- <emote id="11"
+ <emote id="10"
name="Perturbed"
effectid="10011"
image="graphics/particles/emotes/perturbed.png"
width="30" height="32">
</emote>
- <emote id="12"
+ <emote id="11"
name="Speech"
effectid="10012"
image="graphics/particles/emotes/speech.png"
width="30" height="32">
</emote>
- <emote id="13"
+ <emote id="12"
name="Blah"
effectid="10013"
image="graphics/particles/emotes/blah.png"
width="30" height="32">
</emote>
+ <emote id="13"
+ name="Disgust"
+ effectid="10014"
+ image="graphics/particles/emotes/disgust.png"
+ width="30" height="32">
+ </emote>
</emotes>
diff --git a/gameserver.cbp b/gameserver.cbp
index ef0fc32..14d1dc1 100644
--- a/gameserver.cbp
+++ b/gameserver.cbp
@@ -132,6 +132,8 @@
<Unit filename="src/game-server/commandhandler.h" />
<Unit filename="src/game-server/effect.cpp" />
<Unit filename="src/game-server/effect.h" />
+ <Unit filename="src/game-server/emotemanager.cpp" />
+ <Unit filename="src/game-server/emotemanager.h" />
<Unit filename="src/game-server/entity.cpp" />
<Unit filename="src/game-server/entity.h" />
<Unit filename="src/game-server/eventlistener.h" />
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 73f969f..1d06c5d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -215,6 +215,8 @@ SET(SRCS_MANASERVGAME
game-server/commandhandler.h
game-server/effect.h
game-server/effect.cpp
+ game-server/emotemanager.h
+ game-server/emotemanager.cpp
game-server/entity.h
game-server/entity.cpp
game-server/gamehandler.h
diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h
index 913a126..1fc85ba 100644
--- a/src/common/manaserv_protocol.h
+++ b/src/common/manaserv_protocol.h
@@ -133,6 +133,8 @@ enum {
GPMSG_BEING_LEAVE = 0x0201, // W being id
GPMSG_ITEM_APPEAR = 0x0202, // W item id, W*2 position
GPMSG_BEING_LOOKS_CHANGE = 0x0210, // B sprite layers changed, { B slot type, W item id }*
+ GPMSG_BEING_EMOTE = 0x0211, // W being id, W emote id
+ PGMSG_BEING_EMOTE = 0x0212, // W emoticon id
PGMSG_WALK = 0x0260, // W*2 destination
PGMSG_ACTION_CHANGE = 0x0270, // B Action
GPMSG_BEING_ACTION_CHANGE = 0x0271, // W being id, B action
diff --git a/src/game-server/actor.h b/src/game-server/actor.h
index 324393d..13d4af5 100644
--- a/src/game-server/actor.h
+++ b/src/game-server/actor.h
@@ -37,7 +37,8 @@ enum
UPDATEFLAG_ACTIONCHANGE = 8,
UPDATEFLAG_LOOKSCHANGE = 16,
UPDATEFLAG_DIRCHANGE = 32,
- UPDATEFLAG_HEALTHCHANGE = 64
+ UPDATEFLAG_HEALTHCHANGE = 64,
+ UPDATEFLAG_EMOTE = 128
};
/**
diff --git a/src/game-server/attribute.h b/src/game-server/attribute.h
index 82303ff..736e54a 100644
--- a/src/game-server/attribute.h
+++ b/src/game-server/attribute.h
@@ -134,8 +134,8 @@ class Attribute
public:
Attribute()
: mBase(0)
- , mMaxValue(0)
, mMinValue(0)
+ , mMaxValue(0)
{throw;} // DEBUG; Find improper constructions
Attribute(const AttributeManager::AttributeInfo &info);
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 0e24087..d7df2df 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -41,7 +41,8 @@ Being::Being(EntityType type):
mTarget(NULL),
mGender(GENDER_UNSPECIFIED),
mCurrentAttack(0),
- mDirection(DOWN)
+ mDirection(DOWN),
+ mEmoteId(0)
{
const AttributeManager::AttributeScope &attr = attributeManager->getAttributeScope(BeingScope);
LOG_DEBUG("Being creation: initialisation of " << attr.size() << " attributes.");
@@ -73,6 +74,14 @@ Being::Being(EntityType type):
#endif
}
+void Being::triggerEmote(int id)
+{
+ mEmoteId = id;
+
+ if (id > -1)
+ raiseUpdateFlags(UPDATEFLAG_EMOTE);
+}
+
int Being::damage(Actor * /* source */, const Damage &damage)
{
if (mAction == DEAD)
diff --git a/src/game-server/being.h b/src/game-server/being.h
index a08df01..d5a7358 100644
--- a/src/game-server/being.h
+++ b/src/game-server/being.h
@@ -299,6 +299,17 @@ class Being : public Actor
sigc::signal<void, Being *> signal_died;
+ /**
+ * Activate an emote flag on the being.
+ */
+ void triggerEmote(int id);
+
+ /**
+ * Tells the last emote used.
+ */
+ int getLastEmote() const
+ { return mEmoteId; }
+
protected:
/**
* Performs an attack
@@ -342,6 +353,9 @@ class Being : public Actor
/** Time until hp is regenerated again */
Timeout mHealthRegenerationTimeout;
+
+ /** The last being emote Id. Used when triggering a being emoticon. */
+ int mEmoteId;
};
#endif // BEING_H
diff --git a/src/game-server/emotemanager.cpp b/src/game-server/emotemanager.cpp
new file mode 100644
index 0000000..35f0aa4
--- /dev/null
+++ b/src/game-server/emotemanager.cpp
@@ -0,0 +1,70 @@
+/*
+ * The Mana Server
+ * Copyright (C) 2012 The Mana Developers
+ *
+ * This file is part of The Mana Server.
+ *
+ * The Mana Server 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 Server 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 Server. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "emotemanager.h"
+
+#include "utils/xml.h"
+#include "utils/logger.h"
+
+void EmoteManager::initialize()
+{
+ clear();
+
+ XML::Document doc(mEmoteFile);
+ xmlNodePtr rootNode = doc.rootNode();
+
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes"))
+ {
+ LOG_ERROR("Emote Manager: " << mEmoteFile
+ << " is not a valid emote file!");
+ return;
+ }
+
+ LOG_INFO("Loading emote reference: " << mEmoteFile);
+
+ for_each_xml_child_node(emoteNode, rootNode)
+ {
+ if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote"))
+ continue;
+
+ int id = XML::getProperty(emoteNode, "id", -1);
+ if (id < 0)
+ {
+ LOG_WARN("The " << mEmoteFile << " file is containing an invalid id"
+ "(" << id << ") and will be ignored.");
+ continue;
+ }
+
+ mEmoteIds.push_back(id);
+ }
+ LOG_INFO(mEmoteIds.size() << " emotes available.");
+}
+
+bool EmoteManager::isIdAvailable(int id) const
+{
+ std::vector<int>::const_iterator it = mEmoteIds.begin();
+ std::vector<int>::const_iterator it_end = mEmoteIds.end();
+ for (; it != it_end; ++it)
+ {
+ if ((*it) == id)
+ return true;
+ }
+ return false;
+}
diff --git a/src/game-server/emotemanager.h b/src/game-server/emotemanager.h
new file mode 100644
index 0000000..42c7168
--- /dev/null
+++ b/src/game-server/emotemanager.h
@@ -0,0 +1,64 @@
+/*
+ * The Mana Server
+ * Copyright (C) 2011-2012 The Mana Developers
+ *
+ * This file is part of The Mana Server.
+ *
+ * The Mana Server 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 Server 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 Server. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef EMOTEMANAGER_H
+#define EMOTEMANAGER_H
+
+#include "utils/string.h"
+#include "utils/xml.h"
+
+#include <vector>
+
+class EmoteManager
+{
+public:
+
+ EmoteManager(const std::string &emoteFile):
+ mEmoteFile(emoteFile)
+ { }
+
+ ~EmoteManager()
+ { clear(); }
+
+ /**
+ * Loads emote reference file.
+ */
+ void initialize();
+
+ /**
+ * Tells whether the given id is a valid emote one.
+ */
+ bool isIdAvailable(int id) const;
+
+private:
+ /**
+ * Clears up the emote list.
+ */
+ void clear()
+ { mEmoteIds.clear(); }
+
+ std::string mEmoteFile;
+ std::vector<int> mEmoteIds;
+};
+
+extern EmoteManager *emoteManager;
+
+#endif // EMOTEMANAGER_H
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 18059d6..3b356a5 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -28,6 +28,7 @@
#include "game-server/accountconnection.h"
#include "game-server/buysell.h"
#include "game-server/commandhandler.h"
+#include "game-server/emotemanager.h"
#include "game-server/inventory.h"
#include "game-server/item.h"
#include "game-server/itemmanager.h"
@@ -302,6 +303,10 @@ void GameHandler::processMessage(NetComputer *computer, MessageIn &message)
handlePartyInvite(client, message);
break;
+ case PGMSG_BEING_EMOTE:
+ handleTriggerEmoticon(client, message);
+ break;
+
default:
LOG_WARN("Invalid message type");
client.send(MessageOut(XXMSG_INVALID));
@@ -919,6 +924,13 @@ void GameHandler::handlePartyInvite(GameClient &client, MessageIn &message)
client.send(out);
}
+void GameHandler::handleTriggerEmoticon(GameClient &client, MessageIn &message)
+{
+ const int id = message.readInt16();
+ if (emoteManager->isIdAvailable(id))
+ client.character->triggerEmote(id);
+}
+
void GameHandler::sendNpcError(GameClient &client, int id,
const std::string &errorMsg)
{
diff --git a/src/game-server/gamehandler.h b/src/game-server/gamehandler.h
index c0d843e..c05e008 100644
--- a/src/game-server/gamehandler.h
+++ b/src/game-server/gamehandler.h
@@ -152,6 +152,8 @@ class GameHandler: public ConnectionHandler
void handlePartyInvite(GameClient &client, MessageIn &message);
+ void handleTriggerEmoticon(GameClient &client, MessageIn &message);
+
void sendNpcError(GameClient &client, int id,
const std::string &errorMsg);
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 406e7c5..5814f0b 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -25,6 +25,7 @@
#include "game-server/accountconnection.h"
#include "game-server/attributemanager.h"
#include "game-server/gamehandler.h"
+#include "game-server/emotemanager.h"
#include "game-server/itemmanager.h"
#include "game-server/mapmanager.h"
#include "game-server/monstermanager.h"
@@ -74,6 +75,7 @@ using utils::Logger;
#define DEFAULT_PERMISSION_FILE "permissions.xml"
#define DEFAULT_MAIN_SCRIPT_FILE "scripts/main.lua"
#define DEFAULT_SPECIALSDB_FILE "specials.xml"
+#define DEFAULT_EMOTESDB_FILE "emotes.xml"
static int const WORLD_TICK_SKIP = 2; /** tolerance for lagging behind in world calculation) **/
@@ -89,6 +91,7 @@ ItemManager *itemManager = new ItemManager(DEFAULT_ITEMSDB_FILE, DEFAULT_EQUIPDB
MonsterManager *monsterManager = new MonsterManager(DEFAULT_MONSTERSDB_FILE);
SkillManager *skillManager = new SkillManager(DEFAULT_SKILLSDB_FILE);
SpecialManager *specialManager = new SpecialManager(DEFAULT_SPECIALSDB_FILE);
+EmoteManager *emoteManager = new EmoteManager(DEFAULT_EMOTESDB_FILE);
/** Core game message handler */
GameHandler *gameHandler;
@@ -141,6 +144,7 @@ static void initializeServer()
specialManager->initialize();
itemManager->initialize();
monsterManager->initialize();
+ emoteManager->initialize();
StatusManager::initialize(DEFAULT_STATUSDB_FILE);
PermissionManager::initialize(DEFAULT_PERMISSION_FILE);
@@ -196,6 +200,7 @@ static void deinitializeServer()
delete monsterManager; monsterManager = 0;
delete skillManager; skillManager = 0;
delete itemManager; itemManager = 0;
+ delete emoteManager; emoteManager = 0;
MapManager::deinitialize();
StatusManager::deinitialize();
ScriptManager::deinitialize();
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 485492d..4c7dc66 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -464,10 +464,10 @@ Script::Ref MapComposite::mUpdateCallback;
MapComposite::MapComposite(int id, const std::string &name):
mActive(false),
mMap(0),
- mPvPRules(PVP_NONE),
mContent(0),
mName(name),
- mID(id)
+ mID(id),
+ mPvPRules(PVP_NONE)
{
}
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index 006075b..6fdfb6f 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -193,6 +193,19 @@ static void informPlayer(MapComposite *map, Character *p)
gameHandler->sendTo(p, LooksMsg);
}
+ // Send emote messages.
+ if (oflags & UPDATEFLAG_EMOTE)
+ {
+ int emoteId = o->getLastEmote();
+ if (emoteId > -1)
+ {
+ MessageOut EmoteMsg(GPMSG_BEING_EMOTE);
+ EmoteMsg.writeInt16(oid);
+ EmoteMsg.writeInt16(emoteId);
+ gameHandler->sendTo(p, EmoteMsg);
+ }
+ }
+
// Send direction change messages.
if (oflags & UPDATEFLAG_DIRCHANGE)
{