Skip to content

Commit 9d9a522

Browse files
authored
fix: Fixes PlayerZombies null pointer exception (#1963)
1 parent 4e2fcee commit 9d9a522

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

Projects/UOContent/Holiday Stuff/Halloween/2012/Engines/PlayerZombies.cs

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public static class HalloweenHauntings
1313
private static Timer _timer;
1414
private static Timer _clearTimer;
1515

16-
private static int m_TotalZombieLimit;
17-
private static int m_DeathQueueLimit;
18-
private static int m_QueueDelaySeconds;
19-
private static int m_QueueClearIntervalSeconds;
16+
private const int TotalZombieLimit = 200;
17+
private const int DeathQueueLimit = 200;
18+
private const int QueueDelaySeconds = 120;
19+
private const int QueueClearIntervalSeconds = 1800;
2020

2121
private static HashSet<PlayerMobile> _deathQueue;
2222

23-
private static readonly Rectangle2D[] m_Cemetaries =
24-
{
23+
private static readonly Rectangle2D[] _cemetaries =
24+
[
2525
new(1272, 3712, 30, 20), // Jhelom
2626
new(1337, 1444, 48, 52), // Britain
2727
new(2424, 1098, 20, 28), // Trinsic
@@ -39,37 +39,31 @@ public static class HalloweenHauntings
3939
new(712, 1104, 22, 30), // Yew
4040
new(5824, 1464, 6, 22), // Fire Dungeon
4141
new(5224, 3655, 5, 14) // T2A
42-
};
42+
];
4343

4444
internal static Dictionary<PlayerMobile, ZombieSkeleton> _reAnimated;
4545

46-
public static void Initialize()
46+
[OnEvent(nameof(PlayerMobile.PlayerDeathEvent))]
47+
public static void OnPlayerDeathEvent(PlayerMobile pm)
4748
{
48-
m_TotalZombieLimit = 200;
49-
m_DeathQueueLimit = 200;
50-
m_QueueDelaySeconds = 120;
51-
m_QueueClearIntervalSeconds = 1800;
49+
var now = Core.Now;
5250

53-
var today = Core.Now;
54-
var tick = TimeSpan.FromSeconds(m_QueueDelaySeconds);
55-
var clear = TimeSpan.FromSeconds(m_QueueClearIntervalSeconds);
56-
57-
_reAnimated = new Dictionary<PlayerMobile, ZombieSkeleton>();
58-
_deathQueue = new HashSet<PlayerMobile>();
59-
60-
if (today >= HolidaySettings.StartHalloween && today <= HolidaySettings.FinishHalloween)
51+
if (now < HolidaySettings.StartHalloween || now > HolidaySettings.FinishHalloween)
6152
{
62-
_timer = Timer.DelayCall(tick, 0, Timer_Callback);
63-
_clearTimer = Timer.DelayCall(clear, 0, Clear_Callback);
53+
return;
6454
}
65-
}
6655

67-
[OnEvent(nameof(PlayerMobile.PlayerDeathEvent))]
68-
public static void OnPlayerDeathEvent(PlayerMobile pm)
69-
{
70-
if (_timer.Running && !_deathQueue.Contains(pm) && _deathQueue.Count < m_DeathQueueLimit)
56+
_timer ??= Timer.DelayCall(TimeSpan.FromSeconds(QueueDelaySeconds), 0, Timer_Callback);
57+
_clearTimer ??= Timer.DelayCall(TimeSpan.FromSeconds(QueueClearIntervalSeconds), 0, Clear_Callback);
58+
59+
if (_timer.Running)
7160
{
72-
_deathQueue.Add(pm);
61+
_deathQueue ??= [];
62+
63+
if (_deathQueue.Count < DeathQueueLimit)
64+
{
65+
_deathQueue.Add(pm);
66+
}
7367
}
7468
}
7569

@@ -84,49 +78,53 @@ private static void Clear_Callback()
8478
return;
8579
}
8680

87-
_reAnimated.Clear();
88-
_deathQueue.Clear();
81+
_reAnimated?.Clear();
82+
_deathQueue?.Clear();
8983
}
9084

9185
private static void Timer_Callback()
9286
{
93-
9487
if (Core.Now > HolidaySettings.FinishHalloween)
9588
{
9689
_timer.Stop();
9790
_timer = null;
9891
return;
9992
}
10093

101-
PlayerMobile player = null;
94+
if (_deathQueue == null)
95+
{
96+
return;
97+
}
10298

99+
PlayerMobile player = null;
103100
foreach (var entry in _deathQueue)
104101
{
105-
if (!_reAnimated.ContainsKey(entry))
102+
if (_reAnimated?.ContainsKey(entry) != true)
106103
{
107104
player = entry;
108105
break;
109106
}
110107
}
111108

112-
if (player?.Deleted != false || _reAnimated.Count >= m_TotalZombieLimit)
109+
if (player?.Deleted != false || _reAnimated?.Count >= TotalZombieLimit)
113110
{
114111
return;
115112
}
116113

117114
var map = Utility.RandomBool() ? Map.Trammel : Map.Felucca;
118-
var home = Utility.RandomPointIn(m_Cemetaries.RandomElement(), map);
115+
var home = Utility.RandomPointIn(_cemetaries.RandomElement(), map);
119116

120117
if (map.CanSpawnMobile(home))
121118
{
122119
var zombieskel = new ZombieSkeleton(player);
123120

121+
_reAnimated ??= [];
124122
_reAnimated.Add(player, zombieskel);
123+
125124
zombieskel.Home = home;
126125
zombieskel.RangeHome = 10;
127126

128127
zombieskel.MoveToWorld(home, map);
129-
130128
_deathQueue.Remove(player);
131129
}
132130
}

0 commit comments

Comments
 (0)