Fix weapon cooldown serialization while mapping (#15123)

This commit is contained in:
Leon Friedrich
2023-04-06 11:37:50 +12:00
committed by GitHub
parent c851a9af23
commit 29ad3e50ac
7 changed files with 38 additions and 32 deletions

View File

@@ -53,7 +53,7 @@ namespace Content.Server.Abilities.Mime
/// <summary>
/// How long it takes the mime to get their powers back
/// </summary>
[DataField("vowCooldown", customTypeSerializer: typeof(TimeOffsetSerializer))]
[DataField("vowCooldown")]
public TimeSpan VowCooldown = TimeSpan.FromMinutes(5);
}
}

View File

@@ -55,7 +55,7 @@ public sealed class MaterialStorageComponent : Component
/// <summary>
/// How long the inserting animation will play
/// </summary>
[DataField("insertionTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
[DataField("insertionTime")]
public TimeSpan InsertionTime = TimeSpan.FromSeconds(0.79f); // 0.01 off for animation timing
}

View File

@@ -70,6 +70,16 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
SubscribeAllEvent<HeavyAttackEvent>(OnHeavyAttack);
SubscribeAllEvent<DisarmAttackEvent>(OnDisarmAttack);
SubscribeAllEvent<StopAttackEvent>(OnStopAttack);
#if DEBUG
SubscribeLocalEvent<MeleeWeaponComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(EntityUid uid, MeleeWeaponComponent component, MapInitEvent args)
{
if (component.NextAttack > TimeSpan.Zero)
Logger.Warning($"Initializing a map that contains an entity that is on cooldown. Entity: {ToPrettyString(uid)}");
#endif
}
private void OnMeleeSelected(EntityUid uid, MeleeWeaponComponent component, HandSelectedEvent args)
@@ -80,6 +90,9 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (!component.ResetOnHandSelected)
return;
if (Paused(uid))
return;
// If someone swaps to this weapon then reset its cd.
var curTime = Timing.CurTime;
var minimum = curTime + TimeSpan.FromSeconds(1 / component.AttackRate);

View File

@@ -152,7 +152,8 @@ public abstract partial class SharedGunSystem
{
// Reset shotting for cycling
if (Resolve(uid, ref gunComp, false) &&
gunComp is { FireRate: > 0f })
gunComp is { FireRate: > 0f } &&
!Paused(uid))
{
gunComp.NextFire = Timing.CurTime + TimeSpan.FromSeconds(1 / gunComp.FireRate);
}

View File

@@ -64,6 +64,9 @@ public abstract partial class SharedGunSystem
DebugTools.Assert((component.AvailableModes & fire) != 0x0);
component.SelectedMode = fire;
if (!Paused(uid))
{
var curTime = Timing.CurTime;
var cooldown = TimeSpan.FromSeconds(InteractNextFire);
@@ -71,6 +74,7 @@ public abstract partial class SharedGunSystem
component.NextFire = curTime + cooldown;
else
component.NextFire += cooldown;
}
Audio.PlayPredicted(component.SoundModeToggle, uid, user);
Popup(Loc.GetString("gun-selected-mode", ("mode", GetLocSelector(fire))), uid, user);

View File

@@ -88,6 +88,16 @@ public abstract partial class SharedGunSystem : EntitySystem
SubscribeLocalEvent<GunComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<GunComponent, CycleModeEvent>(OnCycleMode);
SubscribeLocalEvent<GunComponent, ComponentInit>(OnGunInit);
#if DEBUG
SubscribeLocalEvent<GunComponent, MapInitEvent>(OnMapInit);
}
private void OnMapInit(EntityUid uid, GunComponent component, MapInitEvent args)
{
if (component.NextFire > TimeSpan.Zero)
Logger.Warning($"Initializing a map that contains an entity that is on cooldown. Entity: {ToPrettyString(uid)}");
#endif
}
private void OnGunInit(EntityUid uid, GunComponent component, ComponentInit args)

View File

@@ -1055,8 +1055,6 @@ entities:
- pos: -2.172831,4.5306726
parent: 179
type: Transform
- nextAttack: 384.7724706
type: MeleeWeapon
- uid: 148
type: Ointment
components:
@@ -1687,8 +1685,6 @@ entities:
- pos: -3.4579864,-1.9811735
parent: 179
type: Transform
- nextAttack: 582.1216812
type: MeleeWeapon
- uid: 186
type: PowerCellMedium
components:
@@ -2617,16 +2613,12 @@ entities:
- pos: -0.11783123,4.753312
parent: 179
type: Transform
- nextAttack: 244.2972008
type: MeleeWeapon
- uid: 328
type: MopItem
components:
- pos: 7.6382103,16.08618
parent: 179
type: Transform
- nextAttack: 3088.5283222
type: MeleeWeapon
- solutions:
absorbed:
temperature: 293.15
@@ -2728,8 +2720,6 @@ entities:
- pos: 0.6895334,4.7183027
parent: 179
type: Transform
- nextAttack: 247.8805212
type: MeleeWeapon
- uid: 344
type: ClothingHeadHatWelding
components:
@@ -2838,8 +2828,6 @@ entities:
- pos: -1.6207478,4.3951616
parent: 179
type: Transform
- nextAttack: 232.4472496
type: MeleeWeapon
- uid: 360
type: PowerCellMedium
components:
@@ -2973,8 +2961,6 @@ entities:
- pos: -3.277628,-2.15838
parent: 179
type: Transform
- nextAttack: 578.7883598
type: MeleeWeapon
- uid: 382
type: SheetSteel
components:
@@ -3357,8 +3343,6 @@ entities:
- pos: -1.235331,4.739151
parent: 179
type: Transform
- nextAttack: 385.5557994
type: MeleeWeapon
- uid: 432
type: ChemicalPayload
components:
@@ -3377,8 +3361,6 @@ entities:
- pos: -3.1734612,-2.6066077
parent: 179
type: Transform
- nextAttack: 577.9550312
type: MeleeWeapon
- uid: 435
type: ModularGrenade
components:
@@ -5099,8 +5081,6 @@ entities:
- pos: 1.1246341,7.500063
parent: 179
type: Transform
- nextAttack: 669.0197422
type: MeleeWeapon
- uid: 673
type: Poweredlight
components:
@@ -7191,13 +7171,11 @@ entities:
parent: 179
type: Transform
- uid: 956
type: EmergencyOxygenTank
type: EmergencyOxygenTankFilled
components:
- pos: -10.505015,6.711994
parent: 179
type: Transform
- nextAttack: 396.1132382
type: MeleeWeapon
- uid: 957
type: AlwaysPoweredLightLED
components: