A spell that cures for 80 levels would cure a level 78 spell and a level 2 spell. Or a level 68 spell and a level 12 spell, and so on. And it cures from highest to lowest.
Code: Select all
void Entity::CureDetrimentByType(int8 cure_level, int8 det_type, string cure_name, Entity* caster) {
if (cure_level <= 0 || (GetDetTypeCount(det_type) <= 0 && (det_type == DET_TYPE_ALL && GetDetCount() <= 0)))
return;
vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
map<int8, vector<LuaSpell*>> remove_list;
int8 total_cure_level = 0;
MDetriments.readlock(__FUNCTION__, __LINE__);
for (const auto& det : *det_list) {
if ((det.det_type == det_type || (det_type == DET_TYPE_ALL && det.det_type != DET_TYPE_CURSE)) && !det.incurable) {
vector<LevelArray*>* levels = det.spell->spell->GetSpellLevels();
InfoStruct* info_struct = det.caster->GetInfoStruct();
if (levels->size() > 0) {
for (const auto& x : *levels) {
int8 level = x->spell_level / 10;
int8 det_class = x->adventure_class;
if ((info_struct->class1 == det_class || info_struct->class2 == det_class || info_struct->class3 == det_class || det.caster->GetAdventureClass() == det_class) && cure_level >= level) {
remove_list[level].push_back(det.spell);
break;
}
}
} else if (cure_level >= det.caster->GetLevel()) {
remove_list[det.caster->GetLevel()].push_back(det.spell);
break;
}
}
}
MDetriments.releasereadlock(__FUNCTION__, __LINE__);
for (auto it = remove_list.rbegin(); it != remove_list.rend(); ++it) {
if (total_cure_level + it->first > cure_level) break;
for (const auto& spell : it->second) {
if (total_cure_level + it->first > cure_level) break;
GetZone()->SendDispellPacket(caster, this, cure_name, (string)spell->spell->GetName(), DISPELL_TYPE_CURE);
if (GetZone())
GetZone()->RemoveTargetFromSpell(spell, this);
RemoveSpellEffect(spell);
RemoveDetrimentalSpell(spell);
total_cure_level += it->first;
}
}
}
Also requires a change to the Lua function call:
Code: Select all
static_cast<Entity*>(target)->CureDetrimentByType(cure_level, cure_type, cure_name.length() > 0 ? cure_name : static_cast<string>(spell->spell->GetName()), spell->caster);