* Revert "- fix: YAML linter fixes. (#598)" This reverts commit012bf3c357. * Revert "Automatic changelog update" This reverts commitcf1c3a9af5. * Revert "[Fix] Base Layer Prototype (#597)" This reverts commitb000423999. * Revert "Modules update (#596)" This reverts commit00fbdead77. * Revert "Automatic changelog update" This reverts commit0d7a12b2a2. * Revert "Fixes (#593)" This reverts commit943c77031c. * Revert "minor loadout fixes (#594)" This reverts commit143c010a89. * Revert "Update DryDock.yml (#595)" This reverts commit4cd0100ac7. * Revert "Automatic changelog update" This reverts commit08eadc690f. * Revert "fix: Maximum message size (#591)" This reverts commit343f3612eb. * Revert "Черри пики 7 (#592)" This reverts commit3f97bdce2f. * Revert "Automatic changelog update" This reverts commit0678eca250. * Revert "Рандомфиксы (#590)" This reverts commit2b9e5e2437. * Revert "Нижнее бельё в лодауты (#580)" This reverts commite01a47b089. * Revert "add lathe sounds (#588)" This reverts commitc80a2985f2. * Revert "Добавил параметр группы для некоторых реагентов (#585)" This reverts commit713b16bb98. * Revert "add hrp ++++ aspect (#587)" This reverts commita6a69cc60f. * Revert "Новые амбиенты и пару песен (#586)" This reverts commit48c86bd846. * Revert "Сообщения в ПДА 2 (#583)" This reverts commitcced3cc98b. * Revert "Automatic changelog update" This reverts commitabf435b11d. * Revert "Chem stuff and more (#584)" This reverts commit3608960f5c. * Revert "JobRequiremet refactor (#579)" This reverts commit9a9c9598e0. * Revert "Revert "Reapply "Нижнее бельё в лодауты""" This reverts commit44447d573f. * Revert "Reapply "Нижнее бельё в лодауты"" This reverts commit0c4d082ad3. * Revert "Revert "Нижнее бельё в лодауты"" This reverts commit56473c5492. * Revert "Нижнее бельё в лодауты" This reverts commitd1cb0cb364. * Revert "DryDock and WhiteMoose update (#578)" This reverts commit14755808af. * Revert "Automatic changelog update" This reverts commit0133f82722. * Revert "Fixes (#576)" This reverts commitb7cc49896c. * Revert "порт системы регенерации солюшена цинки (#574)" This reverts commita22cf3d50b. * Revert "Воровские перчатки (#573)" This reverts commitbb7140f3d4. * Revert "mood resprite (#572)" This reverts commit4db96dc569. * Revert "fix missing letter (#571)" This reverts commit94ea756794. * Revert "Сообщения в ПДА (#564)" This reverts commitd023d29e54. * Revert "- fix: No visible aghost." This reverts commit27e7f25f7e. * Revert "- tweak: Nerf cult shield." This reverts commit6a384246b8.
277 lines
11 KiB
C#
277 lines
11 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Shared._White.Telescope;
|
|
using Content.Shared._White.WeaponModules;
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
using Content.Shared.Weapons.Ranged.Systems;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Server._White.WeaponModules;
|
|
|
|
public sealed class WeaponModulesSystem : EntitySystem
|
|
{
|
|
protected static readonly Dictionary<string, Enum> Slots = new()
|
|
{
|
|
{ "handguard_module", ModuleVisualState.HandGuardModule }, { "barrel_module", ModuleVisualState.BarrelModule }, { "aim_module", ModuleVisualState.AimModule }, { "shutter_module", ModuleVisualState.ShutterModule }
|
|
};
|
|
|
|
[Dependency] private readonly PointLightSystem _lightSystem = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
|
[Dependency] private readonly SharedGunSystem _gunSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<LightModuleComponent, EntGotInsertedIntoContainerMessage>(LightModuleOnInsert);
|
|
SubscribeLocalEvent<LightModuleComponent, EntGotRemovedFromContainerMessage>(LightModuleOnEject);
|
|
|
|
SubscribeLocalEvent<LaserModuleComponent, EntGotInsertedIntoContainerMessage>(LaserModuleOnInsert);
|
|
SubscribeLocalEvent<LaserModuleComponent, EntGotRemovedFromContainerMessage>(LaserModuleOnEject);
|
|
|
|
SubscribeLocalEvent<FlameHiderModuleComponent, EntGotInsertedIntoContainerMessage>(FlameHiderModuleOnInsert);
|
|
SubscribeLocalEvent<FlameHiderModuleComponent, EntGotRemovedFromContainerMessage>(FlameHiderModuleOnEject);
|
|
|
|
SubscribeLocalEvent<SilencerModuleComponent, EntGotInsertedIntoContainerMessage>(SilencerModuleOnInsert);
|
|
SubscribeLocalEvent<SilencerModuleComponent, EntGotRemovedFromContainerMessage>(SilencerModuleOnEject);
|
|
|
|
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotInsertedIntoContainerMessage>(AcceleratorModuleOnInsert);
|
|
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotRemovedFromContainerMessage>(AcceleratorModuleOnEject);
|
|
|
|
SubscribeLocalEvent<AimModuleComponent, EntGotInsertedIntoContainerMessage>(EightAimModuleOnInsert);
|
|
SubscribeLocalEvent<AimModuleComponent, EntGotRemovedFromContainerMessage>(EightAimModuleOnEject);
|
|
|
|
SubscribeLocalEvent<ShutterModuleComponent, EntGotInsertedIntoContainerMessage>(ShutterModuleOnInsert);
|
|
SubscribeLocalEvent<ShutterModuleComponent, EntGotRemovedFromContainerMessage>(ShutterModuleOnEject);
|
|
}
|
|
|
|
private bool TryInsertModule(EntityUid module, EntityUid weapon, BaseModuleComponent component,
|
|
string containerId, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent)
|
|
{
|
|
if (!TryComp(weapon, out weaponModulesComponent) || !TryComp<AppearanceComponent>(weapon, out var appearanceComponent) ||
|
|
!Slots.ContainsKey(containerId))
|
|
{
|
|
weaponModulesComponent = null;
|
|
appearanceComponent = null;
|
|
return false;
|
|
}
|
|
|
|
if(!weaponModulesComponent.Modules.Contains(module))
|
|
weaponModulesComponent.Modules.Add(module);
|
|
|
|
if (!Slots.TryGetValue(containerId, out var value))
|
|
return false;
|
|
|
|
_appearanceSystem.SetData(weapon, value, component.AppearanceValue, appearanceComponent);
|
|
|
|
return true;
|
|
}
|
|
|
|
private bool TryEjectModule(EntityUid module, EntityUid weapon, string containerId, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent)
|
|
{
|
|
if (!TryComp(weapon, out weaponModulesComponent) || !TryComp<AppearanceComponent>(weapon, out var appearanceComponent) || !Slots.ContainsKey(containerId))
|
|
{
|
|
weaponModulesComponent = null;
|
|
appearanceComponent = null;
|
|
return false;
|
|
}
|
|
|
|
|
|
if(weaponModulesComponent.Modules.Contains(module))
|
|
weaponModulesComponent.Modules.Remove(module);
|
|
|
|
if (!Slots.TryGetValue(containerId, out var value))
|
|
return false;
|
|
|
|
_appearanceSystem.SetData(weapon, value, "none", appearanceComponent);
|
|
|
|
return true;
|
|
}
|
|
|
|
#region InsertModules
|
|
private void LightModuleOnInsert(EntityUid module, LightModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryInsertModule(module, weapon, component, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
TryComp<AppearanceComponent>(weapon, out var appearanceComponent);
|
|
|
|
SharedPointLightComponent light = _lightSystem.EnsureLight(weapon);
|
|
|
|
_appearanceSystem.SetData(weapon, Modules.Light, "none", appearanceComponent);
|
|
|
|
_lightSystem.SetRadius(weapon, component.Radius, light);
|
|
_lightSystem.SetEnabled(weapon, true, light);
|
|
}
|
|
|
|
private void LaserModuleOnInsert(EntityUid module, LaserModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
|
|
|
if(!TryInsertModule(module, weapon, component, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
component.OldProjectileSpeed = gunComp.ProjectileSpeed;
|
|
|
|
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed + component.ProjectileSpeedAdd);
|
|
}
|
|
|
|
private void FlameHiderModuleOnInsert(EntityUid module, FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryInsertModule(module, weapon, component, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
weaponModulesComponent.WeaponFireEffect = true;
|
|
Dirty(module, weaponModulesComponent);
|
|
}
|
|
|
|
private void SilencerModuleOnInsert(EntityUid module, SilencerModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
|
|
|
if(!TryInsertModule(module, weapon, component, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
component.OldSoundGunshot = gunComp.SoundGunshot;
|
|
|
|
weaponModulesComponent.WeaponFireEffect = true;
|
|
_gunSystem.SetSound(weapon, component.NewSoundGunshot);
|
|
|
|
Dirty(module, weaponModulesComponent);
|
|
}
|
|
|
|
private void AcceleratorModuleOnInsert(EntityUid module, AcceleratorModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
|
|
|
if(!TryInsertModule(module, weapon, component, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
component.OldFireRate = gunComp.FireRate;
|
|
|
|
_gunSystem.SetFireRate(weapon, component.OldFireRate + component.FireRateAdd);
|
|
}
|
|
|
|
private void EightAimModuleOnInsert(EntityUid module, AimModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
|
|
|
if(!TryInsertModule(module, weapon, component, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
EnsureComp<TelescopeComponent>(weapon).Divisor = component.Divisor;
|
|
}
|
|
|
|
private void ShutterModuleOnInsert(EntityUid module, ShutterModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
|
|
|
if(!TryInsertModule(module, weapon, component, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
if (!TryComp<BallisticAmmoProviderComponent>(weapon, out var ballisticAmmo))
|
|
return;
|
|
|
|
ballisticAmmo.Whitelist?.Tags?.Add(component.Tag);
|
|
Dirty(weapon, ballisticAmmo);
|
|
}
|
|
#endregion
|
|
|
|
#region EjectModules
|
|
private void LightModuleOnEject(EntityUid module, LightModuleComponent component, EntGotRemovedFromContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryEjectModule(module, weapon, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
if(!_lightSystem.TryGetLight(weapon, out var light))
|
|
return;
|
|
|
|
_lightSystem.SetRadius(weapon, 0F, light);
|
|
_lightSystem.SetEnabled(weapon, false, light);
|
|
}
|
|
|
|
private void LaserModuleOnEject(EntityUid module, LaserModuleComponent component, EntGotRemovedFromContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryEjectModule(module, weapon, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed);
|
|
}
|
|
|
|
private void FlameHiderModuleOnEject(EntityUid module, FlameHiderModuleComponent component, EntGotRemovedFromContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryEjectModule(module, weapon, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
weaponModulesComponent.WeaponFireEffect = false;
|
|
Dirty(module, weaponModulesComponent);
|
|
}
|
|
|
|
private void SilencerModuleOnEject(EntityUid module, SilencerModuleComponent component, EntGotRemovedFromContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryEjectModule(module, weapon, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
weaponModulesComponent.WeaponFireEffect = false;
|
|
_gunSystem.SetSound(weapon, component.OldSoundGunshot!);
|
|
Dirty(module, weaponModulesComponent);
|
|
}
|
|
|
|
private void AcceleratorModuleOnEject(EntityUid module, AcceleratorModuleComponent component, EntGotRemovedFromContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryEjectModule(module, weapon, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
_gunSystem.SetFireRate(weapon, component.OldFireRate);
|
|
}
|
|
|
|
private void EightAimModuleOnEject(EntityUid module, AimModuleComponent component, EntGotRemovedFromContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryEjectModule(module, weapon, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
RemComp<TelescopeComponent>(weapon);
|
|
}
|
|
|
|
private void ShutterModuleOnEject(EntityUid module, ShutterModuleComponent component, EntGotRemovedFromContainerMessage args)
|
|
{
|
|
EntityUid weapon = args.Container.Owner;
|
|
|
|
if(!TryEjectModule(module, weapon, args.Container.ID, out var weaponModulesComponent))
|
|
return;
|
|
|
|
if (!TryComp<BallisticAmmoProviderComponent>(weapon, out var ballisticAmmo))
|
|
return;
|
|
|
|
ballisticAmmo.Whitelist?.Tags?.Remove(component.Tag);
|
|
Dirty(weapon, ballisticAmmo);
|
|
}
|
|
#endregion
|
|
}
|