Page 1 of 1

GameLivingEvent.EnemyHealed

PostPosted: Sat Mar 14, 2009 2:53 am
by Kakuri
This is driving me a little batty...

Mobs on my server mysteriously stopped receiving EnemyHealed events. A quick search of the entire project revealed there's only one origin for EnemyHealed events, and it's in GameLiving.ChangeHealth. If my health changes, and it's the result of a heal (rather than health regen), I notify all my attackers with an EnemyHealed event. In quick look at the SVN history for GameLiving.cs I didn't see any recent changes to this method.

So here's the kicker:
Why did this ever work? It looks like it notifies all of your attackers of the EnemyHealed event except for the one you have targeted.
Code: Select all
foreach (GameObject attacker in attackers)
{
if (attacker is GameLiving && attacker != TargetObject)
{
(attacker as GameLiving).Notify(GameLivingEvent.EnemyHealed, (GameLiving)attacker, args);
(attacker as GameLiving).AddXPGainer(changeSource, healthChanged);
}
}
I changed that loop to the following and it's now working:
Code: Select all
foreach ( GameLiving attacker in attackers )
{
if ( attacker != null )
{
attacker.Notify( GameLivingEvent.EnemyHealed, attacker, args );
attacker.AddXPGainer( changeSource, healthChanged );
}
}
Should I commit this change, or can anyone tell me some good reason for the original code? Has anyone else noticed this not working?

Re: GameLivingEvent.EnemyHealed

PostPosted: Sat Mar 14, 2009 8:11 am
by Graveen
I don't even understand why it worked previously.

The event is fired on health changes; can we fall in a recursive loop ?

Can the attackers table contains yourself, or strictly non related objects to attack ?

I suggest to commit, anw.

Re: GameLivingEvent.EnemyHealed

PostPosted: Sat Mar 14, 2009 9:29 pm
by Aredhel
Seems like an ok fix to me.