ECS AsteroidRock and add a doafter to mining (#6120)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Mining;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Mining.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class AsteroidRockComponent : Component, IInteractUsing
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override string Name => "AsteroidRock";
|
||||
private static readonly string[] SpriteStates = {"0", "1", "2", "3", "4"};
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(AsteroidRockVisuals.State, _random.Pick(SpriteStates));
|
||||
}
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
var item = eventArgs.Using;
|
||||
if (!_entMan.TryGetComponent(item, out MeleeWeaponComponent? meleeWeaponComponent))
|
||||
return false;
|
||||
|
||||
EntitySystem.Get<DamageableSystem>().TryChangeDamage(Owner, meleeWeaponComponent.Damage);
|
||||
|
||||
if (!_entMan.TryGetComponent(item, out PickaxeComponent? pickaxeComponent))
|
||||
return true;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(Owner), pickaxeComponent.MiningSound.GetSound(), Owner, AudioParams.Default);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Content.Server/Mining/Components/MineableComponent.cs
Normal file
11
Content.Server/Mining/Components/MineableComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Mining.Components;
|
||||
|
||||
[RegisterComponent, ComponentProtoName("Mineable")]
|
||||
[Friend(typeof(MineableSystem))]
|
||||
public class MineableComponent : Component
|
||||
{
|
||||
public float BaseMineTime = 1.0f;
|
||||
}
|
||||
@@ -1,18 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Mining.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[RegisterComponent, ComponentProtoName("Pickaxe")]
|
||||
public class PickaxeComponent : Component
|
||||
{
|
||||
public override string Name => "Pickaxe";
|
||||
|
||||
[DataField("miningSound")]
|
||||
[DataField("sound")]
|
||||
public SoundSpecifier MiningSound { get; set; } = new SoundPathSpecifier("/Audio/Items/Mining/pickaxe.ogg");
|
||||
|
||||
[DataField("miningSpeedMultiplier")]
|
||||
public float MiningSpeedMultiplier { get; set; } = 1f;
|
||||
[DataField("timeMultiplier")]
|
||||
public float MiningTimeMultiplier { get; set; } = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// What damage should be given to objects when
|
||||
/// mined using a pickaxe?
|
||||
/// </summary>
|
||||
[DataField("damage", required: true)]
|
||||
public DamageSpecifier Damage { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// How many entities can this pickaxe mine at once?
|
||||
/// </summary>
|
||||
[DataField("maxEntities")]
|
||||
public int MaxMiningEntities = 1;
|
||||
|
||||
public HashSet<EntityUid> MiningEntities = new();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user