Files
systemrevivalserver/Game/GameContracts.cs
T
2025-11-29 15:44:45 -05:00

234 lines
4.8 KiB
C#

using System.Text.Json.Serialization;
namespace VoidScavengers.Networking.Messages;
// ===== Lobby Contracts =====
public sealed record LobbyJoinRequest(string PlayerName);
public sealed record LobbyJoinResult(bool Ok, string? Error, string? LobbyId, int PlayerCount);
public sealed record LobbyState(string LobbyId, LobbyPlayer[] Players, int CountdownSeconds);
public sealed record LobbyPlayer(ulong PlayerId, string Name, bool Ready);
public sealed record LobbyReadyRequest(bool Ready);
public sealed record LobbyCountdown(int SecondsRemaining);
// ===== Game Start =====
public sealed record GameStartInfo(
string MatchId,
int MapSeed,
float MapWidth,
float MapHeight,
PlayerSpawnInfo Self,
PlayerSpawnInfo[] OtherPlayers,
AsteroidInfo[] Asteroids,
ResourceNodeInfo[] Resources,
ExtractionZoneInfo[] ExtractionZones
);
public sealed record PlayerSpawnInfo(
ulong PlayerId,
string Name,
float X,
float Y,
float Rotation,
int Health,
int MaxHealth
);
public sealed record AsteroidInfo(
int Id,
float X,
float Y,
float Radius,
int AsteroidType // 0=small, 1=medium, 2=large
);
public sealed record ResourceNodeInfo(
int Id,
float X,
float Y,
int ResourceType, // 0=scrap, 1=energy, 2=rare
int Amount
);
public sealed record ExtractionZoneInfo(
int Id,
float X,
float Y,
float Radius,
bool Active,
int ActivatesAtTick
);
// ===== Game State Snapshots =====
public sealed record GameStateSnapshot(
long Tick,
float TimeRemaining,
int PlayersAlive,
EntityState[] Entities,
ProjectileState[] Projectiles,
ResourceState[] Resources
);
public sealed record EntityState(
ulong Id,
int Type, // 0=player, 1=dropped_item
float X,
float Y,
float Rotation,
float VelX,
float VelY,
int Health,
int? ItemId // For dropped items
);
public sealed record ProjectileState(
int Id,
float X,
float Y,
float VelX,
float VelY,
ulong OwnerId,
int ProjectileType
);
public sealed record ResourceState(
int Id,
int Amount
);
// ===== Player Input =====
public sealed record MoveInput(
float Dx, // -1 to 1 normalized
float Dy, // -1 to 1 normalized
float AimAngle, // Radians, where player is aiming
uint Seq // Client sequence number for reconciliation
);
public sealed record ActionInput(
int ActionType, // 0=interact, 1=pickup, 2=use_ability
int? TargetId
);
public sealed record ShootInput(
float AimAngle,
uint Seq
);
public sealed record DropInput(
int InventorySlot
);
public sealed record CraftRequest(
int RecipeId
);
// ===== Events =====
public sealed record SpawnEvent(
ulong EntityId,
int EntityType,
float X,
float Y,
object? Data // Type-specific spawn data
);
public sealed record DespawnEvent(ulong EntityId);
public sealed record DamageEvent(
ulong TargetId,
ulong? SourceId,
int Amount,
int NewHealth,
int DamageType // 0=projectile, 1=collision, 2=zone
);
public sealed record DeathEvent(
ulong PlayerId,
ulong? KillerId,
string PlayerName,
string? KillerName,
DroppedItemInfo[] DroppedItems
);
public sealed record DroppedItemInfo(
int DropId,
float X,
float Y,
int ItemId,
int Quantity
);
public sealed record PickupEvent(
ulong PlayerId,
int DropId,
int ItemId,
int Quantity
);
public sealed record ProjectileEvent(
int ProjectileId,
ulong OwnerId,
float X,
float Y,
float VelX,
float VelY,
int ProjectileType
);
public sealed record ExplosionEvent(
float X,
float Y,
float Radius,
int ExplosionType
);
public sealed record CraftCompleteEvent(
ulong PlayerId,
int RecipeId,
int ResultItemId,
int Quantity
);
public sealed record ExtractEvent(
ulong PlayerId,
string PlayerName,
int TotalLootValue
);
// ===== Game End =====
public sealed record GameEndInfo(
string MatchId,
string Reason, // "last_standing", "time_expired", "all_extracted"
ulong? WinnerId,
string? WinnerName,
PlayerStatsInfo[] PlayerStats
);
public sealed record PlayerStatsInfo(
ulong PlayerId,
string Name,
int Kills,
int Deaths,
int DamageDealt,
int ResourcesCollected,
int ItemsCrafted,
bool Extracted,
int FinalPlacement
);
// ===== Inventory State (sent periodically or on change) =====
public sealed record InventoryUpdate(
InventorySlot[] Slots,
int ScrapCount,
int EnergyCount,
int RareCount
);
public sealed record InventorySlot(
int SlotIndex,
int? ItemId,
int Quantity
);
// ===== Chat =====
public sealed record ChatMessage(string Text);
public sealed record ChatReceived(ulong SenderId, string SenderName, string Text, long Timestamp);