Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 44 additions & 25 deletions Intersect.Server.Core/Entities/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@
}

//Targeting
public void AssignTarget(Entity? en)
public void AssignTarget(Entity? entity)
{
var oldTarget = Target;

// Are we resetting? If so, do not allow for a new target.
var pathTarget = mPathFinder?.GetTarget();
if (AggroCenterMap != null && pathTarget != null &&
Expand All @@ -203,54 +201,55 @@
return;
}

var oldTarget = Target;

//Why are we doing all of this logic if we are assigning a target that we already have?
if (en != null && en != Target)
if (entity != null && entity != Target)
{
// Can't assign a new target if taunted, unless we're resetting their target somehow.
// Also make sure the taunter is in range.. If they're dead or gone, we go for someone else!
if ((pathTarget != null && AggroCenterMap != null && (pathTarget.TargetMapId != AggroCenterMap.Id || pathTarget.TargetX != AggroCenterX || pathTarget.TargetY != AggroCenterY)))
{
foreach (var status in CachedStatuses)
{
if (status.Type == SpellEffect.Taunt && en != status.Attacker && GetDistanceTo(status.Attacker) != 9999)
if (status.Type == SpellEffect.Taunt && entity != status.Attacker && GetDistanceTo(status.Attacker) != 9999)
{
return;
}
}
}

if (en is Projectile projectile)
if (entity is Projectile projectile)
{
if (projectile.Owner != this && !projectile.HasStatusEffect(SpellEffect.Stealth))
{
Target = projectile.Owner;
}
}
else
else if (entity is Npc npc)
{
if (en is Npc npc)
if (!Base.NpcVsNpcEnabled || (Base == npc.Base && !Base.AttackAllies))
{
if (npc.Base == Base)
{
if (Base.AttackAllies == false)
{
return;
}
}
return;
}
else if (en is Player player)

if (CanTarget(entity))
{
//TODO Make sure that the npc can target the player
if (CanTarget(player))
{
Target = player;
}
Target = entity;
}
else if (CanTarget(en))
}
else if (entity is Player player)
{
//TODO Make sure that the npc can target the player
if (CanTarget(player))
{
Target = en;
Target = player;
}
}
else if (CanTarget(entity))
{
Target = entity;
}

// Are we configured to handle resetting NPCs after they chase a target for a specified amount of tiles?
if (Options.Instance.Npc.AllowResetRadius)
Expand All @@ -267,7 +266,7 @@
}
else
{
Target = en;
Target = entity;
}

if (Target != oldTarget)
Expand All @@ -278,6 +277,26 @@
mTargetFailCounter = 0;
}

public override bool CanTarget(Entity entity)
{
// ReSharper disable once InvertIf
if (entity is Npc npc)
{
if (!Base.NpcVsNpcEnabled)
{
return false;
}

// ReSharper disable once InvertIf
if (Base == npc.Base && !Base.AttackAllies)
{
return false;
}
}

return base.CanTarget(entity);
}

public void RemoveFromDamageMap(Entity en)
{
DamageMap.TryRemove(en, out _);
Expand Down Expand Up @@ -1228,7 +1247,7 @@
// If so, remove target and move back to the origin point.
if (Options.Instance.Npc.AllowResetRadius && AggroCenterMap != null && (GetDistanceTo(AggroCenterMap, AggroCenterX, AggroCenterY) > Math.Max(Options.Instance.Npc.ResetRadius, Math.Min(Base.ResetRadius, Math.Max(Options.Instance.Map.MapWidth, Options.Instance.Map.MapHeight))) || forceDistance))
{
Reset(Options.Instance.Npc.ResetVitalsAndStatusses);
Reset(Options.Instance.Npc.ResetVitalsAndStatuses);

Check failure on line 1250 in Intersect.Server.Core/Entities/Npc.cs

View workflow job for this annotation

GitHub Actions / build

'NpcOptions' does not contain a definition for 'ResetVitalsAndStatuses' and no accessible extension method 'ResetVitalsAndStatuses' accepting a first argument of type 'NpcOptions' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 1250 in Intersect.Server.Core/Entities/Npc.cs

View workflow job for this annotation

GitHub Actions / build

'NpcOptions' does not contain a definition for 'ResetVitalsAndStatuses' and no accessible extension method 'ResetVitalsAndStatuses' accepting a first argument of type 'NpcOptions' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 1250 in Intersect.Server.Core/Entities/Npc.cs

View workflow job for this annotation

GitHub Actions / build

'NpcOptions' does not contain a definition for 'ResetVitalsAndStatuses' and no accessible extension method 'ResetVitalsAndStatuses' accepting a first argument of type 'NpcOptions' could be found (are you missing a using directive or an assembly reference?)

mResetCounter = 0;
mResetDistance = 0;
Expand Down
Loading