Ported .Net Core commits:
hondacrx: - Initial commit: Switch to .Net Core 2.0 - Fix build and removed not needed files Fabi: - Updated solution platforms. - Changed folder structure. - Change library target framework to netstandard2.0. - Updated solution platforms again... - Removed windows specific kernel32 function usage (Ctrl-C handler).
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Game.Combat
|
||||
{
|
||||
public class UnitBaseEvent
|
||||
{
|
||||
public UnitBaseEvent(UnitEventTypes pType)
|
||||
{
|
||||
iType = pType;
|
||||
}
|
||||
public UnitEventTypes getType()
|
||||
{
|
||||
return iType;
|
||||
}
|
||||
bool matchesTypeMask(uint pMask)
|
||||
{
|
||||
return Convert.ToBoolean((uint)iType & pMask);
|
||||
}
|
||||
|
||||
void setType(UnitEventTypes pType)
|
||||
{
|
||||
iType = pType;
|
||||
}
|
||||
|
||||
UnitEventTypes iType;
|
||||
}
|
||||
|
||||
public class ThreatRefStatusChangeEvent : UnitBaseEvent
|
||||
{
|
||||
public ThreatRefStatusChangeEvent(UnitEventTypes pType)
|
||||
: base(pType)
|
||||
{
|
||||
iHostileReference = null;
|
||||
}
|
||||
public ThreatRefStatusChangeEvent(UnitEventTypes pType, HostileReference pHostileReference)
|
||||
: base(pType)
|
||||
{
|
||||
iHostileReference = pHostileReference;
|
||||
}
|
||||
public ThreatRefStatusChangeEvent(UnitEventTypes pType, HostileReference pHostileReference, float pValue)
|
||||
: base(pType)
|
||||
{
|
||||
iHostileReference = pHostileReference;
|
||||
iFValue = pValue;
|
||||
}
|
||||
public ThreatRefStatusChangeEvent(UnitEventTypes pType, HostileReference pHostileReference, bool pValue)
|
||||
: base(pType)
|
||||
{
|
||||
iHostileReference = pHostileReference;
|
||||
iBValue = pValue;
|
||||
}
|
||||
|
||||
public float getFValue()
|
||||
{
|
||||
return iFValue;
|
||||
}
|
||||
|
||||
bool getBValue()
|
||||
{
|
||||
return iBValue;
|
||||
}
|
||||
|
||||
void setBValue(bool pValue)
|
||||
{
|
||||
iBValue = pValue;
|
||||
}
|
||||
|
||||
public HostileReference getReference()
|
||||
{
|
||||
return iHostileReference;
|
||||
}
|
||||
|
||||
public void setThreatManager(ThreatManager pThreatManager)
|
||||
{
|
||||
iThreatManager = pThreatManager;
|
||||
}
|
||||
|
||||
ThreatManager getThreatManager()
|
||||
{
|
||||
return iThreatManager;
|
||||
}
|
||||
|
||||
float iFValue;
|
||||
bool iBValue;
|
||||
HostileReference iHostileReference;
|
||||
ThreatManager iThreatManager;
|
||||
}
|
||||
|
||||
public enum UnitEventTypes
|
||||
{
|
||||
// Player/Pet Changed On/Offline Status
|
||||
ThreatRefOnlineStatus = 1 << 0,
|
||||
|
||||
// Threat For Player/Pet Changed
|
||||
ThreatRefThreatChange = 1 << 1,
|
||||
|
||||
// Player/Pet Will Be Removed From List (Dead) [For Internal Use]
|
||||
ThreatRefRemoveFromList = 1 << 2,
|
||||
|
||||
// Player/Pet Entered/Left Water Or Some Other Place Where It Is/Was Not Accessible For The Creature
|
||||
ThreatRefAccessibleStatus = 1 << 3,
|
||||
|
||||
// Threat List Is Going To Be Sorted (If Dirty Flag Is Set)
|
||||
ThreatSortList = 1 << 4,
|
||||
|
||||
// New Target Should Be Fetched, Could Tbe The Current Target As Well
|
||||
ThreatSetNextTarget = 1 << 5,
|
||||
|
||||
// A New Victim (Target) Was Set. Could Be Null
|
||||
ThreatVictimChanged = 1 << 6
|
||||
|
||||
// Future Use
|
||||
//Unit_Killed = 1<<7,
|
||||
|
||||
//Future Use
|
||||
//Unit_Health_Change = 1<<8,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Dynamic;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
|
||||
namespace Game.Combat
|
||||
{
|
||||
public class HostileRefManager : RefManager<Unit, ThreatManager>
|
||||
{
|
||||
Unit Owner;
|
||||
|
||||
public HostileRefManager(Unit owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
Unit getOwner() { return Owner; }
|
||||
|
||||
// send threat to all my haters for the victim
|
||||
// The victim is then hated by them as well
|
||||
// use for buffs and healing threat functionality
|
||||
public void threatAssist(Unit victim, float baseThreat, SpellInfo threatSpell = null)
|
||||
{
|
||||
float threat = ThreatManager.calcThreat(victim, Owner, baseThreat, (threatSpell != null ? threatSpell.GetSchoolMask() : SpellSchoolMask.Normal), threatSpell);
|
||||
threat /= getSize();
|
||||
|
||||
HostileReference refe = getFirst();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
public new HostileReference getFirst() { return ((HostileReference)base.getFirst()); }
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// 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 class HostileReference : Reference<Unit, ThreatManager>
|
||||
{
|
||||
public HostileReference(Unit refUnit, ThreatManager threatManager, float threat)
|
||||
{
|
||||
iThreat = threat;
|
||||
iTempThreatModifier = 0.0f;
|
||||
link(refUnit, threatManager);
|
||||
iUnitGuid = refUnit.GetGUID();
|
||||
iOnline = true;
|
||||
iAccessible = true;
|
||||
}
|
||||
|
||||
public override void targetObjectBuildLink()
|
||||
{
|
||||
getTarget().addHatedBy(this);
|
||||
}
|
||||
public override void targetObjectDestroyLink()
|
||||
{
|
||||
getTarget().removeHatedBy(this);
|
||||
}
|
||||
public override void sourceObjectDestroyLink()
|
||||
{
|
||||
setOnlineOfflineState(false);
|
||||
}
|
||||
|
||||
void fireStatusChanged(ThreatRefStatusChangeEvent threatRefStatusChangeEvent)
|
||||
{
|
||||
if (GetSource() != null)
|
||||
GetSource().processThreatEvent(threatRefStatusChangeEvent);
|
||||
}
|
||||
|
||||
public void addThreat(float modThreat)
|
||||
{
|
||||
if (modThreat == 0.0f)
|
||||
return;
|
||||
|
||||
iThreat += modThreat;
|
||||
|
||||
// the threat is changed. Source and target unit have to be available
|
||||
// if the link was cut before relink it again
|
||||
if (!isOnline())
|
||||
updateOnlineStatus();
|
||||
|
||||
ThreatRefStatusChangeEvent Event = new ThreatRefStatusChangeEvent(UnitEventTypes.ThreatRefThreatChange, this, modThreat);
|
||||
fireStatusChanged(Event);
|
||||
|
||||
if (isValid() && modThreat > 0.0f)
|
||||
{
|
||||
Unit victimOwner = getTarget().GetCharmerOrOwner();
|
||||
if (victimOwner != null && victimOwner.IsAlive())
|
||||
GetSource().addThreat(victimOwner, 0.0f); // create a threat to the owner of a pet, if the pet attacks
|
||||
}
|
||||
}
|
||||
|
||||
public void addThreatPercent(int percent)
|
||||
{
|
||||
addThreat(MathFunctions.CalculatePct(iThreat, percent));
|
||||
}
|
||||
|
||||
// check, if source can reach target and set the status
|
||||
public void updateOnlineStatus()
|
||||
{
|
||||
bool online = false;
|
||||
bool accessible = false;
|
||||
|
||||
if (!isValid())
|
||||
{
|
||||
Unit target = Global.ObjAccessor.GetUnit(getSourceUnit(), getUnitGuid());
|
||||
if (target != null)
|
||||
link(target, GetSource());
|
||||
}
|
||||
|
||||
// only check for online status if
|
||||
// ref is valid
|
||||
// target is no player or not gamemaster
|
||||
// target is not in flight
|
||||
if (isValid()
|
||||
&& (getTarget().IsTypeId(TypeId.Player) || !getTarget().ToPlayer().IsGameMaster())
|
||||
&& !getTarget().HasUnitState(UnitState.InFlight)
|
||||
&& getTarget().IsInMap(getSourceUnit())
|
||||
&& getTarget().IsInPhase(getSourceUnit())
|
||||
)
|
||||
{
|
||||
Creature creature = getSourceUnit().ToCreature();
|
||||
online = getTarget().isInAccessiblePlaceFor(creature);
|
||||
if (!online)
|
||||
{
|
||||
if (creature.IsWithinCombatRange(getTarget(), creature.m_CombatDistance))
|
||||
online = true; // not accessible but stays online
|
||||
}
|
||||
else
|
||||
accessible = true;
|
||||
}
|
||||
setAccessibleState(accessible);
|
||||
setOnlineOfflineState(online);
|
||||
}
|
||||
|
||||
public void setOnlineOfflineState(bool isOnline)
|
||||
{
|
||||
if (iOnline != isOnline)
|
||||
{
|
||||
iOnline = isOnline;
|
||||
if (!iOnline)
|
||||
setAccessibleState(false); // if not online that not accessable as well
|
||||
|
||||
ThreatRefStatusChangeEvent Event = new ThreatRefStatusChangeEvent(UnitEventTypes.ThreatRefOnlineStatus, this);
|
||||
fireStatusChanged(Event);
|
||||
}
|
||||
}
|
||||
|
||||
void setAccessibleState(bool isAccessible)
|
||||
{
|
||||
if (iAccessible != isAccessible)
|
||||
{
|
||||
iAccessible = isAccessible;
|
||||
|
||||
ThreatRefStatusChangeEvent Event = new ThreatRefStatusChangeEvent(UnitEventTypes.ThreatRefAccessibleStatus, this);
|
||||
fireStatusChanged(Event);
|
||||
}
|
||||
}
|
||||
|
||||
// reference is not needed anymore. realy delete it !
|
||||
public void removeReference()
|
||||
{
|
||||
invalidate();
|
||||
|
||||
ThreatRefStatusChangeEvent Event = new ThreatRefStatusChangeEvent(UnitEventTypes.ThreatRefRemoveFromList, this);
|
||||
fireStatusChanged(Event);
|
||||
}
|
||||
|
||||
Unit getSourceUnit()
|
||||
{
|
||||
return GetSource().GetOwner();
|
||||
}
|
||||
|
||||
public void setThreat(float threat)
|
||||
{
|
||||
addThreat(threat - iThreat);
|
||||
}
|
||||
|
||||
public float getThreat()
|
||||
{
|
||||
return iThreat + iTempThreatModifier;
|
||||
}
|
||||
|
||||
public bool isOnline()
|
||||
{
|
||||
return iOnline;
|
||||
}
|
||||
|
||||
// The Unit might be in water and the creature can not enter the water, but has range attack
|
||||
// in this case online = true, but accessible = false
|
||||
bool isAccessible()
|
||||
{
|
||||
return iAccessible;
|
||||
}
|
||||
|
||||
// used for temporary setting a threat and reducing it later again.
|
||||
// the threat modification is stored
|
||||
public void setTempThreat(float threat)
|
||||
{
|
||||
addTempThreat(threat - iTempThreatModifier);
|
||||
}
|
||||
|
||||
public void addTempThreat(float threat)
|
||||
{
|
||||
if (threat == 0.0f)
|
||||
return;
|
||||
|
||||
iTempThreatModifier += threat;
|
||||
|
||||
ThreatRefStatusChangeEvent Event = new ThreatRefStatusChangeEvent(UnitEventTypes.ThreatRefThreatChange, this, threat);
|
||||
fireStatusChanged(Event);
|
||||
}
|
||||
|
||||
public void resetTempThreat()
|
||||
{
|
||||
addTempThreat(-iTempThreatModifier);
|
||||
}
|
||||
|
||||
public float getTempThreatModifier()
|
||||
{
|
||||
return iTempThreatModifier;
|
||||
}
|
||||
|
||||
public ObjectGuid getUnitGuid()
|
||||
{
|
||||
return iUnitGuid;
|
||||
}
|
||||
|
||||
public new HostileReference next() { return (HostileReference)base.next(); }
|
||||
|
||||
float iThreat;
|
||||
float iTempThreatModifier; // used for SPELL_AURA_MOD_TOTAL_THREAT
|
||||
ObjectGuid iUnitGuid;
|
||||
bool iOnline;
|
||||
bool iAccessible;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Combat
|
||||
{
|
||||
public class ThreatManager
|
||||
{
|
||||
public ThreatManager(Unit owner)
|
||||
{
|
||||
currentVictim = null;
|
||||
Owner = owner;
|
||||
updateTimer = ThreatUpdateInternal;
|
||||
threatContainer = new ThreatContainer();
|
||||
threatOfflineContainer = new ThreatContainer();
|
||||
}
|
||||
|
||||
const int ThreatUpdateInternal = 1 * Time.InMilliseconds;
|
||||
|
||||
public void clearReferences()
|
||||
{
|
||||
threatContainer.clearReferences();
|
||||
threatOfflineContainer.clearReferences();
|
||||
currentVictim = null;
|
||||
updateTimer = ThreatUpdateInternal;
|
||||
}
|
||||
|
||||
public void addThreat(Unit victim, float threat, SpellSchoolMask schoolMask = SpellSchoolMask.Normal, SpellInfo threatSpell = null)
|
||||
{
|
||||
if (!isValidProcess(victim, Owner, threatSpell))
|
||||
return;
|
||||
|
||||
doAddThreat(victim, calcThreat(victim, Owner, threat, schoolMask, threatSpell));
|
||||
}
|
||||
|
||||
public void doAddThreat(Unit victim, float threat)
|
||||
{
|
||||
uint redirectThreadPct = victim.GetRedirectThreatPercent();
|
||||
|
||||
// must check > 0.0f, otherwise dead loop
|
||||
if (threat > 0.0f && redirectThreadPct != 0)
|
||||
{
|
||||
Unit redirectTarget = victim.GetRedirectThreatTarget();
|
||||
if (redirectTarget != null)
|
||||
{
|
||||
float redirectThreat = MathFunctions.CalculatePct(threat, redirectThreadPct);
|
||||
threat -= redirectThreat;
|
||||
_addThreat(redirectTarget, redirectThreat);
|
||||
}
|
||||
}
|
||||
|
||||
_addThreat(victim, threat);
|
||||
}
|
||||
|
||||
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 modifyThreatPercent(Unit victim, int percent)
|
||||
{
|
||||
threatContainer.modifyThreatPercent(victim, percent);
|
||||
}
|
||||
|
||||
public Unit getHostilTarget()
|
||||
{
|
||||
threatContainer.update();
|
||||
HostileReference nextVictim = threatContainer.selectNextVictim(GetOwner().ToCreature(), getCurrentVictim());
|
||||
setCurrentVictim(nextVictim);
|
||||
return getCurrentVictim() != null ? getCurrentVictim().getTarget() : null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
void tauntFadeOut(Unit taunter)
|
||||
{
|
||||
HostileReference refe = threatContainer.getReferenceByTarget(taunter);
|
||||
if (refe != null)
|
||||
refe.resetTempThreat();
|
||||
}
|
||||
|
||||
public void setCurrentVictim(HostileReference pHostileReference)
|
||||
{
|
||||
if (pHostileReference != null && pHostileReference != currentVictim)
|
||||
{
|
||||
Owner.SendChangeCurrentVictim(pHostileReference);
|
||||
}
|
||||
currentVictim = pHostileReference;
|
||||
}
|
||||
|
||||
public void processThreatEvent(ThreatRefStatusChangeEvent threatRefStatusChangeEvent)
|
||||
{
|
||||
threatRefStatusChangeEvent.setThreatManager(this); // now we can set the threat manager
|
||||
|
||||
HostileReference hostilRef = threatRefStatusChangeEvent.getReference();
|
||||
|
||||
switch (threatRefStatusChangeEvent.getType())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool isNeedUpdateToClient(uint time)
|
||||
{
|
||||
if (isThreatListEmpty())
|
||||
return false;
|
||||
|
||||
if (time >= updateTimer)
|
||||
{
|
||||
updateTimer = ThreatUpdateInternal;
|
||||
return true;
|
||||
}
|
||||
updateTimer -= time;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reset all aggro without modifying the threatlist.
|
||||
void resetAllAggro()
|
||||
{
|
||||
var threatList = threatContainer.threatList;
|
||||
if (threatList.Empty())
|
||||
return;
|
||||
|
||||
foreach (var refe in threatList)
|
||||
refe.setThreat(0);
|
||||
|
||||
setDirty(true);
|
||||
}
|
||||
public bool isThreatListEmpty()
|
||||
{
|
||||
return threatContainer.empty();
|
||||
}
|
||||
|
||||
public HostileReference getCurrentVictim()
|
||||
{
|
||||
return currentVictim;
|
||||
}
|
||||
|
||||
public Unit GetOwner()
|
||||
{
|
||||
return Owner;
|
||||
}
|
||||
|
||||
void setDirty(bool isDirty)
|
||||
{
|
||||
threatContainer.setDirty(isDirty);
|
||||
}
|
||||
|
||||
public List<HostileReference> getThreatList() { return threatContainer.getThreatList(); }
|
||||
public List<HostileReference> getOfflineThreatList() { return threatOfflineContainer.getThreatList(); }
|
||||
public ThreatContainer getOnlineContainer() { return threatContainer; }
|
||||
|
||||
// The hatingUnit is not used yet
|
||||
public static float calcThreat(Unit hatedUnit, Unit hatingUnit, float threat, SpellSchoolMask schoolMask = SpellSchoolMask.Normal, SpellInfo threatSpell = null)
|
||||
{
|
||||
if (threatSpell != null)
|
||||
{
|
||||
var threatEntry = Global.SpellMgr.GetSpellThreatEntry(threatSpell.Id);
|
||||
if (threatEntry != null)
|
||||
if (threatEntry.pctMod != 1.0f)
|
||||
threat *= threatEntry.pctMod;
|
||||
|
||||
// Energize is not affected by Mods
|
||||
foreach (SpellEffectInfo effect in threatSpell.GetEffectsForDifficulty(hatedUnit.GetMap().GetDifficultyID()))
|
||||
if (effect != null && (effect.Effect == SpellEffectName.Energize || effect.ApplyAuraName == AuraType.PeriodicEnergize))
|
||||
return threat;
|
||||
|
||||
Player modOwner = hatedUnit.GetSpellModOwner();
|
||||
if (modOwner != null)
|
||||
modOwner.ApplySpellMod(threatSpell.Id, SpellModOp.Threat, ref threat);
|
||||
}
|
||||
|
||||
return hatedUnit.ApplyTotalThreatModifier(threat, schoolMask);
|
||||
}
|
||||
|
||||
public static bool isValidProcess(Unit hatedUnit, Unit hatingUnit, SpellInfo threatSpell)
|
||||
{
|
||||
//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 (hatedUnit == null || hatingUnit == null)
|
||||
return false;
|
||||
|
||||
// not to self
|
||||
if (hatedUnit == hatingUnit)
|
||||
return false;
|
||||
|
||||
// not to GM
|
||||
if (hatedUnit.IsTypeId(TypeId.Player) && hatedUnit.ToPlayer().IsGameMaster())
|
||||
return false;
|
||||
|
||||
// not to dead and not for dead
|
||||
if (!hatedUnit.IsAlive() || !hatingUnit.IsAlive())
|
||||
return false;
|
||||
|
||||
// not in same map or phase
|
||||
if (!hatedUnit.IsInMap(hatingUnit) || !hatedUnit.IsInPhase(hatingUnit))
|
||||
return false;
|
||||
|
||||
// spell not causing threat
|
||||
if (threatSpell != null && threatSpell.HasAttribute(SpellAttr1.NoThreat))
|
||||
return false;
|
||||
|
||||
Contract.Assert(hatingUnit.IsTypeId(TypeId.Unit));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Unit Owner;
|
||||
HostileReference currentVictim;
|
||||
uint updateTimer;
|
||||
ThreatContainer threatContainer;
|
||||
ThreatContainer threatOfflineContainer;
|
||||
}
|
||||
|
||||
public class ThreatContainer
|
||||
{
|
||||
public ThreatContainer()
|
||||
{
|
||||
threatList = new List<HostileReference>();
|
||||
iDirty = false;
|
||||
}
|
||||
|
||||
public void clearReferences()
|
||||
{
|
||||
foreach (var reff in threatList)
|
||||
{
|
||||
reff.unlink();
|
||||
}
|
||||
|
||||
threatList.Clear();
|
||||
}
|
||||
|
||||
public HostileReference getReferenceByTarget(Unit victim)
|
||||
{
|
||||
if (victim == null)
|
||||
return null;
|
||||
|
||||
ObjectGuid guid = victim.GetGUID();
|
||||
foreach (var reff in threatList)
|
||||
{
|
||||
if (reff != null && reff.getUnitGuid() == guid)
|
||||
return reff;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public HostileReference addThreat(Unit victim, float threat)
|
||||
{
|
||||
var reff = getReferenceByTarget(victim);
|
||||
if (reff != null)
|
||||
reff.addThreat(threat);
|
||||
return reff;
|
||||
}
|
||||
|
||||
public void modifyThreatPercent(Unit victim, int percent)
|
||||
{
|
||||
HostileReference refe = getReferenceByTarget(victim);
|
||||
if (refe != null)
|
||||
refe.addThreatPercent(percent);
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
if (iDirty && threatList.Count > 1)
|
||||
threatList = threatList.OrderByDescending(p => p.getThreat()).ToList();
|
||||
|
||||
iDirty = false;
|
||||
}
|
||||
|
||||
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();
|
||||
Contract.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((uint)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 setDirty(bool isDirty)
|
||||
{
|
||||
iDirty = isDirty;
|
||||
}
|
||||
|
||||
bool isDirty()
|
||||
{
|
||||
return iDirty;
|
||||
}
|
||||
|
||||
public bool empty()
|
||||
{
|
||||
return threatList.Empty();
|
||||
}
|
||||
public HostileReference getMostHated()
|
||||
{
|
||||
return threatList.Count() == 0 ? null : threatList[0];
|
||||
}
|
||||
|
||||
public void remove(HostileReference hostileRef)
|
||||
{
|
||||
threatList.Remove(hostileRef);
|
||||
}
|
||||
public void addReference(HostileReference hostileRef)
|
||||
{
|
||||
threatList.Add(hostileRef);
|
||||
}
|
||||
|
||||
public List<HostileReference> getThreatList() { return threatList; }
|
||||
|
||||
public List<HostileReference> threatList { get; set; }
|
||||
bool iDirty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user