From e358ea9917006f81c3c8dcdd26afdc814595dab2 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 1 Jan 2017 23:14:24 +0200 Subject: [PATCH] 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) --- Subsurface/Source/Events/ArtifactEvent.cs | 7 ++-- Subsurface/Source/Events/MonsterEvent.cs | 10 ++--- Subsurface/Source/Events/PropertyTask.cs | 2 - Subsurface/Source/Events/RepairTask.cs | 2 - Subsurface/Source/Events/ScriptedEvent.cs | 49 +---------------------- Subsurface/Source/Events/ScriptedTask.cs | 15 +------ Subsurface/Source/Events/TaskManager.cs | 30 +------------- 7 files changed, 10 insertions(+), 105 deletions(-) diff --git a/Subsurface/Source/Events/ArtifactEvent.cs b/Subsurface/Source/Events/ArtifactEvent.cs index 3cbc2b822..5beb42a4c 100644 --- a/Subsurface/Source/Events/ArtifactEvent.cs +++ b/Subsurface/Source/Events/ArtifactEvent.cs @@ -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: diff --git a/Subsurface/Source/Events/MonsterEvent.cs b/Subsurface/Source/Events/MonsterEvent.cs index 3ea17299f..e65e78d93 100644 --- a/Subsurface/Source/Events/MonsterEvent.cs +++ b/Subsurface/Source/Events/MonsterEvent.cs @@ -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; } diff --git a/Subsurface/Source/Events/PropertyTask.cs b/Subsurface/Source/Events/PropertyTask.cs index 0f30ced22..acb9e7591 100644 --- a/Subsurface/Source/Events/PropertyTask.cs +++ b/Subsurface/Source/Events/PropertyTask.cs @@ -15,8 +15,6 @@ this.item = item; IsFinishedChecker = isFinished; - - taskManager.TaskStarted(this); } public override void Update(float deltaTime) diff --git a/Subsurface/Source/Events/RepairTask.cs b/Subsurface/Source/Events/RepairTask.cs index ef8472de6..e18dbdaaa 100644 --- a/Subsurface/Source/Events/RepairTask.cs +++ b/Subsurface/Source/Events/RepairTask.cs @@ -10,8 +10,6 @@ if (taskManager == null) return; this.item = item; - - taskManager.TaskStarted(this); } public override void Update(float deltaTime) diff --git a/Subsurface/Source/Events/ScriptedEvent.cs b/Subsurface/Source/Events/ScriptedEvent.cs index 8fb0ba70c..06d18c902 100644 --- a/Subsurface/Source/Events/ScriptedEvent.cs +++ b/Subsurface/Source/Events/ScriptedEvent.cs @@ -7,25 +7,12 @@ namespace Barotrauma { class ScriptedEvent { - //const int MaxPreviousEvents = 6; - //const float PreviouslyUsedWeight = 10.0f; - - //static List previousEvents = new List(); - 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() diff --git a/Subsurface/Source/Events/ScriptedTask.cs b/Subsurface/Source/Events/ScriptedTask.cs index 1f98d53c5..bace81513 100644 --- a/Subsurface/Source/Events/ScriptedTask.cs +++ b/Subsurface/Source/Events/ScriptedTask.cs @@ -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(); } diff --git a/Subsurface/Source/Events/TaskManager.cs b/Subsurface/Source/Events/TaskManager.cs index 06022dc2c..52b27a96d 100644 --- a/Subsurface/Source/Events/TaskManager.cs +++ b/Subsurface/Source/Events/TaskManager.cs @@ -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) {