Skip to content

Commit

Permalink
fix sentienceRule
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril committed Jan 11, 2025
1 parent 736f70b commit a8b6657
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions Content.Server/StationEvents/Events/RandomSentienceRule.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Content.Server.Announcements.Systems;
using System.Linq;
using Content.Shared.Dataset;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Components;
using Content.Shared.GameTicking.Components;
using Content.Shared.Random.Helpers;
Expand All @@ -13,27 +11,25 @@ namespace Content.Server.StationEvents.Events;

public sealed class RandomSentienceRule : StationEventSystem<RandomSentienceRuleComponent>
{
[Dependency] private readonly AnnouncerSystem _announcer = default!;

[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
protected override void Started(EntityUid uid, RandomSentienceRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
if (!TryGetRandomStation(out var randomStation))
if (!TryGetRandomStation(out var station))
return;

var targetList = new List<Entity<SentienceTargetComponent>>();
var query = EntityQueryEnumerator<SentienceTargetComponent, TransformComponent>();
while (query.MoveNext(out var targetUid, out var target, out var xform))
{
if (StationSystem.GetOwningStation(targetUid, xform) != randomStation)
if (StationSystem.GetOwningStation(targetUid, xform) != station)
continue;

targetList.Add((targetUid, target));
}

var toMakeSentient = _random.Next(component.MinSentiences, component.MaxSentiences);
var stationsToNotify = new List<EntityUid>();

var groups = new HashSet<string>();

for (var i = 0; i < toMakeSentient && targetList.Count > 0; i++)
Expand Down Expand Up @@ -72,27 +68,12 @@ protected override void Started(EntityUid uid, RandomSentienceRuleComponent comp
var kind2 = groupList.Count > 1 ? groupList[1] : "???";
var kind3 = groupList.Count > 2 ? groupList[2] : "???";

foreach (var target in targetList)
{
var targetStation = StationSystem.GetOwningStation(target);
if(targetStation == null)
continue;
stationsToNotify.Add((EntityUid) targetStation);
}
foreach (var station in stationsToNotify)
{
_announcer.SendAnnouncement(
_announcer.GetAnnouncementId(args.RuleId),
StationSystem.GetInStation(EntityManager.GetComponent<StationDataComponent>(station)),
"station-event-random-sentience-announcement",
null,
Color.Gold,
null,
null,
ChatSystem.DispatchStationAnnouncement(
station.Value,
_announcer.GetAnnouncementId(args.RuleId),
("kind1", kind1), ("kind2", kind2), ("kind3", kind3), ("amount", groupList.Count),
("data", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventData"))),
("strength", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventStrength")))
);
}
("data", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventData"))),
("strength", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventStrength")))
);
}
}
}

0 comments on commit a8b6657

Please sign in to comment.