Skip to content

Commit

Permalink
Merge pull request #716 from planetarium/bugfix/adv-boss/recording
Browse files Browse the repository at this point in the history
Fix adventure boss action recording issue
  • Loading branch information
U-lis authored Jul 9, 2024
2 parents 83a405a + 9e4fb68 commit 7e2d7b8
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace NineChronicles.DataProvider.DataRendering.AdventureBoss
using Nekoyume.Model.AdventureBoss;
using Nekoyume.Module;
using NineChronicles.DataProvider.Store.Models.AdventureBoss;
using Serilog;

public static class AdventureBossChallengeData
{
Expand All @@ -23,6 +24,9 @@ ExploreAdventureBoss challenge
var outputExplorer = outputStates.GetExplorer(challenge.Season, challenge.AvatarAddress);
var exploreBoard = outputStates.GetExploreBoard(challenge.Season);

Log.Debug(
$"[Adventure Boss] GetChallengeData: {challenge.Season}::{prevExplorer.Floor}~{outputExplorer.Floor}::{outputExplorer.UsedApPotion - prevExplorer.UsedApPotion}::{exploreBoard.TotalPoint}"
);
return new AdventureBossChallengeModel
{
Id = challenge.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace NineChronicles.DataProvider.DataRendering.AdventureBoss
using Nekoyume.Action.AdventureBoss;
using Nekoyume.Module;
using NineChronicles.DataProvider.Store.Models.AdventureBoss;
using Serilog;

public static class AdventureBossRushData
{
Expand All @@ -20,6 +21,9 @@ SweepAdventureBoss rush
var outputExplorer = outputStates.GetExplorer(rush.Season, rush.AvatarAddress);
var outputExploreBoard = outputStates.GetExploreBoard(rush.Season);

Log.Debug(
$"[Adventure Boss] GetChallengeData: {rush.Season}::{outputExplorer.Floor}::{outputExplorer.UsedApPotion - prevExplorer.UsedApPotion}::{outputExploreBoard.TotalPoint}"
);
return new AdventureBossRushModel
{
Id = rush.Id.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static AdventureBossUnlockFloorModel GetUnlockInfo(
UnlockFloor unlock
)
{
var prevExploreBoard = prevState.GetExploreBoard(unlock.Season);
var outputExploreBoard = outputState.GetExploreBoard(unlock.Season);
var prevExplorer = prevState.GetExplorer(unlock.Season, unlock.AvatarAddress);
var outputExplorer = outputState.GetExplorer(unlock.Season, unlock.AvatarAddress);
Expand All @@ -27,8 +26,8 @@ UnlockFloor unlock
Season = unlock.Season,
AvatarAddress = unlock.AvatarAddress.ToString(),
UnlockFloor = prevExplorer.Floor + 1,
UsedGoldenDust = outputExplorer.UsedGoldenDust - prevExploreBoard.UsedGoldenDust,
UsedNcg = (decimal)(outputExploreBoard.UsedNcg - prevExploreBoard.UsedNcg),
UsedGoldenDust = outputExplorer.UsedGoldenDust - prevExplorer.UsedGoldenDust,
UsedNcg = (decimal)(outputExplorer.UsedNcg - prevExplorer.UsedNcg),
TotalUsedGoldenDust = outputExploreBoard.UsedGoldenDust,
TotalUsedNcg = (decimal)outputExploreBoard.UsedNcg,
Date = DateOnly.FromDateTime(blockTime.DateTime),
Expand Down
18 changes: 18 additions & 0 deletions NineChronicles.DataProvider/Store/MySql/AdventureBossStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class MySqlStore
{
public async partial Task StoreAdventureBossSeasonList(List<AdventureBossSeasonModel> seasonList)
{
Log.Debug($"[Adventure Boss] StoreAdventureBossSeason: {seasonList.Count}");
NineChroniclesContext? ctx = null;
try
{
Expand All @@ -25,10 +26,12 @@ public async partial Task StoreAdventureBossSeasonList(List<AdventureBossSeasonM
var existSeason = await ctx.AdventureBossSeason.FirstOrDefaultAsync(s => s.Season == season.Season);
if (existSeason is null)
{
Log.Debug("[Adventure Boss] Season not exist.");
await ctx.AdventureBossSeason.AddAsync(season);
}
else
{
Log.Debug("[Adventure Boss] Season Exist: update");
existSeason.RaffleReward = season.RaffleReward;
existSeason.RaffleWinnerAddress = season.RaffleWinnerAddress;
ctx.AdventureBossSeason.Update(existSeason);
Expand All @@ -52,6 +55,7 @@ public async partial Task StoreAdventureBossSeasonList(List<AdventureBossSeasonM

public async partial Task StoreAdventureBossWantedList(List<AdventureBossWantedModel> wantedList)
{
Log.Debug($"[Adventure Boss] StoreAdventureBossWantedList: {wantedList.Count}");
NineChroniclesContext? ctx = null;
try
{
Expand All @@ -70,7 +74,9 @@ public async partial Task StoreAdventureBossWantedList(List<AdventureBossWantedM
}

Task.WaitAll(tasks.ToArray());
Log.Debug("[Adventure Boss] Wanted Added");
await ctx.SaveChangesAsync();
Log.Debug("[Adventure Boss] Wanted Saved");
}
catch (Exception e)
{
Expand All @@ -87,6 +93,7 @@ public async partial Task StoreAdventureBossWantedList(List<AdventureBossWantedM

public async partial Task StoreAdventureBossChallengeList(List<AdventureBossChallengeModel> challengeList)
{
Log.Debug($"[Adventure Boss] StoreAdventureBossChallenge: {challengeList.Count}");
NineChroniclesContext? ctx = null;
try
{
Expand All @@ -105,7 +112,9 @@ public async partial Task StoreAdventureBossChallengeList(List<AdventureBossChal
}

Task.WaitAll(tasks.ToArray());
Log.Debug("[Adventure Boss] Challenge Added");
await ctx.SaveChangesAsync();
Log.Debug("[Adventure Boss] Challenge Saved");
}
catch (Exception e)
{
Expand All @@ -122,6 +131,7 @@ public async partial Task StoreAdventureBossChallengeList(List<AdventureBossChal

public async partial Task StoreAdventureBossRushList(List<AdventureBossRushModel> rushList)
{
Log.Debug($"[Adventure Boss] StoreAdventureBossRush: {rushList.Count}");
NineChroniclesContext? ctx = null;
try
{
Expand All @@ -140,7 +150,9 @@ public async partial Task StoreAdventureBossRushList(List<AdventureBossRushModel
}

Task.WaitAll(tasks.ToArray());
Log.Debug("[Adventure Boss] Rush Added");
await ctx.SaveChangesAsync();
Log.Debug("[Adventure Boss] Rush Saved");
}
catch (Exception e)
{
Expand All @@ -157,6 +169,7 @@ public async partial Task StoreAdventureBossRushList(List<AdventureBossRushModel

public async partial Task StoreAdventureBossUnlockFloorList(List<AdventureBossUnlockFloorModel> unlockFloorList)
{
Log.Debug($"[Adventure Boss] StoreAdventureBossUnlockFloor: {unlockFloorList.Count}");
NineChroniclesContext? ctx = null;

try
Expand All @@ -176,7 +189,9 @@ public async partial Task StoreAdventureBossUnlockFloorList(List<AdventureBossUn
}

Task.WaitAll(tasks.ToArray());
Log.Debug("[Adventure Boss] UnlockFloor Added");
await ctx.SaveChangesAsync();
Log.Debug("[Adventure Boss] UnlockFloor Saved");
}
catch (Exception e)
{
Expand All @@ -193,6 +208,7 @@ public async partial Task StoreAdventureBossUnlockFloorList(List<AdventureBossUn

public async partial Task StoreAdventureBossClaimRewardList(List<AdventureBossClaimRewardModel> claimList)
{
Log.Debug($"[Adventure Boss] StoreAdventureBossClaimReward: {claimList.Count}");
NineChroniclesContext? ctx = null;

try
Expand All @@ -212,7 +228,9 @@ public async partial Task StoreAdventureBossClaimRewardList(List<AdventureBossCl
}

Task.WaitAll(tasks.ToArray());
Log.Debug("[Adventure Boss] Claim Added");
await ctx.SaveChangesAsync();
Log.Debug("[Adventure Boss] Claim Saved");
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace NineChronicles.DataProvider
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Lib9c.Renderers;
using Libplanet.Action.State;
using Nekoyume.Action.AdventureBoss;
Expand All @@ -23,16 +24,65 @@ public partial class RenderSubscriber

private void StoreAdventureBossList()
{
MySqlStore.StoreAdventureBossSeasonList(_adventureBossSeasonList);
MySqlStore.StoreAdventureBossWantedList(_adventureBossWantedList);
MySqlStore.StoreAdventureBossChallengeList(_adventureBossChallengeList);
MySqlStore.StoreAdventureBossRushList(_adventureBossRushList);
MySqlStore.StoreAdventureBossUnlockFloorList(_adventureBossUnlockFloorList);
MySqlStore.StoreAdventureBossClaimRewardList(_adventureBossClaimRewardList);
try
{
var tasks = new List<Task>();
Log.Debug("[Adventure Boss] Store adventure boss list");

tasks.Add(Task.Run(async () =>
{
Log.Debug($"[Adventure Boss] {_adventureBossSeasonList.Count} Season");
await MySqlStore.StoreAdventureBossSeasonList(_adventureBossSeasonList);
}
));

tasks.Add(Task.Run(async () =>
{
Log.Debug($"[Adventure Boss] {_adventureBossWantedList.Count} Wanted");
await MySqlStore.StoreAdventureBossWantedList(_adventureBossWantedList);
}
));

tasks.Add(Task.Run(async () =>
{
Log.Debug($"[Adventure Boss] {_adventureBossChallengeList.Count} Challenge");
await MySqlStore.StoreAdventureBossChallengeList(_adventureBossChallengeList);
}
));

tasks.Add(Task.Run(async () =>
{
Log.Debug($"[Adventure Boss] {_adventureBossRushList.Count} Rush");
await MySqlStore.StoreAdventureBossRushList(_adventureBossRushList);
}
));

tasks.Add(Task.Run(async () =>
{
Log.Debug($"[Adventure Boss] {_adventureBossUnlockFloorList.Count} Unlock");
await MySqlStore.StoreAdventureBossUnlockFloorList(_adventureBossUnlockFloorList);
}
));

tasks.Add(Task.Run(async () =>
{
Log.Debug($"[Adventure Boss] {_adventureBossClaimRewardList.Count} claim");
await MySqlStore.StoreAdventureBossClaimRewardList(_adventureBossClaimRewardList);
}
));

Task.WaitAll(tasks.ToArray());
}
catch (Exception e)
{
Log.Error(e.Message);
}
}

private void ClearAdventureBossList()
{
Log.Debug("[Adventure Boss] Clear adventure boss action lists");
_adventureBossSeasonList.Clear();
_adventureBossWantedList.Clear();
_adventureBossChallengeList.Clear();
_adventureBossRushList.Clear();
Expand All @@ -42,6 +92,7 @@ private void ClearAdventureBossList()

partial void SubscribeAdventureBossWanted(ActionEvaluation<Wanted> evt)
{
Log.Debug("[Adventure Boss] Subscribe Wanted");
try
{
if (evt.Exception is null && evt.Action is { } wanted)
Expand All @@ -50,11 +101,13 @@ partial void SubscribeAdventureBossWanted(ActionEvaluation<Wanted> evt)
_adventureBossWantedList.Add(AdventureBossWantedData.GetWantedInfo(
outputState, evt.BlockIndex, _blockTimeOffset, wanted
));
Log.Debug($"[Adventure Boss] Wanted added : {_adventureBossWantedList.Count}");

// Update season info
_adventureBossSeasonList.Add(AdventureBossSeasonData.GetAdventureBossSeasonInfo(
outputState, wanted.Season, _blockTimeOffset
));
Log.Debug($"[Adventure Boss] Season added : {_adventureBossSeasonList.Count}");
}
}
catch (Exception e)
Expand All @@ -70,6 +123,7 @@ partial void SubscribeAdventureBossWanted(ActionEvaluation<Wanted> evt)

partial void SubscribeAdventureBossChallenge(ActionEvaluation<ExploreAdventureBoss> evt)
{
Log.Debug("[Adventure Boss] Subscribe Explore");
try
{
if (evt.Exception is null && evt.Action is { } challenge)
Expand All @@ -79,6 +133,7 @@ partial void SubscribeAdventureBossChallenge(ActionEvaluation<ExploreAdventureBo
_adventureBossChallengeList.Add(AdventureBossChallengeData.GetChallengeInfo(
prevState, outputState, evt.BlockIndex, _blockTimeOffset, challenge
));
Log.Debug($"[Adventure Boss] Challenge added : {_adventureBossChallengeList.Count}");
}
}
catch (Exception e)
Expand All @@ -94,6 +149,7 @@ partial void SubscribeAdventureBossChallenge(ActionEvaluation<ExploreAdventureBo

partial void SubscribeAdventureBossRush(ActionEvaluation<SweepAdventureBoss> evt)
{
Log.Debug("[Adventure Boss] Subscribe Rush");
try
{
if (evt.Exception is null && evt.Action is { } rush)
Expand All @@ -103,6 +159,7 @@ partial void SubscribeAdventureBossRush(ActionEvaluation<SweepAdventureBoss> evt
_adventureBossRushList.Add(AdventureBossRushData.GetRushInfo(
prevState, outputState, evt.BlockIndex, _blockTimeOffset, rush
));
Log.Debug($"[Adventure Boss] Rush added : {_adventureBossRushList.Count}");
}
}
catch (Exception e)
Expand All @@ -118,6 +175,7 @@ partial void SubscribeAdventureBossRush(ActionEvaluation<SweepAdventureBoss> evt

partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation<UnlockFloor> evt)
{
Log.Debug("[Adventure Boss] Subscribe UnlockFloor");
try
{
if (evt.Exception is null && evt.Action is { } unlock)
Expand All @@ -127,6 +185,7 @@ partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation<UnlockFloor> evt
_adventureBossUnlockFloorList.Add(AdventureBossUnlockFloorData.GetUnlockInfo(
prevState, outputState, evt.BlockIndex, _blockTimeOffset, unlock
));
Log.Debug($"[Adventure Boss] Unlock added : {_adventureBossUnlockFloorList.Count}");
}
}
catch (Exception e)
Expand All @@ -142,6 +201,7 @@ partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation<UnlockFloor> evt

partial void SubscribeAdventureBossClaim(ActionEvaluation<ClaimAdventureBossReward> evt)
{
Log.Debug("[Adventure Boss] Subscribe Claim");
try
{
if (evt.Exception is null && evt.Action is { } claim)
Expand All @@ -151,6 +211,7 @@ partial void SubscribeAdventureBossClaim(ActionEvaluation<ClaimAdventureBossRewa
_adventureBossClaimRewardList.Add(AdventureBossClaimRewardData.GetClaimInfo(
prevState, evt.BlockIndex, _blockTimeOffset, claim
));
Log.Debug($"[Adventure Boss] Claim added : {_adventureBossClaimRewardList.Count}");

// Update season info
var latestSeason = prevState.GetLatestAdventureBossSeason();
Expand All @@ -160,6 +221,7 @@ partial void SubscribeAdventureBossClaim(ActionEvaluation<ClaimAdventureBossRewa
_adventureBossSeasonList.Add(AdventureBossSeasonData.GetAdventureBossSeasonInfo(
outputState, season, _blockTimeOffset
));
Log.Debug($"[Adventure Boss] Season updated : {_adventureBossSeasonList.Count}");
}
}
catch (Exception e)
Expand Down

0 comments on commit 7e2d7b8

Please sign in to comment.