2022-02-25 23:10:09 -06:00
|
|
|
|
using System.Linq;
|
2023-04-25 20:23:14 -04:00
|
|
|
|
using Content.Server.GameTicking.Rules.Components;
|
2022-02-25 23:40:15 -06:00
|
|
|
|
using Content.Server.Ghost.Roles.Components;
|
2022-02-25 23:10:09 -06:00
|
|
|
|
using Content.Server.StationEvents.Components;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
|
public sealed class RandomSentienceRule : StationEventSystem<RandomSentienceRuleComponent>
|
2022-02-25 23:10:09 -06:00
|
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
|
protected override void Started(EntityUid uid, RandomSentienceRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
2022-02-25 23:10:09 -06:00
|
|
|
|
{
|
2022-06-03 21:37:35 +10:00
|
|
|
|
HashSet<EntityUid> stationsToNotify = new();
|
2022-02-25 23:10:09 -06:00
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
|
var targetList = new List<Entity<SentienceTargetComponent>>();
|
|
|
|
|
|
var query = EntityQueryEnumerator<SentienceTargetComponent>();
|
|
|
|
|
|
while (query.MoveNext(out var targetUid, out var target))
|
|
|
|
|
|
{
|
|
|
|
|
|
targetList.Add((targetUid, target));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-10 18:48:41 -07:00
|
|
|
|
RobustRandom.Shuffle(targetList);
|
2022-02-25 23:10:09 -06:00
|
|
|
|
|
2024-02-25 15:04:51 -07:00
|
|
|
|
var toMakeSentient = RobustRandom.Next(2, 5);
|
2022-02-25 23:10:09 -06:00
|
|
|
|
var groups = new HashSet<string>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var target in targetList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (toMakeSentient-- == 0)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
|
RemComp<SentienceTargetComponent>(target);
|
|
|
|
|
|
var ghostRole = EnsureComp<GhostRoleComponent>(target);
|
|
|
|
|
|
EnsureComp<GhostTakeoverAvailableComponent>(target);
|
|
|
|
|
|
ghostRole.RoleName = MetaData(target).EntityName;
|
2023-04-12 06:32:14 -07:00
|
|
|
|
ghostRole.RoleDescription = Loc.GetString("station-event-random-sentience-role-description", ("name", ghostRole.RoleName));
|
2023-10-19 12:34:31 -07:00
|
|
|
|
groups.Add(Loc.GetString(target.Comp.FlavorKind));
|
2022-02-25 23:10:09 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (groups.Count == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
var groupList = groups.ToList();
|
|
|
|
|
|
var kind1 = groupList.Count > 0 ? groupList[0] : "???";
|
|
|
|
|
|
var kind2 = groupList.Count > 1 ? groupList[1] : "???";
|
|
|
|
|
|
var kind3 = groupList.Count > 2 ? groupList[2] : "???";
|
2022-06-03 21:37:35 +10:00
|
|
|
|
|
|
|
|
|
|
foreach (var target in targetList)
|
|
|
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
|
var station = StationSystem.GetOwningStation(target);
|
|
|
|
|
|
if(station == null)
|
|
|
|
|
|
continue;
|
2022-06-03 21:37:35 +10:00
|
|
|
|
stationsToNotify.Add((EntityUid) station);
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var station in stationsToNotify)
|
|
|
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
|
ChatSystem.DispatchStationAnnouncement(
|
2023-01-19 03:56:45 +01:00
|
|
|
|
station,
|
2022-06-03 21:37:35 +10:00
|
|
|
|
Loc.GetString("station-event-random-sentience-announcement",
|
|
|
|
|
|
("kind1", kind1), ("kind2", kind2), ("kind3", kind3), ("amount", groupList.Count),
|
2022-07-10 18:48:41 -07:00
|
|
|
|
("data", Loc.GetString($"random-sentience-event-data-{RobustRandom.Next(1, 6)}")),
|
|
|
|
|
|
("strength", Loc.GetString($"random-sentience-event-strength-{RobustRandom.Next(1, 8)}"))),
|
2022-05-08 15:07:59 +10:00
|
|
|
|
playDefaultSound: false,
|
2022-04-10 13:54:07 -07:00
|
|
|
|
colorOverride: Color.Gold
|
2022-06-03 21:37:35 +10:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2022-02-25 23:10:09 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|