mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
137 lines
5.1 KiB
C#
137 lines
5.1 KiB
C#
using Content.Server.Clothing.Systems;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Server.KillTracking;
|
|
using Content.Server.Mind;
|
|
using Content.Server.Points;
|
|
using Content.Server.RoundEnd;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Shared.EntityTable;
|
|
using Content.Shared.GameTicking;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.GameTicking.Rules;
|
|
using Content.Shared.Points;
|
|
using Content.Shared.Station.Systems;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
/// <summary>
|
|
/// Manages <see cref="DeathMatchRuleComponent"/>
|
|
/// </summary>
|
|
public sealed partial class DeathMatchRuleSystem : GameRuleSystem<DeathMatchRuleComponent>
|
|
{
|
|
[Dependency] private IPlayerManager _player = default!;
|
|
[Dependency] private MindSystem _mind = default!;
|
|
[Dependency] private OutfitSystem _outfitSystem = default!;
|
|
[Dependency] private PointSystem _point = default!;
|
|
[Dependency] private RespawnRuleSystem _respawn = default!;
|
|
[Dependency] private RoundEndSystem _roundEnd = default!;
|
|
[Dependency] private StationSpawningSystem _stationSpawning = default!;
|
|
[Dependency] private EntityTableSystem _entityTable = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<PlayerBeforeSpawnEvent>(OnBeforeSpawn);
|
|
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnSpawnComplete);
|
|
SubscribeLocalEvent<KillReportedEvent>(OnKillReported);
|
|
SubscribeLocalEvent<DeathMatchRuleComponent, PlayerPointChangedEvent>(OnPointChanged);
|
|
}
|
|
|
|
private void OnBeforeSpawn(PlayerBeforeSpawnEvent ev)
|
|
{
|
|
var query = EntityQueryEnumerator<DeathMatchRuleComponent, RespawnTrackerComponent, PointManagerComponent, GameRuleComponent>();
|
|
while (query.MoveNext(out var uid, out var dm, out var tracker, out var point, out var rule))
|
|
{
|
|
if (!GameTicker.IsGameRuleActive((uid, rule)))
|
|
continue;
|
|
|
|
var newMind = _mind.CreateMind(ev.Player.UserId, ev.Profile.Name);
|
|
_mind.SetUserId(newMind, ev.Player.UserId);
|
|
|
|
var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(ev.Station, null, ev.Profile);
|
|
DebugTools.AssertNotNull(mobMaybe);
|
|
var mob = mobMaybe!.Value;
|
|
|
|
_mind.TransferTo(newMind, mob);
|
|
_outfitSystem.SetOutfit(mob, dm.Gear);
|
|
EnsureComp<KillTrackerComponent>(mob);
|
|
_respawn.AddToTracker(ev.Player.UserId, (uid, tracker));
|
|
|
|
_point.EnsurePlayer(ev.Player.UserId, uid, point);
|
|
|
|
ev.Handled = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void OnSpawnComplete(PlayerSpawnCompleteEvent ev)
|
|
{
|
|
EnsureComp<KillTrackerComponent>(ev.Mob);
|
|
var query = EntityQueryEnumerator<DeathMatchRuleComponent, RespawnTrackerComponent, GameRuleComponent>();
|
|
while (query.MoveNext(out var uid, out _, out var tracker, out var rule))
|
|
{
|
|
if (!GameTicker.IsGameRuleActive((uid, rule)))
|
|
continue;
|
|
|
|
_respawn.AddToTracker((ev.Mob, null), (uid, tracker));
|
|
}
|
|
}
|
|
|
|
private void OnKillReported(ref KillReportedEvent ev)
|
|
{
|
|
var query = EntityQueryEnumerator<DeathMatchRuleComponent, PointManagerComponent, GameRuleComponent>();
|
|
while (query.MoveNext(out var uid, out var dm, out var point, out var rule))
|
|
{
|
|
if (!GameTicker.IsGameRuleActive((uid, rule)))
|
|
continue;
|
|
|
|
// YOU SUICIDED OR GOT THROWN INTO LAVA!
|
|
// WHAT A GIANT FUCKING NERD! LAUGH NOW!
|
|
if (ev.Primary is not KillPlayerSource player)
|
|
{
|
|
_point.AdjustPointValue(ev.Entity, -1, uid, point);
|
|
continue;
|
|
}
|
|
|
|
_point.AdjustPointValue(player.PlayerId, 1, uid, point);
|
|
|
|
if (ev.Assist is KillPlayerSource assist && dm.Victor == null)
|
|
_point.AdjustPointValue(assist.PlayerId, 1, uid, point);
|
|
|
|
foreach (var spawn in _entityTable.GetSpawns(dm.RewardSpawns))
|
|
{
|
|
SpawnNextToOrDrop(spawn, ev.Entity);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnPointChanged(EntityUid uid, DeathMatchRuleComponent component, ref PlayerPointChangedEvent args)
|
|
{
|
|
if (component.Victor != null)
|
|
return;
|
|
|
|
if (args.Points < component.KillCap)
|
|
return;
|
|
|
|
component.Victor = args.Player;
|
|
_roundEnd.EndRound(component.RestartDelay);
|
|
}
|
|
|
|
protected override void AppendRoundEndText(Entity<DeathMatchRuleComponent> entity, ref RoundEndTextAppendEvent args)
|
|
{
|
|
if (!TryComp<PointManagerComponent>(entity, out var point))
|
|
return;
|
|
|
|
if (entity.Comp.Victor != null && _player.TryGetPlayerData(entity.Comp.Victor.Value, out var data))
|
|
{
|
|
args.AddLine(Loc.GetString("point-scoreboard-winner", ("player", data.UserName)));
|
|
args.AddLine("");
|
|
}
|
|
args.AddLine(Loc.GetString("point-scoreboard-header"));
|
|
args.AddLine(new FormattedMessage(point.Scoreboard).ToMarkup());
|
|
args.AddLine("");
|
|
}
|
|
}
|