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;
var chat = IoCManager.Resolve<IChatManager>();
var owner = player.ContentData()?.Mind?.OwnedMob.Owner;
var owner = player.ContentData()?.Mind?.OwnedComponent.Owner;
if (owner == null)
{

View File

@@ -31,7 +31,7 @@ namespace Content.Server.Commands.Mobs
var mind = data.ContentData().Mind;
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)
{
builder.AppendFormat("{0} ", role.Name);

View File

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

View File

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

View File

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