mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 05:23:59 +00:00
Implemented weapon changes
This commit is contained in:
49
GameServer/Server/CallGS/Handlers/Weapon/Weapon_Replace.cs
Normal file
49
GameServer/Server/CallGS/Handlers/Weapon/Weapon_Replace.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Weapon;
|
||||
|
||||
[CallGSApi("Weapon_Replace")]
|
||||
public class Weapon_Replace : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<WeaponReplaceParam>(param);
|
||||
var cardData = req == null ? null : player.CharacterManager.GetCharacterByGUID((uint)req.CardId);
|
||||
var newWeapon = req == null ? null : player.InventoryManager.GetWeaponItem((uint)req.Id);
|
||||
|
||||
if (cardData != null && newWeapon != null)
|
||||
{
|
||||
var oldWeaponId = cardData.WeaponUniqueId;
|
||||
var oldWeapon = oldWeaponId == 0 ? null : player.InventoryManager.GetWeaponItem(oldWeaponId);
|
||||
|
||||
cardData.WeaponUniqueId = newWeapon.UniqueId;
|
||||
newWeapon.EquipAvatarId = cardData.Guid;
|
||||
|
||||
if (oldWeapon != null && oldWeapon.UniqueId != newWeapon.UniqueId)
|
||||
{
|
||||
oldWeapon.EquipAvatarId = 0;
|
||||
}
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||
|
||||
var sync = new NtfSyncPlayer
|
||||
{
|
||||
Items = { cardData.ToProto() }
|
||||
};
|
||||
await CallGSRouter.SendScript(connection, "Weapon_Replace", "{}", sync);
|
||||
return;
|
||||
}
|
||||
|
||||
await CallGSRouter.SendScript(connection, "Weapon_Replace", "{}");
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class WeaponReplaceParam
|
||||
{
|
||||
public int CardId { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user