Skip to content

Commit 4eff95e

Browse files
authored
fix: server crash when crafting (AscensionGameDev#2246)
1 parent 269e845 commit 4eff95e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Intersect.Server.Core/Entities/Player.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,17 +4152,29 @@ public bool ShouldCancelCrafting()
41524152
return true;
41534153
}
41544154

4155+
if (CraftingState == null)
4156+
{
4157+
return true;
4158+
}
4159+
4160+
if (CraftingState.RemainingCount <= 0)
4161+
{
4162+
return true;
4163+
}
4164+
41554165
if (!CraftingTableBase.TryGet(OpenCraftingTableId, out var table))
41564166
{
41574167
return true;
41584168
}
41594169

4160-
if (!table.Crafts.Contains(CraftingState?.Id ?? default))
4170+
var craftingStateId = CraftingState?.Id;
4171+
4172+
if (craftingStateId == null || !table.Crafts.Contains(craftingStateId.Value))
41614173
{
41624174
return true;
41634175
}
41644176

4165-
if (!CraftBase.TryGet(CraftingState?.Id ?? default, out var craftDescriptor))
4177+
if (!CraftBase.TryGet(craftingStateId.Value, out var craftDescriptor))
41664178
{
41674179
return true;
41684180
}
@@ -4173,11 +4185,10 @@ public bool ShouldCancelCrafting()
41734185
return true;
41744186
}
41754187

4176-
var craftItem = ItemBase.Get(craftDescriptor.ItemId);
4177-
if (craftItem == null)
4188+
if (!ItemBase.TryGet(craftDescriptor.ItemId, out var craftItem))
41784189
{
41794190
PacketSender.SendChatMsg(this, Strings.Errors.UnknownErrorTryAgain, ChatMessageType.Error, CustomColors.Alerts.Error);
4180-
Log.Error($"Unable to find item descriptor {craftItem.Id} for craft {craftDescriptor.Id}.");
4191+
Log.Error($"Unable to find item descriptor {craftItem?.Id} for craft {craftDescriptor?.Id}.");
41814192
return true;
41824193
}
41834194

0 commit comments

Comments
 (0)