Monster::Monster(MonsterType* _mType): Creature() { isIdle = true; nick = _mType->name; name = _mType->realName; isMasterInRange = false; teleportToMaster = false; mType = _mType; spawn = NULL; raid = NULL; defaultOutfit = mType->outfit; currentOutfit = mType->outfit; double multiplier = g_config.getDouble(ConfigManager::RATE_MONSTER_HEALTH); health = (int32_t)(mType->health * multiplier); healthMax = (int32_t)(mType->healthMax * multiplier); baseSpeed = mType->baseSpeed; internalLight.level = mType->lightLevel; internalLight.color = mType->lightColor; setSkull(mType->skull); setShield(mType->partyShield); hideName = mType->hideName, hideHealth = mType->hideHealth; minCombatValue = 0; maxCombatValue = 0; targetTicks = 0; targetChangeTicks = 0; targetChangeCooldown = 0; attackTicks = 0; defenseTicks = 0; yellTicks = 0; extraMeleeAttack = false; //setStorage(510, mType->name); // register creature events for(StringVec::iterator it = mType->scriptList.begin(); it != mType->scriptList.end(); ++it) { if(!registerCreatureEvent(*it)) std::cout << "[Warning - Monster::Monster] Unknown event name - " << *it << std::endl; } #ifdef __ENABLE_SERVER_DIAGNOSTIC__ monsterCount++; #endif }
Monster::Monster(MonsterType* __type, Raid* raid, Spawn* spawn) : Creature(), _raid(raid), _spawn(spawn) { _type = __type; defaultOutfit = _type->outfit; currentOutfit = _type->outfit; double multiplier = server.configManager().getDouble(ConfigManager::RATE_MONSTER_HEALTH); health = (int32_t)(_type->health * multiplier); healthMax = (int32_t)(_type->healthMax * multiplier); baseSpeed = _type->baseSpeed; internalLight.level = _type->lightLevel; internalLight.color = _type->lightColor; setSkull(_type->skull); setShield(_type->partyShield); hideName = _type->hideName, hideHealth = _type->hideHealth; minCombatValue = 0; maxCombatValue = 0; targetTicks = 0; attackTicks = 0; defenseTicks = 0; yellTicks = 0; extraMeleeAttack = false; resetTicks = false; // register creature events for(StringVector::iterator it = _type->scriptList.begin(); it != _type->scriptList.end(); ++it) { if(!registerCreatureEvent(*it)) LOGe("[Monster::Monster] Unknown event name - " << *it); } }
bool Npc::loadFromXml() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(filename.c_str()); if (!result) { printXMLError("Error - Npc::loadFromXml", filename, result); return false; } pugi::xml_node npcNode = doc.child("npc"); if (!npcNode) { std::cout << "[Error - Npc::loadFromXml] Missing npc tag in " << filename << std::endl; return false; } name = npcNode.attribute("name").as_string(); attackable = npcNode.attribute("attackable").as_bool(); floorChange = npcNode.attribute("floorchange").as_bool(); pugi::xml_attribute attr; if ((attr = npcNode.attribute("speed"))) { baseSpeed = pugi::cast<uint32_t>(attr.value()); } else { baseSpeed = 100; } if ((attr = npcNode.attribute("walkinterval"))) { walkTicks = pugi::cast<uint32_t>(attr.value()); } if ((attr = npcNode.attribute("walkradius"))) { masterRadius = pugi::cast<int32_t>(attr.value()); } if ((attr = npcNode.attribute("ignoreheight"))) { ignoreHeight = attr.as_bool(); } if ((attr = npcNode.attribute("speechbubble"))) { speechBubble = pugi::cast<uint32_t>(attr.value()); } if ((attr = npcNode.attribute("skull"))) { setSkull(getSkullType(attr.as_string())); } pugi::xml_node healthNode = npcNode.child("health"); if (healthNode) { if ((attr = healthNode.attribute("now"))) { health = pugi::cast<int32_t>(attr.value()); } else { health = 100; } if ((attr = healthNode.attribute("max"))) { healthMax = pugi::cast<int32_t>(attr.value()); } else { healthMax = 100; } } pugi::xml_node lookNode = npcNode.child("look"); if (lookNode) { pugi::xml_attribute lookTypeAttribute = lookNode.attribute("type"); if (lookTypeAttribute) { defaultOutfit.lookType = pugi::cast<uint16_t>(lookTypeAttribute.value()); defaultOutfit.lookHead = pugi::cast<uint16_t>(lookNode.attribute("head").value()); defaultOutfit.lookBody = pugi::cast<uint16_t>(lookNode.attribute("body").value()); defaultOutfit.lookLegs = pugi::cast<uint16_t>(lookNode.attribute("legs").value()); defaultOutfit.lookFeet = pugi::cast<uint16_t>(lookNode.attribute("feet").value()); defaultOutfit.lookAddons = pugi::cast<uint16_t>(lookNode.attribute("addons").value()); } else if ((attr = lookNode.attribute("typeex"))) { defaultOutfit.lookTypeEx = pugi::cast<uint16_t>(attr.value()); } defaultOutfit.lookMount = pugi::cast<uint16_t>(lookNode.attribute("mount").value()); currentOutfit = defaultOutfit; } for (auto parameterNode : npcNode.child("parameters").children()) { parameters[parameterNode.attribute("key").as_string()] = parameterNode.attribute("value").as_string(); } pugi::xml_attribute scriptFile = npcNode.attribute("script"); if (scriptFile) { npcEventHandler = new NpcEventsHandler(scriptFile.as_string(), this); if (!npcEventHandler->isLoaded()) { delete npcEventHandler; npcEventHandler = nullptr; return false; } } return true; }