Skip to content

Commit

Permalink
Add SelectWorld handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Aug 28, 2024
1 parent fe33306 commit 62ae5ee
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,72 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Edelstein.Protocol.Gameplay.Contracts.Packets.Shared;
using Edelstein.Protocol.Gameplay.Entities;
using Edelstein.Protocol.Gameplay.Handling;
using Edelstein.Protocol.Gameplay.Login;
using Edelstein.Protocol.Gameplay.Login.Contracts.Packets;
using Edelstein.Protocol.Gameplay.Login.Contracts.Packets.Recv;
using Edelstein.Protocol.Gameplay.Login.Contracts.Packets.Send;
using Edelstein.Protocol.Services.Server;
using Edelstein.Protocol.Services.Server.Contracts;
using Edelstein.Protocol.Utilities.Pipelines;

namespace Edelstein.Common.Gameplay.Login.Handling.Pipes;

public class UserOnPacketSelectWorld : IPipe<PipedPacketMessage<ILoginStageSystem, ILoginStageSystemUser, SelectWorld>>
public class UserOnPacketSelectWorld(
IServerService servers,
IAccountWorldDataRepository accountWorldDataRepository,
ICharacterRepository characterRepository
) : IPipe<PipedPacketMessage<ILoginStageSystem, ILoginStageSystemUser, SelectWorld>>
{
public async Task Handle(IPipelineContext ctx, PipedPacketMessage<ILoginStageSystem, ILoginStageSystemUser, SelectWorld> message)
{
if (message.User.State != LoginState.SelectWorld) return;
await message.User.Dispatch(new SelectWorldResult

try
{
Result = LoginResultCode.Success,
Info = new SelectWorldResultSuccessInfo
var response = await servers.GetGameByWorldAndChannel(new ServerServiceGetByWorldAndChannelRequest
{
WorldID = message.Packet.WorldID,
ChannelID = message.Packet.ChannelID
});
var accountWorldData = await accountWorldDataRepository.RetrieveByAccountAndWorld(message.User.Account!.ID, response.Info!.WorldID) ??
await accountWorldDataRepository.Insert(new AccountWorldData
{
AccountID = message.User.Account.ID,
WorldID = response.Info.WorldID
});
var characters = await characterRepository.RetrieveAllByAccountWorldData(accountWorldData.ID);

message.User.AccountWorldData = accountWorldData;
message.User.State = LoginState.SelectCharacter;
message.User.SelectedWorldID = (byte)response.Info!.WorldID;
message.User.SelectedChannelID = (byte)response.Info!.ChannelID;

await message.User.Dispatch(new SelectWorldResult
{
Characters = new List<SelectWorldResultSuccessInfoCharacter>
Result = LoginResultCode.Success,
Info = new SelectWorldResultSuccessInfo
{
new()
{
CharacterStat = new StructuredCharacterStat
Characters = characters
.Select(c => new SelectWorldResultSuccessInfoCharacter
{
ID = 1,
Name = "Beef",
Hair = 30000,
Face = 20724
},
AvatarLook = new StructuredAvatarLook
{
Hair = 30000,
Face = 20724
}
}
},
SlotCount = 3
}
});
CharacterStat = c.ToStructuredCharacterStat(),
AvatarLook = c.ToStructuredAvatarLook()
})
.ToList(),
SlotCount = accountWorldData.CharacterSlotMax
}
});
}
catch (Exception)
{
await message.User.Dispatch(new SelectWorldResult
{
Result = LoginResultCode.Unknown
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Edelstein.Protocol.Gameplay.Contracts.Packets.Shared;

namespace Edelstein.Protocol.Gameplay.Entities;

public static class CharacterExtensions
{
public static StructuredCharacterStat ToStructuredCharacterStat(this Character character)
=> new()
{
ID = character.ID,
Name = character.Name,
Gender = character.Gender,
Skin = character.Skin,
Face = character.Face,
Hair = character.Hair,

Level = character.Level,
Job = character.Job,
STR = character.STR,
DEX = character.DEX,
INT = character.INT,
LUK = character.LUK,
HP = character.HP,
MaxHP = character.MaxHP,
MP = character.MP,
MaxMP = character.MaxMP,

AP = character.AP,
SP = character.SP,

EXP = character.EXP,
POP = character.POP,
TempEXP = character.TempEXP,

PosMap = character.FieldID,
Portal = character.FieldPortal,

Playtime = character.PlayTime,

SubJob = character.SubJob
};

public static StructuredAvatarLook ToStructuredAvatarLook(this Character character)
{
// TODO inventories

return new StructuredAvatarLook
{
Gender = character.Gender,
Skin = character.Skin,
Face = character.Face,
Hair = character.Hair
};
}
}

0 comments on commit 62ae5ee

Please sign in to comment.