Skip to content

Commit

Permalink
Add null check to DropLoot() for artifact scrolls (#269)
Browse files Browse the repository at this point in the history
When an artifact scroll couldn't be created, it lead to a null exception which stopped further loot templates from being processed and messed up mobs dying.

It now logs an error including the scroll data string so it can be added to item templates.
  • Loading branch information
tegstewart authored Dec 7, 2020
1 parent 3d78cdf commit aa0989d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions GameServer/gameobjects/GameNPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4606,7 +4606,7 @@ public virtual void DropLoot(GameObject killer)
foreach (ItemTemplate lootTemplate in lootTemplates)
{
if (lootTemplate == null) continue;
GameStaticItem loot;
GameStaticItem loot = null;
if (GameMoney.IsItemMoney(lootTemplate.Name))
{
long value = lootTemplate.Price;
Expand Down Expand Up @@ -4666,16 +4666,29 @@ public virtual void DropLoot(GameObject killer)
else if (lootTemplate.Name.StartsWith("scroll|"))
{
String[] scrollData = lootTemplate.Name.Split('|');
String artifactID = scrollData[1];
int pageNumber = UInt16.Parse(scrollData[2]);
loot = ArtifactMgr.CreateScroll(artifactID, pageNumber);
loot.X = X;
loot.Y = Y;
loot.Z = Z;
loot.Heading = Heading;
loot.CurrentRegion = CurrentRegion;
(loot as WorldInventoryItem).Item.IsCrafted = false;
(loot as WorldInventoryItem).Item.Creator = Name;

if (scrollData.Length >= 3)
{
String artifactID = scrollData[1];
int pageNumber = UInt16.Parse(scrollData[2]);
loot = ArtifactMgr.CreateScroll(artifactID, pageNumber);
}

if (loot == null)
{
log.Error($"Artifact scroll could not be created for data string [{lootTemplate.Name}]");
continue;
}
else
{
loot.X = X;
loot.Y = Y;
loot.Z = Z;
loot.Heading = Heading;
loot.CurrentRegion = CurrentRegion;
(loot as WorldInventoryItem).Item.IsCrafted = false;
(loot as WorldInventoryItem).Item.Creator = Name;
}
}
else
{
Expand Down

0 comments on commit aa0989d

Please sign in to comment.