mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-11 03:11:14 +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
86 lines
3.7 KiB
C#
86 lines
3.7 KiB
C#
using System.Linq;
|
|
using Content.Shared.Dataset;
|
|
using Content.Server.Ghost.Roles.Components;
|
|
using Content.Server.StationEvents.Components;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.Random.Helpers;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
public sealed partial class RandomSentienceRule : StationEventSystem<RandomSentienceRuleComponent>
|
|
{
|
|
private static readonly ProtoId<LocalizedDatasetPrototype> DataSourceNames = "RandomSentienceEventData";
|
|
private static readonly ProtoId<LocalizedDatasetPrototype> IntelligenceLevelNames = "RandomSentienceEventStrength";
|
|
|
|
[Dependency] private IPrototypeManager _prototype = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
|
|
protected override void Started(EntityUid uid, RandomSentienceRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
|
{
|
|
if (!Station.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 (Station.GetOwningStation(targetUid, xform) != station.Value.Owner)
|
|
continue;
|
|
|
|
targetList.Add((targetUid, target));
|
|
}
|
|
|
|
var toMakeSentient = _random.Next(component.MinSentiences, component.MaxSentiences);
|
|
|
|
var groups = new HashSet<string>();
|
|
|
|
for (var i = 0; i < toMakeSentient && targetList.Count > 0; i++)
|
|
{
|
|
// weighted random to pick a sentience target
|
|
var totalWeight = targetList.Sum(x => x.Comp.Weight);
|
|
// This initial target should never be picked.
|
|
// It's just so that target doesn't need to be nullable and as a safety fallback for id floating point errors ever mess up the comparison in the foreach.
|
|
var target = targetList[0];
|
|
var chosenWeight = _random.NextFloat(totalWeight);
|
|
var currentWeight = 0.0;
|
|
foreach (var potentialTarget in targetList)
|
|
{
|
|
currentWeight += potentialTarget.Comp.Weight;
|
|
if (currentWeight > chosenWeight)
|
|
{
|
|
target = potentialTarget;
|
|
break;
|
|
}
|
|
}
|
|
targetList.Remove(target);
|
|
|
|
RemComp<SentienceTargetComponent>(target);
|
|
var ghostRole = EnsureComp<GhostRoleComponent>(target);
|
|
EnsureComp<GhostTakeoverAvailableComponent>(target);
|
|
ghostRole.RoleName = MetaData(target).EntityName;
|
|
ghostRole.RoleDescription = Loc.GetString("station-event-random-sentience-role-description", ("name", ghostRole.RoleName));
|
|
groups.Add(Loc.GetString(target.Comp.FlavorKind));
|
|
}
|
|
|
|
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] : "???";
|
|
|
|
ChatSystem.DispatchStationAnnouncement(
|
|
station.Value,
|
|
Loc.GetString("station-event-random-sentience-announcement",
|
|
("kind1", kind1), ("kind2", kind2), ("kind3", kind3), ("amount", groupList.Count),
|
|
("data", _random.Pick(_prototype.Index(DataSourceNames))),
|
|
("strength", _random.Pick(_prototype.Index(IntelligenceLevelNames)))
|
|
),
|
|
playDefaultSound: false,
|
|
colorOverride: Color.Gold
|
|
);
|
|
}
|
|
}
|