chaapter dbs but no tuse dyet

This commit is contained in:
rfi
2024-02-25 10:06:28 +07:00
parent ded826adf0
commit 068142914f
4 changed files with 634 additions and 1 deletions

View File

@@ -1,10 +1,10 @@
using BLHX.Server.Common.Proto.common;
using BLHX.Server.Common.Proto.p12;
using BLHX.Server.Common.Proto.p13;
using BLHX.Server.Common.Utils;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Numerics;
namespace BLHX.Server.Common.Database
{
@@ -16,6 +16,7 @@ namespace BLHX.Server.Common.Database
public DbSet<PlayerResource> Resources { get; set; }
public DbSet<ResourceField> ResourceFields { get; set; }
public DbSet<PlayerShip> Ships { get; set; }
public DbSet<ChapterInfo> ChapterInfoes { get; set; }
public PlayerContext()
{
@@ -127,6 +128,31 @@ namespace BLHX.Server.Common.Database
e.Property(b => b.CoreLists)
.HasJsonConversion();
});
modelBuilder.Entity<ChapterInfo>(e =>
{
e.Property(x => x.EscortLists)
.HasJsonConversion();
e.Property(x => x.AiLists)
.HasJsonConversion();
e.Property(x => x.BuffLists)
.HasJsonConversion();
e.Property(x => x.GroupLists)
.HasJsonConversion();
e.Property(x => x.BattleStatistics)
.HasJsonConversion();
e.Property(x => x.CellFlagLists)
.HasJsonConversion();
e.Property(x => x.CellLists)
.HasJsonConversion();
e.Property(x => x.ChapterStrategyLists)
.HasJsonConversion();
e.Property(x => x.ExtraFlagLists)
.HasJsonConversion();
e.Property(x => x.FleetDuties)
.HasJsonConversion();
e.Property(x => x.OperationBuffs)
.HasJsonConversion();
});
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
@@ -153,10 +179,12 @@ namespace BLHX.Server.Common.Database
public List<Groupinfo> Fleets { get; set; } = null!;
public List<Idtimeinfo> ShipSkins { get; set; } = null!;
public uint? CurrentChapter { get; set; }
public virtual ICollection<PlayerResource> Resources { get; set; } = [];
public virtual ICollection<ResourceField> ResourceFields { get; set; } = [];
public virtual ICollection<PlayerShip> Ships { get; set; } = [];
public virtual ICollection<ChapterInfo> ChapterInfoes { get; set; } = [];
public Player(string token, Displayinfo displayInfo, string name)
{
@@ -389,4 +417,65 @@ namespace BLHX.Server.Common.Database
return amount;
}
}
[PrimaryKey(nameof(Id), nameof(PlayerUid))]
public class ChapterInfo
{
[Key]
public uint Id { get; set; }
public DateTime Time { get; set; }
public List<Chaptercellinfo> CellLists { get; set; } = [];
public List<Groupinchapter> GroupLists { get; set; } = [];
public List<Chaptercellinfo> AiLists { get; set; } = [];
public List<Chaptercellinfo> EscortLists { get; set; } = [];
public uint Round { get; set; }
public bool IsSubmarineAutoAttack { get; set; }
public List<uint> OperationBuffs { get; set; } = [];
public uint ModelActCount { get; set; }
public List<uint> BuffLists { get; set; } = [];
public uint LoopFlag { get; set; }
public List<uint> ExtraFlagLists { get; set; } = [];
public List<Cellflag> CellFlagLists { get; set; } = [];
public uint ChapterHp { get; set; }
public List<Strategyinfo> ChapterStrategyLists { get; set; } = [];
public uint KillCount { get; set; }
public uint InitShipCount { get; set; }
public uint ContinuousKillCount { get; set; }
public List<Strategyinfo> BattleStatistics { get; set; } = [];
public List<fleetDutykeyValuePair> FleetDuties { get; set; } = [];
public uint MoveStepCount { get; set; }
[Key]
public uint PlayerUid { get; set; }
public virtual Player Player { get; set; } = null!;
public Currentchapterinfo ToProto()
{
return new Currentchapterinfo()
{
Id = Id,
AiLists = AiLists,
BattleStatistics = BattleStatistics,
BuffLists = BuffLists,
CellFlagLists = CellFlagLists,
CellLists = CellLists,
ChapterHp = ChapterHp,
ChapterStrategyLists = ChapterStrategyLists,
ContinuousKillCount = ContinuousKillCount,
EscortLists = EscortLists,
ExtraFlagLists = ExtraFlagLists,
FleetDuties = FleetDuties,
GroupLists = GroupLists,
InitShipCount = InitShipCount,
IsSubmarineAutoAttack = Convert.ToUInt32(IsSubmarineAutoAttack),
KillCount = KillCount,
LoopFlag = LoopFlag,
ModelActCount = ModelActCount,
MoveStepCount = MoveStepCount,
OperationBuffs = OperationBuffs,
Round = Round,
Time = (uint)new DateTimeOffset(Time).ToUnixTimeSeconds()
};
}
}
}

View File

@@ -0,0 +1,363 @@
// <auto-generated />
using System;
using BLHX.Server.Common.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BLHX.Server.Common.Migrations.Player
{
[DbContext(typeof(PlayerContext))]
[Migration("20240225030459_ChaptersDB")]
partial class ChaptersDB
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Proxies:ChangeTracking", false)
.HasAnnotation("Proxies:CheckEquality", false)
.HasAnnotation("Proxies:LazyLoading", true);
modelBuilder.Entity("BLHX.Server.Common.Database.ChapterInfo", b =>
{
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<uint>("PlayerUid")
.HasColumnType("INTEGER");
b.Property<string>("AiLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("BattleStatistics")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("BuffLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("CellFlagLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("CellLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("ChapterHp")
.HasColumnType("INTEGER");
b.Property<string>("ChapterStrategyLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("ContinuousKillCount")
.HasColumnType("INTEGER");
b.Property<string>("EscortLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("ExtraFlagLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("FleetDuties")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("GroupLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("InitShipCount")
.HasColumnType("INTEGER");
b.Property<bool>("IsSubmarineAutoAttack")
.HasColumnType("INTEGER");
b.Property<uint>("KillCount")
.HasColumnType("INTEGER");
b.Property<uint>("LoopFlag")
.HasColumnType("INTEGER");
b.Property<uint>("ModelActCount")
.HasColumnType("INTEGER");
b.Property<uint>("MoveStepCount")
.HasColumnType("INTEGER");
b.Property<string>("OperationBuffs")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("Round")
.HasColumnType("INTEGER");
b.Property<DateTime>("Time")
.HasColumnType("TEXT");
b.HasKey("Id", "PlayerUid");
b.HasIndex("PlayerUid");
b.ToTable("ChapterInfoes");
});
modelBuilder.Entity("BLHX.Server.Common.Database.Player", b =>
{
b.Property<uint>("Uid")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Adv")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasDefaultValue("");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<uint?>("CurrentChapter")
.HasColumnType("INTEGER");
b.Property<string>("DisplayInfo")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("Exp")
.HasColumnType("INTEGER");
b.Property<string>("Fleets")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("jsonb")
.HasDefaultValue("[{\"Id\":1,\"Name\":null,\"ShipLists\":[1,2],\"Commanders\":[]},{\"Id\":2,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":11,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]},{\"Id\":12,\"Name\":null,\"ShipLists\":[],\"Commanders\":[]}]");
b.Property<uint>("Level")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ShipSkins")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("jsonb")
.HasDefaultValue("[]");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Uid");
b.HasIndex("Token")
.IsUnique();
b.ToTable("Players");
});
modelBuilder.Entity("BLHX.Server.Common.Database.PlayerResource", b =>
{
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<uint>("PlayerUid")
.HasColumnType("INTEGER");
b.Property<uint>("Num")
.HasColumnType("INTEGER");
b.HasKey("Id", "PlayerUid");
b.HasIndex("PlayerUid");
b.ToTable("Resources");
});
modelBuilder.Entity("BLHX.Server.Common.Database.PlayerShip", b =>
{
b.Property<uint>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<uint>("ActivityNpc")
.HasColumnType("INTEGER");
b.Property<uint>("BluePrintFlag")
.HasColumnType("INTEGER");
b.Property<uint>("CommanderId")
.HasColumnType("INTEGER");
b.Property<uint?>("CommonFlag")
.HasColumnType("INTEGER");
b.Property<string>("CoreLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<uint>("Energy")
.HasColumnType("INTEGER");
b.Property<string>("EquipInfoLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("Exp")
.HasColumnType("INTEGER");
b.Property<uint>("Intimacy")
.HasColumnType("INTEGER");
b.Property<bool>("IsLocked")
.HasColumnType("INTEGER");
b.Property<DateTime?>("LastChangeName")
.HasColumnType("TEXT");
b.Property<uint>("Level")
.HasColumnType("INTEGER");
b.Property<string>("MetaRepairLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<uint>("PlayerUid")
.HasColumnType("INTEGER");
b.Property<uint>("Proficiency")
.HasColumnType("INTEGER");
b.Property<uint>("Propose")
.HasColumnType("INTEGER");
b.Property<string>("SkillIdLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("SkinId")
.HasColumnType("INTEGER");
b.Property<string>("State")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("StrengthLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("TemplateId")
.HasColumnType("INTEGER");
b.Property<string>("TransformLists")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Id");
b.HasIndex("PlayerUid");
b.ToTable("Ships");
});
modelBuilder.Entity("BLHX.Server.Common.Database.ResourceField", b =>
{
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<uint>("PlayerUid")
.HasColumnType("INTEGER");
b.Property<DateTime>("LastHarvestTime")
.HasColumnType("TEXT");
b.Property<uint>("Level")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpgradeTime")
.HasColumnType("TEXT");
b.HasKey("Type", "PlayerUid");
b.HasIndex("PlayerUid");
b.ToTable("ResourceFields");
});
modelBuilder.Entity("BLHX.Server.Common.Database.ChapterInfo", b =>
{
b.HasOne("BLHX.Server.Common.Database.Player", "Player")
.WithMany("ChapterInfoes")
.HasForeignKey("PlayerUid")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("BLHX.Server.Common.Database.PlayerResource", b =>
{
b.HasOne("BLHX.Server.Common.Database.Player", "Player")
.WithMany("Resources")
.HasForeignKey("PlayerUid")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("BLHX.Server.Common.Database.PlayerShip", b =>
{
b.HasOne("BLHX.Server.Common.Database.Player", "Player")
.WithMany("Ships")
.HasForeignKey("PlayerUid")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("BLHX.Server.Common.Database.ResourceField", b =>
{
b.HasOne("BLHX.Server.Common.Database.Player", "Player")
.WithMany("ResourceFields")
.HasForeignKey("PlayerUid")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("BLHX.Server.Common.Database.Player", b =>
{
b.Navigation("ChapterInfoes");
b.Navigation("ResourceFields");
b.Navigation("Resources");
b.Navigation("Ships");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,76 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BLHX.Server.Common.Migrations.Player
{
/// <inheritdoc />
public partial class ChaptersDB : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<uint>(
name: "CurrentChapter",
table: "Players",
type: "INTEGER",
nullable: true);
migrationBuilder.CreateTable(
name: "ChapterInfoes",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false),
PlayerUid = table.Column<uint>(type: "INTEGER", nullable: false),
Time = table.Column<DateTime>(type: "TEXT", nullable: false),
CellLists = table.Column<string>(type: "jsonb", nullable: false),
GroupLists = table.Column<string>(type: "jsonb", nullable: false),
AiLists = table.Column<string>(type: "jsonb", nullable: false),
EscortLists = table.Column<string>(type: "jsonb", nullable: false),
Round = table.Column<uint>(type: "INTEGER", nullable: false),
IsSubmarineAutoAttack = table.Column<bool>(type: "INTEGER", nullable: false),
OperationBuffs = table.Column<string>(type: "jsonb", nullable: false),
ModelActCount = table.Column<uint>(type: "INTEGER", nullable: false),
BuffLists = table.Column<string>(type: "jsonb", nullable: false),
LoopFlag = table.Column<uint>(type: "INTEGER", nullable: false),
ExtraFlagLists = table.Column<string>(type: "jsonb", nullable: false),
CellFlagLists = table.Column<string>(type: "jsonb", nullable: false),
ChapterHp = table.Column<uint>(type: "INTEGER", nullable: false),
ChapterStrategyLists = table.Column<string>(type: "jsonb", nullable: false),
KillCount = table.Column<uint>(type: "INTEGER", nullable: false),
InitShipCount = table.Column<uint>(type: "INTEGER", nullable: false),
ContinuousKillCount = table.Column<uint>(type: "INTEGER", nullable: false),
BattleStatistics = table.Column<string>(type: "jsonb", nullable: false),
FleetDuties = table.Column<string>(type: "jsonb", nullable: false),
MoveStepCount = table.Column<uint>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChapterInfoes", x => new { x.Id, x.PlayerUid });
table.ForeignKey(
name: "FK_ChapterInfoes_Players_PlayerUid",
column: x => x.PlayerUid,
principalTable: "Players",
principalColumn: "Uid",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ChapterInfoes_PlayerUid",
table: "ChapterInfoes",
column: "PlayerUid");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChapterInfoes");
migrationBuilder.DropColumn(
name: "CurrentChapter",
table: "Players");
}
}
}

View File

@@ -21,6 +21,95 @@ namespace BLHX.Server.Common.Migrations.Player
.HasAnnotation("Proxies:CheckEquality", false)
.HasAnnotation("Proxies:LazyLoading", true);
modelBuilder.Entity("BLHX.Server.Common.Database.ChapterInfo", b =>
{
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<uint>("PlayerUid")
.HasColumnType("INTEGER");
b.Property<string>("AiLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("BattleStatistics")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("BuffLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("CellFlagLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("CellLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("ChapterHp")
.HasColumnType("INTEGER");
b.Property<string>("ChapterStrategyLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("ContinuousKillCount")
.HasColumnType("INTEGER");
b.Property<string>("EscortLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("ExtraFlagLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("FleetDuties")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("GroupLists")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("InitShipCount")
.HasColumnType("INTEGER");
b.Property<bool>("IsSubmarineAutoAttack")
.HasColumnType("INTEGER");
b.Property<uint>("KillCount")
.HasColumnType("INTEGER");
b.Property<uint>("LoopFlag")
.HasColumnType("INTEGER");
b.Property<uint>("ModelActCount")
.HasColumnType("INTEGER");
b.Property<uint>("MoveStepCount")
.HasColumnType("INTEGER");
b.Property<string>("OperationBuffs")
.IsRequired()
.HasColumnType("jsonb");
b.Property<uint>("Round")
.HasColumnType("INTEGER");
b.Property<DateTime>("Time")
.HasColumnType("TEXT");
b.HasKey("Id", "PlayerUid");
b.HasIndex("PlayerUid");
b.ToTable("ChapterInfoes");
});
modelBuilder.Entity("BLHX.Server.Common.Database.Player", b =>
{
b.Property<uint>("Uid")
@@ -36,6 +125,9 @@ namespace BLHX.Server.Common.Migrations.Player
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<uint?>("CurrentChapter")
.HasColumnType("INTEGER");
b.Property<string>("DisplayInfo")
.IsRequired()
.HasColumnType("jsonb");
@@ -208,6 +300,17 @@ namespace BLHX.Server.Common.Migrations.Player
b.ToTable("ResourceFields");
});
modelBuilder.Entity("BLHX.Server.Common.Database.ChapterInfo", b =>
{
b.HasOne("BLHX.Server.Common.Database.Player", "Player")
.WithMany("ChapterInfoes")
.HasForeignKey("PlayerUid")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("BLHX.Server.Common.Database.PlayerResource", b =>
{
b.HasOne("BLHX.Server.Common.Database.Player", "Player")
@@ -243,6 +346,8 @@ namespace BLHX.Server.Common.Migrations.Player
modelBuilder.Entity("BLHX.Server.Common.Database.Player", b =>
{
b.Navigation("ChapterInfoes");
b.Navigation("ResourceFields");
b.Navigation("Resources");