Fix Moving NPC bugs see desc.

Fixed Straight Moving NPC from stopping if the player stands next to it.
Hopefully fixed the bug where if you time it right you could walk into the path of a moving NPC.
This commit is contained in:
JappaWakka 2024-09-26 19:44:32 +02:00
parent 4fca486fab
commit d02763959f
2 changed files with 113 additions and 96 deletions

View File

@ -657,6 +657,10 @@
''frontRotation = original faceRotation
Dim frontRotation As Integer = Me.faceRotation
''for the check if the NPC can rotate when it can't walk
Dim CanRotate As Boolean = False
Dim OnlyRotateRotation = Me.faceRotation
Dim contains As Boolean = False
Dim newPosition As Vector3 = (GetMove(newRotation) / Speed) + Me.Position
Dim blocked As Boolean = False
@ -677,6 +681,15 @@
End If
Next
End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
@ -697,6 +710,15 @@
End If
Next
End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
@ -717,6 +739,15 @@
End If
Next
End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
@ -737,49 +768,25 @@
End If
Next
End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
Moved = 1.0F
End If
Else
Dim CanRotate As Boolean = False
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
Exit For
End If
Next
If CanRotate = True Then
Me.faceRotation = newRotation
Me.faceRotation = OnlyRotateRotation
End If
End If
End If
Else
Dim CanRotate As Boolean = False
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
Exit For
End If
Next
If CanRotate = True Then
Me.faceRotation = newRotation
End If
End If
End If
Else
Dim CanRotate As Boolean = False
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
Exit For
End If
Next
If CanRotate = True Then
Me.faceRotation = newRotation
End If
End If
End If
End If
End If
@ -790,35 +797,34 @@
newPosition = New Vector3(CInt(newPosition.X), CInt(newPosition.Y), CInt(newPosition.Z))
Dim oldPosition As Vector3 = Me.Position
Dim interactPlayer As Boolean = True
Dim interactPlayer As Boolean = False
If Screen.Camera.IsMoving() = False Then
If CInt(Screen.Camera.Position.X) <> newPosition.X Or CInt(Screen.Camera.Position.Z) <> newPosition.Z Then
If CInt(Screen.Level.OverworldPokemon.Position.X) <> newPosition.X Or CInt(Screen.Level.OverworldPokemon.Position.Z) <> newPosition.Z Then
interactPlayer = False
If CInt(Screen.Camera.Position.X) = newPosition.X And CInt(Screen.Camera.Position.Z) = newPosition.Z Then
If CInt(Screen.Level.OverworldPokemon.Position.X) = newPosition.X And CInt(Screen.Level.OverworldPokemon.Position.Z) = newPosition.Z Then
interactPlayer = True
End If
End If
Else
Dim cameraNewPosition As Vector3 = Screen.Camera.GetForwardMovedPosition()
Dim cameraOldPosition As Vector3 = Screen.Camera.GetForwardMovedPosition() - Screen.Camera.GetMoveDirection()
If CInt(cameraNewPosition.X) <> newPosition.X And CInt(cameraOldPosition.X) <> newPosition.X Or CInt(cameraNewPosition.Z) <> newPosition.Z And CInt(cameraOldPosition.Z) <> newPosition.Z Then
If CInt(Screen.Level.OverworldPokemon.Position.X) <> newPosition.X Or CInt(Screen.Level.OverworldPokemon.Position.Z) <> newPosition.Z Then
interactPlayer = False
Dim cameraNewPosition As Vector3 = CType(Screen.Camera, OverworldCamera).LastStepPosition + Screen.Camera.PlannedMovement()
If CInt(cameraNewPosition.X) = newPosition.X And CInt(cameraNewPosition.Z) = newPosition.Z Then
If CInt(Screen.Level.OverworldPokemon.Position.X) = newPosition.X And CInt(Screen.Level.OverworldPokemon.Position.Z) = newPosition.Z Then
interactPlayer = True
End If
End If
End If
'' check if a NetworkPlayer is not in the way
For Each Player As NetworkPlayer In Screen.Level.NetworkPlayers
If CInt(Player.Position.X) <> newPosition.X And CInt(Player.Position.Z) <> newPosition.Z Then
interactPlayer = False
If CInt(Player.Position.X) = newPosition.X And CInt(Player.Position.Z) = newPosition.Z Then
interactPlayer = True
Exit For
End If
Next
'' check if a NetworkPokémon is not in the way
For Each Pokemon As NetworkPokemon In Screen.Level.NetworkPokemon
If CInt(Pokemon.Position.X) <> newPosition.X And CInt(Pokemon.Position.Z) <> newPosition.Z Then
interactPlayer = False
If CInt(Pokemon.Position.X) = newPosition.X And CInt(Pokemon.Position.Z) = newPosition.Z Then
interactPlayer = True
Exit For
End If
Next

View File

@ -859,20 +859,31 @@ Public Class OverworldCamera
setSurfFalse = True
End If
Next
Dim PlayerBoundingBox As New BoundingBox(
newPosition + New Vector3(-0.465F),
newPosition + New Vector3(0.465F))
If cannotWalk = False Then
For Each Entity As Entity In Screen.Level.Entities
If Entity.boundingBox.Contains(Position2D) = ContainmentType.Contains Then
If cannotWalk = False Then
If Entity.EntityID.ToLower = "npc" Then
If Entity.ViewBox.Contains(PlayerBoundingBox) = ContainmentType.Intersects Then
If Entity.Collision = True Then
cannotWalk = Entity.WalkAgainstFunction()
Else
cannotWalk = Entity.WalkIntoFunction()
End If
End If
Else
If Entity.boundingBox.Contains(Position2D) = ContainmentType.Contains Then
If Entity.Collision = True Then
cannotWalk = Entity.WalkAgainstFunction()
Else
cannotWalk = Entity.WalkIntoFunction()
End If
ElseIf Entity.boundingBox.Contains(New Vector3(Position2D.X, Position2D.Y - 1, Position2D.Z)) = ContainmentType.Contains Then
Entity.WalkOntoFunction()
End If
End If
Next
Else
For Each Entity As Entity In Screen.Level.Entities