| 1 |
/* |
| 2 |
* The Mana World |
| 3 |
* Copyright (C) 2004 The Mana World Development Team |
| 4 |
* |
| 5 |
* This file is part of The Mana World. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "animatedsprite.h" |
| 23 |
#include "beingmanager.h" |
| 24 |
#include "npc.h" |
| 25 |
#include "particle.h" |
| 26 |
#include "text.h" |
| 27 |
|
| 28 |
#include "gui/palette.h" |
| 29 |
|
| 30 |
#include "net/net.h" |
| 31 |
#include "net/npchandler.h" |
| 32 |
|
| 33 |
#include "resources/npcdb.h" |
| 34 |
|
| 35 |
bool NPC::isTalking = false; |
| 36 |
int current_npc = 0; |
| 37 |
|
| 38 |
NPC::NPC(int id, int job, Map *map): |
| 39 |
Player(id, job, map, true) |
| 40 |
{ |
| 41 |
NPCInfo info = NPCDB::get(job); |
| 42 |
|
| 43 |
// Setup NPC sprites |
| 44 |
for (std::list<NPCsprite*>::const_iterator i = info.sprites.begin(); |
| 45 |
i != info.sprites.end(); |
| 46 |
i++) |
| 47 |
{ |
| 48 |
std::string file = "graphics/sprites/" + (*i)->sprite; |
| 49 |
int variant = (*i)->variant; |
| 50 |
mSprites.push_back(AnimatedSprite::load(file, variant)); |
| 51 |
mSpriteIDs.push_back(0); |
| 52 |
mSpriteColors.push_back(""); |
| 53 |
} |
| 54 |
|
| 55 |
if (mParticleEffects) |
| 56 |
{ |
| 57 |
//setup particle effects |
| 58 |
for (std::list<std::string>::const_iterator i = info.particles.begin(); |
| 59 |
i != info.particles.end(); |
| 60 |
i++) |
| 61 |
{ |
| 62 |
Particle *p = particleEngine->addEffect(*i, 0, 0); |
| 63 |
this->controlParticle(p); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
setShowName(true); |
| 68 |
} |
| 69 |
|
| 70 |
void NPC::setName(const std::string &name) |
| 71 |
{ |
| 72 |
const std::string displayName = name.substr(0, name.find('#', 0)); |
| 73 |
|
| 74 |
Being::setName(displayName); |
| 75 |
} |
| 76 |
|
| 77 |
void NPC::talk() |
| 78 |
{ |
| 79 |
if (isTalking) |
| 80 |
return; |
| 81 |
|
| 82 |
isTalking = true; |
| 83 |
|
| 84 |
Net::getNpcHandler()->talk(mId); |
| 85 |
} |
| 86 |
|
| 87 |
void NPC::setSprite(unsigned int slot, int id, const std::string &color) |
| 88 |
{ |
| 89 |
// Do nothing |
| 90 |
} |