Ejemplo n.º 1
0
Unit* ThreatManager::getHostileTarget()
{
    iThreatContainer.update();
    HostileReference* nextVictim = iThreatContainer.selectNextVictim((Creature*) getOwner(), getCurrentVictim());
    setCurrentVictim(nextVictim);
    return getCurrentVictim() != nullptr ? getCurrentVictim()->getTarget() : nullptr;
}
Ejemplo n.º 2
0
Unit* ThreatManager::getHostilTarget()
{
    iThreatContainer.update();
    HostileReference* nextVictim = iThreatContainer.selectNextVictim(getOwner()->ToCreature(), getCurrentVictim());
    setCurrentVictim(nextVictim);
    return getCurrentVictim() != NULL ? getCurrentVictim()->getTarget() : NULL;
}
Ejemplo n.º 3
0
void ThreatManager::tauntApply(Unit* taunter)
{
    HostileReference* ref = iThreatContainer.getReferenceByTarget(taunter);
    if (getCurrentVictim() && ref && (ref->getThreat() < getCurrentVictim()->getThreat()))
    {
        if (ref->getTempThreatModifier() == 0.0f) // Ok, temp threat is unused
            ref->setTempThreat(getCurrentVictim()->getThreat());
    }
}
Ejemplo n.º 4
0
void ThreatManager::tauntApply(Unit* pTaunter)
{
    if (HostileReference* ref = iThreatContainer.getReferenceByTarget(pTaunter))
    {
        if (getCurrentVictim() && (ref->getThreat() < getCurrentVictim()->getThreat()))
        {
            // Ok, temp threat is unused
            if (ref->getTempThreatModifyer() == 0.0f)
            {
                ref->setTempThreat(getCurrentVictim()->getThreat());
                iUpdateNeed = true;
            }
        }
    }
}
Ejemplo n.º 5
0
void ThreatManager::processThreatEvent (ThreatRefStatusChangeEvent* threatRefStatusChangeEvent)
{
    threatRefStatusChangeEvent->setThreatManager(this);          // now we can set the threat manager

    HostileReference* hostilReference = threatRefStatusChangeEvent->getReference();

    switch (threatRefStatusChangeEvent->getType())
    {
    case UEV_THREAT_REF_THREAT_CHANGE:
        if ((getCurrentVictim() == hostilReference && threatRefStatusChangeEvent->getFValue() < 0.0f) || (getCurrentVictim() != hostilReference && threatRefStatusChangeEvent->getFValue() > 0.0f))
            setDirty(true);          // the order in the threat list might have changed
        break;
    case UEV_THREAT_REF_ONLINE_STATUS:
        if (!hostilReference->isOnline())
        {
            if (hostilReference == getCurrentVictim())
            {
                setCurrentVictim (NULL);
                setDirty(true);
            }
            iThreatContainer.remove(hostilReference);
            iThreatOfflineContainer.addReference(hostilReference);
        }
        else
        {
            if (getCurrentVictim() && hostilReference->getThreat() > (1.1f * getCurrentVictim()->getThreat()))
                setDirty(true);
            iThreatContainer.addReference(hostilReference);
            iThreatOfflineContainer.remove(hostilReference);
        }
        break;
    case UEV_THREAT_REF_REMOVE_FROM_LIST:
        if (hostilReference == getCurrentVictim())
        {
            setCurrentVictim (NULL);
            setDirty(true);
        }
        iOwner->SendRemoveFromThreatListOpcode(hostilReference);
        if (hostilReference->isOnline())
            iThreatContainer.remove(hostilReference);
        else
            iThreatOfflineContainer.remove(hostilReference);
        break;
    }
}
Ejemplo n.º 6
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;
    }
}
Ejemplo n.º 7
0
bool ThreatManager::processThreatEvent(const UnitBaseEvent* pUnitBaseEvent)
{
    bool consumed = false;

    ThreatRefStatusChangeEvent* threatRefStatusChangeEvent;
    HostilReference* hostilReference;

    threatRefStatusChangeEvent = (ThreatRefStatusChangeEvent*) pUnitBaseEvent;
    threatRefStatusChangeEvent->setThreatManager(this);     // now we can set the threat manager
    hostilReference = threatRefStatusChangeEvent->getReference();

    switch(pUnitBaseEvent->getType())
    {
        case UEV_THREAT_REF_THREAT_CHANGE:
            if((getCurrentVictim() == hostilReference && threatRefStatusChangeEvent->getFValue()<0.0f) ||
                (getCurrentVictim() != hostilReference && threatRefStatusChangeEvent->getFValue()>0.0f))
                setDirty(true);                             // the order in the threat list might have changed
            break;
        case UEV_THREAT_REF_ONLINE_STATUS:
            if(!hostilReference->isOnline())
            {
                if (hostilReference == getCurrentVictim())
                {
                    setCurrentVictim(NULL);
                    setDirty(true);
                }
                iThreatContainer.remove(hostilReference);
                iThreatOfflineContainer.addReference(hostilReference);
            }
            else
            {
                if(getCurrentVictim() && hostilReference->getThreat() > (1.1f * getCurrentVictim()->getThreat()))
                    setDirty(true);
                iThreatContainer.addReference(hostilReference);
                iThreatOfflineContainer.remove(hostilReference);
            }
            break;
        case UEV_THREAT_REF_REMOVE_FROM_LIST:
            if (hostilReference == getCurrentVictim())
            {
                setCurrentVictim(NULL);
                setDirty(true);
            }
            if(hostilReference->isOnline())
                iThreatContainer.remove(hostilReference);
            else
                iThreatOfflineContainer.remove(hostilReference);
            break;
    }
    return consumed;
}