Fixed clients spawning monsters twice (first during mission/event initialization and again when the server notifies them about the spawning)
This commit is contained in:
@@ -450,7 +450,7 @@ namespace Barotrauma
|
|||||||
return Create(characterInfo.File, position, characterInfo, isRemotePlayer, hasAi);
|
return Create(characterInfo.File, position, characterInfo, isRemotePlayer, hasAi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Character Create(string file, Vector2 position, CharacterInfo characterInfo = null, bool isRemotePlayer = false, bool hasAi=true)
|
public static Character Create(string file, Vector2 position, CharacterInfo characterInfo = null, bool isRemotePlayer = false, bool hasAi=true, bool createNetworkEvent = true)
|
||||||
{
|
{
|
||||||
#if LINUX
|
#if LINUX
|
||||||
if (!System.IO.File.Exists(file))
|
if (!System.IO.File.Exists(file))
|
||||||
@@ -508,8 +508,10 @@ namespace Barotrauma
|
|||||||
newCharacter.minHealth = -100.0f;
|
newCharacter.minHealth = -100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameMain.Server != null && Entity.Spawner != null)
|
if (GameMain.Server != null && Spawner != null && createNetworkEvent)
|
||||||
Entity.Spawner.CreateNetworkEvent(newCharacter, false);
|
{
|
||||||
|
Spawner.CreateNetworkEvent(newCharacter, false);
|
||||||
|
}
|
||||||
|
|
||||||
return newCharacter;
|
return newCharacter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ namespace Barotrauma
|
|||||||
: base(element, locations)
|
: base(element, locations)
|
||||||
{
|
{
|
||||||
monsterFile = ToolBox.GetAttributeString(element, "monsterfile", "");
|
monsterFile = ToolBox.GetAttributeString(element, "monsterfile", "");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Start(Level level)
|
public override void Start(Level level)
|
||||||
{
|
{
|
||||||
Vector2 spawnPos = Level.Loaded.GetRandomInterestingPosition(true, Level.PositionType.MainPath, true);
|
Vector2 spawnPos = Level.Loaded.GetRandomInterestingPosition(true, Level.PositionType.MainPath, true);
|
||||||
|
|
||||||
monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null);
|
monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null, true, false);
|
||||||
monster.Enabled = false;
|
monster.Enabled = false;
|
||||||
radarPosition = spawnPos;
|
radarPosition = spawnPos;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
base.Init();
|
base.Init();
|
||||||
|
|
||||||
SpawnMonsters(Rand.Range(minAmount, maxAmount, Rand.RandSync.Server));
|
monsters = SpawnMonsters(Rand.Range(minAmount, maxAmount, Rand.RandSync.Server));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Character[] SpawnMonsters(int amount)
|
private Character[] SpawnMonsters(int amount)
|
||||||
@@ -90,7 +90,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
spawnPos.X += Rand.Range(-0.5f, 0.5f, Rand.RandSync.Server);
|
spawnPos.X += Rand.Range(-0.5f, 0.5f, Rand.RandSync.Server);
|
||||||
spawnPos.Y += Rand.Range(-0.5f, 0.5f, Rand.RandSync.Server);
|
spawnPos.Y += Rand.Range(-0.5f, 0.5f, Rand.RandSync.Server);
|
||||||
monsters[i] = Character.Create(characterFile, spawnPos, null, GameMain.Client != null);
|
monsters[i] = Character.Create(characterFile, spawnPos, null, GameMain.Client != null, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return monsters;
|
return monsters;
|
||||||
@@ -104,12 +104,6 @@ namespace Barotrauma
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monsters == null)
|
|
||||||
{
|
|
||||||
monsters = SpawnMonsters(Rand.Range(minAmount, maxAmount, Rand.RandSync.Server));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
//clients aren't allowed to spawn more monsters mid-round
|
//clients aren't allowed to spawn more monsters mid-round
|
||||||
|
|||||||
Reference in New Issue
Block a user