Explorar el Código

add migration and first step to play

USRINGENICO\fmorel hace 3 años
padre
commit
1b20956176

BIN
.vs/slnx.sqlite


+ 6 - 1
Dotnet/Warhammer/DataLayer/DeathwatchDbContext.cs

@@ -5,11 +5,16 @@ namespace Warhammer.DataLayer
 {
     public class DeathwatchDbContext : DbContext
     {
+        public DeathwatchDbContext() : base()
+        {
+
+        }
+
         public DeathwatchDbContext(DbContextOptions<DeathwatchDbContext> options) : base(options)
         {
         }
 
-        public virtual DbSet<Player> Players { get; set; }
+        public DbSet<Player> Players { get; set; }
 
         protected override void OnModelCreating(ModelBuilder modelBuilder)
         {

+ 84 - 0
Dotnet/Warhammer/Migrations/20220920105933_DeathwatchDbFirstMigration.Designer.cs

@@ -0,0 +1,84 @@
+// <auto-generated />
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Warhammer.DataLayer;
+
+namespace Warhammer.Migrations
+{
+    [DbContext(typeof(DeathwatchDbContext))]
+    [Migration("20220920105933_DeathwatchDbFirstMigration")]
+    partial class DeathwatchDbFirstMigration
+    {
+        protected override void BuildTargetModel(ModelBuilder modelBuilder)
+        {
+#pragma warning disable 612, 618
+            modelBuilder
+                .HasAnnotation("ProductVersion", "3.1.0")
+                .HasAnnotation("Relational:MaxIdentifierLength", 128)
+                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+            modelBuilder.Entity("Warhammer.Models.Player", b =>
+                {
+                    b.Property<string>("Name")
+                        .HasColumnType("nvarchar(450)");
+
+                    b.Property<int>("AG")
+                        .HasColumnType("int");
+
+                    b.Property<string>("Background")
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<int>("CC")
+                        .HasColumnType("int");
+
+                    b.Property<int>("CT")
+                        .HasColumnType("int");
+
+                    b.Property<string>("CharacterName")
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<DateTime>("CreatedDate")
+                        .HasColumnType("datetime2");
+
+                    b.Property<int>("E")
+                        .HasColumnType("int");
+
+                    b.Property<int>("Experience")
+                        .HasColumnType("int");
+
+                    b.Property<int>("F")
+                        .HasColumnType("int");
+
+                    b.Property<int>("FM")
+                        .HasColumnType("int");
+
+                    b.Property<int>("INT")
+                        .HasColumnType("int");
+
+                    b.Property<Guid>("Id")
+                        .HasColumnType("uniqueidentifier");
+
+                    b.Property<int>("MF")
+                        .HasColumnType("int");
+
+                    b.Property<DateTime>("ModifiedDate")
+                        .HasColumnType("datetime2");
+
+                    b.Property<int>("PER")
+                        .HasColumnType("int");
+
+                    b.Property<int>("SOC")
+                        .HasColumnType("int");
+
+                    b.HasKey("Name");
+
+                    b.ToTable("Players");
+                });
+#pragma warning restore 612, 618
+        }
+    }
+}

+ 44 - 0
Dotnet/Warhammer/Migrations/20220920105933_DeathwatchDbFirstMigration.cs

@@ -0,0 +1,44 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Warhammer.Migrations
+{
+    public partial class DeathwatchDbFirstMigration : Migration
+    {
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.CreateTable(
+                name: "Players",
+                columns: table => new
+                {
+                    Name = table.Column<string>(nullable: false),
+                    Id = table.Column<Guid>(nullable: false),
+                    CreatedDate = table.Column<DateTime>(nullable: false),
+                    ModifiedDate = table.Column<DateTime>(nullable: false),
+                    CharacterName = table.Column<string>(nullable: true),
+                    Background = table.Column<string>(nullable: true),
+                    Experience = table.Column<int>(nullable: false),
+                    CC = table.Column<int>(nullable: false),
+                    CT = table.Column<int>(nullable: false),
+                    F = table.Column<int>(nullable: false),
+                    E = table.Column<int>(nullable: false),
+                    AG = table.Column<int>(nullable: false),
+                    INT = table.Column<int>(nullable: false),
+                    PER = table.Column<int>(nullable: false),
+                    FM = table.Column<int>(nullable: false),
+                    SOC = table.Column<int>(nullable: false),
+                    MF = table.Column<int>(nullable: false)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_Players", x => x.Name);
+                });
+        }
+
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropTable(
+                name: "Players");
+        }
+    }
+}

+ 82 - 0
Dotnet/Warhammer/Migrations/DeathwatchDbContextModelSnapshot.cs

@@ -0,0 +1,82 @@
+// <auto-generated />
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Warhammer.DataLayer;
+
+namespace Warhammer.Migrations
+{
+    [DbContext(typeof(DeathwatchDbContext))]
+    partial class DeathwatchDbContextModelSnapshot : ModelSnapshot
+    {
+        protected override void BuildModel(ModelBuilder modelBuilder)
+        {
+#pragma warning disable 612, 618
+            modelBuilder
+                .HasAnnotation("ProductVersion", "3.1.0")
+                .HasAnnotation("Relational:MaxIdentifierLength", 128)
+                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+            modelBuilder.Entity("Warhammer.Models.Player", b =>
+                {
+                    b.Property<string>("Name")
+                        .HasColumnType("nvarchar(450)");
+
+                    b.Property<int>("AG")
+                        .HasColumnType("int");
+
+                    b.Property<string>("Background")
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<int>("CC")
+                        .HasColumnType("int");
+
+                    b.Property<int>("CT")
+                        .HasColumnType("int");
+
+                    b.Property<string>("CharacterName")
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<DateTime>("CreatedDate")
+                        .HasColumnType("datetime2");
+
+                    b.Property<int>("E")
+                        .HasColumnType("int");
+
+                    b.Property<int>("Experience")
+                        .HasColumnType("int");
+
+                    b.Property<int>("F")
+                        .HasColumnType("int");
+
+                    b.Property<int>("FM")
+                        .HasColumnType("int");
+
+                    b.Property<int>("INT")
+                        .HasColumnType("int");
+
+                    b.Property<Guid>("Id")
+                        .HasColumnType("uniqueidentifier");
+
+                    b.Property<int>("MF")
+                        .HasColumnType("int");
+
+                    b.Property<DateTime>("ModifiedDate")
+                        .HasColumnType("datetime2");
+
+                    b.Property<int>("PER")
+                        .HasColumnType("int");
+
+                    b.Property<int>("SOC")
+                        .HasColumnType("int");
+
+                    b.HasKey("Name");
+
+                    b.ToTable("Players");
+                });
+#pragma warning restore 612, 618
+        }
+    }
+}

+ 14 - 0
Dotnet/Warhammer/Models/BaseEntity.cs

@@ -0,0 +1,14 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace Domain.BackOffice
+{
+    public class BaseEntity
+    {
+        [Key]
+        public Guid Id { get; set; }
+        public DateTime CreatedDate { get; set; }
+        public DateTime ModifiedDate { get; set; }
+
+    }
+}

+ 27 - 4
Dotnet/Warhammer/Models/Player.cs

@@ -1,11 +1,17 @@
-using System.ComponentModel.DataAnnotations;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using Domain.BackOffice;
+using Warhammer.Models.Weapons;
+using Warhammer.Service;
 
 namespace Warhammer.Models
 {
-    public class Player
+    public class Player : BaseEntity
     {
-        [Key] public string Name { get; set; }
-
+        public string Name { get; set; }
+        public string CharacterName { get; set; }
+        public string Background { get; set; }
         public int Experience { get; set; }
         public int CC { get; set; }
         public int CT { get; set; }
@@ -17,5 +23,22 @@ namespace Warhammer.Models
         public int FM { get; set; }
         public int SOC { get; set; }
         public int MF { get; set; }
+
+        public int Initiative()
+        {
+            return DiceService.RollDices(1, 10) + DiceService.Bonus(AG);
+        }
+        public bool TestCC() { return DiceService.RollDices(100, 1) <= CC; }
+        public bool TestCT() { return DiceService.RollDices(100, 1) <= CT; }
+        public bool TestF() { return DiceService.RollDices(100, 1) <= F; }
+        public bool TestE() { return DiceService.RollDices(100, 1) <= E; }
+        public bool TestAG() { return DiceService.RollDices(100, 1) <= AG; }
+        public bool TestINT() { return DiceService.RollDices(100, 1) <= INT; }
+        public bool TestPER() { return DiceService.RollDices(100, 1) <= PER; }
+        public bool TestFM() { return DiceService.RollDices(100, 1) <= FM; }
+        public bool TestSOC() { return DiceService.RollDices(100, 1) <= SOC; }
+        public bool TestMF() { return DiceService.RollDices(100, 1) <= MF; }
+
+        public IList Weapons { get; set; }
     }
 }

+ 0 - 12
Dotnet/Warhammer/Models/Weapon.cs

@@ -1,12 +0,0 @@
-using System.ComponentModel.DataAnnotations;
-
-namespace Warhammer.Models
-{
-    public class Weapon
-    {
-        [Key] public int id { get; set; }
-
-        public int Range { get; set; }
-        public string Name { get; set; }
-    }
-}

+ 11 - 0
Dotnet/Warhammer/Models/Weapons/Bolter.cs

@@ -0,0 +1,11 @@
+namespace Warhammer.Models.Weapons
+{
+    public class Bolter : Weapon
+    {
+        public override int Shoot(string amo = null)
+        {
+
+            return 0;
+        }
+    }
+}

+ 10 - 0
Dotnet/Warhammer/Models/Weapons/FlameThrower.cs

@@ -0,0 +1,10 @@
+namespace Warhammer.Models.Weapons
+{
+    public class FlameThrower : Weapon
+    {
+        public override int Shoot(string amo = null)
+        {
+            return 0;
+        }
+    }
+}

+ 13 - 0
Dotnet/Warhammer/Models/Weapons/Weapon.cs

@@ -0,0 +1,13 @@
+using Domain.BackOffice;
+
+namespace Warhammer.Models.Weapons
+{
+    public abstract class Weapon : BaseEntity
+    {
+        public int Damage;
+        public int Range { get; set; }
+        public string Name { get; set; }
+
+        public abstract int Shoot(string amo = null);
+    }
+}

+ 0 - 1
Dotnet/Warhammer/Program.cs

@@ -11,7 +11,6 @@ namespace Warhammer
     {
         public static void Main(string[] args)
         {
-            CreateHostBuilder(args).Build().Run();
             var host = CreateHostBuilder(args).Build();
 
             CreateDbIfNotExists(host);

+ 89 - 0
Dotnet/Warhammer/Service/DiceService.cs

@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Warhammer.Models;
+
+namespace Warhammer.Service
+{
+    public static class DiceService
+    {
+        public static Random Random = new Random();
+
+        public static int Bonus(double statValue)
+        {
+            var bonus = statValue / 10;
+            return Convert.ToInt32(Math.Round(bonus, MidpointRounding.AwayFromZero));
+        }
+
+        public static int RollDices(int diceValue, int numberOfRoll)
+        {
+            var sum = 0;
+
+            for (int i = 0; i < numberOfRoll; i++)
+            {
+                sum += Random.Next(1, diceValue);
+            }
+
+            return sum;
+        }
+
+      
+        //public int flamethrower(bool hord = true)
+        //{
+        //    if (hord)
+        //    {
+        //        return np.ceil(this.weapons[0].range / 4) + RollDices(1, 5);
+        //    }
+        //}
+
+        //public virtual object bolter_damage(object success_degree)
+        //{
+        //    var throw = new List<object>();
+        //    foreach (var degree in Enumerable.Range(0, success_degree))
+        //    {
+        //        var current_throw = this.RollDices(3, 10);
+        //        throw.append(current_throw[np.argsort(current_throw)[-2]]);
+        //    }
+        //    Console.WriteLine(throw);
+        //    return np.sum(throw) + 5 * success_degree;
+        //}
+
+        //public virtual object bolter(object bonus_ct = 0)
+        //{
+        //    object success_degree;
+        //    var ct_dice = this.CT - this.RollDices(1, 100) + bonus_ct;
+        //    Console.WriteLine(String.Format("ct_dice_roll %i", ct_dice));
+        //    if (ct_dice > 0)
+        //    {
+        //        success_degree = 1 + Convert.ToInt32(math.floor(ct_dice / 10));
+        //        Console.WriteLine(success_degree);
+        //    }
+        //    else
+        //    {
+        //        success_degree = 0;
+        //    }
+        //    return this.bolter_damage(success_degree);
+        //}
+
+        //public virtual object sword_damage()
+        //{
+        //    return this.RollDices(1, 10) + 3 + this.MF;
+        //}
+
+       
+
+        //public virtual object fast_attack()
+        //{
+        //    var damage = 0;
+        //    foreach (var i in Enumerable.Range(0, 2))
+        //    {
+        //        if (this.test_cc())
+        //        {
+        //            damage += this.sword_damage();
+        //            Console.WriteLine(String.Format("Sword damage % i penetration 4", damage));
+        //        }
+        //    }
+        //    return damage;
+        //}
+    }
+}

+ 7 - 2
Dotnet/Warhammer/Warhammer.csproj

@@ -7,10 +7,15 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.23" />
+    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.0" />
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
-    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
+    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
   </ItemGroup>
 
 </Project>

+ 8 - 4
Dotnet/Warhammer/Warhammer.csproj.user

@@ -1,15 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
-    <View_SelectedScaffolderID>ApiControllerWithContextScaffolder</View_SelectedScaffolderID>
-    <View_SelectedScaffolderCategoryPath>root/Common/Api</View_SelectedScaffolderCategoryPath>
-    <WebStackScaffolding_ViewDialogWidth>650.4</WebStackScaffolding_ViewDialogWidth>
+    <View_SelectedScaffolderID>RazorViewScaffolder</View_SelectedScaffolderID>
+    <View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
+    <WebStackScaffolding_ViewDialogWidth>650</WebStackScaffolding_ViewDialogWidth>
     <WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
     <WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
     <WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
     <WebStackScaffolding_LayoutPageFile />
-    <Controller_SelectedScaffolderID>MvcControllerWithActionsScaffolder</Controller_SelectedScaffolderID>
+    <Controller_SelectedScaffolderID>MvcControllerWithContextScaffolder</Controller_SelectedScaffolderID>
     <Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
     <WebStackScaffolding_ControllerDialogWidth>650</WebStackScaffolding_ControllerDialogWidth>
+    <ActiveDebugProfile>IIS Express</ActiveDebugProfile>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
   </PropertyGroup>
 </Project>

+ 1 - 2
Dotnet/Warhammer/appsettings.json

@@ -1,7 +1,6 @@
 {
   "ConnectionStrings": {
-    "DefaultConnection":
-      "Server=(localdb)\\mssqllocaldb;Database=Warhammer;Trusted_Connection=True;MultipleActiveResultSets=true"
+    "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=Warhammer;Trusted_Connection=True;MultipleActiveResultSets=true",
   },
   "Logging": {
     "LogLevel": {