mirror of
https://github.com/edubart/otclient.git
synced 2025-12-21 16:07:12 +01:00
Added support for enhanced animations for items.
Thanks to @conde2, @BenDol
This commit is contained in:
@@ -39,6 +39,7 @@ ThingType::ThingType()
|
||||
m_null = true;
|
||||
m_exactSize = 0;
|
||||
m_realSize = 0;
|
||||
m_animator = nullptr;
|
||||
m_numPatternX = m_numPatternY = m_numPatternZ = 0;
|
||||
m_animationPhases = 0;
|
||||
m_layers = 0;
|
||||
@@ -117,15 +118,8 @@ void ThingType::serialize(const FileStreamPtr& fin)
|
||||
fin->addU8(m_animationPhases);
|
||||
|
||||
if(g_game.getFeature(Otc::GameEnhancedAnimations)) {
|
||||
if(m_animationPhases > 1) {
|
||||
fin->addU8(m_animation.async ? 0 : 1);
|
||||
fin->add32(m_animation.loopCount);
|
||||
fin->addU8(m_animation.startIndex);
|
||||
|
||||
for(std::tuple<int, int> frame : m_animation.frames) {
|
||||
fin->addU32(std::get<0>(frame));
|
||||
fin->addU32(std::get<1>(frame));
|
||||
}
|
||||
if(m_animationPhases > 1 && m_animator != nullptr) {
|
||||
m_animator->serialize(fin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,11 +268,11 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
|
||||
stdext::throw_exception(stdext::format("corrupt data (id: %d, category: %d, count: %d, lastAttr: %d)",
|
||||
m_id, m_category, count, attr));
|
||||
|
||||
uint8 frames = 1;
|
||||
uint8 groupCount = 1;
|
||||
if(category == ThingCategoryCreature && g_game.getClientVersion() >= 1057)
|
||||
frames = fin->getU8();
|
||||
groupCount = fin->getU8();
|
||||
|
||||
for(int i = 0; i < frames; ++i) {
|
||||
for(int i = 0; i < groupCount; ++i) {
|
||||
uint8 frameGroup = FrameGroupDefault;
|
||||
if(category == ThingCategoryCreature && g_game.getClientVersion() >= 1057) {
|
||||
frameGroup = fin->getU8();
|
||||
@@ -303,19 +297,9 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
|
||||
m_numPatternZ = 1;
|
||||
m_animationPhases = fin->getU8();
|
||||
|
||||
if(g_game.getFeature(Otc::GameEnhancedAnimations)) {
|
||||
if(m_animationPhases > 1) {
|
||||
m_animation.async = fin->getU8() == 0;
|
||||
m_animation.loopCount = fin->get32();
|
||||
m_animation.startIndex = fin->getU8();
|
||||
|
||||
for (int i = 0; i < m_animationPhases; i++) {
|
||||
int minDuration = fin->getU32();
|
||||
int maxDuration = fin->getU32();
|
||||
|
||||
m_animation.frames.push_back(std::make_tuple(minDuration, maxDuration));
|
||||
}
|
||||
}
|
||||
if(m_animationPhases > 1 && g_game.getFeature(Otc::GameEnhancedAnimations)) {
|
||||
m_animator = AnimatorPtr(new Animator);
|
||||
m_animator->unserialize(m_animationPhases, fin);
|
||||
}
|
||||
|
||||
int totalSprites = m_size.area() * m_layers * m_numPatternX * m_numPatternY * m_numPatternZ * m_animationPhases;
|
||||
|
||||
Reference in New Issue
Block a user