mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 13:23:58 +00:00
ClimbTowerLogic_SetLevelDiff
This commit is contained in:
18
Common/Data/Excel/ClimbTowerDiffExcel.cs
Normal file
18
Common/Data/Excel/ClimbTowerDiffExcel.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("challenge/climbtower/climb_tower_diff.json")]
|
||||||
|
public class ClimbTowerDiffExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("ID")] public uint ID { get; set; }
|
||||||
|
[JsonProperty("Level1")] public int Level1 { get; set; }
|
||||||
|
[JsonProperty("Level2")] public int Level2 { get; set; }
|
||||||
|
|
||||||
|
public override uint GetId() => ID;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.ClimbTowerDiffData[ID] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ public static class GameData
|
|||||||
public static Dictionary<uint, BossPvpBossExcel> BossPvpBossData { get; private set; } = [];
|
public static Dictionary<uint, BossPvpBossExcel> BossPvpBossData { get; private set; } = [];
|
||||||
public static Dictionary<uint, BossPvpNumExcel> BossPvpNumData { get; private set; } = [];
|
public static Dictionary<uint, BossPvpNumExcel> BossPvpNumData { get; private set; } = [];
|
||||||
public static Dictionary<uint, ClimbTowerTimeExcel> ClimbTowerTimeData { get; private set; } = [];
|
public static Dictionary<uint, ClimbTowerTimeExcel> ClimbTowerTimeData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, ClimbTowerDiffExcel> ClimbTowerDiffData { get; private set; } = [];
|
||||||
public static Dictionary<uint, Dictionary<int, ClimbTowerAwardExcel>> ClimbTowerAwardData { get; private set; } = [];
|
public static Dictionary<uint, Dictionary<int, ClimbTowerAwardExcel>> ClimbTowerAwardData { get; private set; } = [];
|
||||||
public static Dictionary<uint, ClimbTowerLevelOrderExcel> ClimbTowerLevelOrderData { get; private set; } = [];
|
public static Dictionary<uint, ClimbTowerLevelOrderExcel> ClimbTowerLevelOrderData { get; private set; } = [];
|
||||||
public static Dictionary<uint, TowerLevelExcel> TowerLevelData { get; private set; } = [];
|
public static Dictionary<uint, TowerLevelExcel> TowerLevelData { get; private set; } = [];
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Database;
|
||||||
|
using MikuSB.Database.Player;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Tower;
|
||||||
|
|
||||||
|
[CallGSApi("ClimbTowerLogic_SetLevelDiff")]
|
||||||
|
public class ClimbTowerLogic_SetLevelDiff : ICallGSHandler
|
||||||
|
{
|
||||||
|
private const uint TowerGroupId = 3;
|
||||||
|
private const uint DiffSid = 4;
|
||||||
|
private const uint HisDiffSid = 5;
|
||||||
|
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
var req = JsonSerializer.Deserialize<ClimbTowerSetLevelDiffParam>(param);
|
||||||
|
if (req == null || req.Diff <= 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "ClimbTowerLogic_SetLevelDiff", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GameData.ClimbTowerDiffData.ContainsKey((uint)req.Diff))
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "ClimbTowerLogic_SetLevelDiff", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hisDiff = GetAttrValue(player.Data, TowerGroupId, HisDiffSid);
|
||||||
|
if (req.Diff > hisDiff + 1)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "ClimbTowerLogic_SetLevelDiff", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var diffAttr = GetOrCreateAttr(player.Data, TowerGroupId, DiffSid);
|
||||||
|
diffAttr.Val = (uint)req.Diff;
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.Custom[player.ToPackedAttrKey(diffAttr.Gid, diffAttr.Sid)] = diffAttr.Val;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(diffAttr.Gid, diffAttr.Sid)] = diffAttr.Val;
|
||||||
|
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||||
|
await CallGSRouter.SendScript(connection, "ClimbTowerLogic_SetLevelDiff", "{}", sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetAttrValue(PlayerGameData data, uint gid, uint sid)
|
||||||
|
{
|
||||||
|
return data.Attrs.FirstOrDefault(x => x.Gid == gid && x.Sid == sid)?.Val ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlayerAttr GetOrCreateAttr(PlayerGameData data, uint gid, uint sid)
|
||||||
|
{
|
||||||
|
var attr = data.Attrs.FirstOrDefault(x => x.Gid == gid && x.Sid == sid);
|
||||||
|
if (attr != null)
|
||||||
|
return attr;
|
||||||
|
|
||||||
|
attr = new PlayerAttr
|
||||||
|
{
|
||||||
|
Gid = gid,
|
||||||
|
Sid = sid
|
||||||
|
};
|
||||||
|
data.Attrs.Add(attr);
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class ClimbTowerSetLevelDiffParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nDiff")]
|
||||||
|
public int Diff { get; set; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user