Fixed RespawnManager not removing respawn items. Closes #234

This commit is contained in:
Joonas Rikkonen
2018-04-04 18:53:23 +03:00
parent 5731f8a522
commit 3aeaae0595
@@ -10,9 +10,6 @@ namespace Barotrauma.Networking
{ {
class RespawnManager : Entity, IServerSerializable class RespawnManager : Entity, IServerSerializable
{ {
// TODO: Instead of hard-coding the tags in the code, maybe they should be defined in a config file?
private static string respawnItemTag = "respawn";
private readonly float respawnInterval; private readonly float respawnInterval;
private float maxTransportTime; private float maxTransportTime;
@@ -31,6 +28,10 @@ namespace Barotrauma.Networking
private Steering shuttleSteering; private Steering shuttleSteering;
private List<Door> shuttleDoors; private List<Door> shuttleDoors;
//items created during respawn
//any respawn items left in the shuttle are removed when the shuttle despawns
private List<Item> respawnItems = new List<Item>();
public bool UsingShuttle public bool UsingShuttle
{ {
get { return respawnShuttle != null; } get { return respawnShuttle != null; }
@@ -367,17 +368,16 @@ namespace Barotrauma.Networking
foreach (Item item in Item.ItemList) foreach (Item item in Item.ItemList)
{ {
if (item.Submarine != respawnShuttle) continue; if (item.Submarine != respawnShuttle) continue;
// Ignore the respawn items, defined in RespawnCharacters method.
if (item.HasTag(respawnItemTag)) continue;
if (item.body != null && item.body.Enabled && item.ParentInventory == null) //remove respawn items that have been left in the shuttle
if (respawnItems.Contains(item))
{ {
Entity.Spawner.AddToRemoveQueue(item); Spawner.AddToRemoveQueue(item);
continue; continue;
} }
//restore other items to full condition and recharge batteries
item.Condition = item.Prefab.Health; item.Condition = item.Prefab.Health;
var powerContainer = item.GetComponent<PowerContainer>(); var powerContainer = item.GetComponent<PowerContainer>();
if (powerContainer != null) if (powerContainer != null)
{ {
@@ -507,9 +507,6 @@ namespace Barotrauma.Networking
Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position; Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position;
// Temp list to hold all respawn items.
// TODO: Instead of tags, wouldn't it be better to keep a local reference to the list that we create and simple filter out the items on it, before clearing the items in ResetShuttle method?
var respawnItems = new List<Item>();
if (divingSuitPrefab != null && oxyPrefab != null) if (divingSuitPrefab != null && oxyPrefab != null)
{ {
var divingSuit = new Item(divingSuitPrefab, pos, respawnSub); var divingSuit = new Item(divingSuitPrefab, pos, respawnSub);
@@ -542,7 +539,6 @@ namespace Barotrauma.Networking
respawnItems.Add(scooter); respawnItems.Add(scooter);
respawnItems.Add(battery); respawnItems.Add(battery);
} }
respawnItems.ForEach(item => item.AddTag(respawnItemTag));
//give the character the items they would've gotten if they had spawned in the main sub //give the character the items they would've gotten if they had spawned in the main sub
character.GiveJobItems(mainSubSpawnPoints[i]); character.GiveJobItems(mainSubSpawnPoints[i]);