public void OnPerception(uint PerceivedObjectId, bool Heard, bool Inaudible, bool Seen, bool Vanished)
{
//
// No need to manage perception tracking for PC or DM avatars as
// these will never be AI controlled.
//
if (IsPC || IsDM)
return;
//
// Update the perception list. This is done even if we are not yet
// AI controlled (as control could be temporarily suspended e.g. by
// DM command).
//
PerceptionNode Node = (from PN in PerceivedObjects
where PN.PerceivedObjectId == PerceivedObjectId
select PN).FirstOrDefault();
bool NewNode = false;
bool RemoveNode = false;
if (Node == null)
{
if (Heard || Seen)
{
Node = new PerceptionNode(PerceivedObjectId);
NewNode = true;
PerceivedObjects.Add(Node);
}
else
{
return;
}
}
if (Heard)
{
Node.Heard = true;
if (Party == null) OnSpawn();
OnPerceptionSeenObject(PerceivedObjectId, NewNode);
}
if (Seen)
{
Node.Seen = true;
if (Party == null) OnSpawn();
OnPerceptionHeardObject(PerceivedObjectId, NewNode);
}
if (Vanished)
{
Node.Seen = false;
if (!Node.Heard)
{
RemoveNode = true;
PerceivedObjects.Remove(Node);
}
OnPerceptionLostSightObject(PerceivedObjectId, RemoveNode);
}
if (Inaudible)
{
Node.Heard = false;
if (!Node.Seen)
{
RemoveNode = true;
PerceivedObjects.Remove(Node);
}
OnPerceptionLostHearingObject(PerceivedObjectId, RemoveNode);
}
}