diff options
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 104 |
1 files changed, 76 insertions, 28 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index f72aa59a..245bd891 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -1,9 +1,8 @@ /* - * Aethyra + * The Mana World * Copyright (C) 2004 The Mana World Development Team * - * This file is part of Aethyra based on original code - * from The Mana World. + * This file is part of The Mana World. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,9 +33,11 @@ #include "particle.h" #include "simpleanimation.h" #include "sound.h" +#include "statuseffect.h" #include "text.h" #include "gui/gui.h" +#include "gui/ministatus.h" #include "gui/palette.h" #include "gui/storagewindow.h" @@ -69,7 +70,7 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map): ATK_BONUS(0), MATK_BONUS(0), DEF_BONUS(0), MDEF_BONUS(0), FLEE_BONUS(0), mStatPoint(0), mSkillPoint(0), mStatsPointsToAttribute(0), - mEquipment(new Equipment()), + mEquipment(new Equipment), mXp(0), mNetwork(0), mTarget(NULL), mPickUpTarget(NULL), mTrading(false), mGoingToTarget(false), @@ -180,20 +181,30 @@ void LocalPlayer::logic() if (mTarget) { - // Find whether target is in range - const int rangeX = abs(mTarget->mX - mX); - const int rangeY = abs(mTarget->mY - mY); - const int attackRange = getAttackRange(); - const int inRange = rangeX > attackRange || rangeY > attackRange ? 1 : 0; - - mTarget->setTargetAnimation( - mTargetCursor[inRange][mTarget->getTargetCursorSize()]); - - if (mTarget->mAction == DEAD) - stopAttack(); - - if (mKeepAttacking && mTarget) - attack(mTarget, true); + if (mTarget->getType() == Being::NPC) + { + // NPCs are always in range + mTarget->setTargetAnimation( + mTargetCursor[0][mTarget->getTargetCursorSize()]); + } + else + { + // Find whether target is in range + const int rangeX = abs(mTarget->mX - mX); + const int rangeY = abs(mTarget->mY - mY); + const int attackRange = getAttackRange(); + const int inRange = rangeX > attackRange || rangeY > attackRange + ? 1 : 0; + + mTarget->setTargetAnimation( + mTargetCursor[inRange][mTarget->getTargetCursorSize()]); + + if (mTarget->mAction == DEAD) + stopAttack(); + + if (mKeepAttacking && mTarget) + attack(mTarget, true); + } } Being::logic(); @@ -413,10 +424,7 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) void LocalPlayer::setWalkingDir(int dir) { - if (mWalkingDir != dir) - { - mWalkingDir = dir; - } + mWalkingDir = dir; // If we're not already walking, start walking. if (mAction != WALK && dir) @@ -526,7 +534,7 @@ void LocalPlayer::attack(Being *target, bool keep) { mKeepAttacking = keep; - if (!target) + if (!target || target->getType() == Being::NPC) return; if ((mTarget != target) || !mTarget) @@ -538,10 +546,8 @@ void LocalPlayer::attack(Being *target, bool keep) int dist_x = target->mX - mX; int dist_y = target->mY - mY; - // Must be standing and be within attack range to continue - if ((mAction != STAND) || (mAttackRange < abs(dist_x)) || - (mAttackRange < abs(dist_y))) - return; + // Must be standing to attack + if (mAction != STAND) return; if (abs(dist_y) >= abs(dist_x)) { @@ -650,6 +656,48 @@ void LocalPlayer::setGotoTarget(Being *target) setDestination(target->mX, target->mY); } + +extern MiniStatusWindow *miniStatusWindow; + +void LocalPlayer::handleStatusEffect(StatusEffect *effect, int effectId) +{ + Being::handleStatusEffect(effect, effectId); + + + + if (effect) { + effect->deliverMessage(); + effect->playSFX(); + + AnimatedSprite *sprite = effect->getIcon(); + + if (!sprite) { + // delete sprite, if necessary + for (unsigned int i = 0; i < mStatusEffectIcons.size();) + if (mStatusEffectIcons[i] == effectId) { + mStatusEffectIcons.erase(mStatusEffectIcons.begin() + i); + miniStatusWindow->eraseIcon(i); + } else i++; + } else { + // replace sprite or append + bool found = false; + + for (unsigned int i = 0; i < mStatusEffectIcons.size(); i++) + if (mStatusEffectIcons[i] == effectId) { + miniStatusWindow->setIcon(i, sprite); + found = true; + break; + } + + if (!found) { // add new + int offset = mStatusEffectIcons.size(); + miniStatusWindow->setIcon(offset, sprite); + mStatusEffectIcons.push_back(effectId); + } + } + } +} + void LocalPlayer::initTargetCursor() { // Load target cursors @@ -679,7 +727,7 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height, ResourceManager *resman = ResourceManager::getInstance(); currentImageSet = resman->getImageSet(filename, width, height); - Animation *anim = new Animation(); + Animation *anim = new Animation; for (unsigned int i = 0; i < currentImageSet->size(); ++i) { |