Turn brain behavior into a component/system (#5281)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Body.Behavior;
|
||||
using Content.Shared.Body.Events;
|
||||
using Content.Shared.Body.Part;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -168,12 +169,14 @@ namespace Content.Shared.Body.Components
|
||||
}
|
||||
}
|
||||
|
||||
// TODO BODY Turn these into event listeners so they dont need to be exposed
|
||||
public void AddedToBody(SharedBodyComponent body)
|
||||
{
|
||||
DebugTools.AssertNotNull(Body);
|
||||
DebugTools.AssertNotNull(body);
|
||||
|
||||
var ev = new AddedToBodyEvent(body);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false);
|
||||
|
||||
foreach (var behavior in _behaviors.Values)
|
||||
{
|
||||
behavior.AddedToBody(body);
|
||||
@@ -187,6 +190,9 @@ namespace Content.Shared.Body.Components
|
||||
|
||||
Owner.Transform.AttachParent(part.Owner);
|
||||
|
||||
var ev = new AddedToPartEvent(part);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false);
|
||||
|
||||
foreach (var behavior in _behaviors.Values)
|
||||
{
|
||||
behavior.AddedToPart(part);
|
||||
@@ -202,6 +208,9 @@ namespace Content.Shared.Body.Components
|
||||
|
||||
Owner.Transform.AttachParent(part.Owner);
|
||||
|
||||
var ev = new AddedToPartInBodyEvent(body, part);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false);
|
||||
|
||||
foreach (var behavior in _behaviors.Values)
|
||||
{
|
||||
behavior.AddedToPartInBody(body, part);
|
||||
@@ -213,6 +222,9 @@ namespace Content.Shared.Body.Components
|
||||
DebugTools.AssertNull(Body);
|
||||
DebugTools.AssertNotNull(old);
|
||||
|
||||
var ev = new RemovedFromBodyEvent(old);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false);
|
||||
|
||||
foreach (var behavior in _behaviors.Values)
|
||||
{
|
||||
behavior.RemovedFromBody(old);
|
||||
@@ -226,6 +238,9 @@ namespace Content.Shared.Body.Components
|
||||
|
||||
Owner.Transform.AttachToGridOrMap();
|
||||
|
||||
var ev = new RemovedFromPartEvent(old);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false);
|
||||
|
||||
foreach (var behavior in _behaviors.Values)
|
||||
{
|
||||
behavior.RemovedFromPart(old);
|
||||
@@ -241,6 +256,9 @@ namespace Content.Shared.Body.Components
|
||||
|
||||
Owner.Transform.AttachToGridOrMap();
|
||||
|
||||
var ev = new RemovedFromPartInBodyEvent(oldBody, oldPart);
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, ev, false);
|
||||
|
||||
foreach (var behavior in _behaviors.Values)
|
||||
{
|
||||
behavior.RemovedFromPartInBody(oldBody, oldPart);
|
||||
|
||||
90
Content.Shared/Body/Events/MechanismBodyEvents.cs
Normal file
90
Content.Shared/Body/Events/MechanismBodyEvents.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Body.Events
|
||||
{
|
||||
// All of these events are raised on a mechanism entity when added/removed to a body in different
|
||||
// ways.
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a mechanism when it is added to a body.
|
||||
/// </summary>
|
||||
public class AddedToBodyEvent : EntityEventArgs
|
||||
{
|
||||
public SharedBodyComponent Body;
|
||||
|
||||
public AddedToBodyEvent(SharedBodyComponent body)
|
||||
{
|
||||
Body = body;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a mechanism when it is added to a body part.
|
||||
/// </summary>
|
||||
public class AddedToPartEvent : EntityEventArgs
|
||||
{
|
||||
public SharedBodyPartComponent Part;
|
||||
|
||||
public AddedToPartEvent(SharedBodyPartComponent part)
|
||||
{
|
||||
Part = part;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a mechanism when it is added to a body part within a body.
|
||||
/// </summary>
|
||||
public class AddedToPartInBodyEvent : EntityEventArgs
|
||||
{
|
||||
public SharedBodyComponent Body;
|
||||
public SharedBodyPartComponent Part;
|
||||
|
||||
public AddedToPartInBodyEvent(SharedBodyComponent body, SharedBodyPartComponent part)
|
||||
{
|
||||
Body = body;
|
||||
Part = part;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a mechanism when it is removed from a body.
|
||||
/// </summary>
|
||||
public class RemovedFromBodyEvent : EntityEventArgs
|
||||
{
|
||||
public SharedBodyComponent Old;
|
||||
|
||||
public RemovedFromBodyEvent(SharedBodyComponent old)
|
||||
{
|
||||
Old = old;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a mechanism when it is removed from a body part.
|
||||
/// </summary>
|
||||
public class RemovedFromPartEvent : EntityEventArgs
|
||||
{
|
||||
public SharedBodyPartComponent Old;
|
||||
|
||||
public RemovedFromPartEvent(SharedBodyPartComponent old)
|
||||
{
|
||||
Old = old;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on a mechanism when it is removed from a body part within a body.
|
||||
/// </summary>
|
||||
public class RemovedFromPartInBodyEvent : EntityEventArgs
|
||||
{
|
||||
public SharedBodyComponent OldBody;
|
||||
public SharedBodyPartComponent OldPart;
|
||||
|
||||
public RemovedFromPartInBodyEvent(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart)
|
||||
{
|
||||
OldBody = oldBody;
|
||||
OldPart = oldPart;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user