Skip to content

Commit

Permalink
Fix crash getting next frame in NPCs
Browse files Browse the repository at this point in the history
Attempting to animate next frame for an NPC that is not doing the expected action would sometimes put the npc's frame out of bounds, which later caused a crash when attempting to load the texture for that (non-existent) frame.
  • Loading branch information
ethanmoffat committed May 31, 2024
1 parent 21181f8 commit a419a60
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions EOLib/Domain/Extensions/NPCExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public static int GetWalkFrame(this NPC.NPC npc)

public static NPC.NPC WithNextWalkFrame(this NPC.NPC npc)
{
if (npc.IsActing(NPCActionState.Attacking))
return npc;

if (npc.Frame == NPCFrame.WalkFrame4)
{
return npc.WithFrame(NPCFrame.Standing);
Expand All @@ -52,6 +55,9 @@ public static NPC.NPC WithNextWalkFrame(this NPC.NPC npc)

public static NPC.NPC WithNextAttackFrame(this NPC.NPC npc)
{
if (npc.IsActing(NPCActionState.Walking))
return npc;

var retNpc = npc.WithActualAttackFrame((npc.ActualAttackFrame + 1) % 5);

if (npc.ActualAttackFrame == 0)
Expand Down

0 comments on commit a419a60

Please sign in to comment.