summaryrefslogtreecommitdiff
path: root/src/npc.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-25 22:50:59 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-25 22:50:59 +0100
commitcc79f0fe21e1a2ef73cbe987d54e848b9a47142d (patch)
treeedd316eb6094f0c02d6d014385865dcd88a2bc56 /src/npc.cpp
parentb0df784f1be44a657ca8092069488602270629b7 (diff)
parent99e8a3fd77b63a029fe02dcf771b6af1aad252ed (diff)
downloadmana-cc79f0fe21e1a2ef73cbe987d54e848b9a47142d.tar.gz
mana-cc79f0fe21e1a2ef73cbe987d54e848b9a47142d.tar.bz2
mana-cc79f0fe21e1a2ef73cbe987d54e848b9a47142d.tar.xz
mana-cc79f0fe21e1a2ef73cbe987d54e848b9a47142d.zip
Merge branch 'eathena/master'
Conflicts: A lot of files.
Diffstat (limited to 'src/npc.cpp')
-rw-r--r--src/npc.cpp108
1 files changed, 18 insertions, 90 deletions
diff --git a/src/npc.cpp b/src/npc.cpp
index 792d1aa4..df43d548 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -20,11 +20,13 @@
*/
#include "animatedsprite.h"
+#include "beingmanager.h"
#include "npc.h"
#include "particle.h"
#include "text.h"
#include "gui/npc_text.h"
+#include "gui/palette.h"
#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/gameserver/player.h"
@@ -35,9 +37,8 @@
#include "resources/npcdb.h"
-extern NpcTextDialog *npcTextDialog;
-
-NPC *current_npc = 0;
+bool NPC::isTalking = false;
+int current_npc = 0;
static const int NAME_X_OFFSET = 15;
static const int NAME_Y_OFFSET = 30;
@@ -46,7 +47,7 @@ static const int NAME_Y_OFFSET = 30;
NPC::NPC(Uint16 id, int job, Map *map):
Player(id, job, map)
#else
-NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
+NPC::NPC(int id, Uint16 job, Map *map, Network *network):
Player(id, job, map),
mNetwork(network)
#endif
@@ -59,7 +60,8 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
i != info.sprites.end();
i++)
{
- if (c == VECTOREND_SPRITE) break;
+ if (c == VECTOREND_SPRITE)
+ break;
std::string file = "graphics/sprites/" + (*i)->sprite;
int variant = (*i)->variant;
@@ -80,14 +82,12 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
}
mName = 0;
- mNameColor = 0x21bbbb;
+ mNameColor = &guiPalette->getColor(Palette::NPC);
}
NPC::~NPC()
{
delete mName;
-
- if (current_npc == this) handleDeath();
}
void NPC::setName(const std::string &name)
@@ -96,7 +96,8 @@ void NPC::setName(const std::string &name)
delete mName;
mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET,
- gcn::Graphics::CENTER, gcn::Color(200, 200, 255));
+ gcn::Graphics::CENTER,
+ &guiPalette->getColor(Palette::NPC));
Being::setName(displayName + " (NPC)");
}
@@ -118,88 +119,25 @@ Being::Type NPC::getType() const
void NPC::talk()
{
-#ifdef TMWSERV_SUPPORT
- Net::GameServer::Player::talkToNPC(mId, true);
-#else
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_TALK);
- outMsg.writeInt32(mId);
- outMsg.writeInt8(0);
-#endif
- current_npc = this;
-}
+ if (isTalking)
+ return;
-void NPC::nextDialog()
-{
-#ifdef TMWSERV_SUPPORT
- Net::GameServer::Player::talkToNPC(mId, false);
-#else
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST);
- outMsg.writeInt32(mId);
-#endif
-}
+ isTalking = true;
-void NPC::dialogChoice(char choice)
-{
#ifdef TMWSERV_SUPPORT
- Net::GameServer::Player::selectFromNPC(mId, choice);
+ Net::GameServer::Player::talkToNPC(mId, true);
#else
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_LIST_CHOICE);
- outMsg.writeInt32(mId);
- outMsg.writeInt8(choice);
-#endif
-}
-
-void NPC::integerInput(int value)
-{
-#ifdef EATHENA_SUPPORT
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_INT_RESPONSE);
- outMsg.writeInt32(mId);
- outMsg.writeInt32(value);
-#endif
-}
+ if (!mNetwork)
+ return;
-void NPC::stringInput(const std::string &value)
-{
-#ifdef EATHENA_SUPPORT
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_STR_RESPONSE);
- outMsg.writeInt16(value.length() + 9);
- outMsg.writeInt32(mId);
- outMsg.writeString(value, value.length());
- outMsg.writeInt8(0);
-#endif
-}
-
-/*
- * TODO Unify the buy() and sell() methods, without sacrificing readability of
- * the code calling the method. buy(bool buySell) would be bad...
- */
-void NPC::buy()
-{
- // XXX Convert for new server
-#ifdef EATHENA_SUPPORT
MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST);
+ outMsg.writeInt16(CMSG_NPC_TALK);
+ outMsg.writeInt16(CMSG_NPC_TALK);
outMsg.writeInt32(mId);
outMsg.writeInt8(0);
#endif
}
-void NPC::sell()
-{
- // XXX Convert for new server
-#ifdef EATHENA_SUPPORT
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST);
- outMsg.writeInt32(mId);
- outMsg.writeInt8(1);
-#endif
-}
-
void NPC::updateCoords()
{
if (mName)
@@ -215,13 +153,3 @@ void NPC::updateCoords()
mName->adviseXY(px, py);
}
}
-
-void NPC::handleDeath()
-{
- printf("NPC::handleDeath\n");
- if (this != current_npc) return;
-
- if (npcTextDialog->isVisible())
- npcTextDialog->showCloseButton();
- else current_npc = NULL;
-}