CreateEntityReactionEffect.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Content.Shared.EntityEffects;
  2. using Robust.Shared.Prototypes;
  3. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  4. namespace Content.Server.EntityEffects.Effects;
  5. [DataDefinition]
  6. public sealed partial class CreateEntityReactionEffect : EntityEffect
  7. {
  8. /// <summary>
  9. /// What entity to create.
  10. /// </summary>
  11. [DataField(required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
  12. public string Entity = default!;
  13. /// <summary>
  14. /// How many entities to create per unit reaction.
  15. /// </summary>
  16. [DataField]
  17. public uint Number = 1;
  18. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  19. => Loc.GetString("reagent-effect-guidebook-create-entity-reaction-effect",
  20. ("chance", Probability),
  21. ("entname", IoCManager.Resolve<IPrototypeManager>().Index<EntityPrototype>(Entity).Name),
  22. ("amount", Number));
  23. public override void Effect(EntityEffectBaseArgs args)
  24. {
  25. var transform = args.EntityManager.GetComponent<TransformComponent>(args.TargetEntity);
  26. var transformSystem = args.EntityManager.System<SharedTransformSystem>();
  27. var quantity = (int)Number;
  28. if (args is EntityEffectReagentArgs reagentArgs)
  29. quantity *= reagentArgs.Quantity.Int();
  30. for (var i = 0; i < quantity; i++)
  31. {
  32. var uid = args.EntityManager.SpawnEntity(Entity, transformSystem.GetMapCoordinates(args.TargetEntity, xform: transform));
  33. transformSystem.AttachToGridOrMap(uid);
  34. // TODO figure out how to properly spawn inside of containers
  35. // e.g. cheese:
  36. // if the user is holding a bowl milk & enzyme, should drop to floor, not attached to the user.
  37. // if reaction happens in a backpack, should insert cheese into backpack.
  38. // --> if it doesn't fit, iterate through parent storage until it attaches to the grid (again, DON'T attach to players).
  39. // if the reaction happens INSIDE a stomach? the bloodstream? I have no idea how to handle that.
  40. // presumably having cheese materialize inside of your blood would have "disadvantages".
  41. }
  42. }
  43. }