1
0

ZombieSystem.Transform.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. using Content.Server.Atmos.Components;
  2. using Content.Server.Body.Components;
  3. using Content.Server.Chat;
  4. using Content.Server.Chat.Managers;
  5. using Content.Server.Ghost.Roles.Components;
  6. using Content.Server.Humanoid;
  7. using Content.Server.IdentityManagement;
  8. using Content.Server.Inventory;
  9. using Content.Server.Mind;
  10. using Content.Server.Mind.Commands;
  11. using Content.Server.NPC;
  12. using Content.Server.NPC.HTN;
  13. using Content.Server.NPC.Systems;
  14. using Content.Server.Speech.Components;
  15. using Content.Server.Temperature.Components;
  16. using Content.Shared.CombatMode;
  17. using Content.Shared.CombatMode.Pacification;
  18. using Content.Shared.Damage;
  19. using Content.Shared.Hands.Components;
  20. using Content.Shared.Hands.EntitySystems;
  21. using Content.Shared.Humanoid;
  22. using Content.Shared.Interaction.Components;
  23. using Content.Shared.Mobs;
  24. using Content.Shared.Mobs.Components;
  25. using Content.Shared.Movement.Pulling.Components;
  26. using Content.Shared.Movement.Systems;
  27. using Content.Shared.NameModifier.EntitySystems;
  28. using Content.Shared.NPC.Systems;
  29. using Content.Shared.Nutrition.AnimalHusbandry;
  30. using Content.Shared.Nutrition.Components;
  31. using Content.Shared.Popups;
  32. using Content.Shared.Weapons.Melee;
  33. using Content.Shared.Zombies;
  34. using Content.Shared.Prying.Components;
  35. using Content.Shared.Traits.Assorted;
  36. using Robust.Shared.Audio.Systems;
  37. using Content.Shared.Ghost.Roles.Components;
  38. using Content.Shared.Tag;
  39. namespace Content.Server.Zombies;
  40. /// <summary>
  41. /// Handles zombie propagation and inherent zombie traits
  42. /// </summary>
  43. /// <remarks>
  44. /// Don't Shitcode Open Inside
  45. /// </remarks>
  46. public sealed partial class ZombieSystem
  47. {
  48. [Dependency] private readonly SharedAudioSystem _audio = default!;
  49. [Dependency] private readonly IChatManager _chatMan = default!;
  50. [Dependency] private readonly SharedCombatModeSystem _combat = default!;
  51. [Dependency] private readonly NpcFactionSystem _faction = default!;
  52. [Dependency] private readonly SharedHandsSystem _hands = default!;
  53. [Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearance = default!;
  54. [Dependency] private readonly IdentitySystem _identity = default!;
  55. [Dependency] private readonly ServerInventorySystem _inventory = default!;
  56. [Dependency] private readonly MindSystem _mind = default!;
  57. [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
  58. [Dependency] private readonly NPCSystem _npc = default!;
  59. [Dependency] private readonly TagSystem _tag = default!;
  60. [Dependency] private readonly NameModifierSystem _nameMod = default!;
  61. /// <summary>
  62. /// Handles an entity turning into a zombie when they die or go into crit
  63. /// </summary>
  64. private void OnDamageChanged(EntityUid uid, ZombifyOnDeathComponent component, MobStateChangedEvent args)
  65. {
  66. if (args.NewMobState == MobState.Dead)
  67. {
  68. ZombifyEntity(uid, args.Component);
  69. }
  70. }
  71. /// <summary>
  72. /// This is the general purpose function to call if you want to zombify an entity.
  73. /// It handles both humanoid and nonhumanoid transformation and everything should be called through it.
  74. /// </summary>
  75. /// <param name="target">the entity being zombified</param>
  76. /// <param name="mobState"></param>
  77. /// <remarks>
  78. /// ALRIGHT BIG BOYS, GIRLS AND ANYONE ELSE. YOU'VE COME TO THE LAYER OF THE BEAST. THIS IS YOUR WARNING.
  79. /// This function is the god function for zombie stuff, and it is cursed. I have
  80. /// attempted to label everything thouroughly for your sanity. I have attempted to
  81. /// rewrite this, but this is how it shall lie eternal. Turn back now.
  82. /// -emo
  83. /// </remarks>
  84. public void ZombifyEntity(EntityUid target, MobStateComponent? mobState = null)
  85. {
  86. //Don't zombfiy zombies
  87. if (HasComp<ZombieComponent>(target) || HasComp<ZombieImmuneComponent>(target))
  88. return;
  89. if (!Resolve(target, ref mobState, logMissing: false))
  90. return;
  91. //you're a real zombie now, son.
  92. var zombiecomp = AddComp<ZombieComponent>(target);
  93. //we need to basically remove all of these because zombies shouldn't
  94. //get diseases, breath, be thirst, be hungry, die in space, have offspring or be paraplegic.
  95. RemComp<RespiratorComponent>(target);
  96. RemComp<BarotraumaComponent>(target);
  97. RemComp<HungerComponent>(target);
  98. RemComp<ThirstComponent>(target);
  99. RemComp<ReproductiveComponent>(target);
  100. RemComp<ReproductivePartnerComponent>(target);
  101. RemComp<LegsParalyzedComponent>(target);
  102. RemComp<ComplexInteractionComponent>(target);
  103. //funny voice
  104. var accentType = "zombie";
  105. if (TryComp<ZombieAccentOverrideComponent>(target, out var accent))
  106. accentType = accent.Accent;
  107. EnsureComp<ReplacementAccentComponent>(target).Accent = accentType;
  108. //This is needed for stupid entities that fuck up combat mode component
  109. //in an attempt to make an entity not attack. This is the easiest way to do it.
  110. var combat = EnsureComp<CombatModeComponent>(target);
  111. RemComp<PacifiedComponent>(target);
  112. _combat.SetCanDisarm(target, false, combat);
  113. _combat.SetInCombatMode(target, true, combat);
  114. //This is the actual damage of the zombie. We assign the visual appearance
  115. //and range here because of stuff we'll find out later
  116. var melee = EnsureComp<MeleeWeaponComponent>(target);
  117. melee.Animation = zombiecomp.AttackAnimation;
  118. melee.WideAnimation = zombiecomp.AttackAnimation;
  119. melee.AltDisarm = false;
  120. melee.Range = 1.2f;
  121. melee.Angle = 0.0f;
  122. melee.HitSound = zombiecomp.BiteSound;
  123. if (mobState.CurrentState == MobState.Alive)
  124. {
  125. // Groaning when damaged
  126. EnsureComp<EmoteOnDamageComponent>(target);
  127. _emoteOnDamage.AddEmote(target, "Scream");
  128. // Random groaning
  129. EnsureComp<AutoEmoteComponent>(target);
  130. _autoEmote.AddEmote(target, "ZombieGroan");
  131. }
  132. //We have specific stuff for humanoid zombies because they matter more
  133. if (TryComp<HumanoidAppearanceComponent>(target, out var huApComp)) //huapcomp
  134. {
  135. //store some values before changing them in case the humanoid get cloned later
  136. zombiecomp.BeforeZombifiedSkinColor = huApComp.SkinColor;
  137. zombiecomp.BeforeZombifiedEyeColor = huApComp.EyeColor;
  138. zombiecomp.BeforeZombifiedCustomBaseLayers = new(huApComp.CustomBaseLayers);
  139. if (TryComp<BloodstreamComponent>(target, out var stream))
  140. zombiecomp.BeforeZombifiedBloodReagent = stream.BloodReagent;
  141. _humanoidAppearance.SetSkinColor(target, zombiecomp.SkinColor, verify: false, humanoid: huApComp);
  142. // Messing with the eye layer made it vanish upon cloning, and also it didn't even appear right
  143. huApComp.EyeColor = zombiecomp.EyeColor;
  144. // this might not resync on clone?
  145. _humanoidAppearance.SetBaseLayerId(target, HumanoidVisualLayers.Tail, zombiecomp.BaseLayerExternal, humanoid: huApComp);
  146. _humanoidAppearance.SetBaseLayerId(target, HumanoidVisualLayers.HeadSide, zombiecomp.BaseLayerExternal, humanoid: huApComp);
  147. _humanoidAppearance.SetBaseLayerId(target, HumanoidVisualLayers.HeadTop, zombiecomp.BaseLayerExternal, humanoid: huApComp);
  148. _humanoidAppearance.SetBaseLayerId(target, HumanoidVisualLayers.Snout, zombiecomp.BaseLayerExternal, humanoid: huApComp);
  149. //This is done here because non-humanoids shouldn't get baller damage
  150. //lord forgive me for the hardcoded damage
  151. DamageSpecifier dspec = new()
  152. {
  153. DamageDict = new()
  154. {
  155. { "Slash", 13 },
  156. { "Piercing", 7 },
  157. { "Structural", 10 }
  158. }
  159. };
  160. melee.Damage = dspec;
  161. // humanoid zombies get to pry open doors and shit
  162. var pryComp = EnsureComp<PryingComponent>(target);
  163. pryComp.SpeedModifier = 0.75f;
  164. pryComp.PryPowered = true;
  165. pryComp.Force = true;
  166. Dirty(target, pryComp);
  167. }
  168. Dirty(target, melee);
  169. //The zombie gets the assigned damage weaknesses and strengths
  170. _damageable.SetDamageModifierSetId(target, "Zombie");
  171. //This makes it so the zombie doesn't take bloodloss damage.
  172. //NOTE: they are supposed to bleed, just not take damage
  173. _bloodstream.SetBloodLossThreshold(target, 0f);
  174. //Give them zombie blood
  175. _bloodstream.ChangeBloodReagent(target, zombiecomp.NewBloodReagent);
  176. //This is specifically here to combat insuls, because frying zombies on grilles is funny as shit.
  177. _inventory.TryUnequip(target, "gloves", true, true);
  178. //Should prevent instances of zombies using comms for information they shouldnt be able to have.
  179. _inventory.TryUnequip(target, "ears", true, true);
  180. //popup
  181. _popup.PopupEntity(Loc.GetString("zombie-transform", ("target", target)), target, PopupType.LargeCaution);
  182. //Make it sentient if it's an animal or something
  183. MakeSentientCommand.MakeSentient(target, EntityManager);
  184. //Make the zombie not die in the cold. Good for space zombies
  185. if (TryComp<TemperatureComponent>(target, out var tempComp))
  186. tempComp.ColdDamage.ClampMax(0);
  187. //Heals the zombie from all the damage it took while human
  188. if (TryComp<DamageableComponent>(target, out var damageablecomp))
  189. _damageable.SetAllDamage(target, damageablecomp, 0);
  190. _mobState.ChangeMobState(target, MobState.Alive);
  191. _faction.ClearFactions(target, dirty: false);
  192. _faction.AddFaction(target, "Zombie");
  193. //gives it the funny "Zombie ___" name.
  194. _nameMod.RefreshNameModifiers(target);
  195. _identity.QueueIdentityUpdate(target);
  196. var htn = EnsureComp<HTNComponent>(target);
  197. htn.RootTask = new HTNCompoundTask() { Task = "SimpleHostileCompound" };
  198. htn.Blackboard.SetValue(NPCBlackboard.Owner, target);
  199. _npc.SleepNPC(target, htn);
  200. //He's gotta have a mind
  201. var hasMind = _mind.TryGetMind(target, out var mindId, out _);
  202. if (hasMind && _mind.TryGetSession(mindId, out var session))
  203. {
  204. //Zombie role for player manifest
  205. _role.MindAddRole(mindId, "MindRoleZombie", mind: null, silent: true);
  206. //Greeting message for new bebe zombers
  207. _chatMan.DispatchServerMessage(session, Loc.GetString("zombie-infection-greeting"));
  208. }
  209. else
  210. {
  211. _npc.WakeNPC(target, htn);
  212. }
  213. if (!HasComp<GhostRoleMobSpawnerComponent>(target) && !hasMind) //this specific component gives build test trouble so pop off, ig
  214. {
  215. //yet more hardcoding. Visit zombie.ftl for more information.
  216. var ghostRole = EnsureComp<GhostRoleComponent>(target);
  217. EnsureComp<GhostTakeoverAvailableComponent>(target);
  218. ghostRole.RoleName = Loc.GetString("zombie-generic");
  219. ghostRole.RoleDescription = Loc.GetString("zombie-role-desc");
  220. ghostRole.RoleRules = Loc.GetString("zombie-role-rules");
  221. }
  222. if (TryComp<HandsComponent>(target, out var handsComp))
  223. {
  224. _hands.RemoveHands(target);
  225. RemComp(target, handsComp);
  226. }
  227. // Sloth: What the fuck?
  228. // How long until compregistry lmao.
  229. RemComp<PullerComponent>(target);
  230. // No longer waiting to become a zombie:
  231. // Requires deferral because this is (probably) the event which called ZombifyEntity in the first place.
  232. RemCompDeferred<PendingZombieComponent>(target);
  233. //zombie gamemode stuff
  234. var ev = new EntityZombifiedEvent(target);
  235. RaiseLocalEvent(target, ref ev, true);
  236. //zombies get slowdown once they convert
  237. _movementSpeedModifier.RefreshMovementSpeedModifiers(target);
  238. //Need to prevent them from getting an item, they have no hands.
  239. // Also prevents them from becoming a Survivor. They're undead.
  240. _tag.AddTag(target, "InvalidForGlobalSpawnSpell");
  241. }
  242. }