Entity effects ECS refactor (#40580)

* LOCKED THE FUCK IN

* Forgot this little fella

* Crying

* All entity effects ported, needs cleanup still

* Commit

* HEHEHEHAW

* Shelve for now

* fixe

* Big

* First big chunk of changes

* Big if true

* Commit

* IT BUILDS!!!

* Fix LINTER fails

* Cleanup

* Scale working, cut down on some evil code

* Delete old Entity Effects

* Accidentally breaking shit by fixing bugs

* Fix a bunch of effects not working

* Fix reagent thresholds

* Update damage

* Wait don't change the gas metabolisms A

* Cleanup

* more fixes

* Eh

* Misc fixes and jank

* Remove two things, add bullshit, change condition to inverted

* Remove unused "Shared" system structure

* Namespace fix

* merge conflicts/cleanup

* More fixes

* Guidebook text begins

* Shelve

* Push

* More shit to push

* Fix

* Fix merg conflicts

* BLOOD FOR THE BLOOD GOD!!!

* Mild cleanup and lists

* Fix localization and comments

* Shuffle localization around a bit.

* All done?

* Nearly everything

* Is this the end?

* Whoops forgot to remove that TODO

* Get rid of some warnings for good measure...

* It's done

* Should make those virtual in case we want to override them tbqh...

* Update Content.Shared/EntityEffects/Effects/Botany/PlantAttributes/PlantDestroySeeds.cs

Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>

* Fix test fails real

* Add to codeowners

* Documentation to everything

* Forgot to push whoops

* Standardize Condition names

* Fix up metabolism a little as a treat

* review

* add IsServer checks

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>
This commit is contained in:
Princess Cheeseballs
2025-10-12 14:23:42 -07:00
committed by GitHub
parent 4d316ae553
commit 4059c29ebc
289 changed files with 5635 additions and 4918 deletions

View File

@@ -0,0 +1,152 @@
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityConditions;
/// <summary>
/// This handles entity effects.
/// Specifically it handles the receiving of events for causing entity effects, and provides
/// public API for other systems to take advantage of entity effects.
/// </summary>
public sealed partial class SharedEntityConditionsSystem : EntitySystem, IEntityConditionRaiser
{
/// <summary>
/// Checks a list of conditions to verify that they all return true.
/// </summary>
/// <param name="target">Target entity we're checking conditions on</param>
/// <param name="conditions">Conditions we're checking</param>
/// <returns>Returns true if all conditions return true, false if any fail</returns>
public bool TryConditions(EntityUid target, EntityCondition[]? conditions)
{
// If there's no conditions we can't fail any of them...
if (conditions == null)
return true;
foreach (var condition in conditions)
{
if (!TryCondition(target, condition))
return false;
}
return true;
}
/// <summary>
/// Checks a list of conditions to see if any are true.
/// </summary>
/// <param name="target">Target entity we're checking conditions on</param>
/// <param name="conditions">Conditions we're checking</param>
/// <returns>Returns true if any conditions return true</returns>
public bool TryAnyCondition(EntityUid target, EntityCondition[]? conditions)
{
// If there's no conditions we can't meet any of them...
if (conditions == null)
return false;
foreach (var condition in conditions)
{
if (TryCondition(target, condition))
return true;
}
return false;
}
/// <summary>
/// Checks a single <see cref="EntityCondition"/> on an entity.
/// </summary>
/// <param name="target">Target entity we're checking conditions on</param>
/// <param name="condition">Condition we're checking</param>
/// <returns>Returns true if we meet the condition and false otherwise</returns>
public bool TryCondition(EntityUid target, EntityCondition condition)
{
return condition.Inverted != condition.RaiseEvent(target, this);
}
/// <summary>
/// Raises a condition to an entity. You should not be calling this unless you know what you're doing.
/// </summary>
public bool RaiseConditionEvent<T>(EntityUid target, T effect) where T : EntityConditionBase<T>
{
var effectEv = new EntityConditionEvent<T>(effect);
RaiseLocalEvent(target, ref effectEv);
return effectEv.Result;
}
}
/// <summary>
/// This is a basic abstract entity effect containing all the data an entity effect needs to affect entities with effects...
/// </summary>
/// <typeparam name="T">The Component that is required for the effect</typeparam>
/// <typeparam name="TCon">The Condition we're testing</typeparam>
public abstract partial class EntityConditionSystem<T, TCon> : EntitySystem where T : Component where TCon : EntityConditionBase<TCon>
{
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<T, EntityConditionEvent<TCon>>(Condition);
}
protected abstract void Condition(Entity<T> entity, ref EntityConditionEvent<TCon> args);
}
/// <summary>
/// Used to raise an EntityCondition without losing the type of condition.
/// </summary>
public interface IEntityConditionRaiser
{
bool RaiseConditionEvent<T>(EntityUid target, T effect) where T : EntityConditionBase<T>;
}
/// <summary>
/// Used to store an <see cref="EntityCondition"/> so it can be raised without losing the type of the condition.
/// </summary>
/// <typeparam name="T">The Condition wer are raising.</typeparam>
public abstract partial class EntityConditionBase<T> : EntityCondition where T : EntityConditionBase<T>
{
public override bool RaiseEvent(EntityUid target, IEntityConditionRaiser raiser)
{
if (this is not T type)
return false;
// If the result of the event matches the result we're looking for then we pass.
return raiser.RaiseConditionEvent(target, type);
}
}
/// <summary>
/// A basic condition which can be checked for on an entity via events.
/// </summary>
[ImplicitDataDefinitionForInheritors]
public abstract partial class EntityCondition
{
public abstract bool RaiseEvent(EntityUid target, IEntityConditionRaiser raiser);
/// <summary>
/// If true, invert the result. So false returns true and true returns false!
/// </summary>
[DataField]
public bool Inverted;
/// <summary>
/// A basic description of this condition, which displays in the guidebook.
/// </summary>
public abstract string EntityConditionGuidebookText(IPrototypeManager prototype);
}
/// <summary>
/// An Event carrying an entity effect.
/// </summary>
/// <param name="Condition">The Condition we're checking</param>
[ByRefEvent]
public record struct EntityConditionEvent<T>(T Condition) where T : EntityConditionBase<T>
{
/// <summary>
/// The result of our check, defaults to false if nothing handles it.
/// </summary>
[DataField]
public bool Result;
/// <summary>
/// The Condition being raised in this event
/// </summary>
public readonly T Condition = Condition;
}