Skip to content

Commit 1891091

Browse files
committed
rename DoT -> DamageOverTimeEffect
1 parent b33e7fb commit 1891091

File tree

4 files changed

+76
-31
lines changed

4 files changed

+76
-31
lines changed

Intersect.Server.Core/Entities/Combat/DoT.cs renamed to Intersect.Server.Core/Entities/Combat/DamageOverTimeEffect.cs

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,79 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Intersect.Core;
13
using Intersect.Enums;
24
using Intersect.Framework.Core;
35
using Intersect.GameObjects;
46
using Intersect.Utilities;
7+
using Microsoft.Extensions.Logging;
58

69
namespace Intersect.Server.Entities.Combat;
710

811

9-
public partial class DoT
12+
public partial class DamageOverTimeEffect
1013
{
11-
public Guid Id = Guid.NewGuid();
14+
public Guid Id { get; set; } = Guid.NewGuid();
1215

13-
public Entity Attacker;
16+
public Entity Attacker { get; set; }
1417

15-
public int Count;
18+
public int Count { get; set; }
1619

1720
private long mInterval;
1821

19-
public SpellDescriptor SpellDescriptor;
22+
public SpellDescriptor SpellDescriptor { get; }
2023

21-
public DoT(Entity attacker, Guid spellId, Entity target)
24+
public static bool TryCreate(
25+
Entity attacker,
26+
Guid spellDescriptorId,
27+
Entity target,
28+
[NotNullWhen(true)] out DamageOverTimeEffect? damageOverTimeEffect
29+
)
2230
{
23-
SpellDescriptor = SpellDescriptor.Get(spellId);
31+
if (SpellDescriptor.TryGet(spellDescriptorId, out var spellDescriptor))
32+
{
33+
return TryCreate(attacker, spellDescriptor, target, out damageOverTimeEffect);
34+
}
2435

25-
Attacker = attacker;
26-
Target = target;
36+
ApplicationContext.CurrentContext.Logger.LogWarning(
37+
"Skipping creation of DamageOverTimeEffect because SpellDescriptor is missing {SpellDescriptorId}",
38+
spellDescriptor.Id
39+
);
40+
damageOverTimeEffect = null;
41+
return false;
42+
}
2743

28-
if (SpellDescriptor == null || SpellDescriptor.Combat.HotDotInterval < 1)
44+
public static bool TryCreate(
45+
Entity attacker,
46+
SpellDescriptor spellDescriptor,
47+
Entity target,
48+
[NotNullWhen(true)] out DamageOverTimeEffect? damageOverTimeEffect
49+
)
50+
{
51+
if (spellDescriptor.Combat.HotDotInterval < 1)
2952
{
30-
return;
53+
ApplicationContext.CurrentContext.Logger.LogWarning(
54+
"Skipping creation of DamageOverTimeEffect because the Heal/Damage-over-time interval is less than 1 for {SpellDescriptorId} ({SpellName})",
55+
spellDescriptor.Id,
56+
spellDescriptor.Name
57+
);
58+
damageOverTimeEffect = null;
59+
return false;
3160
}
3261

62+
damageOverTimeEffect = new DamageOverTimeEffect(attacker, spellDescriptor, target);
63+
return damageOverTimeEffect != null;
64+
}
65+
66+
private DamageOverTimeEffect(Entity attacker, SpellDescriptor spellDescriptor, Entity target)
67+
{
68+
ArgumentNullException.ThrowIfNull(attacker, nameof(attacker));
69+
ArgumentNullException.ThrowIfNull(spellDescriptor, nameof(spellDescriptor));
70+
ArgumentNullException.ThrowIfNull(target, nameof(target));
71+
72+
SpellDescriptor = spellDescriptor;
73+
74+
Attacker = attacker;
75+
Target = target;
76+
3377
// Does target have a cleanse buff? If so, do not allow this DoT when spell is unfriendly.
3478
if (!SpellDescriptor.Combat.Friendly)
3579
{
@@ -44,11 +88,8 @@ public DoT(Entity attacker, Guid spellId, Entity target)
4488

4589

4690
mInterval = Timing.Global.Milliseconds + SpellDescriptor.Combat.HotDotInterval;
91+
// Subtract 1 since the first tick always occurs when the spell is cast.
4792
Count = (SpellDescriptor.Combat.Duration + SpellDescriptor.Combat.HotDotInterval - 1) / SpellDescriptor.Combat.HotDotInterval;
48-
target.DoT.TryAdd(Id, this);
49-
target.CachedDots = target.DoT.Values.ToArray();
50-
51-
//Subtract 1 since the first tick always occurs when the spell is cast.
5293
}
5394

5495
public Entity Target { get; }
@@ -57,14 +98,14 @@ public void Expire()
5798
{
5899
if (Target != null)
59100
{
60-
Target.DoT?.TryRemove(Id, out DoT val);
61-
Target.CachedDots = Target.DoT?.Values.ToArray() ?? new DoT[0];
101+
Target.DamageOverTimeEffects?.TryRemove(Id, out DamageOverTimeEffect val);
102+
Target.CachedDamageOverTimeEffects = Target.DamageOverTimeEffects?.Values.ToArray() ?? new DamageOverTimeEffect[0];
62103
}
63104
}
64105

65106
public bool CheckExpired()
66107
{
67-
if (Target != null && !Target.DoT.ContainsKey(Id))
108+
if (Target != null && !Target.DamageOverTimeEffects.ContainsKey(Id))
68109
{
69110
return false;
70111
}

Intersect.Server.Core/Entities/Combat/Status.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public Status(Entity en, Entity attacker, SpellDescriptor spell, SpellEffect typ
132132
}
133133
}
134134

135-
foreach (var dot in en.CachedDots)
135+
foreach (var dot in en.CachedDamageOverTimeEffects)
136136
{
137137
if (spell.Combat.Friendly != dot.SpellDescriptor.Combat.Friendly)
138138
{

Intersect.Server.Core/Entities/Entity.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ public string FooterLabelJson
247247
public List<Guid> Animations { get; set; } = [];
248248

249249
//DoT/HoT Spells
250-
[NotMapped, JsonIgnore] public ConcurrentDictionary<Guid, DoT> DoT { get; } = [];
250+
// TODO: Are DoTs from the same source entity not stackable? This should be configurable
251+
[NotMapped, JsonIgnore] public ConcurrentDictionary<Guid, DamageOverTimeEffect> DamageOverTimeEffects { get; } = [];
251252

252-
[NotMapped, JsonIgnore]
253-
public DoT[] CachedDots { get; set; } = new DoT[0];
253+
[NotMapped, JsonIgnore] public DamageOverTimeEffect[] CachedDamageOverTimeEffects { get; set; } = [];
254254

255255
[NotMapped, JsonIgnore]
256256
public EventMoveRoute MoveRoute { get; set; } = null;
@@ -350,7 +350,7 @@ public virtual void Update(long timeMs)
350350
}
351351

352352
//DoT/HoT timers
353-
foreach (var dot in CachedDots)
353+
foreach (var dot in CachedDamageOverTimeEffects)
354354
{
355355
dot.Tick();
356356
}
@@ -1946,15 +1946,19 @@ public virtual void TryAttack(
19461946
//Handle DoT/HoT spells]
19471947
if (spellDescriptor.Combat.HoTDoT)
19481948
{
1949-
foreach (var dot in target.CachedDots)
1949+
foreach (var dot in target.CachedDamageOverTimeEffects)
19501950
{
19511951
if (dot.SpellDescriptor.Id == spellDescriptor.Id && dot.Attacker == this)
19521952
{
19531953
dot.Expire();
19541954
}
19551955
}
19561956

1957-
new DoT(this, spellDescriptor.Id, target);
1957+
if (DamageOverTimeEffect.TryCreate(this, spellDescriptor, target, out var damageOverTimeEffect))
1958+
{
1959+
target.DamageOverTimeEffects.TryAdd(Id, damageOverTimeEffect);
1960+
target.CachedDamageOverTimeEffects = target.DamageOverTimeEffects.Values.ToArray();
1961+
}
19581962
}
19591963
}
19601964

@@ -3102,8 +3106,8 @@ public virtual void Die(bool dropItems = true, Entity killer = null)
31023106
instance.ClearEntityTargetsOf(this);
31033107
}
31043108

3105-
DoT?.Clear();
3106-
CachedDots = new DoT[0];
3109+
DamageOverTimeEffects?.Clear();
3110+
CachedDamageOverTimeEffects = new DamageOverTimeEffect[0];
31073111
Statuses?.Clear();
31083112
CachedStatuses = new Status[0];
31093113
Stat?.ToList().ForEach(stat => stat?.Reset());
@@ -3182,8 +3186,8 @@ public virtual void Reset()
31823186
}
31833187

31843188
// Remove any damage over time effects
3185-
DoT.Clear();
3186-
CachedDots = [];
3189+
DamageOverTimeEffects.Clear();
3190+
CachedDamageOverTimeEffects = [];
31873191
Statuses.Clear();
31883192
CachedStatuses = [];
31893193

Intersect.Server.Core/Entities/Npc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,8 @@ private void Reset(bool resetVitals, bool clearLocation = false)
12991299
{
13001300
Statuses.Clear();
13011301
CachedStatuses = Statuses.Values.ToArray();
1302-
DoT.Clear();
1303-
CachedDots = DoT.Values.ToArray();
1302+
DamageOverTimeEffects.Clear();
1303+
CachedDamageOverTimeEffects = DamageOverTimeEffects.Values.ToArray();
13041304
for (var v = 0; v < Enum.GetValues<Vital>().Length; v++)
13051305
{
13061306
RestoreVital((Vital)v);

0 commit comments

Comments
 (0)