Skip to content

Commit

Permalink
Teleport via marks on map
Browse files Browse the repository at this point in the history
  • Loading branch information
thexeondev committed Jan 5, 2024
1 parent 42cca1e commit cfa2cc9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
10 changes: 10 additions & 0 deletions NahidaImpact.Gameserver/Controllers/ControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ protected IResult Response<TMessage>(CmdType cmdType, TMessage message) where TM
Body = message.ToByteArray()
});
}

protected IResult Response(CmdType cmdType)
{
return new SinglePacketResult(new()
{
CmdType = cmdType,
Head = Memory<byte>.Empty,
Body = Memory<byte>.Empty
});
}
}
13 changes: 13 additions & 0 deletions NahidaImpact.Gameserver/Controllers/SceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ namespace NahidaImpact.Gameserver.Controllers;
[NetController]
internal class SceneController : ControllerBase
{
[NetCommand(CmdType.MarkMapReq)]
public async ValueTask<IResult> OnMarkMapReq(SceneManager sceneManager)
{
MarkMapReq request = Packet!.DecodeBody<MarkMapReq>();
if (request.Mark != null)
{
Vector teleportToPosition = request.Mark.Pos;
await sceneManager.TeleportTo(teleportToPosition.X, 800, teleportToPosition.Z);
}

return Response(CmdType.MarkMapRsp);
}

[NetCommand(CmdType.EvtDoSkillSuccNotify)]
public async ValueTask<IResult> OnEvtDoSkillSuccNotify(SceneManager sceneManager)
{
Expand Down
13 changes: 12 additions & 1 deletion NahidaImpact.Gameserver/Game/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class Player(ExcelTableCollection excelTables)
public uint CurTeamIndex { get; set; }

public uint CurAvatarEntityId { get; set; }
public Vector LastMainWorldPos { get; set; } = new();

private readonly ExcelTableCollection _excelTables = excelTables;

Expand All @@ -35,10 +36,20 @@ public void InitDefaultPlayer()
Index = 1
});
CurTeamIndex = 1;

LastMainWorldPos = GetDefaultMainWorldPos();
}

private Vector GetDefaultMainWorldPos() => new()
{
X = 2336.789f,
Y = 249.98896f,
Z = -751.3081f
};


public GameAvatarTeam GetCurrentTeam()
=> AvatarTeams.Find(team => team.Index == CurTeamIndex)!;
=> AvatarTeams.Find(team => team.Index == CurTeamIndex)!;

public bool TryGetAvatar(uint avatarId, [MaybeNullWhen(false)] out GameAvatar avatar)
=> (avatar = Avatars.Find(a => a.AvatarId == avatarId)) != null;
Expand Down
37 changes: 28 additions & 9 deletions NahidaImpact.Gameserver/Game/Scene/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ public async ValueTask OnEnterStateChanged(SceneEnterState changedToState)
_enterState = SceneEnterState.Complete;
}

public async ValueTask TeleportTo(float x, float y, float z)
{
SceneEntity? entity = _entityManager.GetEntityById(_player.CurAvatarEntityId);
if (entity == null) return;

entity.MotionInfo.Pos = new Vector
{
X = x,
Y = y,
Z = z
};

_player.LastMainWorldPos = entity.MotionInfo.Pos;
await ReEnterCurScene(EnterType.Jump);
}

public async ValueTask ResetAllCoolDownsForAvatar(uint entityId)
{
await _entityManager.ChangeAvatarFightPropAsync(entityId, FightProp.FIGHT_PROP_NONEXTRA_SKILL_CD_MINUS_RATIO, 1);
Expand Down Expand Up @@ -131,7 +147,9 @@ private async ValueTask OnSceneInitFinished()
GameAvatar gameAvatar = _player.Avatars.Find(avatar => avatar.Guid == guid)!;

AvatarEntity avatarEntity = _entityFactory.CreateAvatar(gameAvatar, _player.Uid);
avatarEntity.SetPosition(2336.789f, 249.98896f, -751.3081f);

Vector initialPos = _player.LastMainWorldPos;
avatarEntity.SetPosition(initialPos.X, initialPos.Y, initialPos.Z);

_teamAvatars.Add(avatarEntity);
}
Expand All @@ -156,7 +174,12 @@ private ValueTask OnPostEnter()
return ValueTask.CompletedTask;
}

public async ValueTask EnterSceneAsync(uint sceneId)
public async ValueTask ReEnterCurScene(EnterType enterType)
{
await EnterSceneAsync(_sceneId, enterType);
}

public async ValueTask EnterSceneAsync(uint sceneId, EnterType enterType = EnterType.Self)
{
if (_beginTime != 0) ResetState();

Expand All @@ -165,21 +188,17 @@ public async ValueTask EnterSceneAsync(uint sceneId)
EnterToken = ++_enterTokenSeed;

_enterState = SceneEnterState.EnterRequested;

await _session.NotifyAsync(CmdType.PlayerEnterSceneNotify, new PlayerEnterSceneNotify
{
SceneBeginTime = _beginTime,
SceneId = _sceneId,
SceneTransaction = CreateTransaction(_sceneId, _player.Uid, _beginTime),
Pos = new()
{
X = 2191.16357421875f,
Y = 214.65115356445312f,
Z = -1120.633056640625f
},
Pos = _player.LastMainWorldPos,
TargetUid = _player.Uid,
EnterSceneToken = EnterToken,
PrevPos = new(),
Type = EnterType.Self
Type = enterType
});
}

Expand Down

0 comments on commit cfa2cc9

Please sign in to comment.