Cures

Code pertaining to the server

Moderator: Team Members

Post Reply
tyrbo
Team Member
Posts: 271
Joined: Thu Feb 18, 2016 12:33 pm

Cures

Post by tyrbo » Tue Jan 02, 2018 8:44 pm

Rewrote the cure code as it didn't appear to be wired up the same way as live cures work.

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;
		}
	}
}
Oh. And DET_TYPE_ALL is just a constant for 0. I'm using 0 to represent cure all the things, which is how cures work in EQ2 nowadays.

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);

tyrbo
Team Member
Posts: 271
Joined: Thu Feb 18, 2016 12:33 pm

Re: Cures

Post by tyrbo » Tue Jan 02, 2018 10:17 pm

Looks like this might only be working for player cures, can't cure NPC spells. Needed a little tweak to check adventure class.

This also has the issue of spells that are not tied to any class being uncurable. Needs another slight tweak I'll get to in a little bit.

Will keep the first post updated.

tyrbo
Team Member
Posts: 271
Joined: Thu Feb 18, 2016 12:33 pm

Re: Cures

Post by tyrbo » Tue Jan 02, 2018 10:26 pm

Okay, I think I'm good with the current iteration.

User avatar
Cynnar
Project Leader
Posts: 738
Joined: Sat Sep 27, 2014 1:22 am
EQ2Emu Server: Eq2emulator
Characters: Vlash
Veinlash
Taragak
Cynnar

Re: Cures

Post by Cynnar » Wed Jan 03, 2018 8:34 am

Thanks for the submission!

I can't do anything right now. I'm at the dealership getting my truck serviced. Check engine light came on, and it's still under warranty. Could be an all day affair.
[ 01000011 01111001 01101110 01101110 01100001 01110010 ]

Follow on:
Twitter Facebook

Contact me:
PM Discord chat email

Hardware: the parts of a computer that can be kicked

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests