CatStation/Content.Server/Implants/ChameleonControllerSystem.cs
Princess Cheeseballs 2c6ffecf62
Move GameTicker to Shared (#45834)
* 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
2026-09-16 19:34:19 +00:00

149 lines
6.3 KiB
C#

using Content.Server.Clothing.Systems;
using Content.Server.Preferences.Managers;
using Content.Shared.Clothing;
using Content.Shared.Clothing.Components;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
using Content.Shared.Inventory;
using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts;
using Content.Shared.Roles;
using Content.Shared.Station.Systems;
using Content.Shared.Timing.Systems;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.Implants;
public sealed partial class ChameleonControllerSystem : SharedChameleonControllerSystem
{
[Dependency] private InventorySystem _inventory = default!;
[Dependency] private StationSpawningSystem _stationSpawningSystem = default!;
[Dependency] private ChameleonClothingSystem _chameleonClothingSystem = default!;
[Dependency] private IServerPreferencesManager _preferences = default!;
[Dependency] private UseDelaySystem _delay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ChameleonControllerImplantComponent, ChameleonControllerSelectedOutfitMessage>(OnSelected);
SubscribeLocalEvent<ChameleonClothingComponent, InventoryRelayedEvent<ChameleonControllerOutfitSelectedEvent>>(ChameleonControllerOutfitItemSelected);
}
private void OnSelected(Entity<ChameleonControllerImplantComponent> ent, ref ChameleonControllerSelectedOutfitMessage args)
{
if (!TryComp<SubdermalImplantComponent>(ent, out var implantComp) || implantComp.ImplantedEntity == null || !_delay.TryResetDelay(ent.Owner, true))
return;
ChangeChameleonClothingToOutfit(implantComp.ImplantedEntity.Value, args.SelectedChameleonOutfit);
}
/// <summary>
/// Switches all the chameleon clothing that the implant user is wearing to look like the selected job.
/// </summary>
private void ChangeChameleonClothingToOutfit(EntityUid user, ProtoId<ChameleonOutfitPrototype> outfit)
{
var outfitPrototype = ProtoMan.Index(outfit);
ProtoMan.Resolve(outfitPrototype.Job, out var jobPrototype);
ProtoMan.Resolve(outfitPrototype.StartingGear, out var startingGearPrototype);
GetJobEquipmentInformation(jobPrototype, user, out var customRoleLoadout, out var defaultRoleLoadout, out var jobStartingGearPrototype);
var ev = new ChameleonControllerOutfitSelectedEvent(
outfitPrototype,
customRoleLoadout,
defaultRoleLoadout,
jobStartingGearPrototype,
startingGearPrototype
);
RaiseLocalEvent(user, ref ev);
}
// This gets as much information from the job as it can.
// E.g. the players profile, the default equipment for that job etc...
private void GetJobEquipmentInformation(
JobPrototype? jobPrototype,
EntityUid? user,
out RoleLoadout? customRoleLoadout,
out RoleLoadout? defaultRoleLoadout,
out StartingGearPrototype? jobStartingGearPrototype)
{
customRoleLoadout = null;
defaultRoleLoadout = null;
jobStartingGearPrototype = null;
if (jobPrototype == null)
return;
ProtoMan.Resolve(jobPrototype.StartingGear, out jobStartingGearPrototype);
if (!TryComp<ActorComponent>(user, out var actorComponent))
return;
var userId = actorComponent.PlayerSession.UserId;
var prefs = _preferences.GetPreferences(userId);
if (prefs.SelectedCharacter is not HumanoidCharacterProfile profile)
return;
var jobProtoId = LoadoutSystem.GetJobPrototype(jobPrototype.ID);
profile.Loadouts.TryGetValue(jobProtoId, out customRoleLoadout);
if (!ProtoMan.HasIndex<RoleLoadoutPrototype>(jobProtoId))
return;
defaultRoleLoadout = new RoleLoadout(jobProtoId);
defaultRoleLoadout.SetDefault(profile, null, ProtoMan); // only sets the default if the player has no loadout
}
private void ChameleonControllerOutfitItemSelected(Entity<ChameleonClothingComponent> ent, ref InventoryRelayedEvent<ChameleonControllerOutfitSelectedEvent> args)
{
if (!ent.Comp.CanBeSetByController || !_inventory.TryGetContainingSlot(ent.Owner, out var slot))
return;
_chameleonClothingSystem.SetSelectedPrototype(ent, GetGearForSlot(args, slot.Name), component: ent.Comp);
}
public string? GetGearForSlot(InventoryRelayedEvent<ChameleonControllerOutfitSelectedEvent> ev, string slotName)
{
return GetGearForSlot(ev.Args.ChameleonOutfit, ev.Args.CustomRoleLoadout, ev.Args.DefaultRoleLoadout, ev.Args.JobStartingGearPrototype, ev.Args.StartingGearPrototype, slotName);
}
/// <summary>
/// Get the gear for the given slot. The priority is:
/// <br/>1.) Custom loadout from the player for the slot.
/// <br/>2.) Chameleon outfit slot equipment.
/// <br/>3.) Chameleon outfit starting gear equipment.
/// <br/>4.) Default job equipment.
/// <br/>5.) Staring equipment for that job.
/// </summary>
/// <returns>The entity (as a protoid) if there is gear for that slot, null if there isn't.</returns>
public string? GetGearForSlot(ChameleonOutfitPrototype? chameleonOutfitPrototype, RoleLoadout? customRoleLoadout, RoleLoadout? defaultRoleLoadout, StartingGearPrototype? jobStartingGearPrototype, StartingGearPrototype? startingGearPrototype, string slotName)
{
var customLoadoutGear = _stationSpawningSystem.GetGearForSlot(customRoleLoadout, slotName);
if (customLoadoutGear != null)
return customLoadoutGear;
if (chameleonOutfitPrototype != null && chameleonOutfitPrototype.Equipment.TryGetValue(slotName, out var forSlot))
return forSlot;
var startingGear = startingGearPrototype != null ? ((IEquipmentLoadout)startingGearPrototype).GetGear(slotName) : "";
if (startingGear != "")
return startingGear;
var defaultLoadoutGear = _stationSpawningSystem.GetGearForSlot(defaultRoleLoadout, slotName);
if (defaultLoadoutGear != null)
return defaultLoadoutGear;
var jobStartingGear = jobStartingGearPrototype != null ? ((IEquipmentLoadout)jobStartingGearPrototype).GetGear(slotName) : "";
if (jobStartingGear != "")
return jobStartingGear;
return null;
}
}