Files
tbd-station-14/Content.Server/GlobalVerbs/ControlMobVerb.cs
Víctor Aguilera Puerto 090dd8cee8 ControlMob verb and command (#724)
* ControlMob verb and command, mobs have MindComponent by default

* Use IActorComponent instead of MindComponent for User entity.
Fixes using Control Mob while aghosting/visiting an entity.

* Use static Loc class
2020-02-24 03:49:40 +01:00

51 lines
1.7 KiB
C#

using Content.Server.GameObjects;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Nutrition;
using Content.Server.Players;
using Content.Shared.GameObjects;
using Robust.Server.Console;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
namespace Content.Server.GlobalVerbs
{
[GlobalVerb]
public class ControlMobVerb : GlobalVerb
{
public override string GetText(IEntity user, IEntity target) => "Control Mob";
public override bool RequireInteractionRange => false;
public override VerbVisibility GetVisibility(IEntity user, IEntity target)
{
var groupController = IoCManager.Resolve<IConGroupController>();
if (user == target) return VerbVisibility.Invisible;
if (user.TryGetComponent<IActorComponent>(out var player))
{
if (!user.HasComponent<MindComponent>() || !target.HasComponent<MindComponent>())
return VerbVisibility.Invisible;
if (groupController.CanCommand(player.playerSession, "controlmob"))
return VerbVisibility.Visible;
}
return VerbVisibility.Invisible;
}
public override void Activate(IEntity user, IEntity target)
{
var userMind = user.GetComponent<IActorComponent>().playerSession.ContentData().Mind;
var targetMind = target.GetComponent<MindComponent>();
if(userMind.IsVisitingEntity)
userMind.UnVisit();
targetMind.Mind?.TransferTo(null);
userMind.TransferTo(target);
}
}
}