Files

105 lines
4.0 KiB
C#
Raw Permalink Normal View History

using Content.Server.Explosion.EntitySystems;
using Content.Server.Pointing.Components;
using Content.Shared.Pointing.Components;
using JetBrains.Annotations;
using Robust.Shared.Random;
2021-06-09 22:19:39 +02:00
namespace Content.Server.Pointing.EntitySystems
{
[UsedImplicitly]
internal sealed class RoguePointingSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
Explosion refactor (#5230) * Explosions * fix yaml typo and prevent silly UI inputs * oop * Use modified contains() checks And remove IEnumerable * Buff nuke, nerf meteors * optimize the entity lookup stuff a bit * fix tile (0,0) error forgot to do an initial Enumerator.MoveNext(), so the first tile was always the "null" tile. * remove celebration * byte -> int * remove diag edge tile dict * fix one bug but there is another * fix the other bug turns out dividing a ushort leads to rounding errors. Why TF is the grid tile size even a ushort in the first place. * improve edge map * fix minor bug If the initial-explosion tile had an airtight entity on it, the tile was processed twice. * some reviews (transform queries, eye.mapid, and tilesizes in overlays) * Apply suggestions from code review Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * is map paused * GetAllTiles ignores space by default * WriteLine -> WriteError * First -> FirstOrDefault() * default prototype const string * entity query * misc review changes * grid edge max distance * fix fire texture defn bad use of type serializer and ioc-resolves * Remove ExplosionLaunched And allow nukes to throw items towards the outer part of an explosion * no hot-reload disclaimer * replace prototype id string with int index * optimise damage a tiiiiny bit. * entity queries * comments * misc mirror comments * cvars * admin logs * move intensity-per-state to prototype * update tile event to ECS event * git mv * Tweak rpg & minibomb also fix merge bug * you don't exist anymore go away * Fix build Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-04-01 15:39:26 +13:00
[Dependency] private readonly ExplosionSystem _explosion = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
2021-12-06 00:52:58 +01:00
private EntityUid? RandomNearbyPlayer(EntityUid uid, RoguePointingArrowComponent? component = null, TransformComponent? transform = null)
{
if (!Resolve(uid, ref component, ref transform))
return null;
var targets = new List<Entity<PointingArrowAngeringComponent>>();
var query = EntityQueryEnumerator<PointingArrowAngeringComponent>();
while (query.MoveNext(out var angeringUid, out var angeringComp))
{
targets.Add((angeringUid, angeringComp));
}
if (targets.Count == 0)
return null;
var angering = _random.Pick(targets);
angering.Comp.RemainingAnger -= 1;
if (angering.Comp.RemainingAnger <= 0)
RemComp<PointingArrowAngeringComponent>(uid);
return angering.Owner;
}
private void UpdateAppearance(EntityUid uid, RoguePointingArrowComponent? component = null, TransformComponent? transform = null, AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref component, ref transform, ref appearance) || component.Chasing == null)
return;
_appearance.SetData(uid, RoguePointingArrowVisuals.Rotation, transform.LocalRotation.Degrees, appearance);
}
public void SetTarget(EntityUid arrow, EntityUid target, RoguePointingArrowComponent? component = null)
{
if (!Resolve(arrow, ref component))
throw new ArgumentException("Input was not a rogue pointing arrow!", nameof(arrow));
component.Chasing = target;
}
public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<RoguePointingArrowComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var component, out var transform))
{
component.Chasing ??= RandomNearbyPlayer(uid, component, transform);
if (component.Chasing is not {Valid: true} chasing || Deleted(chasing))
{
EntityManager.QueueDeleteEntity(uid);
2022-09-17 00:37:15 +10:00
continue;
}
component.TurningDelay -= frameTime;
if (component.TurningDelay > 0)
{
var difference = Comp<TransformComponent>(chasing).WorldPosition - transform.WorldPosition;
var angle = difference.ToAngle();
var adjusted = angle.Degrees + 90;
var newAngle = Angle.FromDegrees(adjusted);
transform.WorldRotation = newAngle;
UpdateAppearance(uid, component, transform);
2022-09-17 00:37:15 +10:00
continue;
}
transform.WorldRotation += Angle.FromDegrees(20);
UpdateAppearance(uid, component, transform);
var toChased = Comp<TransformComponent>(chasing).WorldPosition - transform.WorldPosition;
transform.WorldPosition += toChased * frameTime * component.ChasingSpeed;
component.ChasingTime -= frameTime;
if (component.ChasingTime > 0)
{
2022-09-17 00:37:15 +10:00
continue;
}
2022-09-17 00:37:15 +10:00
Explosion refactor (#5230) * Explosions * fix yaml typo and prevent silly UI inputs * oop * Use modified contains() checks And remove IEnumerable * Buff nuke, nerf meteors * optimize the entity lookup stuff a bit * fix tile (0,0) error forgot to do an initial Enumerator.MoveNext(), so the first tile was always the "null" tile. * remove celebration * byte -> int * remove diag edge tile dict * fix one bug but there is another * fix the other bug turns out dividing a ushort leads to rounding errors. Why TF is the grid tile size even a ushort in the first place. * improve edge map * fix minor bug If the initial-explosion tile had an airtight entity on it, the tile was processed twice. * some reviews (transform queries, eye.mapid, and tilesizes in overlays) * Apply suggestions from code review Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * is map paused * GetAllTiles ignores space by default * WriteLine -> WriteError * First -> FirstOrDefault() * default prototype const string * entity query * misc review changes * grid edge max distance * fix fire texture defn bad use of type serializer and ioc-resolves * Remove ExplosionLaunched And allow nukes to throw items towards the outer part of an explosion * no hot-reload disclaimer * replace prototype id string with int index * optimise damage a tiiiiny bit. * entity queries * comments * misc mirror comments * cvars * admin logs * move intensity-per-state to prototype * update tile event to ECS event * git mv * Tweak rpg & minibomb also fix merge bug * you don't exist anymore go away * Fix build Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-04-01 15:39:26 +13:00
_explosion.QueueExplosion(uid, ExplosionSystem.DefaultExplosionPrototypeId, 50, 3, 10);
EntityManager.QueueDeleteEntity(uid);
}
}
}
}