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:
committed by
GitHub
parent
4d316ae553
commit
4059c29ebc
@@ -1,145 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Localizations;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Robust.Shared.Toolshed.TypeParsers;
|
||||
|
||||
namespace Content.Shared.EntityEffects;
|
||||
|
||||
/// <summary>
|
||||
/// Entity effects describe behavior that occurs on different kinds of triggers, e.g. when a reagent is ingested and metabolized by some
|
||||
/// organ. They only trigger when all of <see cref="Conditions"/> are satisfied.
|
||||
/// </summary>
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
[MeansImplicitUse]
|
||||
public abstract partial class EntityEffect
|
||||
{
|
||||
private protected string _id => this.GetType().Name;
|
||||
/// <summary>
|
||||
/// The list of conditions required for the effect to activate. Not required.
|
||||
/// </summary>
|
||||
[DataField("conditions")]
|
||||
public EntityEffectCondition[]? Conditions;
|
||||
|
||||
public virtual string ReagentEffectFormat => "guidebook-reagent-effect-description";
|
||||
|
||||
protected abstract string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys);
|
||||
|
||||
/// <summary>
|
||||
/// What's the chance, from 0 to 1, that this effect will occur?
|
||||
/// </summary>
|
||||
[DataField("probability")]
|
||||
public float Probability = 1.0f;
|
||||
|
||||
public virtual LogImpact LogImpact { get; private set; } = LogImpact.Low;
|
||||
|
||||
/// <summary>
|
||||
/// Should this entity effect log at all?
|
||||
/// </summary>
|
||||
public virtual bool ShouldLog { get; private set; } = false;
|
||||
|
||||
public abstract void Effect(EntityEffectBaseArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// Produces a localized, bbcode'd guidebook description for this effect.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string? GuidebookEffectDescription(IPrototypeManager prototype, IEntitySystemManager entSys)
|
||||
{
|
||||
var effect = ReagentEffectGuidebookText(prototype, entSys);
|
||||
if (effect is null)
|
||||
return null;
|
||||
|
||||
return Loc.GetString(ReagentEffectFormat, ("effect", effect), ("chance", Probability),
|
||||
("conditionCount", Conditions?.Length ?? 0),
|
||||
("conditions",
|
||||
ContentLocalizationManager.FormatList(Conditions?.Select(x => x.GuidebookExplanation(prototype)).ToList() ??
|
||||
new List<string>())));
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityEffectExt
|
||||
{
|
||||
public static bool ShouldApply(this EntityEffect effect, EntityEffectBaseArgs args,
|
||||
IRobustRandom? random = null)
|
||||
{
|
||||
if (random == null)
|
||||
random = IoCManager.Resolve<IRobustRandom>();
|
||||
|
||||
if (effect.Probability < 1.0f && !random.Prob(effect.Probability))
|
||||
return false;
|
||||
|
||||
if (effect.Conditions != null)
|
||||
{
|
||||
foreach (var cond in effect.Conditions)
|
||||
{
|
||||
if (!cond.Condition(args))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public struct ExecuteEntityEffectEvent<T> where T : EntityEffect
|
||||
{
|
||||
public T Effect;
|
||||
public EntityEffectBaseArgs Args;
|
||||
|
||||
public ExecuteEntityEffectEvent(T effect, EntityEffectBaseArgs args)
|
||||
{
|
||||
Effect = effect;
|
||||
Args = args;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EntityEffectBaseArgs only contains the target of an effect.
|
||||
/// If a trigger wants to include more info (e.g. the quantity of the chemical triggering the effect), it can be extended (see EntityEffectReagentArgs).
|
||||
/// </summary>
|
||||
public record class EntityEffectBaseArgs
|
||||
{
|
||||
public EntityUid TargetEntity;
|
||||
|
||||
public IEntityManager EntityManager = default!;
|
||||
|
||||
public EntityEffectBaseArgs(EntityUid targetEntity, IEntityManager entityManager)
|
||||
{
|
||||
TargetEntity = targetEntity;
|
||||
EntityManager = entityManager;
|
||||
}
|
||||
}
|
||||
|
||||
public record class EntityEffectReagentArgs : EntityEffectBaseArgs
|
||||
{
|
||||
public EntityUid? OrganEntity;
|
||||
|
||||
public Solution? Source;
|
||||
|
||||
public FixedPoint2 Quantity;
|
||||
|
||||
public ReagentPrototype? Reagent;
|
||||
|
||||
public ReactionMethod? Method;
|
||||
|
||||
public FixedPoint2 Scale;
|
||||
|
||||
public EntityEffectReagentArgs(EntityUid targetEntity, IEntityManager entityManager, EntityUid? organEntity, Solution? source, FixedPoint2 quantity, ReagentPrototype? reagent, ReactionMethod? method, FixedPoint2 scale) : base(targetEntity, entityManager)
|
||||
{
|
||||
OrganEntity = organEntity;
|
||||
Source = source;
|
||||
Quantity = quantity;
|
||||
Reagent = reagent;
|
||||
Method = method;
|
||||
Scale = scale;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user