Implement field-deltas for melee (#33977)

* Implement field-deltas for melee

* Review
This commit is contained in:
metalgearsloth
2025-03-30 16:02:45 +11:00
committed by GitHub
parent b1f542a54c
commit 0ff70fdb40
3 changed files with 55 additions and 29 deletions

View File

@@ -104,7 +104,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (gun.NextFire > component.NextAttack)
{
component.NextAttack = gun.NextFire;
Dirty(uid, component);
DirtyField(uid, component, nameof(MeleeWeaponComponent.NextAttack));
}
}
@@ -128,7 +128,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
return;
component.NextAttack = minimum;
Dirty(uid, component);
DirtyField(uid, component, nameof(MeleeWeaponComponent.NextAttack));
}
private void OnGetBonusMeleeDamage(EntityUid uid, BonusMeleeDamageComponent component, ref GetMeleeDamageEvent args)
@@ -168,7 +168,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
return;
weapon.Attacking = false;
Dirty(weaponUid, weapon);
DirtyField(weaponUid, weapon, nameof(MeleeWeaponComponent.Attacking));
}
private void OnLightAttack(LightAttackEvent msg, EntitySessionEventArgs args)
@@ -392,7 +392,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
swings++;
}
Dirty(weaponUid, weapon);
DirtyField(weaponUid, weapon, nameof(MeleeWeaponComponent.NextAttack));
// Do this AFTER attack so it doesn't spam every tick
var ev = new AttemptMeleeEvent();
@@ -442,6 +442,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
RaiseLocalEvent(user, ref attackEv);
weapon.Attacking = true;
DirtyField(weaponUid, weapon, nameof(MeleeWeaponComponent.Attacking));
return true;
}
@@ -838,15 +839,21 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
//Setting deactivated damage to the weapon's regular value before changing it.
itemToggleMelee.DeactivatedDamage ??= meleeWeapon.Damage;
meleeWeapon.Damage = itemToggleMelee.ActivatedDamage;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.Damage));
}
meleeWeapon.HitSound = itemToggleMelee.ActivatedSoundOnHit;
if (meleeWeapon.HitSound?.Equals(itemToggleMelee.ActivatedSoundOnHit) != true)
{
meleeWeapon.HitSound = itemToggleMelee.ActivatedSoundOnHit;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.HitSound));
}
if (itemToggleMelee.ActivatedSoundOnHitNoDamage != null)
{
//Setting the deactivated sound on no damage hit to the weapon's regular value before changing it.
itemToggleMelee.DeactivatedSoundOnHitNoDamage ??= meleeWeapon.NoDamageSound;
meleeWeapon.NoDamageSound = itemToggleMelee.ActivatedSoundOnHitNoDamage;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.NoDamageSound));
}
if (itemToggleMelee.ActivatedSoundOnSwing != null)
@@ -854,28 +861,41 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
//Setting the deactivated sound on no damage hit to the weapon's regular value before changing it.
itemToggleMelee.DeactivatedSoundOnSwing ??= meleeWeapon.SwingSound;
meleeWeapon.SwingSound = itemToggleMelee.ActivatedSoundOnSwing;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.SwingSound));
}
if (itemToggleMelee.DeactivatedSecret)
{
meleeWeapon.Hidden = false;
}
}
else
{
if (itemToggleMelee.DeactivatedDamage != null)
{
meleeWeapon.Damage = itemToggleMelee.DeactivatedDamage;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.Damage));
}
meleeWeapon.HitSound = itemToggleMelee.DeactivatedSoundOnHit;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.HitSound));
if (itemToggleMelee.DeactivatedSoundOnHitNoDamage != null)
{
meleeWeapon.NoDamageSound = itemToggleMelee.DeactivatedSoundOnHitNoDamage;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.NoDamageSound));
}
if (itemToggleMelee.DeactivatedSoundOnSwing != null)
{
meleeWeapon.SwingSound = itemToggleMelee.DeactivatedSoundOnSwing;
DirtyField(uid, meleeWeapon, nameof(MeleeWeaponComponent.SwingSound));
}
if (itemToggleMelee.DeactivatedSecret)
{
meleeWeapon.Hidden = true;
}
}
Dirty(uid, meleeWeapon);
}
}