示例#1
0
void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent)
{
    threatRefStatusChangeEvent->setThreatManager(this);     // now we can set the threat manager

    HostileReference* hostileReference = threatRefStatusChangeEvent->getReference();

    switch(threatRefStatusChangeEvent->getType())
    {
        case UEV_THREAT_REF_THREAT_CHANGE:
            if((getCurrentVictim() == hostileReference && threatRefStatusChangeEvent->getFValue()<0.0f) ||
                (getCurrentVictim() != hostileReference && threatRefStatusChangeEvent->getFValue()>0.0f))
                setDirty(true);                             // the order in the threat list might have changed
            break;
        case UEV_THREAT_REF_ONLINE_STATUS:
            if(!hostileReference->isOnline())
            {
                if (hostileReference == getCurrentVictim())
                {
                    setCurrentVictim(NULL);
                    setDirty(true);
                }
                if (getOwner() && getOwner()->IsInWorld())
                    if (Unit* target = ObjectAccessor::GetUnit(*getOwner(), hostileReference->getUnitGuid()))
                        if (getOwner()->IsInMap(target))
                            getOwner()->SendThreatRemove(hostileReference);
                iThreatContainer.remove(hostileReference);
                iUpdateNeed = true;
                iThreatOfflineContainer.addReference(hostileReference);
            }
            else
            {
                if(getCurrentVictim() && hostileReference->getThreat() > (1.1f * getCurrentVictim()->getThreat()))
                    setDirty(true);
                iThreatContainer.addReference(hostileReference);
                iUpdateNeed = true;
                iThreatOfflineContainer.remove(hostileReference);
            }
            break;
        case UEV_THREAT_REF_REMOVE_FROM_LIST:
            if (hostileReference == getCurrentVictim())
            {
                setCurrentVictim(NULL);
                setDirty(true);
            }
            if(hostileReference->isOnline())
            {
                if (getOwner() && getOwner()->IsInWorld())
                    if (Unit* target = ObjectAccessor::GetUnit(*getOwner(), hostileReference->getUnitGuid()))
                        if (getOwner()->IsInMap(target))
                            getOwner()->SendThreatRemove(hostileReference);
                iThreatContainer.remove(hostileReference);
                iUpdateNeed = true;
            }
            else
                iThreatOfflineContainer.remove(hostileReference);
            break;
    }
}
示例#2
0
//============================================================
// Return the HostileReference of NULL, if not found
HostileReference* ThreatContainer::getReferenceByTarget(Unit* victim) const
{
    if (!victim)
        return NULL;

    uint64 const guid = victim->GetGUID();
    for (ThreatContainer::StorageType::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
    {
        HostileReference* ref = (*i);
        if (ref && ref->getUnitGuid() == guid)
            return ref;
    }

    return NULL;
}