-
Notifications
You must be signed in to change notification settings - Fork 293
/
ThreatManager.cpp
770 lines (659 loc) · 25 KB
/
ThreatManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
/*
* This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Combat/ThreatManager.h"
#include "Entities/Unit.h"
#include "Entities/Creature.h"
#include "AI/BaseAI/CreatureAI.h"
#include "Maps/Map.h"
#include "Entities/Player.h"
#include "Globals/ObjectAccessor.h"
#include "Entities/UnitEvents.h"
#include "Spells/SpellAuras.h"
//==============================================================
//================= ThreatCalcHelper ===========================
//==============================================================
// The pHatingUnit is not used yet
float ThreatCalcHelper::CalcThreat(Unit* hatedUnit, Unit* hatingUnit, float threat, bool crit, SpellSchoolMask schoolMask, SpellEntry const* threatSpell, bool assist)
{
// all flat mods applied early
if (!threat)
return 0.f;
if (hatedUnit->GetNoThreatState()) // some NPCs cause no threat
return 0.f;
if (hatingUnit->GetTypeId() == TYPEID_PLAYER) // players have entries with 0 threat during charm
return 0.f;
if (!assist && hatedUnit->IsSupportThreatOnly())
return 0.f;
if (threatSpell)
{
if (Player* modOwner = hatedUnit->GetSpellModOwner())
modOwner->ApplySpellMod(threatSpell->Id, SPELLMOD_THREAT, threat);
if (crit)
threat *= hatedUnit->GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRITICAL_THREAT, schoolMask);
}
threat = hatedUnit->ApplyTotalThreatModifier(threat, schoolMask);
return threat;
}
//============================================================
//================= HostileReference ==========================
//============================================================
HostileReference::HostileReference(Unit* unit, ThreatManager* threatManager, float threat) :
m_hostileState(STATE_NORMAL), m_tauntState(STATE_NONE)
{
iThreat = threat;
iFadeoutThreadReduction = 0.f;
link(unit, threatManager);
iUnitGuid = unit->GetObjectGuid();
m_online = true;
m_suppresabilityToggle = false;
iAccessible = true;
}
//============================================================
// Tell our refTo (target) object that we have a link
void HostileReference::targetObjectBuildLink()
{
getTarget()->addHatedBy(this);
}
//============================================================
// Tell our refTo (taget) object, that the link is cut
void HostileReference::targetObjectDestroyLink()
{
getTarget()->removeHatedBy(this);
}
//============================================================
// Tell our refFrom (source) object, that the link is cut (Target destroyed)
void HostileReference::sourceObjectDestroyLink()
{
setOnlineOfflineState(false);
}
//============================================================
// Inform the source, that the status of the reference changed
void HostileReference::fireStatusChanged(ThreatRefStatusChangeEvent& threatRefStatusChangeEvent)
{
if (getSource())
getSource()->processThreatEvent(threatRefStatusChangeEvent);
}
//============================================================
void HostileReference::addThreat(float mod)
{
if (mod + iThreat < 0)
mod = -iThreat;
iThreat += mod;
// If threat has changed, clear suppress
if (m_suppresabilityToggle && mod != 0.f)
SetHostileState(STATE_NORMAL);
if (mod != 0.0f)
{
ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, mod);
fireStatusChanged(event);
}
}
//============================================================
// check, if source can reach target and set the status
void HostileReference::updateOnlineStatus()
{
bool online = false;
if (!isValid())
{
if (Unit* target = ObjectAccessor::GetUnit(*getSourceUnit(), getUnitGuid()))
link(target, getSource());
}
// only check for online status if
// ref is valid
if (isValid())
{
Unit* unit = getSourceUnit();
Unit* target = getTarget();
if (!unit->IsOfflineTarget(target))
online = true;
}
setOnlineOfflineState(online);
}
//============================================================
// set the status and fire the event on status change
void HostileReference::setOnlineOfflineState(bool isOnline)
{
if (m_online != isOnline)
{
m_online = isOnline;
ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ONLINE_STATUS, this);
fireStatusChanged(event);
}
}
//============================================================
void HostileReference::setAccessibleState(bool isAccessible)
{
if (iAccessible != isAccessible)
{
iAccessible = isAccessible;
ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ASSECCIBLE_STATUS, this);
fireStatusChanged(event);
}
}
void HostileReference::SetHostileState(HostileState state)
{
if (m_hostileState != state)
{
m_hostileState = state;
ThreatRefStatusChangeEvent event(UEV_THREAT_REF_SUPPRESSED_STATUS, this);
fireStatusChanged(event);
}
m_suppresabilityToggle = false;
}
//============================================================
// prepare the reference for deleting
// this is called be the target
void HostileReference::removeReference()
{
invalidate();
ThreatRefStatusChangeEvent event(UEV_THREAT_REF_REMOVE_FROM_LIST, this);
fireStatusChanged(event);
}
//============================================================
Unit* HostileReference::getSourceUnit() const
{
return getSource()->getOwner();
}
//============================================================
//================ ThreatContainer ===========================
//============================================================
void ThreatContainer::clearReferences()
{
for (ThreatList::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
{
(*i)->unlink();
delete (*i);
}
iThreatList.clear();
}
//============================================================
// Return the HostileReference of nullptr, if not found
HostileReference* ThreatContainer::getReferenceByTarget(Unit* victim)
{
if (!victim)
return nullptr;
ObjectGuid guid = victim->GetObjectGuid();
for (ThreatList::const_iterator i = iThreatList.begin(); i != iThreatList.end(); ++i)
if ((*i)->getUnitGuid() == guid)
return (*i);
return nullptr;
}
//============================================================
// Add the threat, if we find the reference
HostileReference* ThreatContainer::addThreat(Unit* victim, float threat)
{
HostileReference* ref = getReferenceByTarget(victim);
if (ref)
ref->addThreat(threat);
return ref;
}
//============================================================
void ThreatContainer::modifyThreatPercent(Unit* victim, int32 threatPercent)
{
if (HostileReference* ref = getReferenceByTarget(victim))
{
if (threatPercent < -100)
{
ref->removeReference();
delete ref;
}
else
ref->addThreatPercent(threatPercent);
}
}
//============================================================
// Modify all threat by provided percentage
void ThreatContainer::modifyAllThreatPercent(int32 threatPercent)
{
if (threatPercent < -100)
{
while (!iThreatList.empty())
{
HostileReference* ref = *iThreatList.begin();
ref->removeReference();
delete ref;
}
}
else
{
for (auto itr : iThreatList)
itr->addThreatPercent(threatPercent);
}
}
//============================================================
// Check if the list is dirty and sort if necessary
void ThreatContainer::update(bool force, bool isPlayer)
{
if ((iDirty || force || isPlayer) && iThreatList.size() > 1)
{
iThreatList.sort([&](const HostileReference* lhs, const HostileReference* rhs)->bool
{
Unit* owner = lhs->getSource()->getOwner();
if (isPlayer)
{
Unit* left = lhs->getTarget();
Unit* right = rhs->getTarget();
if (left->IsPlayer() && !right->IsPlayer())
return true;
if (!left->IsPlayer() && right->IsPlayer())
return false;
bool attackLeft = owner->CanAttack(left);
bool attackRight = owner->CanAttack(right);
if (attackLeft && !attackRight)
return true;
if (!attackLeft && attackRight)
return false;
}
if (lhs->GetTauntState() != rhs->GetTauntState())
return lhs->GetTauntState() > rhs->GetTauntState();
if (force)
{
bool first = owner->CanReachWithMeleeAttack(lhs->getTarget());
bool second = owner->CanReachWithMeleeAttack(rhs->getTarget());
if (first != second)
return first > second;
}
if (lhs->GetHostileState() != rhs->GetHostileState())
return lhs->GetHostileState() > rhs->GetHostileState();
return lhs->getThreat() > rhs->getThreat(); // reverse sorting
});
}
iDirty = false;
}
//============================================================
// return the next best victim
// could be the current victim
HostileReference* ThreatContainer::selectNextVictim(Unit* attacker, HostileReference* currentVictim)
{
HostileReference* currentRef = nullptr;
bool found = false;
bool onlySecondChoiceTargetsFound = false;
bool checkedCurrentVictim = false;
bool suppressRanged = attacker->IsIgnoringRangedTargets();
bool currentVictimInMelee = true;
if (suppressRanged && currentVictim)
currentVictimInMelee = attacker->CanReachWithMeleeAttack(currentVictim->getTarget());
ThreatList::const_iterator lastRef = iThreatList.end();
--lastRef;
for (ThreatList::const_iterator iter = iThreatList.begin(); iter != iThreatList.end() && !found;)
{
currentRef = (*iter);
Unit* target = currentRef->getTarget();
MANGOS_ASSERT(target); // if the ref has status online the target must be there!
bool isInMelee = attacker->CanReachWithMeleeAttack(target);
if (currentVictim) // select 1.3/1.1 better target in comparison current target
{
// normal case: pCurrentRef is still valid and most hated
if (currentVictim == currentRef)
{
if (suppressRanged && !currentVictimInMelee)
{
++iter;
continue;
}
found = true;
break;
}
if (currentRef->GetTauntState() > currentVictim->GetTauntState()) // taunt overrides root skipping
{
found = true;
break;
}
if (currentRef->getTarget()->IsPlayer() && !currentVictim->getTarget()->IsPlayer())
{
found = true;
break;
}
if (suppressRanged) // suppress ranged when rooted
{
if (!isInMelee) // if current ref is not in melee - skip it
{
++iter;
continue;
}
else if (!currentVictimInMelee)
{
found = true;
break;
}
}
if (currentRef->GetHostileState() > currentVictim->GetHostileState())
{
found = true;
break;
}
// list sorted and and we check current target, then this is best case
if (currentRef->getThreat() <= 1.1f * currentVictim->getThreat())
{
currentRef = currentVictim;
found = true;
break;
}
if (currentRef->getThreat() > 1.3f * currentVictim->getThreat() ||
(currentRef->getThreat() > 1.1f * currentVictim->getThreat() && isInMelee))
{
// 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 if (!suppressRanged || isInMelee) // select any
{
found = true;
break;
}
++iter;
}
if (!found)
currentRef = nullptr;
return currentRef;
}
//============================================================
//=================== ThreatManager ==========================
//============================================================
ThreatManager::ThreatManager(Unit* owner)
: iCurrentVictim(nullptr), iOwner(owner), iUpdateTimer(THREAT_UPDATE_INTERVAL), iUpdateNeed(false)
{
}
//============================================================
void ThreatManager::clearReferences()
{
iThreatContainer.clearReferences();
iThreatOfflineContainer.clearReferences();
iCurrentVictim = nullptr;
iUpdateTimer.Reset(THREAT_UPDATE_INTERVAL);
iUpdateNeed = false;
}
//============================================================
void ThreatManager::addThreat(Unit* victim, float threat, bool crit, SpellSchoolMask schoolMask, SpellEntry const* threatSpell, bool assist)
{
// 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.)
// not to self
if (victim == getOwner())
return;
// not to GM
if (!victim || (victim->GetTypeId() == TYPEID_PLAYER && static_cast<Player*>(victim)->IsGameMaster()))
return;
// not to dead and not for dead
if (!victim->IsAlive() || !getOwner()->IsAlive())
return;
float calculatedThreat = ThreatCalcHelper::CalcThreat(victim, iOwner, threat, crit, schoolMask, threatSpell, assist);
if (calculatedThreat > 0.0f)
{
float totalMod = 0.f;
auto& redirectionData = victim->getHostileRefManager().GetThreatRedirectionData();
for (auto& redirection : redirectionData)
{
float redirectedMod = redirection.second.mod;
Unit* redirectedTarget = iOwner->GetMap()->GetUnit(redirection.second.target);
if (!redirectedTarget)
continue;
if (redirectedTarget != getOwner() && redirectedTarget->IsAlive())
{
float redirectedThreat = threat * redirectedMod;
totalMod += redirectedMod;
addThreatDirectly(redirectedTarget, redirectedThreat, false);
}
}
if (totalMod != 0.f)
{
totalMod = std::min(totalMod, 100.f);
calculatedThreat = (calculatedThreat * (100 - totalMod)) / 100;
}
}
addThreatDirectly(victim, calculatedThreat, threatSpell && threatSpell->HasAttribute(SPELL_ATTR_EX_NO_THREAT));
}
void ThreatManager::addThreatDirectly(Unit* victim, float threat, bool noNew)
{
HostileReference* ref = iThreatContainer.addThreat(victim, threat);
// Ref is online
if (ref)
iUpdateNeed = true;
// Ref is not in the online refs, search the offline refs next
else
ref = iThreatOfflineContainer.addThreat(victim, threat);
if (!ref && !noNew) // there was no ref => create a new one
{
HostileReference* hostileReference = new HostileReference(victim, this, 0); // threat has to be 0 here
iThreatContainer.addReference(hostileReference);
hostileReference->addThreat(threat); // now we add the real threat
iUpdateNeed = true;
Unit* owner = getOwner();
owner->TriggerAggroLinkingEvent(victim);
Unit* victim_owner = victim->GetMaster();
if (victim->IsPropagatingThreatToOwner() && victim_owner && victim_owner->IsAlive() && victim_owner->CanJoinInAttacking(getOwner()))
addThreat(victim_owner, 0.0f); // create a threat to the owner of a pet, if the pet attacks
if (owner->IsOfflineTarget(victim) || victim->IsPlayer() && static_cast<Player*>(victim)->IsGameMaster())
hostileReference->setOnlineOfflineState(false); // GM is always offline
}
}
//============================================================
void ThreatManager::modifyThreatPercent(Unit* victim, int32 threatPercent)
{
iThreatContainer.modifyThreatPercent(victim, threatPercent);
iUpdateNeed = true;
}
void ThreatManager::modifyAllThreatPercent(int32 threatPercent)
{
iThreatContainer.modifyAllThreatPercent(threatPercent);
iUpdateNeed = true;
}
//============================================================
void ThreatManager::UpdateContainers()
{
iThreatContainer.update(getOwner()->IsIgnoringRangedTargets(), getOwner()->IsPlayer());
}
Unit* ThreatManager::getHostileTarget()
{
UpdateContainers();
HostileReference* nextVictim = iThreatContainer.selectNextVictim(getOwner(), getCurrentVictim());
setCurrentVictim(nextVictim);
return getCurrentVictim() != nullptr ? getCurrentVictim()->getTarget() : nullptr;
}
//============================================================
float ThreatManager::getThreat(Unit* victim, bool alsoSearchOfflineList)
{
float threat = 0.0f;
HostileReference* ref = iThreatContainer.getReferenceByTarget(victim);
if (!ref && alsoSearchOfflineList)
ref = iThreatOfflineContainer.getReferenceByTarget(victim);
if (ref)
threat = ref->getThreat();
else if (alsoSearchOfflineList)
threat = iThreatOfflineContainer.getReferenceByTarget(victim)->getThreat();
return threat;
}
float ThreatManager::GetHighestThreat()
{
float value = 0.f;
for (auto& ref : iThreatContainer.getThreatList())
if (ref->getThreat() > value)
value = ref->getThreat();
for (auto& ref : iThreatOfflineContainer.getThreatList())
if (ref->getThreat() > value)
value = ref->getThreat();
return value;
}
bool ThreatManager::HasThreat(Unit * victim, bool alsoSearchOfflineList)
{
HostileReference* ref = iThreatContainer.getReferenceByTarget(victim);
if (!ref && alsoSearchOfflineList)
ref = iThreatOfflineContainer.getReferenceByTarget(victim);
return ref != nullptr;
}
//============================================================
void ThreatManager::TauntUpdate()
{
const Unit::AuraList& tauntAuras = iOwner->GetAurasByType(SPELL_AURA_MOD_TAUNT);
std::unordered_map<ObjectGuid, TauntState> tauntStates;
uint32 state = STATE_TAUNTED;
for (auto tauntAura : tauntAuras)
tauntStates[tauntAura->GetCasterGuid()] = TauntState(state++);
for (auto& ref : iThreatContainer.getThreatList())
{
if (ref->GetTauntState() == STATE_FIXATED)
continue;
auto iter = tauntStates.find(ref->getTarget()->GetObjectGuid());
if (iter != tauntStates.end())
ref->SetTauntState((*iter).second);
else if (ref->getTarget()->HasAuraTypeWithCaster(SPELL_AURA_DETAUNT, ref->getSource()->getOwner()->GetObjectGuid()))
ref->SetTauntState(STATE_DETAUNTED);
else
ref->SetTauntState(STATE_NONE);
}
setDirty(true);
}
void ThreatManager::FixateTarget(Unit* victim)
{
HostileReference* fixateRef = iThreatContainer.getReferenceByTarget(victim);
if (fixateRef)
fixateRef->SetTauntState(STATE_FIXATED);
for (auto& ref : iThreatContainer.getThreatList())
if (ref != fixateRef && ref->GetTauntState() == STATE_FIXATED)
ref->SetTauntState(STATE_NONE);
TauntUpdate();
}
void ThreatManager::setCurrentVictim(HostileReference* hostileReference)
{
// including nullptr==nullptr case
if (hostileReference == iCurrentVictim)
return;
if (hostileReference)
iOwner->SendHighestThreatUpdate(hostileReference);
iCurrentVictim = hostileReference;
iUpdateNeed = true;
}
void ThreatManager::setCurrentVictimByTarget(Unit* target)
{
if (iCurrentVictim && target == iCurrentVictim->getTarget())
return;
if (HostileReference* ref = iThreatContainer.getReferenceByTarget(target))
setCurrentVictim(ref);
}
//============================================================
// The hated unit is gone, dead or deleted
// return true, if the event is consumed
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(nullptr);
setDirty(true);
}
iOwner->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(nullptr);
setDirty(true);
}
if (hostileReference->isOnline())
{
iOwner->SendThreatRemove(hostileReference);
iThreatContainer.remove(hostileReference);
iUpdateNeed = true;
}
else
iThreatOfflineContainer.remove(hostileReference);
break;
case UEV_THREAT_REF_SUPPRESSED_STATUS:
// Clear suppressed on suppress change
ClearSuppressed(hostileReference);
setDirty(true);
break;
}
}
void ThreatManager::UpdateForClient(uint32 diff)
{
if (!iUpdateNeed || isThreatListEmpty())
return;
iUpdateTimer.Update(diff);
if (iUpdateTimer.Passed())
{
iOwner->SendThreatUpdate();
iUpdateTimer.Reset(THREAT_UPDATE_INTERVAL);
iUpdateNeed = false;
}
}
void ThreatManager::ClearSuppressed(HostileReference* except)
{
for (HostileReference* const curRef : iThreatContainer.getThreatList())
if (curRef->GetHostileState() == STATE_SUPPRESSED && curRef != except && !getOwner()->IsSuppressedTarget(curRef->getTarget()))
curRef->SetHostileState(STATE_NORMAL);
}
void ThreatManager::DeleteOutOfRangeReferences()
{
std::vector<HostileReference*> m_refs;
for (auto& ref : iThreatContainer.getThreatList())
if (ref->isValid() && ref->getTarget()->GetDistance(getOwner(), true, DIST_CALC_COMBAT_REACH) > 60.f)
m_refs.push_back(ref);
for (auto& ref : iThreatOfflineContainer.getThreatList())
if (ref->isValid() && ref->getTarget()->GetDistance(getOwner(), true, DIST_CALC_COMBAT_REACH) > 60.f)
m_refs.push_back(ref);
for (auto& ref : m_refs)
{
ref->removeReference();
delete ref;
}
}
void ThreatManager::SetTargetSuppressed(Unit* target)
{
if (HostileReference* ref = iThreatContainer.getReferenceByTarget(target))
{
ref->SetHostileState(STATE_SUPPRESSED);
ref->SetSuppressabilityToggle();
}
}
void HostileReference::setFadeoutThreatReduction(float value)
{
iFadeoutThreadReduction = value;
addThreat(iFadeoutThreadReduction);
}
void HostileReference::resetFadeoutThreatReduction()
{
addThreat(-iFadeoutThreadReduction);
iFadeoutThreadReduction = 0.f;
}