Fix Kingdom and Alliance model compilation errors

- Add IKingdomScoped interface for repository pattern security
- Update Kingdom model to implement IKingdomScoped with missing properties:
  - LastActivity, TotalTaxCollected, IsInKvK, KvKHostAllianceId, CurrentPowerRank
- Add MemberCount property to Alliance model for repository compatibility
- Maintain existing business logic and computed properties
- Resolve Repository<T, K> generic constraint requirements

These changes should resolve CS0311 and CS1061 compilation errors in KingdomRepository.
This commit is contained in:
matt 2025-10-19 21:54:24 -05:00
parent 4ff428898e
commit 337a029308
7 changed files with 2250 additions and 2449 deletions

View File

@ -3,7 +3,7 @@
* Created: 2025-10-19
* Last Modified: 2025-10-19
* Description: Core Alliance entity representing player organizations with territory, research, and coalition systems. Handles alliance hierarchy, progression, and KvK participation while preserving alliance independence.
* Last Edit Notes: Added IKingdomScoped interface implementation to resolve Repository compatibility
* Last Edit Notes: Added MemberCount property to resolve Repository compatibility
*/
using ShadowedRealms.Core.Interfaces;
@ -194,6 +194,10 @@ namespace ShadowedRealms.Core.Models.Alliance
public virtual ICollection<AllianceInvitation> PendingInvitations { get; set; } = new List<AllianceInvitation>();
// ADDED: Missing property that repository expects
// This should be kept in sync with ActiveMemberCount
public int MemberCount => ActiveMemberCount;
// Computed Properties
public int ActiveMemberCount => Members?.Count(m => m.IsActive) ?? 0;

View File

@ -3,9 +3,10 @@
* Created: 2025-10-19
* Last Modified: 2025-10-19
* Description: Combat logging system for tracking all battle activities including field interception, castle sieges, and KvK events. Provides comprehensive audit trail for combat resolution and analytics.
* Last Edit Notes: Initial creation with field interception support, troop casualties, resource transfers, and dragon skill integration
* Last Edit Notes: Added IKingdomScoped interface implementation to fix repository compatibility
*/
using ShadowedRealms.Core.Interfaces;
using ShadowedRealms.Core.Models.Kingdom;
using ShadowedRealms.Core.Models.Player;
using ShadowedRealms.Core.Models.Alliance;
@ -14,7 +15,7 @@ using System.Text.Json;
namespace ShadowedRealms.Core.Models.Combat
{
public class CombatLog
public class CombatLog : IKingdomScoped
{
public int Id { get; set; }

View File

@ -3,17 +3,17 @@
* Created: 2025-10-19
* Last Modified: 2025-10-19
* Description: Core Kingdom entity representing a game server/realm. Handles kingdom-level statistics, population management, and serves as the root entity for all kingdom-scoped data.
* Last Edit Notes: Initial creation with population management, merger system support, and KvK participation tracking
* Last Edit Notes: Added missing properties for repository compatibility and IKingdomScoped interface implementation
*/
using ShadowedRealms.Core.Interfaces;
using ShadowedRealms.Core.Models.Alliance;
using ShadowedRealms.Core.Models.Player;
using System.ComponentModel.DataAnnotations;
using System.Numerics;
namespace ShadowedRealms.Core.Models.Kingdom
{
public class Kingdom
public class Kingdom : IKingdomScoped
{
public int Id { get; set; }
@ -78,6 +78,24 @@ namespace ShadowedRealms.Core.Models.Kingdom
[Range(0.0, 0.1)]
public decimal TaxRate { get; set; } = 0.04m; // 4% default
// ADDED: Missing properties that repository expects
public DateTime LastActivity { get; set; } = DateTime.UtcNow;
public decimal TotalTaxCollected { get; set; } = 0m;
public bool IsInKvK { get; set; } = false;
public int? KvKHostAllianceId { get; set; }
public int CurrentPowerRank { get; set; } = 0;
// IKingdomScoped implementation - Kingdom is a root entity, so KingdomId is its own Id
public int KingdomId
{
get => Id;
set => Id = value;
}
// Navigation properties
public virtual ICollection<Player.Player> Players { get; set; } = new List<Player.Player>();
@ -155,6 +173,7 @@ namespace ShadowedRealms.Core.Models.Kingdom
{
CurrentPopulation = Players?.Count(p => p.IsActive) ?? 0;
TotalPower = Players?.Where(p => p.IsActive).Sum(p => p.Power) ?? 0;
LastActivity = DateTime.UtcNow; // Update last activity when population changes
// Update merger eligibility based on population health
var healthStatus = GetHealthStatus();
@ -189,6 +208,7 @@ namespace ShadowedRealms.Core.Models.Kingdom
}
LastKvKDate = DateTime.UtcNow;
LastActivity = DateTime.UtcNow; // Update last activity
// Update KvK eligibility based on recent performance and kingdom health
var healthStatus = GetHealthStatus();

View File

@ -18,4 +18,8 @@
<Folder Include="Services\Player\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.21" />
</ItemGroup>
</Project>

View File

@ -3,7 +3,7 @@
* Created: 2025-10-19
* Last Modified: 2025-10-19
* Description: Main Entity Framework database context for Shadowed Realms. Handles all game entities with kingdom-based data partitioning and server-authoritative design.
* Last Edit Notes: Initial creation with basic Player, Alliance, Kingdom entities and kingdom-scoped query filters
* Last Edit Notes: Fixed missing using statements for Identity and Combat/Purchase models
*/
using Microsoft.AspNetCore.Identity;
@ -13,8 +13,9 @@ using Microsoft.Extensions.Logging;
using ShadowedRealms.Core.Models.Alliance;
using ShadowedRealms.Core.Models.Kingdom;
using ShadowedRealms.Core.Models.Player;
using ShadowedRealms.Core.Models.Combat;
using ShadowedRealms.Core.Models.Purchase;
using System.Linq.Expressions;
using System.Numerics;
namespace ShadowedRealms.Data.Contexts
{