mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 17:04:13 +00:00
Implement Weapon_Evolution
This commit is contained in:
77
GameServer/Server/CallGS/Handlers/Weapon/Weapon_Evolution.cs
Normal file
77
GameServer/Server/CallGS/Handlers/Weapon/Weapon_Evolution.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Weapon;
|
||||
|
||||
// s2c: function(sErr) — send "null" on success
|
||||
// Id = target weapon UniqueId
|
||||
// nItemId = material item UniqueId (weapon or supply item to consume)
|
||||
[CallGSApi("Weapon_Evolution")]
|
||||
public class Weapon_Evolution : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<WeaponEvolutionParam>(param);
|
||||
if (req == null || req.WeaponId == 0 || req.MaterialId == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"error.BadParam\"");
|
||||
return;
|
||||
}
|
||||
|
||||
var weapon = player.InventoryManager.InventoryData.Weapons.GetValueOrDefault((uint)req.WeaponId);
|
||||
if (weapon == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"error.BadParam\"");
|
||||
return;
|
||||
}
|
||||
|
||||
var syncItems = new List<Item>();
|
||||
|
||||
// Material can be a weapon or a regular item
|
||||
if (player.InventoryManager.InventoryData.Weapons.TryGetValue((uint)req.MaterialId, out var matWeapon))
|
||||
{
|
||||
player.InventoryManager.InventoryData.Weapons.Remove((uint)req.MaterialId);
|
||||
var removed = matWeapon.ToProto();
|
||||
removed.Count = 0;
|
||||
syncItems.Add(removed);
|
||||
}
|
||||
else if (player.InventoryManager.InventoryData.Items.TryGetValue((uint)req.MaterialId, out var matItem))
|
||||
{
|
||||
matItem.ItemCount--;
|
||||
var proto = matItem.ToProto();
|
||||
if (matItem.ItemCount == 0)
|
||||
{
|
||||
player.InventoryManager.InventoryData.Items.Remove(matItem.UniqueId);
|
||||
proto.Count = 0;
|
||||
}
|
||||
syncItems.Add(proto);
|
||||
}
|
||||
else
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"tip.not_material\"");
|
||||
return;
|
||||
}
|
||||
|
||||
weapon.Evolue++;
|
||||
syncItems.Add(weapon.ToProto());
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.Items.AddRange(syncItems);
|
||||
|
||||
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "null", sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class WeaponEvolutionParam
|
||||
{
|
||||
[JsonPropertyName("Id")]
|
||||
public int WeaponId { get; set; }
|
||||
|
||||
[JsonPropertyName("nItemId")]
|
||||
public int MaterialId { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user