Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port] Aspects / Аспекты #9

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Text;
using Content.Server.GameTicking.Components;
using Content.Server.Traitor.Components;
using Content.Shared.Mobs.Systems;

namespace Content.Server.GameTicking.Rules;

Expand All @@ -31,6 +32,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
[Dependency] private readonly SharedRoleSystem _roleSystem = default!;
[Dependency] private readonly SharedJobSystem _jobs = default!;
[Dependency] private readonly ObjectivesSystem _objectives = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!; // WD EDIT

public const int MaxPicks = 20;

Expand Down Expand Up @@ -74,6 +76,8 @@ public bool MakeTraitor(EntityUid traitor, TraitorRuleComponent component, bool
if (!_mindSystem.TryGetMind(traitor, out var mindId, out var mind))
return false;

component.SelectionStatus = TraitorRuleComponent.SelectionState.Started; // WD EDIT

var briefing = Loc.GetString("traitor-role-codewords-short", ("codewords", string.Join(", ", component.Codewords)));

if (TryComp<AutoTraitorComponent>(traitor, out var autoTraitorComponent))
Expand Down Expand Up @@ -190,4 +194,47 @@ private string GenerateBriefing(string[] codewords, Note[]? uplinkCode)

return traitors;
}

// WD EDIT START
public List<(EntityUid Id, MindComponent Mind)> GetAllLivingConnectedTraitors()
{
var traitors = new List<(EntityUid Id, MindComponent Mind)>();

var traitorRules = EntityQuery<TraitorRuleComponent>();

foreach (var traitorRule in traitorRules)
{
traitors.AddRange(GetLivingConnectedTraitors(traitorRule));
}

return traitors;
}

private List<(EntityUid Id, MindComponent Mind)> GetLivingConnectedTraitors(TraitorRuleComponent traitorRule)
{
var traitors = new List<(EntityUid Id, MindComponent Mind)>();

foreach (var traitor in traitorRule.TraitorMinds)
{
if (!TryComp(traitor, out MindComponent? mind))
continue;

if (mind.OwnedEntity == null)
continue;

if (mind.Session == null)
continue;

if (!_mobStateSystem.IsAlive(mind.OwnedEntity.Value))
continue;

if (mind.CurrentEntity != mind.OwnedEntity)
continue;

traitors.Add((traitor, mind));
}

return traitors;
}
// WD EDIT END
}
13 changes: 10 additions & 3 deletions Content.Server/Holiday/Christmas/RandomGiftSystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Content.Server.Administration.Logs;
using System.Linq;
using Content.Server._White.Other;
using Content.Server.Administration.Logs;
using Content.Server.Hands.Systems;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Interaction.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Robust.Server.Audio;
using Robust.Server.GameObjects;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
Expand Down Expand Up @@ -90,6 +92,8 @@ private void BuildIndex()
var itemCompName = _componentFactory.GetComponentName(typeof(ItemComponent));
var mapGridCompName = _componentFactory.GetComponentName(typeof(MapGridComponent));
var physicsCompName = _componentFactory.GetComponentName(typeof(PhysicsComponent));
var giftIgnoreCompName = _componentFactory.GetComponentName(typeof(GiftIgnoreComponent)); // WD
var unremovableCompName = _componentFactory.GetComponentName(typeof(UnremoveableComponent)); // WD

foreach (var proto in _prototype.EnumeratePrototypes<EntityPrototype>())
{
Expand All @@ -98,7 +102,10 @@ private void BuildIndex()

_possibleGiftsUnsafe.Add(proto.ID);

if (!proto.Components.ContainsKey(itemCompName))
if (!proto.Components.ContainsKey(itemCompName) || proto.Components.ContainsKey(giftIgnoreCompName) ||
proto.Components.ContainsKey(unremovableCompName) || proto.SetSuffix != null &&
new[] {"Debug, Admeme, Admin"}.Any(x =>
proto.SetSuffix.Contains(x, StringComparison.OrdinalIgnoreCase))) // WD EDIT
continue;

_possibleGiftsSafe.Add(proto.ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Content.Server._White.AspectsSystem.Aspects.Components;

[RegisterComponent]
public sealed partial class ImmersiveAspectComponent : Component
{
[DataField]
public float EyeModifier = 0.6f;

[DataField]
public float TelescopeDivisor = 0.15f;

[DataField]
public float TelescopeLerpAmount = 0.07f;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Content.Server._White.AspectsSystem.Aspects.Components;

[RegisterComponent]
public sealed partial class LandmineAspectComponent : Component
{
[DataField]
public int Min = 40;

[DataField]
public int Max = 60;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server._White.AspectsSystem.Aspects.Components;

[RegisterComponent]
public sealed partial class NothingAspectComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Content.Server._White.AspectsSystem.Aspects.Components;

[RegisterComponent]
public sealed partial class PresentAspectComponent : Component
{
[DataField]
public int Min = 150;

[DataField]
public int Max = 200;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server._White.AspectsSystem.Aspects.Components;

[RegisterComponent]
public sealed partial class ReflectAspectComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server._White.AspectsSystem.Aspects.Components;

[RegisterComponent]
public sealed partial class TraitorRichAspectComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Content.Server._White.AspectsSystem.Aspects.Components;

[RegisterComponent]
public sealed partial class TraitoredAspectComponent : Component
{
[DataField]
public int TimeElapsedForTraitors = 60;

[DataField]
public int TimeElapsedForAllMin = 300;

[DataField]
public int TimeElapsedForAllMax = 360;

[DataField]
public string AnnouncementForTraitorSound = "/Audio/_White/Aspects/palevo.ogg";
}
97 changes: 97 additions & 0 deletions Content.Server/_White/AspectsSystem/Aspects/ImmersiveAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Numerics;
using Content.Server._White.AspectsSystem.Aspects.Components;
using Content.Server._White.AspectsSystem.Base;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Components;
using Content.Shared._White.Telescope;
using Content.Shared.Humanoid;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;

namespace Content.Server._White.AspectsSystem.Aspects;

public sealed class ImmersiveAspect : AspectSystem<ImmersiveAspectComponent>
{

[Dependency] private readonly SharedContentEyeSystem _eye = default!;
[Dependency] private readonly SharedTelescopeSystem _telescope = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawn);
}

protected override void Started(EntityUid uid, ImmersiveAspectComponent component, GameRuleComponent gameRule,
GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);

OnStarted(component);
}

private void OnStarted(ImmersiveAspectComponent component)
{
var humans = EntityQuery<HumanoidAppearanceComponent>();

foreach (var human in humans)
{
var entity = human.Owner;

if (!HasComp<ContentEyeComponent>(entity))
continue;

SetEyeZoom(entity, component.EyeModifier);
AddTelescope(entity, component.TelescopeDivisor, component.TelescopeLerpAmount);
}
}

private void SetEyeZoom(EntityUid human, float modifier)
{
_eye.SetMaxZoom(human, new Vector2(modifier));
_eye.SetZoom(human, new Vector2(modifier));
}

private void AddTelescope(EntityUid human, float divisor, float lerpAmount)
{
var telescope = EnsureComp<TelescopeComponent>(human);

_telescope.SetParameters((human, telescope), divisor, lerpAmount);
}

private void OnPlayerSpawn(PlayerSpawnCompleteEvent ev)
{
if (!HasComp<ContentEyeComponent>(ev.Mob))
return;

var query = EntityQueryEnumerator<ImmersiveAspectComponent, GameRuleComponent>();
while (query.MoveNext(out var ruleEntity, out var immersiveAspect, out var gameRule))
{
if (!GameTicker.IsGameRuleAdded(ruleEntity, gameRule))
continue;

SetEyeZoom(ev.Mob, immersiveAspect.EyeModifier);
AddTelescope(ev.Mob, immersiveAspect.TelescopeDivisor, immersiveAspect.TelescopeLerpAmount);
}
}


protected override void Ended(EntityUid uid, ImmersiveAspectComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args)
{
base.Ended(uid, component, gameRule, args);

var humans = EntityQuery<HumanoidAppearanceComponent>();

foreach (var human in humans)
{
var entity = human.Owner;

if (!HasComp<ContentEyeComponent>(entity))
continue;

SetEyeZoom(entity, 1f);

RemComp<TelescopeComponent>(entity);
}
}
}
32 changes: 32 additions & 0 deletions Content.Server/_White/AspectsSystem/Aspects/LandmineAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server._White.AspectsSystem.Aspects.Components;
using Content.Server._White.AspectsSystem.Base;
using Content.Server.GameTicking.Components;
using Robust.Shared.Random;

namespace Content.Server._White.AspectsSystem.Aspects;

public sealed class LandmineAspect : AspectSystem<LandmineAspectComponent>
{
[Dependency] private readonly IRobustRandom _random = default!;

protected override void Added(EntityUid uid, LandmineAspectComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
{
base.Added(uid, component, gameRule, args);

SpawnMines(component);
}

private void SpawnMines(LandmineAspectComponent component)
{
var minMines = _random.Next(component.Min, component.Max);

for (var i = 0; i < minMines; i++)
{
if (!TryFindRandomTile(out _, out _, out _, out var targetCoords))
break;

EntityManager.SpawnEntity("LandMineAspectExplosive", targetCoords);
}
}
}
8 changes: 8 additions & 0 deletions Content.Server/_White/AspectsSystem/Aspects/NothingAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Server._White.AspectsSystem.Aspects.Components;
using Content.Server._White.AspectsSystem.Base;

namespace Content.Server._White.AspectsSystem.Aspects;

public sealed class NothingAspect : AspectSystem<NothingAspectComponent>
{
}
32 changes: 32 additions & 0 deletions Content.Server/_White/AspectsSystem/Aspects/PresentAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server._White.AspectsSystem.Aspects.Components;
using Content.Server._White.AspectsSystem.Base;
using Content.Server.GameTicking.Components;
using Robust.Shared.Random;

namespace Content.Server._White.AspectsSystem.Aspects;

public sealed class PresentAspect : AspectSystem<PresentAspectComponent>
{
[Dependency] private readonly IRobustRandom _random = default!;

protected override void Added(EntityUid uid, PresentAspectComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
{
base.Added(uid, component, gameRule, args);

SpawnPresents(component);
}

private void SpawnPresents(PresentAspectComponent component)
{
var minPresents = _random.Next(component.Min, component.Max);

for (var i = 0; i < minPresents; i++)
{
if (!TryFindRandomTile(out _, out _, out _, out var targetCoords))
break;

EntityManager.SpawnEntity("PresentRandomUnsafe", targetCoords);
}
}
}
25 changes: 25 additions & 0 deletions Content.Server/_White/AspectsSystem/Aspects/ReflectAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server._White.AspectsSystem.Aspects.Components;
using Content.Server._White.AspectsSystem.Base;
using Content.Server._White.Other;
using Content.Server.GameTicking.Components;
using Content.Shared.Weapons.Reflect;

namespace Content.Server._White.AspectsSystem.Aspects;

public sealed class ReflectAspect : AspectSystem<ReflectAspectComponent>
{
protected override void Started(EntityUid uid, ReflectAspectComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);

var query = EntityQueryEnumerator<ReflectAspectMarkComponent>();
while (query.MoveNext(out var ent, out _))
{
var reflect = EnsureComp<ReflectComponent>(ent);
reflect.ReflectProb = 1;
reflect.Reflects = ReflectType.Energy | ReflectType.NonEnergy;
}
}

}
Loading
Loading