Item* ProtocolAdmin::createMail(const std::string& xmlData, std::string& name, uint32_t& depotId) { xmlDocPtr doc = xmlParseMemory(xmlData.c_str(), strlen(xmlData.c_str())); if(!doc){ return NULL; } xmlNodePtr root = xmlDocGetRootElement(doc); if(xmlStrcmp(root->name,(const xmlChar*)"mail") != 0){ return NULL; } int32_t itemId = ITEM_PARCEL; int32_t intValue; std::string strValue; if(readXMLString(root, "to", strValue)){ name = strValue; } if(readXMLString(root, "town", strValue)){ if(!Mailbox::getDepotId(strValue, depotId)){ return NULL; } } else{ //use the players default town if(!IOPlayer::instance()->getDefaultTown(name, depotId)){ return NULL; } } if(readXMLInteger(root, "id", intValue)){ itemId = intValue; } Item* mailItem = Item::CreateItem(itemId); mailItem->setParent(VirtualCylinder::virtualCylinder); if(Container* mailContainer = mailItem->getContainer()){ xmlNodePtr node = root->children; while(node){ if(node->type != XML_ELEMENT_NODE){ node = node->next; continue; } if(!Item::loadItem(node, mailContainer)){ delete mailContainer; return NULL; } node = node->next; } } return mailItem; }
bool Outfits::parseOutfitNode(xmlNodePtr p) { if(xmlStrcmp(p->name, (const xmlChar*)"outfit")) return false; int32_t intValue; if(!readXMLInteger(p, "id", intValue)) { LOGe("[Outfits::parseOutfitNode] Missing outfit id, skipping"); return false; } Outfit newOutfit; newOutfit.outfitId = intValue; std::string name, strValue; if(readXMLString(p, "default", strValue)) newOutfit.isDefault = booleanString(strValue); if(!readXMLString(p, "name", strValue)) { std::stringstream ss; ss << "Outfit #" << newOutfit.outfitId; ss >> name; }
bool TalkAction::configureEvent(xmlNodePtr p) { std::string str; int intValue; if(readXMLString(p, "words", str)){ commandString = str; } else{ std::cout << "Error: [TalkAction::configureEvent] No words for TalkAction or Spell." << std::endl; return false; } if(readXMLString(p, "filter", str)){ if(str == "quotation") { filterType = TALKACTION_MATCH_QUOTATION; } else if(str == "first word") { filterType = TALKACTION_MATCH_FIRST_WORD; } } if(readXMLInteger(p, "case-sensitive", intValue) || readXMLInteger(p, "sensitive", intValue)){ caseSensitive = (intValue != 0); } if(readXMLInteger(p, "access", intValue)){ accessLevel = intValue; } return true; }
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; }
bool EffectEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; int32_t intValue; std::string strValue; if(!readXMLInteger(eventNode, "id", intValue)) { if(!readXMLString(eventNode, "name", strValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] id (or name) tag missing for effect event." << std::endl; return false; } else m_effect = getMagicEffect(strValue); } else m_effect = (MagicEffect_t)intValue; if(!readXMLString(eventNode, "pos", strValue)) { if(!readXMLInteger(eventNode, "x", intValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] x tag missing for effect event." << std::endl; return false; } m_position.x = intValue; if(!readXMLInteger(eventNode, "y", intValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] y tag missing for effect event." << std::endl; return false; } m_position.y = intValue; if(!readXMLInteger(eventNode, "z", intValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] z tag missing for effect event." << std::endl; return false; } m_position.z = intValue; } else { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - EffectEvent::configureRaidEvent] Malformed pos tag for effect event." << std::endl; return false; } m_position = Position(posList[0], posList[1], posList[2]); } return true; }
bool Item::loadItem(xmlNodePtr node, Container* parent) { if(!xmlStrcmp(node->name, (const xmlChar*)"item")) return false; int32_t intValue; std::string strValue; Item* item = NULL; if(readXMLInteger(node, "id", intValue)) item = Item::CreateItem(intValue); if(!item) return false; if(readXMLString(node, "attributes", strValue)) { StringVec v, attr = explodeString(strValue, ";"); for(StringVec::iterator it = attr.begin(); it != attr.end(); ++it) { v = explodeString((*it), ","); if(v.size() < 2) continue; if(atoi(v[1].c_str()) || v[1] == "0") item->setAttribute(v[0].c_str(), atoi(v[1].c_str())); else item->setAttribute(v[0].c_str(), v[1]); } } //compatibility if(readXMLInteger(node, "subtype", intValue) || readXMLInteger(node, "subType", intValue)) item->setSubType(intValue); if(readXMLInteger(node, "actionId", intValue) || readXMLInteger(node, "actionid", intValue) || readXMLInteger(node, "aid", intValue)) item->setActionId(intValue); if(readXMLInteger(node, "uniqueId", intValue) || readXMLInteger(node, "uniqueid", intValue) || readXMLInteger(node, "uid", intValue)) item->setUniqueId(intValue); if(readXMLString(node, "text", strValue)) item->setText(strValue); if(item->getContainer()) loadContainer(node, item->getContainer()); if(parent) parent->addItem(item); return true; }
bool Item::unserialize(xmlNodePtr nodeItem) { int intValue; std::string strValue; if(readXMLInteger(nodeItem, "id", intValue)){ id = intValue; } else{ return false; } if(readXMLInteger(nodeItem, "count", intValue)){ setSubType(intValue); } if(readXMLString(nodeItem, "special_description", strValue)){ setSpecialDescription(strValue); } if(readXMLString(nodeItem, "text", strValue)){ setText(strValue); } if(readXMLInteger(nodeItem, "written_date", intValue)){ setWrittenDate(intValue); } if(readXMLString(nodeItem, "writer", strValue)){ setWriter(strValue); } if(readXMLInteger(nodeItem, "actionId", intValue)){ setActionId(intValue); } if(readXMLInteger(nodeItem, "uniqueId", intValue)){ setUniqueId(intValue); } if(readXMLInteger(nodeItem, "duration", intValue)){ setDuration(intValue); } if(readXMLInteger(nodeItem, "decayState", intValue)){ ItemDecayState_t decayState = (ItemDecayState_t)intValue; if(decayState != DECAYING_FALSE){ setDecaying(DECAYING_PENDING); } } return true; }
bool SingleSpawnEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; std::string strValue; if(!readXMLString(eventNode, "name", strValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] name tag missing for singlespawn event." << std::endl; return false; } m_monsterName = strValue; if(!readXMLString(eventNode, "pos", strValue)) { int32_t intValue; if(!readXMLInteger(eventNode, "x", intValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] x tag missing for singlespawn event." << std::endl; return false; } m_position.x = intValue; if(!readXMLInteger(eventNode, "y", intValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] y tag missing for singlespawn event." << std::endl; return false; } m_position.y = intValue; if(!readXMLInteger(eventNode, "z", intValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] z tag missing for singlespawn event." << std::endl; return false; } m_position.z = intValue; } else { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] Malformed pos tag for singlespawn event." << std::endl; return false; } m_position = Position(posList[0], posList[1], posList[2]); } return true; }
bool AnnounceEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)){ return false; } std::string strValue; if(readXMLString(eventNode, "message", strValue)){ m_message = strValue; } else{ std::cout << "[Error] Raid: message tag missing for announce event." << std::endl; return false; } if(readXMLString(eventNode, "type", strValue)){ if(asLowerCaseString(strValue) == "warning"){ m_messageType = MSG_STATUS_WARNING; } else if(asLowerCaseString(strValue) == "event"){ m_messageType = MSG_EVENT_ADVANCE; } else if(asLowerCaseString(strValue) == "default"){ m_messageType = MSG_EVENT_DEFAULT; } else if(asLowerCaseString(strValue) == "description"){ m_messageType = MSG_INFO_DESCR; } else if(asLowerCaseString(strValue) == "smallstatus"){ m_messageType = MSG_STATUS_SMALL; } else if(asLowerCaseString(strValue) == "blueconsole"){ m_messageType = MSG_STATUS_CONSOLE_BLUE; } else if(asLowerCaseString(strValue) == "redconsole"){ m_messageType = MSG_STATUS_CONSOLE_RED; } else{ m_messageType = MSG_EVENT_ADVANCE; std::cout << "[Notice] Raid: Unknown type tag missing for announce event. Using default: " << (int32_t)m_messageType << std::endl; } } else{ m_messageType = MSG_EVENT_ADVANCE; std::cout << "[Notice] Raid: type tag missing for announce event. Using default: " << (int32_t)m_messageType << std::endl; } return true; }
bool Materials::unserializeTileset(xmlNodePtr node, wxArrayString& warnings) { std::string strVal; if(readXMLString(node, "name", strVal)) { Tileset* ts; TilesetContainer::iterator iter = tilesets.find(strVal); if(iter != tilesets.end()) { ts = iter->second; } else { ts = newd Tileset(brushes, strVal); tilesets.insert(make_pair(strVal, ts)); } xmlNodePtr child = node->children; while(child) { ts->loadCategory(child, warnings); child = child->next; } } else { warnings.push_back(wxT("Couldn't read tileset name")); return false; } return true; }
bool WeaponWand::configureEvent(xmlNodePtr p) { if(!Weapon::configureEvent(p)) return false; int32_t intValue; std::string strValue; if(readXMLInteger(p, "min", intValue)) minChange = intValue; if(readXMLInteger(p, "max", intValue)) maxChange = intValue; if(readXMLString(p, "type", strValue)) { std::string tmpStrValue = asLowerCaseString(strValue); if(tmpStrValue == "earth") params.combatType = COMBAT_EARTHDAMAGE; else if(tmpStrValue == "ice") params.combatType = COMBAT_ICEDAMAGE; else if(tmpStrValue == "energy") params.combatType = COMBAT_ENERGYDAMAGE; else if(tmpStrValue == "fire") params.combatType = COMBAT_FIREDAMAGE; else if(tmpStrValue == "death") params.combatType = COMBAT_DEATHDAMAGE; else if(tmpStrValue == "holy") params.combatType = COMBAT_HOLYDAMAGE; else std::cout << "[Warning - WeaponWand::configureEvent] Type \"" << strValue << "\" does not exist." << std::endl; } return true; }
bool ScriptEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; std::string scriptsName = Raids::getInstance()->getScriptBaseName(); if(!m_interface.loadDirectory(getFilePath(FILE_TYPE_OTHER, std::string(scriptsName + "/lib/")))) std::cout << "[Warning - ScriptEvent::configureRaidEvent] Cannot load " << scriptsName << "/lib/" << std::endl; std::string strValue; if(readXMLString(eventNode, "file", strValue)) { if(!loadScript(getFilePath(FILE_TYPE_OTHER, std::string(scriptsName + "/scripts/" + strValue)), true)) { std::cout << "[Error - ScriptEvent::configureRaidEvent] Cannot load raid script file (" << strValue << ")." << std::endl; return false; } } else if(!parseXMLContentString(eventNode->children, strValue) && !loadBuffer(strValue)) { std::cout << "[Error - ScriptEvent::configureRaidEvent] Cannot load raid script buffer." << std::endl; return false; } return true; }
bool CreatureEvent::configureEvent(xmlNodePtr p) { std::string str; //Name that will be used in monster xml files and // lua function to register events to reference this event if (readXMLString(p, "name", str)) { m_eventName = str; } else { std::cout << "Error: [CreatureEvent::configureEvent] No name for creature event." << std::endl; return false; } if (readXMLString(p, "type", str)) { std::string tmpStr = asLowerCaseString(str); if (tmpStr == "login") { m_type = CREATURE_EVENT_LOGIN; } else if (tmpStr == "logout") { m_type = CREATURE_EVENT_LOGOUT; } else if (tmpStr == "think") { m_type = CREATURE_EVENT_THINK; } else if (tmpStr == "preparedeath") { m_type = CREATURE_EVENT_PREPAREDEATH; } else if (tmpStr == "death") { m_type = CREATURE_EVENT_DEATH; } else if (tmpStr == "kill") { m_type = CREATURE_EVENT_KILL; } else if (tmpStr == "advance") { m_type = CREATURE_EVENT_ADVANCE; } else if (tmpStr == "modalwindow") { m_type = CREATURE_EVENT_MODALWINDOW; } else if (tmpStr == "textedit") { m_type = CREATURE_EVENT_TEXTEDIT; } else { std::cout << "[Error - CreatureEvent::configureEvent] No valid type for creature event." << str << std::endl; return false; } } else { std::cout << "[Error - CreatureEvent::configureEvent] No type for creature event." << std::endl; return false; } m_isLoaded = true; return true; }
bool Groups::parseGroupNode(xmlNodePtr p) { if(xmlStrcmp(p->name, (const xmlChar*)"group")) return false; int32_t intValue; if(!readXMLInteger(p, "id", intValue)) { std::cout << "[Warning - Groups::parseGroupNode] Missing group id." << std::endl; return false; } std::string strValue; int64_t int64Value; Group* group = new Group(intValue); if(readXMLString(p, "name", strValue)) { group->setFullName(strValue); group->setName(asLowerCaseString(strValue)); } if(readXMLInteger64(p, "flags", int64Value)) group->setFlags(int64Value); if(readXMLInteger64(p, "customFlags", int64Value)) group->setCustomFlags(int64Value); if(readXMLInteger(p, "access", intValue)) group->setAccess(intValue); if(readXMLInteger(p, "ghostAccess", intValue)) group->setGhostAccess(intValue); else group->setGhostAccess(group->getAccess()); if(readXMLInteger(p, "violationReasons", intValue)) group->setViolationReasons(intValue); if(readXMLInteger(p, "nameViolationFlags", intValue)) group->setNameViolationFlags(intValue); if(readXMLInteger(p, "statementViolationFlags", intValue)) group->setStatementViolationFlags(intValue); if(readXMLInteger(p, "depotLimit", intValue)) group->setDepotLimit(intValue); if(readXMLInteger(p, "maxVips", intValue)) group->setMaxVips(intValue); if(readXMLInteger(p, "outfit", intValue)) group->setOutfit(intValue); groupsMap[group->getId()] = group; return true; }
bool CreatureEvent::configureEvent(xmlNodePtr p) { std::string str; //Name that will be used in monster xml files and // lua function to register events to reference this event if(readXMLString(p, "name", str)) { m_eventName = str; } else { std::cout << "Error: [CreatureEvent::configureEvent] No name for creature event." << std::endl; return false; } if(readXMLString(p, "type", str)) { if(asLowerCaseString(str) == "login") { m_type = CREATURE_EVENT_LOGIN; } else if(asLowerCaseString(str) == "logout") { m_type = CREATURE_EVENT_LOGOUT; } else if(asLowerCaseString(str) == "die") { m_type = CREATURE_EVENT_DIE; } else if(asLowerCaseString(str) == "kill") { m_type = CREATURE_EVENT_KILL; } else if(asLowerCaseString(str) == "advance") { m_type = CREATURE_EVENT_ADVANCE; } else if(asLowerCaseString(str) == "look") { m_type = CREATURE_EVENT_LOOK; } else { std::cout << "Error: [CreatureEvent::configureEvent] No valid type for creature event." << str << std::endl; return false; } } else { std::cout << "Error: [CreatureEvent::configureEvent] No type for creature event." << std::endl; return false; } return true; }
bool Monsters::loadFromXml(bool reloading /*= false*/) { loaded = false; xmlDocPtr doc = xmlParseFile(getFilePath(FILE_TYPE_OTHER, "monster/monsters.xml").c_str()); if(!doc) { std::clog << "[Warning - Monsters::loadFromXml] Cannot load monsters file." << std::endl; std::clog << getLastXMLError() << std::endl; return false; } xmlNodePtr root = xmlDocGetRootElement(doc); if(xmlStrcmp(root->name,(const xmlChar*)"monsters")) { std::clog << "[Error - Monsters::loadFromXml] Malformed monsters file." << std::endl; xmlFreeDoc(doc); return false; } for(xmlNodePtr p = root->children; p; p = p->next) { if(p->type != XML_ELEMENT_NODE) continue; if(xmlStrcmp(p->name, (const xmlChar*)"monster")) { std::clog << "[Warning - Monsters::loadFromXml] Unknown node name (" << p->name << ")." << std::endl; continue; } std::string file, name; if(!readXMLString(p, "file", file) || !readXMLString(p, "name", name)) continue; file = getFilePath(FILE_TYPE_OTHER, "monster/" + file); loadMonster(file, name, reloading); } xmlFreeDoc(doc); loaded = true; return loaded; }
bool Chat::load() { xmlDocPtr doc = xmlParseFile("data/chatchannels/chatchannels.xml"); if (!doc) { return false; } xmlNodePtr root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"channels") != 0) { xmlFreeDoc(doc); return false; } xmlNodePtr p = root->children; while (p) { if (xmlStrcmp(p->name, (const xmlChar*)"channel") == 0) { ChatChannel channel; channel.id = readXMLValue<uint16_t>(p, "id"); readXMLString(p, "name", channel.name); channel.publicChannel = readXMLValue<int32_t>(p, "public") > 0; std::string scriptFile; if (readXMLString(p, "script", scriptFile)) { if (m_scriptInterface.loadFile("data/chatchannels/scripts/" + scriptFile) == 0) { channel.onSpeakEvent = m_scriptInterface.getEvent("onSpeak"); channel.canJoinEvent = m_scriptInterface.getEvent("canJoin"); channel.onJoinEvent = m_scriptInterface.getEvent("onJoin"); channel.onLeaveEvent = m_scriptInterface.getEvent("onLeave"); } else { std::cout << "[Warning - Chat::load] Can not load script: " << scriptFile << std::endl; } } normalChannels[channel.id] = channel; } p = p->next; } xmlFreeDoc(doc); return true; }
bool TalkAction::configureEvent(xmlNodePtr p) { std::string str; if(readXMLString(p, "words", str)){ m_words = str; } else{ std::cout << "Error: [TalkAction::configureEvent] No words for TalkAction or Spell." << std::endl; return false; } return true; }
bool RaidEvent::configureRaidEvent(xmlNodePtr eventNode) { std::string strValue; if(readXMLString(eventNode, "ref", strValue)) m_ref = booleanString(strValue); int32_t intValue; if(readXMLInteger(eventNode, "delay", intValue)) m_delay = std::max((int32_t)m_delay, intValue); return true; }
bool AnnounceEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; std::string strValue; if(!readXMLString(eventNode, "message", strValue)) { std::clog << "[Error - AnnounceEvent::configureRaidEvent] Message tag missing for announce event." << std::endl; return false; } m_message = strValue; if(readXMLString(eventNode, "type", strValue)) { std::string tmpStrValue = asLowerCaseString(strValue); if(tmpStrValue == "warning") m_messageType = MSG_STATUS_WARNING; else if(tmpStrValue == "event") m_messageType = MSG_EVENT_ADVANCE; else if(tmpStrValue == "default") m_messageType = MSG_EVENT_DEFAULT; else if(tmpStrValue == "description") m_messageType = MSG_INFO_DESCR; else if(tmpStrValue == "status") m_messageType = MSG_STATUS_SMALL; else if(tmpStrValue == "blue") m_messageType = MSG_STATUS_CONSOLE_BLUE; else if(tmpStrValue == "red") m_messageType = MSG_STATUS_CONSOLE_RED; else std::clog << "[Notice - AnnounceEvent::configureRaidEvent] Unknown type tag for announce event, using default: " << (int32_t)m_messageType << std::endl; } else std::clog << "[Notice - AnnounceEvent::configureRaidEvent] Missing type tag for announce event. Using default: " << (int32_t)m_messageType << std::endl; return true; }
bool Item::loadItem(xmlNodePtr node, Container* parent) { if (xmlStrcmp(node->name, (const xmlChar*)"item") == 0) { int32_t intValue; std::string strValue; Item* item = NULL; if (readXMLInteger(node, "id", intValue)) { item = Item::CreateItem(intValue); } if (!item) { return false; } //optional if (readXMLInteger(node, "subtype", intValue)) { item->setSubType(intValue); } if (readXMLInteger(node, "actionid", intValue)) { item->setActionId(intValue); } if (readXMLString(node, "text", strValue)) { item->setText(strValue); } if (item->getContainer()) { loadContainer(node, item->getContainer()); } if (parent) { parent->addItem(item); } return true; } return false; }
Item* Admin::createMail(const std::string xmlData, std::string& name) { xmlDocPtr doc = xmlParseMemory(xmlData.c_str(), xmlData.length()); if(!doc) return NULL; xmlNodePtr root = xmlDocGetRootElement(doc); if(xmlStrcmp(root->name,(const xmlChar*)"mail")) return NULL; int32_t intValue; std::string strValue; int32_t itemId = ITEM_PARCEL; if(readXMLString(root, "to", strValue)) name = strValue; if(readXMLInteger(root, "id", intValue)) itemId = intValue; Item* mailItem = Item::CreateItem(itemId); mailItem->setParent(VirtualCylinder::virtualCylinder); if(Container* mailContainer = mailItem->getContainer()) { xmlNodePtr node = root->children; while(node) { if(node->type != XML_ELEMENT_NODE) { node = node->next; continue; } if(!Item::loadItem(node, mailContainer)) { delete mailContainer; return NULL; } node = node->next; } } return mailItem; }
bool SingleSpawnEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)){ return false; } std::string strValue; int intValue; if(readXMLString(eventNode, "name", strValue)){ m_monsterName = strValue; } else{ std::cout << "[Error] Raid: name tag missing for singlespawn event." << std::endl; return false; } if(readXMLInteger(eventNode, "x", intValue)){ m_position.x = intValue; } else{ std::cout << "[Error] Raid: x tag missing for singlespawn event." << std::endl; return false; } if(readXMLInteger(eventNode, "y", intValue)){ m_position.y = intValue; } else{ std::cout << "[Error] Raid: y tag missing for singlespawn event." << std::endl; return false; } if(readXMLInteger(eventNode, "z", intValue)){ m_position.z = intValue; } else{ std::cout << "[Error] Raid: z tag missing for singlespawn event." << std::endl; return false; } return true; }
bool ScriptEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)){ return false; } std::string str; if(readXMLString(eventNode, "script", str)){ std::string datadir = g_config.getString(ConfigManager::DATA_DIRECTORY); if(!loadScript(datadir + "raids/scripts/" + str)){ std::cout << "Error: [ScriptEvent::configureRaidEvent] Can not load raid script." << std::endl; return false; } } else{ std::cout << "Error: [ScriptEvent::configureRaidEvent] No script file found for raid" << std::endl; return false; } return true; }
bool ScriptEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; std::string str; if(readXMLString(eventNode, "script", str)) { if(!loadScript("data/raids/scripts/" + str)) { std::cout << "Error: [ScriptEvent::configureRaidEvent] Can not load raid script." << std::endl; return false; } } else { std::cout << "Error: [ScriptEvent::configureRaidEvent] No script file found for raid" << std::endl; return false; } return true; }
bool Vocations::loadFromXml() { std::string filename = "data/XML/vocations.xml"; xmlDocPtr doc = xmlParseFile(filename.c_str()); if (doc) { xmlNodePtr root, p; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"vocations") != 0) { xmlFreeDoc(doc); return false; } p = root->children; while (p) { std::string str; int32_t intVal; if (xmlStrcmp(p->name, (const xmlChar*)"vocation") == 0) { Vocation* voc = new Vocation(); uint32_t voc_id; xmlNodePtr configNode; if (readXMLInteger(p, "id", intVal)) { float floatVal; voc_id = intVal; if (readXMLString(p, "name", str)) { voc->name = str; } if (readXMLInteger(p, "clientid", intVal)) { voc->clientId = intVal; } if (readXMLString(p, "description", str)) { voc->description = str; } if (readXMLInteger(p, "gaincap", intVal)) { voc->gainCap = intVal; } if (readXMLInteger(p, "gainhp", intVal)) { voc->gainHP = intVal; } if (readXMLInteger(p, "gainmana", intVal)) { voc->gainMana = intVal; } if (readXMLInteger(p, "gainhpticks", intVal)) { voc->gainHealthTicks = intVal; } if (readXMLInteger(p, "gainhpamount", intVal)) { voc->gainHealthAmount = intVal; } if (readXMLInteger(p, "gainmanaticks", intVal)) { voc->gainManaTicks = intVal; } if (readXMLInteger(p, "gainmanaamount", intVal)) { voc->gainManaAmount = intVal; } if (readXMLFloat(p, "manamultiplier", floatVal)) { voc->manaMultiplier = floatVal; } if (readXMLInteger(p, "attackspeed", intVal)) { voc->attackSpeed = intVal; } if (readXMLInteger(p, "basespeed", intVal)) { voc->baseSpeed = intVal; } if (readXMLInteger(p, "soulmax", intVal)) { voc->soulMax = intVal; } if (readXMLInteger(p, "gainsoulticks", intVal)) { voc->gainSoulTicks = intVal; } if (readXMLInteger(p, "fromvoc", intVal)) { voc->fromVocation = intVal; } configNode = p->children; while (configNode) { if (xmlStrcmp(configNode->name, (const xmlChar*)"skill") == 0) { uint32_t skill_id; if (readXMLInteger(configNode, "id", intVal)) { skill_id = intVal; if (skill_id > SKILL_LAST) { std::cout << "No valid skill id. " << skill_id << std::endl; } else { if (readXMLFloat(configNode, "multiplier", floatVal)) { voc->skillMultipliers[skill_id] = floatVal; } } } else { std::cout << "Missing skill id." << std::endl; } } else if (xmlStrcmp(configNode->name, (const xmlChar*)"formula") == 0) { if (readXMLFloat(configNode, "meleeDamage", floatVal)) { voc->meleeDamageMultipler = floatVal; } if (readXMLFloat(configNode, "distDamage", floatVal)) { voc->distDamageMultipler = floatVal; } if (readXMLFloat(configNode, "defense", floatVal)) { voc->defenseMultipler = floatVal; } if (readXMLFloat(configNode, "armor", floatVal)) { voc->armorMultipler = floatVal; } } configNode = configNode->next; } vocationsMap[voc_id] = voc; } else { std::cout << "Missing vocation id." << std::endl; } } p = p->next; } xmlFreeDoc(doc); } return true; }
bool Chat::load() { xmlDocPtr doc = xmlParseFile("data/chatchannels/chatchannels.xml"); if (!doc) { return false; } xmlNodePtr root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"channels") != 0) { xmlFreeDoc(doc); return false; } xmlNodePtr p = root->children; while (p) { if (xmlStrcmp(p->name, (const xmlChar*)"channel") == 0) { ChatChannel channel; channel.id = readXMLValue<uint16_t>(p, "id"); readXMLString(p, "name", channel.name); channel.publicChannel = readXMLValue<int32_t>(p, "public") > 0; std::string scriptFile; if (readXMLString(p, "onspeak", scriptFile)) { OnSpeakChannelEvent* scriptedEvent = new OnSpeakChannelEvent; if (scriptedEvent->loadScript("data/chatchannels/scripts/" + scriptFile)) { channel.onSpeakEvent = scriptedEvent; } else { delete scriptedEvent; } } if (readXMLString(p, "canjoin", scriptFile)) { CanJoinChannelEvent* scriptedEvent = new CanJoinChannelEvent; if (scriptedEvent->loadScript("data/chatchannels/scripts/" + scriptFile)) { channel.canJoinEvent = scriptedEvent; } else { delete scriptedEvent; } } if (readXMLString(p, "onjoin", scriptFile)) { OnJoinChannelEvent* scriptedEvent = new OnJoinChannelEvent; if (scriptedEvent->loadScript("data/chatchannels/scripts/" + scriptFile)) { channel.onJoinEvent = scriptedEvent; } else { delete scriptedEvent; } } if (readXMLString(p, "onleave", scriptFile)) { OnLeaveChannelEvent* scriptedEvent = new OnLeaveChannelEvent; if (scriptedEvent->loadScript("data/chatchannels/scripts/" + scriptFile)) { channel.onLeaveEvent = scriptedEvent; } else { delete scriptedEvent; } } normalChannels[channel.id] = channel; } p = p->next; } xmlFreeDoc(doc); return true; }
bool MoveEvent::configureEvent(xmlNodePtr p) { std::string str; int intValue; if(readXMLString(p, "event", str)){ if(asLowerCaseString(str) == "stepin"){ m_eventType = MOVE_EVENT_STEP_IN; } else if(asLowerCaseString(str) == "stepout"){ m_eventType = MOVE_EVENT_STEP_OUT; } else if(asLowerCaseString(str) == "equip"){ m_eventType = MOVE_EVENT_EQUIP; } else if(asLowerCaseString(str) == "deequip"){ m_eventType = MOVE_EVENT_DEEQUIP; } else if(asLowerCaseString(str) == "additem"){ m_eventType = MOVE_EVENT_ADD_ITEM; } else if(asLowerCaseString(str) == "removeitem"){ m_eventType = MOVE_EVENT_REMOVE_ITEM; } else{ std::cout << "Error: [MoveEvent::configureMoveEvent] No valid event name " << str << std::endl; return false; } if(m_eventType == MOVE_EVENT_EQUIP || m_eventType == MOVE_EVENT_DEEQUIP){ if(readXMLString(p, "slot", str)){ if(asLowerCaseString(str) == "head"){ slot = SLOT_HEAD; } else if(asLowerCaseString(str) == "necklace"){ slot = SLOT_NECKLACE; } else if(asLowerCaseString(str) == "backpack"){ slot = SLOT_BACKPACK; } else if(asLowerCaseString(str) == "armor"){ slot = SLOT_ARMOR; } else if(asLowerCaseString(str) == "right-hand"){ slot = SLOT_RIGHT; } else if(asLowerCaseString(str) == "left-hand"){ slot = SLOT_LEFT; } else if(asLowerCaseString(str) == "legs"){ slot = SLOT_LEGS; } else if(asLowerCaseString(str) == "feet"){ slot = SLOT_FEET; } else if(asLowerCaseString(str) == "ring"){ slot = SLOT_RING; } else if(asLowerCaseString(str) == "ammo"){ slot = SLOT_AMMO; } else{ std::cout << "Warning: [MoveEvent::configureMoveEvent] " << "Unknown slot type " << str << std::endl; } } wieldInfo = 0; if(readXMLInteger(p, "lvl", intValue) || readXMLInteger(p, "level", intValue)){ reqLevel = intValue; if(reqLevel > 0){ wieldInfo |= WIELDINFO_LEVEL; } } if(readXMLInteger(p, "maglv", intValue) || readXMLInteger(p, "maglevel", intValue)){ reqMagLevel = intValue; if(reqMagLevel > 0){ wieldInfo |= WIELDINFO_MAGLV; } } if(readXMLInteger(p, "prem", intValue) || readXMLInteger(p, "premium", intValue)){ premium = (intValue != 0); if(premium){ wieldInfo |= WIELDINFO_PREMIUM; } } //Gather vocation information typedef std::list<std::string> STRING_LIST; STRING_LIST vocStringList; xmlNodePtr vocationNode = p->children; while(vocationNode){ if(xmlStrcmp(vocationNode->name,(const xmlChar*)"vocation") == 0){ if(readXMLString(vocationNode, "name", str)){ int32_t vocationId = g_vocations.getVocationId(str); if(vocationId != -1){ vocEquipMap[vocationId] = true; intValue = 1; readXMLInteger(vocationNode, "showInDescription", intValue); if(intValue != 0){ toLowerCaseString(str); vocStringList.push_back(str); } } } } vocationNode = vocationNode->next; } if(!vocStringList.empty()){ for(STRING_LIST::iterator it = vocStringList.begin(); it != vocStringList.end(); ++it){ if(*it != vocStringList.front()){ if(*it != vocStringList.back()){ vocationString += ", "; } else{ vocationString += " and "; } } vocationString += *it; vocationString += "s"; } wieldInfo |= WIELDINFO_VOCREQ; } } } else{ std::cout << "Error: [MoveEvent::configureMoveEvent] No event found." << std::endl; return false; } return true; }
bool MoveEvents::registerEvent(Event* event, xmlNodePtr p) { MoveEvent* moveEvent = dynamic_cast<MoveEvent*>(event); if(!moveEvent) return false; bool success = true; int id; std::string str; MoveEvent_t eventType = moveEvent->getEventType(); if(eventType == MOVE_EVENT_ADD_ITEM || eventType == MOVE_EVENT_REMOVE_ITEM){ if(readXMLInteger(p,"tileitem",id) && id == 1){ switch(eventType){ case MOVE_EVENT_ADD_ITEM: moveEvent->setEventType(MOVE_EVENT_ADD_ITEM_ITEMTILE); break; case MOVE_EVENT_REMOVE_ITEM: moveEvent->setEventType(MOVE_EVENT_REMOVE_ITEM_ITEMTILE); break; default: break; } } } if(readXMLInteger(p,"itemid",id)){ if(moveEvent->getEventType() == MOVE_EVENT_EQUIP){ ItemType& it = Item::items.getItemType(id); it.wieldInfo = moveEvent->getWieldInfo(); it.minReqLevel = moveEvent->getReqLevel(); it.minReqMagicLevel = moveEvent->getReqMagLv(); it.vocationString = moveEvent->getVocationString(); } addEvent(moveEvent, id, m_itemIdMap); } else if(readXMLInteger(p,"uniqueid",id)){ addEvent(moveEvent, id, m_uniqueIdMap); } else if(readXMLInteger(p,"actionid",id)){ addEvent(moveEvent, id, m_actionIdMap); } else if(readXMLString(p,"pos",str)){ std::vector<std::string> posList = explodeString(str, ";"); if(posList.size() < 3){ success = false; } else{ Position pos; pos.x = atoi(posList[0].c_str()); pos.y = atoi(posList[1].c_str()); pos.z = atoi(posList[2].c_str()); addEvent(moveEvent, pos, m_positionMap); } } else{ success = false; } return success; }
bool Vocations::parseVocationNode(xmlNodePtr p) { std::string strValue; int32_t intValue; float floatValue; if(xmlStrcmp(p->name, (const xmlChar*)"vocation")) return false; if(!readXMLInteger(p, "id", intValue)) { std::cout << "[Error - Vocations::parseVocationNode] Missing vocation id." << std::endl; return false; } Vocation* voc = new Vocation(intValue); if(readXMLString(p, "name", strValue)) voc->setName(strValue); if(readXMLString(p, "description", strValue)) voc->setDescription(strValue); if(readXMLString(p, "needpremium", strValue)) voc->setNeedPremium(booleanString(strValue)); if(readXMLInteger(p, "gaincap", intValue) || readXMLInteger(p, "gaincapacity", intValue)) voc->setGainCap(intValue); if(readXMLInteger(p, "gainhp", intValue) || readXMLInteger(p, "gainhealth", intValue)) voc->setGain(GAIN_HEALTH, intValue); if(readXMLInteger(p, "gainmana", intValue)) voc->setGain(GAIN_MANA, intValue); if(readXMLInteger(p, "gainhpticks", intValue) || readXMLInteger(p, "gainhealthticks", intValue)) voc->setGainTicks(GAIN_HEALTH, intValue); if(readXMLInteger(p, "gainhpamount", intValue) || readXMLInteger(p, "gainhealthamount", intValue)) voc->setGainAmount(GAIN_HEALTH, intValue); if(readXMLInteger(p, "gainmanaticks", intValue)) voc->setGainTicks(GAIN_MANA, intValue); if(readXMLInteger(p, "gainmanaamount", intValue)) voc->setGainAmount(GAIN_MANA, intValue); if(readXMLFloat(p, "manamultiplier", floatValue)) voc->setMultiplier(MULTIPLIER_MANA, floatValue); if(readXMLInteger(p, "attackspeed", intValue)) voc->setAttackSpeed(intValue); if(readXMLInteger(p, "basespeed", intValue)) voc->setBaseSpeed(intValue); if(readXMLInteger(p, "soulmax", intValue)) voc->setGain(GAIN_SOUL, intValue); if(readXMLInteger(p, "gainsoulamount", intValue)) voc->setGainAmount(GAIN_SOUL, intValue); if(readXMLInteger(p, "gainsoulticks", intValue)) voc->setGainTicks(GAIN_SOUL, intValue); if(readXMLString(p, "attackable", strValue)) voc->setAttackable(booleanString(strValue)); if(readXMLInteger(p, "fromvoc", intValue) || readXMLInteger(p, "fromvocation", intValue)) voc->setFromVocation(intValue); if(readXMLInteger(p, "lessloss", intValue)) voc->setLessLoss(intValue); xmlNodePtr configNode = p->children; while(configNode) { if(!xmlStrcmp(configNode->name, (const xmlChar*)"skill")) { if(readXMLFloat(configNode, "fist", floatValue)) voc->setSkillMultiplier(SKILL_FIST, floatValue); if(readXMLInteger(configNode, "fistBase", intValue)) voc->setSkillBase(SKILL_FIST, intValue); if(readXMLFloat(configNode, "club", floatValue)) voc->setSkillMultiplier(SKILL_CLUB, floatValue); if(readXMLInteger(configNode, "clubBase", intValue)) voc->setSkillBase(SKILL_CLUB, intValue); if(readXMLFloat(configNode, "axe", floatValue)) voc->setSkillMultiplier(SKILL_AXE, floatValue); if(readXMLInteger(configNode, "axeBase", intValue)) voc->setSkillBase(SKILL_AXE, intValue); if(readXMLFloat(configNode, "sword", floatValue)) voc->setSkillMultiplier(SKILL_SWORD, floatValue); if(readXMLInteger(configNode, "swordBase", intValue)) voc->setSkillBase(SKILL_SWORD, intValue); if(readXMLFloat(configNode, "distance", floatValue) || readXMLFloat(configNode, "dist", floatValue)) voc->setSkillMultiplier(SKILL_DIST, floatValue); if(readXMLInteger(configNode, "distanceBase", intValue) || readXMLInteger(configNode, "distBase", intValue)) voc->setSkillBase(SKILL_DIST, intValue); if(readXMLFloat(configNode, "shielding", floatValue) || readXMLFloat(configNode, "shield", floatValue)) voc->setSkillMultiplier(SKILL_SHIELD, floatValue); if(readXMLInteger(configNode, "shieldingBase", intValue) || readXMLInteger(configNode, "shieldBase", intValue)) voc->setSkillBase(SKILL_SHIELD, intValue); if(readXMLFloat(configNode, "fishing", floatValue) || readXMLFloat(configNode, "fish", floatValue)) voc->setSkillMultiplier(SKILL_FISH, floatValue); if(readXMLInteger(configNode, "fishingBase", intValue) || readXMLInteger(configNode, "fishBase", intValue)) voc->setSkillBase(SKILL_FISH, intValue); if(readXMLFloat(configNode, "experience", floatValue) || readXMLFloat(configNode, "exp", floatValue)) voc->setSkillMultiplier(SKILL__LEVEL, floatValue); if(readXMLInteger(configNode, "id", intValue)) { skills_t skill = (skills_t)intValue; if(intValue < SKILL_FIRST || intValue >= SKILL__LAST) { std::cout << "[Error - Vocations::parseVocationNode] No valid skill id (" << intValue << ")." << std::endl; continue; } if(readXMLInteger(configNode, "base", intValue)) voc->setSkillBase(skill, intValue); if(readXMLFloat(configNode, "multiplier", floatValue)) voc->setSkillMultiplier(skill, floatValue); } } else if(!xmlStrcmp(configNode->name, (const xmlChar*)"formula")) { if(readXMLFloat(configNode, "meleeDamage", floatValue)) voc->setMultiplier(MULTIPLIER_MELEE, floatValue); if(readXMLFloat(configNode, "distDamage", floatValue) || readXMLFloat(configNode, "distanceDamage", floatValue)) voc->setMultiplier(MULTIPLIER_DISTANCE, floatValue); if(readXMLFloat(configNode, "wandDamage", floatValue) || readXMLFloat(configNode, "rodDamage", floatValue)) voc->setMultiplier(MULTIPLIER_WAND, floatValue); if(readXMLFloat(configNode, "magDamage", floatValue) || readXMLFloat(configNode, "magicDamage", floatValue)) voc->setMultiplier(MULTIPLIER_MAGIC, floatValue); if(readXMLFloat(configNode, "magHealingDamage", floatValue) || readXMLFloat(configNode, "magicHealingDamage", floatValue)) voc->setMultiplier(MULTIPLIER_MAGICHEALING, floatValue); if(readXMLFloat(configNode, "defense", floatValue)) voc->setMultiplier(MULTIPLIER_DEFENSE, floatValue); if(readXMLFloat(configNode, "magDefense", floatValue) || readXMLFloat(configNode, "magicDefense", floatValue)) voc->setMultiplier(MULTIPLIER_MAGICDEFENSE, floatValue); if(readXMLFloat(configNode, "armor", floatValue)) voc->setMultiplier(MULTIPLIER_ARMOR, floatValue); } else if(!xmlStrcmp(configNode->name, (const xmlChar*)"absorb")) { if(readXMLInteger(configNode, "percentAll", intValue)) { for(uint32_t i = COMBAT_FIRST; i <= COMBAT_LAST; i++) voc->increaseAbsorbPercent((CombatType_t)i, intValue); } else if(readXMLInteger(configNode, "percentElements", intValue)) { voc->increaseAbsorbPercent(COMBAT_ENERGYDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_FIREDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_EARTHDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_ICEDAMAGE, intValue); } else if(readXMLInteger(configNode, "percentMagic", intValue)) { voc->increaseAbsorbPercent(COMBAT_ENERGYDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_FIREDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_EARTHDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_ICEDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_HOLYDAMAGE, intValue); voc->increaseAbsorbPercent(COMBAT_DEATHDAMAGE, intValue); } else if(readXMLInteger(configNode, "percentEnergy", intValue)) voc->increaseAbsorbPercent(COMBAT_ENERGYDAMAGE, intValue); else if(readXMLInteger(configNode, "percentFire", intValue)) voc->increaseAbsorbPercent(COMBAT_FIREDAMAGE, intValue); else if(readXMLInteger(configNode, "percentPoison", intValue) || readXMLInteger(configNode, "percentEarth", intValue)) voc->increaseAbsorbPercent(COMBAT_EARTHDAMAGE, intValue); else if(readXMLInteger(configNode, "percentIce", intValue)) voc->increaseAbsorbPercent(COMBAT_ICEDAMAGE, intValue); else if(readXMLInteger(configNode, "percentHoly", intValue)) voc->increaseAbsorbPercent(COMBAT_HOLYDAMAGE, intValue); else if(readXMLInteger(configNode, "percentDeath", intValue)) voc->increaseAbsorbPercent(COMBAT_DEATHDAMAGE, intValue); else if(readXMLInteger(configNode, "percentLifeDrain", intValue)) voc->increaseAbsorbPercent(COMBAT_LIFEDRAIN, intValue); else if(readXMLInteger(configNode, "percentManaDrain", intValue)) voc->increaseAbsorbPercent(COMBAT_MANADRAIN, intValue); else if(readXMLInteger(configNode, "percentDrown", intValue)) voc->increaseAbsorbPercent(COMBAT_DROWNDAMAGE, intValue); else if(readXMLInteger(configNode, "percentPhysical", intValue)) voc->increaseAbsorbPercent(COMBAT_PHYSICALDAMAGE, intValue); else if(readXMLInteger(configNode, "percentHealing", intValue)) voc->increaseAbsorbPercent(COMBAT_HEALING, intValue); else if(readXMLInteger(configNode, "percentUndefined", intValue)) voc->increaseAbsorbPercent(COMBAT_UNDEFINEDDAMAGE, intValue); } configNode = configNode->next; } vocationsMap[voc->getId()] = voc; return true; }