Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixes null crash on deserialization for Champs #1932

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
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
302 changes: 157 additions & 145 deletions Projects/UOContent/Engines/CannedEvil/ChampionSpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ public partial class ChampionSpawn : Item
[SerializedCommandProperty(AccessLevel.GameMaster)]
private ChampionSpawnType _type;

[Tidy]
[SerializableField(14)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private List<Mobile> _creatures;

[Tidy]
[SerializableField(15)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private List<Item> _redSkulls;

[Tidy]
[SerializableField(16)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private List<Item> _whiteSkulls;
Expand Down Expand Up @@ -524,126 +527,128 @@ public void OnSlice()
Champion = null;
Stop();
}
}
else
{
int kills = _kills;

for (var i = 0; i < _creatures.Count; ++i)
{
Mobile m = _creatures[i];

if (m.Deleted)
{
if (m.Corpse is { Deleted: false })
{
((Corpse)m.Corpse).BeginDecay(TimeSpan.FromMinutes(1));
}

RemoveFromCreaturesAt(i);
--i;
++_kills;

Mobile killer = m.FindMostRecentDamager(false);
return;
}

RegisterDamageTo(m);
int kills = _kills;

if (killer is BaseCreature creature)
{
killer = creature.GetMaster();
}
for (var i = 0; i < _creatures.Count; ++i)
{
Mobile m = _creatures[i];

if (killer is not PlayerMobile pm)
{
continue;
}
if (!m.Deleted)
{
continue;
}

int mobSubLevel = GetSubLevelfor(m) + 1;
if (m.Corpse is { Deleted: false })
{
((Corpse)m.Corpse).BeginDecay(TimeSpan.FromMinutes(1));
}

if (mobSubLevel >= 0)
{
bool gainedPath = false;
RemoveFromCreaturesAt(i);
--i;
++_kills;

int pointsToGain = mobSubLevel * 40;
Mobile killer = m.FindMostRecentDamager(false);

if (VirtueSystem.Award(pm, VirtueName.Valor, pointsToGain, ref gainedPath))
{
if (gainedPath)
{
pm.SendLocalizedMessage(1054032); // You have gained a path in Valor!
}
else
{
pm.SendLocalizedMessage(1054030); // You have gained in Valor!
}
RegisterDamageTo(m);

// No delay on Valor gains
}
if (killer is BaseCreature creature)
{
killer = creature.GetMaster();
}

pm.ChampionTitles.Award(_type, mobSubLevel);
}
if (killer is not PlayerMobile pm)
{
continue;
}

if (!Core.ML)
{
continue;
}
int mobSubLevel = GetSubLevelfor(m) + 1;

var isFel = Map == Map.Felucca;
double mapChance;
if (isFel)
{
mapChance = 0.001;
}
else if (Map == Map.Ilshenar || Map == Map.Tokuno)
{
mapChance = 0.0015;
}
else // Nothing drops in Trammel, Malas or TerMur
{
continue;
}
if (mobSubLevel >= 0)
{
bool gainedPath = false;

if (Utility.RandomDouble() >= mapChance)
{
continue;
}
int pointsToGain = mobSubLevel * 40;

if (!isFel || Utility.RandomBool())
if (VirtueSystem.Award(pm, VirtueName.Valor, pointsToGain, ref gainedPath))
{
if (gainedPath)
{
GiveScrollTo(pm, CreateRandomSoT(isFel), isFel);
pm.SendLocalizedMessage(1054032); // You have gained a path in Valor!
}
else
{
GiveScrollTo(pm, CreateRandomPS());
pm.SendLocalizedMessage(1054030); // You have gained in Valor!
}

// No delay on Valor gains
}

pm.ChampionTitles.Award(_type, mobSubLevel);
}

// Only really needed once.
if (_kills > kills)
if (!Core.ML)
{
InvalidateProperties();
continue;
}

double n = _kills / (double)MaxKills;
int p = (int)(n * 100);

if (p >= 99)
var isFel = Map == Map.Felucca;
double mapChance;
if (isFel)
{
AdvanceLevel();
mapChance = 0.001;
}
else if (p > 0)
else if (Map == Map.Ilshenar || Map == Map.Tokuno)
{
SetWhiteSkullCount(p / 20);
mapChance = 0.0015;
}
else // Nothing drops in Trammel, Malas or TerMur
{
continue;
}

if (Utility.RandomDouble() >= mapChance)
{
continue;
}

if (Core.Now >= ExpireTime)
if (!isFel || Utility.RandomBool())
{
GiveScrollTo(pm, CreateRandomSoT(isFel), isFel);
}
else
{
Expire();
GiveScrollTo(pm, CreateRandomPS());
}
}

// Only really needed once.
if (_kills > kills)
{
InvalidateProperties();
}

double n = _kills / (double)MaxKills;
int p = (int)(n * 100);

if (p >= 99)
{
AdvanceLevel();
}
else if (p > 0)
{
SetWhiteSkullCount(p / 20);
}

Respawn();
if (Core.Now >= ExpireTime)
{
Expire();
}

Respawn();
}

public void AdvanceLevel()
Expand Down Expand Up @@ -1361,67 +1366,72 @@ public override void AlterLightLevel(Mobile m, ref int global, ref int personal)

public override void OnEnter(Mobile m)
{
if (m.Player && m.AccessLevel == AccessLevel.Player && !Spawn.Active)
if (!m.Player || m.AccessLevel != AccessLevel.Player || Spawn.Active)
{
Region parent = Parent ?? this;
return;
}

if (Spawn.ReadyToActivate)
Region parent = Parent ?? this;

if (Spawn.ReadyToActivate)
{
Spawn.Start();
return;
}

if (!Spawn.ProximitySpawn || Spawn.ActivatedByProximity || Core.Now < Spawn.NextProximityTime)
{
return;
}

List<Mobile> players = parent.GetPlayers();
List<IPAddress> addresses = new List<IPAddress>();
for (var i = 0; i < players.Count; i++)
{
if (players[i].AccessLevel == AccessLevel.Player && players[i].NetState != null &&
!addresses.Contains(players[i].NetState.Address) && !((PlayerMobile)players[i]).Young)
{
Spawn.Start();
addresses.Add(players[i].NetState.Address);
}
else if (Spawn.ProximitySpawn && !Spawn.ActivatedByProximity && Core.Now >= Spawn.NextProximityTime)
{
List<Mobile> players = parent.GetPlayers();
List<IPAddress> addresses = new List<IPAddress>();
for (var i = 0; i < players.Count; i++)
{
if (players[i].AccessLevel == AccessLevel.Player && players[i].NetState != null &&
!addresses.Contains(players[i].NetState.Address) && !((PlayerMobile)players[i]).Young)
{
addresses.Add(players[i].NetState.Address);
}
}

if (addresses.Count >= 15)
{
foreach (Mobile player in players)
{
player.SendMessage(0x20, Spawn.BroadcastMessage);
}
}

Spawn.ActivatedByProximity = true;
Spawn.BeginRestart(TimeSpan.FromMinutes(5.0));
}
if (addresses.Count >= 15)
{
foreach (Mobile player in players)
{
player.SendMessage(0x20, Spawn.BroadcastMessage);
}

Spawn.ActivatedByProximity = true;
Spawn.BeginRestart(TimeSpan.FromMinutes(5.0));
}
}

public override bool OnMoveInto(Mobile m, Direction d, Point3D newLocation, Point3D oldLocation)
{
if (base.OnMoveInto(m, d, newLocation, oldLocation))
if (!base.OnMoveInto(m, d, newLocation, oldLocation))
{
if (m.Player)
{
if (((PlayerMobile)m).Young)
{
m.SendMessage("You decide against going here because of the danger.");
}
else if (!m.Alive)
{
m.SendMessage("A magical force prevents ghosts from entering this region.");
}
else
{
return true;
}
}
else
{
return true;
}
return false;
}

if (!m.Player)
{
return true;
}

return false;
if (((PlayerMobile)m).Young)
{
m.SendMessage("You decide against going here because of the danger.");
return false;
}

if (!m.Alive)
{
m.SendMessage("A magical force prevents ghosts from entering this region.");
return false;
}

return true;
}

public override bool OnBeforeDeath(Mobile m)
Expand Down Expand Up @@ -1454,22 +1464,24 @@ public EjectTimer(Mobile from, ChampionSpawnRegion region) : base(TimeSpan.FromM
protected override void OnTick()
{
//See if they are dead, or logged out!
if (m_Region.Spawn != null && m_Region.CanSpawn() && !m_From.Alive)
if (m_Region.Spawn == null || !m_Region.CanSpawn() || m_From.Alive)
{
if (m_From.NetState != null)
{
if (m_From.Region.IsPartOf(m_Region))
{
m_From.MoveToWorld(m_Region.Spawn.EjectLocation, m_Region.Spawn.EjectMap);
m_From.SendMessage("A magical force forces you out of the area.");
}
}
else if (Find(m_From.LogoutLocation, m_From.LogoutMap).IsPartOf(m_Region))
return;
}

if (m_From.NetState != null)
{
if (m_From.Region.IsPartOf(m_Region))
{
m_From.LogoutLocation = m_Region.Spawn.EjectLocation;
m_From.LogoutMap = m_Region.Spawn.EjectMap;
m_From.MoveToWorld(m_Region.Spawn.EjectLocation, m_Region.Spawn.EjectMap);
m_From.SendMessage("A magical force forces you out of the area.");
}
}
else if (Find(m_From.LogoutLocation, m_From.LogoutMap).IsPartOf(m_Region))
{
m_From.LogoutLocation = m_Region.Spawn.EjectLocation;
m_From.LogoutMap = m_Region.Spawn.EjectMap;
}
}
}
}
Expand Down
Loading
Loading