Update trivial components to use auto comp states (#20539)

This commit is contained in:
DrSmugleaf
2023-09-28 16:20:29 -07:00
committed by GitHub
parent 14cfe44ece
commit a44fa86b68
158 changed files with 806 additions and 2866 deletions

View File

@@ -3,16 +3,14 @@ using Content.Shared.FixedPoint;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Weapons.Melee;
/// <summary>
/// When given to a mob lets them do unarmed attacks, or when given to an item lets someone wield it to do attacks.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class MeleeWeaponComponent : Component
{
// TODO: This is becoming bloated as shit.
@@ -20,26 +18,27 @@ public sealed partial class MeleeWeaponComponent : Component
/// <summary>
/// Does this entity do a disarm on alt attack.
/// </summary>
[DataField("altDisarm"), ViewVariables(VVAccess.ReadWrite)]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool AltDisarm = true;
/// <summary>
/// Should the melee weapon's damage stats be examinable.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("hidden")]
public bool HideFromExamine;
[DataField]
public bool Hidden;
/// <summary>
/// Next time this component is allowed to light attack. Heavy attacks are wound up and never have a cooldown.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("nextAttack", customTypeSerializer:typeof(TimeOffsetSerializer))]
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan NextAttack;
/// <summary>
/// Starts attack cooldown when equipped if true.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("resetOnHandSelected")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool ResetOnHandSelected = true;
/*
@@ -51,50 +50,51 @@ public sealed partial class MeleeWeaponComponent : Component
/// <summary>
/// How many times we can attack per second.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("attackRate")]
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float AttackRate = 1f;
/// <summary>
/// Are we currently holding down the mouse for an attack.
/// Used so we can't just hold the mouse button and attack constantly.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool Attacking = false;
/// <summary>
/// Base damage for this weapon. Can be modified via heavy damage or other means.
/// </summary>
[DataField("damage", required:true)]
[DataField(required:true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier Damage = default!;
[DataField("bluntStaminaDamageFactor")] [ViewVariables(VVAccess.ReadWrite)]
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 BluntStaminaDamageFactor = FixedPoint2.New(0.5f);
/// <summary>
/// Multiplies damage by this amount for single-target attacks.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("clickDamageModifier")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public FixedPoint2 ClickDamageModifier = FixedPoint2.New(1);
// TODO: Temporarily 1.5 until interactionoutline is adjusted to use melee, then probably drop to 1.2
/// <summary>
/// Nearest edge range to hit an entity.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("range")]
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public float Range = 1.5f;
/// <summary>
/// Total width of the angle for wide attacks.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("angle")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public Angle Angle = Angle.FromDegrees(60);
[ViewVariables(VVAccess.ReadWrite), DataField("animation", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string ClickAnimation = "WeaponArcPunch";
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public EntProtoId Animation = "WeaponArcPunch";
[ViewVariables(VVAccess.ReadWrite), DataField("wideAnimation", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string WideAnimation = "WeaponArcSlash";
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public EntProtoId WideAnimation = "WeaponArcSlash";
// Sounds
@@ -132,27 +132,3 @@ public sealed class GetMeleeWeaponEvent : HandledEntityEventArgs
{
public EntityUid? Weapon;
}
[Serializable, NetSerializable]
public sealed class MeleeWeaponComponentState : ComponentState
{
// None of the other data matters for client as they're not predicted.
public float AttackRate;
public bool Attacking;
public TimeSpan NextAttack;
public string ClickAnimation;
public string WideAnimation;
public float Range;
public MeleeWeaponComponentState(float attackRate, bool attacking, TimeSpan nextAttack, string clickAnimation, string wideAnimation, float range)
{
AttackRate = attackRate;
Attacking = attacking;
NextAttack = nextAttack;
ClickAnimation = clickAnimation;
WideAnimation = wideAnimation;
Range = range;
}
}

View File

@@ -20,7 +20,6 @@ using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
@@ -65,8 +64,6 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<MeleeWeaponComponent, EntityUnpausedEvent>(OnMeleeUnpaused);
SubscribeLocalEvent<MeleeWeaponComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<MeleeWeaponComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<MeleeWeaponComponent, HandSelectedEvent>(OnMeleeSelected);
SubscribeLocalEvent<MeleeWeaponComponent, ShotAttemptedEvent>(OnMeleeShotAttempted);
SubscribeLocalEvent<MeleeWeaponComponent, GunShotEvent>(OnMeleeShot);
@@ -223,25 +220,6 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
AttemptAttack(args.SenderSession.AttachedEntity.Value, weaponUid, weapon, msg, args.SenderSession);
}
private void OnGetState(EntityUid uid, MeleeWeaponComponent component, ref ComponentGetState args)
{
args.State = new MeleeWeaponComponentState(component.AttackRate, component.Attacking, component.NextAttack, component.ClickAnimation, component.WideAnimation, component.Range);
}
private void OnHandleState(EntityUid uid, MeleeWeaponComponent component, ref ComponentHandleState args)
{
if (args.Current is not MeleeWeaponComponentState state)
return;
component.Attacking = state.Attacking;
component.AttackRate = state.AttackRate;
component.NextAttack = state.NextAttack;
component.ClickAnimation = state.ClickAnimation;
component.WideAnimation = state.WideAnimation;
component.Range = state.Range;
}
/// <summary>
/// Gets the total damage a weapon does, including modifiers like wielding and enablind/disabling
/// </summary>
@@ -427,13 +405,13 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
{
case LightAttackEvent light:
DoLightAttack(user, light, weaponUid, weapon, session);
animation = weapon.ClickAnimation;
animation = weapon.Animation;
break;
case DisarmAttackEvent disarm:
if (!DoDisarm(user, disarm, weaponUid, weapon, session))
return false;
animation = weapon.ClickAnimation;
animation = weapon.Animation;
break;
case HeavyAttackEvent heavy:
if (!DoHeavyAttack(user, heavy, weaponUid, weapon, session))

View File

@@ -3,37 +3,36 @@ using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Weapons.Ranged.Components;
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class BallisticAmmoProviderComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("soundRack")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public SoundSpecifier? SoundRack = new SoundPathSpecifier("/Audio/Weapons/Guns/Cock/smg_cock.ogg");
[ViewVariables(VVAccess.ReadWrite), DataField("soundInsert")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public SoundSpecifier? SoundInsert = new SoundPathSpecifier("/Audio/Weapons/Guns/MagIn/bullet_insert.ogg");
[ViewVariables(VVAccess.ReadWrite), DataField("proto", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? FillProto;
[ViewVariables(VVAccess.ReadWrite), DataField]
public EntProtoId? Proto;
[ViewVariables(VVAccess.ReadWrite), DataField("capacity")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public int Capacity = 30;
public int Count => UnspawnedCount + Container.ContainedEntities.Count;
[ViewVariables(VVAccess.ReadWrite), DataField("unspawnedCount")]
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public int UnspawnedCount;
[ViewVariables(VVAccess.ReadWrite), DataField("whitelist")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public EntityWhitelist? Whitelist;
public Container Container = default!;
// TODO: Make this use stacks when the typeserializer is done.
[DataField("entities")]
[DataField, AutoNetworkedField]
public List<EntityUid> Entities = new();
/// <summary>
@@ -42,18 +41,18 @@ public sealed partial class BallisticAmmoProviderComponent : Component
/// <remarks>
/// Set to false for entities like turrets to avoid users being able to cycle them.
/// </remarks>
[ViewVariables(VVAccess.ReadWrite), DataField("cycleable")]
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool Cycleable = true;
/// <summary>
/// Is it okay for this entity to directly transfer its valid ammunition into another provider?
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("mayTransfer")]
public bool MayTransfer = false;
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool MayTransfer;
/// <summary>
/// DoAfter delay for filling a bullet into another ballistic ammo provider.
/// </summary>
[DataField("fillDelay")]
[DataField]
public TimeSpan FillDelay = TimeSpan.FromSeconds(0.5);
}

View File

@@ -6,7 +6,6 @@ using Content.Shared.Verbs;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
@@ -29,29 +28,6 @@ public abstract partial class SharedGunSystem
SubscribeLocalEvent<BallisticAmmoProviderComponent, AfterInteractEvent>(OnBallisticAfterInteract);
SubscribeLocalEvent<BallisticAmmoProviderComponent, AmmoFillDoAfterEvent>(OnBallisticAmmoFillDoAfter);
SubscribeLocalEvent<BallisticAmmoProviderComponent, UseInHandEvent>(OnBallisticUse);
SubscribeLocalEvent<BallisticAmmoProviderComponent, ComponentGetState>(OnBallisticGetState);
SubscribeLocalEvent<BallisticAmmoProviderComponent, ComponentHandleState>(OnBallisticHandleState);
}
private void OnBallisticGetState(EntityUid uid, BallisticAmmoProviderComponent component, ref ComponentGetState args)
{
args.State = new BallisticAmmoProviderComponentState()
{
UnspawnedCount = component.UnspawnedCount,
Cycleable = component.Cycleable,
Entities = GetNetEntityList(component.Entities),
};
}
private void OnBallisticHandleState(EntityUid uid, BallisticAmmoProviderComponent component, ref ComponentHandleState args)
{
if (args.Current is not BallisticAmmoProviderComponentState state)
return;
component.UnspawnedCount = state.UnspawnedCount;
component.Cycleable = state.Cycleable;
component.Entities = EnsureEntityList<BallisticAmmoProviderComponent>(state.Entities, uid);
}
private void OnBallisticUse(EntityUid uid, BallisticAmmoProviderComponent component, UseInHandEvent args)
@@ -239,7 +215,7 @@ public abstract partial class SharedGunSystem
{
// TODO this should be part of the prototype, not set on map init.
// Alternatively, just track spawned count, instead of unspawned count.
if (component.FillProto != null)
if (component.Proto != null)
{
component.UnspawnedCount = Math.Max(0, component.Capacity - component.Container.ContainedEntities.Count);
UpdateBallisticAppearance(uid, component);
@@ -269,7 +245,7 @@ public abstract partial class SharedGunSystem
else if (component.UnspawnedCount > 0)
{
component.UnspawnedCount--;
entity = Spawn(component.FillProto, args.Coordinates);
entity = Spawn(component.Proto, args.Coordinates);
args.Ammo.Add((entity, EnsureShootable(entity)));
}
}
@@ -292,14 +268,6 @@ public abstract partial class SharedGunSystem
Appearance.SetData(uid, AmmoVisuals.AmmoCount, GetBallisticShots(component), appearance);
Appearance.SetData(uid, AmmoVisuals.AmmoMax, component.Capacity, appearance);
}
[Serializable, NetSerializable]
private sealed class BallisticAmmoProviderComponentState : ComponentState
{
public int UnspawnedCount;
public List<NetEntity> Entities = new();
public bool Cycleable = true;
}
}
/// <summary>