summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/viewport.cpp61
-rw-r--r--src/gui/viewport.h7
-rw-r--r--src/localplayer.cpp1
-rw-r--r--src/localplayer.h12
-rw-r--r--src/net/equipmenthandler.cpp5
-rw-r--r--src/net/protocol.h1
6 files changed, 87 insertions, 0 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 513a7ee5..96f44068 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -28,6 +28,7 @@
#include "gui.h"
#include "popupmenu.h"
+#include "../simpleanimation.h"
#include "../beingmanager.h"
#include "../configuration.h"
#include "../flooritemmanager.h"
@@ -36,7 +37,10 @@
#include "../map.h"
#include "../npc.h"
+#include "../resources/animation.h"
#include "../resources/monsterdb.h"
+#include "../resources/resourcemanager.h"
+#include "../resources/spriteset.h"
#include "../utils/tostring.h"
@@ -60,11 +64,35 @@ Viewport::Viewport():
config.addListener("ScrollRadius", this);
mPopupMenu = new PopupMenu();
+
+ // Load target cursors.
+ ResourceManager *resman = ResourceManager::getInstance();
+ Animation *animInRange = new Animation();
+ //Load animation frames into a spriteset, with each frame being 44x35
+ Spriteset *ssInRange = resman->getSpriteset("graphics/gui/target-cursor-blue.png", 44, 35);
+ for(int i = 0; i < 8; ++i)
+ {
+ //Have a delay of 75
+ animInRange->addFrame(ssInRange->get(i),75,0,0);
+ }
+ mTargetCursorInRange = new SimpleAnimation(animInRange);
+ Animation *animOutRange = new Animation();
+ //Load animation frames into a spriteset, with each frame being 44x35
+ Spriteset *ssOutRange = resman->getSpriteset("graphics/gui/target-cursor-red.png", 44, 35);
+ for(int j = 0; j < 8; ++j)
+ {
+ //Have a delay of 75
+ animOutRange->addFrame(ssOutRange->get(j),75,0,0);
+ }
+ mTargetCursorOutRange = new SimpleAnimation(animOutRange);
}
Viewport::~Viewport()
{
delete mPopupMenu;
+
+ delete mTargetCursorInRange;
+ delete mTargetCursorOutRange;
}
void
@@ -217,6 +245,39 @@ Viewport::draw(gcn::Graphics *gcnGraphics)
{
int mobId = target->mJob - 1002;
mobName = MonsterDB::get(mobId).getName();
+
+ // Find whether target is in range
+ int rangex = target->mX - player_node->mX;
+ int rangey = target->mY - player_node->mY;
+ int attackRange = player_node->getAttackRange();
+
+ // If either is negative, convert to positive
+ if (rangex < 0)
+ {
+ rangex = -rangex;
+ }
+ if (rangey < 0)
+ {
+ rangey = -rangey;
+ }
+
+ // Draw the target cursor, which one depends if the target is in range
+ if (rangex > attackRange || rangey > attackRange)
+ {
+ // Update animation frame and then draw the next image
+ mTargetCursorOutRange->update(10);
+ graphics->drawImage(mTargetCursorOutRange->getCurrentImage(),
+ target->getPixelX() - (int) mViewX,
+ target->getPixelY() - (int) mViewY);
+ }
+ else
+ {
+ // Update animation frame and then draw the next image
+ mTargetCursorInRange->update(10);
+ graphics->drawImage(mTargetCursorInRange->getCurrentImage(),
+ target->getPixelX() - (int) mViewX,
+ target->getPixelY() - (int) mViewY);
+ }
graphics->drawText(mobName,
target->getPixelX() - (int) mViewX + 15,
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index f1cadd98..45863228 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -35,6 +35,7 @@ class Being;
class FloorItem;
class Item;
class PopupMenu;
+class SimpleAnimation;
/**
* The viewport on the map. Displays the current map and handles mouse input
@@ -148,6 +149,12 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
int mCameraX; /**< Current viewpoint in tiles. */
int mCameraY; /**< Current viewpoint in tiles. */
bool mShowDebugPath; /**< Show a path from player to pointer. */
+
+ /**
+ * Target animated cursor.
+ */
+ SimpleAnimation *mTargetCursorInRange;
+ SimpleAnimation *mTargetCursorOutRange;
bool mPlayerFollowMouse;
int mWalkTime;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 2e583404..24976c0a 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -38,6 +38,7 @@ LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
Player(id, job, map),
+ mAttackRange(0),
mInventory(new Inventory()),
mTarget(NULL), mPickUpTarget(NULL),
mTrading(false), mLastAction(-1)
diff --git a/src/localplayer.h b/src/localplayer.h
index f4ba3747..55e63d40 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -92,6 +92,16 @@ class LocalPlayer : public Player
void useItem(Item *item);
void dropItem(Item *item, int quantity);
void pickUp(FloorItem *item);
+
+ /**
+ * Sets the attack range.
+ */
+ void setAttackRange(int range) { mAttackRange = range; }
+
+ /**
+ * Gets the attack range.
+ */
+ int getAttackRange() const { return mAttackRange; }
/**
* Sents a trade request to the given being.
@@ -162,6 +172,8 @@ class LocalPlayer : public Player
Uint32 mXpForNextLevel, mJobXpForNextLevel;
Uint16 mHp, mMaxHp, mMp, mMaxMp;
Uint32 mGp;
+
+ Uint16 mAttackRange;
Uint32 mTotalWeight, mMaxWeight;
diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp
index 01760eeb..74ce95f3 100644
--- a/src/net/equipmenthandler.cpp
+++ b/src/net/equipmenthandler.cpp
@@ -43,6 +43,7 @@ EquipmentHandler::EquipmentHandler()
0x01d7,
SMSG_PLAYER_UNEQUIP,
SMSG_PLAYER_ARROW_EQUIP,
+ SMSG_PLAYER_ATTACK_RANGE,
0
};
handledMessages = _messages;
@@ -191,6 +192,10 @@ void EquipmentHandler::handleMessage(MessageIn *msg)
logger->log("Unequipping: %i %i(%i) %i",
index, equipPoint, type, position);
break;
+
+ case SMSG_PLAYER_ATTACK_RANGE:
+ player_node->setAttackRange(msg->readInt16());
+ break;
case SMSG_PLAYER_ARROW_EQUIP:
itemId = msg->readInt16();
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 72b459ed..f755eda4 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -44,6 +44,7 @@
#define SMSG_PLAYER_EQUIPMENT 0x00a4
#define SMSG_PLAYER_EQUIP 0x00aa
#define SMSG_PLAYER_UNEQUIP 0x00ac
+#define SMSG_PLAYER_ATTACK_RANGE 0x013a
#define SMSG_PLAYER_ARROW_EQUIP 0x013c
#define SMSG_PLAYER_ARROW_MESSAGE 0x013b
#define SMSG_PLAYER_SKILLS 0x010f