Salvage mining, ore processing, and material clean-up (#7406)
* adding stuff cuz new computer * removed unused materials * remove unused materials and such, lathe things * material volume no longer hardcoded * fixed mining system * add 5 stacks of materials, and add them to the ore processor * fix copyright for ores and handdrill * comma momma * whyyyyy * more fixes to make the yaml linter happy * i should get my eyes checked * silver proper * more cleanup * leftovers * remove more references to material doors * couldn't bear to be without bearhide * added uranium, added more lathe recipes * copyright fix, stack fix * ore processor sprite and such * ore processing some binches * MaterialCotton removal * 1 uranium ore means 1 sheet * fix merge conflict? idk * time to ketchup * lathe recognizes material volume again * yaml cleanup * forgot to remove adamantine lol * re-added diamond for now * diamond stacks * functional ore processor * added ignoreColor to lathe visuals * ore processor machine board * add board to industrial tech and circuit printer * provided lathes their whitelists * fix wonky ore spawning, added insert sound to lathe, adjusted ore chance * re-added ore processor * typos and cleanup * Update Content.Client/Lathe/LatheSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Lathe/LatheSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * revert mapchange * VV ignorecolor, pass entitymanager, move canceltoken to pickaxe, removed foreach from orespawn * actually null canceltoken * remove five-stacks, ore processor produces full stacks or single sheets/ingots * VV proper * adjust ore chances * readd Cotton * Update Content.Server/Mining/MineableSystem.cs * tweaks * Material is now dict (material, volume) * removed unused property * Space crystal -> space quartz * forgor asteroid space quartz Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Shared.Lathe;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Server.GameObjects;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Whitelist;
|
||||
|
||||
namespace Content.Server.Lathe.Components
|
||||
{
|
||||
@@ -10,9 +11,11 @@ namespace Content.Server.Lathe.Components
|
||||
public sealed class LatheComponent : SharedLatheComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// How much volume in cm^3 each sheet of material adds
|
||||
/// Whitelist for specifying the kind of materials that can be insert into the lathe
|
||||
/// </summary>
|
||||
public int VolumePerSheet = 100;
|
||||
[ViewVariables]
|
||||
[DataField("whitelist")]
|
||||
public EntityWhitelist? LatheWhitelist;
|
||||
|
||||
/// <summary>
|
||||
/// The lathe's construction queue
|
||||
@@ -46,10 +49,16 @@ namespace Content.Server.Lathe.Components
|
||||
/// </summary>
|
||||
[DataField("producingSound")]
|
||||
public SoundSpecifier? ProducingSound;
|
||||
|
||||
/// <summary>
|
||||
/// The sound that plays when inserting an item into the lathe, if any
|
||||
/// </summary>
|
||||
[DataField("insertingSound")]
|
||||
public SoundSpecifier? InsertingSound;
|
||||
|
||||
/// <summmary>
|
||||
/// The lathe's UI.
|
||||
/// </summary>
|
||||
[ViewVariables] public BoundUserInterface? UserInterface;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,9 @@ namespace Content.Server.Lathe
|
||||
/// </summary>
|
||||
private void OnInteractUsing(EntityUid uid, LatheComponent component, InteractUsingEvent args)
|
||||
{
|
||||
if (!TryComp<MaterialStorageComponent>(uid, out var storage) || !TryComp<MaterialComponent>(args.Used, out var material))
|
||||
if (!TryComp<MaterialStorageComponent>(uid, out var storage)
|
||||
|| !TryComp<MaterialComponent>(args.Used, out var material)
|
||||
|| component.LatheWhitelist?.IsValid(args.Used) == false)
|
||||
return;
|
||||
|
||||
var multiplier = 1;
|
||||
@@ -113,24 +115,30 @@ namespace Content.Server.Lathe
|
||||
var totalAmount = 0;
|
||||
|
||||
// Check if it can insert all materials.
|
||||
foreach (var mat in material.MaterialIds)
|
||||
foreach (var (mat, vol) in material._materials)
|
||||
{
|
||||
// TODO: Change how MaterialComponent works so this is not hard-coded.
|
||||
if (!storage.CanInsertMaterial(mat, component.VolumePerSheet * multiplier))
|
||||
return;
|
||||
totalAmount += component.VolumePerSheet * multiplier;
|
||||
if (!storage.CanInsertMaterial(mat,
|
||||
vol * multiplier)) return;
|
||||
totalAmount += vol * multiplier;
|
||||
}
|
||||
|
||||
// Check if it can take ALL of the material's volume.
|
||||
if (storage.StorageLimit > 0 && !storage.CanTakeAmount(totalAmount))
|
||||
return;
|
||||
var lastMat = string.Empty;
|
||||
foreach (var mat in material.MaterialIds)
|
||||
foreach (var (mat, vol) in material._materials)
|
||||
{
|
||||
storage.InsertMaterial(mat, component.VolumePerSheet * multiplier);
|
||||
storage.InsertMaterial(mat, vol * multiplier);
|
||||
lastMat = mat;
|
||||
}
|
||||
/// We need the prototype to get the color
|
||||
|
||||
// Play a sound when inserting, if any
|
||||
if (component.InsertingSound != null)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(component.Owner, entityManager: EntityManager), component.InsertingSound.GetSound(), component.Owner);
|
||||
}
|
||||
|
||||
// We need the prototype to get the color
|
||||
_prototypeManager.TryIndex(lastMat, out MaterialPrototype? matProto);
|
||||
|
||||
EntityManager.QueueDeleteEntity(args.Used);
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Materials;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
|
||||
namespace Content.Server.Materials
|
||||
{
|
||||
@@ -18,10 +13,10 @@ namespace Content.Server.Materials
|
||||
public sealed class MaterialComponent : Component
|
||||
{
|
||||
[ViewVariables]
|
||||
[DataField("materials", customTypeSerializer:typeof(PrototypeIdListSerializer<MaterialPrototype>))]
|
||||
[DataField("materials", customTypeSerializer:typeof(PrototypeIdDictionarySerializer<int, MaterialPrototype>))]
|
||||
// ReSharper disable once CollectionNeverUpdated.Local
|
||||
private readonly List<string> _materials = new();
|
||||
public IEnumerable<string> MaterialIds => _materials;
|
||||
public readonly Dictionary<string, int> _materials = new();
|
||||
public List<string> MaterialIds => _materials.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Returns all materials which make up this entity.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using System.Threading;
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Mining.Components;
|
||||
|
||||
@@ -7,5 +7,6 @@ namespace Content.Server.Mining.Components;
|
||||
[Friend(typeof(MineableSystem))]
|
||||
public sealed class MineableComponent : Component
|
||||
{
|
||||
[DataField("ores")] public List<EntitySpawnEntry> Ores = new();
|
||||
public float BaseMineTime = 1.0f;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Mining.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// When interacting with an <see cref="MineableComponent"/> allows it to spawn entities.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class PickaxeComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("sound")]
|
||||
public SoundSpecifier MiningSound { get; set; } = new SoundPathSpecifier("/Audio/Items/Mining/pickaxe.ogg");
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("timeMultiplier")]
|
||||
public float MiningTimeMultiplier { get; set; } = 1f;
|
||||
|
||||
@@ -25,9 +28,11 @@ namespace Content.Server.Mining.Components
|
||||
/// <summary>
|
||||
/// How many entities can this pickaxe mine at once?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("maxEntities")]
|
||||
public int MaxMiningEntities = 1;
|
||||
|
||||
public HashSet<EntityUid> MiningEntities = new();
|
||||
[ViewVariables]
|
||||
public readonly Dictionary<EntityUid, CancellationTokenSource> MiningEntities = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using Content.Server.DoAfter;
|
||||
using System.Threading;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Mining.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Mining;
|
||||
|
||||
@@ -13,6 +14,7 @@ public sealed class MineableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = null!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -20,7 +22,7 @@ public sealed class MineableSystem : EntitySystem
|
||||
|
||||
SubscribeLocalEvent<MineableComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<MiningDoafterCancel>(OnDoafterCancel);
|
||||
SubscribeLocalEvent<MiningDoafterSuccess>(OnDoafterSuccess);
|
||||
SubscribeLocalEvent<MineableComponent, MiningDoafterSuccess>(OnDoafterSuccess);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, MineableComponent component, InteractUsingEvent args)
|
||||
@@ -28,45 +30,63 @@ public sealed class MineableSystem : EntitySystem
|
||||
if (!TryComp<PickaxeComponent>(args.Used, out var pickaxe))
|
||||
return;
|
||||
|
||||
if (pickaxe.MiningEntities.TryGetValue(uid, out var cancelToken))
|
||||
{
|
||||
cancelToken.Cancel();
|
||||
pickaxe.MiningEntities.Remove(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
// Can't mine too many entities at once.
|
||||
if (pickaxe.MaxMiningEntities < pickaxe.MiningEntities.Count + 1)
|
||||
return;
|
||||
|
||||
// Can't mine one object multiple times.
|
||||
if (!pickaxe.MiningEntities.Add(uid))
|
||||
return;
|
||||
cancelToken = new CancellationTokenSource();
|
||||
pickaxe.MiningEntities[uid] = cancelToken;
|
||||
|
||||
var doAfter = new DoAfterEventArgs(args.User, component.BaseMineTime * pickaxe.MiningTimeMultiplier, default, uid)
|
||||
var doAfter = new DoAfterEventArgs(args.User, component.BaseMineTime * pickaxe.MiningTimeMultiplier, cancelToken.Token, uid)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
MovementThreshold = 0.5f,
|
||||
BroadcastCancelledEvent = new MiningDoafterCancel() { Pickaxe = args.Used, Rock = uid },
|
||||
BroadcastFinishedEvent = new MiningDoafterSuccess() { Pickaxe = args.Used, Rock = uid }
|
||||
MovementThreshold = 0.25f,
|
||||
BroadcastCancelledEvent = new MiningDoafterCancel { Pickaxe = args.Used, Rock = uid },
|
||||
TargetFinishedEvent = new MiningDoafterSuccess { Pickaxe = args.Used, Rock = uid, Player = args.User }
|
||||
};
|
||||
|
||||
_doAfterSystem.DoAfter(doAfter);
|
||||
}
|
||||
|
||||
private void OnDoafterSuccess(MiningDoafterSuccess ev)
|
||||
private void OnDoafterSuccess(EntityUid uid, MineableComponent component, MiningDoafterSuccess ev)
|
||||
{
|
||||
if (!TryComp(ev.Pickaxe, out PickaxeComponent? pickaxe))
|
||||
return;
|
||||
|
||||
_damageableSystem.TryChangeDamage(ev.Rock, pickaxe.Damage);
|
||||
SoundSystem.Play(Filter.Pvs(ev.Rock), pickaxe.MiningSound.GetSound(), ev.Rock, AudioParams.Default);
|
||||
SoundSystem.Play(Filter.Pvs(ev.Rock, entityManager: EntityManager), pickaxe.MiningSound.GetSound(), ev.Rock);
|
||||
pickaxe.MiningEntities.Remove(ev.Rock);
|
||||
|
||||
var spawnOre = EntitySpawnCollection.GetSpawns(component.Ores, _random);
|
||||
var playerPos = Transform(ev.Player).MapPosition;
|
||||
var spawnPos = playerPos.Offset(_random.NextVector2(0.3f));
|
||||
EntityManager.SpawnEntity(spawnOre[0], spawnPos);
|
||||
pickaxe.MiningEntities.Remove(uid);
|
||||
}
|
||||
|
||||
private void OnDoafterCancel(MiningDoafterCancel ev)
|
||||
{
|
||||
if (!TryComp(ev.Pickaxe, out PickaxeComponent? pickaxe))
|
||||
if (!TryComp<PickaxeComponent>(ev.Pickaxe, out var pickaxe))
|
||||
return;
|
||||
|
||||
pickaxe.MiningEntities.Remove(ev.Rock);
|
||||
}
|
||||
|
||||
private sealed class MiningDoafterCancel : EntityEventArgs
|
||||
{
|
||||
public EntityUid Pickaxe;
|
||||
public EntityUid Rock;
|
||||
}
|
||||
}
|
||||
|
||||
// grumble grumble
|
||||
@@ -74,10 +94,6 @@ public sealed class MiningDoafterSuccess : EntityEventArgs
|
||||
{
|
||||
public EntityUid Pickaxe;
|
||||
public EntityUid Rock;
|
||||
public EntityUid Player;
|
||||
}
|
||||
|
||||
public sealed class MiningDoafterCancel : EntityEventArgs
|
||||
{
|
||||
public EntityUid Pickaxe;
|
||||
public EntityUid Rock;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user