Update item OTBM attributes reader
* Fix some lua errors generated by playMusic * Fix possible crash when starting otcliet without dat loaded
This commit is contained in:
parent
7cd49712f8
commit
b0e6b3b8fb
|
@ -10,4 +10,4 @@ function TibiaFiles.init()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TibiaFiles.terminate()
|
function TibiaFiles.terminate()
|
||||||
end
|
end
|
||||||
|
|
|
@ -107,8 +107,10 @@ void SoundManager::poll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::preload(const std::string& filename)
|
void SoundManager::preload(std::string filename)
|
||||||
{
|
{
|
||||||
|
filename = g_resources.resolvePath(filename);
|
||||||
|
|
||||||
auto it = m_buffers.find(filename);
|
auto it = m_buffers.find(filename);
|
||||||
if(it != m_buffers.end())
|
if(it != m_buffers.end())
|
||||||
return;
|
return;
|
||||||
|
@ -130,11 +132,13 @@ void SoundManager::enableSound(bool enable)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::play(const std::string& filename)
|
void SoundManager::play(std::string filename)
|
||||||
{
|
{
|
||||||
if(!m_soundEnabled)
|
if(!m_soundEnabled || filename.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
filename = g_resources.resolvePath(filename);
|
||||||
|
|
||||||
SoundSourcePtr soundSource = createSoundSource(filename);
|
SoundSourcePtr soundSource = createSoundSource(filename);
|
||||||
if(!soundSource) {
|
if(!soundSource) {
|
||||||
g_logger.error(stdext::format("unable to play '%s'", filename));
|
g_logger.error(stdext::format("unable to play '%s'", filename));
|
||||||
|
@ -154,17 +158,21 @@ void SoundManager::enableMusic(bool enable)
|
||||||
|
|
||||||
m_musicEnabled = enable;
|
m_musicEnabled = enable;
|
||||||
|
|
||||||
if(enable)
|
if(enable && !m_currentMusic.empty())
|
||||||
playMusic(m_currentMusic, 3.0f);
|
playMusic(m_currentMusic, 3.0f);
|
||||||
else
|
else
|
||||||
m_musicSource = nullptr;
|
m_musicSource = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::playMusic(const std::string& filename, float fadetime)
|
void SoundManager::playMusic(std::string filename, float fadetime)
|
||||||
{
|
{
|
||||||
|
if(filename.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
filename = g_resources.resolvePath(filename);
|
||||||
|
|
||||||
if(m_currentMusic == filename && m_musicSource)
|
if(m_currentMusic == filename && m_musicSource)
|
||||||
return;
|
return;
|
||||||
m_currentMusic = g_resources.resolvePath(filename);
|
|
||||||
|
|
||||||
if(!m_musicEnabled)
|
if(!m_musicEnabled)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -38,12 +38,12 @@ public:
|
||||||
void terminate();
|
void terminate();
|
||||||
void poll();
|
void poll();
|
||||||
|
|
||||||
void preload(const std::string& filename);
|
void preload(std::string filename);
|
||||||
void enableSound(bool enable);
|
void enableSound(bool enable);
|
||||||
void play(const std::string& filename);
|
void play(std::string filename);
|
||||||
|
|
||||||
void enableMusic(bool enable);
|
void enableMusic(bool enable);
|
||||||
void playMusic(const std::string& filename, float fadetime);
|
void playMusic(std::string filename, float fadetime);
|
||||||
void stopMusic(float fadetime = 0);
|
void stopMusic(float fadetime = 0);
|
||||||
|
|
||||||
bool isMusicEnabled() { return m_musicEnabled; }
|
bool isMusicEnabled() { return m_musicEnabled; }
|
||||||
|
|
|
@ -199,78 +199,67 @@ bool Item::isValid()
|
||||||
|
|
||||||
void Item::unserializeItem(const BinaryTreePtr &in)
|
void Item::unserializeItem(const BinaryTreePtr &in)
|
||||||
{
|
{
|
||||||
while (in->canRead()) {
|
try {
|
||||||
uint8 attrType = in->getU8();
|
while(in->canRead()) {
|
||||||
if(attrType == 0)
|
int attrib = in->getU8();
|
||||||
break;
|
if(attrib == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
// fugly switch yes?
|
switch(attrib) {
|
||||||
switch ((AttrTypes_t)attrType) {
|
case ATTR_COUNT:
|
||||||
case ATTR_COUNT:
|
case ATTR_RUNE_CHARGES:
|
||||||
setSubType(in->getU8());
|
setCount(in->getU8());
|
||||||
break;
|
break;
|
||||||
case ATTR_CHARGES:
|
case ATTR_CHARGES:
|
||||||
setSubType(in->getU16());
|
setCount(in->getU16());
|
||||||
break;
|
break;
|
||||||
case ATTR_ACTION_ID:
|
case ATTR_HOUSEDOORID:
|
||||||
setActionId(in->getU16());
|
case ATTR_SCRIPTPROTECTED:
|
||||||
break;
|
case ATTR_DUALWIELD:
|
||||||
case ATTR_UNIQUE_ID:
|
case ATTR_DECAYING_STATE:
|
||||||
setUniqueId(in->getU16());
|
m_attribs.set(attrib, in->getU8());
|
||||||
break;
|
break;
|
||||||
case ATTR_NAME:
|
case ATTR_ACTION_ID:
|
||||||
m_attribs.set(ATTR_NAME, in->getString());
|
case ATTR_UNIQUE_ID:
|
||||||
break;
|
case ATTR_DEPOT_ID:
|
||||||
case ATTR_TEXT:
|
m_attribs.set(attrib, in->getU16());
|
||||||
m_attribs.set(ATTR_TEXT, in->getString());
|
break;
|
||||||
break;
|
case ATTR_CONTAINER_ITEMS:
|
||||||
case ATTR_DESC:
|
case ATTR_ATTACK:
|
||||||
m_attribs.set(ATTR_DESC, in->getString());
|
case ATTR_EXTRAATTACK:
|
||||||
break;
|
case ATTR_DEFENSE:
|
||||||
case ATTR_CONTAINER_ITEMS:
|
case ATTR_EXTRADEFENSE:
|
||||||
m_attribs.set(ATTR_CONTAINER_ITEMS, in->getU32());
|
case ATTR_ARMOR:
|
||||||
break;
|
case ATTR_ATTACKSPEED:
|
||||||
case ATTR_HOUSEDOORID:
|
case ATTR_HITCHANCE:
|
||||||
m_attribs.set(ATTR_HOUSEDOORID, in->getU8());
|
case ATTR_DURATION:
|
||||||
break;
|
case ATTR_WRITTENDATE:
|
||||||
case ATTR_DEPOT_ID:
|
case ATTR_SLEEPERGUID:
|
||||||
m_attribs.set(ATTR_DEPOT_ID, in->getU16());
|
case ATTR_SLEEPSTART:
|
||||||
break;
|
case ATTR_ATTRIBUTE_MAP:
|
||||||
case ATTR_TELE_DEST: {
|
m_attribs.set(attrib, in->getU32());
|
||||||
Position teleportDestination;
|
break;
|
||||||
teleportDestination.x = in->getU16();
|
case ATTR_TELE_DEST: {
|
||||||
teleportDestination.y = in->getU16();
|
Position pos;
|
||||||
teleportDestination.z = in->getU8();
|
pos.x = in->getU16();
|
||||||
m_attribs.set(ATTR_TELE_DEST, teleportDestination);
|
pos.y = in->getU16();
|
||||||
break;
|
pos.z = in->getU8();
|
||||||
|
m_attribs.set(attrib, pos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ATTR_NAME:
|
||||||
|
case ATTR_TEXT:
|
||||||
|
case ATTR_DESC:
|
||||||
|
case ATTR_ARTICLE:
|
||||||
|
case ATTR_WRITTENBY:
|
||||||
|
m_attribs.set(attrib, in->getString());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
stdext::throw_exception(stdext::format("invalid item attribute %d", attrib));
|
||||||
}
|
}
|
||||||
case ATTR_ARTICLE:
|
|
||||||
case ATTR_WRITTENBY:
|
|
||||||
in->getString();
|
|
||||||
break;
|
|
||||||
case ATTR_ATTACK:
|
|
||||||
case ATTR_EXTRAATTACK:
|
|
||||||
case ATTR_DEFENSE:
|
|
||||||
case ATTR_EXTRADEFENSE:
|
|
||||||
case ATTR_ARMOR:
|
|
||||||
case ATTR_ATTACKSPEED:
|
|
||||||
case ATTR_HITCHANCE:
|
|
||||||
case ATTR_DURATION:
|
|
||||||
case ATTR_WRITTENDATE:
|
|
||||||
case ATTR_SLEEPERGUID:
|
|
||||||
case ATTR_SLEEPSTART:
|
|
||||||
case ATTR_ATTRIBUTE_MAP:
|
|
||||||
in->skip(4);
|
|
||||||
break;
|
|
||||||
case ATTR_SCRIPTPROTECTED:
|
|
||||||
case ATTR_DUALWIELD:
|
|
||||||
case ATTR_DECAYING_STATE:
|
|
||||||
case ATTR_RUNE_CHARGES:
|
|
||||||
in->skip(1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
stdext::throw_exception(stdext::format("invalid item attribute %d", (int)attrType));
|
|
||||||
}
|
}
|
||||||
|
} catch(stdext::exception& e) {
|
||||||
|
g_logger.error(stdext::format("Failed to unserialize OTBM item: %s", e.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
enum AttrTypes_t
|
enum AttrTypes_t
|
||||||
{
|
{
|
||||||
ATTR_END = 0,
|
ATTR_END = 0,
|
||||||
|
//ATTR_DESCRIPTION = 1,
|
||||||
|
//ATTR_EXT_FILE = 2,
|
||||||
ATTR_TILE_FLAGS = 3,
|
ATTR_TILE_FLAGS = 3,
|
||||||
ATTR_ACTION_ID = 4,
|
ATTR_ACTION_ID = 4,
|
||||||
ATTR_UNIQUE_ID = 5,
|
ATTR_UNIQUE_ID = 5,
|
||||||
|
@ -39,7 +41,9 @@ enum AttrTypes_t
|
||||||
ATTR_TELE_DEST = 8,
|
ATTR_TELE_DEST = 8,
|
||||||
ATTR_ITEM = 9,
|
ATTR_ITEM = 9,
|
||||||
ATTR_DEPOT_ID = 10,
|
ATTR_DEPOT_ID = 10,
|
||||||
|
//ATTR_EXT_SPAWN_FILE = 11,
|
||||||
ATTR_RUNE_CHARGES = 12,
|
ATTR_RUNE_CHARGES = 12,
|
||||||
|
//ATTR_EXT_HOUSE_FILE = 13,
|
||||||
ATTR_HOUSEDOORID = 14,
|
ATTR_HOUSEDOORID = 14,
|
||||||
ATTR_COUNT = 15,
|
ATTR_COUNT = 15,
|
||||||
ATTR_DURATION = 16,
|
ATTR_DURATION = 16,
|
||||||
|
|
|
@ -43,6 +43,9 @@ void ThingTypeManager::init()
|
||||||
m_datLoaded = false;
|
m_datLoaded = false;
|
||||||
m_xmlLoaded = false;
|
m_xmlLoaded = false;
|
||||||
m_otbLoaded = false;
|
m_otbLoaded = false;
|
||||||
|
for(int i = 0; i < DatLastCategory; ++i)
|
||||||
|
m_datTypes[i].resize(1, m_nullDatType);
|
||||||
|
m_otbTypes.resize(1, m_nullOtbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThingTypeManager::terminate()
|
void ThingTypeManager::terminate()
|
||||||
|
|
Loading…
Reference in New Issue