Ordering of ItemDestroyed and ItemUnsubscribed events

Options
Tetrad
edited October 2012 in Photon Server
So in our game based on the Mmo project, I'm trying to implement death animations for NPCs.

The way I'm doing this is by, on the client, handling ItemDestroyed events to remove the client item from the cache, play the animation. then clean itself up.

ItemUnsubscribed just removes/hides the item model immediately on the client (by virtue of item.RemoveVisibleInterestArea). If the ItemDestroy message happens first, then nothing happens because ItemDestroy had already removed the item (through game.RemoveItem).

On NPC death, the server publishes on the EventChannel the ItemDestroyed ItemEventMessage, then calls Dispose on the item.

The problem I'm running in to is that the client *sometimes* gets ItemUnsubscribed messages before ItemDestroyed messages. The result of this is that my enemies just pop out of existence on death.

As far as I can tell, the ItemUnsubscribe happens because Item.Dispose sends a message on the ItemDisposedChannel and the ItemDestroyed gets published to the ItemEventChannel. And therefore which events get sent to the peer is non-deterministic.

I'm not sure the best way to resolve this issue. Ideally it would be set up such that those events always occur in the correct order. Right now I'm half tempted to jam more information into ItemUnsubscribed to say whether the item needs to do "something else" (i.e. play a death anim or whatever other than your normal "it's out of your interest area"). The other alternatives I've considered are delaying the Item.Dispose call (feels really hacky), or fundamentally changing my NPC code to have the concept of "being dead" (as well as all the targeting/attacking code to accommodate this new state) so that they aren't disposed on death but instead stick around for some arbitrary length of time.

Comments