* Тюрьма (#150) * Prison Init * Новая карта для планетарных тюрем * Готовая планетарная тюрьма * Незначительное изменение тайлов --------- Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com> * Космическая тюрьма и всё остальное говно * фиксы * фикс PrisonlDoctor * фикс PrisonDoctor * день длится 20 минут --------- Co-authored-by: SplikZerys <136282037+SplikZerys@users.noreply.github.com>
141 lines
5.3 KiB
C#
141 lines
5.3 KiB
C#
using System.Linq;
|
||
using Content.Server.Chat.Managers;
|
||
using Content.Server.GameTicking;
|
||
using Content.Server.Mind;
|
||
using Content.Server.Objectives;
|
||
using Content.Shared.Mind.Components;
|
||
using Content.Shared.Roles;
|
||
using Robust.Server.GameObjects;
|
||
using Robust.Shared.Timing;
|
||
|
||
namespace Content.Server._Sunrise.PlanetPrison
|
||
{
|
||
public sealed class PlanetPrisonSystem : EntitySystem
|
||
{
|
||
private const string AntagRole = "PlanetPrisoner";
|
||
private const string EscapeObjective = "PlanetPrisonerEscapeObjective";
|
||
private const string GameRule = "PlanetPrison";
|
||
|
||
private const float EscapeDistance = 200f;
|
||
|
||
public TimeSpan NextTick = TimeSpan.Zero;
|
||
public TimeSpan RefreshCooldown = TimeSpan.FromSeconds(5);
|
||
|
||
[Dependency] private readonly MindSystem _mindSystem = default!;
|
||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||
[Dependency] private readonly SharedRoleSystem _roleSystem = default!;
|
||
[Dependency] private readonly GameTicker _gameTicker = default!;
|
||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
||
[Dependency] private readonly IGameTiming _timing = default!;
|
||
|
||
public override void Initialize()
|
||
{
|
||
base.Initialize();
|
||
SubscribeLocalEvent<PlanetPrisonerComponent, MindAddedMessage>(OnMindAdded);
|
||
SubscribeLocalEvent<PlanetPrisonRuleComponent, ObjectivesTextGetInfoEvent>(OnObjectivesTextGetInfo);
|
||
SubscribeLocalEvent<PlanetPrisonRuleComponent, ObjectivesTextPrependEvent>(OnObjectivesTextPrepend);
|
||
}
|
||
|
||
private void OnObjectivesTextPrepend(EntityUid uid, PlanetPrisonRuleComponent comp, ref ObjectivesTextPrependEvent args)
|
||
{
|
||
var planetPrisonRule = GetPlanetPrisonRule();
|
||
args.Text += Loc.GetString("planet-prison-round-end-result", ("count", planetPrisonRule.PrisonersMinds.Count));
|
||
}
|
||
|
||
private void OnObjectivesTextGetInfo(EntityUid uid, PlanetPrisonRuleComponent comp, ref ObjectivesTextGetInfoEvent args)
|
||
{
|
||
args.Minds = comp.PrisonersMinds;
|
||
args.AgentName = Loc.GetString("planet-prisoner-round-end-name");
|
||
}
|
||
|
||
public override void Update(float frameTime)
|
||
{
|
||
if (NextTick > _timing.CurTime)
|
||
return;
|
||
|
||
NextTick += RefreshCooldown;
|
||
|
||
var planetPrisonRule = GetPlanetPrisonRule();
|
||
var planetPrisonStation = EntityQuery<PlanetPrisonStationComponent>().FirstOrDefault();
|
||
if (planetPrisonStation == null)
|
||
return;
|
||
var xformPrison = Transform(planetPrisonStation.PrisonGrid);
|
||
var prisonPosition = _transformSystem.GetMapCoordinates(xformPrison);
|
||
|
||
base.Update(frameTime);
|
||
var query = AllEntityQuery<PlanetPrisonerComponent, TransformComponent>();
|
||
while (query.MoveNext(out var prisoner, out _, out var xform))
|
||
{
|
||
var prisonerPosition = _transformSystem.GetMapCoordinates(xform);
|
||
|
||
if (prisonerPosition.MapId != planetPrisonStation.MapId)
|
||
continue;
|
||
|
||
var distance = (prisonerPosition.Position - prisonPosition.Position).Length();
|
||
|
||
if (!(distance > EscapeDistance) || !_mindSystem.TryGetMind(prisoner, out var mindId, out var mind))
|
||
continue;
|
||
|
||
if (planetPrisonRule.EscapedPrisoners.Contains(mindId))
|
||
continue;
|
||
|
||
// Не ну а чо
|
||
QueueDel(prisoner);
|
||
planetPrisonRule.EscapedPrisoners.Add(mindId);
|
||
}
|
||
}
|
||
|
||
public PlanetPrisonRuleComponent GetPlanetPrisonRule()
|
||
{
|
||
var planetPrisonRule = EntityQuery<PlanetPrisonRuleComponent>().FirstOrDefault();
|
||
if (planetPrisonRule != null)
|
||
return planetPrisonRule;
|
||
|
||
_gameTicker.StartGameRule(GameRule, out var ruleEntity);
|
||
planetPrisonRule = Comp<PlanetPrisonRuleComponent>(ruleEntity);
|
||
|
||
return planetPrisonRule;
|
||
}
|
||
|
||
public bool PrisonerEscaped(EntityUid mind)
|
||
{
|
||
var planetPrisonRule = GetPlanetPrisonRule();
|
||
return planetPrisonRule.EscapedPrisoners.Contains(mind);
|
||
}
|
||
|
||
private void OnMindAdded(EntityUid uid, PlanetPrisonerComponent component, MindAddedMessage args)
|
||
{
|
||
var planetPrisonRule = GetPlanetPrisonRule();
|
||
|
||
if (!_mindSystem.TryGetMind(uid, out var mindId, out var mind))
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (component.FirstMindAdded)
|
||
return;
|
||
|
||
component.FirstMindAdded = true;
|
||
|
||
|
||
if (_roleSystem.MindHasRole<PlanetPrisonerRoleComponent>(mindId))
|
||
{
|
||
_roleSystem.MindTryRemoveRole<PlanetPrisonerRoleComponent>(mindId);
|
||
}
|
||
|
||
_roleSystem.MindAddRole(mindId, new PlanetPrisonerRoleComponent
|
||
{
|
||
PrototypeId = AntagRole,
|
||
});
|
||
|
||
if (_mindSystem.TryGetSession(mind, out var session))
|
||
{
|
||
_chatManager.DispatchServerMessage(session, Loc.GetString("fugitive-role-greeting"));
|
||
}
|
||
|
||
_mindSystem.TryAddObjective(mindId, mind, EscapeObjective);
|
||
|
||
planetPrisonRule.PrisonersMinds.Add((mindId, Name(uid)));
|
||
}
|
||
}
|
||
}
|