begin working on interception rewards

This commit is contained in:
Mikhail Tyukin
2025-06-23 22:12:04 +04:00
parent 13086f6d19
commit bb7411643c
4 changed files with 99 additions and 5 deletions

View File

@@ -170,6 +170,14 @@ namespace EpinelPS.Data
[LoadRecord("PopupPackageListTable.json", "id", typeof(ProductOfferTable))]
public readonly Dictionary<int, ProductOfferRecord> PopupPackages = [];
[LoadRecord("InterceptNormalTable.json", "id", typeof(InterceptionTable))]
public readonly Dictionary<int, InterceptionRecord> InterceptNormal = [];
[LoadRecord("InterceptSpecialTable.json", "id", typeof(InterceptionTable))]
public readonly Dictionary<int, InterceptionRecord> InterceptSpecial = [];
[LoadRecord("ConditionRewardTable.json", "id", typeof(ConditionRewardTable))]
public readonly Dictionary<int, ConditionRewardRecord> ConditionRewards = [];
static async Task<GameData> 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<T>(fileString);
if (deseralizedObject == null) throw new Exception("failed to parse " + entry);
T? deserializedObject = JsonConvert.DeserializeObject<T>(fileString);
if (deserializedObject == null) throw new Exception("failed to parse " + entry);
currentFile++;
bar.Report((double)currentFile / totalFiles);
return deseralizedObject;
return deserializedObject;
}
private async Task<JArray> 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;
}
}
}

View File

@@ -769,5 +769,30 @@
{
public List<ProductOfferRecord> 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<InterceptionRecord> 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<ConditionRewardRecord> records = [];
}
}

View File

@@ -8,13 +8,17 @@ namespace EpinelPS.LobbyServer.Intercept
protected override async Task HandleAsync()
{
var req = await ReadData<ReqClearIntercept>();
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);

View File

@@ -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<int, InterceptionRecord> 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();
}
}