Delete ghost when respawning (#3519)

* Delete ghost when respawning

Fix session.AttachedEntity not being set to null when mind is wiped
Fix MindComponent not getting disconnected when Mind is wiped
Rename OwnedMob to OwnedComponent

* Update Content.Server/GameTicking/GameTicker.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
ShadowCommander
2021-03-11 01:37:16 -08:00
committed by GitHub
parent 8fc4895c1f
commit 481fee135b
5 changed files with 24 additions and 14 deletions

View File

@@ -69,7 +69,7 @@ namespace Content.Server.Commands.Chat
return; return;
var chat = IoCManager.Resolve<IChatManager>(); var chat = IoCManager.Resolve<IChatManager>();
var owner = player.ContentData()?.Mind?.OwnedMob.Owner; var owner = player.ContentData()?.Mind?.OwnedComponent.Owner;
if (owner == null) if (owner == null)
{ {

View File

@@ -31,7 +31,7 @@ namespace Content.Server.Commands.Mobs
var mind = data.ContentData().Mind; var mind = data.ContentData().Mind;
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.AppendFormat("player: {0}, mob: {1}\nroles: ", mind.UserId, mind.OwnedMob?.Owner?.Uid); builder.AppendFormat("player: {0}, mob: {1}\nroles: ", mind.UserId, mind.OwnedComponent?.Owner?.Uid);
foreach (var role in mind.AllRoles) foreach (var role in mind.AllRoles)
{ {
builder.AppendFormat("{0} ", role.Name); builder.AppendFormat("{0} ", role.Name);

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
@@ -409,7 +409,10 @@ namespace Content.Server.GameTicking
public void Respawn(IPlayerSession targetPlayer) public void Respawn(IPlayerSession targetPlayer)
{ {
targetPlayer.AttachedEntity.TryGetComponent<GhostComponent>(out var ghost);
targetPlayer.ContentData()?.WipeMind(); targetPlayer.ContentData()?.WipeMind();
if (ghost?.Deleted == false)
ghost.Owner.Delete();
if (LobbyEnabled) if (LobbyEnabled)
_playerJoinLobby(targetPlayer); _playerJoinLobby(targetPlayer);

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Mobs;
@@ -62,14 +62,14 @@ namespace Content.Server.Mobs
/// Can be null. /// Can be null.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
public MindComponent OwnedMob { get; private set; } public MindComponent OwnedComponent { get; private set; }
/// <summary> /// <summary>
/// The entity currently owned by this mind. /// The entity currently owned by this mind.
/// Can be null. /// Can be null.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
public IEntity OwnedEntity => OwnedMob?.Owner; public IEntity OwnedEntity => OwnedComponent?.Owner;
/// <summary> /// <summary>
/// An enumerable over all the roles this mind has. /// An enumerable over all the roles this mind has.
@@ -121,7 +121,7 @@ namespace Content.Server.Mobs
role.Greet(); role.Greet();
var message = new RoleAddedMessage(role); var message = new RoleAddedMessage(role);
OwnedEntity?.SendMessage(OwnedMob, message); OwnedEntity?.SendMessage(OwnedComponent, message);
return role; return role;
} }
@@ -143,7 +143,7 @@ namespace Content.Server.Mobs
_roles.Remove(role); _roles.Remove(role);
var message = new RoleRemovedMessage(role); var message = new RoleRemovedMessage(role);
OwnedEntity?.SendMessage(OwnedMob, message); OwnedEntity?.SendMessage(OwnedComponent, message);
} }
public bool HasRole<T>() where T : Role public bool HasRole<T>() where T : Role
@@ -220,12 +220,13 @@ namespace Content.Server.Mobs
} }
} }
OwnedMob?.InternalEjectMind(); OwnedComponent?.InternalEjectMind();
OwnedMob = component;
OwnedMob?.InternalAssignMind(this); OwnedComponent = component;
OwnedComponent?.InternalAssignMind(this);
// Player is CURRENTLY connected. // Player is CURRENTLY connected.
if (Session != null && OwnedMob != null && !alreadyAttached) if (Session != null && !alreadyAttached)
{ {
Session.AttachToEntity(entity); Session.AttachToEntity(entity);
} }
@@ -233,6 +234,11 @@ namespace Content.Server.Mobs
VisitingEntity = null; VisitingEntity = null;
} }
public void RemoveOwningPlayer()
{
UserId = null;
}
public void ChangeOwningPlayer(NetUserId? newOwner) public void ChangeOwningPlayer(NetUserId? newOwner)
{ {
var playerMgr = IoCManager.Resolve<IPlayerManager>(); var playerMgr = IoCManager.Resolve<IPlayerManager>();

View File

@@ -1,4 +1,4 @@
#nullable enable #nullable enable
using Content.Server.Mobs; using Content.Server.Mobs;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Network; using Robust.Shared.Network;
@@ -33,7 +33,8 @@ namespace Content.Server.Players
public void WipeMind() public void WipeMind()
{ {
Mind?.ChangeOwningPlayer(null); Mind?.TransferTo(null);
Mind?.RemoveOwningPlayer();
Mind = null; Mind = null;
} }