bool Monsters::loadLoot(xmlNodePtr node, LootBlock& lootBlock)
{
std::string strValue;
if(readXMLString(node, "id", strValue) || readXMLString(node, "ids", strValue))
{
IntegerVec idsVec;
parseIntegerVec(strValue, idsVec);
for(IntegerVec::iterator it = idsVec.begin(); it != idsVec.end(); ++it)
{
lootBlock.ids.push_back(*it);
if(Item::items[(*it)].isContainer())
loadChildLoot(node, lootBlock);
}
}
else if(readXMLString(node, "name", strValue) || readXMLString(node, "names", strValue))
{
StringVec names = explodeString(strValue, ";");
for(StringVec::iterator it = names.begin(); it != names.end(); ++it)
{
uint16_t tmp = Item::items.getItemIdByName(strValue);
if(!tmp)
continue;
lootBlock.ids.push_back(tmp);
if(Item::items[tmp].isContainer())
loadChildLoot(node, lootBlock);
}
}
if(lootBlock.ids.empty())
return false;
int32_t intValue;
if(readXMLInteger(node, "count", intValue) || readXMLInteger(node, "countmax", intValue))
lootBlock.count = intValue;
else
lootBlock.count = 1;
if(readXMLInteger(node, "chance", intValue) || readXMLInteger(node, "chance1", intValue))
lootBlock.chance = std::min(MAX_LOOTCHANCE, intValue);
else
lootBlock.chance = MAX_LOOTCHANCE;
if(readXMLInteger(node, "subtype", intValue) || readXMLInteger(node, "subType", intValue))
lootBlock.subType = intValue;
if(readXMLInteger(node, "actionId", intValue) || readXMLInteger(node, "actionid", intValue)
|| readXMLInteger(node, "aid", intValue))
lootBlock.actionId = intValue;
if(readXMLInteger(node, "uniqueId", intValue) || readXMLInteger(node, "uniqueid", intValue)
|| readXMLInteger(node, "uid", intValue))
lootBlock.uniqueId = intValue;
if(readXMLString(node, "text", strValue))
lootBlock.text = strValue;
return true;
}