-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix player location on login * Fix unit test
- Loading branch information
1 parent
063e5ae
commit 6bd6452
Showing
21 changed files
with
144 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/ApplicationServer/NeoServer.Server/Services/PlayerLocationResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using NeoServer.Data.Entities; | ||
using NeoServer.Game.Common.Contracts.World; | ||
using NeoServer.Game.Common.Contracts.World.Tiles; | ||
using NeoServer.Game.Common.Location.Structs; | ||
using NeoServer.Game.Creatures; | ||
using NeoServer.Game.World; | ||
using Serilog; | ||
|
||
namespace NeoServer.Server.Services; | ||
|
||
//todo: this project is not the best place for this | ||
public class PlayerLocationResolver(World world, ILogger logger) | ||
{ | ||
public Location GetPlayerLocation(PlayerEntity playerEntity) | ||
{ | ||
var location = new Location((ushort)playerEntity.PosX, (ushort)playerEntity.PosY, (byte)playerEntity.PosZ); | ||
|
||
var playerTile = world.TryGetTile(ref location, out var tile) && | ||
PlayerEnterTileRule.Rule.CanEnter(tile, location) | ||
? tile | ||
: null; | ||
|
||
if (playerTile is not null) return location; | ||
|
||
foreach (var neighbour in location.Neighbours) | ||
{ | ||
world.TryGetTile(ref location, out var neighbourTile); | ||
if (neighbourTile is IDynamicTile && PlayerEnterTileRule.Rule.CanEnter(neighbourTile, neighbour)) | ||
{ | ||
return location; | ||
} | ||
} | ||
|
||
var town = GetTown(playerEntity); | ||
if (town is null) return Location.Zero; | ||
|
||
var townLocation = town.Coordinate.Location; | ||
|
||
playerTile = world.TryGetTile(ref townLocation, out var townTile) && townTile is IDynamicTile townDynamicTile && | ||
PlayerEnterTileRule.Rule.CanEnter(townDynamicTile, townLocation) | ||
? townDynamicTile | ||
: null; | ||
|
||
return playerTile?.Location ?? Location.Zero; | ||
} | ||
|
||
protected ITown GetTown(PlayerEntity playerEntity) | ||
{ | ||
if (!world.TryGetTown((ushort)playerEntity.TownId, out var town)) | ||
logger.Error("player town not found: {PlayerModelTownId}", playerEntity.TownId); | ||
return town; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.