1
0

ChameleonProjectorSystem.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Content.Client.Effects;
  2. using Content.Client.Smoking;
  3. using Content.Shared.Chemistry.Components;
  4. using Content.Shared.Polymorph.Components;
  5. using Content.Shared.Polymorph.Systems;
  6. using Robust.Client.GameObjects;
  7. using Robust.Shared.Player;
  8. namespace Content.Client.Polymorph.Systems;
  9. public sealed class ChameleonProjectorSystem : SharedChameleonProjectorSystem
  10. {
  11. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  12. private EntityQuery<AppearanceComponent> _appearanceQuery;
  13. private EntityQuery<SpriteComponent> _spriteQuery;
  14. public override void Initialize()
  15. {
  16. base.Initialize();
  17. _appearanceQuery = GetEntityQuery<AppearanceComponent>();
  18. _spriteQuery = GetEntityQuery<SpriteComponent>();
  19. SubscribeLocalEvent<ChameleonDisguiseComponent, AfterAutoHandleStateEvent>(OnHandleState);
  20. SubscribeLocalEvent<ChameleonDisguisedComponent, ComponentStartup>(OnStartup);
  21. SubscribeLocalEvent<ChameleonDisguisedComponent, ComponentShutdown>(OnShutdown);
  22. SubscribeLocalEvent<ChameleonDisguisedComponent, GetFlashEffectTargetEvent>(OnGetFlashEffectTargetEvent);
  23. }
  24. private void OnHandleState(Entity<ChameleonDisguiseComponent> ent, ref AfterAutoHandleStateEvent args)
  25. {
  26. CopyComp<SpriteComponent>(ent);
  27. CopyComp<GenericVisualizerComponent>(ent);
  28. CopyComp<SolutionContainerVisualsComponent>(ent);
  29. CopyComp<BurnStateVisualsComponent>(ent);
  30. // reload appearance to hopefully prevent any invisible layers
  31. if (_appearanceQuery.TryComp(ent, out var appearance))
  32. _appearance.QueueUpdate(ent, appearance);
  33. }
  34. private void OnStartup(Entity<ChameleonDisguisedComponent> ent, ref ComponentStartup args)
  35. {
  36. if (!_spriteQuery.TryComp(ent, out var sprite))
  37. return;
  38. ent.Comp.WasVisible = sprite.Visible;
  39. sprite.Visible = false;
  40. }
  41. private void OnShutdown(Entity<ChameleonDisguisedComponent> ent, ref ComponentShutdown args)
  42. {
  43. if (_spriteQuery.TryComp(ent, out var sprite))
  44. sprite.Visible = ent.Comp.WasVisible;
  45. }
  46. private void OnGetFlashEffectTargetEvent(Entity<ChameleonDisguisedComponent> ent, ref GetFlashEffectTargetEvent args)
  47. {
  48. args.Target = ent.Comp.Disguise;
  49. }
  50. }