forked from PGR/ascnet
1
0
Fork 0

CharacterCommand works perfectly i guess

This commit is contained in:
rfi 2023-12-02 19:25:37 +07:00
parent 8bcb27b3ad
commit ea62c7a9c8
2 changed files with 25 additions and 21 deletions

View File

@ -1,5 +1,8 @@
using AscNet.Common.MsgPack;
using AscNet.Table.share.character;
using AscNet.Common.Database;
using AscNet.Common.Util;
using AscNet.Common.MsgPack;
using AscNet.GameServer.Handlers;
using AscNet.Table.V2.share.character;
namespace AscNet.GameServer.Commands
{
@ -18,33 +21,33 @@ namespace AscNet.GameServer.Commands
public override void Execute()
{
uint id = 0;
uint.TryParse(Target, out id);
int id = Miscs.ParseIntOr(Target);
List<AddCharacterRet> rets = new();
switch (Op)
{
case "add":
if (Target == "all")
{
new Thread(() =>
{
foreach (CharacterTable character in CharacterTableReader.Instance.All)
{
if (session.character.Characters.FirstOrDefault(c => c.Id == character.Id) is not null)
session.character.AddCharacter((uint)character.Id);
Thread.Sleep(100);
}
}).Start();
}
else if (id > 0)
{
if (session.character.Characters.Find(c => c.Id == id) == null)
session.character.AddCharacter(id);
foreach (var characterData in TableReaderV2.Parse<CharacterTable>().Where(x => !session.character.Characters.Any(y => y.Id == x.Id)))
rets.Add(session.character.AddCharacter((uint)characterData.Id));
}
else
throw new ArgumentException("Invalid Target / ID!");
{
if (!session.character.Characters.Any(c => c.Id == id))
rets.Add(session.character.AddCharacter((uint)id));
}
NotifyEquipDataList notifyEquipData = new();
FashionSyncNotify fashionSync = new();
NotifyCharacterDataList notifyCharacterData = new();
notifyEquipData.EquipDataList.AddRange(rets.Select(x => x.Equip));
fashionSync.FashionList.AddRange(rets.Select(x => x.Fashion));
notifyCharacterData.CharacterDataList.AddRange(rets.Select(x => x.Character));
session.SendPush(notifyEquipData);
session.SendPush(fashionSync);
session.SendPush(notifyCharacterData);
break;
default:
throw new InvalidOperationException("Invalid operation!");

View File

@ -89,6 +89,7 @@ namespace AscNet.GameServer.Handlers
fashionSync.FashionList.Add(addRet.Fashion);
notifyCharacterData.CharacterDataList.Add(addRet.Character);
session.SendPush(notifyEquipData);
session.SendPush(fashionSync);
session.SendPush(notifyCharacterData);
}
catch (ServerCodeException ex)