(913ed2ce9) Merge remote-tracking branch 'origin/dev' into enemy-ai

This commit is contained in:
Joonas Rikkonen
2019-03-26 14:07:11 +02:00
parent 14832e2040
commit 4b3e78b566
11 changed files with 167 additions and 45 deletions
@@ -93,7 +93,7 @@ namespace Barotrauma.Items.Components
public void Draw(SpriteBatch spriteBatch, bool editing) public void Draw(SpriteBatch spriteBatch, bool editing)
{ {
Color color = Color.White; Color color = item.SpriteColor;
if (brokenSprite == null) if (brokenSprite == null)
{ {
//broken doors turn black if no broken sprite has been configured //broken doors turn black if no broken sprite has been configured
@@ -108,7 +108,7 @@ namespace Barotrauma.Items.Components
weldSpritePos.Y = -weldSpritePos.Y; weldSpritePos.Y = -weldSpritePos.Y;
weldedSprite.Draw(spriteBatch, weldedSprite.Draw(spriteBatch,
weldSpritePos, Color.White * (stuck / 100.0f), scale: item.Scale); weldSpritePos, item.SpriteColor * (stuck / 100.0f), scale: item.Scale);
} }
if (openState == 1.0f) if (openState == 1.0f)
@@ -237,13 +237,13 @@ namespace Barotrauma.Items.Components
railSprite?.Draw(spriteBatch, railSprite?.Draw(spriteBatch,
drawPos, drawPos,
Color.White, item.SpriteColor,
rotation + MathHelper.PiOver2, item.Scale, rotation + MathHelper.PiOver2, item.Scale,
SpriteEffects.None, item.SpriteDepth + (railSprite.Depth - item.Sprite.Depth)); SpriteEffects.None, item.SpriteDepth + (railSprite.Depth - item.Sprite.Depth));
barrelSprite?.Draw(spriteBatch, barrelSprite?.Draw(spriteBatch,
drawPos - new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * recoilOffset * item.Scale, drawPos - new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * recoilOffset * item.Scale,
Color.White, item.SpriteColor,
rotation + MathHelper.PiOver2, item.Scale, rotation + MathHelper.PiOver2, item.Scale,
SpriteEffects.None, item.SpriteDepth + (barrelSprite.Depth - item.Sprite.Depth)); SpriteEffects.None, item.SpriteDepth + (barrelSprite.Depth - item.Sprite.Depth));
@@ -241,20 +241,30 @@ namespace Barotrauma.Networking
FileSize = fileSize FileSize = fileSize
}; };
try int maxRetries = 4;
for (int i = 0; i <= maxRetries; i++)
{ {
newTransfer.OpenStream(); try
{
newTransfer.OpenStream();
}
catch (IOException e)
{
if (i < maxRetries)
{
DebugConsole.NewMessage("Failed to initiate a file transfer {" + e.Message + "}, retrying in 250 ms...", Color.Red);
Thread.Sleep(250);
}
else
{
DebugConsole.NewMessage("Failed to initiate a file transfer {" + e.Message + "}", Color.Red);
GameMain.Client.CancelFileTransfer(inc.SequenceChannel);
newTransfer.Status = FileTransferStatus.Error;
OnTransferFailed(newTransfer);
return;
}
}
} }
catch (IOException e)
{
GameMain.Client.CancelFileTransfer(inc.SequenceChannel);
DebugConsole.NewMessage("Failed to initiate a file transfer {" + e.Message + "}", Color.Red);
newTransfer.Status = FileTransferStatus.Error;
OnTransferFailed(newTransfer);
return;
}
activeTransfers.Add(newTransfer); activeTransfers.Add(newTransfer);
} }
break; break;
@@ -141,8 +141,23 @@ namespace Barotrauma.Networking
{ {
OnClicked = (btn, userdata) => OnClicked = (btn, userdata) =>
{ {
if (!permissions.HasFlag(ClientPermissions.ManageRound)) return false; if (!permissions.HasFlag(ClientPermissions.ManageRound)) { return false; }
RequestRoundEnd(); if (!Submarine.MainSub.AtStartPosition && !Submarine.MainSub.AtEndPosition)
{
var msgBox = new GUIMessageBox("", TextManager.Get("EndRoundSubNotAtLevelEnd"),
new string[] { TextManager.Get("Yes"), TextManager.Get("No") });
msgBox.Buttons[0].OnClicked = (_, __) =>
{
GameMain.Client.RequestRoundEnd();
return true;
};
msgBox.Buttons[0].OnClicked += msgBox.Close;
msgBox.Buttons[1].OnClicked += msgBox.Close;
}
else
{
RequestRoundEnd();
}
return true; return true;
}, },
Visible = false Visible = false
@@ -1267,6 +1282,75 @@ namespace Barotrauma.Networking
} }
} }
private void ReadLobbyUpdate(NetIncomingMessage inc)
{
UInt16 listId = inc.ReadUInt16();
List<TempClient> tempClients = new List<TempClient>();
int clientCount = inc.ReadByte();
for (int i = 0; i < clientCount; i++)
{
byte id = inc.ReadByte();
string name = inc.ReadString();
UInt16 characterID = inc.ReadUInt16();
bool muted = inc.ReadBoolean();
inc.ReadPadBits();
tempClients.Add(new TempClient
{
ID = id,
Name = name,
CharacterID = characterID,
Muted = muted
});
}
if (NetIdUtils.IdMoreRecent(listId, LastClientListUpdateID))
{
bool updateClientListId = true;
List<Client> currentClients = new List<Client>();
foreach (TempClient tc in tempClients)
{
//see if the client already exists
var existingClient = ConnectedClients.Find(c => c.ID == tc.ID && c.Name == tc.Name);
if (existingClient == null) //if not, create it
{
existingClient = new Client(tc.Name, tc.ID)
{
Muted = tc.Muted
};
ConnectedClients.Add(existingClient);
GameMain.NetLobbyScreen.AddPlayer(existingClient);
}
existingClient.Character = null;
existingClient.Muted = tc.Muted;
if (tc.CharacterID > 0)
{
existingClient.Character = Entity.FindEntityByID(tc.CharacterID) as Character;
if (existingClient.Character == null)
{
updateClientListId = false;
}
}
if (existingClient.ID == myID)
{
existingClient.SetPermissions(permissions, permittedConsoleCommands);
}
currentClients.Add(existingClient);
}
//remove clients that aren't present anymore
for (int i = ConnectedClients.Count - 1; i >= 0; i--)
{
if (!currentClients.Contains(ConnectedClients[i]))
{
GameMain.NetLobbyScreen.RemovePlayer(ConnectedClients[i]);
ConnectedClients[i].Dispose();
ConnectedClients.RemoveAt(i);
}
}
if (updateClientListId) LastClientListUpdateID = listId;
}
}
private void ReadLobbyUpdate(NetIncomingMessage inc) private void ReadLobbyUpdate(NetIncomingMessage inc)
{ {
ServerNetObject objHeader; ServerNetObject objHeader;
@@ -1429,7 +1513,11 @@ namespace Barotrauma.Networking
break; break;
case ServerNetObject.ENTITY_EVENT: case ServerNetObject.ENTITY_EVENT:
case ServerNetObject.ENTITY_EVENT_INITIAL: case ServerNetObject.ENTITY_EVENT_INITIAL:
if (!entityEventManager.Read(objHeader, inc, sendingTime, entities)) { break; } if (!entityEventManager.Read(objHeader, inc, sendingTime, entities))
{
eventReadFailed = true;
break;
}
break; break;
case ServerNetObject.CHAT_MESSAGE: case ServerNetObject.CHAT_MESSAGE:
ChatMessage.ClientRead(inc); ChatMessage.ClientRead(inc);
@@ -457,11 +457,14 @@ namespace Barotrauma
{ {
IgnoreLayoutGroups = true, IgnoreLayoutGroups = true,
OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return true; }, OnClicked = (GUIButton btn, object obj) => { StartRound?.Invoke(); return true; },
Enabled = true, Enabled = true
Visible = GameMain.Client == null ||
GameMain.Client.HasPermission(Networking.ClientPermissions.ManageRound) ||
GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign)
}; };
if (GameMain.Client != null)
{
startButton.Visible = !GameMain.Client.GameStarted &&
(GameMain.Client.HasPermission(Networking.ClientPermissions.ManageRound) ||
GameMain.Client.HasPermission(Networking.ClientPermissions.ManageCampaign));
}
} }
OnLocationSelected?.Invoke(location, connection); OnLocationSelected?.Invoke(location, connection);
@@ -726,6 +726,12 @@ namespace Barotrauma
spectateButton.Visible = GameMain.Client.GameStarted; spectateButton.Visible = GameMain.Client.GameStarted;
ReadyToStartBox.Visible = !GameMain.Client.GameStarted; ReadyToStartBox.Visible = !GameMain.Client.GameStarted;
ReadyToStartBox.Selected = false; ReadyToStartBox.Selected = false;
if (campaignUI?.StartButton != null)
{
campaignUI.StartButton.Visible = !GameMain.Client.GameStarted &&
(GameMain.Client.HasPermission(ClientPermissions.ManageRound) ||
GameMain.Client.HasPermission(ClientPermissions.ManageCampaign));
}
GameMain.Client.SetReadyToStart(ReadyToStartBox); GameMain.Client.SetReadyToStart(ReadyToStartBox);
} }
else else
@@ -847,9 +853,9 @@ namespace Barotrauma
if (campaignUI?.StartButton != null) if (campaignUI?.StartButton != null)
{ {
campaignUI.StartButton.Visible = campaignUI.StartButton.Visible = !GameMain.Client.GameStarted &&
GameMain.Client.HasPermission(ClientPermissions.ManageRound) || (GameMain.Client.HasPermission(ClientPermissions.ManageRound) ||
GameMain.Client.HasPermission(ClientPermissions.ManageCampaign); GameMain.Client.HasPermission(ClientPermissions.ManageCampaign));
} }
} }
@@ -813,7 +813,16 @@ namespace Barotrauma.Networking
Log(c.Name + " has reported an error: " + errorStr, ServerLog.MessageType.Error); Log(c.Name + " has reported an error: " + errorStr, ServerLog.MessageType.Error);
GameAnalyticsManager.AddErrorEventOnce("GameServer.HandleClientError:LevelsDontMatch" + error, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorStr); GameAnalyticsManager.AddErrorEventOnce("GameServer.HandleClientError:LevelsDontMatch" + error, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorStr);
KickClient(c, errorStr);
if (c.Connection == OwnerConnection)
{
SendDirectChatMessage(errorStr, c, ChatMessageType.MessageBox);
EndGame();
}
else
{
KickClient(c, errorStr);
}
} }
public override void CreateEntityEvent(INetSerializable entity, object[] extraData = null) public override void CreateEntityEvent(INetSerializable entity, object[] extraData = null)
@@ -1030,7 +1039,7 @@ namespace Barotrauma.Networking
if (command == ClientPermissions.ManageRound && inc.PeekBoolean() && if (command == ClientPermissions.ManageRound && inc.PeekBoolean() &&
GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign) GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign)
{ {
if (!mpCampaign.AllowedToEndRound(sender.Character)) if (!mpCampaign.AllowedToEndRound(sender.Character) && !sender.HasPermission(command))
{ {
return; return;
} }
@@ -103,12 +103,6 @@ namespace Barotrauma
if (missionType == MissionType.Random) if (missionType == MissionType.Random)
{ {
allowedMissions.AddRange(MissionPrefab.List); allowedMissions.AddRange(MissionPrefab.List);
#if SERVER
if (GameMain.Server != null)
{
allowedMissions.RemoveAll(mission => !GameMain.Server.ServerSettings.AllowedRandomMissionTypes.Contains(mission.type));
}
#endif
} }
else if (missionType == MissionType.None) else if (missionType == MissionType.None)
{ {
@@ -211,14 +211,14 @@ namespace Barotrauma
set { spriteColor = value; } set { spriteColor = value; }
} }
[Serialize("1.0,1.0,1.0,1.0", false), Editable] [Serialize("1.0,1.0,1.0,1.0", true), Editable]
public Color InventoryIconColor public Color InventoryIconColor
{ {
get; get;
protected set; protected set;
} }
[Serialize("1.0,1.0,1.0,1.0", false), Editable(ToolTip = "Changes the color of the item this item is contained inside. Only has an effect if either of the UseContainedSpriteColor or UseContainedInventoryIconColor property of the container is set to true.")] [Serialize("1.0,1.0,1.0,1.0", true), Editable(ToolTip = "Changes the color of the item this item is contained inside. Only has an effect if either of the UseContainedSpriteColor or UseContainedInventoryIconColor property of the container is set to true.")]
public Color ContainerColor public Color ContainerColor
{ {
get; get;
@@ -33,7 +33,7 @@ namespace Barotrauma
get get
{ {
CheckMissionCompleted(); CheckMissionCompleted();
for (int i = availableMissions.Count; i < Connections.Count * 2; i++) for (int i = availableMissions.Count; i < Connections.Count * 2; i++)
{ {
int seed = (ToolBox.StringToInt(BaseName) + MissionsCompleted * 10 + i) % int.MaxValue; int seed = (ToolBox.StringToInt(BaseName) + MissionsCompleted * 10 + i) % int.MaxValue;
@@ -47,7 +47,7 @@ namespace Barotrauma
if (availableMissions.Any(m => m.Prefab == mission.Prefab)) { continue; } if (availableMissions.Any(m => m.Prefab == mission.Prefab)) { continue; }
if (GameSettings.VerboseLogging && mission != null) if (GameSettings.VerboseLogging && mission != null)
{ {
DebugConsole.NewMessage("Generated a new mission for a location connection (seed: " + seed.ToString("X") + ", type: " + mission.Name + ")", Color.White); DebugConsole.NewMessage("Generated a new mission for a location (location: " + Name + ", seed: " + seed.ToString("X") + ", missions completed: " + MissionsCompleted + ", type: " + mission.Name + ")", Color.White);
} }
availableMissions.Add(mission); availableMissions.Add(mission);
} }
@@ -100,7 +100,16 @@ namespace Barotrauma
public void ChangeType(LocationType newType) public void ChangeType(LocationType newType)
{ {
if (newType == Type) return; if (newType == Type) { return; }
//clear missions from this and adjacent locations (they may be invalid now)
availableMissions.Clear();
foreach (LocationConnection connection in Connections)
{
connection.OtherLocation(this)?.availableMissions.Clear();
}
DebugConsole.Log("Location " + baseName + " changed it's type from " + Type + " to " + newType);
Type = newType; Type = newType;
Name = Type.NameFormats[nameFormatIndex % Type.NameFormats.Count].Replace("[name]", baseName); Name = Type.NameFormats[nameFormatIndex % Type.NameFormats.Count].Replace("[name]", baseName);
@@ -112,6 +121,7 @@ namespace Barotrauma
{ {
if (mission.Completed) if (mission.Completed)
{ {
DebugConsole.Log("Mission \"" + mission.Name + "\" completed in \"" + Name + "\".");
MissionsCompleted++; MissionsCompleted++;
} }
} }
@@ -119,7 +129,7 @@ namespace Barotrauma
availableMissions.RemoveAll(m => m.Completed); availableMissions.RemoveAll(m => m.Completed);
} }
private string RandomName(LocationType type) public void Remove()
{ {
baseName = type.GetRandomName(); baseName = type.GetRandomName();
nameFormatIndex = Rand.Int(type.NameFormats.Count, Rand.RandSync.Server); nameFormatIndex = Rand.Int(type.NameFormats.Count, Rand.RandSync.Server);
@@ -32,6 +32,7 @@ namespace Barotrauma
public static void SaveGame(string filePath) public static void SaveGame(string filePath)
{ {
DebugConsole.Log("Saving the game to: " + filePath);
Directory.CreateDirectory(TempPath); Directory.CreateDirectory(TempPath);
try try
{ {
@@ -111,6 +112,7 @@ namespace Barotrauma
public static XDocument LoadGameSessionDoc(string filePath) public static XDocument LoadGameSessionDoc(string filePath)
{ {
DebugConsole.Log("Loading game session doc: " + filePath);
try try
{ {
DecompressToDirectory(filePath, TempPath, null); DecompressToDirectory(filePath, TempPath, null);
@@ -401,18 +403,18 @@ namespace Barotrauma
} }
} }
public static void ClearFolder(string FolderName, string[] ignoredFiles = null) public static void ClearFolder(string FolderName, string[] ignoredFileNames = null)
{ {
DirectoryInfo dir = new DirectoryInfo(FolderName); DirectoryInfo dir = new DirectoryInfo(FolderName);
foreach (FileInfo fi in dir.GetFiles()) foreach (FileInfo fi in dir.GetFiles())
{ {
if (ignoredFiles != null) if (ignoredFileNames != null)
{ {
bool ignore = false; bool ignore = false;
foreach (string ignoredFile in ignoredFiles) foreach (string ignoredFile in ignoredFileNames)
{ {
if (Path.GetFullPath(fi.FullName).Equals(Path.GetFullPath(ignoredFile))) if (Path.GetFileName(fi.FullName).Equals(Path.GetFileName(ignoredFile)))
{ {
ignore = true; ignore = true;
break; break;