- clients don't spawn character jobitems themselves (item data is written in the StartGame network message)

- after receiving a StartGame message, clients will wait until the game is loaded before reading new messages from the server
- the Item(prefab, position, submarine) constructor uses the position as the center of the item, not as top-left corner
This commit is contained in:
Regalis
2016-07-29 18:38:42 +03:00
parent c773320a55
commit 4252f4b9d0
12 changed files with 146 additions and 110 deletions
@@ -45,7 +45,6 @@
</fixrequirement> </fixrequirement>
<Engine minvoltage="0.5" powerconsumption="500.0" maxforce="300" canbeselected = "true"> <Engine minvoltage="0.5" powerconsumption="500.0" maxforce="300" canbeselected = "true">
<StatusEffect type="InWater" target="This" condition="-2.0"/>
<GuiFrame rect="0,0,350,160" alignment="Center" color="0.0,0.0,0.0,0.6"/> <GuiFrame rect="0,0,350,160" alignment="Center" color="0.0,0.0,0.0,0.6"/>
<sound file="engine.ogg" type="OnActive" range="3000.0" volume="CurrentVolume" loop="true"/> <sound file="engine.ogg" type="OnActive" range="3000.0" volume="CurrentVolume" loop="true"/>
</Engine> </Engine>
+2 -10
View File
@@ -37,6 +37,8 @@ namespace Barotrauma
public bool SpawnedMidRound; public bool SpawnedMidRound;
public List<Item> SpawnItems = new List<Item>();
private bool enabled; private bool enabled;
public bool Enabled public bool Enabled
@@ -74,10 +76,6 @@ namespace Barotrauma
protected Key[] keys; protected Key[] keys;
//protected Key selectKeyHit;
//protected Key actionKeyHit, actionKeyDown;
//protected Key secondaryKeyHit, secondaryKeyDown;
private Item selectedConstruction; private Item selectedConstruction;
private Item[] selectedItems; private Item[] selectedItems;
@@ -161,12 +159,6 @@ namespace Barotrauma
get { return inventory; } get { return inventory; }
} }
public WayPoint SpawnPoint
{
get;
set;
}
private Color speechBubbleColor; private Color speechBubbleColor;
private float speechBubbleTimer; private float speechBubbleTimer;
+1
View File
@@ -127,6 +127,7 @@ namespace Barotrauma
} }
} }
character.SpawnItems.Add(item);
if (parentItem != null) parentItem.Combine(item); if (parentItem != null) parentItem.Combine(item);
@@ -71,7 +71,7 @@ namespace Barotrauma
Vector2 position = new Vector2( Vector2 position = new Vector2(
cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, false), cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, false),
cargoRoom.Rect.Y - cargoRoom.Rect.Height + 16.0f); cargoRoom.Rect.Y - cargoRoom.Rect.Height);
var item = new Item(itemPrefab, position, cargoRoom.Submarine); var item = new Item(itemPrefab, position, cargoRoom.Submarine);
item.FindHull(); item.FindHull();
+2 -2
View File
@@ -351,12 +351,12 @@ namespace Barotrauma
} }
static bool waitForKeyHit = true; static bool waitForKeyHit = true;
public static void ShowLoading(IEnumerable<object> loader, bool waitKeyHit = true) public static CoroutineHandle ShowLoading(IEnumerable<object> loader, bool waitKeyHit = true)
{ {
waitForKeyHit = waitKeyHit; waitForKeyHit = waitKeyHit;
titleScreenOpen = true; titleScreenOpen = true;
TitleScreen.LoadState = null; TitleScreen.LoadState = null;
CoroutineManager.StartCoroutine(TitleScreen.DoLoading(loader)); return CoroutineManager.StartCoroutine(TitleScreen.DoLoading(loader));
} }
protected override void OnExiting(object sender, EventArgs args) protected override void OnExiting(object sender, EventArgs args)
@@ -39,7 +39,7 @@ namespace Barotrauma
{ {
Vector2 position = new Vector2( Vector2 position = new Vector2(
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20), Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
Rand.Range(cargoRoom.Rect.Y - cargoRoom.Rect.Height + 20.0f, cargoRoom.Rect.Y)); Rand.Range(cargoRoom.Rect.Y - cargoRoom.Rect.Height, cargoRoom.Rect.Y));
new Item(prefab as ItemPrefab, position, wp.Submarine); new Item(prefab as ItemPrefab, position, wp.Submarine);
} }
+7 -2
View File
@@ -301,7 +301,12 @@ namespace Barotrauma
} }
public Item(ItemPrefab itemPrefab, Vector2 position, Submarine submarine) public Item(ItemPrefab itemPrefab, Vector2 position, Submarine submarine)
: this(new Rectangle((int)position.X, (int)position.Y, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), itemPrefab, submarine) : this(new Rectangle(
(int)(position.X - itemPrefab.sprite.size.X / 2),
(int)(position.Y + itemPrefab.sprite.size.Y / 2),
(int)itemPrefab.sprite.size.X,
(int)itemPrefab.sprite.size.Y),
itemPrefab, submarine)
{ {
} }
@@ -511,6 +516,7 @@ namespace Barotrauma
return CurrentHull; return CurrentHull;
} }
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull); CurrentHull = Hull.FindHull(WorldPosition, CurrentHull);
if (body != null && body.Enabled) if (body != null && body.Enabled)
{ {
@@ -690,7 +696,6 @@ namespace Barotrauma
} }
} }
inWater = IsInWater(); inWater = IsInWater();
if (inWater) ApplyStatusEffects(ActionType.InWater, deltaTime); if (inWater) ApplyStatusEffects(ActionType.InWater, deltaTime);
+67 -11
View File
@@ -52,7 +52,7 @@ namespace Barotrauma
if (!spawnQueue.Any()) return; if (!spawnQueue.Any()) return;
List<Item> items = new List<Item>(); List<Item> items = new List<Item>();
List<Inventory> inventories = new List<Inventory>(); //List<Inventory> inventories = new List<Inventory>();
while (spawnQueue.Count>0) while (spawnQueue.Count>0)
{ {
@@ -71,20 +71,25 @@ namespace Barotrauma
if (itemInfo.Second is Inventory) if (itemInfo.Second is Inventory)
{ {
var item = new Item(itemInfo.First, Vector2.Zero, null); var item = new Item(itemInfo.First, Vector2.Zero, null);
spawnItems.Add(item); AddToSpawnedList(item);
var inventory = (Inventory)itemInfo.Second; var inventory = (Inventory)itemInfo.Second;
inventory.TryPutItem(item, null, false); inventory.TryPutItem(item, null, false);
items.Add(item); items.Add(item);
inventories.Add(inventory); //inventories.Add(inventory);
} }
} }
if (GameMain.Server != null) GameMain.Server.SendItemSpawnMessage(items, inventories); if (GameMain.Server != null) GameMain.Server.SendItemSpawnMessage(items);
} }
public void FillNetworkData(Lidgren.Network.NetBuffer message, List<Item> items, List<Inventory> inventories) public void AddToSpawnedList(Item item)
{
spawnItems.Add(item);
}
public void FillNetworkData(Lidgren.Network.NetBuffer message, List<Item> items)
{ {
message.Write((byte)items.Count); message.Write((byte)items.Count);
@@ -93,7 +98,25 @@ namespace Barotrauma
message.Write(items[i].Prefab.Name); message.Write(items[i].Prefab.Name);
message.Write(items[i].ID); message.Write(items[i].ID);
message.Write((inventories == null || inventories[i] == null || inventories[i].Owner == null) ? (ushort)0 : inventories[i].Owner.ID); if (items[i].ParentInventory == null || items[i].ParentInventory.Owner == null)
{
message.Write((ushort)0);
message.Write(items[i].Position.X);
message.Write(items[i].Position.Y);
}
else
{
message.Write(items[i].ParentInventory.Owner.ID);
int index = items[i].ParentInventory.FindIndex(items[i]);
message.Write(index < 0 ? (byte)255 : (byte)index);
}
if (items[i].Name == "ID Card")
{
message.Write(items[i].Tags);
}
} }
} }
@@ -103,10 +126,29 @@ namespace Barotrauma
for (int i = 0; i < itemCount; i++) for (int i = 0; i < itemCount; i++)
{ {
string itemName = message.ReadString(); string itemName = message.ReadString();
ushort itemId = message.ReadUInt16(); ushort itemId = message.ReadUInt16();
Vector2 pos = Vector2.Zero;
ushort inventoryId = message.ReadUInt16(); ushort inventoryId = message.ReadUInt16();
Submarine sub = null;
int inventorySlotIndex = -1;
if (inventoryId > 0)
{
inventorySlotIndex = message.ReadByte();
}
else
{
pos = new Vector2(message.ReadSingle(), message.ReadSingle());
}
string tags = "";
if (itemName == "ID Card")
{
tags = message.ReadString();
}
var prefab = MapEntityPrefab.list.Find(me => me.Name == itemName); var prefab = MapEntityPrefab.list.Find(me => me.Name == itemName);
if (prefab == null) continue; if (prefab == null) continue;
@@ -133,9 +175,23 @@ namespace Barotrauma
} }
} }
var item = new Item(itemPrefab, Vector2.Zero, null); var item = new Item(itemPrefab, pos, null);
item.ID = itemId; item.ID = itemId;
if (inventory != null) inventory.TryPutItem(item, null, false); item.CurrentHull = Hull.FindHull(pos, null, false);
item.Submarine = item.CurrentHull == null ? null : item.CurrentHull.Submarine;
if (!string.IsNullOrEmpty(tags)) item.Tags = tags;
if (inventory != null)
{
if (inventorySlotIndex >= 0 && inventorySlotIndex < 255 &&
inventory.TryPutItem(item, inventorySlotIndex, false, false))
{
continue;
}
inventory.TryPutItem(item, item.AllowedSlots, false);
}
} }
} }
@@ -204,8 +260,8 @@ namespace Barotrauma
{ {
ushort itemId = message.ReadUInt16(); ushort itemId = message.ReadUInt16();
var item = MapEntity.FindEntityByID(itemId); var item = MapEntity.FindEntityByID(itemId) as Item;
if (item == null || !(item is Item)) continue; if (item == null) continue;
item.Remove(); item.Remove();
} }
@@ -411,7 +411,7 @@ namespace Barotrauma.RuinGeneration
doorPos.Y = (wall.A.Y + wall.B.Y) / 2.0f; doorPos.Y = (wall.A.Y + wall.B.Y) / 2.0f;
} }
var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos - new Vector2(doorPrefab.Prefab.sprite.size.X, -doorPrefab.Prefab.sprite.size.Y)/2.0f, null); var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos, null);
door.MoveWithLevel = true; door.MoveWithLevel = true;
door.GetComponent<Items.Components.Door>().IsOpen = Rand.Range(0.0f, 1.0f, false) < 0.8f; door.GetComponent<Items.Components.Door>().IsOpen = Rand.Range(0.0f, 1.0f, false) < 0.8f;
+17 -37
View File
@@ -456,6 +456,8 @@ namespace Barotrauma.Networking
updateTimer = DateTime.Now + updateInterval; updateTimer = DateTime.Now + updateInterval;
} }
private CoroutineHandle startGameCoroutine;
/// <summary> /// <summary>
/// Check for new incoming messages from server /// Check for new incoming messages from server
/// </summary> /// </summary>
@@ -464,6 +466,8 @@ namespace Barotrauma.Networking
// Create new incoming message holder // Create new incoming message holder
NetIncomingMessage inc; NetIncomingMessage inc;
if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return;
while ((inc = client.ReadMessage()) != null) while ((inc = client.ReadMessage()) != null)
{ {
if (inc.MessageType != NetIncomingMessageType.Data) continue; if (inc.MessageType != NetIncomingMessageType.Data) continue;
@@ -492,7 +496,7 @@ namespace Barotrauma.Networking
case (byte)PacketTypes.StartGame: case (byte)PacketTypes.StartGame:
if (Screen.Selected == GameMain.GameScreen) continue; if (Screen.Selected == GameMain.GameScreen) continue;
GameMain.ShowLoading(StartGame(inc), false); startGameCoroutine = GameMain.ShowLoading(StartGame(inc), false);
break; break;
case (byte)PacketTypes.EndGame: case (byte)PacketTypes.EndGame:
@@ -616,6 +620,8 @@ namespace Barotrauma.Networking
Item.Remover.ReadNetworkData(inc); Item.Remover.ReadNetworkData(inc);
break; break;
} }
if (packetType == (byte)PacketTypes.StartGame) break;
} }
} }
@@ -650,7 +656,6 @@ namespace Barotrauma.Networking
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
yield return CoroutineStatus.Running;
Rand.SetSyncedSeed(seed); Rand.SetSyncedSeed(seed);
//int gameModeIndex = inc.ReadInt32(); //int gameModeIndex = inc.ReadInt32();
@@ -660,7 +665,6 @@ namespace Barotrauma.Networking
if (respawnAllowed) respawnManager = new RespawnManager(this); if (respawnAllowed) respawnManager = new RespawnManager(this);
yield return CoroutineStatus.Running;
//myCharacter = ReadCharacterData(inc); //myCharacter = ReadCharacterData(inc);
//Character.Controlled = myCharacter; //Character.Controlled = myCharacter;
@@ -699,7 +703,7 @@ namespace Barotrauma.Networking
Character newCharacter = ReadCharacterData(inc, ownerId == myID); Character newCharacter = ReadCharacterData(inc, ownerId == myID);
if (id != myID) if (ownerId != myID)
{ {
var characterOwner = otherClients.Find(c => c.ID == ownerId); var characterOwner = otherClients.Find(c => c.ID == ownerId);
if (characterOwner != null) characterOwner.Character = newCharacter; if (characterOwner != null) characterOwner.Character = newCharacter;
@@ -707,7 +711,6 @@ namespace Barotrauma.Networking
crew.Add(newCharacter); crew.Add(newCharacter);
} }
//int count = inc.ReadByte(); //int count = inc.ReadByte();
//for (int n = 0; n < count; n++) //for (int n = 0; n < count; n++)
//{ //{
@@ -725,7 +728,8 @@ namespace Barotrauma.Networking
// yield return CoroutineStatus.Running; // yield return CoroutineStatus.Running;
//} //}
} }
gameStarted = true;
gameStarted = true;
endRoundButton.Visible = Voting.AllowEndVoting && myCharacter != null; endRoundButton.Visible = Voting.AllowEndVoting && myCharacter != null;
@@ -1061,12 +1065,7 @@ namespace Barotrauma.Networking
string jobName = inc.ReadString(); string jobName = inc.ReadString();
JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName); JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName);
ushort spawnPointID = inc.ReadUInt16(); //ushort spawnPointID = inc.ReadUInt16();
if (inc.Position > inc.LengthBits)
{
return null;
}
CharacterInfo ch = new CharacterInfo(Character.HumanConfigFile, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab); CharacterInfo ch = new CharacterInfo(Character.HumanConfigFile, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab);
ch.HeadSpriteId = headSpriteID; ch.HeadSpriteId = headSpriteID;
@@ -1076,32 +1075,13 @@ namespace Barotrauma.Networking
character.ID = ID; character.ID = ID;
WayPoint spawnPoint = Entity.FindEntityByID(spawnPointID) as WayPoint; //WayPoint spawnPoint = Entity.FindEntityByID(spawnPointID) as WayPoint;
if (spawnPoint != null) //if (spawnPoint != null)
{ //{
character.GiveJobItems(spawnPoint); // //character.GiveJobItems(spawnPoint);
} //}
for (int i = 0; i < character.Inventory.Items.Length; i++) Item.Spawner.ReadNetworkData(inc);
{
ushort itemID = inc.ReadUInt16();
System.Diagnostics.Debug.Assert((itemID == 0) == (character.Inventory.Items[i] == null));
if (character.Inventory.Items[i] == null) continue;
character.Inventory.Items[i].ID = itemID;
int containedCount = inc.ReadByte();
if (containedCount > 0)
{
var containedItems = character.Inventory.Items[i].ContainedItems;
for (int j = 0; j<containedCount; j++)
{
ushort containedID = inc.ReadUInt16();
if (containedItems[j] != null) containedItems[j].ID = containedID;
}
}
}
if (isMyCharacter) if (isMyCharacter)
{ {
+9 -33
View File
@@ -621,7 +621,7 @@ namespace Barotrauma.Networking
if (gameStarted && AllowSpectating) if (gameStarted && AllowSpectating)
{ {
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset); var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered); server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered);
dataSender.Spectating = true; dataSender.Spectating = true;
CoroutineManager.StartCoroutine(SyncSpectator(dataSender)); CoroutineManager.StartCoroutine(SyncSpectator(dataSender));
@@ -828,7 +828,7 @@ namespace Barotrauma.Networking
} }
SendItemRemoveMessage(Item.Remover.removedItems, new List<NetConnection>() { sender.Connection }); SendItemRemoveMessage(Item.Remover.removedItems, new List<NetConnection>() { sender.Connection });
SendItemSpawnMessage(Item.Spawner.spawnItems, null, new List<NetConnection>() { sender.Connection }); SendItemSpawnMessage(Item.Spawner.spawnItems, new List<NetConnection>() { sender.Connection });
yield return new WaitForSeconds(1.0f); yield return new WaitForSeconds(1.0f);
@@ -1032,7 +1032,6 @@ namespace Barotrauma.Networking
{ {
connectedClients[i].Character = Character.Create( connectedClients[i].Character = Character.Create(
connectedClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false); connectedClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
connectedClients[i].Character.SpawnPoint = assignedWayPoints[i];
connectedClients[i].Character.GiveJobItems(assignedWayPoints[i]); connectedClients[i].Character.GiveJobItems(assignedWayPoints[i]);
GameMain.GameSession.CrewManager.characters.Add(connectedClients[i].Character); GameMain.GameSession.CrewManager.characters.Add(connectedClients[i].Character);
@@ -1043,14 +1042,16 @@ namespace Barotrauma.Networking
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false); myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
Character.Controlled = myCharacter; Character.Controlled = myCharacter;
myCharacter.SpawnPoint = assignedWayPoints[assignedWayPoints.Length - 1];
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]); myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
GameMain.GameSession.CrewManager.characters.Add(myCharacter); GameMain.GameSession.CrewManager.characters.Add(myCharacter);
} }
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset); var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
SendMessage(startMessage, NetDeliveryMethod.ReliableUnordered);
SendMessage(startMessage, NetDeliveryMethod.ReliableOrdered);
//SendItemSpawnMessage(allItems, inventories);
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
@@ -1747,33 +1748,8 @@ namespace Barotrauma.Networking
message.Write(character.WorldPosition.Y); message.Write(character.WorldPosition.Y);
message.Write(character.Info.Job.Name); message.Write(character.Info.Job.Name);
message.Write(character.SpawnPoint == null ? (ushort)0 : character.SpawnPoint.ID);
for (int i = 0; i < character.Inventory.Items.Length; i++) Item.Spawner.FillNetworkData(message, character.SpawnItems);
{
if (character.Inventory.Items[i] == null)
{
message.Write((ushort)0);
}
else
{
message.Write(character.Inventory.Items[i].ID);
var containedItems = character.Inventory.Items[i].ContainedItems;
if (containedItems == null || !containedItems.Any(c => c != null))
{
message.Write((byte)0);
}
else
{
message.Write((byte)containedItems.Length);
for (int j = 0; j < containedItems.Length; j++)
{
message.Write(containedItems[j] == null ? (ushort)0 : containedItems[j].ID);
}
}
}
}
} }
public void SendCharacterSpawnMessage(Character character, List<NetConnection> recipients = null) public void SendCharacterSpawnMessage(Character character, List<NetConnection> recipients = null)
@@ -1791,14 +1767,14 @@ namespace Barotrauma.Networking
SendMessage(message, NetDeliveryMethod.ReliableUnordered, recipients); SendMessage(message, NetDeliveryMethod.ReliableUnordered, recipients);
} }
public void SendItemSpawnMessage(List<Item> items, List<Inventory> inventories = null, List<NetConnection> recipients = null) public void SendItemSpawnMessage(List<Item> items, List<NetConnection> recipients = null)
{ {
if (items == null || !items.Any()) return; if (items == null || !items.Any()) return;
NetOutgoingMessage message = server.CreateMessage(); NetOutgoingMessage message = server.CreateMessage();
message.Write((byte)PacketTypes.NewItem); message.Write((byte)PacketTypes.NewItem);
Item.Spawner.FillNetworkData(message, items, inventories); Item.Spawner.FillNetworkData(message, items);
SendMessage(message, NetDeliveryMethod.ReliableOrdered, recipients); SendMessage(message, NetDeliveryMethod.ReliableOrdered, recipients);
} }
+31 -4
View File
@@ -224,6 +224,8 @@ namespace Barotrauma.Networking
{ {
updateReturnTimer = 0.0f; updateReturnTimer = 0.0f;
respawnShuttle.SubBody.Body.IgnoreCollisionWith(Level.Loaded.ShaftBodies[0]);
shuttleSteering.AutoPilot = true; shuttleSteering.AutoPilot = true;
shuttleSteering.MaintainPos = false; shuttleSteering.MaintainPos = false;
@@ -279,6 +281,8 @@ namespace Barotrauma.Networking
ResetShuttle(); ResetShuttle();
shuttleSteering.TargetVelocity = Vector2.Zero;
server.SendChatMessage(ChatMessage.Create("", "Transportation shuttle dispatched", ChatMessageType.Server, null), server.ConnectedClients); server.SendChatMessage(ChatMessage.Create("", "Transportation shuttle dispatched", ChatMessageType.Server, null), server.ConnectedClients);
server.SendRespawnManagerMsg(); server.SendRespawnManagerMsg();
@@ -346,6 +350,9 @@ namespace Barotrauma.Networking
respawnShuttle.SetPosition(new Vector2(Level.Loaded.StartPosition.X, Level.Loaded.Size.Y + respawnShuttle.Borders.Height)); respawnShuttle.SetPosition(new Vector2(Level.Loaded.StartPosition.X, Level.Loaded.Size.Y + respawnShuttle.Borders.Height));
respawnShuttle.Velocity = Vector2.Zero; respawnShuttle.Velocity = Vector2.Zero;
respawnShuttle.SubBody.Body.RestoreCollisionWith(Level.Loaded.ShaftBodies[0]);
} }
public void WriteNetworkEvent(NetOutgoingMessage msg) public void WriteNetworkEvent(NetOutgoingMessage msg)
@@ -371,11 +378,34 @@ namespace Barotrauma.Networking
var waypoints = WayPoint.SelectCrewSpawnPoints(characterInfos, respawnShuttle); var waypoints = WayPoint.SelectCrewSpawnPoints(characterInfos, respawnShuttle);
ItemPrefab divingSuitPrefab = ItemPrefab.list.Find(ip => ip.Name == "Diving Suit") as ItemPrefab;
ItemPrefab oxyPrefab = ItemPrefab.list.Find(ip => ip.Name == "Oxygen Tank") as ItemPrefab;
var cargoSp = WayPoint.WayPointList.Find(wp => wp.Submarine == respawnShuttle && wp.SpawnType == SpawnType.Cargo);
List<Item> spawnedItems = new List<Item>();
msg.Write((byte)characterInfos.Count); msg.Write((byte)characterInfos.Count);
for (int i = 0; i < characterInfos.Count; i++) for (int i = 0; i < characterInfos.Count; i++)
{ {
var character = Character.Create(characterInfos[i], waypoints[i].WorldPosition, true, false); var character = Character.Create(characterInfos[i], waypoints[i].WorldPosition, true, false);
if (divingSuitPrefab != null && oxyPrefab != null)
{
Vector2 pos = cargoSp == null ? character.Position : cargoSp.Position;
var divingSuit = new Item(divingSuitPrefab, pos, respawnShuttle);
var oxyTank = new Item(oxyPrefab, pos, respawnShuttle);
oxyTank.Combine(divingSuit);
spawnedItems.Add(divingSuit);
spawnedItems.Add(oxyTank);
Item.Spawner.AddToSpawnedList(divingSuit);
Item.Spawner.AddToSpawnedList(oxyTank);
}
if (i < clients.Count) if (i < clients.Count)
{ {
msg.Write((byte)clients[i].ID); msg.Write((byte)clients[i].ID);
@@ -388,7 +418,6 @@ namespace Barotrauma.Networking
Character.Controlled = character; Character.Controlled = character;
} }
character.SpawnPoint = waypoints[i];
character.GiveJobItems(waypoints[i]); character.GiveJobItems(waypoints[i]);
GameMain.GameSession.CrewManager.characters.Add(character); GameMain.GameSession.CrewManager.characters.Add(character);
@@ -396,6 +425,7 @@ namespace Barotrauma.Networking
server.WriteCharacterData(msg, character.Name, character); server.WriteCharacterData(msg, character.Name, character);
} }
GameMain.Server.SendItemSpawnMessage(spawnedItems);
break; break;
case State.Waiting: case State.Waiting:
msg.Write(CountdownStarted); msg.Write(CountdownStarted);
@@ -437,14 +467,11 @@ namespace Barotrauma.Networking
case State.Waiting: case State.Waiting:
CountdownStarted = true; CountdownStarted = true;
respawnShuttle.SubBody.Body.RestoreCollisionWith(Level.Loaded.ShaftBodies[0]);
ResetShuttle(); ResetShuttle();
respawnTimer = inc.ReadSingle(); respawnTimer = inc.ReadSingle();
break; break;
case State.Returning: case State.Returning:
respawnShuttle.SubBody.Body.IgnoreCollisionWith(Level.Loaded.ShaftBodies[0]);
CountdownStarted = false; CountdownStarted = false;
break; break;