Index: sql/item_mods.sql =================================================================== --- sql/item_mods.sql (revision 2013) +++ sql/item_mods.sql (working copy) @@ -11745,6 +11745,7 @@ INSERT INTO `item_mods` VALUES(15965, 2, 15); INSERT INTO `item_mods` VALUES(15965, 23, 5); INSERT INTO `item_mods` VALUES(15965, 68, 5); +INSERT INTO `item_mods` VALUES(15965, 357, 3); INSERT INTO `item_mods` VALUES(15966, 24, 2); INSERT INTO `item_mods` VALUES(15968, 23, 5); INSERT INTO `item_mods` VALUES(15970, 2, 20); Index: src/map/battleutils.cpp =================================================================== --- src/map/battleutils.cpp (revision 2013) +++ src/map/battleutils.cpp (working copy) @@ -1046,9 +1046,10 @@ } damage -= absorb; } + + // assign calculated damage + damage = AssignDamage(PAttacker, PDefender, damage); - PDefender->addHP(-damage); - if (PAttacker->PMaster != NULL) { PDefender->m_OwnerID.id = PAttacker->PMaster->id; @@ -1186,8 +1187,19 @@ damage = damage * (100 - (10 * PAttacker->m_ActionList.size() / 2)) / 100; damage = damage * (1000 - PDefender->getMod(MOD_FIREDEF + PSpell->getElement())) / 1000; - PDefender->addHP(-damage); + // calculate conversion mod + uint8 convertDmgToMPPercent = PDefender->getMod(MOD_CONVDMGTOMP); + // if convert mod and exists and damage is + // greater than 33.67 to trigger effects + if(convertDmgToMPPercent > 0 && damage >= 34) { + uint16 conversion = (uint16)(damage * 1.0) * ((convertDmgToMPPercent * 1.0) / 100.0f); + damage = damage - conversion; + PDefender->addMP(conversion); + } + // assign calculated damage + damage = AssignDamage(PAttacker, PDefender, damage); + if (PAttacker->PMaster != NULL) { PDefender->m_OwnerID.id = PAttacker->PMaster->id; @@ -2061,7 +2073,8 @@ damage = damage * (1000 - resistance) / 1000; - PDefender->addHP(-damage); + // assign calculated damage + damage = AssignDamage(PAttacker, PDefender, damage); if (PAttacker->PMaster != NULL) { @@ -2278,6 +2291,41 @@ } /************************************************************************ + * Actually assigns damage from spells, physical sources, etc. This allows + * conversion and on damage modifications/effects to share a single code + * path when the damage source is irrelevant + ************************************************************************/ +uint16 AssignDamage(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint16 baseDamage) +{ + ShowDebug("battleutils::AssignDamage called with %u base damage. \n", baseDamage); + + // calcualte from damage + uint16 damage = baseDamage; + + // calculate conversion mod + uint16 convertDmgToMPPercent = PDefender->getMod(MOD_CONVDMGTOMP); + + ShowDebug("battleutils::AssignDamage using convert mod: %u. \n", convertDmgToMPPercent); + + // if convert mod and exists and damage is + // greater than 33.67 to trigger effects + if(convertDmgToMPPercent > 0 && baseDamage >= 34) { + uint16 conversion = (uint16)(baseDamage * 1.0) * ((convertDmgToMPPercent * 1.0) / 100.0); + damage = baseDamage - conversion; + + ShowDebug("battleutils::AssignDamage converting damage to %u MP", conversion); + + PDefender->addMP(conversion); + } + + ShowDebug("battleutils::AssignDamage is assigning %u damage to target. \n", damage); + + PDefender->addHP(-damage); + + return damage; +} + +/************************************************************************ * * * Adds enmity to PSource for all the MOB targets who have * * PTarget on their enmity list. * Index: src/map/battleutils.h =================================================================== --- src/map/battleutils.h (revision 2013) +++ src/map/battleutils.h (working copy) @@ -122,6 +122,7 @@ bool isValidSelfTargetWeaponskill(int wsid); bool TryInterruptSpell(CBattleEntity* PAttacker, CBattleEntity* PDefender); float CalculateBaseTP(int delay, int stp); + uint16 AssignDamage(CBattleEntity* PAttacker, CBattleEntity* PDefender, uint16 baseDamage); void GenerateCureEnmity(CBattleEntity* PSource, CBattleEntity* PTarget, uint16 amount); CItemWeapon* GetEntityWeapon(CBattleEntity* PEntity, SLOTTYPE Slot); Index: src/map/modifier.h =================================================================== --- src/map/modifier.h (revision 2013) +++ src/map/modifier.h (working copy) @@ -392,10 +392,15 @@ // Special Modifier MOD_ADDS_WEAPONSKILL = 0x163, - MOD_ADDS_WEAPONSKILL_DYN = 0x164 + MOD_ADDS_WEAPONSKILL_DYN = 0x164, + +// Convert Damage to MP + + MOD_CONVDMGTOMP = 0x165 // ethereal earing, really + }; -#define MAX_MODIFIER 0x167 +#define MAX_MODIFIER 0x168 /************************************************************************