improvfmeents
This commit is contained in:
@@ -770,6 +770,121 @@ public class GameEngine
|
||||
|
||||
private void EmitEvent(GameEvent e)
|
||||
{
|
||||
RecordStatsAndLog(e);
|
||||
OnGameEvent?.Invoke(e);
|
||||
}
|
||||
|
||||
private void RecordStatsAndLog(GameEvent e)
|
||||
{
|
||||
State.Stats.TotalTurns = State.TurnCount;
|
||||
switch (e.Type)
|
||||
{
|
||||
case GameEventType.GameStarted:
|
||||
AddLogItem(new GameLogItem("🎮", "Hra sa začala!", null, DateTime.UtcNow));
|
||||
break;
|
||||
case GameEventType.CardPlayed:
|
||||
if (e.SourcePlayer != null)
|
||||
{
|
||||
State.Stats.RecordCardPlayed(e.SourcePlayer, e.Cards?.Count ?? 1);
|
||||
if (e.Card?.Rank == Rank.Ace || (e.Cards != null && e.Cards.Any(c => c.Rank == Rank.Ace)))
|
||||
{
|
||||
State.Stats.TotalAcesPlayed++;
|
||||
}
|
||||
if (e.Card?.Rank == Rank.Seven || (e.Cards != null && e.Cards.Any(c => c.Rank == Rank.Seven)))
|
||||
{
|
||||
State.Stats.TotalSevensPlayed++;
|
||||
}
|
||||
|
||||
string cardDesc = e.Cards != null && e.Cards.Count > 1
|
||||
? $"{e.Cards.Count}x {e.Cards[0].RankName}"
|
||||
: (e.Card != null ? $"{e.Card.RankName} {e.Card.SuitSymbol}" : "karta");
|
||||
|
||||
AddLogItem(new GameLogItem("🎴", $"{e.SourcePlayer.Name} zahral {cardDesc}", null, DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar));
|
||||
}
|
||||
break;
|
||||
case GameEventType.CardDrawn:
|
||||
if (e.SourcePlayer != null)
|
||||
{
|
||||
int count = e.ExtraData > 0 ? e.ExtraData : 1;
|
||||
State.Stats.RecordCardDrawn(e.SourcePlayer, count);
|
||||
string countText = count > 1 ? $"{count} kariet" : "z balíčka";
|
||||
string? sub = count > 1 ? "Trest za sedmy" : null;
|
||||
string? accent = count > 1 ? "#f59e0b" : null;
|
||||
AddLogItem(new GameLogItem("📥", $"{e.SourcePlayer.Name} potiahol {countText}", sub, DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar, accent));
|
||||
}
|
||||
break;
|
||||
case GameEventType.SevenStacked:
|
||||
if (e.TargetPlayer != null)
|
||||
{
|
||||
State.Stats.RecordCardDrawn(e.TargetPlayer, e.ExtraData);
|
||||
AddLogItem(new GameLogItem("🎒", $"{e.TargetPlayer.Name} musel potiahnuť +{e.ExtraData} kariet!", "Trest zo sediem", DateTime.UtcNow, e.TargetPlayer.Name, e.TargetPlayer.Avatar, "#f59e0b"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.SevenCanceled:
|
||||
if (e.SourcePlayer != null)
|
||||
{
|
||||
AddLogItem(new GameLogItem("🛡️", $"{e.SourcePlayer.Name} zrušil sedmy Zeleným dolníkom!", "Štít úspešný", DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar, "#10b981"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.AceSkipped:
|
||||
if (e.SourcePlayer != null)
|
||||
{
|
||||
AddLogItem(new GameLogItem("❄️", $"{e.SourcePlayer.Name} stojí toto kolo", "Zmrazený Esom", DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar, "#06b6d4"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.AceCountered:
|
||||
if (e.SourcePlayer != null)
|
||||
{
|
||||
AddLogItem(new GameLogItem("⚡", $"{e.SourcePlayer.Name} prebil Eso vlastným Esom!", "Protiútok", DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar, "#3b82f6"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.CardsBurned:
|
||||
if (e.SourcePlayer != null)
|
||||
{
|
||||
State.Stats.RecordBurn(e.SourcePlayer);
|
||||
AddLogItem(new GameLogItem("🔥", $"{e.SourcePlayer.Name} SPÁLIL 4 KARTY!", "Hrá znova", DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar, "#ef4444"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.SuitChanged:
|
||||
if (e.SourcePlayer != null && e.ChosenSuit.HasValue)
|
||||
{
|
||||
AddLogItem(new GameLogItem("👑", $"{e.SourcePlayer.Name} zmenil farbu na {GetSuitName(e.ChosenSuit.Value)}", null, DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar, "#eab308"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.PlayerRevived:
|
||||
if (e.TargetPlayer != null)
|
||||
{
|
||||
AddLogItem(new GameLogItem("❤️", $"{e.TargetPlayer.Name} VSTAL Z MŔTVYCH!", "Červená sedma", DateTime.UtcNow, e.TargetPlayer.Name, e.TargetPlayer.Avatar, "#ec4899"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.PlayerFinished:
|
||||
if (e.SourcePlayer != null)
|
||||
{
|
||||
AddLogItem(new GameLogItem("🏆", $"{e.SourcePlayer.Name} skončil na {e.ExtraData}. mieste!", "Vyprázdnil ruku", DateTime.UtcNow, e.SourcePlayer.Name, e.SourcePlayer.Avatar, "#ffd700"));
|
||||
}
|
||||
break;
|
||||
case GameEventType.GameOver:
|
||||
case GameEventType.MatchWon:
|
||||
State.Stats.EndTime = DateTime.UtcNow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddLogItem(GameLogItem item)
|
||||
{
|
||||
State.MoveLog.Add(item);
|
||||
if (State.MoveLog.Count > 30)
|
||||
{
|
||||
State.MoveLog.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSuitName(Suit suit) => suit switch
|
||||
{
|
||||
Suit.Hearts => "Červeň ❤️",
|
||||
Suit.Leaves => "Zeleň 🍃",
|
||||
Suit.Acorns => "Žaluď 🌰",
|
||||
Suit.Bells => "Guľu 🔔",
|
||||
_ => suit.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,4 +40,7 @@ public class GameState
|
||||
|
||||
public int ActivePlayersCount => Players.Where(p => !p.IsEliminated).Count(p => !p.HasFinished);
|
||||
public List<Player> ActiveTournamentPlayers => Players.Where(p => !p.IsEliminated).ToList();
|
||||
|
||||
public GameMatchStats Stats { get; set; } = new();
|
||||
public List<GameLogItem> MoveLog { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
namespace Faraon.Core.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public record GameLogItem(
|
||||
string Icon,
|
||||
string Text,
|
||||
string? SubText,
|
||||
DateTime Time,
|
||||
string? PlayerName = null,
|
||||
string? PlayerAvatar = null,
|
||||
string? AccentColor = null
|
||||
);
|
||||
|
||||
public class GameMatchStats
|
||||
{
|
||||
public DateTime StartTime { get; set; } = DateTime.UtcNow;
|
||||
public DateTime? EndTime { get; set; }
|
||||
public TimeSpan Duration => (EndTime ?? DateTime.UtcNow) - StartTime;
|
||||
public int TotalTurns { get; set; }
|
||||
public int TotalAcesPlayed { get; set; }
|
||||
public int TotalSevensPlayed { get; set; }
|
||||
public int TotalCardsBurned { get; set; }
|
||||
public int MaxPenaltyDrawnInOneTurn { get; set; }
|
||||
public string? MaxPenaltyPlayerName { get; set; }
|
||||
|
||||
public Dictionary<string, int> CardsPlayedPerPlayer { get; } = new();
|
||||
public Dictionary<string, int> CardsDrawnPerPlayer { get; } = new();
|
||||
public Dictionary<string, int> BurnsPerPlayer { get; } = new();
|
||||
|
||||
public void RecordCardPlayed(Player player, int count = 1)
|
||||
{
|
||||
CardsPlayedPerPlayer[player.Name] = CardsPlayedPerPlayer.GetValueOrDefault(player.Name) + count;
|
||||
}
|
||||
|
||||
public void RecordCardDrawn(Player player, int count = 1)
|
||||
{
|
||||
CardsDrawnPerPlayer[player.Name] = CardsDrawnPerPlayer.GetValueOrDefault(player.Name) + count;
|
||||
if (count > MaxPenaltyDrawnInOneTurn)
|
||||
{
|
||||
MaxPenaltyDrawnInOneTurn = count;
|
||||
MaxPenaltyPlayerName = player.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public void RecordBurn(Player player)
|
||||
{
|
||||
TotalCardsBurned += 4;
|
||||
BurnsPerPlayer[player.Name] = BurnsPerPlayer.GetValueOrDefault(player.Name) + 1;
|
||||
}
|
||||
|
||||
public string GetMvpPlayerName()
|
||||
{
|
||||
string best = "Nikto";
|
||||
int bestScore = -999;
|
||||
foreach (var (name, played) in CardsPlayedPerPlayer)
|
||||
{
|
||||
int burns = BurnsPerPlayer.GetValueOrDefault(name);
|
||||
int drawn = CardsDrawnPerPlayer.GetValueOrDefault(name);
|
||||
int score = (played * 2) + (burns * 10) - drawn;
|
||||
if (score > bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
best = name;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,11 @@ public class Player
|
||||
Avatar = avatar;
|
||||
Difficulty = difficulty;
|
||||
PersonalityId = personalityId;
|
||||
if (type == PlayerType.AI && string.IsNullOrEmpty(PersonalityId))
|
||||
{
|
||||
var pers = AIPersonality.All.FirstOrDefault(a => a.BaseAvatar == avatar);
|
||||
PersonalityId = pers?.Id ?? "fox";
|
||||
}
|
||||
}
|
||||
|
||||
public string GetLiveAvatar()
|
||||
|
||||
@@ -14,8 +14,20 @@ public enum GreenUnderKnaveMode
|
||||
UniversalWildcard // Ruší sedmy, ide na čokoľvek a súper naňho môže dať čokoľvek
|
||||
}
|
||||
|
||||
public enum TableTheme
|
||||
{
|
||||
ClassicGreen = 0,
|
||||
RoyalBurgundy = 1,
|
||||
WoodCabin = 2,
|
||||
CyberNeon = 3
|
||||
}
|
||||
|
||||
public class RuleOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Vizuálna téma a atmosféra herného stola.
|
||||
/// </summary>
|
||||
public TableTheme TableTheme { get; set; } = TableTheme.ClassicGreen;
|
||||
/// <summary>
|
||||
/// Počet kariet rozdaných každému hráčovi na začiatku (zvyčajne 4 alebo 5).
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user