Implement some field-level deltas (#28242)
* Update GasTileOverlayState * Update DecalGridState * Update NavMapState * poke * poke2 * poke3 * Implement field deltas for guns * Content done * Update --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
This commit is contained in:
parent
faa8cd6f8f
commit
57628b8742
|
|
@ -15,6 +15,7 @@ public sealed partial class GunSystem
|
|||
{
|
||||
var existing = component.Entities[^1];
|
||||
component.Entities.RemoveAt(component.Entities.Count - 1);
|
||||
DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.Entities));
|
||||
|
||||
Containers.Remove(existing, component.Container);
|
||||
EnsureShootable(existing);
|
||||
|
|
@ -22,6 +23,7 @@ public sealed partial class GunSystem
|
|||
else if (component.UnspawnedCount > 0)
|
||||
{
|
||||
component.UnspawnedCount--;
|
||||
DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.UnspawnedCount));
|
||||
ent = Spawn(component.Proto, coordinates);
|
||||
EnsureShootable(ent.Value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,9 @@ public sealed partial class GunSystem
|
|||
if (solution == null && !_solutionContainer.TryGetSolution(uid, component.SolutionId, out _, out solution))
|
||||
{
|
||||
component.Shots = shots;
|
||||
DirtyField(uid, component, nameof(SolutionAmmoProviderComponent.Shots));
|
||||
component.MaxShots = maxShots;
|
||||
Dirty(uid, component);
|
||||
DirtyField(uid, component, nameof(SolutionAmmoProviderComponent.MaxShots));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -48,8 +49,10 @@ public sealed partial class GunSystem
|
|||
maxShots = (int) (solution.MaxVolume / component.FireCost);
|
||||
|
||||
component.Shots = shots;
|
||||
DirtyField(uid, component, nameof(SolutionAmmoProviderComponent.Shots));
|
||||
|
||||
component.MaxShots = maxShots;
|
||||
Dirty(uid, component);
|
||||
DirtyField(uid, component, nameof(SolutionAmmoProviderComponent.MaxShots));
|
||||
|
||||
UpdateSolutionAppearance(uid, component);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
|
|||
namespace Content.Shared.Nutrition.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(HungerSystem))]
|
||||
[AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||
[AutoGenerateComponentState(fieldDeltas: true), AutoGenerateComponentPause]
|
||||
public sealed partial class HungerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
|||
namespace Content.Shared.Nutrition.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(ThirstSystem))]
|
||||
[AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||
[AutoGenerateComponentState(fieldDeltas: true), AutoGenerateComponentPause]
|
||||
public sealed partial class ThirstComponent : Component
|
||||
{
|
||||
// Base stuff
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public sealed class HungerSystem : EntitySystem
|
|||
{
|
||||
entity.Comp.LastAuthoritativeHungerChangeTime = _timing.CurTime;
|
||||
entity.Comp.LastAuthoritativeHungerValue = ClampHungerWithinThresholds(entity.Comp, value);
|
||||
Dirty(entity);
|
||||
DirtyField(entity.Owner, entity.Comp, nameof(HungerComponent.LastAuthoritativeHungerChangeTime));
|
||||
}
|
||||
|
||||
private void UpdateCurrentThreshold(EntityUid uid, HungerComponent? component = null)
|
||||
|
|
@ -133,6 +133,7 @@ public sealed class HungerSystem : EntitySystem
|
|||
var calculatedHungerThreshold = GetHungerThreshold(component);
|
||||
if (calculatedHungerThreshold == component.CurrentThreshold)
|
||||
return;
|
||||
|
||||
component.CurrentThreshold = calculatedHungerThreshold;
|
||||
DoHungerThresholdEffects(uid, component);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,8 @@ public sealed class ThirstSystem : EntitySystem
|
|||
component.ThirstThresholds[ThirstThreshold.Dead],
|
||||
component.ThirstThresholds[ThirstThreshold.OverHydrated]
|
||||
);
|
||||
Dirty(uid, component);
|
||||
|
||||
EntityManager.DirtyField(uid, component, nameof(ThirstComponent.CurrentThirst));
|
||||
}
|
||||
|
||||
private bool IsMovementThreshold(ThirstThreshold threshold)
|
||||
|
|
|
|||
|
|
@ -13,27 +13,27 @@ public partial class AmmoComponent : Component, IShootable
|
|||
{
|
||||
// Muzzle flash stored on ammo because if we swap a gun to whatever we may want to override it.
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("muzzleFlash", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? MuzzleFlash = "MuzzleFlashEffect";
|
||||
[DataField]
|
||||
public EntProtoId? MuzzleFlash = "MuzzleFlashEffect";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawns another prototype to be shot instead of itself.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true)]
|
||||
public sealed partial class CartridgeAmmoComponent : AmmoComponent
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string Prototype = default!;
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("proto", required: true)]
|
||||
public EntProtoId Prototype;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("spent")]
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||
[AutoNetworkedField]
|
||||
public bool Spent = false;
|
||||
public bool Spent;
|
||||
|
||||
/// <summary>
|
||||
/// Caseless ammunition.
|
||||
/// </summary>
|
||||
[DataField("deleteOnSpawn")]
|
||||
[DataField]
|
||||
public bool DeleteOnSpawn;
|
||||
|
||||
[DataField("soundEject")]
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ using Robust.Shared.Prototypes;
|
|||
|
||||
namespace Content.Shared.Weapons.Ranged.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedGunSystem))]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true), Access(typeof(SharedGunSystem))]
|
||||
public sealed partial class BallisticAmmoProviderComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||
[DataField]
|
||||
public SoundSpecifier? SoundRack = new SoundPathSpecifier("/Audio/Weapons/Guns/Cock/smg_cock.ogg");
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||
[DataField]
|
||||
public SoundSpecifier? SoundInsert = new SoundPathSpecifier("/Audio/Weapons/Guns/MagIn/bullet_insert.ogg");
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
|||
|
||||
namespace Content.Shared.Weapons.Ranged.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true), AutoGenerateComponentPause]
|
||||
[Access(typeof(SharedGunSystem), typeof(SharedOniSystem))] // DeltaV - I didn't feel like rewriting big chunks of code
|
||||
public sealed partial class GunComponent : Component
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,38 +5,38 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
|
|||
|
||||
namespace Content.Shared.Weapons.Ranged.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedGunSystem))]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true), Access(typeof(SharedGunSystem))]
|
||||
public sealed partial class SolutionAmmoProviderComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The solution where reagents are extracted from for the projectile.
|
||||
/// </summary>
|
||||
[DataField("solutionId", required: true), AutoNetworkedField]
|
||||
[DataField(required: true), AutoNetworkedField]
|
||||
public string SolutionId = default!;
|
||||
|
||||
/// <summary>
|
||||
/// How much reagent it costs to fire once.
|
||||
/// </summary>
|
||||
[DataField("fireCost"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public float FireCost = 5;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of shots currently available.
|
||||
/// used for network predictions.
|
||||
/// </summary>
|
||||
[DataField("shots"), ViewVariables, AutoNetworkedField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public int Shots;
|
||||
|
||||
/// <summary>
|
||||
/// The max amount of shots the gun can fire.
|
||||
/// used for network prediction
|
||||
/// </summary>
|
||||
[DataField("maxShots"), ViewVariables, AutoNetworkedField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public int MaxShots;
|
||||
|
||||
/// <summary>
|
||||
/// The prototype that's fired by the gun.
|
||||
/// </summary>
|
||||
[DataField("proto", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string Prototype = default!;
|
||||
[DataField("proto")]
|
||||
public EntProtoId Prototype;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public abstract partial class SharedGunSystem
|
|||
Audio.PlayPredicted(component.SoundInsert, uid, args.User);
|
||||
args.Handled = true;
|
||||
UpdateBallisticAppearance(uid, component);
|
||||
Dirty(uid, component);
|
||||
DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.Entities));
|
||||
}
|
||||
|
||||
private void OnBallisticAfterInteract(EntityUid uid, BallisticAmmoProviderComponent component, AfterInteractEvent args)
|
||||
|
|
@ -194,10 +194,9 @@ public abstract partial class SharedGunSystem
|
|||
!Paused(uid))
|
||||
{
|
||||
gunComp.NextFire = Timing.CurTime + TimeSpan.FromSeconds(1 / gunComp.FireRateModified);
|
||||
Dirty(uid, gunComp);
|
||||
DirtyField(uid, gunComp, nameof(GunComponent.NextFire));
|
||||
}
|
||||
|
||||
Dirty(uid, component);
|
||||
Audio.PlayPredicted(component.SoundRack, uid, user);
|
||||
|
||||
var shots = GetBallisticShots(component);
|
||||
|
|
@ -228,7 +227,7 @@ public abstract partial class SharedGunSystem
|
|||
{
|
||||
component.UnspawnedCount = Math.Max(0, component.Capacity - component.Container.ContainedEntities.Count);
|
||||
UpdateBallisticAppearance(uid, component);
|
||||
Dirty(uid, component);
|
||||
DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.UnspawnedCount));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,18 +248,19 @@ public abstract partial class SharedGunSystem
|
|||
|
||||
args.Ammo.Add((entity, EnsureShootable(entity)));
|
||||
component.Entities.RemoveAt(component.Entities.Count - 1);
|
||||
DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.Entities));
|
||||
Containers.Remove(entity, component.Container);
|
||||
}
|
||||
else if (component.UnspawnedCount > 0)
|
||||
{
|
||||
component.UnspawnedCount--;
|
||||
DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.UnspawnedCount));
|
||||
entity = Spawn(component.Proto, args.Coordinates);
|
||||
args.Ammo.Add((entity, EnsureShootable(entity)));
|
||||
}
|
||||
}
|
||||
|
||||
UpdateBallisticAppearance(uid, component);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void OnBallisticAmmoCount(EntityUid uid, BallisticAmmoProviderComponent component, ref GetAmmoCountEvent args)
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
if (melee.NextAttack > component.NextFire)
|
||||
{
|
||||
component.NextFire = melee.NextAttack;
|
||||
Dirty(uid, component);
|
||||
EntityManager.DirtyField(uid, component, nameof(MeleeWeaponComponent.NextAttack));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
gun.ShotCounter = 0;
|
||||
gun.ShootCoordinates = null;
|
||||
gun.Target = null;
|
||||
Dirty(uid, gun);
|
||||
EntityManager.DirtyField(uid, gun, nameof(GunComponent.ShotCounter));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -213,6 +213,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
gun.ShootCoordinates = toCoordinates;
|
||||
AttemptShoot(user, gunUid, gun);
|
||||
gun.ShotCounter = 0;
|
||||
EntityManager.DirtyField(gunUid, gun, nameof(GunComponent.ShotCounter));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -233,7 +234,9 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
|
||||
if (gun.FireRateModified <= 0f ||
|
||||
!_actionBlockerSystem.CanAttack(user))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var toCoordinates = gun.ShootCoordinates;
|
||||
|
||||
|
|
@ -282,7 +285,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
}
|
||||
|
||||
// NextFire has been touched regardless so need to dirty the gun.
|
||||
Dirty(gunUid, gun);
|
||||
EntityManager.DirtyField(gunUid, gun, nameof(GunComponent.NextFire));
|
||||
|
||||
// Get how many shots we're actually allowed to make, due to clip size or otherwise.
|
||||
// Don't do this in the loop so we still reset NextFire.
|
||||
|
|
@ -336,6 +339,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
// Even if we don't actually shoot update the ShotCounter. This is to avoid spamming empty sounds
|
||||
// where the gun may be SemiAuto or Burst.
|
||||
gun.ShotCounter += shots;
|
||||
EntityManager.DirtyField(gunUid, gun, nameof(GunComponent.ShotCounter));
|
||||
|
||||
if (ev.Ammo.Count <= 0)
|
||||
{
|
||||
|
|
@ -392,8 +396,6 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
if (_gravity.IsWeightless(user, userPhysics))
|
||||
CauseImpulse(fromCoordinates, toCoordinates.Value, user, userPhysics);
|
||||
}
|
||||
|
||||
Dirty(gunUid, gun);
|
||||
}
|
||||
|
||||
public void Shoot(
|
||||
|
|
@ -447,7 +449,7 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
protected void SetCartridgeSpent(EntityUid uid, CartridgeAmmoComponent cartridge, bool spent)
|
||||
{
|
||||
if (cartridge.Spent != spent)
|
||||
Dirty(uid, cartridge);
|
||||
DirtyField(uid, cartridge, nameof(CartridgeAmmoComponent.Spent));
|
||||
|
||||
cartridge.Spent = spent;
|
||||
Appearance.SetData(uid, AmmoVisuals.Spent, spent);
|
||||
|
|
@ -546,17 +548,59 @@ public abstract partial class SharedGunSystem : EntitySystem
|
|||
|
||||
RaiseLocalEvent(gun, ref ev);
|
||||
|
||||
comp.SoundGunshotModified = ev.SoundGunshot;
|
||||
comp.CameraRecoilScalarModified = ev.CameraRecoilScalar;
|
||||
comp.AngleIncreaseModified = ev.AngleIncrease;
|
||||
comp.AngleDecayModified = ev.AngleDecay;
|
||||
comp.MaxAngleModified = ev.MaxAngle;
|
||||
comp.MinAngleModified = ev.MinAngle;
|
||||
comp.ShotsPerBurstModified = ev.ShotsPerBurst;
|
||||
comp.FireRateModified = ev.FireRate;
|
||||
comp.ProjectileSpeedModified = ev.ProjectileSpeed;
|
||||
if (comp.SoundGunshotModified != ev.SoundGunshot)
|
||||
{
|
||||
comp.SoundGunshotModified = ev.SoundGunshot;
|
||||
DirtyField(gun, nameof(GunComponent.SoundGunshotModified));
|
||||
}
|
||||
|
||||
Dirty(gun);
|
||||
if (!MathHelper.CloseTo(comp.CameraRecoilScalarModified, ev.CameraRecoilScalar))
|
||||
{
|
||||
comp.CameraRecoilScalarModified = ev.CameraRecoilScalar;
|
||||
DirtyField(gun, nameof(GunComponent.CameraRecoilScalarModified));
|
||||
}
|
||||
|
||||
if (!comp.AngleIncreaseModified.EqualsApprox(ev.AngleIncrease))
|
||||
{
|
||||
comp.AngleIncreaseModified = ev.AngleIncrease;
|
||||
DirtyField(gun, nameof(GunComponent.AngleIncreaseModified));
|
||||
}
|
||||
|
||||
if (!comp.AngleDecayModified.EqualsApprox(ev.AngleDecay))
|
||||
{
|
||||
comp.AngleDecayModified = ev.AngleDecay;
|
||||
DirtyField(gun, nameof(GunComponent.AngleDecayModified));
|
||||
}
|
||||
|
||||
if (!comp.MaxAngleModified.EqualsApprox(ev.MinAngle))
|
||||
{
|
||||
comp.MaxAngleModified = ev.MaxAngle;
|
||||
DirtyField(gun, nameof(GunComponent.MaxAngleModified));
|
||||
}
|
||||
|
||||
if (!comp.MinAngleModified.EqualsApprox(ev.MinAngle))
|
||||
{
|
||||
comp.MinAngleModified = ev.MinAngle;
|
||||
DirtyField(gun, nameof(GunComponent.MinAngleModified));
|
||||
}
|
||||
|
||||
if (comp.ShotsPerBurstModified != ev.ShotsPerBurst)
|
||||
{
|
||||
comp.ShotsPerBurstModified = ev.ShotsPerBurst;
|
||||
DirtyField(gun, nameof(GunComponent.ShotsPerBurstModified));
|
||||
}
|
||||
|
||||
if (!MathHelper.CloseTo(comp.FireRateModified, ev.FireRate))
|
||||
{
|
||||
comp.FireRateModified = ev.FireRate;
|
||||
DirtyField(gun, nameof(GunComponent.FireRateModified));
|
||||
}
|
||||
|
||||
if (!MathHelper.CloseTo(comp.ProjectileSpeedModified, ev.ProjectileSpeed))
|
||||
{
|
||||
comp.ProjectileSpeedModified = ev.ProjectileSpeed;
|
||||
DirtyField(gun, nameof(GunComponent.ProjectileSpeedModified));
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void CreateEffect(EntityUid gunUid, MuzzleFlashEvent message, EntityUid? user = null);
|
||||
|
|
|
|||
Loading…
Reference in New Issue