tweak: main values to components, rework methods

This commit is contained in:
CaYpeN1
2024-03-25 14:27:01 +05:00
parent b2cf4d5f46
commit 428a153ddb
7 changed files with 43 additions and 62 deletions

View File

@@ -2,6 +2,7 @@
using Content.Shared._White.WeaponModules;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Linguini.Syntax.Ast;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
@@ -33,35 +34,37 @@ public sealed class WeaponModulesSystem : EntitySystem
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotInsertedIntoContainerMessage>(AcceleratorModuleOnInsert);
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotRemovedFromContainerMessage>(AcceleratorModuleOnEject);
}
private bool TryInsertModule(EntityUid module, EntityUid weapon, EntGotInsertedIntoContainerMessage args, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent)
private bool TryInsertModule(EntityUid module, EntityUid weapon, BaseModuleComponent component, EntGotInsertedIntoContainerMessage args, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent)
{
if (TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponents) && ModulesSlot == args.Container.ID)
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponents) || !TryComp<AppearanceComponent>(weapon, out var appearanceComponent) || ModulesSlot != args.Container.ID)
{
if(!weaponModulesComponents.Modules.Contains(module))
weaponModulesComponents.Modules.Add(module);
weaponModulesComponent = weaponModulesComponents;
return true;
weaponModulesComponent = null;
appearanceComponent = null;
return false;
}
if(!weaponModulesComponents.Modules.Contains(module))
weaponModulesComponents.Modules.Add(module);
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
weaponModulesComponent = weaponModulesComponents;
return false;
return true;
}
private bool TryEjectModule(EntityUid module, EntityUid weapon, EntGotRemovedFromContainerMessage args, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent)
{
if (TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponents) && ModulesSlot == args.Container.ID)
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponents) || !TryComp<AppearanceComponent>(weapon, out var appearanceComponent) || ModulesSlot != args.Container.ID)
{
if(weaponModulesComponents.Modules.Contains(module))
weaponModulesComponents.Modules.Remove(module);
weaponModulesComponent = weaponModulesComponents;
return true;
weaponModulesComponent = null;
appearanceComponent = null;
return false;
}
weaponModulesComponent = weaponModulesComponents;
return false;
}
private void SetAppearance(EntityUid weapon, Enum key, string value, AppearanceComponent appearanceComponent)
{
_appearanceSystem.SetData(weapon, key, value, appearanceComponent);
if(weaponModulesComponents.Modules.Contains(module))
weaponModulesComponents.Modules.Remove(module);
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
weaponModulesComponent = weaponModulesComponents;
return true;
}
#region InsertModules
@@ -69,19 +72,17 @@ public sealed class WeaponModulesSystem : EntitySystem
{
EntityUid weapon = args.Container.Owner;
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
_lightSystem.EnsureLight(weapon);
_lightSystem.TryGetLight(weapon, out var light);
_appearanceSystem.SetData(weapon, Modules.Light, "none", appearanceComponent);
_lightSystem.SetRadius(weapon, 4F, light);
_lightSystem.SetRadius(weapon, component.Radius, light);
_lightSystem.SetEnabled(weapon, true, light);
}
@@ -89,28 +90,23 @@ public sealed class WeaponModulesSystem : EntitySystem
{
EntityUid weapon = args.Container.Owner;
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
component.OldProjectileSpeed = gunComp.ProjectileSpeed;
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed + 15F);
_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, args, out var weaponModulesComponent))
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
weaponModulesComponent.UseEffect = true;
Dirty(module, weaponModulesComponent);
}
@@ -119,15 +115,13 @@ public sealed class WeaponModulesSystem : EntitySystem
{
EntityUid weapon = args.Container.Owner;
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
component.OldSoundGunshot = gunComp.SoundGunshot;
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
weaponModulesComponent.UseEffect = true;
_gunSystem.SetSound(weapon, component.NewSoundGunshot);
@@ -138,17 +132,14 @@ public sealed class WeaponModulesSystem : EntitySystem
{
EntityUid weapon = args.Container.Owner;
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
component.OldFireRate = gunComp.FireRate;
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
_gunSystem.SetFireRate(weapon, component.OldFireRate + 2F);
_gunSystem.SetFireRate(weapon, component.OldFireRate + component.FireRateAdd);
}
#endregion
@@ -160,9 +151,6 @@ public sealed class WeaponModulesSystem : EntitySystem
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_lightSystem.TryGetLight(weapon, out var light);
_lightSystem.SetRadius(weapon, 0F, light);
_lightSystem.SetEnabled(weapon, false, light);
@@ -175,9 +163,6 @@ public sealed class WeaponModulesSystem : EntitySystem
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed);
}
@@ -188,9 +173,6 @@ public sealed class WeaponModulesSystem : EntitySystem
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
weaponModulesComponent.UseEffect = false;
Dirty(module, weaponModulesComponent);
}
@@ -202,9 +184,6 @@ public sealed class WeaponModulesSystem : EntitySystem
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
weaponModulesComponent.UseEffect = false;
_gunSystem.SetSound(weapon, component.OldSoundGunshot!);
Dirty(module, weaponModulesComponent);
@@ -217,9 +196,6 @@ public sealed class WeaponModulesSystem : EntitySystem
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
return;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.SetFireRate(weapon, component.OldFireRate);
}
#endregion

View File

@@ -8,4 +8,7 @@ public sealed partial class AcceleratorModuleComponent : BaseModuleComponent
{
[ViewVariables(VVAccess.ReadWrite), DataField]
public float OldFireRate;
[ViewVariables(VVAccess.ReadWrite), DataField]
public float FireRateAdd = 2.4F;
}

View File

@@ -8,4 +8,7 @@ public sealed partial class LaserModuleComponent : BaseModuleComponent
{
[ViewVariables(VVAccess.ReadWrite), DataField]
public float OldProjectileSpeed;
[ViewVariables(VVAccess.ReadWrite), DataField]
public float ProjectileSpeedAdd = 15F;
}

View File

@@ -8,4 +8,7 @@ public sealed partial class LightModuleComponent : BaseModuleComponent
{
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool Enabled;
[ViewVariables(VVAccess.ReadWrite), DataField]
public float Radius = 4F;
}

View File

@@ -119,7 +119,6 @@
magState: mag
steps: 1
zeroVisible: true
- type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true
@@ -225,7 +224,6 @@
magState: mag
steps: 1
zeroVisible: true
- type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true

View File

@@ -166,7 +166,6 @@
magState: mag
steps: 1
zeroVisible: true
- type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true
@@ -286,7 +285,6 @@
magState: mag
steps: 6
zeroVisible: true
- type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true

View File

@@ -23,7 +23,7 @@
# modules
- type: entity
id: LightModule
description: Light module for rifles (lector, CV, drozd, WT).
description: Light module for rifles (lecter, CV, drozd, WT).
name: "light module"
parent: BaseModule
components:
@@ -36,7 +36,7 @@
- type: entity
id: LaserModule
description: Laser module for rifles (lector, CV, drozd, WT).
description: Laser module for rifles (lecter, CV, drozd, WT).
name: "laser module"
parent: BaseModule
components:
@@ -49,7 +49,7 @@
- type: entity
id: FlameHiderModule
description: Flame Hider module for rifles (lector, CV, drozd, WT).
description: Flame Hider module for rifles (lecter, CV, drozd, WT).
name: "flamehider module"
parent: BaseModule
components:
@@ -62,7 +62,7 @@
- type: entity
id: SilencerModule
description: Silencer module for rifles (lector, CV, drozd, WT).
description: Silencer module for rifles (lecter, CV, drozd, WT).
name: "silencer module"
parent: BaseModule
components:
@@ -75,7 +75,7 @@
- type: entity
id: AcceleratorModule
description: Accelerator module for rifles (lector, CV, drozd, WT).
description: Accelerator module for rifles (lecter, CV, drozd, WT).
name: "accelerator module"
parent: BaseModule
components: