1 do_after for ore veins (#14083)

* Ore veins

I dislike rocks just providing generic drops and this factors into mining more.

* fixes

* descriptions

* comment

* every flipping time

* Make mining destroy rocks with 1 hit

Having to click 3 times was pretty annoying.

* a
This commit is contained in:
metalgearsloth
2023-02-14 02:32:09 +11:00
committed by GitHub
parent 44a0888c15
commit bfbb1a689f
5 changed files with 33 additions and 15 deletions

View File

@@ -0,0 +1,8 @@
using Content.Shared.Destructible;
namespace Content.Client.Damage;
public sealed class DestructibleSystem : SharedDestructibleSystem
{
}

View File

@@ -17,13 +17,6 @@ namespace Content.Server.Gatherable.Components
[DataField("sound")] [DataField("sound")]
public SoundSpecifier GatheringSound { get; set; } = new SoundPathSpecifier("/Audio/Items/Mining/pickaxe.ogg"); public SoundSpecifier GatheringSound { get; set; } = new SoundPathSpecifier("/Audio/Items/Mining/pickaxe.ogg");
/// <summary>
/// This directly plugs into the time delay for gathering.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("gatheringTime")]
public float GatheringTime { get; set; } = 1f;
/// <summary> /// <summary>
/// What damage should be given to objects when /// What damage should be given to objects when
/// gathered using this tool? (0 for infinite gathering) /// gathered using this tool? (0 for infinite gathering)

View File

@@ -1,7 +1,9 @@
using System.Threading; using System.Threading;
using Content.Server.Destructible;
using Content.Server.DoAfter; using Content.Server.DoAfter;
using Content.Server.Gatherable.Components; using Content.Server.Gatherable.Components;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Destructible;
using Content.Shared.EntityList; using Content.Shared.EntityList;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Tag; using Content.Shared.Tag;
@@ -12,12 +14,13 @@ namespace Content.Server.Gatherable;
public sealed class GatherableSystem : EntitySystem public sealed class GatherableSystem : EntitySystem
{ {
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly DestructibleSystem _destructible = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -39,10 +42,14 @@ public sealed class GatherableSystem : EntitySystem
if (tool.MaxGatheringEntities < tool.GatheringEntities.Count + 1) if (tool.MaxGatheringEntities < tool.GatheringEntities.Count + 1)
return; return;
var damageRequired = _destructible.DestroyedAt(uid);
var damageTime = (damageRequired / tool.Damage.Total).Float();
damageTime = Math.Max(1f, damageTime);
cancelToken = new CancellationTokenSource(); cancelToken = new CancellationTokenSource();
tool.GatheringEntities[uid] = cancelToken; tool.GatheringEntities[uid] = cancelToken;
var doAfter = new DoAfterEventArgs(args.User, tool.GatheringTime, cancelToken.Token, uid) var doAfter = new DoAfterEventArgs(args.User, damageTime, cancelToken.Token, uid)
{ {
BreakOnDamage = true, BreakOnDamage = true,
BreakOnStun = true, BreakOnStun = true,
@@ -62,7 +69,7 @@ public sealed class GatherableSystem : EntitySystem
return; return;
// Complete the gathering process // Complete the gathering process
_damageableSystem.TryChangeDamage(ev.Resource, tool.Damage, origin: ev.Player); _destructible.DestroyEntity(uid);
_audio.PlayPvs(tool.GatheringSound, ev.Resource); _audio.PlayPvs(tool.GatheringSound, ev.Resource);
tool.GatheringEntities.Remove(ev.Resource); tool.GatheringEntities.Remove(ev.Resource);

View File

@@ -38,7 +38,7 @@ public sealed class MiningSystem : EntitySystem
var toSpawn = _random.Next(proto.MinOreYield, proto.MaxOreYield); var toSpawn = _random.Next(proto.MinOreYield, proto.MaxOreYield);
for (var i = 0; i < toSpawn; i++) for (var i = 0; i < toSpawn; i++)
{ {
Spawn(proto.OreEntity, coords.Offset(_random.NextVector2(0.3f))); Spawn(proto.OreEntity, coords.Offset(_random.NextVector2(0.2f)));
} }
} }

View File

@@ -13,6 +13,16 @@
- type: Tag - type: Tag
tags: tags:
- Ore - Ore
- type: Fixtures
fixtures:
- shape:
!type:PhysShapeCircle
radius: 0.2
density: 20
mask:
- ItemMask
restitution: 0.3
friction: 0.2
- type: Damageable - type: Damageable
damageContainer: Inorganic damageContainer: Inorganic
damageModifierSet: Metallic damageModifierSet: Metallic