From bb7411643c546c0749041f70c8e4101234285daa Mon Sep 17 00:00:00 2001 From: Mikhail Tyukin Date: Mon, 23 Jun 2025 22:12:04 +0400 Subject: [PATCH] begin working on interception rewards --- EpinelPS/Data/GameData.cs | 22 +++++++-- EpinelPS/Data/JsonStaticData.cs | 25 ++++++++++ .../LobbyServer/Intercept/InterceptClear.cs | 8 ++- EpinelPS/Utils/InterceptionHelper.cs | 49 +++++++++++++++++++ 4 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 EpinelPS/Utils/InterceptionHelper.cs diff --git a/EpinelPS/Data/GameData.cs b/EpinelPS/Data/GameData.cs index df092bd..5280fe3 100644 --- a/EpinelPS/Data/GameData.cs +++ b/EpinelPS/Data/GameData.cs @@ -170,6 +170,14 @@ namespace EpinelPS.Data [LoadRecord("PopupPackageListTable.json", "id", typeof(ProductOfferTable))] public readonly Dictionary PopupPackages = []; + [LoadRecord("InterceptNormalTable.json", "id", typeof(InterceptionTable))] + public readonly Dictionary InterceptNormal = []; + + [LoadRecord("InterceptSpecialTable.json", "id", typeof(InterceptionTable))] + public readonly Dictionary InterceptSpecial = []; + + [LoadRecord("ConditionRewardTable.json", "id", typeof(ConditionRewardTable))] + public readonly Dictionary ConditionRewards = []; static async Task BuildAsync() { await Load(); @@ -337,13 +345,13 @@ namespace EpinelPS.Data using StreamReader fileReader = new(MainZip.GetInputStream(fileEntry)); string fileString = await fileReader.ReadToEndAsync(); - T? deseralizedObject = JsonConvert.DeserializeObject(fileString); - if (deseralizedObject == null) throw new Exception("failed to parse " + entry); + T? deserializedObject = JsonConvert.DeserializeObject(fileString); + if (deserializedObject == null) throw new Exception("failed to parse " + entry); currentFile++; bar.Report((double)currentFile / totalFiles); - return deseralizedObject; + return deserializedObject; } private async Task LoadZip(string entry, ProgressBar bar) @@ -613,5 +621,13 @@ namespace EpinelPS.Data return data.hard_field_id; else return data.field_id; } + + internal int GetConditionReward(int groupId, long damage) + { + var results = ConditionRewards.Where(x => x.Value.group == groupId && x.Value.value_min <= damage && x.Value.value_max >= damage); + if (results.Any()) + return results.FirstOrDefault().Value.reward_id; + else return 0; + } } } diff --git a/EpinelPS/Data/JsonStaticData.cs b/EpinelPS/Data/JsonStaticData.cs index e7bec92..87e8d08 100644 --- a/EpinelPS/Data/JsonStaticData.cs +++ b/EpinelPS/Data/JsonStaticData.cs @@ -769,5 +769,30 @@ { public List records = []; } + public class InterceptionRecord + { + public int id; + public int group; + public int condition_reward_group; + public int percent_condition_reward_group; + public long fixed_damage; + } + public class InterceptionTable + { + public List records = []; + } + public class ConditionRewardRecord + { + public int id; + public int group; + public int priority; + public long value_min; + public long value_max; + public int reward_id; + } + public class ConditionRewardTable + { + public List records = []; + } } diff --git a/EpinelPS/LobbyServer/Intercept/InterceptClear.cs b/EpinelPS/LobbyServer/Intercept/InterceptClear.cs index 1d0def6..8f21eb2 100644 --- a/EpinelPS/LobbyServer/Intercept/InterceptClear.cs +++ b/EpinelPS/LobbyServer/Intercept/InterceptClear.cs @@ -8,13 +8,17 @@ namespace EpinelPS.LobbyServer.Intercept protected override async Task HandleAsync() { var req = await ReadData(); - + var user = GetUser(); + + var sRes = InterceptionHelper.Clear(user, req.Intercept, req.InterceptId, req.Damage); var response = new ResClearIntercept { Intercept = req.Intercept, InterceptId = req.InterceptId, TicketCount = 5, - MaxTicketCount = 10 + MaxTicketCount = 10, + NormalReward = sRes.NormalReward, + }; await WriteDataAsync(response); diff --git a/EpinelPS/Utils/InterceptionHelper.cs b/EpinelPS/Utils/InterceptionHelper.cs new file mode 100644 index 0000000..2db2291 --- /dev/null +++ b/EpinelPS/Utils/InterceptionHelper.cs @@ -0,0 +1,49 @@ +using EpinelPS.Data; +using EpinelPS.Database; + +namespace EpinelPS.Utils +{ + public static class InterceptionHelper + { + public static InterceptionClearResult Clear(User user, int type, int id, long damage = 0) + { + InterceptionClearResult response = new(); + + if (type != 0 && type != 1) throw new Exception("unknown type"); + + Dictionary records = type == 0 ? GameData.Instance.InterceptNormal : GameData.Instance.InterceptSpecial; + + var record = records[id]; + + var normReward = GameData.Instance.GetConditionReward(record.condition_reward_group, damage); + if (normReward != 0) + { + response.NormalReward = RewardUtils.RegisterRewardsForUser(user, normReward); + } + else + { + Logging.WriteLine($"unable to find reward which meets condition of damage {damage} and group {record.condition_reward_group}"); + } + + var percentReward = GameData.Instance.GetConditionReward(record.percent_condition_reward_group, damage); + if (percentReward != 0) + { + var r = RewardUtils.RegisterRewardsForUser(user, normReward); + response.NormalReward = NetUtils.MergeRewards([response.NormalReward, r], user); + } + else + { + Logging.WriteLine($"unable to find reward which meets condition of damage {damage} and group {record.condition_reward_group}"); + } + + JsonDb.Save(); + + return response; + } + } + + public class InterceptionClearResult + { + public NetRewardData NormalReward = new(); + } +}