1
0

ZombieSystem.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Linq;
  2. using Content.Shared.Ghost;
  3. using Content.Shared.Humanoid;
  4. using Content.Shared.StatusIcon;
  5. using Content.Shared.StatusIcon.Components;
  6. using Content.Shared.Zombies;
  7. using Robust.Client.GameObjects;
  8. using Robust.Shared.Prototypes;
  9. namespace Content.Client.Zombies;
  10. public sealed class ZombieSystem : SharedZombieSystem
  11. {
  12. [Dependency] private readonly IPrototypeManager _prototype = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<ZombieComponent, ComponentStartup>(OnStartup);
  17. SubscribeLocalEvent<ZombieComponent, GetStatusIconsEvent>(GetZombieIcon);
  18. SubscribeLocalEvent<InitialInfectedComponent, GetStatusIconsEvent>(GetInitialInfectedIcon);
  19. }
  20. private void GetZombieIcon(Entity<ZombieComponent> ent, ref GetStatusIconsEvent args)
  21. {
  22. var iconPrototype = _prototype.Index(ent.Comp.StatusIcon);
  23. args.StatusIcons.Add(iconPrototype);
  24. }
  25. private void GetInitialInfectedIcon(Entity<InitialInfectedComponent> ent, ref GetStatusIconsEvent args)
  26. {
  27. if (HasComp<ZombieComponent>(ent))
  28. return;
  29. var iconPrototype = _prototype.Index(ent.Comp.StatusIcon);
  30. args.StatusIcons.Add(iconPrototype);
  31. }
  32. private void OnStartup(EntityUid uid, ZombieComponent component, ComponentStartup args)
  33. {
  34. if (HasComp<HumanoidAppearanceComponent>(uid))
  35. return;
  36. if (!TryComp<SpriteComponent>(uid, out var sprite))
  37. return;
  38. for (var i = 0; i < sprite.AllLayers.Count(); i++)
  39. {
  40. sprite.LayerSetColor(i, component.SkinColor);
  41. }
  42. }
  43. }