From 502d5c892c92b4a71eceae1d275032100d42dd23 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Mon, 19 May 2008 15:07:45 +0000 Subject: Implemented NPC names. Implemented the theoretical possibility to have named monsters along the way. Note that the syntax of the LUA functions for creating NPCs has changed. --- src/game-server/being.hpp | 11 +++++++++++ src/game-server/character.cpp | 6 +++--- src/game-server/character.hpp | 11 ----------- src/game-server/mapreader.cpp | 2 +- src/game-server/npc.cpp | 3 ++- src/game-server/npc.hpp | 2 +- src/game-server/state.cpp | 2 ++ 7 files changed, 20 insertions(+), 17 deletions(-) (limited to 'src/game-server') diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp index b725bfee..6c7ff398 100644 --- a/src/game-server/being.hpp +++ b/src/game-server/being.hpp @@ -218,6 +218,16 @@ class Being : public MovingObject */ virtual void modifiedAttribute(int) {} + /** Gets the name of the being. */ + std::string const & + getName() const + { return mName; } + + /** Sets the name of the being. */ + void + setName(const std::string& name) + { mName = name; } + protected: static const int TICKS_PER_HP_REGENERATION = 100; Action mAction; @@ -227,6 +237,7 @@ class Being : public MovingObject Being(Being const &rhs); Being &operator=(Being const &rhs); + std::string mName; /**< Name of the being. */ Hits mHitsTaken; /**< List of punches taken since last update */ AttributeModifiers mModifiers; /**< Currently modified attributes. */ int mHpRegenTimer; /**< timer for hp regeneration*/ diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index e21de7c9..f169bd26 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -59,7 +59,7 @@ Character::Character(MessageIn &msg): mExperience.resize(CHAR_SKILL_NB, 0); // Get character data. mDatabaseID = msg.readLong(); - mName = msg.readString(); + setName(msg.readString()); deserializeCharacterData(*this, msg); for (int i = CHAR_ATTR_BEGIN; i < CHAR_ATTR_END; ++i) { @@ -120,7 +120,7 @@ void Character::respawn() { if (mAction != DEAD) { - LOG_WARN("Character \""<sendTo(this, levelupMsg); - LOG_INFO(mName<<" reached level "< mExperience; /**< experience collected for each skill.*/ - std::string mName; /**< Name of the character. */ int mDatabaseID; /**< Character's database ID. */ unsigned char mGender; /**< Gender of the character. */ unsigned char mHairStyle; /**< Hair Style of the character. */ diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp index 39d209d6..3d0a82ff 100644 --- a/src/game-server/mapreader.cpp +++ b/src/game-server/mapreader.cpp @@ -323,7 +323,7 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp if (npcId != -1 && scriptText != NULL) { - s->loadNPC(npcId, objX, objY, scriptText); + s->loadNPC(objName, npcId, objX, objY, scriptText); } else { diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp index abc425ec..fd462c50 100644 --- a/src/game-server/npc.cpp +++ b/src/game-server/npc.cpp @@ -24,9 +24,10 @@ #include "game-server/npc.hpp" #include "scripting/script.hpp" -NPC::NPC(int id, Script *s): +NPC::NPC(const std::string &name, int id, Script *s): Being(OBJECT_NPC, 65535), mScript(s), mID(id) { + setName(name); } void NPC::update() diff --git a/src/game-server/npc.hpp b/src/game-server/npc.hpp index 2d790c4c..c4d8b384 100644 --- a/src/game-server/npc.hpp +++ b/src/game-server/npc.hpp @@ -34,7 +34,7 @@ class Character; class NPC : public Being { public: - NPC(int id, Script *); + NPC(const std::string &name, int id, Script *); void update(); diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 03c6e3c1..a129e889 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -273,12 +273,14 @@ static void informPlayer(MapComposite *map, Character *p) { Monster *q = static_cast< Monster * >(o); enterMsg.writeShort(q->getSpecy()->getType()); + enterMsg.writeString(q->getName()); } break; case OBJECT_NPC: { NPC *q = static_cast< NPC * >(o); enterMsg.writeShort(q->getNPC()); + enterMsg.writeString(q->getName()); } break; default: -- cgit v1.2.3-60-g2f50