OrganType.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Content.Server.Body.Components;
  2. using Content.Shared.Body.Prototypes;
  3. using Content.Shared.EntityEffects;
  4. using Robust.Shared.Prototypes;
  5. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  6. namespace Content.Server.EntityEffects.EffectConditions;
  7. /// <summary>
  8. /// Requires that the metabolizing organ is or is not tagged with a certain MetabolizerType
  9. /// </summary>
  10. public sealed partial class OrganType : EntityEffectCondition
  11. {
  12. [DataField(required: true, customTypeSerializer: typeof(PrototypeIdSerializer<MetabolizerTypePrototype>))]
  13. public string Type = default!;
  14. /// <summary>
  15. /// Does this condition pass when the organ has the type, or when it doesn't have the type?
  16. /// </summary>
  17. [DataField]
  18. public bool ShouldHave = true;
  19. public override bool Condition(EntityEffectBaseArgs args)
  20. {
  21. if (args is EntityEffectReagentArgs reagentArgs)
  22. {
  23. if (reagentArgs.OrganEntity == null)
  24. return false;
  25. return Condition(reagentArgs.OrganEntity.Value, reagentArgs.EntityManager);
  26. }
  27. // TODO: Someone needs to figure out how to do this for non-reagent effects.
  28. throw new NotImplementedException();
  29. }
  30. public bool Condition(Entity<MetabolizerComponent?> metabolizer, IEntityManager entMan)
  31. {
  32. metabolizer.Comp ??= entMan.GetComponentOrNull<MetabolizerComponent>(metabolizer.Owner);
  33. if (metabolizer.Comp != null
  34. && metabolizer.Comp.MetabolizerTypes != null
  35. && metabolizer.Comp.MetabolizerTypes.Contains(Type))
  36. return ShouldHave;
  37. return !ShouldHave;
  38. }
  39. public override string GuidebookExplanation(IPrototypeManager prototype)
  40. {
  41. return Loc.GetString("reagent-effect-condition-guidebook-organ-type",
  42. ("name", prototype.Index<MetabolizerTypePrototype>(Type).LocalizedName),
  43. ("shouldhave", ShouldHave));
  44. }
  45. }