Пример #1
0
        public void ProcessThreatEvent(ThreatRefStatusChangeEvent threatRefStatusChangeEvent)
        {
            threatRefStatusChangeEvent.SetThreatManager(this);     // now we can set the threat manager

            HostileReference hostilRef = threatRefStatusChangeEvent.GetReference();

            switch (threatRefStatusChangeEvent.GetEventType())
            {
            case UnitEventTypes.ThreatRefThreatChange:
                if ((getCurrentVictim() == hostilRef && threatRefStatusChangeEvent.GetFValue() < 0.0f) ||
                    (getCurrentVictim() != hostilRef && threatRefStatusChangeEvent.GetFValue() > 0.0f))
                {
                    SetDirty(true);                                 // the order in the threat list might have changed
                }
                break;

            case UnitEventTypes.ThreatRefOnlineStatus:
                if (!hostilRef.IsOnline())
                {
                    if (hostilRef == getCurrentVictim())
                    {
                        SetCurrentVictim(null);
                        SetDirty(true);
                    }
                    Owner.SendRemoveFromThreatList(hostilRef);
                    threatContainer.Remove(hostilRef);
                    threatOfflineContainer.AddReference(hostilRef);
                }
                else
                {
                    if (GetCurrentVictim() != null && hostilRef.GetThreat() > (1.1f * getCurrentVictim().GetThreat()))
                    {
                        SetDirty(true);
                    }
                    threatContainer.AddReference(hostilRef);
                    threatOfflineContainer.Remove(hostilRef);
                }
                break;

            case UnitEventTypes.ThreatRefRemoveFromList:
                if (hostilRef == getCurrentVictim())
                {
                    SetCurrentVictim(null);
                    SetDirty(true);
                }
                Owner.SendRemoveFromThreatList(hostilRef);
                if (hostilRef.IsOnline())
                {
                    threatContainer.Remove(hostilRef);
                }
                else
                {
                    threatOfflineContainer.Remove(hostilRef);
                }
                break;
            }
        }