Skip to content

Commit

Permalink
Merge pull request #769 from planetarium/feature/unlock-combination-slot
Browse files Browse the repository at this point in the history
Save UnlockCombinationSlot action
  • Loading branch information
U-lis authored Sep 13, 2024
2 parents d5d2fbb + b1d58eb commit fafaeb3
Show file tree
Hide file tree
Showing 12 changed files with 4,714 additions and 65 deletions.

Large diffs are not rendered by default.

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

#nullable disable

namespace NineChronicles.DataProvider.Executable.Migrations
{
public partial class UnlockCombinationSlot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "UnlockCombinationSlot",
columns: table => new
{
Id = table.Column<string>(type: "varchar(255)", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
AgentAddress = table.Column<string>(type: "varchar(255)", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
AvatarAddress = table.Column<string>(type: "varchar(255)", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
SlotIndex = table.Column<int>(type: "int", nullable: false),
NcgCost = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
CrystalCost = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
MaterialCosts = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
BlockIndex = table.Column<long>(type: "bigint", nullable: false),
Date = table.Column<DateOnly>(type: "date", nullable: false),
TimeStamp = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UnlockCombinationSlot", x => x.Id);
table.ForeignKey(
name: "FK_UnlockCombinationSlot_Agents_AgentAddress",
column: x => x.AgentAddress,
principalTable: "Agents",
principalColumn: "Address");
table.ForeignKey(
name: "FK_UnlockCombinationSlot_Avatars_AvatarAddress",
column: x => x.AvatarAddress,
principalTable: "Avatars",
principalColumn: "Address");
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateIndex(
name: "IX_UnlockCombinationSlot_AgentAddress",
table: "UnlockCombinationSlot",
column: "AgentAddress");

migrationBuilder.CreateIndex(
name: "IX_UnlockCombinationSlot_AvatarAddress",
table: "UnlockCombinationSlot",
column: "AvatarAddress");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UnlockCombinationSlot");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -940,110 +940,80 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("RapidCombinations");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.CraftRankingModel", b =>
modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.Crafting.UnlockCombinationSlotModel", b =>
{
b.Property<string>("AgentAddress")
.HasColumnType("longtext");
b.Property<string>("Id")
.HasColumnType("varchar(255)");
b.Property<int?>("ArmorId")
.HasColumnType("int");
b.Property<string>("AgentAddress")
.HasColumnType("varchar(255)");
b.Property<string>("AvatarAddress")
.HasColumnType("longtext");
b.Property<int?>("AvatarLevel")
.HasColumnType("int");
.HasColumnType("varchar(255)");
b.Property<long>("BlockIndex")
.HasColumnType("bigint");
b.Property<int?>("Cp")
.HasColumnType("int");
b.Property<decimal>("CrystalCost")
.HasColumnType("decimal(65,30)");
b.Property<int>("CraftCount")
.HasColumnType("int");
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<string>("Name")
b.Property<string>("MaterialCosts")
.HasColumnType("longtext");
b.Property<int>("Ranking")
.HasColumnType("int");
b.Property<decimal>("NcgCost")
.HasColumnType("decimal(65,30)");
b.Property<int?>("TitleId")
b.Property<int>("SlotIndex")
.HasColumnType("int");
b.ToTable("CraftRankings");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.CustomCraft.CustomEquipmentCraftCountModel", b =>
{
b.Property<int>("IconId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<DateTimeOffset>("TimeStamp")
.HasColumnType("datetime(6)");
b.Property<long>("Count")
.HasColumnType("bigint");
b.HasKey("Id");
b.Property<string>("ItemSubType")
.HasColumnType("longtext");
b.HasIndex("AgentAddress");
b.HasKey("IconId");
b.HasIndex("AvatarAddress");
b.ToTable("CustomEquipmentCraftCount");
b.ToTable("UnlockCombinationSlot");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.CustomCraft.CustomEquipmentCraftModel", b =>
modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.CraftRankingModel", b =>
{
b.Property<string>("Id")
.HasColumnType("varchar(255)");
b.Property<string>("AdditionalCost")
b.Property<string>("AgentAddress")
.HasColumnType("longtext");
b.Property<string>("AvatarAddress")
.HasColumnType("varchar(255)");
b.Property<long>("BlockIndex")
.HasColumnType("bigint");
b.Property<DateOnly>("Date")
.HasColumnType("date");
b.Property<int>("DrawingAmount")
b.Property<int?>("ArmorId")
.HasColumnType("int");
b.Property<int>("DrawingToolAmount")
b.Property<string>("AvatarAddress")
.HasColumnType("longtext");
b.Property<int?>("AvatarLevel")
.HasColumnType("int");
b.Property<string>("ElementalType")
.HasColumnType("longtext");
b.Property<long>("BlockIndex")
.HasColumnType("bigint");
b.Property<int>("EquipmentItemId")
b.Property<int?>("Cp")
.HasColumnType("int");
b.Property<int>("IconId")
b.Property<int>("CraftCount")
.HasColumnType("int");
b.Property<string>("ItemSubType")
b.Property<string>("Name")
.HasColumnType("longtext");
b.Property<decimal>("NcgCost")
.HasColumnType("decimal(65,30)");
b.Property<int>("RecipeId")
b.Property<int>("Ranking")
.HasColumnType("int");
b.Property<int>("SlotIndex")
b.Property<int?>("TitleId")
.HasColumnType("int");
b.Property<DateTimeOffset>("TimeStamp")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.HasIndex("AvatarAddress");
b.ToTable("CustomEquipmentCraft");
b.ToTable("CraftRankings");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.DailyMetricModel", b =>
Expand Down Expand Up @@ -3974,6 +3944,21 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("Avatar");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.Crafting.UnlockCombinationSlotModel", b =>
{
b.HasOne("NineChronicles.DataProvider.Store.Models.AgentModel", "Agent")
.WithMany()
.HasForeignKey("AgentAddress");
b.HasOne("NineChronicles.DataProvider.Store.Models.AvatarModel", "Avatar")
.WithMany()
.HasForeignKey("AvatarAddress");
b.Navigation("Agent");
b.Navigation("Avatar");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.EventConsumableItemCraftsModel", b =>
{
b.HasOne("NineChronicles.DataProvider.Store.Models.AgentModel", "Agent")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace NineChronicles.DataProvider.DataRendering.Crafting
{
using System;
using System.Collections.Generic;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume.Action;
using Nekoyume.Module;
using Nekoyume.TableData;
using NineChronicles.DataProvider.Store.Models.Crafting;

public static class UnlockCombinationSlotData
{
private const int GoldenDustId = 600201;
private const int RubyDustId = 600202;

public static UnlockCombinationSlotModel GetUnlockCombinationSlotInfo(
IWorld prevStates,
Address signer,
UnlockCombinationSlot action,
long blockIndex,
DateTimeOffset blockTime
)
{
var cost = prevStates.GetSheet<UnlockCombinationSlotCostSheet>()[action.SlotIndex];
var materialCost = new List<string>();
if (cost.GoldenDustPrice > 0)
{
materialCost.Add($"{GoldenDustId}:{cost.GoldenDustPrice}");
}

if (cost.RubyDustPrice > 0)
{
materialCost.Add($"{RubyDustId}:{cost.RubyDustPrice}");
}

return new UnlockCombinationSlotModel
{
Id = Guid.NewGuid().ToString(),
AgentAddress = signer.ToString(),
AvatarAddress = action.AvatarAddress.ToString(),
SlotIndex = action.SlotIndex,
NcgCost = (decimal)cost.NcgPrice,
CrystalCost = cost.CrystalPrice,
MaterialCosts = string.Join(",", materialCost),
BlockIndex = blockIndex,
Date = DateOnly.FromDateTime(blockTime.DateTime),
TimeStamp = blockTime,
};
}
}
}
3 changes: 3 additions & 0 deletions NineChronicles.DataProvider/RenderSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)
// Crafting
_actionRenderer.EveryRender<RapidCombination>().Subscribe(SubscribeRapidCombination);
_actionRenderer.EveryRender<CustomEquipmentCraft>().Subscribe(SubscribeCustomEquipmentCraft);
_actionRenderer.EveryRender<UnlockCombinationSlot>().Subscribe(SubscribeUnlockCombinationSlot);

// Grinding
_actionRenderer.EveryRender<Grinding>().Subscribe(SubscribeGrinding);
Expand All @@ -1683,6 +1684,8 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken)

partial void SubscribeCustomEquipmentCraft(ActionEvaluation<CustomEquipmentCraft> evt);

partial void SubscribeUnlockCombinationSlot(ActionEvaluation<UnlockCombinationSlot> evt);

//// Grinding
partial void SubscribeGrinding(ActionEvaluation<Grinding> ev);
/* Partial Methods */
Expand Down
21 changes: 21 additions & 0 deletions NineChronicles.DataProvider/Store/Models/Base/BaseModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NineChronicles.DataProvider.Store.Models
{
using System;
using System.ComponentModel.DataAnnotations;

public abstract class BaseModel
{
[Key]
public string? Id { get; set; }

public long BlockIndex { get; set; }

public string? AgentAddress { get; set; }

public AgentModel? Agent { get; set; }

public DateOnly Date { get; set; }

public DateTimeOffset TimeStamp { get; set; }
}
}
9 changes: 9 additions & 0 deletions NineChronicles.DataProvider/Store/Models/Base/IAvatar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NineChronicles.DataProvider.Store.Models
{
public interface IAvatar
{
string? AvatarAddress { get; set; }

AvatarModel? Avatar { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NineChronicles.DataProvider.Store.Models.Crafting
{
public class UnlockCombinationSlotModel : BaseModel, IAvatar
{
public string? AvatarAddress { get; set; }

public AvatarModel? Avatar { get; set; }

public int SlotIndex { get; set; }

public decimal NcgCost { get; set; }

public decimal CrystalCost { get; set; }

public string? MaterialCosts { get; set; }
}
}
35 changes: 35 additions & 0 deletions NineChronicles.DataProvider/Store/MySql/CraftingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,40 @@ public partial List<CustomEquipmentCraftCountModel> GetCustomEquipmentCraftCount
? ctx.CustomEquipmentCraftCount.ToList()
: ctx.CustomEquipmentCraftCount.Where(c => c.ItemSubType == itemSubType).ToList();
}

// UnlockCombinationSlot
public async partial Task StoreUnlockCombinationSlotList(
List<UnlockCombinationSlotModel> unlockCombinationSlotList
)
{
NineChroniclesContext? ctx = null;
try
{
ctx = await _dbContextFactory.CreateDbContextAsync();

foreach (var ucs in unlockCombinationSlotList)
{
if (!await ctx.UnlockCombinationSlot.AnyAsync(u => u.Id == ucs.Id))
{
await ctx.UnlockCombinationSlot.AddAsync(ucs);
}
}

await ctx.SaveChangesAsync();
Log.Debug($"[UnlockCombinationSlot] {unlockCombinationSlotList.Count} UnlockCombinationSlot saved.");
}
catch (Exception e)
{
Log.Debug(e.Message);
Log.Debug(e.StackTrace);
}
finally
{
if (ctx is not null)
{
await ctx.DisposeAsync();
}
}
}
}
}
Loading

0 comments on commit fafaeb3

Please sign in to comment.