2021-02-27 04:12:09 +01:00
|
|
|
#nullable enable
|
2021-01-07 00:31:43 -06:00
|
|
|
using System;
|
2020-04-08 15:53:15 +05:00
|
|
|
using System.Linq;
|
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-04-08 15:53:15 +05:00
|
|
|
|
2021-01-07 00:31:43 -06:00
|
|
|
namespace Content.Shared.GameObjects.EntitySystems
|
2020-04-08 15:53:15 +05:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This interface gives components behavior on whether entities solution (implying SolutionComponent is in place) is changed
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface ISolutionChange
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called when solution is mixed with some other solution, or when some part of the solution is removed
|
|
|
|
|
/// </summary>
|
|
|
|
|
void SolutionChanged(SolutionChangeEventArgs eventArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SolutionChangeEventArgs : EventArgs
|
|
|
|
|
{
|
2021-02-27 04:12:09 +01:00
|
|
|
public IEntity Owner { get; set; } = default!;
|
2020-04-08 15:53:15 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class ChemistrySystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
public void HandleSolutionChange(IEntity owner)
|
|
|
|
|
{
|
|
|
|
|
var eventArgs = new SolutionChangeEventArgs
|
|
|
|
|
{
|
|
|
|
|
Owner = owner,
|
|
|
|
|
};
|
|
|
|
|
var solutionChangeArgs = owner.GetAllComponents<ISolutionChange>().ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var solutionChangeArg in solutionChangeArgs)
|
|
|
|
|
{
|
|
|
|
|
solutionChangeArg.SolutionChanged(eventArgs);
|
2021-01-10 15:40:04 +01:00
|
|
|
|
|
|
|
|
if (owner.Deleted)
|
|
|
|
|
return;
|
2020-04-08 15:53:15 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|