diff --git a/.idea/.idea.IsleBot/.idea/dataSources.xml b/.idea/.idea.IsleBot/.idea/dataSources.xml new file mode 100644 index 0000000..c86e388 --- /dev/null +++ b/.idea/.idea.IsleBot/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/database.db + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/.idea.IsleBot/.idea/efCoreCommonOptions.xml b/.idea/.idea.IsleBot/.idea/efCoreCommonOptions.xml new file mode 100644 index 0000000..5db860c --- /dev/null +++ b/.idea/.idea.IsleBot/.idea/efCoreCommonOptions.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.IsleBot/.idea/efCoreDialogsState.xml b/.idea/.idea.IsleBot/.idea/efCoreDialogsState.xml new file mode 100644 index 0000000..834a8f6 --- /dev/null +++ b/.idea/.idea.IsleBot/.idea/efCoreDialogsState.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.IsleBotSharp/.idea/workspace.xml b/.idea/.idea.IsleBotSharp/.idea/workspace.xml deleted file mode 100644 index 000c6a3..0000000 --- a/.idea/.idea.IsleBotSharp/.idea/workspace.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - IsleBotSharp.csproj - - - - - - - - - - - - - - - - - - - - { - "associatedIndex": 8 -} - - - - - - - - - - - - - 1699202233917 - - - - - - - - - - - \ No newline at end of file diff --git a/Card.cs b/Card.cs index ed17aba..be4f28a 100644 --- a/Card.cs +++ b/Card.cs @@ -1,12 +1,17 @@ -namespace IsleBot; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; -public class Card -{ +namespace IsleBot; + +public class Card { + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } public string Name { get; set; } public int Attack { get; set; } public int Defense { get; set; } public int MaxHealth { get; set; } public int CurrentHealth { get; set; } + public User Owner { get; set; } public override string ToString() { return $"{Name} ATK: {Attack} DEF: {Defense} HP: {CurrentHealth}/{MaxHealth}"; diff --git a/DbManager.cs b/DbManager.cs index 0c51001..a3a688d 100644 --- a/DbManager.cs +++ b/DbManager.cs @@ -18,4 +18,5 @@ public class DbManager : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlite($"Data Source={dbpath}"); + } \ No newline at end of file diff --git a/IsleBot.csproj b/IsleBot.csproj index e07710d..3104a12 100644 --- a/IsleBot.csproj +++ b/IsleBot.csproj @@ -10,6 +10,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -17,6 +21,9 @@ PreserveNewest + + PreserveNewest + diff --git a/Match.cs b/Match.cs index 59ee0c2..ce9bebc 100644 --- a/Match.cs +++ b/Match.cs @@ -1,17 +1,38 @@ -using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace IsleBot; public class Match { - public int MatchId { get; set; } - + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [DataMember(IsRequired = true)] + public int Id { get; set; } + [ForeignKey("PlayerAId"), Column(Order = 1)] public User PlayerA { get; set; } + [ForeignKey("PlayerACardId"), Column(Order = 2)] public Card PlayerACard { get; set; } + [ForeignKey("PlayerBId"), Column(Order=3)] public User PlayerB { get; set; } + [ForeignKey("PlayerBCardId"), Column(Order=4)] public Card PlayerBCard { get; set; } public int PlayedTurns { get; set; } - + public EStatus Status { get; set; } + + public Match() { } //required for EFCore build + + public Match(User playerA, User playerB, Card playerACard, Card playerBCard) { + PlayerA = playerA; + PlayerB = playerB; + PlayerACard = playerACard; + PlayerBCard = playerBCard; + PlayedTurns = 0; + Status = EStatus.NotStarted; + } } \ No newline at end of file diff --git a/Migrations/20231107003428_Initial.Designer.cs b/Migrations/20231107003428_Initial.Designer.cs new file mode 100644 index 0000000..b3341e3 --- /dev/null +++ b/Migrations/20231107003428_Initial.Designer.cs @@ -0,0 +1,159 @@ +// +using IsleBot; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace IsleBot.Migrations +{ + [DbContext(typeof(DbManager))] + [Migration("20231107003428_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.13"); + + modelBuilder.Entity("IsleBot.Card", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Attack") + .HasColumnType("INTEGER"); + + b.Property("CurrentHealth") + .HasColumnType("INTEGER"); + + b.Property("Defense") + .HasColumnType("INTEGER"); + + b.Property("MaxHealth") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("OwnerId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Cards"); + }); + + modelBuilder.Entity("IsleBot.Match", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("PlayedTurns") + .HasColumnType("INTEGER"); + + b.Property("PlayerACardId") + .HasColumnType("INTEGER"); + + b.Property("PlayerAId") + .HasColumnType("INTEGER"); + + b.Property("PlayerBCardId") + .HasColumnType("INTEGER"); + + b.Property("PlayerBId") + .HasColumnType("INTEGER"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("PlayerACardId"); + + b.HasIndex("PlayerAId"); + + b.HasIndex("PlayerBCardId"); + + b.HasIndex("PlayerBId"); + + b.ToTable("Matches"); + }); + + modelBuilder.Entity("IsleBot.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("IsleBot.Card", b => + { + b.HasOne("IsleBot.User", "Owner") + .WithMany("Cards") + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("IsleBot.Match", b => + { + b.HasOne("IsleBot.Card", "PlayerACard") + .WithMany() + .HasForeignKey("PlayerACardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IsleBot.User", "PlayerA") + .WithMany() + .HasForeignKey("PlayerAId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IsleBot.Card", "PlayerBCard") + .WithMany() + .HasForeignKey("PlayerBCardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IsleBot.User", "PlayerB") + .WithMany() + .HasForeignKey("PlayerBId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlayerA"); + + b.Navigation("PlayerACard"); + + b.Navigation("PlayerB"); + + b.Navigation("PlayerBCard"); + }); + + modelBuilder.Entity("IsleBot.User", b => + { + b.Navigation("Cards"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20231107003428_Initial.cs b/Migrations/20231107003428_Initial.cs new file mode 100644 index 0000000..a5e1047 --- /dev/null +++ b/Migrations/20231107003428_Initial.cs @@ -0,0 +1,131 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IsleBot.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Players", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserName = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Players", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Cards", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Attack = table.Column(type: "INTEGER", nullable: false), + Defense = table.Column(type: "INTEGER", nullable: false), + MaxHealth = table.Column(type: "INTEGER", nullable: false), + CurrentHealth = table.Column(type: "INTEGER", nullable: false), + OwnerId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cards", x => x.Id); + table.ForeignKey( + name: "FK_Cards_Players_OwnerId", + column: x => x.OwnerId, + principalTable: "Players", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Matches", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + PlayerAId = table.Column(type: "INTEGER", nullable: false), + PlayerACardId = table.Column(type: "INTEGER", nullable: false), + PlayerBId = table.Column(type: "INTEGER", nullable: false), + PlayerBCardId = table.Column(type: "INTEGER", nullable: false), + PlayedTurns = table.Column(type: "INTEGER", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Matches", x => x.Id); + table.ForeignKey( + name: "FK_Matches_Cards_PlayerACardId", + column: x => x.PlayerACardId, + principalTable: "Cards", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Matches_Cards_PlayerBCardId", + column: x => x.PlayerBCardId, + principalTable: "Cards", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Matches_Players_PlayerAId", + column: x => x.PlayerAId, + principalTable: "Players", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Matches_Players_PlayerBId", + column: x => x.PlayerBId, + principalTable: "Players", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Cards_OwnerId", + table: "Cards", + column: "OwnerId"); + + migrationBuilder.CreateIndex( + name: "IX_Matches_PlayerACardId", + table: "Matches", + column: "PlayerACardId"); + + migrationBuilder.CreateIndex( + name: "IX_Matches_PlayerAId", + table: "Matches", + column: "PlayerAId"); + + migrationBuilder.CreateIndex( + name: "IX_Matches_PlayerBCardId", + table: "Matches", + column: "PlayerBCardId"); + + migrationBuilder.CreateIndex( + name: "IX_Matches_PlayerBId", + table: "Matches", + column: "PlayerBId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Matches"); + + migrationBuilder.DropTable( + name: "Cards"); + + migrationBuilder.DropTable( + name: "Players"); + } + } +} diff --git a/Migrations/DbManagerModelSnapshot.cs b/Migrations/DbManagerModelSnapshot.cs new file mode 100644 index 0000000..480a3f1 --- /dev/null +++ b/Migrations/DbManagerModelSnapshot.cs @@ -0,0 +1,156 @@ +// +using IsleBot; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace IsleBot.Migrations +{ + [DbContext(typeof(DbManager))] + partial class DbManagerModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.13"); + + modelBuilder.Entity("IsleBot.Card", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Attack") + .HasColumnType("INTEGER"); + + b.Property("CurrentHealth") + .HasColumnType("INTEGER"); + + b.Property("Defense") + .HasColumnType("INTEGER"); + + b.Property("MaxHealth") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("OwnerId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Cards"); + }); + + modelBuilder.Entity("IsleBot.Match", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("PlayedTurns") + .HasColumnType("INTEGER"); + + b.Property("PlayerACardId") + .HasColumnType("INTEGER"); + + b.Property("PlayerAId") + .HasColumnType("INTEGER"); + + b.Property("PlayerBCardId") + .HasColumnType("INTEGER"); + + b.Property("PlayerBId") + .HasColumnType("INTEGER"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("PlayerACardId"); + + b.HasIndex("PlayerAId"); + + b.HasIndex("PlayerBCardId"); + + b.HasIndex("PlayerBId"); + + b.ToTable("Matches"); + }); + + modelBuilder.Entity("IsleBot.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Players"); + }); + + modelBuilder.Entity("IsleBot.Card", b => + { + b.HasOne("IsleBot.User", "Owner") + .WithMany("Cards") + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("IsleBot.Match", b => + { + b.HasOne("IsleBot.Card", "PlayerACard") + .WithMany() + .HasForeignKey("PlayerACardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IsleBot.User", "PlayerA") + .WithMany() + .HasForeignKey("PlayerAId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IsleBot.Card", "PlayerBCard") + .WithMany() + .HasForeignKey("PlayerBCardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IsleBot.User", "PlayerB") + .WithMany() + .HasForeignKey("PlayerBId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlayerA"); + + b.Navigation("PlayerACard"); + + b.Navigation("PlayerB"); + + b.Navigation("PlayerBCard"); + }); + + modelBuilder.Entity("IsleBot.User", b => + { + b.Navigation("Cards"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/User.cs b/User.cs index 50cf86b..8a04590 100644 --- a/User.cs +++ b/User.cs @@ -1,10 +1,15 @@ -namespace IsleBot; +using System.Runtime.Serialization; -public class User -{ +namespace IsleBot; + +public class User { + [DataMember(IsRequired = true)] public int Id { get; private set; } public string UserName { get; set; } + public List Cards { get; set; } + + //public List Matches { get; set; } public User(int id, string userName) { Id = id; diff --git a/database.db b/database.db new file mode 100644 index 0000000..752c868 Binary files /dev/null and b/database.db differ