Borg type switching. (#32586)
* Borg type switching. This allows borgs (new spawn or constructed) to select their chassis type on creation, like in SS13. This removes the need for the many different chassis types, and means round-start borgs can actually play the game immediately instead of waiting for science to unlock everything. New borgs have an additional action that allows them to select their type. This opens a nice window with basic information about the borgs and a select button. Once a type has been selected it is permanent for that borg chassis. These borg types also immediately start the borg with specific modules, so they do not need to be printed. Additional modules can still be inserted for upgrades, though this is now less critical. The built-in modules cannot be removed, but are shown in the UI. The modules that each borg type starts with: * Generic: tools * Engineering: advanced tools, construction, RCD, cable * Salvage: Grappling gun, appraisal, mining * Janitor: cleaning, light replacer * Medical: treatment * Service: music, service, clowning Specialized borgs have 3 additional module slots available on top of the ones listed above, generic borgs have 5. Borg types are specified in a new BorgTypePrototype. These prototypes specify all information about the borg type. It is assigned to the borg entity through a mix of client side, server, and shared code. Some of the involved components were made networked, others are just ensured they're set on both sides of the wire. The most gnarly change is the inventory template prototype, which needs to change purely to modify the borg hat offset. I managed to bodge this in with an API that *probably* won't explode for specifically for this use case, but it's still not the most clean of API designs. Parts for specific borg chassis have been removed (so much deleted YAML) and specialized borg modules that are in the base set of a type have been removed from the exosuit fab as there's no point to printing those. The ability to "downgrade" a borg so it can select a new chassis, like in SS13, is something that would be nice, but was not high enough priority for me to block the feature on. I did keep it in mind with some of the code, so it may be possible in the future. There is no fancy animation when selecting borg types like in SS13, because I didn't think it was high priority, and it would add a lot of complex code. * Fix sandbox failure due to collection expression. * Module tweak Fix salvage borg modules still having research/lathe recipes Engie borg has regular tool module, not advanced. * Fix inventory system breakage * Fix migrations Some things were missing * Guidebook rewordings & review * MinWidth on confirm selection button
This commit is contained in:
committed by
GitHub
parent
669bc148f9
commit
1bebb3390c
82
Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs
Normal file
82
Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Content.Server.Inventory;
|
||||
using Content.Server.Radio.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Silicons.Borgs;
|
||||
using Content.Shared.Silicons.Borgs.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Silicons.Borgs;
|
||||
|
||||
/// <summary>
|
||||
/// Server-side logic for borg type switching. Handles more heavyweight and server-specific switching logic.
|
||||
/// </summary>
|
||||
public sealed class BorgSwitchableTypeSystem : SharedBorgSwitchableTypeSystem
|
||||
{
|
||||
[Dependency] private readonly BorgSystem _borgSystem = default!;
|
||||
[Dependency] private readonly ServerInventorySystem _inventorySystem = default!;
|
||||
|
||||
protected override void SelectBorgModule(Entity<BorgSwitchableTypeComponent> ent, ProtoId<BorgTypePrototype> borgType)
|
||||
{
|
||||
var prototype = Prototypes.Index(borgType);
|
||||
|
||||
// Assign radio channels
|
||||
string[] radioChannels = [.. ent.Comp.InherentRadioChannels, .. prototype.RadioChannels];
|
||||
if (TryComp(ent, out IntrinsicRadioTransmitterComponent? transmitter))
|
||||
transmitter.Channels = [.. radioChannels];
|
||||
|
||||
if (TryComp(ent, out ActiveRadioComponent? activeRadio))
|
||||
activeRadio.Channels = [.. radioChannels];
|
||||
|
||||
// Borg transponder for the robotics console
|
||||
if (TryComp(ent, out BorgTransponderComponent? transponder))
|
||||
{
|
||||
_borgSystem.SetTransponderSprite(
|
||||
(ent.Owner, transponder),
|
||||
new SpriteSpecifier.Rsi(new ResPath("Mobs/Silicon/chassis.rsi"), prototype.SpriteBodyState));
|
||||
|
||||
_borgSystem.SetTransponderName(
|
||||
(ent.Owner, transponder),
|
||||
Loc.GetString($"borg-type-{borgType}-transponder"));
|
||||
}
|
||||
|
||||
// Configure modules
|
||||
if (TryComp(ent, out BorgChassisComponent? chassis))
|
||||
{
|
||||
var chassisEnt = (ent.Owner, chassis);
|
||||
_borgSystem.SetMaxModules(
|
||||
chassisEnt,
|
||||
prototype.ExtraModuleCount + prototype.DefaultModules.Length);
|
||||
|
||||
_borgSystem.SetModuleWhitelist(chassisEnt, prototype.ModuleWhitelist);
|
||||
|
||||
foreach (var module in prototype.DefaultModules)
|
||||
{
|
||||
var moduleEntity = Spawn(module);
|
||||
var borgModule = Comp<BorgModuleComponent>(moduleEntity);
|
||||
_borgSystem.SetBorgModuleDefault((moduleEntity, borgModule), true);
|
||||
_borgSystem.InsertModule(chassisEnt, moduleEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Configure special components
|
||||
if (Prototypes.TryIndex(ent.Comp.SelectedBorgType, out var previousPrototype))
|
||||
{
|
||||
if (previousPrototype.AddComponents is { } removeComponents)
|
||||
EntityManager.RemoveComponents(ent, removeComponents);
|
||||
}
|
||||
|
||||
if (prototype.AddComponents is { } addComponents)
|
||||
{
|
||||
EntityManager.AddComponents(ent, addComponents);
|
||||
}
|
||||
|
||||
// Configure inventory template (used for hat spacing)
|
||||
if (TryComp(ent, out InventoryComponent? inventory))
|
||||
{
|
||||
_inventorySystem.SetTemplateId((ent.Owner, inventory), prototype.InventoryTemplateId);
|
||||
}
|
||||
|
||||
base.SelectBorgModule(ent, borgType);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction.Components;
|
||||
using Content.Shared.Silicons.Borgs.Components;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Silicons.Borgs;
|
||||
@@ -300,6 +301,24 @@ public sealed partial class BorgSystem
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a module can be removed from a borg.
|
||||
/// </summary>
|
||||
/// <param name="borg">The borg that the module is being removed from.</param>
|
||||
/// <param name="module">The module to remove from the borg.</param>
|
||||
/// <param name="user">The user attempting to remove the module.</param>
|
||||
/// <returns>True if the module can be removed.</returns>
|
||||
public bool CanRemoveModule(
|
||||
Entity<BorgChassisComponent> borg,
|
||||
Entity<BorgModuleComponent> module,
|
||||
EntityUid? user = null)
|
||||
{
|
||||
if (module.Comp.DefaultModule)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs and activates all modules currently inside the borg's module container
|
||||
/// </summary>
|
||||
@@ -369,4 +388,24 @@ public sealed partial class BorgSystem
|
||||
var ev = new BorgModuleUninstalledEvent(uid);
|
||||
RaiseLocalEvent(module, ref ev);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets <see cref="BorgChassisComponent.MaxModules"/>.
|
||||
/// </summary>
|
||||
/// <param name="ent">The borg to modify.</param>
|
||||
/// <param name="maxModules">The new max module count.</param>
|
||||
public void SetMaxModules(Entity<BorgChassisComponent> ent, int maxModules)
|
||||
{
|
||||
ent.Comp.MaxModules = maxModules;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets <see cref="BorgChassisComponent.ModuleWhitelist"/>.
|
||||
/// </summary>
|
||||
/// <param name="ent">The borg to modify.</param>
|
||||
/// <param name="whitelist">The new module whitelist.</param>
|
||||
public void SetModuleWhitelist(Entity<BorgChassisComponent> ent, EntityWhitelist? whitelist)
|
||||
{
|
||||
ent.Comp.ModuleWhitelist = whitelist;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Server.DeviceNetwork;
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Explosion.Components;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Silicons.Borgs;
|
||||
|
||||
@@ -134,4 +135,20 @@ public sealed partial class BorgSystem
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets <see cref="BorgTransponderComponent.Sprite"/>.
|
||||
/// </summary>
|
||||
public void SetTransponderSprite(Entity<BorgTransponderComponent> ent, SpriteSpecifier sprite)
|
||||
{
|
||||
ent.Comp.Sprite = sprite;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets <see cref="BorgTransponderComponent.Name"/>.
|
||||
/// </summary>
|
||||
public void SetTransponderName(Entity<BorgTransponderComponent> ent, string name)
|
||||
{
|
||||
ent.Comp.Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,9 @@ public sealed partial class BorgSystem
|
||||
if (!component.ModuleContainer.Contains(module))
|
||||
return;
|
||||
|
||||
if (!CanRemoveModule((uid, component), (module, Comp<BorgModuleComponent>(module)), args.Actor))
|
||||
return;
|
||||
|
||||
_adminLog.Add(LogType.Action, LogImpact.Medium,
|
||||
$"{ToPrettyString(args.Actor):player} removed module {ToPrettyString(module)} from borg {ToPrettyString(uid)}");
|
||||
_container.Remove(module, component.ModuleContainer);
|
||||
|
||||
@@ -129,7 +129,7 @@ public sealed partial class BorgSystem : SharedBorgSystem
|
||||
|
||||
if (module != null && CanInsertModule(uid, used, component, module, args.User))
|
||||
{
|
||||
_container.Insert(used, component.ModuleContainer);
|
||||
InsertModule((uid, component), used);
|
||||
_adminLog.Add(LogType.Action, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):player} installed module {ToPrettyString(used)} into borg {ToPrettyString(uid)}");
|
||||
args.Handled = true;
|
||||
@@ -137,6 +137,19 @@ public sealed partial class BorgSystem : SharedBorgSystem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a new module into a borg, the same as if a player inserted it manually.
|
||||
/// </summary>
|
||||
/// <para>
|
||||
/// This does not run checks to see if the borg is actually allowed to be inserted, such as whitelists.
|
||||
/// </para>
|
||||
/// <param name="ent">The borg to insert into.</param>
|
||||
/// <param name="module">The module to insert.</param>
|
||||
public void InsertModule(Entity<BorgChassisComponent> ent, EntityUid module)
|
||||
{
|
||||
_container.Insert(module, ent.Comp.ModuleContainer);
|
||||
}
|
||||
|
||||
// todo: consider transferring over the ghost role? managing that might suck.
|
||||
protected override void OnInserted(EntityUid uid, BorgChassisComponent component, EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user