Files
OldThink/Content.Server/Implants/SubdermalImplantSystem.cs

290 lines
11 KiB
C#
Raw Permalink Normal View History

2023-03-13 19:34:26 -04:00
using Content.Server.Cuffs;
using Content.Server.Forensics;
2023-08-13 12:56:21 -04:00
using Content.Server.Humanoid;
using Content.Server.Implants.Components;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
2023-03-13 19:34:26 -04:00
using Content.Shared.Cuffs.Components;
2023-08-13 12:56:21 -04:00
using Content.Shared.Humanoid;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
using Content.Shared.Interaction;
using Content.Shared.Physics;
using Content.Shared.Popups;
2023-08-13 12:56:21 -04:00
using Content.Shared.Preferences;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Random;
using System.Numerics;
using Content.Server.IdentityManagement;
2024-07-31 20:36:59 +03:00
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Pulling.Systems;
using Robust.Shared.Collections;
2024-07-31 20:36:59 +03:00
using Robust.Shared.Enums;
using Robust.Shared.GameObjects.Components.Localization;
using Robust.Shared.Map.Components;
2024-12-01 20:39:26 +03:00
using Content.Server.Ensnaring;
using Content.Shared.Ensnaring.Components;
using System.Linq;
2024-08-24 14:25:47 +03:00
using GrammarSystem = Content.Shared._Amour.GrammarSystem.GrammarSystem;
namespace Content.Server.Implants;
public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
{
2023-03-13 19:34:26 -04:00
[Dependency] private readonly CuffableSystem _cuffable = default!;
2023-08-13 12:56:21 -04:00
[Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearance = default!;
[Dependency] private readonly IRobustRandom _random = default!;
2023-08-13 12:56:21 -04:00
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly StoreSystem _store = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
2023-06-07 15:53:11 +12:00
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedTransformSystem _xform = default!;
[Dependency] private readonly ForensicsSystem _forensicsSystem = default!;
[Dependency] private readonly PullingSystem _pullingSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly IdentitySystem _identity = default!; // WD
2024-12-01 20:39:26 +03:00
[Dependency] private readonly EnsnareableSystem _ensnareable = default!; // WD
[Dependency] private readonly GrammarSystem _grammar = default!; // Amour
private EntityQuery<PhysicsComponent> _physicsQuery;
private HashSet<Entity<MapGridComponent>> _targetGrids = [];
public override void Initialize()
{
base.Initialize();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
SubscribeLocalEvent<SubdermalImplantComponent, UseFreedomImplantEvent>(OnFreedomImplant);
2023-06-07 15:53:11 +12:00
SubscribeLocalEvent<StoreComponent, ImplantRelayEvent<AfterInteractUsingEvent>>(OnStoreRelay);
SubscribeLocalEvent<SubdermalImplantComponent, ActivateImplantEvent>(OnActivateImplantEvent);
SubscribeLocalEvent<SubdermalImplantComponent, UseScramImplantEvent>(OnScramImplant);
SubscribeLocalEvent<SubdermalImplantComponent, UseDnaScramblerImplantEvent>(OnDnaScramblerImplant);
2024-07-31 20:36:59 +03:00
SubscribeLocalEvent<SubdermalImplantComponent, UseGenderSwapImplantEvent>(OnGenderSwapImplant); //Amour
}
2023-06-07 15:53:11 +12:00
private void OnStoreRelay(EntityUid uid, StoreComponent store, ImplantRelayEvent<AfterInteractUsingEvent> implantRelay)
{
2023-06-07 15:53:11 +12:00
var args = implantRelay.Event;
2023-06-07 15:53:11 +12:00
if (args.Handled)
return;
// can only insert into yourself to prevent uplink checking with renault
if (args.Target != args.User)
return;
if (!TryComp<CurrencyComponent>(args.Used, out var currency))
return;
// same as store code, but message is only shown to yourself
Upstream gp (#149) * fix borg (#719) * Automatic changelog update * Переводы снаряжения и прочей мелочи в стартовом меню (#720) * Сумки, мешки и прочее * Перевод снаряжения * перевод черт персонажа * Добавлено ничего * Automatic changelog update * Фикс отображения потери мастера для импланта подчинения (#721) * фикс отображения * brain damage is real * я блять запустил райдер ради рефактора одного ифа * а лучше даже так * Automatic changelog update * add coderabbitai config (#722) * fix (#723) * Шприц теперь является оружием массового поражения (#724) * Automatic changelog update * Пиздец (#725) Я на это потратил 2 недели * Automatic changelog update * Honk FM (#136) (#726) * Fix Cosmic Temperance и новые песенки в jukebox * Новая музыка в jucebox x2 Co-authored-by: Vorge7 <vorge228@gmail.com> * Automatic changelog update * Флаф (fluff) мне (big_zi_348) (#727) * Заработал * brain damage * fuck (#729) * Automatic changelog update * FUCKERS (#732) * Удаление ненужных суффиксов (#731) * Перевод захардкукоженной строки (#728) * Пластырь поможет * очапятка * Перевод ревенанта * Карповый перекат * Create shakeable-component.ftl * Криогеника * Хранилища скафандров * Update autotranslate-14.ftl * Update Cyborgs.xml * Комоды * Кредиты * Удалил дубликат * Информация * Пластырь миму и клоуну * Переводы всего * Перевод аплинка * Удалил ненужные суффиксы * Revert "Удалил ненужные суффиксы" This reverts commit d82f05f30c37ec2c11e5736b91239fe9dd1a4d17. * Удаление ненужных суффиксов * Перевод реагентовых слизней * Перевод аномалий * Перевод маяков * Перевод различной мелочи * Automatic changelog update * Переводы и правки Гайдов (#730) * Automatic changelog update * aaaaa (#733) * Правка локализации (#737) * Update ThirstSystem.cs (#736) * AccessConfiguratorForBorgs (#735) * Automatic changelog update * Починил бесконечную сварку (#734) * Automatic changelog update * ShowManifestFeature (#738) * Automatic changelog update * I LOVE OPENSOURCE * Изменение размеров милишек (#739) * Фикс размеров * Заготовку биты тоже * Правка * Automatic changelog update * Время после взрыва нюки (#740) * More Fun * Автоформатирование * Подкрутка * Automatic changelog update * Скальпель в армейские ботинки (#741) * Automatic changelog update * DoHeavyAttack stamina check (#742) * Automatic changelog update * aaaaaaaaaaaaaaaaaaaaaaaaaaaaa (#743) * fix retarded code (#744) * Automatic changelog update --------- Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru> Co-authored-by: BIGZi0348 <118811750+BIGZi0348@users.noreply.github.com> Co-authored-by: ThereDrD <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Vorge7 <vorge228@gmail.com> Co-authored-by: Valtos <valtos@spaces.ru> Co-authored-by: haiwwkes <49613070+rhailrake@users.noreply.github.com>
2024-10-24 21:36:52 +03:00
if (!_store.TryAddCurrency((args.Used, currency), (uid, store)))
return;
Upstream gp (#149) * fix borg (#719) * Automatic changelog update * Переводы снаряжения и прочей мелочи в стартовом меню (#720) * Сумки, мешки и прочее * Перевод снаряжения * перевод черт персонажа * Добавлено ничего * Automatic changelog update * Фикс отображения потери мастера для импланта подчинения (#721) * фикс отображения * brain damage is real * я блять запустил райдер ради рефактора одного ифа * а лучше даже так * Automatic changelog update * add coderabbitai config (#722) * fix (#723) * Шприц теперь является оружием массового поражения (#724) * Automatic changelog update * Пиздец (#725) Я на это потратил 2 недели * Automatic changelog update * Honk FM (#136) (#726) * Fix Cosmic Temperance и новые песенки в jukebox * Новая музыка в jucebox x2 Co-authored-by: Vorge7 <vorge228@gmail.com> * Automatic changelog update * Флаф (fluff) мне (big_zi_348) (#727) * Заработал * brain damage * fuck (#729) * Automatic changelog update * FUCKERS (#732) * Удаление ненужных суффиксов (#731) * Перевод захардкукоженной строки (#728) * Пластырь поможет * очапятка * Перевод ревенанта * Карповый перекат * Create shakeable-component.ftl * Криогеника * Хранилища скафандров * Update autotranslate-14.ftl * Update Cyborgs.xml * Комоды * Кредиты * Удалил дубликат * Информация * Пластырь миму и клоуну * Переводы всего * Перевод аплинка * Удалил ненужные суффиксы * Revert "Удалил ненужные суффиксы" This reverts commit d82f05f30c37ec2c11e5736b91239fe9dd1a4d17. * Удаление ненужных суффиксов * Перевод реагентовых слизней * Перевод аномалий * Перевод маяков * Перевод различной мелочи * Automatic changelog update * Переводы и правки Гайдов (#730) * Automatic changelog update * aaaaa (#733) * Правка локализации (#737) * Update ThirstSystem.cs (#736) * AccessConfiguratorForBorgs (#735) * Automatic changelog update * Починил бесконечную сварку (#734) * Automatic changelog update * ShowManifestFeature (#738) * Automatic changelog update * I LOVE OPENSOURCE * Изменение размеров милишек (#739) * Фикс размеров * Заготовку биты тоже * Правка * Automatic changelog update * Время после взрыва нюки (#740) * More Fun * Автоформатирование * Подкрутка * Automatic changelog update * Скальпель в армейские ботинки (#741) * Automatic changelog update * DoHeavyAttack stamina check (#742) * Automatic changelog update * aaaaaaaaaaaaaaaaaaaaaaaaaaaaa (#743) * fix retarded code (#744) * Automatic changelog update --------- Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru> Co-authored-by: BIGZi0348 <118811750+BIGZi0348@users.noreply.github.com> Co-authored-by: ThereDrD <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Vorge7 <vorge228@gmail.com> Co-authored-by: Valtos <valtos@spaces.ru> Co-authored-by: haiwwkes <49613070+rhailrake@users.noreply.github.com>
2024-10-24 21:36:52 +03:00
args.Handled = true;
var msg = Loc.GetString("store-currency-inserted-implant", ("used", args.Used));
_popup.PopupEntity(msg, args.User, args.User);
}
2023-06-07 15:53:11 +12:00
private void OnFreedomImplant(EntityUid uid, SubdermalImplantComponent component, UseFreedomImplantEvent args)
{
2024-12-01 20:39:26 +03:00
// WD EDIT START
var ensnareCheck = TryComp<EnsnareableComponent>(component.ImplantedEntity, out var ensnareable) && ensnareable.Container.ContainedEntities.Count > 0;
if (ensnareCheck && ensnareable != null)
{
var ensnaringUid = ensnareable.Container.ContainedEntities.First();
if (TryComp<EnsnaringComponent>(ensnaringUid, out var ensnaringComp))
_ensnareable.ForceFree(ensnaringUid, ensnaringComp);
}
2024-12-01 20:39:26 +03:00
var cuffCheck = TryComp<CuffableComponent>(component.ImplantedEntity, out var cuffs) && cuffs.Container.ContainedEntities.Count > 0;
if (cuffCheck && cuffs != null && component.ImplantedEntity != null)
{
_cuffable.Uncuff(component.ImplantedEntity.Value, cuffs.LastAddedCuffs, cuffs.LastAddedCuffs);
}
if (ensnareCheck || cuffCheck)
{
args.Handled = true;
}
// WD EDIT END
}
private void OnActivateImplantEvent(EntityUid uid, SubdermalImplantComponent component, ActivateImplantEvent args)
{
args.Handled = true;
}
private void OnScramImplant(EntityUid uid, SubdermalImplantComponent component, UseScramImplantEvent args)
{
if (component.ImplantedEntity is not { } ent)
return;
if (!TryComp<ScramImplantComponent>(uid, out var implant))
return;
// We need stop the user from being pulled so they don't just get "attached" with whoever is pulling them.
// This can for example happen when the user is cuffed and being pulled.
if (TryComp<PullableComponent>(ent, out var pull) && _pullingSystem.IsPulled(ent, pull))
_pullingSystem.TryStopPull(ent, pull);
var xform = Transform(ent);
var targetCoords = SelectRandomTileInRange(xform, implant.TeleportRadius);
if (targetCoords != null)
{
_xform.SetCoordinates(ent, targetCoords.Value);
_audio.PlayPvs(implant.TeleportSound, ent);
args.Handled = true;
}
}
private EntityCoordinates? SelectRandomTileInRange(TransformComponent userXform, float radius)
{
var userCoords = userXform.Coordinates.ToMap(EntityManager, _xform);
_targetGrids.Clear();
_lookupSystem.GetEntitiesInRange(userCoords, radius, _targetGrids);
Entity<MapGridComponent>? targetGrid = null;
if (_targetGrids.Count == 0)
return null;
// Give preference to the grid the entity is currently on.
// This does not guarantee that if the probability fails that the owner's grid won't be picked.
// In reality the probability is higher and depends on the number of grids.
if (userXform.GridUid != null && TryComp<MapGridComponent>(userXform.GridUid, out var gridComp))
{
var userGrid = new Entity<MapGridComponent>(userXform.GridUid.Value, gridComp);
if (_random.Prob(0.5f))
{
_targetGrids.Remove(userGrid);
targetGrid = userGrid;
}
}
if (targetGrid == null)
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);
EntityCoordinates? targetCoords = null;
do
{
var valid = false;
var range = (float) Math.Sqrt(radius);
var box = Box2.CenteredAround(userCoords.Position, new Vector2(range, range));
var tilesInRange = _mapSystem.GetTilesEnumerator(targetGrid.Value.Owner, targetGrid.Value.Comp, box, false);
var tileList = new ValueList<Vector2i>();
while (tilesInRange.MoveNext(out var tile))
{
tileList.Add(tile.GridIndices);
}
while (tileList.Count != 0)
{
var tile = tileList.RemoveSwap(_random.Next(tileList.Count));
valid = true;
foreach (var entity in _mapSystem.GetAnchoredEntities(targetGrid.Value.Owner, targetGrid.Value.Comp,
tile))
{
if (!_physicsQuery.TryGetComponent(entity, out var body))
continue;
if (body.BodyType != BodyType.Static ||
!body.Hard ||
(body.CollisionLayer & (int) CollisionGroup.MobMask) == 0)
continue;
valid = false;
break;
}
if (valid)
{
targetCoords = new EntityCoordinates(targetGrid.Value.Owner,
_mapSystem.TileCenterToVector(targetGrid.Value, tile));
break;
}
}
if (valid || _targetGrids.Count == 0) // if we don't do the check here then PickAndTake will blow up on an empty set.
break;
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);
} while (true);
return targetCoords;
}
private void OnDnaScramblerImplant(EntityUid uid, SubdermalImplantComponent component, UseDnaScramblerImplantEvent args)
{
2023-08-13 12:56:21 -04:00
if (component.ImplantedEntity is not { } ent)
return;
2023-08-13 12:56:21 -04:00
if (TryComp<HumanoidAppearanceComponent>(ent, out var humanoid))
{
2023-08-13 12:56:21 -04:00
var newProfile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species);
_humanoidAppearance.LoadProfile(ent, newProfile, humanoid);
_metaData.SetEntityName(ent, newProfile.Name);
_identity.QueueIdentityUpdate(ent); // WD
if (TryComp<DnaComponent>(ent, out var dna))
{
dna.DNA = _forensicsSystem.GenerateDNA();
}
if (TryComp<FingerprintComponent>(ent, out var fingerprint))
{
fingerprint.Fingerprint = _forensicsSystem.GenerateFingerprint();
}
2023-08-13 12:56:21 -04:00
_popup.PopupEntity(Loc.GetString("scramble-implant-activated-popup"), ent, ent);
}
args.Handled = true;
QueueDel(uid);
}
2024-07-31 20:36:59 +03:00
// Amour Start
2024-07-31 20:36:59 +03:00
private void OnGenderSwapImplant(EntityUid uid, SubdermalImplantComponent component, UseGenderSwapImplantEvent args)
{
if (component.ImplantedEntity is not { } ent)
return;
if (TryComp<HumanoidAppearanceComponent>(ent, out var humanoid) && humanoid.Sex != Sex.Unsexed)
{
var newSex = humanoid.Sex;
if (humanoid.Sex == Sex.Male)
newSex = Sex.Female;
else
newSex = Sex.Male;
_humanoidAppearance.SetSex(ent, newSex);
}
if (TryComp<GrammarComponent>(ent, out var grammar) &&
(grammar.Gender != Gender.Neuter || grammar.Gender != Gender.Epicene))
{
var newGender = grammar.Gender;
if (grammar.Gender == Gender.Male)
newGender = Gender.Female;
else
newGender = Gender.Male;
_grammar.SetGender((ent, grammar), newGender);
if (HasComp<IdentityComponent>(ent))
_identity.QueueIdentityUpdate(ent);
}
args.Handled = true;
QueueDel(uid);
}
// Amour End
}