Implement BuCol
This commit is contained in:
parent
800dcf23ba
commit
efa5d452ea
@ -10,7 +10,7 @@ public class Planet
|
||||
public required string Name { get; set; }
|
||||
|
||||
[Index(1)]
|
||||
public string? Owner { get; set; }
|
||||
public string Owner { get; set; } = String.Empty;
|
||||
|
||||
[Index(2)]
|
||||
public string StarbaseType { get; set; } = String.Empty;
|
||||
@ -240,7 +240,7 @@ public class Planet
|
||||
if (dbPlanet.Name != Name)
|
||||
throw new InvalidOperationException($"DB Planet Name {dbPlanet.Name} does not macth the CSV Planet Name {Name}");
|
||||
|
||||
dbPlanet.OwnerId = Owner != "" ? Owner : null;
|
||||
dbPlanet.OwnerId = Owner;
|
||||
dbPlanet.StarbaseType = StarbaseType;
|
||||
dbPlanet.ReportAge = ReportAge;
|
||||
dbPlanet.Population = Population;
|
||||
|
@ -5,12 +5,12 @@ namespace StarsAssistant.Model;
|
||||
|
||||
public class Planet
|
||||
{
|
||||
#region Persistant and derived propeties
|
||||
#region Persistant propeties
|
||||
|
||||
[Key]
|
||||
public required string Name { get; set; }
|
||||
|
||||
public string? OwnerId { get; set; }
|
||||
public string OwnerId { get; set; } = String.Empty;
|
||||
|
||||
public string StarbaseType { get; set; } = String.Empty;
|
||||
|
||||
@ -70,7 +70,7 @@ public class Planet
|
||||
|
||||
public int? DriverWarp { get; set; }
|
||||
|
||||
public string? RouteTarget { get; set; }
|
||||
public string RouteTarget { get; set; } = String.Empty;
|
||||
|
||||
public int? GateRange { get; set; }
|
||||
|
||||
@ -86,22 +86,4 @@ public class Planet
|
||||
|
||||
#endregion
|
||||
|
||||
#region Derived Properties
|
||||
|
||||
// public int EffectiveValue() => EffectiveValue(Value);
|
||||
|
||||
// public int MaxPopOnPlanet() => MaxPopOnPlanet(Value);
|
||||
|
||||
// public int PopGrowth() => PopGrowth(Population ?? 0, MaxPopOnPlanet(), Value ?? 0);
|
||||
|
||||
// public int MaxFact() => MaxFact(Population ?? 0);
|
||||
|
||||
// public int MaxMines() => MaxMines(Population ?? 0);
|
||||
|
||||
// public int ResourcesFromPop() => ResourcesFromPop(Population ?? 0, Value ?? 0);
|
||||
|
||||
// public int ResourcesFromFact() => ResourcesFromFact(Population ?? 0, Factories ?? 0, Value ?? 0);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
@ -18,6 +18,15 @@ public class StarsDatabase(string DbPath) : DbContext
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||
=> options.UseSqlite($"Data Source={DbPath}");
|
||||
|
||||
/// <summary>
|
||||
/// Configure the model, force it to use property accessors we define.
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder">model builder</param>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.UsePropertyAccessMode(PropertyAccessMode.Property);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IStarsDatabase Implementation
|
||||
|
@ -40,25 +40,25 @@ public class GameEngine
|
||||
public static int PlanetPopGrowthForPlayer(int currentPop, int value)
|
||||
{
|
||||
int maxPop = MaxPopOnPlanetForPlayer(value);
|
||||
int growth;
|
||||
double growth;
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
growth = currentPop * value / 10;
|
||||
growth = currentPop * value / 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
double popRatio = currentPop / maxPop;
|
||||
double popRatio = (double) currentPop / maxPop;
|
||||
if (popRatio <= 0.25)
|
||||
growth = currentPop * value * Game.Player.GrowthRatePercent / 100;
|
||||
growth = currentPop * value / 100.0 * Game.Player.GrowthRatePercent / 100.0;
|
||||
else if (popRatio <= 1)
|
||||
growth = currentPop * value * Game.Player.GrowthRatePercent /100 * 16 / 9 * ((int) Math.Pow(1 - popRatio, 2));
|
||||
growth = currentPop * value / 100.0 * Game.Player.GrowthRatePercent / 100.0 * 16.0 / 9.0 * Math.Pow(1.0 - popRatio, 2);
|
||||
else
|
||||
growth = (int) (currentPop * (popRatio - 1) * 0.04);
|
||||
growth = currentPop * (popRatio - 1) * 0.04;
|
||||
}
|
||||
|
||||
// round to nearest 100
|
||||
return growth / 100 * 100;
|
||||
return ((int) growth) / 100 * 100;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -21,5 +21,5 @@ public partial class BuColViewModel : ViewModelBase
|
||||
});
|
||||
}
|
||||
|
||||
public ObservableCollection<PlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
|
||||
public ObservableCollection<PlayerPlanetViewModel> Planets { get; } = PlanetViewModel.LoadAll();
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ namespace StarsAssistant.ViewModels;
|
||||
|
||||
public partial class PlanetViewModel : ViewModelBase
|
||||
{
|
||||
private readonly Planet Planet;
|
||||
|
||||
public PlanetViewModel(Planet planet)
|
||||
{
|
||||
Planet = planet;
|
||||
@ -22,7 +24,6 @@ public partial class PlanetViewModel : ViewModelBase
|
||||
});
|
||||
}
|
||||
|
||||
private readonly Planet Planet;
|
||||
|
||||
public string Name => Planet.Name;
|
||||
|
||||
@ -42,13 +43,14 @@ public partial class PlanetViewModel : ViewModelBase
|
||||
|
||||
// ### TESTING CODE ###
|
||||
|
||||
public static ObservableCollection<PlanetViewModel> LoadAll()
|
||||
public static ObservableCollection<PlayerPlanetViewModel> LoadAll()
|
||||
{
|
||||
using var db = Locator.Current.GetService<StarsDatabase>()!;
|
||||
var result = new ObservableCollection<PlanetViewModel>();
|
||||
var result = new ObservableCollection<PlayerPlanetViewModel>();
|
||||
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
|
||||
// foreach (Planet planet in db.Planet.Where(p => p.Name == "Saddam").ToList())
|
||||
{
|
||||
var vm = new PlanetViewModel(planet);
|
||||
var vm = new PlayerPlanetViewModel(planet);
|
||||
result.Add(vm);
|
||||
}
|
||||
return result;
|
||||
|
128
Stars Assistant/ViewModels/PlayerPlanetViewModel.cs
Normal file
128
Stars Assistant/ViewModels/PlayerPlanetViewModel.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Disposables;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReactiveUI;
|
||||
using StarsAssistant.Services;
|
||||
using Splat;
|
||||
|
||||
namespace StarsAssistant.ViewModels;
|
||||
|
||||
public partial class PlayerPlanetViewModel : ViewModelBase
|
||||
{
|
||||
private readonly Model.Planet Planet;
|
||||
|
||||
private Game Game;
|
||||
|
||||
public PlayerPlanetViewModel(Model.Planet planet)
|
||||
{
|
||||
Game = Locator.Current.GetService<Game>()!;
|
||||
|
||||
if (planet.OwnerId != Game.Player.Name)
|
||||
throw new InvalidOperationException("PlayerPlanet ViewModels can only be created for player planets.");
|
||||
|
||||
Planet = planet;
|
||||
|
||||
this.WhenActivated((CompositeDisposable disposables) =>
|
||||
{
|
||||
// /* handle activation */
|
||||
// Disposable
|
||||
// .Create(() => { /* handle deactivation */ })
|
||||
// .DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
||||
#region Database Properties
|
||||
|
||||
public string Name => Planet.Name;
|
||||
|
||||
public string Owner => Planet.OwnerId;
|
||||
|
||||
public string StarbaseType => Planet.StarbaseType;
|
||||
|
||||
public int Population => Planet.Population ?? 0;
|
||||
|
||||
public int Value => Planet.Value ?? 0;
|
||||
|
||||
public int Mines => Planet.Mines ?? 0;
|
||||
|
||||
public int Factories => Planet.Factories ?? 0;
|
||||
|
||||
public decimal DefPercent => Planet.DefPercent ?? 0;
|
||||
|
||||
public int SurfaceIronium => Planet.SurfaceIronium ?? 0;
|
||||
|
||||
public int SurfaceBoranium => Planet.SurfaceBoranium ?? 0;
|
||||
|
||||
public int SurfaceGermanium => Planet.SurfaceGermanium ?? 0;
|
||||
|
||||
public int MRIronium => Planet.MRIronium ?? 0;
|
||||
|
||||
public int MRBoranium => Planet.MRBoranium ?? 0;
|
||||
|
||||
public int MRGermanium => Planet.MRGermanium ?? 0;
|
||||
|
||||
public int MCIronium => Planet.MCIronium ?? 0;
|
||||
|
||||
public int MCBoranium => Planet.MCBoranium ?? 0;
|
||||
|
||||
public int MCGermanium => Planet.MCGermanium ?? 0;
|
||||
|
||||
public int Resources => Planet.Resources ?? 0;
|
||||
|
||||
public decimal Gravity => Planet.Gravity ?? 0;
|
||||
|
||||
public decimal Temperature => Planet.Temperature ?? 0;
|
||||
|
||||
public decimal Radiation => Planet.Radiation ?? 0;
|
||||
|
||||
public decimal GravityOrig => Planet.GravityOrig ?? 0;
|
||||
|
||||
public decimal TemperatureOrig => Planet.TemperatureOrig ?? 0;
|
||||
|
||||
public decimal RadiationOrig => Planet.RadiationOrig ?? 0;
|
||||
|
||||
public int MaxTerraforming => Planet.MaxTerraforming ?? 0;
|
||||
|
||||
public int CapacityPercent => Planet.CapacityPercent ?? 0;
|
||||
|
||||
public int ScanRange => Planet.ScanRange ?? 0;
|
||||
|
||||
public int PenScanRange => Planet.PenScanRange ?? 0;
|
||||
|
||||
public int Driver => Planet.Driver ?? 0;
|
||||
|
||||
public int DriverWarp => Planet.DriverWarp ?? 0;
|
||||
|
||||
public string RouteTarget => Planet.RouteTarget;
|
||||
|
||||
public int GateRange => Planet.GateRange ?? 0;
|
||||
|
||||
public int GateMass => Planet.GateMass ?? 0;
|
||||
|
||||
public int PctDamage => Planet.PctDamage ?? 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Derived Properties
|
||||
|
||||
public int EffectiveValue => GameEngine.EffectivePlanetValue(Value);
|
||||
|
||||
public int MaxPopulation => GameEngine.MaxPopOnPlanetForPlayer(Value);
|
||||
|
||||
public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
|
||||
|
||||
public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
|
||||
|
||||
public int BuildableMines => GameEngine.MaxBuildableMinesForPlayer(Value);
|
||||
|
||||
public int OperableFactories => GameEngine.MaxOperableFactoriesForPlayer(Population, Value);
|
||||
|
||||
public int OperableMines => GameEngine.MaxOperableMinesForPlayer(Population, Value);
|
||||
|
||||
public int ResourcesFromPopulation => GameEngine.ResourcesFromPopForPlayer(Population, Value);
|
||||
|
||||
public int ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
@ -16,7 +16,39 @@
|
||||
BorderThickness="1" BorderBrush="Gray">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Planet" Binding="{Binding Name}" />
|
||||
<!-- Class -->
|
||||
<!-- Info -->
|
||||
<DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
|
||||
<!-- Pop To Ship -->
|
||||
<DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
|
||||
<!-- Pop en route -->
|
||||
<!-- Pop Target % -->
|
||||
<DataGridTextColumn Header="Pop%" Binding="{Binding CapacityPercent}" />
|
||||
<!-- Terra Delta assumed -->
|
||||
<DataGridTextColumn Header="Value" Binding="{Binding Value}" />
|
||||
<!-- Effective Value including Terra Delta -->
|
||||
<DataGridTextColumn Header="Max Val" Binding="{Binding MaxTerraforming}" />
|
||||
<!-- Cargo Cap T1 -->
|
||||
<!-- Cargo Cap T0 -->
|
||||
<!-- Iro MRE including Shipping -->
|
||||
<!-- Iro Avl including MRE -->
|
||||
<!-- Iro Shipping including MRE -->
|
||||
<!-- Bor MRE including Shipping -->
|
||||
<!-- Bor Avl including MRE -->
|
||||
<!-- Bor Shipping including MRE -->
|
||||
<!-- Ger MRE including Shipping -->
|
||||
<!-- Ger Avl including MRE -->
|
||||
<!-- Bor Shipping including MRE -->
|
||||
<!-- Shipbuilding Columns -->
|
||||
<!-- Factories remaining to pop target -->
|
||||
<!-- Factories Germanium Delta for target -->
|
||||
<!-- Factory production per turn -->
|
||||
<!-- Mines remaining to pop target -->
|
||||
<DataGridTextColumn Header="Mines" Binding="{Binding Mines}" />
|
||||
<DataGridTextColumn Header="Fact" Binding="{Binding Factories}" />
|
||||
<DataGridTextColumn Header="Res" Binding="{Binding Resources}" />
|
||||
<!-- Overcrowding Rate -->
|
||||
<!-- Target population absolute -->
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user