Fix rare stackpos bug caused by chameleon rune

master
Eduardo Bart 12 years ago
parent b39623d437
commit 66760656e9

@ -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);
}

@ -25,7 +25,8 @@
Outfit::Outfit()
{
m_category = ThingCategoryCreature;
m_id = 0;
m_id = 128;
m_auxId = 0;
resetClothes();
}

@ -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;
};

@ -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;
}

Loading…
Cancel
Save