Page 1 of 1

NPC Spells Cast %

Posted: Fri May 10, 2019 6:03 am
by Gangrenous
Before I start digging into the source, are we definitely talking a percentage? So if the cast_percentage is set to 2, then during a turn a random is rolled and it should fire 2% of the time? I swear I changed it to 2 and reloaded, during a 60 second fight I got hit like 10 damn times which seems impossible.

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 6:15 am
by Gangrenous
Well I see where the difference is in what I expected and what is actually happening. ProcessSpell in the brain is firing 3-4 times a second. I am not sure yet if that should actually be happening.

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 7:01 am
by Ememjr
Gangrenous wrote: Fri May 10, 2019 6:15 am Well I see where the difference is in what I expected and what is actually happening. ProcessSpell in the brain is firing 3-4 times a second. I am not sure yet if that should actually be happening.
i dont think that is correct eitherif its the same spell fireing 3-4 times per second, it should only fire as fast as the spell is designed for

so for example Incinarate takes 1 second to cast and has an 8 second recast, which means it should only be getting cast 1 every 9 seconds

but to be complete in my diagnosis, lol, I need to know the name of the spell your looking at

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 8:11 am
by Gangrenous
It is a custom spell, I am still looking into the code to see why. I change spell data such as recast, duration, call frequency but those checks are still being done at the same rate. Combat is being process around every 2000ms on my server. My thinking is that spells should not be processed any faster than that. I mean if you are processing combat at that rate, you should not want a spell firing off 8 times when combat is only processed once in the same amount of time.

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 9:25 am
by Gangrenous
Okay from doing a little bit of searching, in NPC_AI.cpp

BrainThink

Code: Select all

if(!m_body->IsCasting() && (!HasRecovered() || !ProcessSpell(target, distance))) {
   LogWrite(NPC_AI__DEBUG, 7, "NPC_AI", "%s is attempting melee on %s.", m_body->GetName(), target->GetName());
   m_body->FaceTarget(target);
   ProcessMelee(target, distance);
}
That ProcessSpell returns a bool, that is where the check against the GetCastPercentage is done. Since BrainThink is called so much, that is the consideration here. Seems like that could need a change? On a large battle that seems like a ton of checks, not sure if it is needed just yet.

Also in NPC_AI, further down, this is where the GetCastPercentage is done.

Code: Select all

if(rand()%100 > m_body->GetCastPercentage() || m_body->IsStifled() || m_body->IsFeared())

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 11:13 am
by Gangrenous
Looks like around line 42 of NPC_AI.cpp this should be changed.

Code: Select all

m_spellRecovery = Timer::GetCurrentTime2();
Around line 100 I change it to look like this.

Code: Select all

if(!m_body->IsCasting()) {
   LogWrite(NPC_AI__DEBUG, 7, "NPC_AI", "%s is attempting melee on %s.", m_body->GetName(), target->GetName());
   m_body->FaceTarget(target);
   ProcessMelee(target, distance);
					
   if (HasRecovered)
      ProcessSpell(target, distance);
}

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 11:44 am
by Gangrenous
That prevented the mob from being able to constantly cast, this stops it and makes it obey recast rules but the checks are still way too often. If there are 4 checks a second at maybe 5% it does not take any time at all to get a hit. If indeed the npc needs to get a spell roll check on every melee check then the spell chance needs to be a float and drop below 1%.

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 11:57 am
by Gangrenous
This helps spell it out.
Capture.JPG
Within 9 seconds it rolled below a 0 with a 1% spawn cast time. So if you take a simple mob that may cast something like poison, even at 1% chance it is going to be casting it very often if it has recovered from the spell.

Re: NPC Spells Cast %

Posted: Fri May 10, 2019 1:21 pm
by Gangrenous
Well I also found that there is a crash in LuaFunctions when there is a spell call frequency is set, maybe special conditions but I need to go down this rabbit hole now.

Capture.JPG
This is after reverting past changes, so these are not related. It appears to be during removing a spell effect that is running per tick. Once the spell is wearing off and it tries to delete it, a crash.

Code: Select all

void LuaInterface::DeletePendingSpells(bool all) {
	MSpellDelete.lock();
	if(spells_pending_delete.size() > 0){
		int32 time = Timer::GetCurrentTime2();
		map<LuaSpell*, int32>::iterator itr;
		vector<LuaSpell*> tmp_deletes;
		vector<LuaSpell*>::iterator del_itr;
		for(itr = spells_pending_delete.begin(); itr != spells_pending_delete.end(); itr++){
			if(all || time >= itr->second)
				tmp_deletes.push_back(itr->first);
		}
		LuaSpell* spell = 0;
		for(del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++){
			spell = *del_itr;
			spells_pending_delete.erase(spell);
			safe_delete(spell);
		}
	}
	MSpellDelete.unlock();
}
Crashing at safe_delete(spell)