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; }
void Items::parseItemNode(const pugi::xml_node& itemNode, uint16_t id) { if (id > 30000 && id < 30100) { id -= 30000; if (id >= items.size()) { items.resize(id + 1); } ItemType& iType = items[id]; iType.id = id; } ItemType& it = getItemType(id); if (it.id == 0) { return; } it.name = itemNode.attribute("name").as_string(); pugi::xml_attribute articleAttribute = itemNode.attribute("article"); if (articleAttribute) { it.article = articleAttribute.as_string(); } pugi::xml_attribute pluralAttribute = itemNode.attribute("plural"); if (pluralAttribute) { it.pluralName = pluralAttribute.as_string(); } for (auto attributeNode : itemNode.children()) { pugi::xml_attribute keyAttribute = attributeNode.attribute("key"); if (!keyAttribute) { continue; } pugi::xml_attribute valueAttribute = attributeNode.attribute("value"); if (!valueAttribute) { continue; } std::string tmpStrValue = asLowerCaseString(keyAttribute.as_string()); if (tmpStrValue == "type") { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "key") { it.type = ITEM_TYPE_KEY; } else if (tmpStrValue == "magicfield") { it.type = ITEM_TYPE_MAGICFIELD; } else if (tmpStrValue == "container") { it.group = ITEM_GROUP_CONTAINER; it.type = ITEM_TYPE_CONTAINER; } else if (tmpStrValue == "depot") { it.type = ITEM_TYPE_DEPOT; } else if (tmpStrValue == "mailbox") { it.type = ITEM_TYPE_MAILBOX; } else if (tmpStrValue == "trashholder") { it.type = ITEM_TYPE_TRASHHOLDER; } else if (tmpStrValue == "teleport") { it.type = ITEM_TYPE_TELEPORT; } else if (tmpStrValue == "door") { it.type = ITEM_TYPE_DOOR; } else if (tmpStrValue == "bed") { it.type = ITEM_TYPE_BED; } else if (tmpStrValue == "rune") { it.type = ITEM_TYPE_RUNE; } else { std::cout << "[Warning - Items::parseItemNode] Unknown type: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "description") { it.description = valueAttribute.as_string(); } else if (tmpStrValue == "runespellname") { it.runeSpellName = valueAttribute.as_string(); } else if (tmpStrValue == "weight") { it.weight = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "showcount") { it.showCount = valueAttribute.as_bool(); } else if (tmpStrValue == "armor") { it.armor = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "defense") { it.defense = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "extradef") { it.extraDefense = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "attack") { it.attack = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "rotateto") { it.rotateTo = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "moveable" || tmpStrValue == "movable") { it.moveable = valueAttribute.as_bool(); } else if (tmpStrValue == "blockprojectile") { it.blockProjectile = valueAttribute.as_bool(); } else if (tmpStrValue == "allowpickupable" || tmpStrValue == "pickupable") { it.allowPickupable = valueAttribute.as_bool(); } else if (tmpStrValue == "floorchange") { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "down") { it.floorChange = TILESTATE_FLOORCHANGE_DOWN; } else if (tmpStrValue == "north") { it.floorChange = TILESTATE_FLOORCHANGE_NORTH; } else if (tmpStrValue == "south") { it.floorChange = TILESTATE_FLOORCHANGE_SOUTH; } else if (tmpStrValue == "southalt") { it.floorChange = TILESTATE_FLOORCHANGE_SOUTH_ALT; } else if (tmpStrValue == "west") { it.floorChange = TILESTATE_FLOORCHANGE_WEST; } else if (tmpStrValue == "east") { it.floorChange = TILESTATE_FLOORCHANGE_EAST; } else if (tmpStrValue == "eastalt") { it.floorChange = TILESTATE_FLOORCHANGE_EAST_ALT; } else { std::cout << "[Warning - Items::parseItemNode] Unknown floorChange: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "corpsetype") { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "venom") { it.corpseType = RACE_VENOM; } else if (tmpStrValue == "blood") { it.corpseType = RACE_BLOOD; } else if (tmpStrValue == "undead") { it.corpseType = RACE_UNDEAD; } else if (tmpStrValue == "fire") { it.corpseType = RACE_FIRE; } else if (tmpStrValue == "energy") { it.corpseType = RACE_ENERGY; } else { std::cout << "[Warning - Items::parseItemNode] Unknown corpseType: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "containersize") { it.maxItems = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "fluidsource") { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "water") { it.fluidSource = FLUID_WATER; } else if (tmpStrValue == "blood") { it.fluidSource = FLUID_BLOOD; } else if (tmpStrValue == "beer") { it.fluidSource = FLUID_BEER; } else if (tmpStrValue == "slime") { it.fluidSource = FLUID_SLIME; } else if (tmpStrValue == "lemonade") { it.fluidSource = FLUID_LEMONADE; } else if (tmpStrValue == "milk") { it.fluidSource = FLUID_MILK; } else if (tmpStrValue == "mana") { it.fluidSource = FLUID_MANA; } else if (tmpStrValue == "life") { it.fluidSource = FLUID_LIFE; } else if (tmpStrValue == "oil") { it.fluidSource = FLUID_OIL; } else if (tmpStrValue == "urine") { it.fluidSource = FLUID_URINE; } else if (tmpStrValue == "coconut") { it.fluidSource = FLUID_COCONUTMILK; } else if (tmpStrValue == "wine") { it.fluidSource = FLUID_WINE; } else if (tmpStrValue == "mud") { it.fluidSource = FLUID_MUD; } else if (tmpStrValue == "fruitjuice") { it.fluidSource = FLUID_FRUITJUICE; } else if (tmpStrValue == "lava") { it.fluidSource = FLUID_LAVA; } else if (tmpStrValue == "rum") { it.fluidSource = FLUID_RUM; } else if (tmpStrValue == "swamp") { it.fluidSource = FLUID_SWAMP; } else if (tmpStrValue == "tea") { it.fluidSource = FLUID_TEA; } else if (tmpStrValue == "mead") { it.fluidSource = FLUID_MEAD; } else { std::cout << "[Warning - Items::parseItemNode] Unknown fluidSource: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "readable") { it.canReadText = valueAttribute.as_bool(); } else if (tmpStrValue == "writeable") { it.canWriteText = valueAttribute.as_bool(); it.canReadText = it.canWriteText; } else if (tmpStrValue == "maxtextlen") { it.maxTextLen = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "writeonceitemid") { it.writeOnceItemId = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "weapontype") { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "sword") { it.weaponType = WEAPON_SWORD; } else if (tmpStrValue == "club") { it.weaponType = WEAPON_CLUB; } else if (tmpStrValue == "axe") { it.weaponType = WEAPON_AXE; } else if (tmpStrValue == "shield") { it.weaponType = WEAPON_SHIELD; } else if (tmpStrValue == "distance") { it.weaponType = WEAPON_DISTANCE; } else if (tmpStrValue == "wand") { it.weaponType = WEAPON_WAND; } else if (tmpStrValue == "ammunition") { it.weaponType = WEAPON_AMMO; } else { std::cout << "[Warning - Items::parseItemNode] Unknown weaponType: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "slottype") { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "head") { it.slotPosition |= SLOTP_HEAD; } else if (tmpStrValue == "body") { it.slotPosition |= SLOTP_ARMOR; } else if (tmpStrValue == "legs") { it.slotPosition |= SLOTP_LEGS; } else if (tmpStrValue == "feet") { it.slotPosition |= SLOTP_FEET; } else if (tmpStrValue == "backpack") { it.slotPosition |= SLOTP_BACKPACK; } else if (tmpStrValue == "two-handed") { it.slotPosition |= SLOTP_TWO_HAND; } else if (tmpStrValue == "right-hand") { it.slotPosition &= ~SLOTP_LEFT; } else if (tmpStrValue == "left-hand") { it.slotPosition &= ~SLOTP_RIGHT; } else if (tmpStrValue == "necklace") { it.slotPosition |= SLOTP_NECKLACE; } else if (tmpStrValue == "ring") { it.slotPosition |= SLOTP_RING; } else if (tmpStrValue == "ammo") { it.slotPosition |= SLOTP_AMMO; } else if (tmpStrValue == "hand") { it.slotPosition |= SLOTP_HAND; } else { std::cout << "[Warning - Items::parseItemNode] Unknown slotType: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "ammotype") { it.ammoType = getAmmoType(valueAttribute.as_string()); if (it.ammoType == AMMO_NONE) { std::cout << "[Warning - Items::parseItemNode] Unknown ammoType: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "shoottype") { ShootType_t shoot = getShootType(valueAttribute.as_string()); if (shoot != CONST_ANI_NONE) { it.shootType = shoot; } else { std::cout << "[Warning - Items::parseItemNode] Unknown shootType: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "effect") { MagicEffectClasses effect = getMagicEffect(valueAttribute.as_string()); if (effect != CONST_ME_NONE) { it.magicEffect = effect; } else { std::cout << "[Warning - Items::parseItemNode] Unknown effect: " << valueAttribute.as_string() << std::endl; } } else if (tmpStrValue == "range") { it.shootRange = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "stopduration") { it.stopTime = valueAttribute.as_bool(); } else if (tmpStrValue == "decayto") { it.decayTo = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "transformequipto") { it.transformEquipTo = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "transformdeequipto") { it.transformDeEquipTo = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "duration") { it.decayTime = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "showduration") { it.showDuration = valueAttribute.as_bool(); } else if (tmpStrValue == "charges") { it.charges = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "showcharges") { it.showCharges = valueAttribute.as_bool(); } else if (tmpStrValue == "showattributes") { it.showAttributes = valueAttribute.as_bool(); } else if (tmpStrValue == "hitchance") { it.hitChance = std::min<int8_t>(100, std::max<int8_t>(-100, pugi::cast<int16_t>(valueAttribute.value()))); } else if (tmpStrValue == "maxhitchance") { it.maxHitChance = std::min<uint32_t>(100, pugi::cast<uint32_t>(valueAttribute.value())); } else if (tmpStrValue == "invisible") { it.getAbilities().invisible = valueAttribute.as_bool(); } else if (tmpStrValue == "speed") { it.getAbilities().speed = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "healthgain") { Abilities& abilities = it.getAbilities(); abilities.regeneration = true; abilities.healthGain = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "healthticks") { Abilities& abilities = it.getAbilities(); abilities.regeneration = true; abilities.healthTicks = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "managain") { Abilities& abilities = it.getAbilities(); abilities.regeneration = true; abilities.manaGain = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "manaticks") { Abilities& abilities = it.getAbilities(); abilities.regeneration = true; abilities.manaTicks = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "manashield") { it.getAbilities().manaShield = valueAttribute.as_bool(); } else if (tmpStrValue == "skillsword") { it.getAbilities().skills[SKILL_SWORD] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "skillaxe") { it.getAbilities().skills[SKILL_AXE] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "skillclub") { it.getAbilities().skills[SKILL_CLUB] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "skilldist") { it.getAbilities().skills[SKILL_DISTANCE] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "skillfish") { it.getAbilities().skills[SKILL_FISHING] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "skillshield") { it.getAbilities().skills[SKILL_SHIELD] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "skillfist") { it.getAbilities().skills[SKILL_FIST] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "maxhitpoints") { it.getAbilities().stats[STAT_MAXHITPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "maxhitpointspercent") { it.getAbilities().statsPercent[STAT_MAXHITPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "maxmanapoints") { it.getAbilities().stats[STAT_MAXMANAPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "maxmanapointspercent") { it.getAbilities().statsPercent[STAT_MAXMANAPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "magicpoints" || tmpStrValue == "magiclevelpoints") { it.getAbilities().stats[STAT_MAGICPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "magicpointspercent") { it.getAbilities().statsPercent[STAT_MAGICPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); } else if (tmpStrValue == "fieldabsorbpercentenergy") { it.getAbilities().fieldAbsorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "fieldabsorbpercentfire") { it.getAbilities().fieldAbsorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "fieldabsorbpercentpoison" || tmpStrValue == "fieldabsorpercentearth") { it.getAbilities().fieldAbsorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentall" || tmpStrValue == "absorbpercentallelements") { int16_t value = pugi::cast<int16_t>(valueAttribute.value()); Abilities& abilities = it.getAbilities(); for (size_t i = 0; i < COMBAT_COUNT; ++i) { abilities.absorbPercent[i] += value; } } else if (tmpStrValue == "absorbpercentelements") { int16_t value = pugi::cast<int16_t>(valueAttribute.value()); Abilities& abilities = it.getAbilities(); abilities.absorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += value; } else if (tmpStrValue == "absorbpercentmagic") { int16_t value = pugi::cast<int16_t>(valueAttribute.value()); Abilities& abilities = it.getAbilities(); abilities.absorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += value; } else if (tmpStrValue == "absorbpercentenergy") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentfire") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentpoison" || tmpStrValue == "absorbpercentearth") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentlifedrain") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_LIFEDRAIN)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentmanadrain") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_MANADRAIN)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentdrown") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_DROWNDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentphysical") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_PHYSICALDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercenthealing") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_HEALING)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "absorbpercentundefined") { it.getAbilities().absorbPercent[combatTypeToIndex(COMBAT_UNDEFINEDDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); } else if (tmpStrValue == "suppressdrunk") { if (valueAttribute.as_bool()) { it.getAbilities().conditionSuppressions |= CONDITION_DRUNK; } } else if (tmpStrValue == "suppressenergy") { if (valueAttribute.as_bool()) { it.getAbilities().conditionSuppressions |= CONDITION_ENERGY; } } else if (tmpStrValue == "suppressfire") { if (valueAttribute.as_bool()) { it.getAbilities().conditionSuppressions |= CONDITION_FIRE; } } else if (tmpStrValue == "suppresspoison") { if (valueAttribute.as_bool()) { it.getAbilities().conditionSuppressions |= CONDITION_POISON; } } else if (tmpStrValue == "suppressdrown") { if (valueAttribute.as_bool()) { it.getAbilities().conditionSuppressions |= CONDITION_DROWN; } } else if (tmpStrValue == "suppressphysical") { if (valueAttribute.as_bool()) { it.getAbilities().conditionSuppressions |= CONDITION_BLEEDING; } } else if (tmpStrValue == "field") { it.group = ITEM_GROUP_MAGICFIELD; it.type = ITEM_TYPE_MAGICFIELD; CombatType_t combatType = COMBAT_NONE; ConditionDamage* conditionDamage = nullptr; tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "fire") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_FIRE); combatType = COMBAT_FIREDAMAGE; } else if (tmpStrValue == "energy") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_ENERGY); combatType = COMBAT_ENERGYDAMAGE; } else if (tmpStrValue == "poison") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_POISON); combatType = COMBAT_EARTHDAMAGE; } else if (tmpStrValue == "drown") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_DROWN); combatType = COMBAT_DROWNDAMAGE; } else if (tmpStrValue == "physical") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_BLEEDING); combatType = COMBAT_PHYSICALDAMAGE; } else { std::cout << "[Warning - Items::parseItemNode] Unknown field value: " << valueAttribute.as_string() << std::endl; } if (combatType != COMBAT_NONE) { it.combatType = combatType; it.conditionDamage.reset(conditionDamage); uint32_t ticks = 0; int32_t damage = 0; int32_t start = 0; int32_t count = 1; for (auto subAttributeNode : attributeNode.children()) { pugi::xml_attribute subKeyAttribute = subAttributeNode.attribute("key"); if (!subKeyAttribute) { continue; } pugi::xml_attribute subValueAttribute = subAttributeNode.attribute("value"); if (!subValueAttribute) { continue; } tmpStrValue = asLowerCaseString(subKeyAttribute.as_string()); if (tmpStrValue == "ticks") { ticks = pugi::cast<uint32_t>(subValueAttribute.value()); } else if (tmpStrValue == "count") { count = std::max<int32_t>(1, pugi::cast<int32_t>(subValueAttribute.value())); } else if (tmpStrValue == "start") { start = std::max<int32_t>(0, pugi::cast<int32_t>(subValueAttribute.value())); } else if (tmpStrValue == "damage") { damage = -pugi::cast<int32_t>(subValueAttribute.value()); if (start > 0) { std::list<int32_t> damageList; ConditionDamage::generateDamageList(damage, start, damageList); for (int32_t damageValue : damageList) { conditionDamage->addDamage(1, ticks, -damageValue); } start = 0; } else { conditionDamage->addDamage(count, ticks, damage); } } } conditionDamage->setParam(CONDITION_PARAM_FIELD, 1); if (conditionDamage->getTotalDamage() > 0) { conditionDamage->setParam(CONDITION_PARAM_FORCEUPDATE, 1); } } } else if (tmpStrValue == "replaceable") { it.replaceable = valueAttribute.as_bool(); } else if (tmpStrValue == "partnerdirection") { it.bedPartnerDir = getDirection(valueAttribute.as_string()); } else if (tmpStrValue == "leveldoor") { it.levelDoor = pugi::cast<uint32_t>(valueAttribute.value()); } else if (tmpStrValue == "maletransformto" || tmpStrValue == "malesleeper") { uint16_t value = pugi::cast<uint16_t>(valueAttribute.value()); it.transformToOnUse[PLAYERSEX_MALE] = value; ItemType& other = getItemType(value); if (other.transformToFree == 0) { other.transformToFree = it.id; } if (it.transformToOnUse[PLAYERSEX_FEMALE] == 0) { it.transformToOnUse[PLAYERSEX_FEMALE] = value; } } else if (tmpStrValue == "femaletransformto" || tmpStrValue == "femalesleeper") { uint16_t value = pugi::cast<uint16_t>(valueAttribute.value()); it.transformToOnUse[PLAYERSEX_FEMALE] = value; ItemType& other = getItemType(value); if (other.transformToFree == 0) { other.transformToFree = it.id; } if (it.transformToOnUse[PLAYERSEX_MALE] == 0) { it.transformToOnUse[PLAYERSEX_MALE] = value; } } else if (tmpStrValue == "transformto") { it.transformToFree = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "destroyto") { it.destroyTo = pugi::cast<uint16_t>(valueAttribute.value()); } else if (tmpStrValue == "elementearth") { Abilities& abilities = it.getAbilities(); abilities.elementDamage = pugi::cast<uint16_t>(valueAttribute.value()); abilities.elementType = COMBAT_EARTHDAMAGE; } else if (tmpStrValue == "elementfire") { Abilities& abilities = it.getAbilities(); abilities.elementDamage = pugi::cast<uint16_t>(valueAttribute.value()); abilities.elementType = COMBAT_FIREDAMAGE; } else if (tmpStrValue == "elementenergy") { Abilities& abilities = it.getAbilities(); abilities.elementDamage = pugi::cast<uint16_t>(valueAttribute.value()); abilities.elementType = COMBAT_ENERGYDAMAGE; } else if (tmpStrValue == "walkstack") { it.walkStack = valueAttribute.as_bool(); } else if (tmpStrValue == "blocking") { it.blockSolid = valueAttribute.as_bool(); } else if (tmpStrValue == "allowdistread") { it.allowDistRead = booleanString(valueAttribute.as_string()); } else { std::cout << "[Warning - Items::parseItemNode] Unknown key value: " << keyAttribute.as_string() << std::endl; } } //check bed items if ((it.transformToFree != 0 || it.transformToOnUse[PLAYERSEX_FEMALE] != 0 || it.transformToOnUse[PLAYERSEX_MALE] != 0) && it.type != ITEM_TYPE_BED) { std::cout << "[Warning - Items::parseItemNode] Item " << it.id << " is not set as a bed-type" << std::endl; } }
bool Monsters::deserializeSpell(xmlNodePtr node, spellBlock_t& sb, const std::string& description) { sb.range = sb.minCombatValue = sb.maxCombatValue = 0; sb.combatSpell = sb.isMelee = false; sb.chance = 100; sb.speed = 2000; std::string name, scriptName; bool isScripted = false; if(readXMLString(node, "script", scriptName)) isScripted = true; else if(!readXMLString(node, "name", name)) return false; int32_t intValue; std::string strValue; if(readXMLInteger(node, "speed", intValue) || readXMLInteger(node, "interval", intValue)) sb.speed = std::max(1, intValue); if(readXMLInteger(node, "chance", intValue)) { if(intValue < 0 || intValue > 100) intValue = 100; sb.chance = intValue; } if(readXMLInteger(node, "range", intValue)) { if(intValue < 0) intValue = 0; if(intValue > Map::maxViewportX * 2) intValue = Map::maxViewportX * 2; sb.range = intValue; } if(readXMLInteger(node, "min", intValue)) sb.minCombatValue = intValue; if(readXMLInteger(node, "max", intValue)) sb.maxCombatValue = intValue; //normalize values if(std::abs(sb.minCombatValue) > std::abs(sb.maxCombatValue)) std::swap(sb.minCombatValue, sb.maxCombatValue); if((sb.spell = g_spells->getSpellByName(name))) return true; CombatSpell* combatSpell = NULL; bool needTarget = false, needDirection = false; if(isScripted) { if(readXMLString(node, "direction", strValue)) needDirection = booleanString(strValue); if(readXMLString(node, "target", strValue)) needTarget = booleanString(strValue); combatSpell = new CombatSpell(NULL, needTarget, needDirection); if(!combatSpell->loadScript(getFilePath(FILE_TYPE_OTHER, g_spells->getScriptBaseName() + "/scripts/" + scriptName), true)) { delete combatSpell; return false; } if(!combatSpell->loadScriptCombat()) { delete combatSpell; return false; } combatSpell->getCombat()->setPlayerCombatValues(FORMULA_VALUE, sb.minCombatValue, 0, sb.maxCombatValue, 0, 0, 0, 0, 0, 0, 0); } else { Combat* combat = new Combat; sb.combatSpell = true; if(readXMLInteger(node, "length", intValue)) { int32_t length = intValue; if(length > 0) { int32_t spread = 3; //need direction spell if(readXMLInteger(node, "spread", intValue)) spread = std::max(0, intValue); CombatArea* area = new CombatArea(); area->setupArea(length, spread); combat->setArea(area); needDirection = true; } } if(readXMLInteger(node, "radius", intValue)) { int32_t radius = intValue; //target spell if(readXMLInteger(node, "target", intValue)) needTarget = (intValue != 0); CombatArea* area = new CombatArea(); area->setupArea(radius); combat->setArea(area); } std::string tmpName = asLowerCaseString(name); if(tmpName == "melee" || tmpName == "distance") { int32_t attack = 0, skill = 0; if(readXMLInteger(node, "attack", attack) && readXMLInteger(node, "skill", skill)) { sb.minCombatValue = 0; sb.maxCombatValue = -Weapons::getMaxMeleeDamage(skill, attack); } uint32_t tickInterval = 2000; ConditionType_t conditionType = CONDITION_NONE; if(readXMLInteger(node, "physical", intValue)) conditionType = CONDITION_PHYSICAL; else if(readXMLInteger(node, "fire", intValue)) { conditionType = CONDITION_FIRE; tickInterval = 9000; } else if(readXMLInteger(node, "energy", intValue)) { conditionType = CONDITION_ENERGY; tickInterval = 10000; } else if(readXMLInteger(node, "earth", intValue)) { conditionType = CONDITION_POISON; tickInterval = 5000; } else if(readXMLInteger(node, "freeze", intValue)) { conditionType = CONDITION_FREEZING; tickInterval = 8000; } else if(readXMLInteger(node, "dazzle", intValue)) { conditionType = CONDITION_DAZZLED; tickInterval = 10000; } else if(readXMLInteger(node, "curse", intValue)) { conditionType = CONDITION_CURSED; tickInterval = 4000; } else if(readXMLInteger(node, "drown", intValue)) { conditionType = CONDITION_DROWN; tickInterval = 5000; } else if(readXMLInteger(node, "poison", intValue)) { conditionType = CONDITION_POISON; tickInterval = 5000; } uint32_t damage = std::abs(intValue); if(readXMLInteger(node, "tick", intValue) && intValue > 0) tickInterval = intValue; if(conditionType != CONDITION_NONE) { Condition* condition = getDamageCondition(conditionType, damage, damage, 0, tickInterval); if(condition) combat->setCondition(condition); } sb.isMelee = true; sb.range = 1; combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_PHYSICALDAMAGE); combat->setParam(COMBATPARAM_BLOCKEDBYSHIELD, 1); combat->setParam(COMBATPARAM_BLOCKEDBYARMOR, 1); } else if(tmpName == "physical") { combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_PHYSICALDAMAGE); combat->setParam(COMBATPARAM_BLOCKEDBYARMOR, 1); } else if(tmpName == "drown") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_DROWNDAMAGE); else if(tmpName == "fire") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_FIREDAMAGE); else if(tmpName == "energy") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_ENERGYDAMAGE); else if(tmpName == "poison" || tmpName == "earth") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_EARTHDAMAGE); else if(tmpName == "ice") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_ICEDAMAGE); else if(tmpName == "holy") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_HOLYDAMAGE); else if(tmpName == "death") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_DEATHDAMAGE); else if(tmpName == "lifedrain") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_LIFEDRAIN); else if(tmpName == "manadrain") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_MANADRAIN); else if(tmpName == "healing") { bool aggressive = false; if(readXMLInteger(node, "self", intValue)) aggressive = intValue; combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_HEALING); combat->setParam(COMBATPARAM_AGGRESSIVE, aggressive); } else if(tmpName == "undefined") combat->setParam(COMBATPARAM_COMBATTYPE, COMBAT_UNDEFINEDDAMAGE); else if(tmpName == "speed") { int32_t speedChange = 0, duration = 10000; if(readXMLInteger(node, "duration", intValue)) duration = intValue; enum Aggressive { NO, YES, AUTO } aggressive = AUTO; if(readXMLInteger(node, "self", intValue)) aggressive = (Aggressive)intValue; if(readXMLInteger(node, "speedchange", intValue)) speedChange = std::max(-1000, intValue); //cant be slower than 100% std::vector<Outfit_t> outfits; for(xmlNodePtr tmpNode = node->children; tmpNode; tmpNode = tmpNode->next) { if(xmlStrcmp(tmpNode->name,(const xmlChar*)"outfit")) continue; if(readXMLInteger(tmpNode, "type", intValue)) { Outfit_t outfit; outfit.lookType = intValue; if(readXMLInteger(tmpNode, "head", intValue)) outfit.lookHead = intValue; if(readXMLInteger(tmpNode, "body", intValue)) outfit.lookBody = intValue; if(readXMLInteger(tmpNode, "legs", intValue)) outfit.lookLegs = intValue; if(readXMLInteger(tmpNode, "feet", intValue)) outfit.lookFeet = intValue; if(readXMLInteger(tmpNode, "addons", intValue)) outfit.lookAddons = intValue; outfits.push_back(outfit); } if(readXMLInteger(tmpNode, "typeex", intValue) || readXMLInteger(tmpNode, "item", intValue)) { Outfit_t outfit; outfit.lookTypeEx = intValue; outfits.push_back(outfit); } if(readXMLString(tmpNode, "monster", strValue)) { if(MonsterType* mType = g_monsters.getMonsterType(strValue)) outfits.push_back(mType->outfit); } } ConditionType_t conditionType = CONDITION_PARALYZE; if(speedChange > 0) { conditionType = CONDITION_HASTE; if(aggressive == AUTO) aggressive = NO; } else if(aggressive == AUTO) aggressive = YES; if(ConditionSpeed* condition = dynamic_cast<ConditionSpeed*>(Condition::createCondition( CONDITIONID_COMBAT, conditionType, duration))) { condition->setFormulaVars((speedChange / 1000.), 0, (speedChange / 1000.), 0); if(!outfits.empty()) condition->setOutfits(outfits); combat->setCondition(condition); combat->setParam(COMBATPARAM_AGGRESSIVE, aggressive); } } else if(tmpName == "outfit") { std::vector<Outfit_t> outfits; for(xmlNodePtr tmpNode = node->children; tmpNode; tmpNode = tmpNode->next) { if(xmlStrcmp(tmpNode->name,(const xmlChar*)"outfit")) continue; if(readXMLInteger(tmpNode, "type", intValue)) { Outfit_t outfit; outfit.lookType = intValue; if(readXMLInteger(tmpNode, "head", intValue)) outfit.lookHead = intValue; if(readXMLInteger(tmpNode, "body", intValue)) outfit.lookBody = intValue; if(readXMLInteger(tmpNode, "legs", intValue)) outfit.lookLegs = intValue; if(readXMLInteger(tmpNode, "feet", intValue)) outfit.lookFeet = intValue; if(readXMLInteger(tmpNode, "addons", intValue)) outfit.lookAddons = intValue; outfits.push_back(outfit); } if(readXMLInteger(tmpNode, "typeex", intValue) || readXMLInteger(tmpNode, "item", intValue)) { Outfit_t outfit; outfit.lookTypeEx = intValue; outfits.push_back(outfit); } if(readXMLString(tmpNode, "monster", strValue)) { if(MonsterType* mType = g_monsters.getMonsterType(strValue)) outfits.push_back(mType->outfit); } } if(outfits.empty()) { if(readXMLInteger(node, "type", intValue)) { Outfit_t outfit; outfit.lookType = intValue; if(readXMLInteger(node, "head", intValue)) outfit.lookHead = intValue; if(readXMLInteger(node, "body", intValue)) outfit.lookBody = intValue; if(readXMLInteger(node, "legs", intValue)) outfit.lookLegs = intValue; if(readXMLInteger(node, "feet", intValue)) outfit.lookFeet = intValue; if(readXMLInteger(node, "addons", intValue)) outfit.lookAddons = intValue; outfits.push_back(outfit); } if(readXMLInteger(node, "typeex", intValue) || readXMLInteger(node, "item", intValue)) { Outfit_t outfit; outfit.lookTypeEx = intValue; outfits.push_back(outfit); } if(readXMLString(node, "monster", strValue)) { if(MonsterType* mType = g_monsters.getMonsterType(strValue)) outfits.push_back(mType->outfit); } } if(!outfits.empty()) { int32_t duration = 10000; if(readXMLInteger(node, "duration", intValue)) duration = intValue; bool aggressive = false; if(readXMLInteger(node, "self", intValue)) aggressive = intValue; if(ConditionOutfit* condition = dynamic_cast<ConditionOutfit*>(Condition::createCondition( CONDITIONID_COMBAT, CONDITION_OUTFIT, duration))) { condition->setOutfits(outfits); combat->setCondition(condition); combat->setParam(COMBATPARAM_AGGRESSIVE, aggressive); } } } else if(tmpName == "invisible") { int32_t duration = 10000; if(readXMLInteger(node, "duration", intValue)) duration = intValue; bool aggressive = false; if(readXMLInteger(node, "self", intValue)) aggressive = intValue; if(Condition* condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_INVISIBLE, duration)) { combat->setParam(COMBATPARAM_AGGRESSIVE, aggressive); combat->setCondition(condition); } } else if(tmpName == "drunk") { int32_t duration = 10000; if(readXMLInteger(node, "duration", intValue)) duration = intValue; if(Condition* condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_DRUNK, duration)) combat->setCondition(condition); } else if(tmpName == "skills" || tmpName == "attributes") { uint32_t duration = 10000, subId = 0; if(readXMLInteger(node, "duration", intValue)) duration = intValue; if(readXMLInteger(node, "subid", intValue)) subId = intValue; intValue = 0; ConditionParam_t param = CONDITIONPARAM_BUFF; //to know was it loaded if(readXMLInteger(node, "melee", intValue)) param = CONDITIONPARAM_SKILL_MELEE; else if(readXMLInteger(node, "fist", intValue)) param = CONDITIONPARAM_SKILL_FIST; else if(readXMLInteger(node, "club", intValue)) param = CONDITIONPARAM_SKILL_CLUB; else if(readXMLInteger(node, "axe", intValue)) param = CONDITIONPARAM_SKILL_AXE; else if(readXMLInteger(node, "sword", intValue)) param = CONDITIONPARAM_SKILL_SWORD; else if(readXMLInteger(node, "distance", intValue) || readXMLInteger(node, "dist", intValue)) param = CONDITIONPARAM_SKILL_DISTANCE; else if(readXMLInteger(node, "shielding", intValue) || readXMLInteger(node, "shield", intValue)) param = CONDITIONPARAM_SKILL_SHIELD; else if(readXMLInteger(node, "fishing", intValue) || readXMLInteger(node, "fish", intValue)) param = CONDITIONPARAM_SKILL_FISHING; else if(readXMLInteger(node, "meleePercent", intValue)) param = CONDITIONPARAM_SKILL_MELEEPERCENT; else if(readXMLInteger(node, "fistPercent", intValue)) param = CONDITIONPARAM_SKILL_FISTPERCENT; else if(readXMLInteger(node, "clubPercent", intValue)) param = CONDITIONPARAM_SKILL_CLUBPERCENT; else if(readXMLInteger(node, "axePercent", intValue)) param = CONDITIONPARAM_SKILL_AXEPERCENT; else if(readXMLInteger(node, "swordPercent", intValue)) param = CONDITIONPARAM_SKILL_SWORDPERCENT; else if(readXMLInteger(node, "distancePercent", intValue) || readXMLInteger(node, "distPercent", intValue)) param = CONDITIONPARAM_SKILL_DISTANCEPERCENT; else if(readXMLInteger(node, "shieldingPercent", intValue) || readXMLInteger(node, "shieldPercent", intValue)) param = CONDITIONPARAM_SKILL_SHIELDPERCENT; else if(readXMLInteger(node, "fishingPercent", intValue) || readXMLInteger(node, "fishPercent", intValue)) param = CONDITIONPARAM_SKILL_FISHINGPERCENT; else if(readXMLInteger(node, "maxhealth", intValue)) param = CONDITIONPARAM_STAT_MAXHEALTHPERCENT; else if(readXMLInteger(node, "maxmana", intValue)) param = CONDITIONPARAM_STAT_MAXMANAPERCENT; else if(readXMLInteger(node, "soul", intValue)) param = CONDITIONPARAM_STAT_SOULPERCENT; else if(readXMLInteger(node, "magiclevel", intValue) || readXMLInteger(node, "maglevel", intValue)) param = CONDITIONPARAM_STAT_MAGICLEVELPERCENT; else if(readXMLInteger(node, "maxhealthPercent", intValue)) param = CONDITIONPARAM_STAT_MAXHEALTHPERCENT; else if(readXMLInteger(node, "maxmanaPercent", intValue)) param = CONDITIONPARAM_STAT_MAXMANAPERCENT; else if(readXMLInteger(node, "soulPercent", intValue)) param = CONDITIONPARAM_STAT_SOULPERCENT; else if(readXMLInteger(node, "magiclevelPercent", intValue) || readXMLInteger(node, "maglevelPercent", intValue)) param = CONDITIONPARAM_STAT_MAGICLEVELPERCENT; if(param != CONDITIONPARAM_BUFF) { if(ConditionAttributes* condition = dynamic_cast<ConditionAttributes*>(Condition::createCondition( CONDITIONID_COMBAT, CONDITION_ATTRIBUTES, duration, false, subId))) { condition->setParam(param, intValue); combat->setCondition(condition); } } } else if(tmpName == "firefield") combat->setParam(COMBATPARAM_CREATEITEM, 1492); else if(tmpName == "poisonfield") combat->setParam(COMBATPARAM_CREATEITEM, 1496); else if(tmpName == "energyfield") combat->setParam(COMBATPARAM_CREATEITEM, 1495); else if(tmpName == "firecondition" || tmpName == "energycondition" || tmpName == "drowncondition" || tmpName == "poisoncondition" || tmpName == "earthcondition" || tmpName == "freezecondition" || tmpName == "cursecondition" || tmpName == "dazzlecondition") { ConditionType_t conditionType = CONDITION_NONE; uint32_t tickInterval = 2000; if(tmpName == "physicalcondition") conditionType = CONDITION_PHYSICAL; else if(tmpName == "firecondition") { conditionType = CONDITION_FIRE; tickInterval = 9000; } else if(tmpName == "energycondition") { conditionType = CONDITION_ENERGY; tickInterval = 10000; } else if(tmpName == "earthcondition") { conditionType = CONDITION_POISON; tickInterval = 5000; } else if(tmpName == "freezecondition") { conditionType = CONDITION_FREEZING; tickInterval = 8000; } else if(tmpName == "cursecondition") { conditionType = CONDITION_CURSED; tickInterval = 4000; } else if(tmpName == "dazzlecondition") { conditionType = CONDITION_DAZZLED; tickInterval = 10000; } else if(tmpName == "drowncondition") { conditionType = CONDITION_DROWN; tickInterval = 5000; } else if(tmpName == "poisoncondition") { conditionType = CONDITION_POISON; tickInterval = 5000; } if(readXMLInteger(node, "tick", intValue) && intValue > 0) tickInterval = intValue; int32_t startDamage = 0, minDamage = std::abs(sb.minCombatValue), maxDamage = std::abs(sb.maxCombatValue); if(readXMLInteger(node, "start", intValue)) startDamage = std::max(std::abs(intValue), minDamage); if(Condition* condition = getDamageCondition(conditionType, maxDamage, minDamage, startDamage, tickInterval)) combat->setCondition(condition); } else if(tmpName == "strength") { //TODO: monster extra strength } else if(tmpName == "effect") {/*show some effect and bye bye!*/} else { delete combat; std::clog << "[Error - Monsters::deserializeSpell] " << description << " - Unknown spell name: " << name << std::endl; return false; } combat->setPlayerCombatValues(FORMULA_VALUE, sb.minCombatValue, 0, sb.maxCombatValue, 0, 0, 0, 0, 0, 0, 0); combatSpell = new CombatSpell(combat, needTarget, needDirection); for(xmlNodePtr attributeNode = node->children; attributeNode; attributeNode = attributeNode->next) { if(!xmlStrcmp(attributeNode->name, (const xmlChar*)"attribute")) { if(readXMLString(attributeNode, "key", strValue)) { std::string tmpStrValue = asLowerCaseString(strValue); if(tmpStrValue == "shooteffect") { if(readXMLString(attributeNode, "value", strValue)) { ShootEffect_t shoot = getShootType(strValue); if(shoot != SHOOT_EFFECT_UNKNOWN) combat->setParam(COMBATPARAM_DISTANCEEFFECT, shoot); else std::clog << "[Warning - Monsters::deserializeSpell] " << description << " - Unknown shootEffect: " << strValue << std::endl; } } else if(tmpStrValue == "areaeffect") { if(readXMLString(attributeNode, "value", strValue)) { MagicEffect_t effect = getMagicEffect(strValue); if(effect != MAGIC_EFFECT_UNKNOWN) combat->setParam(COMBATPARAM_EFFECT, effect); else std::clog << "[Warning - Monsters::deserializeSpell] " << description << " - Unknown areaEffect: " << strValue << std::endl; } } else std::clog << "[Warning - Monsters::deserializeSpells] Effect type \"" << strValue << "\" does not exist." << std::endl; } } } } sb.spell = combatSpell; return true; }
void Items::parseItemNode(const pugi::xml_node& itemNode, uint16_t id) { if (id > 30000 && id < 30100) { id -= 30000; if (id >= items.size()) { items.resize(id + 1); } ItemType& iType = items[id]; iType.id = id; } ItemType& it = getItemType(id); if (it.id == 0) { return; } it.name = itemNode.attribute("name").as_string(); nameToItems.insert({ asLowerCaseString(it.name), id }); pugi::xml_attribute articleAttribute = itemNode.attribute("article"); if (articleAttribute) { it.article = articleAttribute.as_string(); } pugi::xml_attribute pluralAttribute = itemNode.attribute("plural"); if (pluralAttribute) { it.pluralName = pluralAttribute.as_string(); } Abilities& abilities = it.getAbilities(); for (auto attributeNode : itemNode.children()) { pugi::xml_attribute keyAttribute = attributeNode.attribute("key"); if (!keyAttribute) { continue; } pugi::xml_attribute valueAttribute = attributeNode.attribute("value"); if (!valueAttribute) { continue; } std::string tmpStrValue = asLowerCaseString(keyAttribute.as_string()); auto parseAttribute = ItemParseAttributesMap.find(tmpStrValue); if (parseAttribute != ItemParseAttributesMap.end()) { ItemParseAttributes_t parseType = parseAttribute->second; switch (parseType) { case ITEM_PARSE_TYPE: { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); auto it2 = ItemTypesMap.find(tmpStrValue); if (it2 != ItemTypesMap.end()) { it.type = it2->second; if (it.type == ITEM_TYPE_CONTAINER) { it.group = ITEM_GROUP_CONTAINER; } } else { std::cout << "[Warning - Items::parseItemNode] Unknown type: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_DESCRIPTION: { it.description = valueAttribute.as_string(); break; } case ITEM_PARSE_RUNESPELLNAME: { it.runeSpellName = valueAttribute.as_string(); break; } case ITEM_PARSE_WEIGHT: { it.weight = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SHOWCOUNT: { it.showCount = valueAttribute.as_bool(); break; } case ITEM_PARSE_ARMOR: { it.armor = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_DEFENSE: { it.defense = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_EXTRADEF: { it.extraDefense = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_ATTACK: { it.attack = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_ROTATETO: { it.rotateTo = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MOVEABLE: { it.moveable = valueAttribute.as_bool(); break; } case ITEM_PARSE_BLOCKPROJECTILE: { it.blockProjectile = valueAttribute.as_bool(); break; } case ITEM_PARSE_PICKUPABLE: { it.allowPickupable = valueAttribute.as_bool(); break; } case ITEM_PARSE_FORCESERIALIZE: { it.forceSerialize = valueAttribute.as_bool(); break; } case ITEM_PARSE_FLOORCHANGE: { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); auto it2 = TileStatesMap.find(tmpStrValue); if (it2 != TileStatesMap.end()) { it.floorChange = it2->second; } else { std::cout << "[Warning - Items::parseItemNode] Unknown floorChange: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_CORPSETYPE: { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); auto it2 = RaceTypesMap.find(tmpStrValue); if (it2 != RaceTypesMap.end()) { it.corpseType = it2->second; } else { std::cout << "[Warning - Items::parseItemNode] Unknown corpseType: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_CONTAINERSIZE: { it.maxItems = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_FLUIDSOURCE: { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); auto it2 = FluidTypesMap.find(tmpStrValue); if (it2 != FluidTypesMap.end()) { it.fluidSource = it2->second; } else { std::cout << "[Warning - Items::parseItemNode] Unknown fluidSource: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_READABLE: { it.canReadText = valueAttribute.as_bool(); break; } case ITEM_PARSE_WRITEABLE: { it.canWriteText = valueAttribute.as_bool(); it.canReadText = it.canWriteText; break; } case ITEM_PARSE_MAXTEXTLEN: { it.maxTextLen = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_WRITEONCEITEMID: { it.writeOnceItemId = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_WEAPONTYPE: { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); auto it2 = WeaponTypesMap.find(tmpStrValue); if (it2 != WeaponTypesMap.end()) { it.weaponType = it2->second; } else { std::cout << "[Warning - Items::parseItemNode] Unknown weaponType: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_SLOTTYPE: { tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "head") { it.slotPosition |= SLOTP_HEAD; } else if (tmpStrValue == "body") { it.slotPosition |= SLOTP_ARMOR; } else if (tmpStrValue == "legs") { it.slotPosition |= SLOTP_LEGS; } else if (tmpStrValue == "feet") { it.slotPosition |= SLOTP_FEET; } else if (tmpStrValue == "backpack") { it.slotPosition |= SLOTP_BACKPACK; } else if (tmpStrValue == "two-handed") { it.slotPosition |= SLOTP_TWO_HAND; } else if (tmpStrValue == "right-hand") { it.slotPosition &= ~SLOTP_LEFT; } else if (tmpStrValue == "left-hand") { it.slotPosition &= ~SLOTP_RIGHT; } else if (tmpStrValue == "necklace") { it.slotPosition |= SLOTP_NECKLACE; } else if (tmpStrValue == "ring") { it.slotPosition |= SLOTP_RING; } else if (tmpStrValue == "ammo") { it.slotPosition |= SLOTP_AMMO; } else if (tmpStrValue == "hand") { it.slotPosition |= SLOTP_HAND; } else { std::cout << "[Warning - Items::parseItemNode] Unknown slotType: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_AMMOTYPE: { it.ammoType = getAmmoType(asLowerCaseString(valueAttribute.as_string())); if (it.ammoType == AMMO_NONE) { std::cout << "[Warning - Items::parseItemNode] Unknown ammoType: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_SHOOTTYPE: { ShootType_t shoot = getShootType(asLowerCaseString(valueAttribute.as_string())); if (shoot != CONST_ANI_NONE) { it.shootType = shoot; } else { std::cout << "[Warning - Items::parseItemNode] Unknown shootType: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_EFFECT: { MagicEffectClasses effect = getMagicEffect(asLowerCaseString(valueAttribute.as_string())); if (effect != CONST_ME_NONE) { it.magicEffect = effect; } else { std::cout << "[Warning - Items::parseItemNode] Unknown effect: " << valueAttribute.as_string() << std::endl; } break; } case ITEM_PARSE_RANGE: { it.shootRange = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_STOPDURATION: { it.stopTime = valueAttribute.as_bool(); break; } case ITEM_PARSE_DECAYTO: { it.decayTo = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_TRANSFORMEQUIPTO: { it.transformEquipTo = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_TRANSFORMDEEQUIPTO: { it.transformDeEquipTo = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_DURATION: { it.decayTime = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SHOWDURATION: { it.showDuration = valueAttribute.as_bool(); break; } case ITEM_PARSE_CHARGES: { it.charges = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SHOWCHARGES: { it.showCharges = valueAttribute.as_bool(); break; } case ITEM_PARSE_SHOWATTRIBUTES: { it.showAttributes = valueAttribute.as_bool(); break; } case ITEM_PARSE_HITCHANCE: { it.hitChance = std::min<int8_t>(100, std::max<int8_t>(-100, pugi::cast<int16_t>(valueAttribute.value()))); break; } case ITEM_PARSE_MAXHITCHANCE: { it.maxHitChance = std::min<uint32_t>(100, pugi::cast<uint32_t>(valueAttribute.value())); break; } case ITEM_PARSE_INVISIBLE: { abilities.invisible = valueAttribute.as_bool(); break; } case ITEM_PARSE_SPEED: { abilities.speed = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_HEALTHGAIN: { abilities.regeneration = true; abilities.healthGain = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_HEALTHTICKS: { abilities.regeneration = true; abilities.healthTicks = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MANAGAIN: { abilities.regeneration = true; abilities.manaGain = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MANATICKS: { abilities.regeneration = true; abilities.manaTicks = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MANASHIELD: { abilities.manaShield = valueAttribute.as_bool(); break; } case ITEM_PARSE_SKILLSWORD: { abilities.skills[SKILL_SWORD] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SKILLAXE: { abilities.skills[SKILL_AXE] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SKILLCLUB: { abilities.skills[SKILL_CLUB] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SKILLDIST: { abilities.skills[SKILL_DISTANCE] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SKILLFISH: { abilities.skills[SKILL_FISHING] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SKILLSHIELD: { abilities.skills[SKILL_SHIELD] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_SKILLFIST: { abilities.skills[SKILL_FIST] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MAXHITPOINTS: { abilities.stats[STAT_MAXHITPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MAXHITPOINTSPERCENT: { abilities.statsPercent[STAT_MAXHITPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MAXMANAPOINTS: { abilities.stats[STAT_MAXMANAPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MAXMANAPOINTSPERCENT: { abilities.statsPercent[STAT_MAXMANAPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MAGICPOINTS: { abilities.stats[STAT_MAGICPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MAGICPOINTSPERCENT: { abilities.statsPercent[STAT_MAGICPOINTS] = pugi::cast<int32_t>(valueAttribute.value()); break; } case ITEM_PARSE_FIELDABSORBPERCENTENERGY: { abilities.fieldAbsorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_FIELDABSORBPERCENTFIRE: { abilities.fieldAbsorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_FIELDABSORBPERCENTPOISON: { abilities.fieldAbsorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTALL: { int16_t value = pugi::cast<int16_t>(valueAttribute.value()); for (auto& i : abilities.absorbPercent) { i += value; } break; } case ITEM_PARSE_ABSORBPERCENTELEMENTS: { int16_t value = pugi::cast<int16_t>(valueAttribute.value()); abilities.absorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_ICEDAMAGE)] += value; break; } case ITEM_PARSE_ABSORBPERCENTMAGIC: { int16_t value = pugi::cast<int16_t>(valueAttribute.value()); abilities.absorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_ICEDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_HOLYDAMAGE)] += value; abilities.absorbPercent[combatTypeToIndex(COMBAT_DEATHDAMAGE)] += value; break; } case ITEM_PARSE_ABSORBPERCENTENERGY: { abilities.absorbPercent[combatTypeToIndex(COMBAT_ENERGYDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTFIRE: { abilities.absorbPercent[combatTypeToIndex(COMBAT_FIREDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTPOISON: { abilities.absorbPercent[combatTypeToIndex(COMBAT_EARTHDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTICE: { abilities.absorbPercent[combatTypeToIndex(COMBAT_ICEDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTHOLY: { abilities.absorbPercent[combatTypeToIndex(COMBAT_HOLYDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTDEATH: { abilities.absorbPercent[combatTypeToIndex(COMBAT_DEATHDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTLIFEDRAIN: { abilities.absorbPercent[combatTypeToIndex(COMBAT_LIFEDRAIN)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTMANADRAIN: { abilities.absorbPercent[combatTypeToIndex(COMBAT_MANADRAIN)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTDROWN: { abilities.absorbPercent[combatTypeToIndex(COMBAT_DROWNDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTPHYSICAL: { abilities.absorbPercent[combatTypeToIndex(COMBAT_PHYSICALDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTHEALING: { abilities.absorbPercent[combatTypeToIndex(COMBAT_HEALING)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ABSORBPERCENTUNDEFINED: { abilities.absorbPercent[combatTypeToIndex(COMBAT_UNDEFINEDDAMAGE)] += pugi::cast<int16_t>(valueAttribute.value()); break; } case ITEM_PARSE_SUPPRESSDRUNK: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_DRUNK; } break; } case ITEM_PARSE_SUPPRESSENERGY: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_ENERGY; } break; } case ITEM_PARSE_SUPPRESSFIRE: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_FIRE; } break; } case ITEM_PARSE_SUPPRESSPOISON: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_POISON; } break; } case ITEM_PARSE_SUPPRESSDROWN: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_DROWN; } break; } case ITEM_PARSE_SUPPRESSPHYSICAL: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_BLEEDING; } break; } case ITEM_PARSE_SUPPRESSFREEZE: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_FREEZING; } break; } case ITEM_PARSE_SUPPRESSDAZZLE: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_DAZZLED; } break; } case ITEM_PARSE_SUPPRESSCURSE: { if (valueAttribute.as_bool()) { abilities.conditionSuppressions |= CONDITION_CURSED; } break; } case ITEM_PARSE_FIELD: { it.group = ITEM_GROUP_MAGICFIELD; it.type = ITEM_TYPE_MAGICFIELD; CombatType_t combatType = COMBAT_NONE; ConditionDamage* conditionDamage = nullptr; tmpStrValue = asLowerCaseString(valueAttribute.as_string()); if (tmpStrValue == "fire") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_FIRE); combatType = COMBAT_FIREDAMAGE; } else if (tmpStrValue == "energy") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_ENERGY); combatType = COMBAT_ENERGYDAMAGE; } else if (tmpStrValue == "poison") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_POISON); combatType = COMBAT_EARTHDAMAGE; } else if (tmpStrValue == "drown") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_DROWN); combatType = COMBAT_DROWNDAMAGE; } else if (tmpStrValue == "physical") { conditionDamage = new ConditionDamage(CONDITIONID_COMBAT, CONDITION_BLEEDING); combatType = COMBAT_PHYSICALDAMAGE; } else { std::cout << "[Warning - Items::parseItemNode] Unknown field value: " << valueAttribute.as_string() << std::endl; } if (combatType != COMBAT_NONE) { it.combatType = combatType; it.conditionDamage.reset(conditionDamage); uint32_t ticks = 0; int32_t start = 0; int32_t count = 1; for (auto subAttributeNode : attributeNode.children()) { pugi::xml_attribute subKeyAttribute = subAttributeNode.attribute("key"); if (!subKeyAttribute) { continue; } pugi::xml_attribute subValueAttribute = subAttributeNode.attribute("value"); if (!subValueAttribute) { continue; } tmpStrValue = asLowerCaseString(subKeyAttribute.as_string()); if (tmpStrValue == "ticks") { ticks = pugi::cast<uint32_t>(subValueAttribute.value()); } else if (tmpStrValue == "count") { count = std::max<int32_t>(1, pugi::cast<int32_t>(subValueAttribute.value())); } else if (tmpStrValue == "start") { start = std::max<int32_t>(0, pugi::cast<int32_t>(subValueAttribute.value())); } else if (tmpStrValue == "damage") { int32_t damage = -pugi::cast<int32_t>(subValueAttribute.value()); if (start > 0) { std::list<int32_t> damageList; ConditionDamage::generateDamageList(damage, start, damageList); for (int32_t damageValue : damageList) { conditionDamage->addDamage(1, ticks, -damageValue); } start = 0; } else { conditionDamage->addDamage(count, ticks, damage); } } } conditionDamage->setParam(CONDITION_PARAM_FIELD, 1); if (conditionDamage->getTotalDamage() > 0) { conditionDamage->setParam(CONDITION_PARAM_FORCEUPDATE, 1); } } break; } case ITEM_PARSE_REPLACEABLE: { it.replaceable = valueAttribute.as_bool(); break; } case ITEM_PARSE_PARTNERDIRECTION: { it.bedPartnerDir = getDirection(valueAttribute.as_string()); break; } case ITEM_PARSE_LEVELDOOR: { it.levelDoor = pugi::cast<uint32_t>(valueAttribute.value()); break; } case ITEM_PARSE_MALETRANSFORMTO: { uint16_t value = pugi::cast<uint16_t>(valueAttribute.value()); it.transformToOnUse[PLAYERSEX_MALE] = value; ItemType& other = getItemType(value); if (other.transformToFree == 0) { other.transformToFree = it.id; } if (it.transformToOnUse[PLAYERSEX_FEMALE] == 0) { it.transformToOnUse[PLAYERSEX_FEMALE] = value; } break; } case ITEM_PARSE_FEMALETRANSFORMTO: { uint16_t value = pugi::cast<uint16_t>(valueAttribute.value()); it.transformToOnUse[PLAYERSEX_FEMALE] = value; ItemType& other = getItemType(value); if (other.transformToFree == 0) { other.transformToFree = it.id; } if (it.transformToOnUse[PLAYERSEX_MALE] == 0) { it.transformToOnUse[PLAYERSEX_MALE] = value; } break; } case ITEM_PARSE_TRANSFORMTO: { it.transformToFree = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_DESTROYTO: { it.destroyTo = pugi::cast<uint16_t>(valueAttribute.value()); break; } case ITEM_PARSE_ELEMENTICE: { abilities.elementDamage = pugi::cast<uint16_t>(valueAttribute.value()); abilities.elementType = COMBAT_ICEDAMAGE; break; } case ITEM_PARSE_ELEMENTEARTH: { abilities.elementDamage = pugi::cast<uint16_t>(valueAttribute.value()); abilities.elementType = COMBAT_EARTHDAMAGE; break; } case ITEM_PARSE_ELEMENTFIRE: { abilities.elementDamage = pugi::cast<uint16_t>(valueAttribute.value()); abilities.elementType = COMBAT_FIREDAMAGE; break; } case ITEM_PARSE_ELEMENTENERGY: { abilities.elementDamage = pugi::cast<uint16_t>(valueAttribute.value()); abilities.elementType = COMBAT_ENERGYDAMAGE; break; } case ITEM_PARSE_WALKSTACK: { it.walkStack = valueAttribute.as_bool(); break; } case ITEM_PARSE_BLOCKING: { it.blockSolid = valueAttribute.as_bool(); break; } case ITEM_PARSE_ALLOWDISTREAD: { it.allowDistRead = booleanString(valueAttribute.as_string()); break; } default: { // It should not ever get to here, only if you add a new key to the map and don't configure a case for it. std::cout << "[Warning - Items::parseItemNode] Not configured key value: " << keyAttribute.as_string() << std::endl; break; } } } else { std::cout << "[Warning - Items::parseItemNode] Unknown key value: " << keyAttribute.as_string() << std::endl; } } //check bed items if ((it.transformToFree != 0 || it.transformToOnUse[PLAYERSEX_FEMALE] != 0 || it.transformToOnUse[PLAYERSEX_MALE] != 0) && it.type != ITEM_TYPE_BED) { std::cout << "[Warning - Items::parseItemNode] Item " << it.id << " is not set as a bed-type" << std::endl; } }
bool Monsters::deserializeSpell(const pugi::xml_node& node, spellBlock_t& sb, const std::string& description) { std::string name; std::string scriptName; bool isScripted; pugi::xml_attribute attr; if ((attr = node.attribute("script"))) { scriptName = attr.as_string(); isScripted = true; } else if ((attr = node.attribute("name"))) { name = attr.as_string(); isScripted = false; } else { return false; } if ((attr = node.attribute("speed")) || (attr = node.attribute("interval"))) { sb.speed = std::max<int32_t>(1, pugi::cast<int32_t>(attr.value())); } if ((attr = node.attribute("chance"))) { uint32_t chance = pugi::cast<uint32_t>(attr.value()); if (chance > 100) { chance = 100; } sb.chance = chance; } if ((attr = node.attribute("range"))) { uint32_t range = pugi::cast<uint32_t>(attr.value()); if (range > (Map::maxViewportX * 2)) { range = Map::maxViewportX * 2; } sb.range = range; } if ((attr = node.attribute("min"))) { sb.minCombatValue = pugi::cast<int32_t>(attr.value()); } if ((attr = node.attribute("max"))) { sb.maxCombatValue = pugi::cast<int32_t>(attr.value()); //normalize values if (std::abs(sb.minCombatValue) > std::abs(sb.maxCombatValue)) { int32_t value = sb.maxCombatValue; sb.maxCombatValue = sb.minCombatValue; sb.minCombatValue = value; } } if (auto spell = g_spells->getSpellByName(name)) { sb.spell = spell; return true; } CombatSpell* combatSpell = nullptr; bool needTarget = false; bool needDirection = false; if (isScripted) { if ((attr = node.attribute("direction"))) { needDirection = attr.as_bool(); } if ((attr = node.attribute("target"))) { needTarget = attr.as_bool(); } std::unique_ptr<CombatSpell> combatSpellPtr(new CombatSpell(nullptr, needTarget, needDirection)); if (!combatSpellPtr->loadScript("data/" + g_spells->getScriptBaseName() + "/scripts/" + scriptName)) { return false; } if (!combatSpellPtr->loadScriptCombat()) { return false; } combatSpell = combatSpellPtr.release(); combatSpell->getCombat()->setPlayerCombatValues(COMBAT_FORMULA_DAMAGE, sb.minCombatValue, 0, sb.maxCombatValue, 0); } else { Combat* combat = new Combat; if ((attr = node.attribute("length"))) { int32_t length = pugi::cast<int32_t>(attr.value()); if (length > 0) { int32_t spread = 3; //need direction spell if ((attr = node.attribute("spread"))) { spread = std::max<int32_t>(0, pugi::cast<int32_t>(attr.value())); } AreaCombat* area = new AreaCombat(); area->setupArea(length, spread); combat->setArea(area); needDirection = true; } } if ((attr = node.attribute("radius"))) { int32_t radius = pugi::cast<int32_t>(attr.value()); //target spell if ((attr = node.attribute("target"))) { needTarget = attr.as_bool(); } AreaCombat* area = new AreaCombat(); area->setupArea(radius); combat->setArea(area); } std::string tmpName = asLowerCaseString(name); if (tmpName == "melee") { sb.isMelee = true; pugi::xml_attribute attackAttribute, skillAttribute; if ((attackAttribute = node.attribute("attack")) && (skillAttribute = node.attribute("skill"))) { sb.minCombatValue = 0; sb.maxCombatValue = -Weapons::getMaxMeleeDamage(pugi::cast<int32_t>(skillAttribute.value()), pugi::cast<int32_t>(attackAttribute.value())); } ConditionType_t conditionType = CONDITION_NONE; int32_t minDamage = 0; int32_t maxDamage = 0; uint32_t tickInterval = 2000; if ((attr = node.attribute("fire"))) { conditionType = CONDITION_FIRE; minDamage = pugi::cast<int32_t>(attr.value()); maxDamage = minDamage; tickInterval = 9000; } else if ((attr = node.attribute("poison"))) { conditionType = CONDITION_POISON; minDamage = pugi::cast<int32_t>(attr.value()); maxDamage = minDamage; tickInterval = 5000; } else if ((attr = node.attribute("energy"))) { conditionType = CONDITION_ENERGY; minDamage = pugi::cast<int32_t>(attr.value()); maxDamage = minDamage; tickInterval = 10000; } else if ((attr = node.attribute("drown"))) { conditionType = CONDITION_DROWN; minDamage = pugi::cast<int32_t>(attr.value()); maxDamage = minDamage; tickInterval = 5000; } else if ((attr = node.attribute("freeze"))) { conditionType = CONDITION_FREEZING; minDamage = pugi::cast<int32_t>(attr.value()); maxDamage = minDamage; tickInterval = 8000; } else if ((attr = node.attribute("dazzle"))) { conditionType = CONDITION_DAZZLED; minDamage = pugi::cast<int32_t>(attr.value()); maxDamage = minDamage; tickInterval = 10000; } else if ((attr = node.attribute("curse"))) { conditionType = CONDITION_CURSED; minDamage = pugi::cast<int32_t>(attr.value()); maxDamage = minDamage; tickInterval = 4000; } else if ((attr = node.attribute("bleed")) || (attr = node.attribute("physical"))) { conditionType = CONDITION_BLEEDING; tickInterval = 5000; } if ((attr = node.attribute("tick"))) { int32_t value = pugi::cast<int32_t>(attr.value()); if (value > 0) { tickInterval = value; } } if (conditionType != CONDITION_NONE) { Condition* condition = getDamageCondition(conditionType, maxDamage, minDamage, 0, tickInterval); combat->setCondition(condition); } sb.range = 1; combat->setParam(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE); combat->setParam(COMBAT_PARAM_BLOCKARMOR, 1); combat->setParam(COMBAT_PARAM_BLOCKSHIELD, 1); combat->setOrigin(ORIGIN_MELEE); } else if (tmpName == "physical") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE); combat->setParam(COMBAT_PARAM_BLOCKARMOR, 1); combat->setOrigin(ORIGIN_RANGED); } else if (tmpName == "bleed") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE); } else if (tmpName == "poison" || tmpName == "earth") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_EARTHDAMAGE); } else if (tmpName == "fire") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE); } else if (tmpName == "energy") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE); } else if (tmpName == "drown") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_DROWNDAMAGE); } else if (tmpName == "ice") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE); } else if (tmpName == "holy") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE); } else if (tmpName == "death") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE); } else if (tmpName == "lifedrain") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_LIFEDRAIN); } else if (tmpName == "manadrain") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_MANADRAIN); } else if (tmpName == "healing") { combat->setParam(COMBAT_PARAM_TYPE, COMBAT_HEALING); combat->setParam(COMBAT_PARAM_AGGRESSIVE, 0); } else if (tmpName == "speed") { int32_t speedChange = 0; int32_t duration = 10000; if ((attr = node.attribute("duration"))) { duration = pugi::cast<int32_t>(attr.value()); } if ((attr = node.attribute("speedchange"))) { speedChange = pugi::cast<int32_t>(attr.value()); if (speedChange < -1000) { //cant be slower than 100% speedChange = -1000; } } ConditionType_t conditionType; if (speedChange > 0) { conditionType = CONDITION_HASTE; combat->setParam(COMBAT_PARAM_AGGRESSIVE, 0); } else { conditionType = CONDITION_PARALYZE; } ConditionSpeed* condition = static_cast<ConditionSpeed*>(Condition::createCondition(CONDITIONID_COMBAT, conditionType, duration, 0)); condition->setFormulaVars(speedChange / 1000.0, 0, speedChange / 1000.0, 0); combat->setCondition(condition); } else if (tmpName == "outfit") { int32_t duration = 10000; if ((attr = node.attribute("duration"))) { duration = pugi::cast<int32_t>(attr.value()); } if ((attr = node.attribute("monster"))) { MonsterType* mType = g_monsters.getMonsterType(attr.as_string()); if (mType) { ConditionOutfit* condition = static_cast<ConditionOutfit*>(Condition::createCondition(CONDITIONID_COMBAT, CONDITION_OUTFIT, duration, 0)); condition->setOutfit(mType->outfit); combat->setParam(COMBAT_PARAM_AGGRESSIVE, 0); combat->setCondition(condition); } } else if ((attr = node.attribute("item"))) { Outfit_t outfit; outfit.lookTypeEx = pugi::cast<uint16_t>(attr.value()); ConditionOutfit* condition = static_cast<ConditionOutfit*>(Condition::createCondition(CONDITIONID_COMBAT, CONDITION_OUTFIT, duration, 0)); condition->setOutfit(outfit); combat->setParam(COMBAT_PARAM_AGGRESSIVE, 0); combat->setCondition(condition); } } else if (tmpName == "invisible") { int32_t duration = 10000; if ((attr = node.attribute("duration"))) { duration = pugi::cast<int32_t>(attr.value()); } Condition* condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_INVISIBLE, duration, 0); combat->setParam(COMBAT_PARAM_AGGRESSIVE, 0); combat->setCondition(condition); } else if (tmpName == "drunk") { int32_t duration = 10000; if ((attr = node.attribute("duration"))) { duration = pugi::cast<int32_t>(attr.value()); } Condition* condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_DRUNK, duration, 0); combat->setCondition(condition); } else if (tmpName == "firefield") { combat->setParam(COMBAT_PARAM_CREATEITEM, ITEM_FIREFIELD_PVP_FULL); } else if (tmpName == "poisonfield") { combat->setParam(COMBAT_PARAM_CREATEITEM, ITEM_POISONFIELD_PVP); } else if (tmpName == "energyfield") { combat->setParam(COMBAT_PARAM_CREATEITEM, ITEM_ENERGYFIELD_PVP); } else if (tmpName == "firecondition" || tmpName == "energycondition" || tmpName == "earthcondition" || tmpName == "poisoncondition" || tmpName == "icecondition" || tmpName == "freezecondition" || tmpName == "deathcondition" || tmpName == "cursecondition" || tmpName == "holycondition" || tmpName == "dazzlecondition" || tmpName == "drowncondition" || tmpName == "bleedcondition" || tmpName == "physicalcondition") { ConditionType_t conditionType = CONDITION_NONE; uint32_t tickInterval = 2000; if (tmpName == "firecondition") { conditionType = CONDITION_FIRE; tickInterval = 10000; } else if (tmpName == "poisoncondition" || tmpName == "earthcondition") { conditionType = CONDITION_POISON; tickInterval = 5000; } else if (tmpName == "energycondition") { conditionType = CONDITION_ENERGY; tickInterval = 10000; } else if (tmpName == "drowncondition") { conditionType = CONDITION_DROWN; tickInterval = 5000; } else if (tmpName == "freezecondition" || tmpName == "icecondition") { conditionType = CONDITION_FREEZING; tickInterval = 10000; } else if (tmpName == "cursecondition" || tmpName == "deathcondition") { conditionType = CONDITION_CURSED; tickInterval = 4000; } else if (tmpName == "dazzlecondition" || tmpName == "holycondition") { conditionType = CONDITION_DAZZLED; tickInterval = 10000; } else if (tmpName == "physicalcondition" || tmpName == "bleedcondition") { conditionType = CONDITION_BLEEDING; tickInterval = 5000; } if ((attr = node.attribute("tick"))) { int32_t value = pugi::cast<int32_t>(attr.value()); if (value > 0) { tickInterval = value; } } int32_t minDamage = std::abs(sb.minCombatValue); int32_t maxDamage = std::abs(sb.maxCombatValue); int32_t startDamage = 0; if ((attr = node.attribute("start"))) { int32_t value = std::abs(pugi::cast<int32_t>(attr.value())); if (value <= minDamage) { startDamage = value; } } Condition* condition = getDamageCondition(conditionType, maxDamage, minDamage, startDamage, tickInterval); combat->setCondition(condition); } else if (tmpName == "strength") { // } else if (tmpName == "effect") { // } else { std::cout << "[Error - Monsters::deserializeSpell] - " << description << " - Unknown spell name: " << name << std::endl; delete combat; return false; } combat->setPlayerCombatValues(COMBAT_FORMULA_DAMAGE, sb.minCombatValue, 0, sb.maxCombatValue, 0); combatSpell = new CombatSpell(combat, needTarget, needDirection); for (auto attributeNode : node.children()) { if ((attr = attributeNode.attribute("key"))) { const char* value = attr.value(); if (strcasecmp(value, "shooteffect") == 0) { if ((attr = attributeNode.attribute("value"))) { ShootType_t shoot = getShootType(attr.as_string()); if (shoot != CONST_ANI_NONE) { combat->setParam(COMBAT_PARAM_DISTANCEEFFECT, shoot); } else { std::cout << "[Warning - Monsters::deserializeSpell] " << description << " - Unknown shootEffect: " << attr.as_string() << std::endl; } } } else if (strcasecmp(value, "areaeffect") == 0) { if ((attr = attributeNode.attribute("value"))) { MagicEffectClasses effect = getMagicEffect(attr.as_string()); if (effect != CONST_ME_NONE) { combat->setParam(COMBAT_PARAM_EFFECT, effect); } else { std::cout << "[Warning - Monsters::deserializeSpell] " << description << " - Unknown areaEffect: " << attr.as_string() << std::endl; } } } else { std::cout << "[Warning - Monsters::deserializeSpells] Effect type \"" << attr.as_string() << "\" does not exist." << std::endl; } } } } sb.spell = combatSpell; if (combatSpell) { sb.combatSpell = true; } return true; }