From ad82c549b87e9254a039dcfcfbdaca349ac66ccd Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Thu, 29 Dec 2011 05:08:02 -0200 Subject: [PATCH] walk fixed, animated text changes --- src/otclient/core/animatedtext.cpp | 3 +- src/otclient/core/creature.cpp | 8 ++--- src/otclient/core/creature.h | 2 +- src/otclient/core/localplayer.cpp | 46 +++++++++++++++++++++----- src/otclient/core/localplayer.h | 3 +- src/otclient/net/protocolgameparse.cpp | 2 +- src/otclient/ui/uimap.cpp | 10 ++++-- 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/otclient/core/animatedtext.cpp b/src/otclient/core/animatedtext.cpp index 22db49b2..ec95a264 100644 --- a/src/otclient/core/animatedtext.cpp +++ b/src/otclient/core/animatedtext.cpp @@ -25,6 +25,7 @@ #include "map.h" #include #include +#include AnimatedText::AnimatedText() { @@ -46,7 +47,7 @@ void AnimatedText::start() void AnimatedText::draw(const Point& p) { if(m_font) - m_font->renderText(m_text, Rect(p + Point(0, -20.0 * g_clock.timeElapsed(m_startTime) / (DURATION / 1000)), m_textSize), Fw::AlignTopCenter, m_color); + m_font->renderText(m_text, Rect(p + Point(20 - m_textSize.width() / 2, -20.0 * g_clock.timeElapsed(m_startTime) / (DURATION / 1000)), m_textSize), Fw::AlignLeft, m_color); } void AnimatedText::setColor(int color) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 8a7fbca1..c3f54731 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -130,14 +130,14 @@ void Creature::drawInformation(int x, int y, bool useGray, const Rect& rect) Rect backgroundRect = Rect(x-(13.5), y, 27, 4); backgroundRect.bound(rect); - Rect textRect = Rect(x - m_nameSize.width() / 2.0, y-15, m_nameSize); + Rect textRect = Rect(x - m_nameSize.width() / 2.0, y-12, m_nameSize); textRect.bound(rect); // distance them if(textRect.top() == rect.top()) - backgroundRect.moveTop(textRect.top() + 15); + backgroundRect.moveTop(textRect.top() + 12); if(backgroundRect.bottom() == rect.bottom()) - textRect.moveTop(backgroundRect.top() - 15); + textRect.moveTop(backgroundRect.top() - 12); // health rect is based on background rect, so no worries Rect healthRect = backgroundRect.expanded(-1); @@ -251,7 +251,7 @@ void Creature::updateWalk() g_dispatcher.scheduleEvent(std::bind(&Creature::updateWalk, asCreature()), m_walkTimePerPixel); } -void Creature::cancelWalk(Otc::Direction direction) +void Creature::cancelWalk(Otc::Direction direction, bool) { m_walking = false; m_walkStart = 0; diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index f754ccb5..2dc388c1 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -62,7 +62,7 @@ public: virtual void walk(const Position& position, bool inverse = true); void turn(Otc::Direction direction); - virtual void cancelWalk(Otc::Direction direction); + virtual void cancelWalk(Otc::Direction direction, bool force = false); Point getWalkOffset() { return m_walkOffset; } bool isWalking() { return m_walking; } diff --git a/src/otclient/core/localplayer.cpp b/src/otclient/core/localplayer.cpp index 52aa1e52..6a281b4b 100644 --- a/src/otclient/core/localplayer.cpp +++ b/src/otclient/core/localplayer.cpp @@ -28,10 +28,12 @@ LocalPlayer::LocalPlayer() { m_clientWalking = false; + m_nextWalkDirection = Otc::InvalidDirection; } void LocalPlayer::clientWalk(Otc::Direction direction) { + // We're not walking, so start a client walk. if(!m_walking) { Position newPos = m_position + Position::getPositionFromDirection(direction); Creature::walk(newPos, false); @@ -41,33 +43,59 @@ void LocalPlayer::clientWalk(Otc::Direction direction) void LocalPlayer::walk(const Position& position, bool inverse) { + // This can only be received by protocol, so its always inverse. + + // If we're already walking, just finish it. if(m_clientWalking) { + m_clientWalking = false; + Position pos = Position::getPositionFromDirection(m_direction); Point walkOffset = Point(m_walkOffset.x - pos.x * 32, m_walkOffset.y - pos.y * 32); Creature::walk(position, inverse); + // Restore walk offset, because we were already walking. m_walkOffset = walkOffset; - m_clientWalking = false; } - else { - m_walkOffset.x = 0; - m_walkOffset.y = 0; + // If we're not client walking, we'll just walk like every NPC. Ie: When player is pushed. + else Creature::walk(position, inverse); - } } -void LocalPlayer::cancelWalk(Otc::Direction direction) +void LocalPlayer::cancelWalk(Otc::Direction direction, bool force) { - m_clientWalking = false; - Creature::cancelWalk(direction); + // Server said we cant walk. Ie: houses, vip areas. + if(force) { + m_clientWalking = false; + Creature::cancelWalk(direction); + } + else { + // Walk finished, and we already received the confirmation from server. + if(m_walking && !m_clientWalking) { + m_clientWalking = false; + Creature::cancelWalk(direction); + + if(m_nextWalkDirection != Otc::InvalidDirection) { + g_game.walk(m_nextWalkDirection); + m_nextWalkDirection = Otc::InvalidDirection; + } + } + //else.. + // Walk finished, however we havent received the confirmation from server. So wait for it. + } } bool LocalPlayer::canWalk(Otc::Direction direction) { - if(m_walking) + if(m_walking) { + if(direction != m_direction && m_nextWalkDirection != direction) + m_nextWalkDirection = direction; + else if(direction == m_direction && m_nextWalkDirection != Otc::InvalidDirection) + m_nextWalkDirection = Otc::InvalidDirection; + return false; + } Position newPos = m_position + Position::getPositionFromDirection(direction); TilePtr tile = g_map.getTile(newPos); diff --git a/src/otclient/core/localplayer.h b/src/otclient/core/localplayer.h index 9d4679fb..77a71185 100644 --- a/src/otclient/core/localplayer.h +++ b/src/otclient/core/localplayer.h @@ -44,7 +44,7 @@ public: void clientWalk(Otc::Direction direction); void walk(const Position& position, bool inverse); - void cancelWalk(Otc::Direction direction); + void cancelWalk(Otc::Direction direction, bool force = false); bool canWalk(Otc::Direction direction); LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast(shared_from_this()); } @@ -53,6 +53,7 @@ private: uint16 m_drawSpeed; bool m_canReportBugs; bool m_clientWalking; + Otc::Direction m_nextWalkDirection; int m_skills[Otc::LastSkill][Otc::LastSkillType]; double m_statistics[Otc::LastStatistic]; diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 702bb764..e40a8824 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -841,7 +841,7 @@ void ProtocolGame::parseTextMessage(InputMessage& msg) void ProtocolGame::parseCancelWalk(InputMessage& msg) { Otc::Direction direction = (Otc::Direction)msg.getU8(); - m_localPlayer->cancelWalk(direction); + m_localPlayer->cancelWalk(direction, true); } void ProtocolGame::parseFloorChangeUp(InputMessage& msg) diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 3ce44e3c..ee9954e6 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -73,10 +73,10 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) // cool testing \/ if(button == Fw::MouseLeftButton) { - /*MissilePtr shot = MissilePtr(new Missile()); + MissilePtr shot = MissilePtr(new Missile()); shot->setId(1); shot->setPath(g_map.getCentralPosition(), tilePos); - g_map.addThing(shot, g_map.getCentralPosition());*/ + g_map.addThing(shot, g_map.getCentralPosition()); AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); animatedText->setPosition(g_map.getCentralPosition()); @@ -91,6 +91,12 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) effect->start(); if(tile) tile->addEffect(effect); + + AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); + animatedText->setPosition(g_map.getCentralPosition()); + animatedText->setColor(12); + animatedText->setText("8"); + g_map.addThing(animatedText, g_map.getCentralPosition()); } }