Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

development merge feature/collection #623

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

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

#nullable disable

namespace NineChronicles.DataProvider.Executable.Migrations
{
public partial class ActivateCollection : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ActivateCollections",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
AvatarAddress = table.Column<string>(type: "varchar(255)", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
CollectionId = table.Column<int>(type: "int", nullable: false),
ActionId = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
BlockIndex = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_ActivateCollections", x => x.Id);
table.ForeignKey(
name: "FK_ActivateCollections_Avatars_AvatarAddress",
column: x => x.AvatarAddress,
principalTable: "Avatars",
principalColumn: "Address",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "CollectionOptionModel",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
StatType = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
OperationType = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Value = table.Column<long>(type: "bigint", nullable: false),
ActivateCollectionId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CollectionOptionModel", x => x.Id);
table.ForeignKey(
name: "FK_CollectionOptionModel_ActivateCollections_ActivateCollection~",
column: x => x.ActivateCollectionId,
principalTable: "ActivateCollections",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateIndex(
name: "IX_ActivateCollections_AvatarAddress",
table: "ActivateCollections",
column: "AvatarAddress");

migrationBuilder.CreateIndex(
name: "IX_CollectionOptionModel_ActivateCollectionId",
table: "CollectionOptionModel",
column: "ActivateCollectionId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CollectionOptionModel");

migrationBuilder.DropTable(
name: "ActivateCollections");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("AbilityRanking");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.ActivateCollectionModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

b.Property<string>("ActionId")
.IsRequired()
.HasColumnType("longtext");

b.Property<string>("AvatarAddress")
.IsRequired()
.HasColumnType("varchar(255)");

b.Property<long>("BlockIndex")
.HasColumnType("bigint");

b.Property<int>("CollectionId")
.HasColumnType("int");

b.Property<DateTimeOffset>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("datetime(6)");

b.HasKey("Id");

b.HasIndex("AvatarAddress");

b.ToTable("ActivateCollections");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.AgentModel", b =>
{
b.Property<string>("Address")
Expand Down Expand Up @@ -3135,6 +3166,49 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("WorldBossSeasonMigrationModels");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.ActivateCollectionModel", b =>
{
b.HasOne("NineChronicles.DataProvider.Store.Models.AvatarModel", "Avatar")
.WithMany("ActivateCollections")
.HasForeignKey("AvatarAddress")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.OwnsMany("NineChronicles.DataProvider.Store.Models.CollectionOptionModel", "Options", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

b1.Property<int>("ActivateCollectionId")
.HasColumnType("int");

b1.Property<string>("OperationType")
.IsRequired()
.HasColumnType("longtext");

b1.Property<string>("StatType")
.IsRequired()
.HasColumnType("longtext");

b1.Property<long>("Value")
.HasColumnType("bigint");

b1.HasKey("Id");

b1.HasIndex("ActivateCollectionId");

b1.ToTable("CollectionOptionModel");

b1.WithOwner()
.HasForeignKey("ActivateCollectionId");
});

b.Navigation("Avatar");

b.Navigation("Options");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.AuraSummonFailModel", b =>
{
b.HasOne("NineChronicles.DataProvider.Store.Models.AgentModel", "Agent")
Expand Down Expand Up @@ -3679,6 +3753,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("Agent");
});

modelBuilder.Entity("NineChronicles.DataProvider.Store.Models.AvatarModel", b =>
{
b.Navigation("ActivateCollections");
});
#pragma warning restore 612, 618
}
}
Expand Down
2 changes: 1 addition & 1 deletion NineChronicles.DataProvider.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ IActionEvaluatorConfiguration GetActionEvaluatorConfiguration(IConfiguration con
ReorgInterval = headlessConfig.ReorgInterval,
TxLifeTime = TimeSpan.FromMinutes(headlessConfig.TxLifeTime),
MinerCount = headlessConfig.NoMiner ? 0 : 1,
NetworkType = headlessConfig.NetworkType,
Planet = headlessConfig.Planet,
};
NineChroniclesNodeService service =
NineChroniclesNodeService.Create(nineChroniclesProperties, context);
Expand Down
79 changes: 79 additions & 0 deletions NineChronicles.DataProvider.Tests/ActivateCollectionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Nekoyume.Model.Stat;
using NineChronicles.DataProvider.Store.Models;
using Xunit;

namespace NineChronicles.DataProvider.Tests;

public class ActivateCollectionTest : TestBase
{

[Fact]
public async Task RelationShip()
{
var avatarAddress = new PrivateKey().Address;
var now = DateTimeOffset.UtcNow;
var agent = new AgentModel
{
Address = avatarAddress.ToString()
};
var avatar = new AvatarModel
{
Address = avatarAddress.ToString(),
AgentAddress = avatarAddress.ToString(),
Name = "name",
AvatarLevel = 1,
TitleId = null,
ArmorId = null,
Cp = 0,
Timestamp = now
};
await Context.Agents.AddAsync(agent);
await Context.Avatars.AddAsync(avatar);
await Context.SaveChangesAsync();

var actionId = Guid.NewGuid().ToString();
for (int i = 0; i < 2; i++)
{
var modifiers = new List<StatModifier>
{
new StatModifier(StatType.HP, StatModifier.OperationType.Add, 1L),
new StatModifier(StatType.HP, StatModifier.OperationType.Percentage, 1L)
};
var options = new List<CollectionOptionModel>();
var collection = new ActivateCollectionModel
{
Avatar = avatar,
CollectionId = 1 + i,
BlockIndex = 1L + i,
ActionId = actionId,
Options = options,
};
foreach (var modifier in modifiers)
{
options.Add(new CollectionOptionModel
{
Value = modifier.Value,
OperationType = modifier.Operation.ToString(),
StatType = modifier.StatType.ToString(),
});
}

await Context.ActivateCollections.AddAsync(collection);
Assert.Equal(avatar.Address, collection.AvatarAddress);
Assert.Equal(2, collection.Options.Count);
}
await Context.SaveChangesAsync();
Assert.Equal(2, avatar.ActivateCollections.Count);
Assert.Equal(2, Context.ActivateCollections.Count(p => p.ActionId == actionId));
}
protected override IWorldState GetMockState()
{
return new MockWorldState();
}
}
7 changes: 4 additions & 3 deletions NineChronicles.DataProvider/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#nullable enable

namespace NineChronicles.DataProvider
{
#nullable enable

using Nekoyume;
using NineChronicles.Headless.Properties;

public class Configuration
Expand Down Expand Up @@ -95,6 +96,6 @@ public class Configuration
#nullable disable
public string MySqlConnectionString { get; set; }

public NetworkType NetworkType { get; set; } = NetworkType.Main;
public Planet Planet { get; set; } = Planet.Odin;
}
}
37 changes: 29 additions & 8 deletions NineChronicles.DataProvider/DataRendering/AvatarData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace NineChronicles.DataProvider.DataRendering
using Nekoyume.Extensions;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Item;
using Nekoyume.Model.Stat;
using Nekoyume.Model.State;
using Nekoyume.Module;
using Nekoyume.TableData;
Expand All @@ -27,14 +28,22 @@ public static AvatarModel GetAvatarInfo(
DateTimeOffset blockTime)
{
AvatarState avatarState = outputStates.GetAvatarState(avatarAddress);
var collectionExist = outputStates.TryGetCollectionState(avatarAddress, out var collectionState);
var sheetTypes = new List<Type>
{
typeof(CharacterSheet),
typeof(CostumeStatSheet),
typeof(RuneListSheet),
typeof(RuneOptionSheet),
typeof(CollectionSheet),
};
if (collectionExist)
{
sheetTypes.Add(typeof(CollectionSheet));
}

var sheets = outputStates.GetSheets(
sheetTypes: new[]
{
typeof(CharacterSheet),
typeof(CostumeStatSheet),
typeof(RuneListSheet),
typeof(RuneOptionSheet),
});
sheetTypes: sheetTypes);

var itemSlotStateAddress = ItemSlotState.DeriveAddress(avatarAddress, BattleType.Adventure);
var itemSlotState = outputStates.TryGetLegacyState(itemSlotStateAddress, out List rawItemSlotState)
Expand Down Expand Up @@ -103,13 +112,25 @@ public static AvatarModel GetAvatarInfo(
avatarTitleId = avatarTitleCostume.Id;
}

var collectionModifiers = new List<StatModifier>();
if (collectionExist)
{
var collectionSheet = sheets.GetSheet<CollectionSheet>();
foreach (var id in collectionState.Ids)
{
var row = collectionSheet[id];
collectionModifiers.AddRange(row.StatModifiers);
}
}

var avatarCp = CPHelper.TotalCP(
equipmentList,
costumeList,
runeOptions,
avatarState.level,
characterRow,
costumeStatSheet);
costumeStatSheet,
collectionModifiers);
string avatarName = avatarState.name;

Log.Debug(
Expand Down
Loading
Loading