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
|
@ -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);
|
||||
if(it != m_buffers.end())
|
||||
return;
|
||||
|
@ -130,11 +132,13 @@ void SoundManager::enableSound(bool enable)
|
|||
return;
|
||||
}
|
||||
|
||||
void SoundManager::play(const std::string& filename)
|
||||
void SoundManager::play(std::string filename)
|
||||
{
|
||||
if(!m_soundEnabled)
|
||||
if(!m_soundEnabled || filename.empty())
|
||||
return;
|
||||
|
||||
filename = g_resources.resolvePath(filename);
|
||||
|
||||
SoundSourcePtr soundSource = createSoundSource(filename);
|
||||
if(!soundSource) {
|
||||
g_logger.error(stdext::format("unable to play '%s'", filename));
|
||||
|
@ -154,17 +158,21 @@ void SoundManager::enableMusic(bool enable)
|
|||
|
||||
m_musicEnabled = enable;
|
||||
|
||||
if(enable)
|
||||
if(enable && !m_currentMusic.empty())
|
||||
playMusic(m_currentMusic, 3.0f);
|
||||
else
|
||||
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)
|
||||
return;
|
||||
m_currentMusic = g_resources.resolvePath(filename);
|
||||
|
||||
if(!m_musicEnabled)
|
||||
return;
|
||||
|
|
|
@ -38,12 +38,12 @@ public:
|
|||
void terminate();
|
||||
void poll();
|
||||
|
||||
void preload(const std::string& filename);
|
||||
void preload(std::string filename);
|
||||
void enableSound(bool enable);
|
||||
void play(const std::string& filename);
|
||||
void play(std::string filename);
|
||||
|
||||
void enableMusic(bool enable);
|
||||
void playMusic(const std::string& filename, float fadetime);
|
||||
void playMusic(std::string filename, float fadetime);
|
||||
void stopMusic(float fadetime = 0);
|
||||
|
||||
bool isMusicEnabled() { return m_musicEnabled; }
|
||||
|
|
|
@ -199,78 +199,67 @@ bool Item::isValid()
|
|||
|
||||
void Item::unserializeItem(const BinaryTreePtr &in)
|
||||
{
|
||||
while (in->canRead()) {
|
||||
uint8 attrType = in->getU8();
|
||||
if(attrType == 0)
|
||||
break;
|
||||
try {
|
||||
while(in->canRead()) {
|
||||
int attrib = in->getU8();
|
||||
if(attrib == 0)
|
||||
break;
|
||||
|
||||
// fugly switch yes?
|
||||
switch ((AttrTypes_t)attrType) {
|
||||
case ATTR_COUNT:
|
||||
setSubType(in->getU8());
|
||||
break;
|
||||
case ATTR_CHARGES:
|
||||
setSubType(in->getU16());
|
||||
break;
|
||||
case ATTR_ACTION_ID:
|
||||
setActionId(in->getU16());
|
||||
break;
|
||||
case ATTR_UNIQUE_ID:
|
||||
setUniqueId(in->getU16());
|
||||
break;
|
||||
case ATTR_NAME:
|
||||
m_attribs.set(ATTR_NAME, in->getString());
|
||||
break;
|
||||
case ATTR_TEXT:
|
||||
m_attribs.set(ATTR_TEXT, in->getString());
|
||||
break;
|
||||
case ATTR_DESC:
|
||||
m_attribs.set(ATTR_DESC, in->getString());
|
||||
break;
|
||||
case ATTR_CONTAINER_ITEMS:
|
||||
m_attribs.set(ATTR_CONTAINER_ITEMS, in->getU32());
|
||||
break;
|
||||
case ATTR_HOUSEDOORID:
|
||||
m_attribs.set(ATTR_HOUSEDOORID, in->getU8());
|
||||
break;
|
||||
case ATTR_DEPOT_ID:
|
||||
m_attribs.set(ATTR_DEPOT_ID, in->getU16());
|
||||
break;
|
||||
case ATTR_TELE_DEST: {
|
||||
Position teleportDestination;
|
||||
teleportDestination.x = in->getU16();
|
||||
teleportDestination.y = in->getU16();
|
||||
teleportDestination.z = in->getU8();
|
||||
m_attribs.set(ATTR_TELE_DEST, teleportDestination);
|
||||
break;
|
||||
switch(attrib) {
|
||||
case ATTR_COUNT:
|
||||
case ATTR_RUNE_CHARGES:
|
||||
setCount(in->getU8());
|
||||
break;
|
||||
case ATTR_CHARGES:
|
||||
setCount(in->getU16());
|
||||
break;
|
||||
case ATTR_HOUSEDOORID:
|
||||
case ATTR_SCRIPTPROTECTED:
|
||||
case ATTR_DUALWIELD:
|
||||
case ATTR_DECAYING_STATE:
|
||||
m_attribs.set(attrib, in->getU8());
|
||||
break;
|
||||
case ATTR_ACTION_ID:
|
||||
case ATTR_UNIQUE_ID:
|
||||
case ATTR_DEPOT_ID:
|
||||
m_attribs.set(attrib, in->getU16());
|
||||
break;
|
||||
case ATTR_CONTAINER_ITEMS:
|
||||
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:
|
||||
m_attribs.set(attrib, in->getU32());
|
||||
break;
|
||||
case ATTR_TELE_DEST: {
|
||||
Position pos;
|
||||
pos.x = in->getU16();
|
||||
pos.y = in->getU16();
|
||||
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
|
||||
{
|
||||
ATTR_END = 0,
|
||||
//ATTR_DESCRIPTION = 1,
|
||||
//ATTR_EXT_FILE = 2,
|
||||
ATTR_TILE_FLAGS = 3,
|
||||
ATTR_ACTION_ID = 4,
|
||||
ATTR_UNIQUE_ID = 5,
|
||||
|
@ -39,7 +41,9 @@ enum AttrTypes_t
|
|||
ATTR_TELE_DEST = 8,
|
||||
ATTR_ITEM = 9,
|
||||
ATTR_DEPOT_ID = 10,
|
||||
//ATTR_EXT_SPAWN_FILE = 11,
|
||||
ATTR_RUNE_CHARGES = 12,
|
||||
//ATTR_EXT_HOUSE_FILE = 13,
|
||||
ATTR_HOUSEDOORID = 14,
|
||||
ATTR_COUNT = 15,
|
||||
ATTR_DURATION = 16,
|
||||
|
|
|
@ -43,6 +43,9 @@ void ThingTypeManager::init()
|
|||
m_datLoaded = false;
|
||||
m_xmlLoaded = 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()
|
||||
|
|
Loading…
Reference in New Issue