ValleyPointsSystem.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. using System.Linq;
  2. using Content.Server.GameTicking.Rules.Components;
  3. using Content.Server.Chat.Managers;
  4. using Content.Server.Popups;
  5. using Content.Shared.GameTicking.Components;
  6. using Content.Shared.Mobs;
  7. using Content.Shared.Mobs.Components;
  8. using Content.Shared.NPC.Components;
  9. using Content.Shared.Interaction;
  10. using Content.Shared.Hands.EntitySystems;
  11. using Robust.Shared.Timing;
  12. using Content.Server.KillTracking;
  13. using Content.Shared.NPC.Systems;
  14. namespace Content.Server.GameTicking.Rules;
  15. /// <summary>
  16. /// Handles the Valley gamemode points system for Blugoslavia vs Insurgents
  17. /// </summary>
  18. public sealed class ValleyPointsRuleSystem : GameRuleSystem<ValleyPointsComponent>
  19. {
  20. [Dependency] private readonly ILogManager _logManager = default!;
  21. [Dependency] private readonly IGameTiming _timing = default!;
  22. [Dependency] private readonly IChatManager _chatManager = default!;
  23. [Dependency] private readonly PopupSystem _popup = default!;
  24. [Dependency] private readonly EntityLookupSystem _lookup = default!;
  25. [Dependency] private readonly SharedTransformSystem _transform = default!;
  26. [Dependency] private readonly SharedHandsSystem _hands = default!;
  27. [Dependency] private readonly NpcFactionSystem _factionSystem = default!; // Added dependency
  28. private ISawmill _sawmill = default!;
  29. private TimeSpan _lastSupplyBoxCheck = TimeSpan.Zero;
  30. private const float SupplyBoxCheckInterval = 30f; // Check every 30 seconds
  31. public override void Initialize()
  32. {
  33. base.Initialize();
  34. _sawmill = _logManager.GetSawmill("valley-points");
  35. SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
  36. SubscribeLocalEvent<CaptureAreaComponent, ComponentStartup>(OnCaptureAreaStartup);
  37. SubscribeLocalEvent<KillReportedEvent>(OnKillReported);
  38. }
  39. protected override void Started(EntityUid uid, ValleyPointsComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
  40. {
  41. component.GameStartTime = _timing.CurTime;
  42. component.LastCheckpointBonusTime = _timing.CurTime;
  43. component.LastScoreAnnouncementTime = _timing.CurTime;
  44. _lastSupplyBoxCheck = _timing.CurTime;
  45. // Initialize checkpoints immediately
  46. InitializeCheckpoints(component);
  47. // Delay civilian count initialization to allow spawning
  48. Timer.Spawn(TimeSpan.FromSeconds(5), () => InitializeCivilianCount(component));
  49. _sawmill.Info("Valley gamemode started - 50 minute timer begins now");
  50. AnnounceToAll("Valley conflict has begun! Blugoslavia and Insurgents fight for control.");
  51. }
  52. private void OnCaptureAreaStartup(EntityUid uid, CaptureAreaComponent component, ComponentStartup args)
  53. {
  54. if (HasComp<ValleyCheckpointComponent>(uid))
  55. {
  56. component.CapturableFactions.Clear();
  57. component.CapturableFactions.Add("Blugoslavia");
  58. component.CapturableFactions.Add("Insurgents");
  59. }
  60. }
  61. private void OnMobStateChanged(MobStateChangedEvent args)
  62. {
  63. if (args.NewMobState == MobState.Dead && args.OldMobState == MobState.Alive)
  64. {
  65. if (TryComp<NpcFactionMemberComponent>(args.Target, out var factionMember) &&
  66. factionMember.Factions.Any(f => f == "Blugoslavia"))
  67. {
  68. var ruleQuery = EntityQueryEnumerator<ValleyPointsComponent>();
  69. if (ruleQuery.MoveNext(out var ruleEntity, out _))
  70. {
  71. AwardInsurgentKill(ruleEntity);
  72. }
  73. }
  74. }
  75. }
  76. private void InitializeCivilianCount(ValleyPointsComponent component)
  77. {
  78. // Count civilian NPCs on the map
  79. var civilianCount = 0;
  80. var query = EntityQueryEnumerator<NpcFactionMemberComponent>();
  81. while (query.MoveNext(out _, out var faction))
  82. {
  83. if (faction.Factions.Any(f => f == "Civilian"))
  84. civilianCount++;
  85. }
  86. component.InitialCivilianCount = civilianCount;
  87. component.TotalCivilianNPCs = civilianCount;
  88. _sawmill.Info($"Initialized with {civilianCount} civilian NPCs");
  89. }
  90. private void InitializeCheckpoints(ValleyPointsComponent valley)
  91. {
  92. var checkpointQuery = EntityQueryEnumerator<ValleyCheckpointComponent, CaptureAreaComponent>();
  93. while (checkpointQuery.MoveNext(out var uid, out var checkpoint, out var area))
  94. {
  95. area.CapturableFactions.Clear();
  96. area.CapturableFactions.Add("Blugoslavia");
  97. area.CapturableFactions.Add("Insurgents");
  98. _sawmill.Info($"Initialized Valley checkpoint: {area.Name}");
  99. }
  100. }
  101. public override void Update(float frameTime)
  102. {
  103. base.Update(frameTime);
  104. var query = EntityQueryEnumerator<ValleyPointsComponent, GameRuleComponent>();
  105. while (query.MoveNext(out var uid, out var valley, out var gameRule))
  106. {
  107. if (!GameTicker.IsGameRuleAdded(uid, gameRule))
  108. continue;
  109. if (valley.GameEnded)
  110. continue;
  111. UpdateCheckpointHolding(valley);
  112. UpdateSupplyBoxSecuring(valley);
  113. CheckCaptureAreaControl(valley);
  114. CheckSupplyBoxDeliveries(valley);
  115. CheckScoreAnnouncement(valley);
  116. CheckWinConditions(uid, valley);
  117. CheckTimeLimit(uid, valley);
  118. }
  119. }
  120. private void CheckSupplyBoxDeliveries(ValleyPointsComponent valley)
  121. {
  122. var currentTime = _timing.CurTime;
  123. // Only check every 30 seconds
  124. if ((currentTime - _lastSupplyBoxCheck).TotalSeconds < SupplyBoxCheckInterval)
  125. return;
  126. _lastSupplyBoxCheck = currentTime;
  127. // Check all capture areas for nearby supply boxes
  128. var areaQuery = EntityQueryEnumerator<CaptureAreaComponent>();
  129. while (areaQuery.MoveNext(out var areaUid, out var area))
  130. {
  131. var areaPos = _transform.GetMapCoordinates(areaUid);
  132. var nearbyEntities = _lookup.GetEntitiesInRange(areaPos, 3f);
  133. foreach (var entity in nearbyEntities)
  134. {
  135. if (TryComp<ValleySupplyBoxComponent>(entity, out var supplyBox) && !supplyBox.Delivered)
  136. {
  137. // Check if this is a checkpoint controlled by Blugoslavia
  138. if (HasComp<ValleyCheckpointComponent>(areaUid) && area.Controller == "Blugoslavia")
  139. {
  140. ProcessBlugoslavianSupplyDelivery(valley, entity, areaUid, area);
  141. }
  142. // Check if this is the Insurgent base
  143. else if (IsInsurgentBase(areaUid, area))
  144. {
  145. ProcessInsurgentSupplyTheft(valley, entity, areaUid, area);
  146. }
  147. }
  148. }
  149. }
  150. }
  151. private bool IsInsurgentBase(EntityUid areaUid, CaptureAreaComponent area)
  152. {
  153. // Check if this area is marked as insurgent base
  154. return area.Name.ToLower().Contains("insurgent");
  155. }
  156. private void ProcessBlugoslavianSupplyDelivery(ValleyPointsComponent valley, EntityUid supplyBox, EntityUid checkpoint, CaptureAreaComponent area)
  157. {
  158. if (!TryComp<ValleySupplyBoxComponent>(supplyBox, out var boxComp))
  159. return;
  160. boxComp.Delivered = true;
  161. boxComp.SecuringAtCheckpoint = checkpoint;
  162. // Start securing timer
  163. valley.SecuringSupplyBoxes[supplyBox] = _timing.CurTime;
  164. _sawmill.Info($"Supply box delivery started at {area.Name}, securing for {valley.SupplyBoxSecureTime} seconds");
  165. AnnounceToAll($"Blugoslavia supply box delivery started at {area.Name}!");
  166. }
  167. private void ProcessInsurgentSupplyTheft(ValleyPointsComponent valley, EntityUid supplyBox, EntityUid baseArea, CaptureAreaComponent area)
  168. {
  169. if (!TryComp<ValleySupplyBoxComponent>(supplyBox, out var boxComp))
  170. return;
  171. boxComp.Delivered = true;
  172. // Award points immediately for insurgent theft
  173. valley.InsurgentPoints += valley.StolenSupplyBoxPoints;
  174. _sawmill.Info($"Insurgents awarded {valley.StolenSupplyBoxPoints} points for stolen supply box at {area.Name}. Total: {valley.InsurgentPoints}");
  175. AnnounceToAll($"Insurgents: +{valley.StolenSupplyBoxPoints} points (Supply Theft at {area.Name}) - Total: {valley.InsurgentPoints}");
  176. // Remove the supply box
  177. QueueDel(supplyBox);
  178. }
  179. private void CheckCaptureAreaControl(ValleyPointsComponent valley)
  180. {
  181. var checkpointQuery = EntityQueryEnumerator<ValleyCheckpointComponent, CaptureAreaComponent>();
  182. while (checkpointQuery.MoveNext(out var uid, out var checkpoint, out var area))
  183. {
  184. var blugoslaviaControlled = area.Controller == "Blugoslavia";
  185. if (checkpoint.BlugoslaviaControlled != blugoslaviaControlled)
  186. {
  187. checkpoint.BlugoslaviaControlled = blugoslaviaControlled;
  188. SetCheckpointControl(valley, uid, blugoslaviaControlled);
  189. }
  190. }
  191. }
  192. public void SetCheckpointControl(ValleyPointsComponent valley, EntityUid checkpoint, bool blugoslaviaControlled)
  193. {
  194. if (blugoslaviaControlled)
  195. {
  196. if (!valley.BlugoslaviaHeldCheckpoints.Contains(checkpoint))
  197. {
  198. valley.BlugoslaviaHeldCheckpoints.Add(checkpoint);
  199. valley.CheckpointHoldStartTimes[checkpoint] = _timing.CurTime;
  200. _sawmill.Info($"Blugoslavia gained control of checkpoint {checkpoint}");
  201. }
  202. }
  203. else
  204. {
  205. if (valley.BlugoslaviaHeldCheckpoints.Contains(checkpoint))
  206. {
  207. valley.BlugoslaviaHeldCheckpoints.Remove(checkpoint);
  208. valley.CheckpointHoldStartTimes.Remove(checkpoint);
  209. _sawmill.Info($"Blugoslavia lost control of checkpoint {checkpoint}");
  210. }
  211. }
  212. }
  213. private void UpdateCheckpointHolding(ValleyPointsComponent valley)
  214. {
  215. var currentTime = _timing.CurTime;
  216. var checkpointsToAward = new List<EntityUid>();
  217. // Check individual checkpoint holding - award points every minute (60 seconds)
  218. foreach (var kvp in valley.CheckpointHoldStartTimes.ToList())
  219. {
  220. var checkpoint = kvp.Key;
  221. var startTime = kvp.Value;
  222. if ((currentTime - startTime).TotalSeconds >= 60f) // 1 minute instead of 5
  223. {
  224. checkpointsToAward.Add(checkpoint);
  225. valley.CheckpointHoldStartTimes[checkpoint] = currentTime;
  226. }
  227. }
  228. if (checkpointsToAward.Count > 0)
  229. {
  230. var pointsAwarded = checkpointsToAward.Count * 5; // 5 points per minute instead of 25 per 5 minutes
  231. valley.BlugoslaviaPoints += pointsAwarded;
  232. _sawmill.Info($"Blugoslavia awarded {pointsAwarded} points for holding {checkpointsToAward.Count} checkpoints");
  233. AnnounceToAll($"Blugoslavia: +{pointsAwarded} points (Checkpoint Control) - Total: {valley.BlugoslaviaPoints}");
  234. }
  235. // Check for all checkpoints bonus - still every 5 minutes but reduced frequency
  236. if (valley.BlugoslaviaHeldCheckpoints.Count >= 4 && // Assuming 4 checkpoints total
  237. (currentTime - valley.LastCheckpointBonusTime).TotalSeconds >= valley.CheckpointBonusInterval)
  238. {
  239. valley.BlugoslaviaPoints += valley.AllCheckpointsBonusPoints;
  240. valley.LastCheckpointBonusTime = currentTime;
  241. _sawmill.Info($"Blugoslavia awarded {valley.AllCheckpointsBonusPoints} bonus points for controlling all checkpoints");
  242. AnnounceToAll($"Blugoslavia: +{valley.AllCheckpointsBonusPoints} points (All Checkpoints Bonus) - Total: {valley.BlugoslaviaPoints}");
  243. }
  244. }
  245. private void UpdateSupplyBoxSecuring(ValleyPointsComponent valley)
  246. {
  247. var currentTime = _timing.CurTime;
  248. var securedBoxes = new List<EntityUid>();
  249. // Check all checkpoints for securing boxes
  250. var checkpointQuery = EntityQueryEnumerator<ValleyCheckpointComponent>();
  251. while (checkpointQuery.MoveNext(out var checkpointUid, out var checkpoint))
  252. {
  253. var boxesToRemove = new List<EntityUid>();
  254. foreach (var boxUid in checkpoint.SecuringBoxes)
  255. {
  256. if (!TryComp<ValleySupplyBoxComponent>(boxUid, out var boxComp))
  257. {
  258. boxesToRemove.Add(boxUid);
  259. continue;
  260. }
  261. // Check if box is still near the checkpoint
  262. var boxPos = _transform.GetMapCoordinates(boxUid);
  263. var checkpointPos = _transform.GetMapCoordinates(checkpointUid);
  264. if ((boxPos.Position - checkpointPos.Position).Length() > 3f)
  265. {
  266. // Box moved away, cancel securing
  267. boxesToRemove.Add(boxUid);
  268. boxComp.Delivered = false;
  269. boxComp.SecuringAtCheckpoint = null;
  270. _sawmill.Info("Supply box moved away from checkpoint, delivery cancelled");
  271. continue;
  272. }
  273. // Check if securing time has elapsed
  274. if (valley.SecuringSupplyBoxes.TryGetValue(boxUid, out var startTime) &&
  275. (currentTime - startTime).TotalSeconds >= valley.SupplyBoxSecureTime)
  276. {
  277. securedBoxes.Add(boxUid);
  278. boxesToRemove.Add(boxUid);
  279. }
  280. }
  281. // Remove boxes that are no longer securing
  282. foreach (var box in boxesToRemove)
  283. {
  284. checkpoint.SecuringBoxes.Remove(box);
  285. }
  286. }
  287. // Award points for secured boxes
  288. foreach (var box in securedBoxes)
  289. {
  290. valley.SecuringSupplyBoxes.Remove(box);
  291. valley.BlugoslaviaPoints += valley.SupplyBoxDeliveryPoints;
  292. _sawmill.Info($"Blugoslavia awarded {valley.SupplyBoxDeliveryPoints} points for secured supply box delivery");
  293. AnnounceToAll($"Blugoslavia: +{valley.SupplyBoxDeliveryPoints} points (Supply Delivery) - Total: {valley.BlugoslaviaPoints}");
  294. // Delete the secured box
  295. QueueDel(box);
  296. }
  297. }
  298. /// <summary>
  299. /// Award points to Blugoslavia for delivering a supply box to a checkpoint.
  300. /// </summary>
  301. public void AwardSupplyBoxDelivery(EntityUid ruleEntity, EntityUid checkpoint, EntityUid supplyBox)
  302. {
  303. if (!TryComp<ValleyPointsComponent>(ruleEntity, out var valley))
  304. return;
  305. // Start securing timer
  306. valley.SecuringSupplyBoxes[supplyBox] = _timing.CurTime;
  307. _sawmill.Info($"Supply box delivery started at checkpoint, securing for {valley.SupplyBoxSecureTime} seconds");
  308. }
  309. /// <summary>
  310. /// Award points to insurgents for killing a Blugoslavian soldier.
  311. /// </summary>
  312. public void AwardInsurgentKill(EntityUid ruleEntity)
  313. {
  314. if (!TryComp<ValleyPointsComponent>(ruleEntity, out var valley))
  315. return;
  316. valley.InsurgentPoints += valley.KillPoints;
  317. _sawmill.Info($"Insurgents awarded {valley.KillPoints} points for kill. Total: {valley.InsurgentPoints}");
  318. AnnounceToAll($"Insurgents: +{valley.KillPoints} points (Kill) - Total: {valley.InsurgentPoints}");
  319. }
  320. /// <summary>
  321. /// Award points to insurgents for stealing and delivering a supply box.
  322. /// </summary>
  323. public void AwardStolenSupplyBox(EntityUid ruleEntity)
  324. {
  325. if (!TryComp<ValleyPointsComponent>(ruleEntity, out var valley))
  326. return;
  327. valley.InsurgentPoints += valley.StolenSupplyBoxPoints;
  328. _sawmill.Info($"Insurgents awarded {valley.StolenSupplyBoxPoints} points for stolen supply box. Total: {valley.InsurgentPoints}");
  329. AnnounceToAll($"Insurgents: +{valley.StolenSupplyBoxPoints} points (Supply Theft) - Total: {valley.InsurgentPoints}");
  330. }
  331. /// <summary>
  332. /// Award points to Blugoslavia for successfully escorting a convoy.
  333. /// </summary>
  334. public void AwardConvoyEscort(EntityUid ruleEntity)
  335. {
  336. if (!TryComp<ValleyPointsComponent>(ruleEntity, out var valley))
  337. return;
  338. valley.BlugoslaviaPoints += valley.ConvoyEscortPoints;
  339. _sawmill.Info($"Blugoslavia awarded {valley.ConvoyEscortPoints} points for convoy escort. Total: {valley.BlugoslaviaPoints}");
  340. AnnounceToAll($"Blugoslavia: +{valley.ConvoyEscortPoints} points (Convoy Escort) - Total: {valley.BlugoslaviaPoints}");
  341. }
  342. private void CheckWinConditions(EntityUid uid, ValleyPointsComponent valley)
  343. {
  344. if (valley.BlugoslaviaPoints >= valley.PointsToWin)
  345. {
  346. EndGame(uid, valley, "Blugoslavia");
  347. }
  348. else if (valley.InsurgentPoints >= valley.PointsToWin)
  349. {
  350. EndGame(uid, valley, "Insurgents");
  351. }
  352. }
  353. private void CheckTimeLimit(EntityUid uid, ValleyPointsComponent valley)
  354. {
  355. var elapsed = (_timing.CurTime - valley.GameStartTime).TotalMinutes;
  356. if (elapsed >= valley.MatchDurationMinutes)
  357. {
  358. // Determine winner by points
  359. if (valley.BlugoslaviaPoints > valley.InsurgentPoints)
  360. {
  361. EndGame(uid, valley, "Blugoslavia");
  362. }
  363. else if (valley.InsurgentPoints > valley.BlugoslaviaPoints)
  364. {
  365. EndGame(uid, valley, "Insurgents");
  366. }
  367. else
  368. {
  369. EndGame(uid, valley, "Draw");
  370. }
  371. }
  372. }
  373. private void EndGame(EntityUid uid, ValleyPointsComponent valley, string winner)
  374. {
  375. valley.GameEnded = true;
  376. var finalMessage = winner switch
  377. {
  378. "Blugoslavia" => $"VICTORY: Blugoslavia wins with {valley.BlugoslaviaPoints} points!",
  379. "Insurgents" => $"VICTORY: Insurgents win with {valley.InsurgentPoints} points!",
  380. "Draw" => $"DRAW: Match ended in a tie! Blugoslavia: {valley.BlugoslaviaPoints}, Insurgents: {valley.InsurgentPoints}",
  381. _ => "Match ended."
  382. };
  383. _sawmill.Info($"Valley gamemode ended: {finalMessage}");
  384. AnnounceToAll(finalMessage);
  385. // Check UN objectives
  386. AnnounceToAll(CheckUNObjectives(valley));
  387. }
  388. private string CheckUNObjectives(ValleyPointsComponent valley)
  389. {
  390. var civilianSurvivalRate = valley.TotalCivilianNPCs > 0
  391. ? (float)valley.AliveCivilianNPCs / valley.TotalCivilianNPCs
  392. : 1.0f;
  393. var query = EntityQueryEnumerator<CaptureAreaComponent>();
  394. while (query.MoveNext(out var uid, out var area))
  395. {
  396. if (area.Name == "UN Hospital")
  397. {
  398. if (area.Occupied == true)
  399. {
  400. valley.UNHospitalZoneControlled = false;
  401. }
  402. else
  403. {
  404. valley.UNHospitalZoneControlled = true;
  405. }
  406. }
  407. }
  408. var unSuccess = civilianSurvivalRate >= valley.RequiredCivilianSurvivalRate &&
  409. valley.UNHospitalZoneControlled &&
  410. valley.UNNeutralityMaintained;
  411. var unMessage = unSuccess
  412. ? $"UN OBJECTIVES COMPLETED: {civilianSurvivalRate:P0} civilian survival rate maintained, hospital zone secured, neutrality preserved."
  413. : $"UN OBJECTIVES FAILED: {civilianSurvivalRate:P0} civilian survival rate, hospital zone: {(valley.UNHospitalZoneControlled ? "Secured" : "Lost")}, neutrality: {(valley.UNNeutralityMaintained ? "Maintained" : "Violated")}";
  414. _sawmill.Info(unMessage);
  415. return unMessage;
  416. }
  417. private void AnnounceToAll(string message)
  418. {
  419. _chatManager.DispatchServerAnnouncement(message);
  420. }
  421. protected override void AppendRoundEndText(EntityUid uid, ValleyPointsComponent component, GameRuleComponent gameRule, ref RoundEndTextAppendEvent args)
  422. {
  423. if (component.BlugoslaviaPoints > component.InsurgentPoints)
  424. {
  425. args.AddLine($"[color=lime]Blugoslavia[/color] has won!");
  426. }
  427. else if (component.BlugoslaviaPoints < component.InsurgentPoints)
  428. {
  429. args.AddLine($"[color=lime]Insurgents[/color] have won!");
  430. }
  431. else
  432. {
  433. args.AddLine("The round ended in a [color=yellow]draw[/color]!");
  434. }
  435. args.AddLine("");
  436. args.AddLine($"Blugoslavia: {component.BlugoslaviaPoints} points");
  437. args.AddLine($"Insurgents: {component.InsurgentPoints} points");
  438. args.AddLine("");
  439. args.AddLine($"UN Objectives:");
  440. args.AddLine(CheckUNObjectives(component));
  441. }
  442. private void OnKillReported(ref KillReportedEvent ev)
  443. {
  444. var query = EntityQueryEnumerator<ValleyPointsComponent, GameRuleComponent>();
  445. while (query.MoveNext(out var uid, out var valley, out var rule))
  446. {
  447. if (!GameTicker.IsGameRuleActive(uid, rule))
  448. continue;
  449. // Check if UN member was involved (either as killer or victim) TODO: Check killer
  450. bool unInvolved = false;
  451. // Check if victim is UN
  452. if (TryComp<NpcFactionMemberComponent>(ev.Entity, out var victimFaction))
  453. {
  454. if (_factionSystem.IsMember(ev.Entity, "UnitedNations"))
  455. {
  456. unInvolved = true;
  457. }
  458. // If UN was involved, set neutrality to false
  459. if (unInvolved && valley.UNNeutralityMaintained)
  460. {
  461. valley.UNNeutralityMaintained = false;
  462. _sawmill.Info("UN neutrality violated - UN member involved in combat");
  463. AnnounceToAll("UN neutrality has been violated!");
  464. }
  465. // Award points to Insurgents for killing Blugoslavian soldiers
  466. if (TryComp<NpcFactionMemberComponent>(ev.Entity, out var deadFaction) &&
  467. deadFaction.Factions.Any(f => f == "Blugoslavia"))
  468. {
  469. valley.InsurgentPoints += valley.KillPoints;
  470. _sawmill.Info($"Insurgents awarded {valley.KillPoints} points for Blugoslavian kill. Total: {valley.InsurgentPoints}");
  471. AnnounceToAll($"Insurgents: +{valley.KillPoints} points (Kill) - Total: {valley.InsurgentPoints}");
  472. }
  473. }
  474. }
  475. }
  476. private void CheckScoreAnnouncement(ValleyPointsComponent valley)
  477. {
  478. var currentTime = _timing.CurTime;
  479. // Announce scores every 5 minutes (300 seconds)
  480. if ((currentTime - valley.LastScoreAnnouncementTime).TotalSeconds >= 300f)
  481. {
  482. valley.LastScoreAnnouncementTime = currentTime;
  483. var elapsedMinutes = (currentTime - valley.GameStartTime).TotalMinutes;
  484. var remainingMinutes = valley.MatchDurationMinutes - elapsedMinutes;
  485. var scoreMessage = $"SCORE UPDATE ({remainingMinutes:F0} minutes remaining): " +
  486. $"Blugoslavia: {valley.BlugoslaviaPoints} points | " +
  487. $"Insurgents: {valley.InsurgentPoints} points";
  488. _sawmill.Info($"Score announcement: {scoreMessage}");
  489. AnnounceToAll(scoreMessage);
  490. }
  491. }
  492. }