summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/net/ea/beinghandler.cpp5
-rw-r--r--src/npc.cpp9
-rw-r--r--src/npc.h8
-rw-r--r--src/player.cpp41
-rw-r--r--src/player.h10
5 files changed, 53 insertions, 20 deletions
diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp
index 96c5986b..29c10900 100644
--- a/src/net/ea/beinghandler.cpp
+++ b/src/net/ea/beinghandler.cpp
@@ -397,8 +397,7 @@ void BeingHandler::handleMessage(MessageIn &msg)
switch (type) {
case 1: // eAthena LOOK_HAIR
- player->setSprite(Player::HAIR_SPRITE, id * -1,
- ColorDB::get(id2));
+ player->setSpriteID(Player::HAIR_SPRITE, id *-1);
break;
case 2: // Weapon ID in id, Shield ID in id2
player->setSprite(Player::WEAPON_SPRITE, id);
@@ -414,7 +413,7 @@ void BeingHandler::handleMessage(MessageIn &msg)
player->setSprite(Player::TOPCLOTHES_SPRITE, id);
break;
case 6: // eAthena LOOK_HAIR_COLOR
- // ignored (duplicate of LOOK_HAIR)
+ player->setSpriteColor(Player::HAIR_SPRITE, ColorDB::get(id));
break;
case 8: // eAthena LOOK_SHIELD
player->setSprite(Player::SHIELD_SPRITE, id);
diff --git a/src/npc.cpp b/src/npc.cpp
index dbae24e4..882f1b42 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -36,7 +36,7 @@ bool NPC::isTalking = false;
int current_npc = 0;
NPC::NPC(int id, int job, Map *map):
- Being(id, job, map)
+ Player(id, job, map, true)
{
NPCInfo info = NPCDB::get(job);
@@ -48,6 +48,8 @@ NPC::NPC(int id, int job, Map *map):
std::string file = "graphics/sprites/" + (*i)->sprite;
int variant = (*i)->variant;
mSprites.push_back(AnimatedSprite::load(file, variant));
+ mSpriteIDs.push_back(0);
+ mSpriteColors.push_back("");
}
if (mParticleEffects)
@@ -81,3 +83,8 @@ void NPC::talk()
Net::getNpcHandler()->talk(mId);
}
+
+void NPC::setSprite(unsigned int slot, int id, const std::string &color)
+{
+ // Do nothing
+}
diff --git a/src/npc.h b/src/npc.h
index 5335d8cd..46e48184 100644
--- a/src/npc.h
+++ b/src/npc.h
@@ -27,7 +27,7 @@
class Graphics;
class Text;
-class NPC : public Being
+class NPC : public Player
{
public:
NPC(int id, int job, Map *map);
@@ -38,6 +38,9 @@ class NPC : public Being
void talk();
+ void setSprite(unsigned int slot, int id,
+ const std::string &color = "");
+
/**
* Gets the way an NPC is blocked by other things on the map
*/
@@ -56,6 +59,9 @@ class NPC : public Being
*/
virtual Map::BlockType getBlockType() const
{ return Map::BLOCKTYPE_CHARACTER; } //blocks like a player character
+
+ // Colors don't change for NPCs
+ virtual void updateColors() {}
};
extern int current_npc;
diff --git a/src/player.cpp b/src/player.cpp
index 55888654..288c565d 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -38,16 +38,27 @@
#include "utils/stringutils.h"
-Player::Player(int id, int job, Map *map):
+Player::Player(int id, int job, Map *map, bool isNPC):
Being(id, job, map),
mGender(GENDER_UNSPECIFIED),
- mSpriteIDs(VECTOREND_SPRITE, 0),
- mSpriteColors(VECTOREND_SPRITE, ""),
mIsGM(false),
mInParty(false)
{
- for (int i = 0; i < VECTOREND_SPRITE; i++)
- mSprites.push_back(NULL);
+ if (!isNPC)
+ {
+ for (int i = 0; i < VECTOREND_SPRITE; i++)
+ {
+ mSprites.push_back(NULL);
+ mSpriteIDs.push_back(0);
+ mSpriteColors.push_back("");
+ }
+
+ /* Human base sprite. When implementing different races remove this
+ * line and set the base sprite when setting the race of the player
+ * character.
+ */
+ setSprite(BASE_SPRITE, -100);
+ }
mShowName = config.getValue("visiblenames", 1);
config.addListener("visiblenames", this);
@@ -125,14 +136,8 @@ void Player::setGender(Gender gender)
{
mGender = gender;
- /* Human base sprite. When implementing different races remove this
- * line and set the base sprite when setting the race of the player
- * character.
- */
- setSprite(BASE_SPRITE, -100);
-
// Reload all subsprites
- for (unsigned int i = 1; i < mSprites.size(); i++)
+ for (unsigned int i = 0; i < mSprites.size(); i++)
{
if (mSpriteIDs.at(i) != 0)
setSprite(i, mSpriteIDs.at(i), mSpriteColors.at(i));
@@ -147,7 +152,7 @@ void Player::setGM(bool gm)
updateColors();
}
-void Player::setSprite(int slot, int id, const std::string &color)
+void Player::setSprite(unsigned int slot, int id, const std::string &color)
{
assert(slot >= BASE_SPRITE && slot < VECTOREND_SPRITE);
@@ -193,6 +198,16 @@ void Player::setSprite(int slot, int id, const std::string &color)
mSpriteColors[slot] = color;
}
+void Player::setSpriteID(unsigned int slot, int id)
+{
+ setSprite(slot, id, mSpriteColors[slot]);
+}
+
+void Player::setSpriteColor(unsigned int slot, const std::string &color)
+{
+ setSprite(slot, mSpriteIDs[slot], color);
+}
+
#ifdef TMWSERV_SUPPORT
Guild* Player::addGuild(short guildId, short rights)
{
diff --git a/src/player.h b/src/player.h
index 36f0266e..3c4cc258 100644
--- a/src/player.h
+++ b/src/player.h
@@ -71,7 +71,7 @@ class Player : public Being
/**
* Constructor.
*/
- Player(int id, int job, Map *map);
+ Player(int id, int job, Map *map, bool isNPC = false);
~Player();
@@ -101,7 +101,13 @@ class Player : public Being
/**
* Sets visible equipments for this player.
*/
- virtual void setSprite(int slot, int id, const std::string &color = "");
+ virtual void setSprite(unsigned int slot, int id,
+ const std::string &color = "");
+
+ virtual void setSpriteID(unsigned int slot, int id);
+
+ virtual void setSpriteColor(unsigned int slot,
+ const std::string &color = "");
#ifdef TMWSERV_SUPPORT
/**