Fixed crash with disabled monsters
This commit is contained in:
@@ -16,6 +16,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private bool spawnDeep;
|
private bool spawnDeep;
|
||||||
|
|
||||||
|
private bool disallowed;
|
||||||
|
|
||||||
private Level.PositionType spawnPosType;
|
private Level.PositionType spawnPosType;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@@ -40,6 +42,16 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
spawnDeep = ToolBox.GetAttributeBool(element, "spawndeep", false);
|
spawnDeep = ToolBox.GetAttributeBool(element, "spawndeep", false);
|
||||||
|
|
||||||
|
if (GameMain.Server != null)
|
||||||
|
{
|
||||||
|
List<string> monsterNames = GameMain.Server.monsterEnabled.Keys.ToList();
|
||||||
|
string tryKey = monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower()));
|
||||||
|
if (!string.IsNullOrWhiteSpace(tryKey))
|
||||||
|
{
|
||||||
|
if (!GameMain.Server.monsterEnabled[tryKey]) disallowed = true; //spawn was disallowed by host
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Start()
|
protected override void Start()
|
||||||
@@ -49,15 +61,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private void SpawnMonsters()
|
private void SpawnMonsters()
|
||||||
{
|
{
|
||||||
if (GameMain.Server != null)
|
if (disallowed) return;
|
||||||
{
|
|
||||||
List<string> monsterNames = GameMain.Server.monsterEnabled.Keys.ToList();
|
|
||||||
string tryKey = monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower()));
|
|
||||||
if (!string.IsNullOrWhiteSpace(tryKey))
|
|
||||||
{
|
|
||||||
if (!GameMain.Server.monsterEnabled[tryKey]) return; //spawn was disallowed by host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float minDist = Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
|
float minDist = Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
|
||||||
|
|
||||||
@@ -90,6 +94,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public override void Update(float deltaTime)
|
public override void Update(float deltaTime)
|
||||||
{
|
{
|
||||||
|
if (disallowed)
|
||||||
|
{
|
||||||
|
Finished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (monsters == null) SpawnMonsters();
|
if (monsters == null) SpawnMonsters();
|
||||||
|
|
||||||
//base.Update(deltaTime);
|
//base.Update(deltaTime);
|
||||||
|
|||||||
@@ -65,12 +65,12 @@ namespace Barotrauma
|
|||||||
while (tries < 5)
|
while (tries < 5)
|
||||||
{
|
{
|
||||||
ScriptedEvent scriptedEvent = ScriptedEvent.LoadRandom(rand);
|
ScriptedEvent scriptedEvent = ScriptedEvent.LoadRandom(rand);
|
||||||
DebugConsole.Log("Created scripted event "+scriptedEvent.ToString());
|
|
||||||
if (scriptedEvent==null || scriptedEvent.Difficulty > totalDifficulty)
|
if (scriptedEvent==null || scriptedEvent.Difficulty > totalDifficulty)
|
||||||
{
|
{
|
||||||
tries++;
|
tries++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
DebugConsole.Log("Created scripted event " + scriptedEvent.ToString());
|
||||||
|
|
||||||
AddTask(new ScriptedTask(scriptedEvent));
|
AddTask(new ScriptedTask(scriptedEvent));
|
||||||
totalDifficulty -= scriptedEvent.Difficulty;
|
totalDifficulty -= scriptedEvent.Difficulty;
|
||||||
|
|||||||
Reference in New Issue
Block a user