void AddThreat(Unit victim, float threat) { var reff = threatContainer.AddThreat(victim, threat); // Ref is not in the online refs, search the offline refs next if (reff == null) { reff = threatOfflineContainer.AddThreat(victim, threat); } if (reff == null) // there was no ref => create a new one { bool isFirst = threatContainer.Empty(); // threat has to be 0 here var hostileRef = new HostileReference(victim, this, 0); threatContainer.AddReference(hostileRef); hostileRef.AddThreat(threat); // now we add the real threat if (victim.IsTypeId(TypeId.Player) && victim.ToPlayer().IsGameMaster()) { hostileRef.SetOnlineOfflineState(false); // GM is always offline } else if (isFirst) { SetCurrentVictim(hostileRef); } } }
public void SetCurrentVictim(HostileReference pHostileReference) { if (pHostileReference != null && pHostileReference != currentVictim) { Owner.SendChangeCurrentVictim(pHostileReference); } currentVictim = pHostileReference; }
public Unit GetHostilTarget() { threatContainer.Update(); HostileReference nextVictim = threatContainer.SelectNextVictim(GetOwner().ToCreature(), getCurrentVictim()); SetCurrentVictim(nextVictim); return(GetCurrentVictim() != null?GetCurrentVictim() : null); }
public void ModifyThreatByPercent(Unit victim, int percent) { HostileReference refe = GetReferenceByTarget(victim); if (refe != null) { refe.AddThreatPercent(percent); } }
void TauntFadeOut(Unit taunter) { HostileReference refe = threatContainer.GetReferenceByTarget(taunter); if (refe != null) { refe.ResetTempThreat(); } }
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; } }
void addThreatPercent(int percent) { HostileReference refe = getFirst(); while (refe != null) { refe.addThreatPercent(percent); refe = refe.next(); } }
public void updateThreatTables() { HostileReference refe = getFirst(); while (refe != null) { refe.updateOnlineStatus(); refe = refe.next(); } }
public void setOnlineOfflineState(bool isOnline) { HostileReference refe = getFirst(); while (refe != null) { refe.setOnlineOfflineState(isOnline); refe = refe.next(); } }
void AddThreatPercent(int percent) { HostileReference refe = GetFirst(); while (refe != null) { refe.AddThreatPercent(percent); refe = refe.Next(); } }
// The references are not needed anymore // tell the source to remove them from the list and free the mem public void deleteReferences() { HostileReference refe = getFirst(); while (refe != null) { HostileReference nextRef = refe.next(); refe.removeReference(); refe = nextRef; } }
// The references are not needed anymore // tell the source to remove them from the list and free the mem public void DeleteReferences() { HostileReference refe = GetFirst(); while (refe != null) { HostileReference nextRef = refe.Next(); refe.RemoveReference(); refe = nextRef; } }
void TauntApply(Unit taunter) { HostileReference refe = threatContainer.GetReferenceByTarget(taunter); if (GetCurrentVictim() != null && refe != null && (refe.GetThreat() < getCurrentVictim().GetThreat())) { if (refe.GetTempThreatModifier() == 0.0f) // Ok, temp threat is unused { refe.SetTempThreat(getCurrentVictim().GetThreat()); } } }
// Remove specific faction references public void deleteReferencesForFaction(uint faction) { HostileReference refe = getFirst(); while (refe != null) { HostileReference nextRef = refe.next(); if (refe.GetSource().GetOwner().GetFactionTemplateEntry().Faction == faction) { refe.removeReference(); } refe = nextRef; } }
// set state for one reference, defined by Unit public void setOnlineOfflineState(Unit creature, bool isOnline) { HostileReference refe = getFirst(); while (refe != null) { HostileReference nextRef = refe.next(); if (refe.GetSource().GetOwner() == creature) { refe.setOnlineOfflineState(isOnline); break; } refe = nextRef; } }
// delete one reference, defined by Unit public void deleteReference(Unit creature) { HostileReference refe = getFirst(); while (refe != null) { HostileReference nextRef = refe.next(); if (refe.GetSource().GetOwner() == creature) { refe.removeReference(); break; } refe = nextRef; } }
public void UpdateVisibility() { HostileReference refe = getFirst(); while (refe != null) { HostileReference nextRef = refe.next(); if (!refe.GetSource().GetOwner().CanSeeOrDetect(getOwner())) { nextRef = refe.next(); refe.removeReference(); } refe = nextRef; } }
public float GetThreat(Unit victim, bool alsoSearchOfflineList = false) { float threat = 0.0f; HostileReference refe = threatContainer.GetReferenceByTarget(victim); if (refe == null && alsoSearchOfflineList) { refe = threatOfflineContainer.GetReferenceByTarget(victim); } if (refe != null) { threat = refe.GetThreat(); } return(threat); }
// delete all references out of specified range public void deleteReferencesOutOfRange(float range) { HostileReference refe = getFirst(); range = range * range; while (refe != null) { HostileReference nextRef = refe.next(); Unit owner = refe.GetSource().GetOwner(); if (!owner.isActiveObject() && owner.GetExactDist2dSq(getOwner()) > range) { refe.removeReference(); } refe = nextRef; } }
// send threat to all my hateres for the victim // The victim is hated than by them as well // use for buffs and healing threat functionality public void threatAssist(Unit victim, float baseThreat, SpellInfo threatSpell = null) { HostileReference refe = getFirst(); float threat = ThreatManager.calcThreat(victim, Owner, baseThreat, (threatSpell != null ? threatSpell.GetSchoolMask() : SpellSchoolMask.Normal), threatSpell); threat /= getSize(); while (refe != null) { if (ThreatManager.isValidProcess(victim, refe.GetSource().GetOwner(), threatSpell)) { refe.GetSource().doAddThreat(victim, threat); } refe = refe.next(); } }
public void addTempThreat(float threat, bool apply) { HostileReference refe = getFirst(); while (refe != null) { if (apply) { if (refe.getTempThreatModifier() == 0.0f) { refe.addTempThreat(threat); } } else { refe.resetTempThreat(); } refe = refe.next(); } }
public void AddReference(HostileReference hostileRef) { threatList.Add(hostileRef); }
public ThreatRefStatusChangeEvent(UnitEventTypes pType, HostileReference pHostileReference, bool pValue) : base(pType) { iHostileReference = pHostileReference; iBValue = pValue; }
public HostileReference SelectNextVictim(Creature attacker, HostileReference currentVictim) { HostileReference currentRef = null; bool found = false; bool noPriorityTargetFound = false; for (var i = 0; i < threatList.Count; i++) { if (found) { break; } currentRef = threatList[i]; Unit target = currentRef.GetTarget(); Cypher.Assert(target); // if the ref has status online the target must be there ! // some units are prefered in comparison to others if (!noPriorityTargetFound && (target.IsImmunedToDamage(attacker.GetMeleeDamageSchoolMask()) || target.HasNegativeAuraWithInterruptFlag(SpellAuraInterruptFlags.TakeDamage))) { if (i != threatList.Count - 1) { // current victim is a second choice target, so don't compare threat with it below if (currentRef == currentVictim) { currentVictim = null; } continue; } else { // if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked. noPriorityTargetFound = true; i = 0; continue; } } if (attacker.CanCreatureAttack(target)) // skip non attackable currently targets { if (currentVictim != null) // 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 (currentVictim == currentRef || currentRef.GetThreat() <= 1.1f * currentVictim.GetThreat()) { if (currentVictim != currentRef && attacker.CanCreatureAttack(currentVictim.GetTarget())) { currentRef = currentVictim; // for second case, if currentvictim is attackable } found = true; break; } if (currentRef.GetThreat() > 1.3f * currentVictim.GetThreat() || (currentRef.GetThreat() > 1.1f * currentVictim.GetThreat() && attacker.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); }
public void Remove(HostileReference hostileRef) { threatList.Remove(hostileRef); }
ThreatManagerEvent(UnitEventTypes pType, HostileReference pHostileReference) : base(pType, pHostileReference) { iThreatContainer = null; }