MonsterEvents and ArtifactEvents spawn the monsters/items during initialization instead of waiting for the round to start (prevents entity ID mismatches if a client starts the event before receiving a message about something the server has spawned)

This commit is contained in:
Regalis
2017-01-01 23:14:24 +02:00
parent 1bba276949
commit e358ea9917
7 changed files with 10 additions and 105 deletions

View File

@@ -29,9 +29,11 @@ namespace Barotrauma
DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name "+itemName);
}
}
protected override void Start()
public override void Init()
{
base.Init();
Vector2 position = Level.Loaded.GetRandomItemPos(
Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 30.0f);
@@ -60,7 +62,6 @@ namespace Barotrauma
switch (state)
{
case 0:
Start();
state = 1;
break;
case 1:

View File

@@ -54,8 +54,10 @@ namespace Barotrauma
}
}
protected override void Start()
public override void Init()
{
base.Init();
SpawnMonsters();
}
@@ -88,10 +90,6 @@ namespace Barotrauma
}
if (monsters == null) SpawnMonsters();
//base.Update(deltaTime);
//if (!isStarted) return;
if (isFinished) return;
bool monstersDead = true;
@@ -99,8 +97,6 @@ namespace Barotrauma
{
if (monster.IsDead) continue;
if (!isStarted && Vector2.Distance(monster.WorldPosition, Submarine.MainSub.WorldPosition) < 5000.0f) isStarted = true;
monstersDead = false;
break;
}

View File

@@ -15,8 +15,6 @@
this.item = item;
IsFinishedChecker = isFinished;
taskManager.TaskStarted(this);
}
public override void Update(float deltaTime)

View File

@@ -10,8 +10,6 @@
if (taskManager == null) return;
this.item = item;
taskManager.TaskStarted(this);
}
public override void Update(float deltaTime)

View File

@@ -7,25 +7,12 @@ namespace Barotrauma
{
class ScriptedEvent
{
//const int MaxPreviousEvents = 6;
//const float PreviouslyUsedWeight = 10.0f;
//static List<int> previousEvents = new List<int>();
protected string name;
protected string description;
protected int commonness;
protected int difficulty;
//the time after starting a shift after which the event is started
//the time is set to a random value between startTimeMin and startTimeMax at the start of the shift
private int startTimeMin;
private int startTimeMax;
private double startTimer;
protected bool isStarted;
protected bool isFinished;
public string Name
@@ -48,12 +35,7 @@ namespace Barotrauma
get;
set;
}
public bool IsStarted
{
get { return isStarted; }
}
public bool IsFinished
{
get { return isFinished; }
@@ -77,20 +59,7 @@ namespace Barotrauma
difficulty = ToolBox.GetAttributeInt(element, "difficulty", 1);
commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
MusicType = ToolBox.GetAttributeString(element, "musictype", "default");
if (element.Attribute("starttime") != null)
{
startTimeMax = ToolBox.GetAttributeInt(element, "starttime", 1);
startTimeMin = startTimeMax;
}
else
{
startTimeMax = ToolBox.GetAttributeInt(element, "starttimemax", 1);
startTimeMin = ToolBox.GetAttributeInt(element, "starttimemin", 1);
}
}
@@ -179,28 +148,12 @@ namespace Barotrauma
public virtual void Init()
{
isStarted = false;
isFinished = false;
startTimer = Rand.Range(startTimeMin, startTimeMax, false);
}
protected virtual void Start()
{
}
public virtual void Update(float deltaTime)
{
if (isStarted) return;
if (startTimer>0)
{
startTimer -= deltaTime;
}
else
{
Start();
isStarted = true;
}
}
public virtual void Finished()

View File

@@ -3,14 +3,7 @@
class ScriptedTask : Task
{
private ScriptedEvent scriptedEvent;
private bool prevStarted;
public override bool IsStarted
{
get { return scriptedEvent.IsStarted; }
}
public ScriptedTask(ScriptedEvent scriptedEvent)
: base(scriptedEvent.Difficulty, scriptedEvent.Name)
{
@@ -24,12 +17,6 @@
public override void Update(float deltaTime)
{
if (prevStarted == false && scriptedEvent.IsStarted)
{
taskManager.TaskStarted(this);
prevStarted = true;
}
scriptedEvent.Update(deltaTime);
if (scriptedEvent.IsFinished) Finished();
}

View File

@@ -78,35 +78,7 @@ namespace Barotrauma
}
}
public void TaskStarted(Task task)
{
//Color color = Color.Red;
//int width = 250;
//if (task.Priority < 30.0f)
//{
// width = 200;
// color = Color.Yellow;
//}
//else if (task.Priority < 60)
//{
// width = 220;
// color = Color.Orange;
//}
//GUIFrame frame = new GUIFrame(new Rectangle(0,0,width,40), Color.Transparent, Alignment.Right, null, taskListBox);
//frame.UserData = task;
//frame.Padding = new Vector4(0.0f, 5.0f, 5.0f, 5.0f);
//GUIFrame colorFrame = new GUIFrame(new Rectangle(0, 0, 0, 0), color * 0.5f, Alignment.Right, null, frame);
//GUITextBlock textBlock = new GUITextBlock(new Rectangle(5, 5, 0, 20), task.Name, Color.Transparent, Color.Black, Alignment.Right, null, colorFrame);
//textBlock.Padding = new Vector4(10.0f, 10.0f, 0.0f, 0.0f);
//colorFrame.AddChild(textBlock);
//taskListBox.children.Sort((x, y) => ((Task)y.UserData).Priority.CompareTo(((Task)x.UserData).Priority));
}
public void TaskFinished(Task task)
{