tweak: main values to components, rework methods
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using Content.Shared._White.WeaponModules;
|
using Content.Shared._White.WeaponModules;
|
||||||
using Content.Shared.Weapons.Ranged.Components;
|
using Content.Shared.Weapons.Ranged.Components;
|
||||||
using Content.Shared.Weapons.Ranged.Systems;
|
using Content.Shared.Weapons.Ranged.Systems;
|
||||||
|
using Linguini.Syntax.Ast;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
|
|
||||||
@@ -33,35 +34,37 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotInsertedIntoContainerMessage>(AcceleratorModuleOnInsert);
|
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotInsertedIntoContainerMessage>(AcceleratorModuleOnInsert);
|
||||||
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotRemovedFromContainerMessage>(AcceleratorModuleOnEject);
|
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))
|
weaponModulesComponent = null;
|
||||||
weaponModulesComponents.Modules.Add(module);
|
appearanceComponent = null;
|
||||||
weaponModulesComponent = weaponModulesComponents;
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!weaponModulesComponents.Modules.Contains(module))
|
||||||
|
weaponModulesComponents.Modules.Add(module);
|
||||||
|
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
|
||||||
weaponModulesComponent = weaponModulesComponents;
|
weaponModulesComponent = weaponModulesComponents;
|
||||||
return false;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryEjectModule(EntityUid module, EntityUid weapon, EntGotRemovedFromContainerMessage args, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent)
|
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))
|
weaponModulesComponent = null;
|
||||||
weaponModulesComponents.Modules.Remove(module);
|
appearanceComponent = null;
|
||||||
weaponModulesComponent = weaponModulesComponents;
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
weaponModulesComponent = weaponModulesComponents;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetAppearance(EntityUid weapon, Enum key, string value, AppearanceComponent appearanceComponent)
|
if(weaponModulesComponents.Modules.Contains(module))
|
||||||
{
|
weaponModulesComponents.Modules.Remove(module);
|
||||||
_appearanceSystem.SetData(weapon, key, value, appearanceComponent);
|
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
|
||||||
|
weaponModulesComponent = weaponModulesComponents;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region InsertModules
|
#region InsertModules
|
||||||
@@ -69,19 +72,17 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
EntityUid weapon = args.Container.Owner;
|
EntityUid weapon = args.Container.Owner;
|
||||||
|
|
||||||
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
|
|
||||||
|
|
||||||
_lightSystem.EnsureLight(weapon);
|
_lightSystem.EnsureLight(weapon);
|
||||||
|
|
||||||
_lightSystem.TryGetLight(weapon, out var light);
|
_lightSystem.TryGetLight(weapon, out var light);
|
||||||
_appearanceSystem.SetData(weapon, Modules.Light, "none", appearanceComponent);
|
_appearanceSystem.SetData(weapon, Modules.Light, "none", appearanceComponent);
|
||||||
|
|
||||||
_lightSystem.SetRadius(weapon, 4F, light);
|
_lightSystem.SetRadius(weapon, component.Radius, light);
|
||||||
_lightSystem.SetEnabled(weapon, true, light);
|
_lightSystem.SetEnabled(weapon, true, light);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,28 +90,23 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
EntityUid weapon = args.Container.Owner;
|
EntityUid weapon = args.Container.Owner;
|
||||||
|
|
||||||
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
||||||
|
|
||||||
component.OldProjectileSpeed = gunComp.ProjectileSpeed;
|
component.OldProjectileSpeed = gunComp.ProjectileSpeed;
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
|
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed + component.ProjectileSpeedAdd);
|
||||||
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed + 15F);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FlameHiderModuleOnInsert(EntityUid module, FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
private void FlameHiderModuleOnInsert(EntityUid module, FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args)
|
||||||
{
|
{
|
||||||
EntityUid weapon = args.Container.Owner;
|
EntityUid weapon = args.Container.Owner;
|
||||||
|
|
||||||
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
|
|
||||||
weaponModulesComponent.UseEffect = true;
|
weaponModulesComponent.UseEffect = true;
|
||||||
Dirty(module, weaponModulesComponent);
|
Dirty(module, weaponModulesComponent);
|
||||||
}
|
}
|
||||||
@@ -119,15 +115,13 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
EntityUid weapon = args.Container.Owner;
|
EntityUid weapon = args.Container.Owner;
|
||||||
|
|
||||||
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
||||||
|
|
||||||
component.OldSoundGunshot = gunComp.SoundGunshot;
|
component.OldSoundGunshot = gunComp.SoundGunshot;
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
|
|
||||||
weaponModulesComponent.UseEffect = true;
|
weaponModulesComponent.UseEffect = true;
|
||||||
_gunSystem.SetSound(weapon, component.NewSoundGunshot);
|
_gunSystem.SetSound(weapon, component.NewSoundGunshot);
|
||||||
|
|
||||||
@@ -138,17 +132,14 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
EntityUid weapon = args.Container.Owner;
|
EntityUid weapon = args.Container.Owner;
|
||||||
|
|
||||||
if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
|
|
||||||
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
|
||||||
|
|
||||||
component.OldFireRate = gunComp.FireRate;
|
component.OldFireRate = gunComp.FireRate;
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent);
|
_gunSystem.SetFireRate(weapon, component.OldFireRate + component.FireRateAdd);
|
||||||
_gunSystem.SetFireRate(weapon, component.OldFireRate + 2F);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -160,9 +151,6 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
|
|
||||||
_lightSystem.TryGetLight(weapon, out var light);
|
_lightSystem.TryGetLight(weapon, out var light);
|
||||||
_lightSystem.SetRadius(weapon, 0F, light);
|
_lightSystem.SetRadius(weapon, 0F, light);
|
||||||
_lightSystem.SetEnabled(weapon, false, light);
|
_lightSystem.SetEnabled(weapon, false, light);
|
||||||
@@ -175,9 +163,6 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
|
|
||||||
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed);
|
_gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,9 +173,6 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
|
|
||||||
weaponModulesComponent.UseEffect = false;
|
weaponModulesComponent.UseEffect = false;
|
||||||
Dirty(module, weaponModulesComponent);
|
Dirty(module, weaponModulesComponent);
|
||||||
}
|
}
|
||||||
@@ -202,9 +184,6 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
|
|
||||||
weaponModulesComponent.UseEffect = false;
|
weaponModulesComponent.UseEffect = false;
|
||||||
_gunSystem.SetSound(weapon, component.OldSoundGunshot!);
|
_gunSystem.SetSound(weapon, component.OldSoundGunshot!);
|
||||||
Dirty(module, weaponModulesComponent);
|
Dirty(module, weaponModulesComponent);
|
||||||
@@ -217,9 +196,6 @@ public sealed class WeaponModulesSystem : EntitySystem
|
|||||||
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
|
|
||||||
|
|
||||||
SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent);
|
|
||||||
_gunSystem.SetFireRate(weapon, component.OldFireRate);
|
_gunSystem.SetFireRate(weapon, component.OldFireRate);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ public sealed partial class AcceleratorModuleComponent : BaseModuleComponent
|
|||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||||
public float OldFireRate;
|
public float OldFireRate;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||||
|
public float FireRateAdd = 2.4F;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ public sealed partial class LaserModuleComponent : BaseModuleComponent
|
|||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||||
public float OldProjectileSpeed;
|
public float OldProjectileSpeed;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||||
|
public float ProjectileSpeedAdd = 15F;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ public sealed partial class LightModuleComponent : BaseModuleComponent
|
|||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||||
public bool Enabled;
|
public bool Enabled;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||||
|
public float Radius = 4F;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,6 @@
|
|||||||
magState: mag
|
magState: mag
|
||||||
steps: 1
|
steps: 1
|
||||||
zeroVisible: true
|
zeroVisible: true
|
||||||
- type: WeaponModulesVisuals
|
|
||||||
- type: PointLight
|
- type: PointLight
|
||||||
enabled: false
|
enabled: false
|
||||||
autoRot: true
|
autoRot: true
|
||||||
@@ -225,7 +224,6 @@
|
|||||||
magState: mag
|
magState: mag
|
||||||
steps: 1
|
steps: 1
|
||||||
zeroVisible: true
|
zeroVisible: true
|
||||||
- type: WeaponModulesVisuals
|
|
||||||
- type: PointLight
|
- type: PointLight
|
||||||
enabled: false
|
enabled: false
|
||||||
autoRot: true
|
autoRot: true
|
||||||
|
|||||||
@@ -166,7 +166,6 @@
|
|||||||
magState: mag
|
magState: mag
|
||||||
steps: 1
|
steps: 1
|
||||||
zeroVisible: true
|
zeroVisible: true
|
||||||
- type: WeaponModulesVisuals
|
|
||||||
- type: PointLight
|
- type: PointLight
|
||||||
enabled: false
|
enabled: false
|
||||||
autoRot: true
|
autoRot: true
|
||||||
@@ -286,7 +285,6 @@
|
|||||||
magState: mag
|
magState: mag
|
||||||
steps: 6
|
steps: 6
|
||||||
zeroVisible: true
|
zeroVisible: true
|
||||||
- type: WeaponModulesVisuals
|
|
||||||
- type: PointLight
|
- type: PointLight
|
||||||
enabled: false
|
enabled: false
|
||||||
autoRot: true
|
autoRot: true
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
# modules
|
# modules
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LightModule
|
id: LightModule
|
||||||
description: Light module for rifles (lector, CV, drozd, WT).
|
description: Light module for rifles (lecter, CV, drozd, WT).
|
||||||
name: "light module"
|
name: "light module"
|
||||||
parent: BaseModule
|
parent: BaseModule
|
||||||
components:
|
components:
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LaserModule
|
id: LaserModule
|
||||||
description: Laser module for rifles (lector, CV, drozd, WT).
|
description: Laser module for rifles (lecter, CV, drozd, WT).
|
||||||
name: "laser module"
|
name: "laser module"
|
||||||
parent: BaseModule
|
parent: BaseModule
|
||||||
components:
|
components:
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: FlameHiderModule
|
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"
|
name: "flamehider module"
|
||||||
parent: BaseModule
|
parent: BaseModule
|
||||||
components:
|
components:
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: SilencerModule
|
id: SilencerModule
|
||||||
description: Silencer module for rifles (lector, CV, drozd, WT).
|
description: Silencer module for rifles (lecter, CV, drozd, WT).
|
||||||
name: "silencer module"
|
name: "silencer module"
|
||||||
parent: BaseModule
|
parent: BaseModule
|
||||||
components:
|
components:
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: AcceleratorModule
|
id: AcceleratorModule
|
||||||
description: Accelerator module for rifles (lector, CV, drozd, WT).
|
description: Accelerator module for rifles (lecter, CV, drozd, WT).
|
||||||
name: "accelerator module"
|
name: "accelerator module"
|
||||||
parent: BaseModule
|
parent: BaseModule
|
||||||
components:
|
components:
|
||||||
|
|||||||
Reference in New Issue
Block a user