Remove ILand (#4582)

* Remove ILand

* Make land not handleable

* Rename ILand
This commit is contained in:
metalgearsloth
2021-09-12 16:22:58 +10:00
committed by GitHub
parent 0137884e16
commit f301e45163
13 changed files with 99 additions and 103 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.Administration; using Content.Server.Administration;
using Content.Server.Damage.Systems;
using Content.Shared.Administration; using Content.Shared.Administration;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Console; using Robust.Shared.Console;

View File

@@ -1,44 +1,28 @@
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Throwing;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Prototypes;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.Damage.Components namespace Content.Server.Damage.Components
{ {
[RegisterComponent] [RegisterComponent]
public class DamageOnLandComponent : Component, ILand public sealed class DamageOnLandComponent : Component
{ {
public override string Name => "DamageOnLand"; public override string Name => "DamageOnLand";
[DataField("amount")] [DataField("amount")]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
private int _amount = 1; public int Amount = 1;
[DataField("ignoreResistances")] [DataField("ignoreResistances")]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
private bool _ignoreResistances; public bool IgnoreResistances;
// TODO PROTOTYPE Replace this datafield variable with prototype references, once they are supported. // TODO PROTOTYPE Replace this datafield variable with prototype references, once they are supported.
// Also remove Initialize override, if no longer needed. // Also remove Initialize override, if no longer needed.
[DataField("damageType")] [DataField("damageType")] public readonly string DamageTypeId = "Blunt";
private readonly string _damageTypeID = "Blunt";
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public DamageTypePrototype DamageType = default!; public DamageTypePrototype DamageType = default!;
protected override void Initialize()
{
base.Initialize();
DamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>(_damageTypeID);
}
void ILand.Land(LandEventArgs eventArgs)
{
if (!Owner.TryGetComponent(out IDamageableComponent? damageable))
return;
damageable.TryChangeDamage(DamageType, _amount, _ignoreResistances);
}
} }
} }

View File

@@ -1,3 +1,4 @@
using Content.Server.Damage.Systems;
using Content.Shared.Damage; using Content.Shared.Damage;
using Robust.Shared.Analyzers; using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;

View File

@@ -11,7 +11,7 @@ using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Timing; using Robust.Shared.Timing;
namespace Content.Server.Damage namespace Content.Server.Damage.Systems
{ {
[UsedImplicitly] [UsedImplicitly]
internal sealed class DamageOnHighSpeedImpactSystem: EntitySystem internal sealed class DamageOnHighSpeedImpactSystem: EntitySystem

View File

@@ -0,0 +1,35 @@
using Content.Server.Damage.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Throwing;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Damage.Systems
{
public sealed class DamageOnLandSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamageOnLandComponent, ComponentInit>(HandleInit);
SubscribeLocalEvent<DamageOnLandComponent, LandEvent>(DamageOnLand);
}
private void HandleInit(EntityUid uid, DamageOnLandComponent component, ComponentInit args)
{
component.DamageType = _protoManager.Index<DamageTypePrototype>(component.DamageTypeId);
}
private void DamageOnLand(EntityUid uid, DamageOnLandComponent component, LandEvent args)
{
if (!ComponentManager.TryGetComponent<IDamageableComponent>(uid, out var damageable))
return;
damageable.TryChangeDamage(component.DamageType, component.Amount, component.IgnoreResistances);
}
}
}

View File

@@ -3,7 +3,7 @@ using Content.Shared.Damage.Components;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Server.Damage namespace Content.Server.Damage.Systems
{ {
public class DamageOtherOnHitSystem : EntitySystem public class DamageOtherOnHitSystem : EntitySystem
{ {

View File

@@ -7,7 +7,7 @@ using Content.Shared.GameTicking;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Server.Damage namespace Content.Server.Damage.Systems
{ {
[UsedImplicitly] [UsedImplicitly]
public class GodmodeSystem : EntitySystem public class GodmodeSystem : EntitySystem

View File

@@ -33,11 +33,8 @@ namespace Content.Server.Light.Components
/// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless. /// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public class LightBulbComponent : Component, ILand, IBreakAct public class LightBulbComponent : Component, IBreakAct
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
/// <summary> /// <summary>
/// Invoked whenever the state of the light bulb changes. /// Invoked whenever the state of the light bulb changes.
/// </summary> /// </summary>
@@ -121,12 +118,6 @@ namespace Content.Server.Light.Components
UpdateColor(); UpdateColor();
} }
void ILand.Land(LandEventArgs eventArgs)
{
PlayBreakSound();
State = LightBulbState.Broken;
}
public void OnBreak(BreakageEventArgs eventArgs) public void OnBreak(BreakageEventArgs eventArgs)
{ {
State = LightBulbState.Broken; State = LightBulbState.Broken;

View File

@@ -0,0 +1,21 @@
using Content.Server.Light.Components;
using Content.Shared.Throwing;
using Robust.Shared.GameObjects;
namespace Content.Server.Light.EntitySystems
{
public sealed class LightBulbSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<LightBulbComponent, LandEvent>(HandleLand);
}
private void HandleLand(EntityUid uid, LightBulbComponent component, LandEvent args)
{
component.PlayBreakSound();
component.State = LightBulbState.Broken;
}
}
}

View File

@@ -12,15 +12,12 @@ using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification.Managers; using Content.Shared.Notification.Managers;
using Content.Shared.Nutrition.Components; using Content.Shared.Nutrition.Components;
using Content.Shared.Sound; using Content.Shared.Sound;
using Content.Shared.Throwing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -28,10 +25,8 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.Nutrition.Components namespace Content.Server.Nutrition.Components
{ {
[RegisterComponent] [RegisterComponent]
public class DrinkComponent : Component, IUse, IAfterInteract, IExamine, ILand public class DrinkComponent : Component, IUse, IAfterInteract, IExamine
{ {
[Dependency] private readonly IRobustRandom _random = default!;
[DataField("solution")] [DataField("solution")]
public string SolutionName { get; set; } = DefaultSolutionName; public string SolutionName { get; set; } = DefaultSolutionName;
public const string DefaultSolutionName = "drink"; public const string DefaultSolutionName = "drink";
@@ -81,10 +76,10 @@ namespace Content.Server.Nutrition.Components
[DataField("openSounds")] [DataField("openSounds")]
private SoundSpecifier _openSounds = new SoundCollectionSpecifier("canOpenSounds"); private SoundSpecifier _openSounds = new SoundCollectionSpecifier("canOpenSounds");
[DataField("pressurized")]
private bool _pressurized = default; [DataField("pressurized")] public bool Pressurized;
[DataField("burstSound")]
private SoundSpecifier _burstSound = new SoundPathSpecifier("/Audio/Effects/flash_bang.ogg"); [DataField("burstSound")] public SoundSpecifier BurstSound = new SoundPathSpecifier("/Audio/Effects/flash_bang.ogg");
private void OpenedChanged() private void OpenedChanged()
{ {
@@ -233,22 +228,5 @@ namespace Content.Server.Nutrition.Components
return true; return true;
} }
void ILand.Land(LandEventArgs eventArgs)
{
if (_pressurized &&
!Opened &&
_random.Prob(0.25f) &&
EntitySystem.Get<SolutionContainerSystem>().TryGetDrainableSolution(Owner.Uid, out var interactions))
{
Opened = true;
var solution = EntitySystem.Get<SolutionContainerSystem>()
.Drain(Owner.Uid, interactions, interactions.DrainAvailable);
solution.SpillAt(Owner, "PuddleSmear");
SoundSystem.Play(Filter.Pvs(Owner), _burstSound.GetSound(), Owner, AudioParams.Default.WithVolume(-4));
}
}
} }
} }

View File

@@ -1,15 +1,21 @@
using Content.Server.Nutrition.Components; using Content.Server.Fluids.Components;
using Content.Server.Nutrition.Components;
using Content.Shared.Chemistry.Components.SolutionManager; using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems; using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Throwing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.Nutrition.EntitySystems namespace Content.Server.Nutrition.EntitySystems
{ {
[UsedImplicitly] [UsedImplicitly]
public class DrinkSystem : EntitySystem public class DrinkSystem : EntitySystem
{ {
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!; [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
public override void Initialize() public override void Initialize()
@@ -18,6 +24,25 @@ namespace Content.Server.Nutrition.EntitySystems
SubscribeLocalEvent<DrinkComponent, SolutionChangedEvent>(OnSolutionChange); SubscribeLocalEvent<DrinkComponent, SolutionChangedEvent>(OnSolutionChange);
SubscribeLocalEvent<DrinkComponent, ComponentInit>(OnDrinkInit); SubscribeLocalEvent<DrinkComponent, ComponentInit>(OnDrinkInit);
SubscribeLocalEvent<DrinkComponent, LandEvent>(HandleLand);
}
private void HandleLand(EntityUid uid, DrinkComponent component, LandEvent args)
{
if (component.Pressurized &&
!component.Opened &&
_random.Prob(0.25f) &&
_solutionContainerSystem.TryGetDrainableSolution(uid, out var interactions))
{
component.Opened = true;
var entity = EntityManager.GetEntity(uid);
var solution = _solutionContainerSystem.Drain(uid, interactions, interactions.DrainAvailable);
solution.SpillAt(entity, "PuddleSmear");
SoundSystem.Play(Filter.Pvs(entity), component.BurstSound.GetSound(), entity, AudioParams.Default.WithVolume(-4));
}
} }
private void OnDrinkInit(EntityUid uid, DrinkComponent component, ComponentInit args) private void OnDrinkInit(EntityUid uid, DrinkComponent component, ComponentInit args)

View File

@@ -1,37 +1,14 @@
using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Map; using Robust.Shared.Map;
namespace Content.Shared.Throwing namespace Content.Shared.Throwing
{ {
/// <summary>
/// This interface gives components behavior when landing after being thrown.
/// </summary>
[RequiresExplicitImplementation]
public interface ILand
{
void Land(LandEventArgs eventArgs);
}
public class LandEventArgs : EventArgs
{
public LandEventArgs(IEntity? user, EntityCoordinates landingLocation)
{
User = user;
LandingLocation = landingLocation;
}
public IEntity? User { get; }
public EntityCoordinates LandingLocation { get; }
}
/// <summary> /// <summary>
/// Raised when an entity that was thrown lands. /// Raised when an entity that was thrown lands.
/// </summary> /// </summary>
[PublicAPI] [PublicAPI]
public class LandEvent : HandledEntityEventArgs public sealed class LandEvent : EntityEventArgs
{ {
/// <summary> /// <summary>
/// Entity that threw the item. /// Entity that threw the item.

View File

@@ -124,25 +124,8 @@ namespace Content.Shared.Throwing
var user = thrownItem.Thrower; var user = thrownItem.Thrower;
var coordinates = landing.Transform.Coordinates; var coordinates = landing.Transform.Coordinates;
// LandInteraction
// TODO: Refactor these to system messages
var landMsg = new LandEvent(user, landing, coordinates); var landMsg = new LandEvent(user, landing, coordinates);
RaiseLocalEvent(landing.Uid, landMsg); RaiseLocalEvent(landing.Uid, landMsg);
if (landMsg.Handled)
{
return;
}
var comps = landing.GetAllComponents<ILand>().ToArray();
var landArgs = new LandEventArgs(user, coordinates);
// Call Land on all components that implement the interface
foreach (var comp in comps)
{
if (landing.Deleted) break;
comp.Land(landArgs);
}
ComponentManager.RemoveComponent(landing.Uid, thrownItem); ComponentManager.RemoveComponent(landing.Uid, thrownItem);
} }