Skip to content

Commit

Permalink
Merge pull request #713 from planetarium/release/160
Browse files Browse the repository at this point in the history
Backmerge 160
  • Loading branch information
U-lis authored Jul 9, 2024
2 parents 577e34e + 30c4d97 commit 83a405a
Show file tree
Hide file tree
Showing 13 changed files with 4,333 additions and 28 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace NineChronicles.DataProvider.Executable.Migrations
{
public partial class AddMissingColumn : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<decimal>(
name: "TotalBounty",
table: "AdventureBossWanted",
type: "decimal(65,30)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");

migrationBuilder.AlterColumn<decimal>(
name: "Bounty",
table: "AdventureBossWanted",
type: "decimal(65,30)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");

migrationBuilder.AddColumn<long>(
name: "Season",
table: "AdventureBossChallenge",
type: "bigint",
nullable: false,
defaultValue: 0L);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Season",
table: "AdventureBossChallenge");

migrationBuilder.AlterColumn<int>(
name: "TotalBounty",
table: "AdventureBossWanted",
type: "int",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(65,30)");

migrationBuilder.AlterColumn<int>(
name: "Bounty",
table: "AdventureBossWanted",
type: "int",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(65,30)");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("Point")
.HasColumnType("int");
b.Property<long>("Season")
.HasColumnType("bigint");
b.Property<int>("StartFloor")
.HasColumnType("int");
Expand Down Expand Up @@ -290,8 +293,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<long>("BlockIndex")
.HasColumnType("bigint");
b.Property<int>("Bounty")
.HasColumnType("int");
b.Property<decimal>("Bounty")
.HasColumnType("decimal(65,30)");
b.Property<int>("Count")
.HasColumnType("int");
Expand All @@ -305,8 +308,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTimeOffset>("TimeStamp")
.HasColumnType("datetime(6)");
b.Property<int>("TotalBounty")
.HasColumnType("int");
b.Property<decimal>("TotalBounty")
.HasColumnType("decimal(65,30)");
b.HasKey("Id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ public async Task WorldBossRanking_Sort()
for (int j = 0; j < 3; j++)
{
var model = (Dictionary<string, object>)models[j];
Assert.Equal(j + 1, model["ranking"]);
Assert.Equal(avatarAddresses[j].ToHex(), model["address"]);

Assert.Equal(3, model["ranking"]);
Assert.Contains(new Address((string)model["address"]), avatarAddresses);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace NineChronicles.DataProvider.DataRendering.AdventureBoss
using System;
using Libplanet.Action.State;
using Nekoyume.Action.AdventureBoss;
using Nekoyume.Model.AdventureBoss;
using Nekoyume.Module;
using NineChronicles.DataProvider.Store.Models.AdventureBoss;

Expand All @@ -16,16 +17,19 @@ public static AdventureBossChallengeModel GetChallengeInfo(
ExploreAdventureBoss challenge
)
{
var prevExplorer = prevStates.GetExplorer(challenge.Season, challenge.AvatarAddress);
var prevExplorer = prevStates.TryGetExplorer(challenge.Season, challenge.AvatarAddress, out var exp)
? exp
: new Explorer(challenge.AvatarAddress, "name");
var outputExplorer = outputStates.GetExplorer(challenge.Season, challenge.AvatarAddress);
var exploreBoard = outputStates.GetExploreBoard(challenge.Season);

return new AdventureBossChallengeModel
{
Id = challenge.Id.ToString(),
BlockIndex = blockIndex,
Season = challenge.Season,
AvatarAddress = challenge.AvatarAddress.ToString(),
StartFloor = prevExplorer.Floor + 1, // Challenge from next of last cleared floor
StartFloor = prevExplorer.Floor,
EndFloor = outputExplorer.Floor,
UsedApPotion = outputExplorer.UsedApPotion - prevExplorer.UsedApPotion,
Point = outputExplorer.Score - prevExplorer.Score,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ ClaimAdventureBossReward claim

if (investor is not null)
{
if (!claimedSeasonList.Contains(szn))
{
claimedSeasonList.Add(szn);
}

continueInv = AdventureBossHelper.CollectWantedReward(
myReward,
gameConfig,
Expand All @@ -83,11 +78,6 @@ ref myReward

if (explorer is not null)
{
if (!claimedSeasonList.Contains(szn))
{
claimedSeasonList.Add(szn);
}

continueExp = AdventureBossHelper.CollectExploreReward(
myReward,
gameConfig,
Expand All @@ -109,6 +99,12 @@ out ncgReward
{
break;
}

// Add claimed season if not breaking loop
if (!claimedSeasonList.Contains(szn))
{
claimedSeasonList.Add(szn);
}
}

var rewardData = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SweepAdventureBoss rush
{
var prevExplorer = prevStates.GetExplorer(rush.Season, rush.AvatarAddress);
var outputExplorer = outputStates.GetExplorer(rush.Season, rush.AvatarAddress);
var prevExploreBoard = prevStates.GetExploreBoard(rush.Season);
var outputExploreBoard = outputStates.GetExploreBoard(rush.Season);

return new AdventureBossRushModel
Expand All @@ -30,7 +29,7 @@ SweepAdventureBoss rush
EndFloor = outputExplorer.Floor,
UsedApPotion = outputExplorer.UsedApPotion - prevExplorer.UsedApPotion,
Point = outputExplorer.Score - prevExplorer.Score,
TotalPoint = outputExploreBoard.TotalPoint - prevExploreBoard.TotalPoint,
TotalPoint = outputExploreBoard.TotalPoint,
Date = DateOnly.FromDateTime(blockTime.DateTime),
TimeStamp = blockTime,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DateTimeOffset blockTime
FixedRewardData = (bountyBoard.FixedRewardItemId ?? bountyBoard.FixedRewardFavId).ToString(),
RandomRewardData = (bountyBoard.RandomRewardItemId ?? bountyBoard.RandomRewardFavId).ToString(),
RaffleWinnerAddress = exploreBoard.RaffleWinner is null ? null : exploreBoard.RaffleWinner.ToString(),
RaffleReward = Convert.ToDecimal(exploreBoard.RaffleReward?.RawValue),
RaffleReward = Convert.ToDecimal(exploreBoard.RaffleReward?.GetQuantityString()),
Date = DateOnly.FromDateTime(blockTime.DateTime),
TimeStamp = blockTime,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class AdventureBossChallengeModel

public long BlockIndex { get; set; }

public long Season { get; set; }

public string? AvatarAddress { get; set; }

public AvatarModel? Avatar { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Refactor: Move MySqlStore.cs to MySql and make all namespaces to NineChronicles.dataProvider.MySqlStore
// NOTE: Only `StoreAdventureBossSeasonList` will update incoming data because other data does not have any data to be updated.

namespace NineChronicles.DataProvider.Store
{
Expand Down
8 changes: 5 additions & 3 deletions NineChronicles.DataProvider/Store/MySqlStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2310,8 +2310,10 @@ public void StoreWorldBossMigration(int raidId)
public List<WorldBossRankingModel> GetWorldBossRanking(int raidId, int? queryOffset, int? queryLimit)
{
using NineChroniclesContext? ctx = _dbContextFactory.CreateDbContext();
var query = ctx.Set<WorldBossRankingModel>()
.FromSqlRaw(@"SELECT `AvatarName`, `HighScore`, `TotalScore`, `Cp`, `Level`, `Address`, `IconId`, row_number() over(ORDER BY `TotalScore` DESC, `UpdatedAt`) as `Ranking` FROM `Raiders` WHERE `RaidId` = {0}", raidId);

// Call ToList for convert query result from IQueryable
IEnumerable<WorldBossRankingModel> query = ctx.Set<WorldBossRankingModel>()
.FromSqlRaw("SET @prev_score = (SELECT max(`TotalScore`) FROM `Raiders` WHERE `RaidId` = {0}); SET @rank = (SELECT count(*) FROM `Raiders` WHERE `RaidId` = {0} AND `TotalScore` = @prev_score); SELECT `AvatarName`, `HighScore`, `TotalScore`, `Cp`, `Level`, `Address`, `IconId`, @rank := IF(@prev_score = TotalScore, @rank, @rank + 1) as `Ranking` FROM `Raiders` WHERE `RaidId` = {0} ORDER BY `TotalScore` DESC", raidId).ToList();
if (queryOffset.HasValue)
{
query = query.Skip(queryOffset.Value);
Expand All @@ -2322,7 +2324,7 @@ public List<WorldBossRankingModel> GetWorldBossRanking(int raidId, int? queryOff
query = query.Take(queryLimit.Value);
}

return query.ToList();
return query.OrderBy(i => i.Ranking).ToList();
}

public int GetTotalRaiders(int raidId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ partial void SubscribeAdventureBossClaim(ActionEvaluation<ClaimAdventureBossRewa
// Update season info
var latestSeason = prevState.GetLatestAdventureBossSeason();
var season = latestSeason.EndBlockIndex <= evt.BlockIndex
? latestSeason.Season
: latestSeason.Season - 1;
? latestSeason.Season // New season not started
: latestSeason.Season - 1; // New season started
_adventureBossSeasonList.Add(AdventureBossSeasonData.GetAdventureBossSeasonInfo(
outputState, season, _blockTimeOffset
));
Expand Down

0 comments on commit 83a405a

Please sign in to comment.