(6b47d1ebc) Fixed inability to spawn items in characters' inventories and simplified the spawnitem command (multi-word item/character names must be surrounded with quotation marks now, so we don't have to guess which words belong to the item name and which to the character name). + added "startwhenclientsready" console command

This commit is contained in:
Joonas Rikkonen
2019-06-04 16:43:16 +03:00
parent 3bc52e2d95
commit 808fcdcb75
2 changed files with 88 additions and 43 deletions

View File

@@ -252,7 +252,7 @@ namespace Barotrauma
NewMessage(GameMain.Server.ServerSettings.AutoRestart ? "Automatic restart enabled." : "Automatic restart disabled.", Color.White);
});
AssignOnExecute("autorestartinterval",(string[] args) =>
AssignOnExecute("autorestartinterval", (string[] args) =>
{
if (GameMain.Server == null) return;
if (args.Length > 0)
@@ -308,6 +308,26 @@ namespace Barotrauma
}
});
AssignOnExecute("startwhenclientsready", (string[] args) =>
{
if (GameMain.Server == null) { return; }
bool enabled = GameMain.Server.ServerSettings.StartWhenClientsReady;
if (args.Length > 0)
{
bool.TryParse(args[0], out enabled);
}
else
{
enabled = !enabled;
}
if (enabled != GameMain.Server.ServerSettings.StartWhenClientsReady)
{
GameMain.Server.ServerSettings.StartWhenClientsReady = enabled;
GameMain.NetLobbyScreen.LastUpdateID++;
}
NewMessage(GameMain.Server.ServerSettings.StartWhenClientsReady ? "Enabled starting the round automatically when clients are ready." : "Disabled starting the round automatically when clients are ready.", Color.White);
});
AssignOnExecute("giveperm", (string[] args) =>
{
if (GameMain.Server == null) return;

View File

@@ -291,6 +291,50 @@ namespace Barotrauma
commands.Add(new Command("autorestarttimer", "autorestarttimer [seconds]: Set the current autorestart countdown to the specified value.", null));
commands.Add(new Command("startwhenclientsready", "startwhenclientsready [true/false]: Enable or disable automatically starting the round when clients are ready to start.", null));
commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", null));
commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", null));
commands.Add(new Command("giverank", "giverank [id]: Assigns a specific rank (= a set of administrative permissions) to the player with the specified client ID.", null));
commands.Add(new Command("givecommandperm", "givecommandperm [id]: Gives the player with the specified client ID the permission to use the specified console commands.", null));
commands.Add(new Command("revokecommandperm", "revokecommandperm [id]: Revokes permission to use the specified console commands from the player with the specified client ID.", null));
commands.Add(new Command("showperm", "showperm [id]: Shows the current administrative permissions of the client with the specified client ID.", null));
//commands.Add(new Command("togglekarma", "togglekarma: Toggles the karma system.", null));
commands.Add(new Command("enablecrewai", "enablecrewai: Enable the AI of the NPCs in the crew.", (string[] args) =>
{
HumanAIController.DisableCrewAI = false;
NewMessage("Crew AI enabled", Color.Green);
}, isCheat: true));
commands.Add(new Command("disableenemyai", "disableenemyai: Disable the AI of the Enemy characters (monsters).", (string[] args) =>
{
EnemyAIController.DisableEnemyAI = true;
NewMessage("Enemy AI disabled", Color.Red);
}, isCheat: true));
commands.Add(new Command("enableenemyai", "enableenemyai: Enable the AI of the Enemy characters (monsters).", (string[] args) =>
{
EnemyAIController.DisableEnemyAI = false;
NewMessage("Enemy AI enabled", Color.Green);
}, isCheat: true));
commands.Add(new Command("botcount", "botcount [x]: Set the number of bots in the crew in multiplayer.", null));
commands.Add(new Command("botspawnmode", "botspawnmode [fill/normal]: Set how bots are spawned in the multiplayer.", null));
commands.Add(new Command("autorestart", "autorestart [true/false]: Enable or disable round auto-restart.", null));
commands.Add(new Command("autorestartinterval", "autorestartinterval [seconds]: Set how long the server waits between rounds before automatically starting a new one. If set to 0, autorestart is disabled.", null));
commands.Add(new Command("autorestarttimer", "autorestarttimer [seconds]: Set the current autorestart countdown to the specified value.", null));
commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", null));
commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", null));
@@ -1235,9 +1279,8 @@ namespace Barotrauma
{
if (args.Length == 0) return null;
int characterIndex;
string characterName;
if (int.TryParse(args.Last(), out characterIndex) && args.Length > 1)
if (int.TryParse(args.Last(), out int characterIndex) && args.Length > 1)
{
characterName = string.Join(" ", args.Take(args.Length - 1)).ToLowerInvariant();
}
@@ -1391,51 +1434,33 @@ namespace Barotrauma
Vector2? spawnPos = null;
Inventory spawnInventory = null;
int extraParams = 0;
switch (args.Last().ToLowerInvariant())
if (args.Length > 1)
{
case "cursor":
extraParams = 1;
spawnPos = cursorPos;
break;
case "inventory":
extraParams = 1;
spawnInventory = controlledCharacter?.Inventory;
break;
case "cargo":
var wp = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub);
spawnPos = wp == null ? Vector2.Zero : wp.WorldPosition;
break;
//Dont do a thing, random is basically Human points anyways - its in the help description.
case "random":
extraParams = 1;
return;
default:
extraParams = 0;
break;
}
string itemName = string.Join(" ", args.Take(args.Length - extraParams)).ToLowerInvariant();
ItemPrefab itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab;
if (itemPrefab == null && extraParams == 0)
{
#if SERVER
if (GameMain.Server != null)
switch (args.Last())
{
var client = GameMain.Server.ConnectedClients.Find(c => c.Name.ToLower() == args.Last().ToLower());
if (client != null)
{
extraParams += 1;
itemName = string.Join(" ", args.Take(args.Length - extraParams)).ToLowerInvariant();
if (client.Character != null && client.Character.Name == args.Last().ToLower()) spawnInventory = client.Character.Inventory;
itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab;
}
case "cursor":
spawnPos = cursorPos;
break;
case "inventory":
spawnInventory = controlledCharacter?.Inventory;
break;
case "cargo":
var wp = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub);
spawnPos = wp == null ? Vector2.Zero : wp.WorldPosition;
break;
case "random":
//Dont do a thing, random is basically Human points anyways - its in the help description.
break;
default:
var matchingCharacter = FindMatchingCharacter(args.Skip(1).ToArray());
if (matchingCharacter != null){ spawnInventory = matchingCharacter.Inventory; }
break;
}
#endif
}
//Check again if the item can be found again after having checked for a character
if (itemPrefab == null)
string itemName = args[0].ToLowerInvariant();
if (!(MapEntityPrefab.Find(itemName) is ItemPrefab itemPrefab))
{
errorMsg = "Item \"" + itemName + "\" not found!";
return;