本文整理汇总了C++中HostilReference类的典型用法代码示例。如果您正苦于以下问题:C++ HostilReference类的具体用法?C++ HostilReference怎么用?C++ HostilReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HostilReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void ThreatManager::addThreat(Unit* pVictim, float pThreat, SpellSchools pSchool, SpellEntry const *pThreatSpell)
{
//function deals with adding threat and adding players and pets into ThreatList
//mobs, NPCs, guards have ThreatList and HateOfflineList
//players and pets have only InHateListOf
//HateOfflineList is used co contain unattackable victims (in-flight, in-water, GM etc.)
if (pVictim == getOwner()) // only for same creatures :)
return;
if(!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster()) )
return;
assert(getOwner()->GetTypeId()== TYPEID_UNIT);
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, pSchool, pThreatSpell);
HostilReference* ref = iThreatContainer.addThreat(pVictim, threat);
// Ref is not in the online refs, search the offline refs next
if(!ref)
ref = iThreatOfflineContainer.addThreat(pVictim, threat);
if(!ref) // there was no ref => create a new one
{
// threat has to be 0 here
HostilReference* hostilReference = new HostilReference(pVictim, this, 0);
iThreatContainer.addReference(hostilReference);
hostilReference->addThreat(threat); // now we add the real threat
if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster())
hostilReference->setOnlineOfflineState(false); // GM is always offline
}
}
示例2: getReferenceByTarget
HostilReference* ThreatContainer::modifyThreatPercent(Unit *pVictim, int32 pPercent)
{
HostilReference* ref = getReferenceByTarget(pVictim);
assert(ref); // for a modification the reference must be there. (or not?)
ref->addThreatPercent(pPercent);
return ref;
}
示例3: getReferenceByTarget
HostilReference* ThreatContainer::addThreat(Unit* pVictim, float pThreat)
{
HostilReference* ref = getReferenceByTarget(pVictim);
if(ref)
ref->addThreat(pThreat);
return ref;
}
示例4: tauntApply
void ThreatManager::tauntApply(Unit* pTaunter)
{
HostilReference* ref = iThreatContainer.getReferenceByTarget(pTaunter);
if(getCurrentVictim() && ref && (ref->getThreat() < getCurrentVictim()->getThreat()))
{
if(ref->getTempThreatModifier() == 0.0f) // Ok, temp threat is unused
ref->setTempThreat(getCurrentVictim()->getThreat());
}
}
示例5: getFirst
void HostilRefManager::updateThreatTables()
{
HostilReference* ref = getFirst();
while(ref)
{
ref->updateOnlineStatus();
ref = ref->next();
}
}
示例6: selectNextVictim
HostilReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostilReference* pCurrentVictim)
{
HostilReference* currentRef = NULL;
bool found = false;
std::list<HostilReference*>::iterator lastRef = iThreatList.end();
lastRef--;
for(std::list<HostilReference*>::iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found; ++iter)
{
currentRef = (*iter);
Unit* target = currentRef->getTarget();
assert(target); // if the ref has status online the target must be there !
// some units are preferred in comparison to others
if(iter != lastRef && (target->IsImmunedToDamage(pAttacker->GetMeleeDamageSchoolMask(), false) ||
target->hasUnitState(UNIT_STAT_CONFUSED)
) )
{
// current victim is a second choice target, so don't compare threat with it below
if(currentRef == pCurrentVictim)
pCurrentVictim = NULL;
continue;
}
if(!pAttacker->IsOutOfThreatArea(target)) // skip non attackable currently targets
{
if(pCurrentVictim) // select 1.3/1.1 better target in comparison current target
{
// list sorted and and we check current target, then this is best case
if(pCurrentVictim == currentRef || currentRef->getThreat() <= 1.1f * pCurrentVictim->getThreat() )
{
currentRef = pCurrentVictim; // for second case
found = true;
break;
}
if( currentRef->getThreat() > 1.3f * pCurrentVictim->getThreat() ||
currentRef->getThreat() > 1.1f * pCurrentVictim->getThreat() && pAttacker->IsWithinMeleeRange(target) )
{ //implement 110% threat rule for targets in melee range
found = true; //and 130% rule for targets in ranged distances
break; //for selecting alive targets
}
}
else // select any
{
found = true;
break;
}
}
}
if(!found)
currentRef = NULL;
return currentRef;
}
示例7: getThreat
float ThreatManager::getThreat(Unit *pVictim, bool pAlsoSearchOfflineList)
{
float threat = 0.0f;
HostilReference* ref = iThreatContainer.getReferenceByTarget(pVictim);
if(!ref && pAlsoSearchOfflineList)
ref = iThreatOfflineContainer.getReferenceByTarget(pVictim);
if(ref)
threat = ref->getThreat();
return threat;
}
示例8: addThreatPercent
void HostilRefManager::addThreatPercent(int32 iPercent)
{
HostilReference* ref;
ref = getFirst();
while (ref != NULL)
{
ref->addThreatPercent(iPercent);
ref = ref->next();
}
}
示例9: setOnlineOfflineState
void HostilRefManager::setOnlineOfflineState(bool bIsOnline)
{
HostilReference* ref;
ref = getFirst();
while(ref != NULL)
{
ref->setOnlineOfflineState(bIsOnline);
ref = ref->next();
}
}
示例10: processThreatEvent
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;
}
示例11: threatAssist
void HostilRefManager::threatAssist(Unit *pVictim, float fThreat, SpellEntry const *pThreatSpell, bool pSingleTarget)
{
HostilReference* ref;
float size = pSingleTarget ? 1.0f : getSize(); // if pSingleTarget do not divide threat
ref = getFirst();
while(ref != NULL)
{
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, fThreat, (pThreatSpell ? GetSpellSchoolMask(pThreatSpell) : SPELL_SCHOOL_MASK_NORMAL), pThreatSpell);
if(pVictim == getOwner())
ref->addThreat(threat / size); // It is faster to modify the threat durectly if possible
else
ref->getSource()->addThreat(pVictim, threat / size);
ref = ref->next();
}
}
示例12: HostilReference
void ThreatManager::_addThreat(Unit *pVictim, float threat)
{
HostilReference* ref = iThreatContainer.addThreat(pVictim, threat);
// Ref is not in the online refs, search the offline refs next
if(!ref)
ref = iThreatOfflineContainer.addThreat(pVictim, threat);
if(!ref) // there was no ref => create a new one
{
// threat has to be 0 here
HostilReference* hostilReference = new HostilReference(pVictim, this, 0);
iThreatContainer.addReference(hostilReference);
hostilReference->addThreat(threat); // now we add the real threat
if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster())
hostilReference->setOnlineOfflineState(false); // GM is always offline
}
}
示例13: processThreatEvent
void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent)
{
threatRefStatusChangeEvent->setThreatManager(this); // now we can set the threat manager
HostilReference* 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;
}
}
示例14: threatAssist
void HostilRefManager::threatAssist(Unit *pVictim, float pThreat, SpellEntry const *pThreatSpell, bool pSingleTarget)
{
if (iOwner->hasUnitState(UNIT_STAT_IGNORE_ATTACKERS))
return;
HostilReference* ref;
uint32 size = pSingleTarget ? 1 : getSize(); // if pSingleTarget do not divide threat
ref = getFirst();
while (ref != NULL)
{
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, (pThreatSpell ? SpellMgr::GetSpellSchoolMask(pThreatSpell) : SPELL_SCHOOL_MASK_NORMAL), pThreatSpell);
if (pVictim == getOwner())
ref->addThreat(float (threat) / size); // It is faster to modify the threat directly if possible
else
ref->getSource()->addThreat(pVictim, float (threat) / size);
ref = ref->next();
}
}
示例15: selectNextVictim
HostilReference* ThreatContainer::selectNextVictim(Creature* pAttacker, HostilReference* pCurrentVictim)
{
HostilReference* currentRef = NULL;
bool found = false;
for(std::list<HostilReference*>::iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found; ++iter)
{
currentRef = (*iter);
Unit* target = currentRef->getTarget();
assert(target); // if the ref has status online the target must be there !
if(!pAttacker->IsOutOfThreatArea(target)) // skip non attackable currently targets
{
if(pCurrentVictim) // select 1.3/1.1 better target in comparison current target
{
// list sorted and and we check current target, then this is best case
if(pCurrentVictim == currentRef || currentRef->getThreat() <= 1.1f * pCurrentVictim->getThreat() )
{
currentRef = pCurrentVictim; // for second case
found = true;
break;
}
if( currentRef->getThreat() > 1.3f * pCurrentVictim->getThreat() ||
currentRef->getThreat() > 1.1f * pCurrentVictim->getThreat() && pAttacker->IsWithinDistInMap(target, ATTACK_DISTANCE) )
{ //implement 110% threat rule for targets in melee range
found = true; //and 130% rule for targets in ranged distances
break; //for selecting alive targets
}
}
else // select any
{
found = true;
break;
}
}
}
if(!found)
currentRef = NULL;
return currentRef;
}