Mime cleanup (#8433)

This commit is contained in:
metalgearsloth
2022-05-25 17:43:48 +10:00
committed by GitHub
parent d79da62a95
commit 495a65bc6d
6 changed files with 51 additions and 39 deletions

View File

@@ -349,6 +349,7 @@ namespace Content.Client.Entry
"Artifact", "Artifact",
"RandomArtifactSprite", "RandomArtifactSprite",
"EnergySword", "EnergySword",
"DeleteAfterTime",
"MeleeSound", "MeleeSound",
"RangedDamageSound", "RangedDamageSound",
"DoorRemote", "DoorRemote",

View File

@@ -1,12 +0,0 @@
namespace Content.Server.Abilities.Mime
{
// Tracks invisible wall despawning
[RegisterComponent]
public sealed class InvisibleWallComponent : Component
{
[DataField("accumulator")]
public float Accumulator = 0f;
[DataField("despawnTime")]
public TimeSpan DespawnTime = TimeSpan.FromSeconds(30);
}
}

View File

@@ -28,27 +28,16 @@ namespace Content.Server.Abilities.Mime
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
base.Update(frameTime); base.Update(frameTime);
/// Queue to despawn invis walls // Queue to track whether mimes can retake vows yet
foreach (var invisWall in EntityQuery<InvisibleWallComponent>())
{
invisWall.Accumulator += frameTime;
if (invisWall.Accumulator < invisWall.DespawnTime.TotalSeconds)
{
continue;
}
EntityManager.QueueDeleteEntity(invisWall.Owner);
}
/// Queue to track whether mimes can retake vows yet
foreach (var mime in EntityQuery<MimePowersComponent>()) foreach (var mime in EntityQuery<MimePowersComponent>())
{ {
if (!mime.VowBroken || mime.ReadyToRepent) if (!mime.VowBroken || mime.ReadyToRepent)
return; continue;
mime.Accumulator += frameTime; mime.Accumulator += frameTime;
if (mime.Accumulator < mime.VowCooldown.TotalSeconds) if (mime.Accumulator < mime.VowCooldown.TotalSeconds)
{
continue; continue;
}
mime.ReadyToRepent = true; mime.ReadyToRepent = true;
_popupSystem.PopupEntity(Loc.GetString("mime-ready-to-repent"), mime.Owner, Filter.Entities(mime.Owner)); _popupSystem.PopupEntity(Loc.GetString("mime-ready-to-repent"), mime.Owner, Filter.Entities(mime.Owner));
} }
@@ -77,14 +66,14 @@ namespace Content.Server.Abilities.Mime
return; return;
var xform = Transform(uid); var xform = Transform(uid);
/// Get the tile in front of the mime // Get the tile in front of the mime
var offsetValue = xform.LocalRotation.ToWorldVec().Normalized; var offsetValue = xform.LocalRotation.ToWorldVec().Normalized;
var coords = xform.Coordinates.Offset(offsetValue).SnapToGrid(); var coords = xform.Coordinates.Offset(offsetValue).SnapToGrid(EntityManager);
/// Check there are no walls or mobs there // Check there are no walls or mobs there
foreach (var entity in coords.GetEntitiesInTile()) foreach (var entity in coords.GetEntitiesInTile())
{ {
IPhysBody? physics = null; /// We use this to check if it's impassable IPhysBody? physics = null; // We use this to check if it's impassable
if ((HasComp<MobStateComponent>(entity) && entity != uid) || /// Is it a mob? if ((HasComp<MobStateComponent>(entity) && entity != uid) || // Is it a mob?
((Resolve(entity, ref physics, false) && (physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0) // Is it impassable? ((Resolve(entity, ref physics, false) && (physics.CollisionLayer & (int) CollisionGroup.Impassable) != 0) // Is it impassable?
&& !(TryComp<DoorComponent>(entity, out var door) && door.State != DoorState.Closed))) // Is it a door that's open and so not actually impassable? && !(TryComp<DoorComponent>(entity, out var door) && door.State != DoorState.Closed))) // Is it a door that's open and so not actually impassable?
{ {
@@ -93,10 +82,9 @@ namespace Content.Server.Abilities.Mime
} }
} }
_popupSystem.PopupEntity(Loc.GetString("mime-invisible-wall-popup", ("mime", uid)), uid, Filter.Pvs(uid)); _popupSystem.PopupEntity(Loc.GetString("mime-invisible-wall-popup", ("mime", uid)), uid, Filter.Pvs(uid));
/// Make sure we set the invisible wall to despawn properly // Make sure we set the invisible wall to despawn properly
var wall = EntityManager.SpawnEntity(component.WallPrototype, coords); Spawn(component.WallPrototype, coords);
EnsureComp<InvisibleWallComponent>(wall); // Handle args so cooldown works
/// Handle args so cooldown works
args.Handled = true; args.Handled = true;
} }

View File

@@ -0,0 +1,15 @@
namespace Content.Server.Delete
{
/// <summary>
/// Deletes the entity after the specified period of time.
/// </summary>
[RegisterComponent]
public sealed class DeleteAfterTimeComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("accumulator")]
public float Accumulator = 0f;
[ViewVariables(VVAccess.ReadWrite), DataField("despawnTime")]
public TimeSpan DespawnTime = TimeSpan.FromSeconds(30);
}
}

View File

@@ -0,0 +1,18 @@
namespace Content.Server.Delete;
public sealed class DeleteAfterTimeSystem : EntitySystem
{
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var comp in EntityQuery<DeleteAfterTimeComponent>())
{
comp.Accumulator += frameTime;
if (comp.Accumulator < comp.DespawnTime.TotalSeconds)
continue;
QueueDel(comp.Owner);
}
}
}

View File

@@ -649,7 +649,7 @@
parent: WallBase parent: WallBase
id: WallVaultAlien id: WallVaultAlien
name: alien vault wall name: alien vault wall
description: A mysterious ornate looking wall. There may be ancient dangers inside. description: A mysterious ornate looking wall. There may be ancient dangers inside.
components: components:
- type: Sprite - type: Sprite
sprite: Structures/Walls/vault.rsi sprite: Structures/Walls/vault.rsi
@@ -665,7 +665,7 @@
behaviors: behaviors:
- !type:DoActsBehavior - !type:DoActsBehavior
acts: [ "Destruction" ] acts: [ "Destruction" ]
- type: entity - type: entity
parent: WallVaultAlien parent: WallVaultAlien
id: WallVaultRock id: WallVaultRock
@@ -677,7 +677,7 @@
- type: Icon - type: Icon
sprite: Structures/Walls/vault.rsi sprite: Structures/Walls/vault.rsi
state: rockvault state: rockvault
- type: entity - type: entity
parent: WallVaultAlien parent: WallVaultAlien
id: WallVaultSandstone id: WallVaultSandstone
@@ -697,6 +697,8 @@
id: WallInvisible id: WallInvisible
name: Invisible Wall name: Invisible Wall
components: components:
- type: DeleteAfterTime
despawnTime: 30
- type: Tag - type: Tag
tags: tags:
- Wall - Wall
@@ -711,4 +713,4 @@
- FullTileMask - FullTileMask
layer: layer:
- GlassLayer - GlassLayer
- type: Airtight - type: Airtight