1+ using System . Diagnostics . CodeAnalysis ;
2+ using Intersect . Core ;
13using Intersect . Enums ;
24using Intersect . Framework . Core ;
35using Intersect . GameObjects ;
46using Intersect . Utilities ;
7+ using Microsoft . Extensions . Logging ;
58
69namespace 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 }
0 commit comments