Allow PKA to gather (#16250)
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Content.Server.Gatherable.Components;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Destroys a gatherable entity when colliding with it.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class GatheringProjectileComponent : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
28
Content.Server/Gatherable/GatherableSystem.Projectile.cs
Normal file
28
Content.Server/Gatherable/GatherableSystem.Projectile.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public sealed partial class GatherableSystem
|
||||||
|
{
|
||||||
|
private void InitializeProjectile()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<GatheringProjectileComponent, StartCollideEvent>(OnProjectileCollide);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnProjectileCollide(EntityUid uid, GatheringProjectileComponent component, ref StartCollideEvent args)
|
||||||
|
{
|
||||||
|
if (!args.OtherFixture.Hard ||
|
||||||
|
args.OurFixture.ID != SharedProjectileSystem.ProjectileFixture ||
|
||||||
|
!TryComp<GatherableComponent>(args.OtherEntity, out var gatherable))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gather(args.OtherEntity, uid, gatherable);
|
||||||
|
QueueDel(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,18 +5,20 @@ using Content.Shared.EntityList;
|
|||||||
using Content.Shared.Gatherable;
|
using Content.Shared.Gatherable;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Tag;
|
using Content.Shared.Tag;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
namespace Content.Server.Gatherable;
|
namespace Content.Server.Gatherable;
|
||||||
|
|
||||||
public sealed class GatherableSystem : EntitySystem
|
public sealed partial class GatherableSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly DestructibleSystem _destructible = default!;
|
[Dependency] private readonly DestructibleSystem _destructible = default!;
|
||||||
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -25,6 +27,7 @@ public sealed class GatherableSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<GatherableComponent, InteractUsingEvent>(OnInteractUsing);
|
SubscribeLocalEvent<GatherableComponent, InteractUsingEvent>(OnInteractUsing);
|
||||||
SubscribeLocalEvent<GatherableComponent, GatherableDoAfterEvent>(OnDoAfter);
|
SubscribeLocalEvent<GatherableComponent, GatherableDoAfterEvent>(OnDoAfter);
|
||||||
|
InitializeProjectile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInteractUsing(EntityUid uid, GatherableComponent component, InteractUsingEvent args)
|
private void OnInteractUsing(EntityUid uid, GatherableComponent component, InteractUsingEvent args)
|
||||||
@@ -53,36 +56,44 @@ public sealed class GatherableSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnDoAfter(EntityUid uid, GatherableComponent component, GatherableDoAfterEvent args)
|
private void OnDoAfter(EntityUid uid, GatherableComponent component, GatherableDoAfterEvent args)
|
||||||
{
|
{
|
||||||
if(!TryComp<GatheringToolComponent>(args.Args.Used, out var tool) || args.Args.Target == null)
|
if(!TryComp<GatheringToolComponent>(args.Args.Used, out var tool))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tool.GatheringEntities.Remove(args.Args.Target.Value);
|
tool.GatheringEntities.Remove(uid);
|
||||||
if (args.Handled || args.Cancelled)
|
if (args.Handled || args.Cancelled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Gather(uid, args.Args.Used, component, tool.GatheringSound);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Gather(EntityUid gatheredUid, EntityUid? gatherer = null, GatherableComponent? component = null, SoundSpecifier? sound = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(gatheredUid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
// Complete the gathering process
|
// Complete the gathering process
|
||||||
_destructible.DestroyEntity(args.Args.Target.Value);
|
_destructible.DestroyEntity(gatheredUid);
|
||||||
_audio.PlayPvs(tool.GatheringSound, args.Args.Target.Value);
|
_audio.PlayPvs(sound, gatheredUid);
|
||||||
|
|
||||||
// Spawn the loot!
|
// Spawn the loot!
|
||||||
if (component.MappedLoot == null)
|
if (component.MappedLoot == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var playerPos = Transform(args.Args.User).MapPosition;
|
var pos = Transform(gatheredUid).MapPosition;
|
||||||
|
|
||||||
foreach (var (tag, table) in component.MappedLoot)
|
foreach (var (tag, table) in component.MappedLoot)
|
||||||
{
|
{
|
||||||
if (tag != "All")
|
if (tag != "All")
|
||||||
{
|
{
|
||||||
if (!_tagSystem.HasTag(tool.Owner, tag))
|
if (gatherer != null && !_tagSystem.HasTag(gatherer.Value, tag))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var getLoot = _prototypeManager.Index<EntityLootTablePrototype>(table);
|
var getLoot = _prototypeManager.Index<EntityLootTablePrototype>(table);
|
||||||
var spawnLoot = getLoot.GetSpawns();
|
var spawnLoot = getLoot.GetSpawns();
|
||||||
var spawnPos = playerPos.Offset(_random.NextVector2(0.3f));
|
var spawnPos = pos.Offset(_random.NextVector2(0.3f));
|
||||||
Spawn(spawnLoot[0], spawnPos);
|
Spawn(spawnLoot[0], spawnPos);
|
||||||
}
|
}
|
||||||
args.Handled = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public abstract class SharedDestructibleSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
var eventArgs = new DestructionEventArgs();
|
var eventArgs = new DestructionEventArgs();
|
||||||
|
|
||||||
RaiseLocalEvent(owner, eventArgs, false);
|
RaiseLocalEvent(owner, eventArgs);
|
||||||
QueueDel(owner);
|
QueueDel(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public abstract class SharedDestructibleSystem : EntitySystem
|
|||||||
public void BreakEntity(EntityUid owner)
|
public void BreakEntity(EntityUid owner)
|
||||||
{
|
{
|
||||||
var eventArgs = new BreakageEventArgs();
|
var eventArgs = new BreakageEventArgs();
|
||||||
RaiseLocalEvent(owner, eventArgs, false);
|
RaiseLocalEvent(owner, eventArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -294,12 +294,12 @@
|
|||||||
description: Not too bad, but you still don't want to get hit by it.
|
description: Not too bad, but you still don't want to get hit by it.
|
||||||
components:
|
components:
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
netsync: false
|
|
||||||
noRot: false
|
noRot: false
|
||||||
sprite: Objects/Weapons/Guns/Projectiles/magic.rsi
|
sprite: Objects/Weapons/Guns/Projectiles/magic.rsi
|
||||||
layers:
|
layers:
|
||||||
- state: chronobolt
|
- state: chronobolt
|
||||||
shader: unshaded
|
shader: unshaded
|
||||||
|
- type: GatheringProjectile
|
||||||
- type: Projectile
|
- type: Projectile
|
||||||
impactEffect: BulletImpactEffectKinetic
|
impactEffect: BulletImpactEffectKinetic
|
||||||
damage:
|
damage:
|
||||||
|
|||||||
Reference in New Issue
Block a user