mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 12:03:57 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4fb4d7722 | ||
|
|
6bc9090c89 | ||
|
|
bc69a072e1 | ||
|
|
2f1b6d35da | ||
|
|
2047758c18 | ||
|
|
6b48c90783 | ||
|
|
a50b0563be | ||
|
|
b78c709f76 | ||
|
|
12094f6dd1 | ||
|
|
c3b675dc34 |
89
Common/Data/Excel/FishingFoodExcel.cs
Normal file
89
Common/Data/Excel/FishingFoodExcel.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("dlc/fishing/food.json")]
|
||||
public class FishingFoodExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("ID")] public uint Id { get; set; }
|
||||
[JsonProperty("FoodType")] public JToken? FoodTypeRaw { get; set; }
|
||||
[JsonProperty("NeedItem")] public JToken? NeedItemRaw { get; set; }
|
||||
[JsonProperty("CreateItems")] public JToken? CreateItemsRaw { get; set; }
|
||||
[JsonProperty("EffectTime")] public JToken? EffectTimeRaw { get; set; }
|
||||
[JsonProperty("FishingLevel")] public JToken? FishingLevelRaw { get; set; }
|
||||
[JsonProperty("SeasonId")] public JToken? SeasonIdRaw { get; set; }
|
||||
[JsonProperty("BaitNum")] public JToken? BaitNumRaw { get; set; }
|
||||
[JsonProperty("FoodArea")] public JToken? FoodAreaRaw { get; set; }
|
||||
|
||||
[JsonIgnore] public uint FoodType => ReadUInt(FoodTypeRaw);
|
||||
[JsonIgnore] public uint EffectTime => ReadUInt(EffectTimeRaw);
|
||||
[JsonIgnore] public uint FishingLevel => ReadUInt(FishingLevelRaw);
|
||||
[JsonIgnore] public uint SeasonId => ReadUInt(SeasonIdRaw);
|
||||
[JsonIgnore] public List<List<uint>> NeedItem => ReadNestedUIntList(NeedItemRaw);
|
||||
[JsonIgnore] public List<uint> CreateItems => ReadUIntList(CreateItemsRaw);
|
||||
[JsonIgnore] public List<uint> BaitNum => ReadUIntList(BaitNumRaw);
|
||||
[JsonIgnore] public List<uint> FoodArea => ReadUIntList(FoodAreaRaw);
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.FishingFoodData[Id] = this;
|
||||
}
|
||||
|
||||
private static int ReadInt(JToken? token)
|
||||
{
|
||||
if (token == null)
|
||||
return 0;
|
||||
|
||||
return token.Type switch
|
||||
{
|
||||
JTokenType.Integer => token.Value<int>(),
|
||||
JTokenType.Float => (int)token.Value<decimal>(),
|
||||
JTokenType.String when int.TryParse(token.Value<string>(), out var value) => value,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
private static uint ReadUInt(JToken? token)
|
||||
{
|
||||
var value = ReadInt(token);
|
||||
return value > 0 ? (uint)value : 0;
|
||||
}
|
||||
|
||||
private static List<uint> ReadUIntList(JToken? token)
|
||||
{
|
||||
if (token is not JArray array)
|
||||
return [];
|
||||
|
||||
var result = new List<uint>(array.Count);
|
||||
foreach (var item in array)
|
||||
{
|
||||
var value = ReadUInt(item);
|
||||
if (value > 0)
|
||||
result.Add(value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<List<uint>> ReadNestedUIntList(JToken? token)
|
||||
{
|
||||
if (token is not JArray array)
|
||||
return [];
|
||||
|
||||
var result = new List<List<uint>>(array.Count);
|
||||
foreach (var row in array.OfType<JArray>())
|
||||
{
|
||||
var values = new List<uint>(row.Count);
|
||||
foreach (var item in row)
|
||||
{
|
||||
values.Add(ReadUInt(item));
|
||||
}
|
||||
result.Add(values);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
26
Common/Data/Excel/MonsterCardExcel.cs
Normal file
26
Common/Data/Excel/MonsterCardExcel.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("item/templates/monster_card.json")]
|
||||
public class MonsterCardExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("Genre")] public uint Genre { get; set; }
|
||||
[JsonProperty("Detail")] public uint Detail { get; set; }
|
||||
[JsonProperty("Particular")] public uint Particular { get; set; }
|
||||
[JsonProperty("Level")] public uint Level { get; set; }
|
||||
[JsonProperty("Color")] public uint Color { get; set; }
|
||||
[JsonProperty("RikiId")] public uint RikiId { get; set; }
|
||||
[JsonProperty("CostValue")] public uint CostValue { get; set; }
|
||||
[JsonProperty("Exp")] public uint Exp { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ulong TemplateId => GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
|
||||
|
||||
public override uint GetId() => Particular;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.MonsterCardData[TemplateId] = this;
|
||||
}
|
||||
}
|
||||
20
Common/Data/Excel/VirCaptureCaptureRegionExcel.cs
Normal file
20
Common/Data/Excel/VirCaptureCaptureRegionExcel.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("dlc/vircapture/captureregion.json")]
|
||||
public class VirCaptureCaptureRegionExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("Id")] public uint Id { get; set; }
|
||||
[JsonProperty("StartTime")] public string StartTime { get; set; } = "";
|
||||
[JsonProperty("EndTime")] public string EndTime { get; set; } = "";
|
||||
[JsonProperty("MapId")] public uint MapId { get; set; }
|
||||
[JsonProperty("LevelRegionName")] public string LevelRegionName { get; set; } = "";
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.VirCaptureCaptureRegionData[Id] = this;
|
||||
}
|
||||
}
|
||||
20
Common/Data/Excel/VirCaptureLevelListExcel.cs
Normal file
20
Common/Data/Excel/VirCaptureLevelListExcel.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("dlc/vircapture/levellist.json")]
|
||||
public class VirCaptureLevelListExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("Level")] public uint Level { get; set; }
|
||||
[JsonProperty("Exp")] public uint Exp { get; set; }
|
||||
[JsonProperty("Num")] public uint Num { get; set; }
|
||||
[JsonProperty("MaxCost")] public uint MaxCost { get; set; }
|
||||
[JsonProperty("ExpUp")] public double ExpUp { get; set; }
|
||||
|
||||
public override uint GetId() => Level;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.VirCaptureLevelListData[Level] = this;
|
||||
}
|
||||
}
|
||||
18
Common/Data/Excel/VirCaptureSeasonExcel.cs
Normal file
18
Common/Data/Excel/VirCaptureSeasonExcel.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("dlc/vircapture/season.json")]
|
||||
public class VirCaptureSeasonExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("Id")] public uint Id { get; set; }
|
||||
[JsonProperty("StartTime")] public string StartTime { get; set; } = "";
|
||||
[JsonProperty("EndTime")] public string EndTime { get; set; } = "";
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.VirCaptureSeasonData[Id] = this;
|
||||
}
|
||||
}
|
||||
20
Common/Data/Excel/VirCaptureTimeExcel.cs
Normal file
20
Common/Data/Excel/VirCaptureTimeExcel.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("dlc/vircapture/timelist.json")]
|
||||
public class VirCaptureTimeExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("Id")] public uint Id { get; set; }
|
||||
[JsonProperty("StartTime")] public string StartTime { get; set; } = "";
|
||||
[JsonProperty("EndTime")] public string EndTime { get; set; } = "";
|
||||
[JsonProperty("CaptureRegionId")] public List<uint> CaptureRegionId { get; set; } = [];
|
||||
[JsonProperty("MaxExp")] public uint MaxExp { get; set; }
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.VirCaptureTimeData[Id] = this;
|
||||
}
|
||||
}
|
||||
44
Common/Data/Excel/VirCaptureTowerExcel.cs
Normal file
44
Common/Data/Excel/VirCaptureTowerExcel.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("dlc/vircapture/tower.json")]
|
||||
public class VirCaptureTowerExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("ID")] public uint Id { get; set; }
|
||||
[JsonProperty("Condition")] public JToken? ConditionRaw { get; set; }
|
||||
[JsonProperty("MapID")] public uint MapId { get; set; }
|
||||
[JsonProperty("TrialCard")] public List<uint> TrialCard { get; set; } = [];
|
||||
[JsonProperty("TaskPath")] public string TaskPath { get; set; } = "";
|
||||
|
||||
[JsonIgnore]
|
||||
public Dictionary<int, uint> Condition { get; } = [];
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
Condition.Clear();
|
||||
if (ConditionRaw is JObject obj)
|
||||
{
|
||||
foreach (var property in obj.Properties())
|
||||
{
|
||||
if (!int.TryParse(property.Name, out var key))
|
||||
continue;
|
||||
|
||||
uint value = 0;
|
||||
if (property.Value.Type == JTokenType.Integer)
|
||||
value = property.Value.Value<uint>();
|
||||
else if (property.Value.Type == JTokenType.String &&
|
||||
uint.TryParse(property.Value.Value<string>(), out var parsed))
|
||||
value = parsed;
|
||||
|
||||
if (value > 0)
|
||||
Condition[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
GameData.VirCaptureTowerData[Id] = this;
|
||||
}
|
||||
}
|
||||
19
Common/Data/Excel/VirCaptureTrialTimeExcel.cs
Normal file
19
Common/Data/Excel/VirCaptureTrialTimeExcel.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MikuSB.Data.Excel;
|
||||
|
||||
[ResourceEntity("dlc/vircapture/trial_timelist.json")]
|
||||
public class VirCaptureTrialTimeExcel : ExcelResource
|
||||
{
|
||||
[JsonProperty("Id")] public uint Id { get; set; }
|
||||
[JsonProperty("StartTime")] public string StartTime { get; set; } = "";
|
||||
[JsonProperty("EndTime")] public string EndTime { get; set; } = "";
|
||||
[JsonProperty("AwardTime")] public string AwardTime { get; set; } = "";
|
||||
|
||||
public override uint GetId() => Id;
|
||||
|
||||
public override void Loaded()
|
||||
{
|
||||
GameData.VirCaptureTrialTimeData[Id] = this;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,14 @@ public static class GameData
|
||||
public static Dictionary<uint, GachaExcel> GachaData { get; private set; } = [];
|
||||
public static Dictionary<uint, GachaProbabilityExcel> GachaProbabilityData { get; private set; } = [];
|
||||
public static Dictionary<string, List<GachaPoolItem>> GachaPoolData { get; private set; } = [];
|
||||
public static Dictionary<uint, VirCaptureTimeExcel> VirCaptureTimeData { get; private set; } = [];
|
||||
public static Dictionary<uint, VirCaptureSeasonExcel> VirCaptureSeasonData { get; private set; } = [];
|
||||
public static Dictionary<uint, VirCaptureTrialTimeExcel> VirCaptureTrialTimeData { get; private set; } = [];
|
||||
public static Dictionary<uint, VirCaptureCaptureRegionExcel> VirCaptureCaptureRegionData { get; private set; } = [];
|
||||
public static Dictionary<uint, VirCaptureLevelListExcel> VirCaptureLevelListData { get; private set; } = [];
|
||||
public static Dictionary<ulong, MonsterCardExcel> MonsterCardData { get; private set; } = [];
|
||||
public static Dictionary<uint, FishingFoodExcel> FishingFoodData { get; private set; } = [];
|
||||
public static Dictionary<uint, VirCaptureTowerExcel> VirCaptureTowerData { get; private set; } = [];
|
||||
}
|
||||
|
||||
public static class GameResourceTemplateId
|
||||
|
||||
@@ -208,6 +208,27 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
|
||||
return InventoryData.Items.Values.FirstOrDefault(x => x.TemplateId == templateId);
|
||||
}
|
||||
|
||||
public async ValueTask<BaseGameItemInfo?> AddMonsterCardItem(uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||
{
|
||||
const ItemTypeEnum genre = ItemTypeEnum.TYPE_MONSTER_CARD;
|
||||
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
|
||||
if (!GameData.MonsterCardData.ContainsKey(templateId))
|
||||
return null;
|
||||
|
||||
var monsterInfo = new BaseGameItemInfo
|
||||
{
|
||||
TemplateId = templateId,
|
||||
UniqueId = InventoryData.NextUniqueUid++,
|
||||
ItemType = genre,
|
||||
ItemCount = 1
|
||||
};
|
||||
InventoryData.Items[monsterInfo.UniqueId] = monsterInfo;
|
||||
|
||||
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([monsterInfo]));
|
||||
|
||||
return monsterInfo;
|
||||
}
|
||||
|
||||
private static uint GetSuppliesMaxCount(SuppliesExcel suppliesData) =>
|
||||
suppliesData.Genre == 5 && suppliesData.Detail == 4 ? 999999u : 99999u;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Text.Json.Serialization;
|
||||
using MikuSB.GameServer.Game.BossPvp;
|
||||
using MikuSB.Proto;
|
||||
using MikuSB.GameServer.Server.CallGS.Handlers.Tower;
|
||||
using MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Chapter;
|
||||
|
||||
@@ -72,6 +73,13 @@ public class Chapter_DealLevelSettlement : ICallGSHandler
|
||||
return response;
|
||||
}
|
||||
|
||||
if (string.Equals(sCmd, "VirCaptureTower_LevelSettlement", StringComparison.Ordinal))
|
||||
{
|
||||
var (response, sync) = VirCaptureTower_LevelSettlement.HandleSettlement(connection.Player!, tbParam);
|
||||
extraSync = sync;
|
||||
return response;
|
||||
}
|
||||
|
||||
return tbParam?.DeepClone() ?? new JsonObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Data.Excel;
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Database.Inventory;
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.Enums.Item;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Fishing;
|
||||
|
||||
[CallGSApi("FishingServer_ConvertFood")]
|
||||
public class FishingServer_ConvertFood : ICallGSHandler
|
||||
{
|
||||
private const uint FishingGroupId = 32;
|
||||
private const uint CashGroupId = 1;
|
||||
private const uint FoodBaseSid = 30000;
|
||||
private const uint FoodAvaTimeSubType = 1;
|
||||
private const uint ExploreAvaTimeSubType = 2;
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var player = connection.Player!;
|
||||
var req = JsonSerializer.Deserialize<FishingConvertFoodParam>(param);
|
||||
if (req == null || req.FoodId <= 0 || req.Num <= 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "FishingServer_ConvertFood", "{\"sError\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GameData.FishingFoodData.TryGetValue((uint)req.FoodId, out var food))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "FishingServer_ConvertFood", "{\"sError\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var count = Math.Max(1u, req.Num);
|
||||
var sync = new NtfSyncPlayer();
|
||||
|
||||
if (!HasEnoughMaterials(player.InventoryManager.InventoryData, food.NeedItem, count) ||
|
||||
!HasEnoughCash(player.Data, food.BaitNum, count))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "FishingServer_ConvertFood", "{\"sError\":\"tip.girlcard_cmd_err\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
ConsumeMaterials(player.InventoryManager.InventoryData, food.NeedItem, count, sync.Items);
|
||||
ConsumeCash(player, food.BaitNum, count, sync);
|
||||
|
||||
var response = new JsonObject
|
||||
{
|
||||
["nFoodID"] = req.FoodId
|
||||
};
|
||||
|
||||
switch (food.FoodType)
|
||||
{
|
||||
case 1:
|
||||
ApplyFoodDuration(player, food, FoodAvaTimeSubType, count, sync);
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
var rewards = await CreateItemsAsync(player, sync, food.CreateItems, count);
|
||||
response["tbBait"] = rewards;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
ApplyFoodDuration(player, food, ExploreAvaTimeSubType, count, sync);
|
||||
break;
|
||||
default:
|
||||
await CallGSRouter.SendScript(connection, "FishingServer_ConvertFood", "{\"sError\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
|
||||
await CallGSRouter.SendScript(connection, "FishingServer_ConvertFood", response.ToJsonString(), sync);
|
||||
}
|
||||
|
||||
private static bool HasEnoughMaterials(InventoryData inventory, IEnumerable<List<uint>> costs, uint multiplier)
|
||||
{
|
||||
foreach (var cost in costs)
|
||||
{
|
||||
if (cost.Count < 5)
|
||||
return false;
|
||||
|
||||
var templateId = GameResourceTemplateId.FromGdpl(cost[0], cost[1], cost[2], cost[3]);
|
||||
var item = inventory.Items.Values.FirstOrDefault(x => x.TemplateId == templateId);
|
||||
var needCount = checked(cost[4] * multiplier);
|
||||
if (item == null || item.ItemCount < needCount)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void ConsumeMaterials(InventoryData inventory, IEnumerable<List<uint>> costs, uint multiplier, ICollection<Item> syncItems)
|
||||
{
|
||||
foreach (var cost in costs)
|
||||
{
|
||||
var templateId = GameResourceTemplateId.FromGdpl(cost[0], cost[1], cost[2], cost[3]);
|
||||
var item = inventory.Items.Values.First(x => x.TemplateId == templateId);
|
||||
var needCount = checked(cost[4] * multiplier);
|
||||
item.ItemCount -= needCount;
|
||||
|
||||
if (item.ItemCount == 0)
|
||||
{
|
||||
inventory.Items.Remove(item.UniqueId);
|
||||
var proto = item.ToProto();
|
||||
proto.Count = 0;
|
||||
syncItems.Add(proto);
|
||||
}
|
||||
else
|
||||
{
|
||||
syncItems.Add(item.ToProto());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool HasEnoughCash(PlayerGameData data, IReadOnlyList<uint> baitNum, uint multiplier)
|
||||
{
|
||||
if (baitNum.Count < 2)
|
||||
return true;
|
||||
|
||||
var moneyType = baitNum[0];
|
||||
var need = checked(baitNum[1] * multiplier);
|
||||
var sid = moneyType * 2 + 1;
|
||||
var attr = data.Attrs.FirstOrDefault(x => x.Gid == CashGroupId && x.Sid == sid);
|
||||
return (attr?.Val ?? 0) >= need;
|
||||
}
|
||||
|
||||
private static void ConsumeCash(MikuSB.GameServer.Game.Player.PlayerInstance player, IReadOnlyList<uint> baitNum, uint multiplier, NtfSyncPlayer sync)
|
||||
{
|
||||
if (baitNum.Count < 2)
|
||||
return;
|
||||
|
||||
var moneyType = baitNum[0];
|
||||
var sid = moneyType * 2 + 1;
|
||||
var need = checked(baitNum[1] * multiplier);
|
||||
var attr = GetOrCreateAttr(player.Data, CashGroupId, sid);
|
||||
attr.Val -= need;
|
||||
SyncAttr(player, sync, attr);
|
||||
}
|
||||
|
||||
private static void ApplyFoodDuration(MikuSB.GameServer.Game.Player.PlayerInstance player, FishingFoodExcel food, uint subType, uint count, NtfSyncPlayer sync)
|
||||
{
|
||||
var sid = FoodBaseSid + food.Id * 10 + subType;
|
||||
var attr = GetOrCreateAttr(player.Data, FishingGroupId, sid);
|
||||
var now = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
var startTime = Math.Max(attr.Val, now);
|
||||
attr.Val = checked(startTime + food.EffectTime * count);
|
||||
SyncAttr(player, sync, attr);
|
||||
}
|
||||
|
||||
private static async Task<JsonArray> CreateItemsAsync(MikuSB.GameServer.Game.Player.PlayerInstance player, NtfSyncPlayer sync, IReadOnlyList<uint> createItem, uint multiplier)
|
||||
{
|
||||
var rewards = new JsonArray();
|
||||
if (createItem.Count < 5)
|
||||
return rewards;
|
||||
|
||||
var itemType = (ItemTypeEnum)createItem[0];
|
||||
var detail = createItem[1];
|
||||
var particular = createItem[2];
|
||||
var level = createItem[3];
|
||||
var totalCount = checked(createItem[4] * multiplier);
|
||||
|
||||
switch (itemType)
|
||||
{
|
||||
case ItemTypeEnum.TYPE_SUPPLIES:
|
||||
{
|
||||
var templateId = (uint)GameResourceTemplateId.FromGdpl(createItem[0], detail, particular, level);
|
||||
if (GameData.SuppliesData.TryGetValue(templateId, out var supplies))
|
||||
{
|
||||
var item = await player.InventoryManager.AddSuppliesItem(supplies, totalCount, sendPacket: false);
|
||||
if (item != null)
|
||||
sync.Items.Add(item.ToProto());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ItemTypeEnum.TYPE_USEABLE:
|
||||
{
|
||||
var item = AddOtherItem(player.InventoryManager.InventoryData, detail, particular, level, totalCount);
|
||||
if (item != null)
|
||||
sync.Items.Add(item.ToProto());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rewards.Add(new JsonArray((int)createItem[0], (int)detail, (int)particular, (int)level, (int)totalCount));
|
||||
return rewards;
|
||||
}
|
||||
|
||||
private static BaseGameItemInfo? AddOtherItem(InventoryData inventory, uint detail, uint particular, uint level, uint count)
|
||||
{
|
||||
var templateId = (uint)GameResourceTemplateId.FromGdpl((uint)ItemTypeEnum.TYPE_USEABLE, detail, particular, level);
|
||||
if (!GameData.OtherItemData.TryGetValue(templateId, out var otherItem))
|
||||
return null;
|
||||
|
||||
var maxCount = otherItem.GMnum > 0 ? otherItem.GMnum : 99999u;
|
||||
var existing = inventory.Items.Values.FirstOrDefault(x => x.TemplateId == templateId);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.ItemCount = Math.Min(existing.ItemCount + count, maxCount);
|
||||
return existing;
|
||||
}
|
||||
|
||||
var item = new BaseGameItemInfo
|
||||
{
|
||||
TemplateId = templateId,
|
||||
UniqueId = inventory.NextUniqueUid++,
|
||||
ItemType = ItemTypeEnum.TYPE_USEABLE,
|
||||
ItemCount = Math.Min(count, maxCount)
|
||||
};
|
||||
inventory.Items[item.UniqueId] = item;
|
||||
return item;
|
||||
}
|
||||
|
||||
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, Val = 0 };
|
||||
data.Attrs.Add(attr);
|
||||
return attr;
|
||||
}
|
||||
|
||||
private static void SyncAttr(MikuSB.GameServer.Game.Player.PlayerInstance player, NtfSyncPlayer sync, PlayerAttr attr)
|
||||
{
|
||||
sync.Custom[player.ToPackedAttrKey(attr.Gid, attr.Sid)] = attr.Val;
|
||||
sync.Custom[player.ToShiftedAttrKey(attr.Gid, attr.Sid)] = attr.Val;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class FishingConvertFoodParam
|
||||
{
|
||||
[JsonPropertyName("nFoodID")]
|
||||
public int FoodId { get; set; }
|
||||
|
||||
[JsonPropertyName("nNum")]
|
||||
public uint Num { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
using MikuSB.Data.Excel;
|
||||
using MikuSB.Util;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
internal static class VirCaptureCaptureRewardResolver
|
||||
{
|
||||
private static readonly Lock CacheLock = new();
|
||||
private static readonly Dictionary<string, Dictionary<uint, VirCaptureLevelRegionReward>> RegionCache = [];
|
||||
private static readonly Dictionary<string, Dictionary<uint, List<uint>>> BossCache = [];
|
||||
|
||||
public static List<uint>? ResolveGdpl(VirCaptureCaptureRegionExcel captureRegion, uint regionId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(captureRegion.LevelRegionName))
|
||||
return null;
|
||||
|
||||
var regionMap = GetOrLoadRegionMap(captureRegion.LevelRegionName);
|
||||
if (!regionMap.TryGetValue(regionId, out var regionReward))
|
||||
return null;
|
||||
|
||||
if (regionReward.PalType == 2)
|
||||
return GetOrLoadBossMap(captureRegion.LevelRegionName).GetValueOrDefault(regionId);
|
||||
|
||||
return regionReward.Rewards1;
|
||||
}
|
||||
|
||||
private static Dictionary<uint, VirCaptureLevelRegionReward> GetOrLoadRegionMap(string mapName)
|
||||
{
|
||||
lock (CacheLock)
|
||||
{
|
||||
if (RegionCache.TryGetValue(mapName, out var cached))
|
||||
return cached;
|
||||
|
||||
var loaded = new Dictionary<uint, VirCaptureLevelRegionReward>();
|
||||
var path = Path.Combine(
|
||||
ConfigManager.Config.Path.ResourcePath,
|
||||
"dlc",
|
||||
"vircapture",
|
||||
mapName,
|
||||
"region_info.json");
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var array = JArray.Parse(File.ReadAllText(path));
|
||||
foreach (var token in array)
|
||||
{
|
||||
var id = ReadUInt(token["Id"]);
|
||||
if (id == 0)
|
||||
continue;
|
||||
|
||||
loaded[id] = new VirCaptureLevelRegionReward
|
||||
{
|
||||
PalType = ReadInt(token["PalType"]),
|
||||
Rewards1 = token["Rewards1"]?.ToObject<List<uint>>() ?? []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
RegionCache[mapName] = loaded;
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<uint, List<uint>> GetOrLoadBossMap(string mapName)
|
||||
{
|
||||
lock (CacheLock)
|
||||
{
|
||||
if (BossCache.TryGetValue(mapName, out var cached))
|
||||
return cached;
|
||||
|
||||
var loaded = new Dictionary<uint, List<uint>>();
|
||||
var path = Path.Combine(
|
||||
ConfigManager.Config.Path.ResourcePath,
|
||||
"dlc",
|
||||
"vircapture",
|
||||
mapName,
|
||||
"boss.json");
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var array = JArray.Parse(File.ReadAllText(path));
|
||||
foreach (var token in array)
|
||||
{
|
||||
var regionId = ReadUInt(token["RegionId"]);
|
||||
var boss = token["Boss"]?.ToObject<List<uint>>();
|
||||
if (regionId == 0 || boss == null || boss.Count < 4)
|
||||
continue;
|
||||
|
||||
loaded.TryAdd(regionId, boss);
|
||||
}
|
||||
}
|
||||
|
||||
BossCache[mapName] = loaded;
|
||||
return loaded;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class VirCaptureLevelRegionReward
|
||||
{
|
||||
public int PalType { get; init; }
|
||||
public List<uint> Rewards1 { get; init; } = [];
|
||||
}
|
||||
|
||||
private static uint ReadUInt(JToken? token)
|
||||
{
|
||||
if (token == null || token.Type == JTokenType.Null)
|
||||
return 0;
|
||||
|
||||
return token.Type switch
|
||||
{
|
||||
JTokenType.Integer => token.Value<uint>(),
|
||||
JTokenType.Float => Math.Max(0u, (uint)token.Value<double>()),
|
||||
JTokenType.String when uint.TryParse(token.Value<string>(), out var value) => value,
|
||||
JTokenType.String => 0,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
private static int ReadInt(JToken? token)
|
||||
{
|
||||
if (token == null || token.Type == JTokenType.Null)
|
||||
return 0;
|
||||
|
||||
return token.Type switch
|
||||
{
|
||||
JTokenType.Integer => token.Value<int>(),
|
||||
JTokenType.Float => (int)token.Value<double>(),
|
||||
JTokenType.String when int.TryParse(token.Value<string>(), out var value) => value,
|
||||
JTokenType.String => 0,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCaptureLevel_ChangeFlag")]
|
||||
public class VirCaptureLevel_ChangeFlag : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<VirCaptureChangeFlagParam>(param);
|
||||
if (req == null || req.LevelId == 0 || req.RegionId == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_ChangeFlag", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var sync = new NtfSyncPlayer();
|
||||
VirCaptureStateHelper.SetPointState(player, (uint)req.LevelId, (uint)req.RegionId, req.Clean ? 0u : 1u, sync);
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
var rsp = $"{{\"nLevelID\":{req.LevelId},\"nRegionId\":{req.RegionId},\"bClean\":{req.Clean.ToString().ToLowerInvariant()}}}";
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_ChangeFlag", rsp, sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureChangeFlagParam
|
||||
{
|
||||
[JsonPropertyName("nLevelID")]
|
||||
public int LevelId { get; set; }
|
||||
|
||||
[JsonPropertyName("nRegionId")]
|
||||
public int RegionId { get; set; }
|
||||
|
||||
[JsonPropertyName("bClean")]
|
||||
public bool Clean { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Data.Excel;
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.GameServer.Game.Player;
|
||||
using MikuSB.Proto;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCaptureLevel_EnterLevel")]
|
||||
public class VirCaptureLevel_EnterLevel : ICallGSHandler
|
||||
{
|
||||
private const uint GroupId = 128;
|
||||
private const uint MapDataStart = 10000;
|
||||
private const uint MaxMapCount = 3;
|
||||
private const uint MaxMapDataLen = 3000;
|
||||
private const uint OffMapId = 1;
|
||||
private const uint OffDayNight = 7;
|
||||
private const uint OffMapLevel = 8;
|
||||
private static readonly Random Random = new();
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<VirCaptureEnterLevelParam>(param);
|
||||
if (req == null || req.LevelId == 0 || req.TeamId <= 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_EnterLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
var act = ResolveCurrent(GameData.VirCaptureTimeData.Values, now);
|
||||
if (act == null || !act.CaptureRegionId.Contains((uint)req.LevelId))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_EnterLevel", "{\"sErr\":\"ui.TxtNotOpen\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GameData.VirCaptureCaptureRegionData.TryGetValue((uint)req.LevelId, out var region))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_EnterLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var regionStart = ParseConfigTime(region.StartTime);
|
||||
var regionEnd = ParseConfigTime(region.EndTime);
|
||||
if (!regionStart.HasValue || !regionEnd.HasValue || now < regionStart.Value || now >= regionEnd.Value)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_EnterLevel", "{\"sErr\":\"ui.TxtNotOpen\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var sync = new NtfSyncPlayer();
|
||||
EnsureMapState(player, (uint)req.LevelId, sync);
|
||||
|
||||
var rsp = $"{{\"nSeed\":{Random.Next(1, 1_000_000_000)}}}";
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_EnterLevel", rsp, sync);
|
||||
}
|
||||
|
||||
private static void EnsureMapState(PlayerInstance player, uint levelId, NtfSyncPlayer sync)
|
||||
{
|
||||
var slotStart = FindOrAllocateMapSlot(player, levelId);
|
||||
if (slotStart == 0)
|
||||
return;
|
||||
|
||||
EnsureMapAttr(player, slotStart + OffMapId, levelId, sync);
|
||||
EnsureMapAttr(player, slotStart + OffDayNight, 1, sync);
|
||||
EnsureMapAttr(player, slotStart + OffMapLevel, 1, sync);
|
||||
}
|
||||
|
||||
private static uint FindOrAllocateMapSlot(PlayerInstance player, uint levelId)
|
||||
{
|
||||
uint? emptySlot = null;
|
||||
for (uint i = 0; i < MaxMapCount; i++)
|
||||
{
|
||||
var slotStart = MapDataStart + (i * MaxMapDataLen);
|
||||
var mapIdAttr = player.Data.Attrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == slotStart + OffMapId);
|
||||
if (mapIdAttr?.Val == levelId)
|
||||
return slotStart;
|
||||
|
||||
if (emptySlot == null && (mapIdAttr == null || mapIdAttr.Val == 0))
|
||||
emptySlot = slotStart;
|
||||
}
|
||||
|
||||
return emptySlot ?? 0;
|
||||
}
|
||||
|
||||
private static void EnsureMapAttr(PlayerInstance player, uint sid, uint minValue, NtfSyncPlayer sync)
|
||||
{
|
||||
var attr = player.Data.Attrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == sid);
|
||||
if (attr == null)
|
||||
{
|
||||
attr = new PlayerAttr
|
||||
{
|
||||
Gid = GroupId,
|
||||
Sid = sid,
|
||||
Val = minValue
|
||||
};
|
||||
player.Data.Attrs.Add(attr);
|
||||
SyncAttr(player, sync, sid, minValue);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attr.Val < minValue)
|
||||
{
|
||||
attr.Val = minValue;
|
||||
SyncAttr(player, sync, sid, attr.Val);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SyncAttr(PlayerInstance player, NtfSyncPlayer sync, uint sid, uint value)
|
||||
{
|
||||
sync.Custom[player.ToPackedAttrKey(GroupId, sid)] = value;
|
||||
sync.Custom[player.ToShiftedAttrKey(GroupId, sid)] = value;
|
||||
}
|
||||
|
||||
private static VirCaptureTimeExcel? ResolveCurrent(IEnumerable<VirCaptureTimeExcel> configs, DateTime now)
|
||||
{
|
||||
var parsed = configs
|
||||
.Select(x => new
|
||||
{
|
||||
Config = x,
|
||||
Start = ParseConfigTime(x.StartTime),
|
||||
End = ParseConfigTime(x.EndTime)
|
||||
})
|
||||
.Where(x => x.Start.HasValue && x.End.HasValue)
|
||||
.OrderBy(x => x.Start)
|
||||
.ToList();
|
||||
|
||||
var current = parsed.FirstOrDefault(x => x.Start <= now && now < x.End);
|
||||
if (current != null)
|
||||
return current.Config;
|
||||
|
||||
var latestStarted = parsed.LastOrDefault(x => x.Start <= now);
|
||||
if (latestStarted != null && latestStarted.End > latestStarted.Start)
|
||||
return latestStarted.Config;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static DateTime? ParseConfigTime(string? raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
return null;
|
||||
|
||||
var normalized = raw.Trim().Trim('[', ']');
|
||||
if (normalized.Length != 12)
|
||||
return null;
|
||||
|
||||
return DateTime.TryParseExact(
|
||||
normalized,
|
||||
"yyyyMMddHHmm",
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None,
|
||||
out var value)
|
||||
? value
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureEnterLevelParam
|
||||
{
|
||||
[JsonPropertyName("nLevelID")]
|
||||
public int LevelId { get; set; }
|
||||
|
||||
[JsonPropertyName("nTeamID")]
|
||||
public int TeamId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Enums.Item;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCaptureLevel_SaveCapture")]
|
||||
public class VirCaptureLevel_SaveCapture : ICallGSHandler
|
||||
{
|
||||
private const uint VirCaptureGroupId = 128;
|
||||
private const uint CurExpSid = 2;
|
||||
private const uint CurLevelSid = 3;
|
||||
private const uint BagNumSid = 5;
|
||||
private const uint DailyExpSid = 8;
|
||||
private const uint ColorMaxStartSid = 11;
|
||||
private const uint RikiGroupId = 135;
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<VirCaptureSaveCaptureParam>(param);
|
||||
if (req == null || req.LevelId == 0 || req.RegionId == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SaveCapture", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var sync = new NtfSyncPlayer();
|
||||
VirCaptureStateHelper.SetPointState(player, (uint)req.LevelId, (uint)req.RegionId, 2u, sync);
|
||||
|
||||
if (!GameData.VirCaptureCaptureRegionData.TryGetValue((uint)req.LevelId, out var captureRegion))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SaveCapture", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var rewardGdpl = VirCaptureCaptureRewardResolver.ResolveGdpl(captureRegion, (uint)req.RegionId);
|
||||
if (rewardGdpl == null || rewardGdpl.Count < 4 || rewardGdpl[0] != (uint)ItemTypeEnum.TYPE_MONSTER_CARD)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SaveCapture", "{\"sErr\":\"error.BadParam\"}", sync);
|
||||
return;
|
||||
}
|
||||
|
||||
var grantedItem = await player.InventoryManager.AddMonsterCardItem(
|
||||
rewardGdpl[1],
|
||||
rewardGdpl[2],
|
||||
rewardGdpl[3],
|
||||
sendPacket: false);
|
||||
if (grantedItem == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SaveCapture", "{\"sErr\":\"error.BadParam\"}", sync);
|
||||
return;
|
||||
}
|
||||
|
||||
sync.Items.Add(grantedItem.ToProto());
|
||||
SyncVirCaptureCounters(player, grantedItem.TemplateId, sync);
|
||||
ApplyCaptureExp(player, grantedItem.TemplateId, sync);
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||
|
||||
var response = new JsonObject
|
||||
{
|
||||
["nLevelID"] = req.LevelId,
|
||||
["nRegionId"] = req.RegionId,
|
||||
["nAddItemId"] = grantedItem.UniqueId,
|
||||
["tbGDPL"] = new JsonArray(rewardGdpl.Select(x => JsonValue.Create((int)x)).ToArray())
|
||||
};
|
||||
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SaveCapture", response.ToJsonString(), sync);
|
||||
}
|
||||
|
||||
private static void SyncVirCaptureCounters(MikuSB.GameServer.Game.Player.PlayerInstance player, ulong templateId, NtfSyncPlayer sync)
|
||||
{
|
||||
var bagCount = (uint)player.InventoryManager.InventoryData.Items.Values.Count(x => x.ItemType == ItemTypeEnum.TYPE_MONSTER_CARD);
|
||||
VirCaptureStateHelper.SetUnsignedAttr(player, BagNumSid, bagCount, sync);
|
||||
|
||||
if (!GameData.MonsterCardData.TryGetValue(templateId, out var monsterCard) || monsterCard.RikiId == 0)
|
||||
return;
|
||||
|
||||
var colorSid = ColorMaxStartSid + Math.Max(0u, monsterCard.Color - 1u);
|
||||
var colorAttr = player.Data.Attrs.FirstOrDefault(x => x.Gid == VirCaptureGroupId && x.Sid == colorSid);
|
||||
var nextColorValue = (colorAttr?.Val ?? 0) + 1;
|
||||
VirCaptureStateHelper.SetUnsignedAttr(player, colorSid, nextColorValue, sync);
|
||||
|
||||
var rikiAttr = player.Data.Attrs.FirstOrDefault(x => x.Gid == RikiGroupId && x.Sid == monsterCard.RikiId);
|
||||
if (rikiAttr == null)
|
||||
{
|
||||
rikiAttr = new Database.Player.PlayerAttr
|
||||
{
|
||||
Gid = RikiGroupId,
|
||||
Sid = monsterCard.RikiId,
|
||||
Val = 0
|
||||
};
|
||||
player.Data.Attrs.Add(rikiAttr);
|
||||
}
|
||||
|
||||
rikiAttr.Val += 1;
|
||||
sync.Custom[player.ToPackedAttrKey(RikiGroupId, monsterCard.RikiId)] = rikiAttr.Val;
|
||||
sync.Custom[player.ToShiftedAttrKey(RikiGroupId, monsterCard.RikiId)] = rikiAttr.Val;
|
||||
}
|
||||
|
||||
private static void ApplyCaptureExp(MikuSB.GameServer.Game.Player.PlayerInstance player, ulong templateId, NtfSyncPlayer sync)
|
||||
{
|
||||
if (!GameData.MonsterCardData.TryGetValue(templateId, out var monsterCard) || monsterCard.Exp == 0)
|
||||
return;
|
||||
|
||||
var curLevelAttr = GetOrCreateVirCaptureAttr(player, CurLevelSid);
|
||||
var curExpAttr = GetOrCreateVirCaptureAttr(player, CurExpSid);
|
||||
var dailyExpAttr = GetOrCreateVirCaptureAttr(player, DailyExpSid);
|
||||
|
||||
var maxLevel = GameData.VirCaptureLevelListData.Count == 0 ? 1u : GameData.VirCaptureLevelListData.Keys.Max();
|
||||
var curLevel = Math.Max(1u, curLevelAttr.Val);
|
||||
if (curLevel >= maxLevel)
|
||||
return;
|
||||
|
||||
var baseExp = monsterCard.Exp;
|
||||
if (GameData.VirCaptureLevelListData.TryGetValue(curLevel, out var currentLevelCfg) && currentLevelCfg.ExpUp > 1d)
|
||||
baseExp = (uint)Math.Floor(baseExp * currentLevelCfg.ExpUp);
|
||||
|
||||
var maxDailyExp = ResolveCurrentAct(player)?.MaxExp ?? 0u;
|
||||
if (maxDailyExp > 0 && dailyExpAttr.Val >= maxDailyExp)
|
||||
return;
|
||||
|
||||
var gainExp = baseExp;
|
||||
if (maxDailyExp > 0)
|
||||
gainExp = Math.Min(gainExp, maxDailyExp - dailyExpAttr.Val);
|
||||
|
||||
if (gainExp == 0)
|
||||
return;
|
||||
|
||||
dailyExpAttr.Val += gainExp;
|
||||
SyncVirCaptureAttr(player, DailyExpSid, dailyExpAttr.Val, sync);
|
||||
|
||||
var pendingExp = curExpAttr.Val + gainExp;
|
||||
while (GameData.VirCaptureLevelListData.TryGetValue(curLevel, out var levelCfg) && curLevel < maxLevel)
|
||||
{
|
||||
if (pendingExp < levelCfg.Exp)
|
||||
break;
|
||||
|
||||
pendingExp -= levelCfg.Exp;
|
||||
curLevel++;
|
||||
}
|
||||
|
||||
curLevelAttr.Val = curLevel;
|
||||
curExpAttr.Val = curLevel >= maxLevel
|
||||
? GameData.VirCaptureLevelListData.GetValueOrDefault(maxLevel)?.Exp ?? pendingExp
|
||||
: pendingExp;
|
||||
|
||||
SyncVirCaptureAttr(player, CurLevelSid, curLevelAttr.Val, sync);
|
||||
SyncVirCaptureAttr(player, CurExpSid, curExpAttr.Val, sync);
|
||||
}
|
||||
|
||||
private static Database.Player.PlayerAttr GetOrCreateVirCaptureAttr(MikuSB.GameServer.Game.Player.PlayerInstance player, uint sid)
|
||||
{
|
||||
var attr = player.Data.Attrs.FirstOrDefault(x => x.Gid == VirCaptureGroupId && x.Sid == sid);
|
||||
if (attr != null)
|
||||
return attr;
|
||||
|
||||
attr = new Database.Player.PlayerAttr
|
||||
{
|
||||
Gid = VirCaptureGroupId,
|
||||
Sid = sid,
|
||||
Val = 0
|
||||
};
|
||||
player.Data.Attrs.Add(attr);
|
||||
return attr;
|
||||
}
|
||||
|
||||
private static void SyncVirCaptureAttr(MikuSB.GameServer.Game.Player.PlayerInstance player, uint sid, uint value, NtfSyncPlayer sync)
|
||||
{
|
||||
sync.Custom[player.ToPackedAttrKey(VirCaptureGroupId, sid)] = value;
|
||||
sync.Custom[player.ToShiftedAttrKey(VirCaptureGroupId, sid)] = value;
|
||||
}
|
||||
|
||||
private static MikuSB.Data.Excel.VirCaptureTimeExcel? ResolveCurrentAct(MikuSB.GameServer.Game.Player.PlayerInstance player)
|
||||
{
|
||||
var actId = player.Data.Attrs.FirstOrDefault(x => x.Gid == VirCaptureGroupId && x.Sid == 1)?.Val ?? 0;
|
||||
if (actId > 0 && GameData.VirCaptureTimeData.TryGetValue(actId, out var act))
|
||||
return act;
|
||||
|
||||
var now = DateTime.Now;
|
||||
return GameData.VirCaptureTimeData.Values
|
||||
.Select(x => new { Config = x, Start = ParseConfigTime(x.StartTime), End = ParseConfigTime(x.EndTime) })
|
||||
.Where(x => x.Start.HasValue && x.End.HasValue && x.Start <= now && now < x.End)
|
||||
.OrderBy(x => x.Start)
|
||||
.Select(x => x.Config)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static DateTime? ParseConfigTime(string? raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
return null;
|
||||
|
||||
var normalized = raw.Trim().Trim('[', ']');
|
||||
if (normalized.Length != 12)
|
||||
return null;
|
||||
|
||||
return DateTime.TryParseExact(
|
||||
normalized,
|
||||
"yyyyMMddHHmm",
|
||||
System.Globalization.CultureInfo.InvariantCulture,
|
||||
System.Globalization.DateTimeStyles.None,
|
||||
out var value)
|
||||
? value
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureSaveCaptureParam
|
||||
{
|
||||
[JsonPropertyName("nLevelID")]
|
||||
public int LevelId { get; set; }
|
||||
|
||||
[JsonPropertyName("nRegionId")]
|
||||
public int RegionId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCaptureLevel_SaveFightData")]
|
||||
public class VirCaptureLevel_SaveFightData : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<VirCaptureSaveFightDataParam>(param);
|
||||
if (req == null || req.LevelId == 0 || req.RegionId == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SaveFightData", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var sync = new NtfSyncPlayer();
|
||||
VirCaptureStateHelper.SetPointState(player, (uint)req.LevelId, (uint)req.RegionId, 2u, sync);
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
|
||||
var response = new JsonObject
|
||||
{
|
||||
["nLevelID"] = req.LevelId,
|
||||
["nRegionId"] = req.RegionId,
|
||||
["tbRewards"] = new JsonArray()
|
||||
};
|
||||
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SaveFightData", response.ToJsonString(), sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureSaveFightDataParam
|
||||
{
|
||||
[JsonPropertyName("nLevelID")]
|
||||
public int LevelId { get; set; }
|
||||
|
||||
[JsonPropertyName("nRegionId")]
|
||||
public int RegionId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCaptureLevel_SavePos")]
|
||||
public class VirCaptureLevel_SavePos : ICallGSHandler
|
||||
{
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<VirCaptureSavePosParam>(param);
|
||||
if (req == null || req.LevelId == 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SavePos", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var sync = new NtfSyncPlayer();
|
||||
VirCaptureStateHelper.SetSignedMapOffset(player, (uint)req.LevelId, VirCaptureStateHelper.OffPosX, req.PosX, sync);
|
||||
VirCaptureStateHelper.SetSignedMapOffset(player, (uint)req.LevelId, VirCaptureStateHelper.OffPosY, req.PosY, sync);
|
||||
VirCaptureStateHelper.SetSignedMapOffset(player, (uint)req.LevelId, VirCaptureStateHelper.OffPosZ, req.PosZ, sync);
|
||||
VirCaptureStateHelper.SetSignedMapOffset(player, (uint)req.LevelId, VirCaptureStateHelper.OffToward, req.Toward, sync);
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureLevel_SavePos", "{}", sync);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureSavePosParam
|
||||
{
|
||||
[JsonPropertyName("nLevelID")]
|
||||
public int LevelId { get; set; }
|
||||
|
||||
[JsonPropertyName("nPosX")]
|
||||
public int PosX { get; set; }
|
||||
|
||||
[JsonPropertyName("nPosY")]
|
||||
public int PosY { get; set; }
|
||||
|
||||
[JsonPropertyName("nPosZ")]
|
||||
public int PosZ { get; set; }
|
||||
|
||||
[JsonPropertyName("nToward")]
|
||||
public int Toward { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.GameServer.Game.Player;
|
||||
using MikuSB.Proto;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
internal static class VirCaptureStateHelper
|
||||
{
|
||||
public const uint GroupId = 128;
|
||||
public const uint MapDataStart = 10000;
|
||||
public const uint MapDataEnd = 19000;
|
||||
public const uint MaxMapCount = 3;
|
||||
public const uint MaxMapDataLen = 3000;
|
||||
public const uint MaxPatrolPoint = 500;
|
||||
public const uint MaxOtherPoint = 2500;
|
||||
public const uint MinMaterialId = 50000;
|
||||
public const uint MaxMaterialId = 51500;
|
||||
|
||||
public const uint OffMapId = 1;
|
||||
public const uint OffTurnNum = 2;
|
||||
public const uint OffPosX = 3;
|
||||
public const uint OffPosY = 4;
|
||||
public const uint OffPosZ = 5;
|
||||
public const uint OffToward = 6;
|
||||
public const uint OffDayNight = 7;
|
||||
public const uint OffMapLevel = 8;
|
||||
public const uint OffPatrolStart = 51;
|
||||
public const uint OffPatrolEnd = 1000;
|
||||
public const uint OffOtherStart = 1001;
|
||||
public const uint OffOtherEnd = 1500;
|
||||
public const uint OffMaterialStart = 1501;
|
||||
public const uint OffMaterialEnd = 3000;
|
||||
|
||||
public static uint FindOrAllocateMapSlot(PlayerInstance player, uint levelId)
|
||||
{
|
||||
uint? emptySlot = null;
|
||||
for (uint i = 0; i < MaxMapCount; i++)
|
||||
{
|
||||
var slotStart = MapDataStart + (i * MaxMapDataLen);
|
||||
var mapIdAttr = player.Data.Attrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == slotStart + OffMapId);
|
||||
if (mapIdAttr?.Val == levelId)
|
||||
return slotStart;
|
||||
|
||||
if (emptySlot == null && (mapIdAttr == null || mapIdAttr.Val == 0))
|
||||
emptySlot = slotStart;
|
||||
}
|
||||
|
||||
return emptySlot ?? 0;
|
||||
}
|
||||
|
||||
public static void EnsureBaseMapState(PlayerInstance player, uint levelId, NtfSyncPlayer sync)
|
||||
{
|
||||
var slotStart = FindOrAllocateMapSlot(player, levelId);
|
||||
if (slotStart == 0)
|
||||
return;
|
||||
|
||||
EnsureUnsignedAttr(player, slotStart + OffMapId, levelId, sync);
|
||||
EnsureUnsignedAttr(player, slotStart + OffDayNight, 1, sync);
|
||||
EnsureUnsignedAttr(player, slotStart + OffMapLevel, 1, sync);
|
||||
}
|
||||
|
||||
public static void SetSignedMapOffset(PlayerInstance player, uint levelId, uint offset, int value, NtfSyncPlayer sync)
|
||||
{
|
||||
var slotStart = FindOrAllocateMapSlot(player, levelId);
|
||||
if (slotStart == 0)
|
||||
return;
|
||||
|
||||
EnsureBaseMapState(player, levelId, sync);
|
||||
SetUnsignedAttr(player, slotStart + offset, unchecked((uint)value), sync);
|
||||
}
|
||||
|
||||
public static void SetPointState(PlayerInstance player, uint levelId, uint pointId, uint value, NtfSyncPlayer sync)
|
||||
{
|
||||
var slotStart = FindOrAllocateMapSlot(player, levelId);
|
||||
if (slotStart == 0 || pointId == 0)
|
||||
return;
|
||||
|
||||
EnsureBaseMapState(player, levelId, sync);
|
||||
|
||||
if (pointId <= MaxPatrolPoint)
|
||||
{
|
||||
var sid = slotStart + (OffPatrolStart - 1) + pointId;
|
||||
SetUnsignedAttr(player, sid, value, sync);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pointId <= MaxOtherPoint)
|
||||
{
|
||||
var relative = pointId - MaxPatrolPoint;
|
||||
var sid = slotStart + (uint)Math.Floor(relative / 30d) + OffOtherStart;
|
||||
if (sid > slotStart + OffOtherEnd)
|
||||
return;
|
||||
|
||||
var bit = (int)(relative % 30);
|
||||
var attr = GetOrCreateAttr(player, sid);
|
||||
var next = value > 0
|
||||
? attr.Val | (1u << bit)
|
||||
: attr.Val & ~(1u << bit);
|
||||
if (next != attr.Val)
|
||||
{
|
||||
attr.Val = next;
|
||||
SyncAttr(player, sync, sid, next);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (pointId > MinMaterialId && pointId <= MaxMaterialId)
|
||||
{
|
||||
var sid = slotStart + (OffMaterialStart - 1) + (pointId - MinMaterialId);
|
||||
if (sid >= slotStart + OffMaterialEnd)
|
||||
return;
|
||||
|
||||
SetUnsignedAttr(player, sid, value, sync);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnsureUnsignedAttr(PlayerInstance player, uint sid, uint minValue, NtfSyncPlayer sync)
|
||||
{
|
||||
var attr = GetOrCreateAttr(player, sid);
|
||||
if (attr.Val < minValue)
|
||||
{
|
||||
attr.Val = minValue;
|
||||
SyncAttr(player, sync, sid, attr.Val);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetUnsignedAttr(PlayerInstance player, uint sid, uint value, NtfSyncPlayer sync)
|
||||
{
|
||||
var attr = GetOrCreateAttr(player, sid);
|
||||
if (attr.Val != value)
|
||||
{
|
||||
attr.Val = value;
|
||||
SyncAttr(player, sync, sid, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static PlayerAttr GetOrCreateAttr(PlayerInstance player, uint sid)
|
||||
{
|
||||
var attr = player.Data.Attrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == sid);
|
||||
if (attr != null)
|
||||
return attr;
|
||||
|
||||
attr = new PlayerAttr
|
||||
{
|
||||
Gid = GroupId,
|
||||
Sid = sid
|
||||
};
|
||||
player.Data.Attrs.Add(attr);
|
||||
return attr;
|
||||
}
|
||||
|
||||
private static void SyncAttr(PlayerInstance player, NtfSyncPlayer sync, uint sid, uint value)
|
||||
{
|
||||
sync.Custom[player.ToPackedAttrKey(GroupId, sid)] = value;
|
||||
sync.Custom[player.ToShiftedAttrKey(GroupId, sid)] = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Database.Player;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCaptureTower_EnterLevel")]
|
||||
public class VirCaptureTower_EnterLevel : ICallGSHandler
|
||||
{
|
||||
private const uint LaunchPassGroupId = 22;
|
||||
private const uint VirCaptureGroupId = 128;
|
||||
private const uint VirCaptureLevelSid = 3;
|
||||
private static readonly Random Random = new();
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<VirCaptureTowerEnterLevelParam>(param);
|
||||
if (req == null || req.LevelId <= 0 || req.TeamId <= 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureTower_EnterLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GameData.VirCaptureTowerData.TryGetValue((uint)req.LevelId, out var levelCfg))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureTower_EnterLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
if (!CheckConditions(player.Data, levelCfg.Condition))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureTower_EnterLevel", "{\"sErr\":\"tip.LevelLocked\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureTower_EnterLevel", $"{{\"nSeed\":{Random.Next(1, 1_000_000_000)}}}");
|
||||
}
|
||||
|
||||
private static bool CheckConditions(PlayerGameData data, IReadOnlyDictionary<int, uint> conditions)
|
||||
{
|
||||
foreach (var (key, value) in conditions)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 1:
|
||||
if (data.Level < value)
|
||||
return false;
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
var pass = data.Attrs.FirstOrDefault(x => x.Gid == LaunchPassGroupId && x.Sid == value)?.Val ?? 0;
|
||||
if (pass == 0)
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case 20:
|
||||
{
|
||||
var virLevel = data.Attrs.FirstOrDefault(x => x.Gid == VirCaptureGroupId && x.Sid == VirCaptureLevelSid)?.Val ?? 0;
|
||||
if (virLevel < value)
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureTowerEnterLevelParam
|
||||
{
|
||||
[JsonPropertyName("nID")]
|
||||
public int LevelId { get; set; }
|
||||
|
||||
[JsonPropertyName("nTeamID")]
|
||||
public int TeamId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.GameServer.Game.Player;
|
||||
using MikuSB.Proto;
|
||||
using MikuSB.Util;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCaptureTower_LevelSettlement")]
|
||||
public class VirCaptureTower_LevelSettlement : ICallGSHandler
|
||||
{
|
||||
private const uint LaunchLevelStateGroupId = 21;
|
||||
private const uint LaunchPassGroupId = 22;
|
||||
private const uint PassedFlagBit = 1u << 8;
|
||||
private static readonly Logger Logger = new("VirCaptureTower");
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var (response, sync) = HandleSettlement(connection.Player!, JsonNode.Parse(param));
|
||||
await CallGSRouter.SendScript(connection, "VirCaptureTower_LevelSettlement", response.ToJsonString(), sync);
|
||||
}
|
||||
|
||||
public static (JsonNode Response, NtfSyncPlayer Sync) HandleSettlement(PlayerInstance player, JsonNode? tbParam)
|
||||
{
|
||||
var req = tbParam?.Deserialize<VirCaptureTowerSettlementParam>();
|
||||
if (req == null || req.LevelId == 0)
|
||||
{
|
||||
Logger.Error($"Invalid vircapture tower settlement payload: {tbParam?.ToJsonString() ?? "null"}");
|
||||
return (new JsonObject { ["sErr"] = "error.BadParam" }, new NtfSyncPlayer());
|
||||
}
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
|
||||
var levelStateAttr = GetOrCreateAttr(player.Data, LaunchLevelStateGroupId, (uint)req.LevelId);
|
||||
levelStateAttr.Val |= MergeStarMask(req.StarMask) | PassedFlagBit;
|
||||
SyncAttr(sync, player, levelStateAttr);
|
||||
|
||||
var passAttr = GetOrCreateAttr(player.Data, LaunchPassGroupId, (uint)req.LevelId);
|
||||
passAttr.Val = Math.Max(1u, passAttr.Val + 1);
|
||||
SyncAttr(sync, player, passAttr);
|
||||
|
||||
Logger.Info(
|
||||
$"VirCaptureTower settlement saved. uid={player.Uid} levelId={req.LevelId} starMask={req.StarMask} " +
|
||||
$"levelStateVal={levelStateAttr.Val} passVal={passAttr.Val}");
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
return (new JsonObject(), sync);
|
||||
}
|
||||
|
||||
private static uint MergeStarMask(int starMask)
|
||||
{
|
||||
uint result = 0;
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
if (((starMask >> i) & 1) != 0)
|
||||
result |= 1u << i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static void SyncAttr(NtfSyncPlayer sync, PlayerInstance player, PlayerAttr attr)
|
||||
{
|
||||
sync.Custom[player.ToPackedAttrKey(attr.Gid, attr.Sid)] = attr.Val;
|
||||
sync.Custom[player.ToShiftedAttrKey(attr.Gid, attr.Sid)] = attr.Val;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureTowerSettlementParam
|
||||
{
|
||||
[JsonPropertyName("nID")]
|
||||
public int LevelId { get; set; }
|
||||
|
||||
[JsonPropertyName("nStar")]
|
||||
public int StarMask { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Enums.Item;
|
||||
using MikuSB.Proto;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCapture_ChangeFormation")]
|
||||
public class VirCapture_ChangeFormation : ICallGSHandler
|
||||
{
|
||||
private const uint StrGroupId = 57;
|
||||
private const uint FormationSid = 1;
|
||||
private const uint VirCaptureGroupId = 128;
|
||||
private const uint CurLevelSid = 3;
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var req = JsonSerializer.Deserialize<VirCaptureChangeFormationParam>(param);
|
||||
if (req == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_ChangeFormation", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var formation = ReadFormation(player);
|
||||
var addId = (uint)Math.Max(0, req.Id);
|
||||
var unloadId = (uint)Math.Max(0, req.UnloadId);
|
||||
|
||||
var unloadIndex = unloadId == 0 ? -1 : formation.FindIndex(x => x == unloadId);
|
||||
if (unloadId > 0 && unloadIndex < 0)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_ChangeFormation", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (addId > 0)
|
||||
{
|
||||
if (formation.Contains(addId))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_ChangeFormation", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var addItem = player.InventoryManager.GetNormalItem(addId);
|
||||
if (addItem == null || addItem.ItemType != ItemTypeEnum.TYPE_MONSTER_CARD)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_ChangeFormation", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (unloadIndex >= 0)
|
||||
formation.RemoveAt(unloadIndex);
|
||||
|
||||
if (addId > 0)
|
||||
{
|
||||
if (unloadIndex >= 0 && unloadIndex <= formation.Count)
|
||||
formation.Insert(unloadIndex, addId);
|
||||
else
|
||||
formation.Add(addId);
|
||||
}
|
||||
|
||||
if (!ValidateFormation(player, formation))
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_ChangeFormation", "{\"sErr\":\"error.BadParam\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var json = JsonSerializer.Serialize(formation);
|
||||
player.SetStrAttr(StrGroupId, FormationSid, json);
|
||||
|
||||
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||
|
||||
var sync = new NtfSyncPlayer();
|
||||
sync.CustomStr[player.ToShiftedAttrKey(StrGroupId, FormationSid)] = json;
|
||||
|
||||
var response = new JsonObject
|
||||
{
|
||||
["nId"] = req.Id,
|
||||
["nUnloadId"] = req.UnloadId,
|
||||
["bAdd"] = addId > 0
|
||||
};
|
||||
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_ChangeFormation", response.ToJsonString(), sync);
|
||||
}
|
||||
|
||||
private static List<uint> ReadFormation(MikuSB.GameServer.Game.Player.PlayerInstance player)
|
||||
{
|
||||
var raw = player.Data.StrAttrs.FirstOrDefault(x => x.Gid == StrGroupId && x.Sid == FormationSid)?.Val;
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
return [];
|
||||
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<uint>>(raw) ?? [];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ValidateFormation(MikuSB.GameServer.Game.Player.PlayerInstance player, List<uint> formation)
|
||||
{
|
||||
var curLevel = player.Data.Attrs.FirstOrDefault(x => x.Gid == VirCaptureGroupId && x.Sid == CurLevelSid)?.Val ?? 1;
|
||||
if (!GameData.VirCaptureLevelListData.TryGetValue(curLevel, out var levelCfg))
|
||||
return formation.Count == 0;
|
||||
|
||||
if (formation.Count > levelCfg.Num)
|
||||
return false;
|
||||
|
||||
uint totalCost = 0;
|
||||
foreach (var itemId in formation)
|
||||
{
|
||||
var item = player.InventoryManager.GetNormalItem(itemId);
|
||||
if (item == null || item.ItemType != ItemTypeEnum.TYPE_MONSTER_CARD)
|
||||
return false;
|
||||
|
||||
if (!GameData.MonsterCardData.TryGetValue(item.TemplateId, out var monsterCfg))
|
||||
return false;
|
||||
|
||||
totalCost += monsterCfg.CostValue;
|
||||
}
|
||||
|
||||
return totalCost <= levelCfg.MaxCost;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class VirCaptureChangeFormationParam
|
||||
{
|
||||
[JsonPropertyName("nId")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("nUnloadId")]
|
||||
public int UnloadId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Data.Excel;
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.GameServer.Game.Player;
|
||||
using MikuSB.Proto;
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.VirCapture;
|
||||
|
||||
[CallGSApi("VirCapture_CheckOpenAct")]
|
||||
public class VirCapture_CheckOpenAct : ICallGSHandler
|
||||
{
|
||||
private const uint GroupId = 128;
|
||||
private const uint ActIdSid = 1;
|
||||
private const uint CurLevelSid = 3;
|
||||
private const uint TrialActIdSid = 6;
|
||||
private const uint SeasonActIdSid = 9;
|
||||
|
||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var act = ResolveCurrent(GameData.VirCaptureTimeData.Values, now);
|
||||
if (act == null)
|
||||
{
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_CheckOpenAct", "{\"bOpen\":false}");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = connection.Player!;
|
||||
var sync = new NtfSyncPlayer();
|
||||
|
||||
SetAttr(player, ActIdSid, act.Id, sync);
|
||||
EnsureMinAttr(player, CurLevelSid, 1, sync);
|
||||
|
||||
var response = new JsonObject
|
||||
{
|
||||
["bOpen"] = true,
|
||||
["nId"] = act.Id,
|
||||
["nStartTime"] = ToUnixSeconds(ParseConfigTime(act.StartTime)),
|
||||
["nEndTime"] = ToUnixSeconds(ParseConfigTime(act.EndTime))
|
||||
};
|
||||
|
||||
var season = ResolveCurrent(GameData.VirCaptureSeasonData.Values, now);
|
||||
if (season != null)
|
||||
{
|
||||
SetAttr(player, SeasonActIdSid, season.Id, sync);
|
||||
response["tbSeason"] = new JsonObject
|
||||
{
|
||||
["nId"] = season.Id,
|
||||
["nStartTime"] = ToUnixSeconds(ParseConfigTime(season.StartTime)),
|
||||
["nEndTime"] = ToUnixSeconds(ParseConfigTime(season.EndTime))
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
SetAttr(player, SeasonActIdSid, 0, sync);
|
||||
}
|
||||
|
||||
var trial = ResolveCurrent(GameData.VirCaptureTrialTimeData.Values, now);
|
||||
SetAttr(player, TrialActIdSid, trial?.Id ?? 0, sync);
|
||||
|
||||
await CallGSRouter.SendScript(connection, "VirCapture_CheckOpenAct", response.ToJsonString(), sync);
|
||||
}
|
||||
|
||||
private static T? ResolveCurrent<T>(IEnumerable<T> configs, DateTime now) where T : class
|
||||
{
|
||||
var parsed = configs
|
||||
.Select(x => new
|
||||
{
|
||||
Config = x,
|
||||
Start = ParseConfigTime(GetTimeValue(x, true)),
|
||||
End = ParseConfigTime(GetTimeValue(x, false))
|
||||
})
|
||||
.Where(x => x.Start.HasValue && x.End.HasValue)
|
||||
.OrderBy(x => x.Start)
|
||||
.ToList();
|
||||
|
||||
var current = parsed.FirstOrDefault(x => x.Start <= now && now < x.End);
|
||||
if (current != null)
|
||||
return current.Config;
|
||||
|
||||
var latestStarted = parsed.LastOrDefault(x => x.Start <= now);
|
||||
if (latestStarted != null && latestStarted.End > latestStarted.Start)
|
||||
return latestStarted.Config;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string? GetTimeValue<T>(T value, bool start) where T : class
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
VirCaptureTimeExcel time => start ? time.StartTime : time.EndTime,
|
||||
VirCaptureSeasonExcel season => start ? season.StartTime : season.EndTime,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
private static DateTime? ParseConfigTime(string? raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
return null;
|
||||
|
||||
var normalized = raw.Trim().Trim('[', ']');
|
||||
if (normalized.Length != 12)
|
||||
return null;
|
||||
|
||||
return DateTime.TryParseExact(
|
||||
normalized,
|
||||
"yyyyMMddHHmm",
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None,
|
||||
out var value)
|
||||
? value
|
||||
: null;
|
||||
}
|
||||
|
||||
private static long ToUnixSeconds(DateTime? value)
|
||||
{
|
||||
return value.HasValue ? new DateTimeOffset(value.Value).ToUnixTimeSeconds() : 0L;
|
||||
}
|
||||
|
||||
private static void EnsureMinAttr(PlayerInstance player, uint sid, uint minValue, NtfSyncPlayer sync)
|
||||
{
|
||||
var attr = GetOrCreateAttr(player, sid);
|
||||
if (attr.Val < minValue)
|
||||
{
|
||||
attr.Val = minValue;
|
||||
SyncAttr(player, sync, sid, attr.Val);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetAttr(PlayerInstance player, uint sid, uint value, NtfSyncPlayer sync)
|
||||
{
|
||||
var attr = GetOrCreateAttr(player, sid);
|
||||
if (attr.Val != value)
|
||||
{
|
||||
attr.Val = value;
|
||||
SyncAttr(player, sync, sid, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static PlayerAttr GetOrCreateAttr(PlayerInstance player, uint sid)
|
||||
{
|
||||
var attr = player.Data.Attrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == sid);
|
||||
if (attr != null)
|
||||
return attr;
|
||||
|
||||
attr = new PlayerAttr
|
||||
{
|
||||
Gid = GroupId,
|
||||
Sid = sid
|
||||
};
|
||||
player.Data.Attrs.Add(attr);
|
||||
return attr;
|
||||
}
|
||||
|
||||
private static void SyncAttr(PlayerInstance player, NtfSyncPlayer sync, uint sid, uint value)
|
||||
{
|
||||
sync.Custom[player.ToPackedAttrKey(GroupId, sid)] = value;
|
||||
sync.Custom[player.ToShiftedAttrKey(GroupId, sid)] = value;
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
v=4.1
|
||||
v=4.3
|
||||
Reference in New Issue
Block a user