+using Content.Shared.EntityList;
using Content.Shared.Whitelist;
+using Robust.Shared.Prototypes;
namespace Content.Server.Gatherable.Components;
/// Whitelist for specifying the kind of tools can be used on a resource
/// Supports multiple tags.
/// </summary>
- [DataField("whitelist", required: true)]
+ [DataField(required: true)]
public EntityWhitelist? ToolWhitelist;
/// <summary>
/// (Tag1, Tag2, LootTableID1, LootTableID2 are placeholders for example)
/// --------------------
/// useMappedLoot: true
- /// whitelist:
+ /// toolWhitelist:
/// tags:
/// - Tag1
/// - Tag2
- /// mappedLoot:
+ /// loot:
/// Tag1: LootTableID1
/// Tag2: LootTableID2
/// </summary>
- [DataField("loot")]
- public Dictionary<string, string>? MappedLoot = new();
+ [DataField]
+ public Dictionary<string, ProtoId<EntityLootTablePrototype>>? Loot = new();
+
+ /// <summary>
+ /// Random shift of the appearing entity during gathering
+ /// </summary>
+ [DataField]
+ public float GatherOffset = 0.3f;
}
using Content.Server.Gatherable.Components;
-using Content.Server.Projectiles;
using Content.Shared.Projectiles;
-using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Physics.Events;
namespace Content.Server.Gatherable;
SubscribeLocalEvent<GatheringProjectileComponent, StartCollideEvent>(OnProjectileCollide);
}
- private void OnProjectileCollide(EntityUid uid, GatheringProjectileComponent component, ref StartCollideEvent args)
+ private void OnProjectileCollide(Entity<GatheringProjectileComponent> gathering, ref StartCollideEvent args)
{
if (!args.OtherFixture.Hard ||
args.OurFixtureId != SharedProjectileSystem.ProjectileFixture ||
- component.Amount <= 0 ||
+ gathering.Comp.Amount <= 0 ||
!TryComp<GatherableComponent>(args.OtherEntity, out var gatherable))
{
return;
}
- Gather(args.OtherEntity, uid, gatherable);
- component.Amount--;
+ Gather(args.OtherEntity, gathering, gatherable);
+ gathering.Comp.Amount--;
- if (component.Amount <= 0)
- QueueDel(uid);
+ if (gathering.Comp.Amount <= 0)
+ QueueDel(gathering);
}
}
using Content.Server.Destructible;
using Content.Server.Gatherable.Components;
-using Content.Shared.EntityList;
using Content.Shared.Interaction;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee.Events;
using Robust.Server.GameObjects;
-using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
public sealed partial class GatherableSystem : EntitySystem
{
- [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+ [Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly DestructibleSystem _destructible = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
InitializeProjectile();
}
- private void OnAttacked(EntityUid uid, GatherableComponent component, AttackedEvent args)
+ private void OnAttacked(Entity<GatherableComponent> gatherable, ref AttackedEvent args)
{
- if (component.ToolWhitelist?.IsValid(args.Used, EntityManager) != true)
+ if (gatherable.Comp.ToolWhitelist?.IsValid(args.Used, EntityManager) != true)
return;
- Gather(uid, args.User, component);
+ Gather(gatherable, args.User);
}
- private void OnActivate(EntityUid uid, GatherableComponent component, ActivateInWorldEvent args)
+ private void OnActivate(Entity<GatherableComponent> gatherable, ref ActivateInWorldEvent args)
{
- if (component.ToolWhitelist?.IsValid(args.User, EntityManager) != true)
+ if (gatherable.Comp.ToolWhitelist?.IsValid(args.User, EntityManager) != true)
return;
- Gather(uid, args.User, component);
+ Gather(gatherable, args.User);
}
public void Gather(EntityUid gatheredUid, EntityUid? gatherer = null, GatherableComponent? component = null)
_destructible.DestroyEntity(gatheredUid);
// Spawn the loot!
- if (component.MappedLoot == null)
+ if (component.Loot == null)
return;
var pos = _transform.GetMapCoordinates(gatheredUid);
- foreach (var (tag, table) in component.MappedLoot)
+ foreach (var (tag, table) in component.Loot)
{
if (tag != "All")
{
if (gatherer != null && !_tagSystem.HasTag(gatherer.Value, tag))
continue;
}
- var getLoot = _prototypeManager.Index<EntityLootTablePrototype>(table);
+ var getLoot = _proto.Index(table);
var spawnLoot = getLoot.GetSpawns(_random);
- var spawnPos = pos.Offset(_random.NextVector2(0.3f));
+ var spawnPos = pos.Offset(_random.NextVector2(component.GatherOffset));
Spawn(spawnLoot[0], spawnPos);
}
}
}
-
-
-