Files
wwdpublic/Content.Server/StationEvents/Events/RandomSentienceRule.cs
sleepyyapril 67ea5d8c3e Station AI Features and Fixes (Also General Fixes) (#1525)
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Check the changelog for the full list.

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- add: Added Holopads (unmapped)
- add: Intellicards are now useful for removing/adding a Station AI's
brain.
- add: Added the Communications Console to Station AI actions.
- add: AI now has a warp point.
- add: Added more things for the AI to press.
- add: More AI laws have been added.
- fix: Fixed the mail system
- fix: Fixed AI actions
- fix: Fixed invalid spawns for station AI breaking and ruining your
ability to play it.
- fix: The Station AI's name will now properly send in "arrived to the
station" announcements.
- fix: Changed the CPR sound to simply not loop until fixed.
- fix: Fixed unlocalized messages being sent for the random sentience
event.

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: Zachary Higgs <compgeek223@gmail.com>
Co-authored-by: MendaxxDev <153332064+MendaxxDev@users.noreply.github.com>
Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

(cherry picked from commit 3e8a7d9b00e19e160321eb81d69a884189dfa4e6)
2025-01-15 00:12:29 +03:00

89 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 class RandomSentienceRule : StationEventSystem<RandomSentienceRuleComponent>
{
[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 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) != station)
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 ? Loc.GetString(groupList[0]) : "???";
var kind2 = groupList.Count > 1 ? Loc.GetString(groupList[1]) : "???";
var kind3 = groupList.Count > 2 ? Loc.GetString(groupList[2]) : "???";
var data = _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventData"));
var strength = _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventStrength"));
data = Loc.GetString(data);
strength = Loc.GetString(strength);
ChatSystem.DispatchStationAnnouncement(
station.Value,
Loc.GetString(
"station-event-random-sentience-announcement",
("kind1", kind1),
("kind2", kind2),
("kind3", kind3),
("amount", groupList.Count),
("data", data),
("strength", strength))
);
}
}