From 59e90e8f1e7f980512225cf5512bdaf172f5f7ba Mon Sep 17 00:00:00 2001 From: dalkon Date: Wed, 13 Nov 2013 00:18:15 +0100 Subject: [PATCH] Item phases --- src/client/item.cpp | 19 +++++++++++++++---- src/client/item.h | 6 ++++++ src/client/protocolgameparse.cpp | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/client/item.cpp b/src/client/item.cpp index 83dc3599..2c984f10 100644 --- a/src/client/item.cpp +++ b/src/client/item.cpp @@ -41,7 +41,10 @@ Item::Item() : m_clientId(0), m_serverId(0), m_countOrSubType(1), - m_color(Color::alpha) + m_color(Color::alpha), + m_async(true), + m_phase(0), + m_lastPhase(0) { } @@ -363,9 +366,17 @@ void Item::calculatePatterns(int& xPattern, int& yPattern, int& zPattern) int Item::calculateAnimationPhase(bool animate) { if(getAnimationPhases() > 1) { - if(animate) - return (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME; - else + if(animate) { + if(m_async) + return (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME; + else { + if(g_clock.millis() - m_lastPhase >= Otc::ITEM_TICKS_PER_FRAME) { + m_phase = (m_phase + 1) % getAnimationPhases(); + m_lastPhase = g_clock.millis(); + } + return m_phase; + } + } else return getAnimationPhases()-1; } return 0; diff --git a/src/client/item.h b/src/client/item.h index e5ad727e..cb145d2a 100644 --- a/src/client/item.h +++ b/src/client/item.h @@ -112,6 +112,8 @@ public: void setActionId(uint16 actionId) { m_attribs.set(ATTR_ACTION_ID, actionId); } void setUniqueId(uint16 uniqueId) { m_attribs.set(ATTR_UNIQUE_ID, uniqueId); } + void setAsync(bool enable) { m_async = enable; } + bool isHouseDoor() { return m_attribs.has(ATTR_HOUSEDOORID); } bool isDepot() { return m_attribs.has(ATTR_DEPOT_ID); } bool isContainer() { return m_attribs.has(ATTR_CONTAINER_ITEMS); } @@ -141,6 +143,10 @@ private: stdext::packed_storage m_attribs; ItemList m_containerItems; Color m_color; + bool m_async; + + uint8 m_phase; + ticks_t m_lastPhase; }; #pragma pack(pop) diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index f1af16d8..332598c8 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -2008,7 +2008,7 @@ ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id) if(item->getAnimationPhases() > 1) { // 0xfe => random phase // 0xff => async? - msg->getU8(); // phase + item->setAsync(msg->getU8() == 0xff); } }