From 11a6f342e579c26320334b9ae9735701386e3b25 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 13 Apr 2010 22:48:28 -0600 Subject: Add race support for eAthena The job/class field is used to select the race. If the given race isn't defined, it falls back on the first race (so servers can use jobs/classes without races). Also rename job to subtype for Being and subclasses, and begin support for changing monster and NPC subtypes on the fly (particle effects still need to be reset when they change). Reviewed-by: Bertram --- src/monster.cpp | 69 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 30 deletions(-) (limited to 'src/monster.cpp') diff --git a/src/monster.cpp b/src/monster.cpp index 23be9395..0876b08d 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -35,37 +35,11 @@ #include "resources/monsterdb.h" #include "resources/monsterinfo.h" -Monster::Monster(int id, int job, Map *map): - Being(id, job, map), +Monster::Monster(int id, int subtype, Map *map): + Being(id, subtype, map), mAttackType(1) { - const MonsterInfo &info = getInfo(); - - // Setup Monster sprites - const std::list &sprites = info.getSprites(); - - for (std::list::const_iterator i = sprites.begin(); - i != sprites.end(); i++) - { - std::string file = "graphics/sprites/" + *i; - mSprites.push_back(AnimatedSprite::load(file)); - } - - // Ensure that something is shown - if (mSprites.size() == 0) - { - mSprites.push_back(AnimatedSprite::load("graphics/sprites/error.xml")); - } - - if (Particle::enabled) - { - const std::list &particleEffects = info.getParticleEffects(); - for (std::list::const_iterator i = particleEffects.begin(); - i != particleEffects.end(); i++) - { - controlParticle(particleEngine->addEffect((*i), 0, 0)); - } - } + setSubtype(subtype); mNameColor = &userPalette->getColor(UserPalette::MONSTER); mTextColor = &userPalette->getColor(UserPalette::MONSTER); @@ -86,6 +60,7 @@ void Monster::logic() Being::logic(); } + void Monster::setAction(Action action, int attackType) { SpriteAction currentAction = ACTION_INVALID; @@ -144,6 +119,40 @@ void Monster::setAction(Action action, int attackType) } } +void Monster::setSubtype(Uint16 subtype) +{ + Being::setSubtype(subtype); + + const MonsterInfo &info = getInfo(); + + // Setup Monster sprites + const std::list &sprites = info.getSprites(); + + mSprites.clear(); + for (std::list::const_iterator i = sprites.begin(); + i != sprites.end(); i++) + { + std::string file = "graphics/sprites/" + *i; + mSprites.push_back(AnimatedSprite::load(file)); + } + + // Ensure that something is shown + if (mSprites.size() == 0) + { + mSprites.push_back(AnimatedSprite::load("graphics/sprites/error.xml")); + } + + if (Particle::enabled) + { + const std::list &particleEffects = info.getParticleEffects(); + for (std::list::const_iterator i = particleEffects.begin(); + i != particleEffects.end(); i++) + { + controlParticle(particleEngine->addEffect((*i), 0, 0)); + } + } +} + void Monster::handleAttack(Being *victim, int damage, AttackType type) { Being::handleAttack(victim, damage, type); @@ -170,7 +179,7 @@ Being::TargetCursorSize Monster::getTargetCursorSize() const const MonsterInfo &Monster::getInfo() const { - return MonsterDB::get(mJob); + return MonsterDB::get(mSubType); } void Monster::updateCoords() -- cgit v1.2.3-70-g09d2