Avatar swap, fix invisible weapons

This commit is contained in:
thexeondev 2024-01-05 00:17:25 +03:00
parent ac277d019a
commit a762ec8241
7 changed files with 37 additions and 15 deletions

View file

@ -9,6 +9,19 @@ namespace NahidaImpact.Gameserver.Controllers;
[NetController] [NetController]
internal class AvatarController : ControllerBase internal class AvatarController : ControllerBase
{ {
[NetCommand(CmdType.ChangeAvatarReq)]
public async ValueTask<IResult> OnChangeAvatarReq(SceneManager sceneManager)
{
ChangeAvatarReq request = Packet!.DecodeBody<ChangeAvatarReq>();
await sceneManager.ReplaceCurrentAvatarAsync(request.Guid);
return Response(CmdType.ChangeAvatarRsp, new ChangeAvatarRsp
{
CurGuid = request.Guid
});
}
[NetCommand(CmdType.SetUpAvatarTeamReq)] [NetCommand(CmdType.SetUpAvatarTeamReq)]
public async ValueTask<IResult> OnSetUpAvatarTeamReq(NetSession session, SceneManager sceneManager) public async ValueTask<IResult> OnSetUpAvatarTeamReq(NetSession session, SceneManager sceneManager)
{ {

View file

@ -9,9 +9,6 @@ namespace NahidaImpact.Gameserver.Controllers;
[NetController] [NetController]
internal class SceneController : ControllerBase internal class SceneController : ControllerBase
{ {
// TODO: Scene management, Entity management!!!
public const uint WeaponEntityId = 100663300;
[NetCommand(CmdType.GetScenePointReq)] [NetCommand(CmdType.GetScenePointReq)]
public ValueTask<IResult> OnGetScenePointReq(SceneManager sceneManager, Player player) public ValueTask<IResult> OnGetScenePointReq(SceneManager sceneManager, Player player)
{ {
@ -37,7 +34,7 @@ internal class SceneController : ControllerBase
SceneId = sceneManager.CurrentSceneId SceneId = sceneManager.CurrentSceneId
}; };
for (uint i = 1; i <= 20; i++) for (uint i = 1; i <= 100; i++)
{ {
rsp.AreaIdList.Add(i); rsp.AreaIdList.Add(i);
} }

View file

@ -5,14 +5,13 @@ using NahidaImpact.Protocol;
namespace NahidaImpact.Gameserver.Game.Avatar; namespace NahidaImpact.Gameserver.Game.Avatar;
internal class GameAvatar internal class GameAvatar
{ {
public const ulong WeaponGuid = 2281337;
public ulong Guid { get; set; } public ulong Guid { get; set; }
public uint AvatarId { get; set; } public uint AvatarId { get; set; }
public uint SkillDepotId { get; set; } public uint SkillDepotId { get; set; }
public uint WearingFlycloakId { get; set; } public uint WearingFlycloakId { get; set; }
public uint BornTime { get; set; } public uint BornTime { get; set; }
public ulong WeaponGuid { get; set; }
public uint WeaponId { get; set; } // TODO: Weapon class! public uint WeaponId { get; set; } // TODO: Weapon class!

View file

@ -12,11 +12,13 @@ internal class AvatarEntity : SceneEntity
public override ProtEntityType EntityType => ProtEntityType.Avatar; public override ProtEntityType EntityType => ProtEntityType.Avatar;
public uint Uid { get; } public uint Uid { get; }
public uint WeaponEntityId { get; }
public GameAvatar GameAvatar { get; } public GameAvatar GameAvatar { get; }
public AvatarEntity(GameAvatar gameAvatar, uint uid, uint entityId) : base(entityId) public AvatarEntity(GameAvatar gameAvatar, uint uid, uint entityId, uint weaponEntityId) : base(entityId)
{ {
Uid = uid; Uid = uid;
WeaponEntityId = ((uint)ProtEntityType.Weapon << 24) + weaponEntityId; // temporary solution, need real weapon entity object.
GameAvatar = gameAvatar; GameAvatar = gameAvatar;
Properties = gameAvatar.Properties; Properties = gameAvatar.Properties;
FightProperties = gameAvatar.FightProperties; FightProperties = gameAvatar.FightProperties;
@ -65,7 +67,7 @@ internal class AvatarEntity : SceneEntity
SkillDepotId = GameAvatar.SkillDepotId, SkillDepotId = GameAvatar.SkillDepotId,
Weapon = new SceneWeaponInfo Weapon = new SceneWeaponInfo
{ {
EntityId = SceneController.WeaponEntityId, EntityId = WeaponEntityId,
GadgetId = 50000000 + GameAvatar.WeaponId, GadgetId = 50000000 + GameAvatar.WeaponId,
ItemId = GameAvatar.WeaponId, ItemId = GameAvatar.WeaponId,
Guid = GameAvatar.WeaponGuid, Guid = GameAvatar.WeaponGuid,

View file

@ -7,6 +7,6 @@ internal class EntityFactory
public AvatarEntity CreateAvatar(GameAvatar gameAvatar, uint belongUid) public AvatarEntity CreateAvatar(GameAvatar gameAvatar, uint belongUid)
{ {
return new(gameAvatar, belongUid, ++_entityIdSeed); return new(gameAvatar, belongUid, ++_entityIdSeed, ++_entityIdSeed);
} }
} }

View file

@ -57,7 +57,8 @@ internal class Player(ExcelTableCollection excelTables)
WeaponId = avatarExcel.InitialWeapon, WeaponId = avatarExcel.InitialWeapon,
BornTime = currentTimestamp, BornTime = currentTimestamp,
Guid = NextGuid(), Guid = NextGuid(),
WearingFlycloakId = 140001 WearingFlycloakId = 140001,
WeaponGuid = NextGuid()
}; };
avatar.InitDefaultProps(avatarExcel); avatar.InitDefaultProps(avatarExcel);

View file

@ -60,13 +60,23 @@ internal class SceneManager(NetSession session, Player player, EntityManager ent
_enterState = SceneEnterState.Complete; _enterState = SceneEnterState.Complete;
} }
public async ValueTask ReplaceCurrentAvatarAsync(ulong replaceToGuid)
{
// TODO: add logic checks.
AvatarEntity avatar = _teamAvatars.Find(a => a.GameAvatar.Guid == replaceToGuid)
?? throw new ArgumentException($"ReplaceCurrentAvatar: avatar with guid {replaceToGuid} not in team!");
await _entityManager.SpawnEntityAsync(avatar, VisionType.Replace);
}
public async ValueTask ChangeTeamAvatarsAsync(ulong[] guidList) public async ValueTask ChangeTeamAvatarsAsync(ulong[] guidList)
{ {
_teamAvatars.Clear(); _teamAvatars.Clear();
foreach (ulong guid in guidList) foreach (ulong guid in guidList)
{ {
GameAvatar gameAvatar = _player.Avatars.Find(avatar => avatar.Guid == guid)!; // currently only first one GameAvatar gameAvatar = _player.Avatars.Find(avatar => avatar.Guid == guid)!;
AvatarEntity avatarEntity = _entityFactory.CreateAvatar(gameAvatar, _player.Uid); AvatarEntity avatarEntity = _entityFactory.CreateAvatar(gameAvatar, _player.Uid);
avatarEntity.SetPosition(2336.789f, 249.98896f, -751.3081f); avatarEntity.SetPosition(2336.789f, 249.98896f, -751.3081f);
@ -152,9 +162,9 @@ internal class SceneManager(NetSession session, Player player, EntityManager ent
sceneTeamUpdate.SceneTeamAvatarList.Add(new SceneTeamAvatar sceneTeamUpdate.SceneTeamAvatarList.Add(new SceneTeamAvatar
{ {
SceneEntityInfo = avatar.AsInfo(), SceneEntityInfo = avatar.AsInfo(),
WeaponEntityId = SceneController.WeaponEntityId, WeaponEntityId = avatar.WeaponEntityId,
PlayerUid = _player.Uid, PlayerUid = _player.Uid,
WeaponGuid = GameAvatar.WeaponGuid, WeaponGuid = avatar.GameAvatar.WeaponGuid,
EntityId = avatar.EntityId, EntityId = avatar.EntityId,
AvatarGuid = avatar.GameAvatar.Guid, AvatarGuid = avatar.GameAvatar.Guid,
AbilityControlBlock = avatar.BuildAbilityControlBlock(_binData), AbilityControlBlock = avatar.BuildAbilityControlBlock(_binData),
@ -191,8 +201,8 @@ internal class SceneManager(NetSession session, Player player, EntityManager ent
{ {
AvatarGuid = avatar.GameAvatar.Guid, AvatarGuid = avatar.GameAvatar.Guid,
AvatarEntityId = avatar.EntityId, AvatarEntityId = avatar.EntityId,
WeaponEntityId = SceneController.WeaponEntityId, WeaponEntityId = avatar.WeaponEntityId,
WeaponGuid = GameAvatar.WeaponGuid WeaponGuid = avatar.GameAvatar.WeaponGuid
}); });
} }