From 66760656e940b052f13bd7e4f8d74225e1c35883 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 20 Aug 2012 22:02:05 -0300 Subject: [PATCH] Fix rare stackpos bug caused by chameleon rune --- src/otclient/creature.cpp | 39 +++++++++++++++++------------- src/otclient/outfit.cpp | 3 ++- src/otclient/outfit.h | 4 ++- src/otclient/protocolgameparse.cpp | 14 +++++------ 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/otclient/creature.cpp b/src/otclient/creature.cpp index 7e1139c7..59c1c1ff 100644 --- a/src/otclient/creature.cpp +++ b/src/otclient/creature.cpp @@ -135,8 +135,10 @@ void Creature::internalDrawOutfit(Point dest, float scaleFactor, bool animateWal } // outfit is a creature imitating an item or the invisible effect } else { + ThingType *type = g_things.rawGetThingType(m_outfit.getAuxId(), m_outfit.getCategory()); + int animationPhase = 0; - int animationPhases = getAnimationPhases(); + int animationPhases = type->getAnimationPhases(); int animateTicks = Otc::ITEM_TICKS_PER_FRAME; // when creature is an effect we cant render the first and last animation phase, @@ -154,14 +156,20 @@ void Creature::internalDrawOutfit(Point dest, float scaleFactor, bool animateWal } if(m_outfit.getCategory() == ThingCategoryEffect) - animationPhase = std::min(animationPhase+1, getAnimationPhases()); + animationPhase = std::min(animationPhase+1, animationPhases); - rawGetThingType()->draw(dest - (getDisplacement() * scaleFactor), scaleFactor, 0, 0, 0, 0, animationPhase); + type->draw(dest - (getDisplacement() * scaleFactor), scaleFactor, 0, 0, 0, 0, animationPhase); } } void Creature::drawOutfit(const Rect& destRect, bool resize) { + int exactSize; + if(m_outfit.getCategory() == ThingCategoryCreature) + exactSize = getExactSize(); + else + exactSize = g_things.rawGetThingType(m_outfit.getAuxId(), m_outfit.getCategory())->getExactSize(); + if(g_graphics.canUseFBO()) { const FrameBufferPtr& outfitBuffer = g_framebuffers.getTemporaryFrameBuffer(); outfitBuffer->resize(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS)); @@ -173,7 +181,7 @@ void Creature::drawOutfit(const Rect& destRect, bool resize) Rect srcRect; if(resize) - srcRect.resize(getExactSize(), getExactSize()); + srcRect.resize(exactSize, exactSize); else srcRect.resize(2*Otc::TILE_PIXELS*0.75f, 2*Otc::TILE_PIXELS*0.75f); srcRect.moveBottomRight(Point(2*Otc::TILE_PIXELS - 1, 2*Otc::TILE_PIXELS - 1)); @@ -181,7 +189,7 @@ void Creature::drawOutfit(const Rect& destRect, bool resize) } else { float scaleFactor; if(resize) - scaleFactor = destRect.width() / (float)getExactSize(); + scaleFactor = destRect.width() / (float)exactSize; else scaleFactor = destRect.width() / (float)(2*Otc::TILE_PIXELS*0.75f); Point dest = destRect.bottomRight() - (Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) - getDisplacement())*scaleFactor; @@ -506,7 +514,7 @@ void Creature::setDirection(Otc::Direction direction) void Creature::setOutfit(const Outfit& outfit) { - if(!g_things.isValidDatId(outfit.getId(), outfit.getCategory())) + if(!g_things.isValidDatId(outfit.getCategory() == ThingCategoryCreature ? outfit.getId() : outfit.getAuxId(), outfit.getCategory())) return; m_walkAnimationPhase = 0; // might happen when player is walking and outfit is changed. m_outfit = outfit; @@ -637,34 +645,31 @@ int Creature::getStepDuration() Point Creature::getDisplacement() { - Point displacement = Thing::getDisplacement(); if(m_outfit.getCategory() == ThingCategoryEffect) - displacement = Point(8, 8); - return displacement; + return Point(8, 8); + return Thing::getDisplacement(); } int Creature::getDisplacementX() { - int displacementX = Thing::getDisplacementX(); if(m_outfit.getCategory() == ThingCategoryEffect) - displacementX = 8; - return displacementX; + return 8; + return Thing::getDisplacementX(); } int Creature::getDisplacementY() { - int displacementY = Thing::getDisplacementY(); if(m_outfit.getCategory() == ThingCategoryEffect) - displacementY = 8; - return displacementY; + return 8; + return Thing::getDisplacementY(); } const ThingTypePtr& Creature::getThingType() { - return g_things.getThingType(m_outfit.getId(), m_outfit.getCategory()); + return g_things.getThingType(m_outfit.getId(), ThingCategoryCreature); } ThingType* Creature::rawGetThingType() { - return g_things.rawGetThingType(m_outfit.getId(), m_outfit.getCategory()); + return g_things.rawGetThingType(m_outfit.getId(), ThingCategoryCreature); } diff --git a/src/otclient/outfit.cpp b/src/otclient/outfit.cpp index 5e50974d..d0605bd6 100644 --- a/src/otclient/outfit.cpp +++ b/src/otclient/outfit.cpp @@ -25,7 +25,8 @@ Outfit::Outfit() { m_category = ThingCategoryCreature; - m_id = 0; + m_id = 128; + m_auxId = 0; resetClothes(); } diff --git a/src/otclient/outfit.h b/src/otclient/outfit.h index b3440272..71c18a1d 100644 --- a/src/otclient/outfit.h +++ b/src/otclient/outfit.h @@ -39,6 +39,7 @@ public: static Color getColor(int color); void setId(int id) { m_id = id; } + void setAuxId(int id) { m_auxId = id; } void setHead(int head) { m_head = head; m_headColor = getColor(head); } void setBody(int body) { m_body = body; m_bodyColor = getColor(body); } void setLegs(int legs) { m_legs = legs; m_legsColor = getColor(legs); } @@ -50,6 +51,7 @@ public: void resetClothes(); int getId() const { return m_id; } + int getAuxId() const { return m_auxId; } int getHead() const { return m_head; } int getBody() const { return m_body; } int getLegs() const { return m_legs; } @@ -65,7 +67,7 @@ public: private: ThingCategory m_category; - int m_id, m_head, m_body, m_legs, m_feet, m_addons, m_mount; + int m_id, m_auxId, m_head, m_body, m_legs, m_feet, m_addons, m_mount; Color m_headColor, m_bodyColor, m_legsColor, m_feetColor; }; diff --git a/src/otclient/protocolgameparse.cpp b/src/otclient/protocolgameparse.cpp index 6531bf14..bdb60ade 100644 --- a/src/otclient/protocolgameparse.cpp +++ b/src/otclient/protocolgameparse.cpp @@ -1451,24 +1451,24 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg) outfit.setLegs(legs); outfit.setFeet(feet); outfit.setAddons(addons); + + if(g_game.getFeature(Otc::GamePlayerMounts)) { + int mount = msg->getU16(); + outfit.setMount(mount); + } } else { int lookTypeEx = msg->getU16(); if(lookTypeEx == 0) { outfit.setCategory(ThingCategoryEffect); - outfit.setId(13); + outfit.setAuxId(13); } else { outfit.setCategory(ThingCategoryItem); - outfit.setId(lookTypeEx); + outfit.setAuxId(lookTypeEx); } } - if(g_game.getFeature(Otc::GamePlayerMounts)) { - int mount = msg->getU16(); - outfit.setMount(mount); - } - return outfit; }