2 Commits da42dc11c4 ... 804cd627d5

Author SHA1 Message Date
  USRINGENICO\fmorel 804cd627d5 calculate dmg for bolter 3 years ago
  USRINGENICO\fmorel 1b20956176 add migration and first step to play 3 years ago

+ 3 - 12
.vs/VSWorkspaceState.json

@@ -1,21 +1,12 @@
 {
   "ExpandedNodes": [
     "",
-<<<<<<< HEAD
     "\\Dotnet",
     "\\Dotnet\\Warhammer",
-    "\\Dotnet\\Warhammer\\DAL",
-    "\\Dotnet\\Warhammer\\DAL\\Database",
     "\\Dotnet\\Warhammer\\Models",
-    "\\Dotnet\\Warhammer\\Models\\Enum",
-    "\\Dotnet\\Warhammer\\Views",
-    "\\Dotnet\\Warhammer\\Views\\Shared"
+    "\\Dotnet\\Warhammer\\Models\\Weapons",
+    "\\Dotnet\\Warhammer\\Service"
   ],
-  "SelectedNode": "\\Dotnet\\Warhammer\\Models\\Player.cs",
-=======
-    "\\Dotnet"
-  ],
-  "SelectedNode": "\\Dotnet\\Warhammer.sln",
->>>>>>> e358957dfb4f64810dea7162fe38a5820cb59cb1
+  "SelectedNode": "\\Dotnet\\Warhammer\\Models\\Weapons\\FlameThrower.cs",
   "PreviewInSolutionExplorer": false
 }

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; }
+
+    }
+}

+ 28 - 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,23 @@ 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(1, 100) <= CC; }
+        public bool TestCT() { return DiceService.RollDices(1, 100) <= CT; }
+        public bool TestF() { return DiceService.RollDices(1, 100) <= F; }
+        public bool TestE() { return DiceService.RollDices(1, 100) <= E; }
+        public bool TestAG() { return DiceService.RollDices(1, 100) <= AG; }
+        public bool TestINT() { return DiceService.RollDices(1, 100) <= INT; }
+        public bool TestPER() { return DiceService.RollDices(1, 100) <= PER; }
+        public bool TestFM() { return DiceService.RollDices(1, 100) <= FM; }
+        public bool TestSOC() { return DiceService.RollDices(1, 100) <= SOC; }
+        public bool TestMF() { return DiceService.RollDices(1, 100) <= MF; }
+
+        public IList Weapons { get; set; }
     }
 }

+ 17 - 0
Dotnet/Warhammer/Models/Utilities.cs

@@ -0,0 +1,17 @@
+using System;
+
+namespace Warhammer.Models
+{
+    public static class Utilities
+    {
+        public static int Round(int value, int dividedBy)
+        {
+            if (value < 0)
+            {
+                return (int)Math.Floor(value / (double)dividedBy);
+            }
+
+            return 0;
+        }
+    }
+}

+ 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; }
-    }
-}

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

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Warhammer.Service;
+
+namespace Warhammer.Models.Weapons
+{
+    public class Bolter : Weapon
+    {
+        public override int DamageAmount(int successDegree)
+        {
+            var throws = new List<int>();
+            for (int i = 0; i < successDegree; i++)
+            {
+                var currentThrow = DiceService.RollDices(3, 10);
+                throws.Add(currentThrow);
+            }
+            return throws.Sum() + 5 * successDegree;
+        }
+
+        public override int Shoot(int bonusCt, int ct, string amo = null, bool? isHorde = null)
+        {
+            int successDegree;
+            var ctDice = ct - DiceService.RollDices(1, 100) + bonusCt;
+            if (ctDice > 0)
+            {
+                successDegree = 1 + Utilities.Round(ctDice, 10);
+            }
+            else
+            {
+                successDegree = 0;
+            }
+            return DamageAmount(successDegree);
+        }
+    }
+}

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

@@ -0,0 +1,28 @@
+using System;
+using Warhammer.Service;
+
+namespace Warhammer.Models.Weapons
+{
+    public class FlameThrower : Weapon
+    {
+        public FlameThrower()
+        {
+            Range = 30;
+        }
+
+        public override int DamageAmount(int successDegree)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override int Shoot(int bonusCt, int ct, string amo = null, bool? isHorde = null)
+        {
+            if (isHorde == true)
+            {
+                return DiceService.RollDices(1,5) + Utilities.Round(Range, 4);
+            }
+            return 0;
+        }
+
+    }
+}

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

@@ -0,0 +1,23 @@
+using Domain.BackOffice;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
+
+namespace Warhammer.Models.Weapons
+{
+    public abstract class Weapon : BaseEntity
+    {
+        public int Damage;
+        public int Range { get; set; }
+        public string Name { get; set; }
+        public string GPE { get; set; }
+        public string Type { get; set; }
+        public int Pene { get; set; }
+        public string Mode { get; set; }
+        public string At { get; set; }
+        public string Rch { get; set; }
+        public string Attribute { get; set; }
+
+        public abstract int Shoot(int bonusCt, int ct, string amo = null, bool? isHorde = null);
+        public abstract int DamageAmount(int successDegree);
+
+    }
+}

+ 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);

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

@@ -0,0 +1,88 @@
+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(int statValue)
+        {
+            return Utilities.Round(statValue, 10);
+        }
+
+        public static int RollDices(int numberOfRoll, int diceValue)
+        {
+            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": {