Refactored event/task logic:
- Instead of configuring a commonness value and difficulty for an event and creating new random events until the maximum difficulty of the selected level is reached, the number of events per level can be configured directly (and overridden for specific level types). - Removed task logic. The initial idea was to display the unfinished tasks to the player somehow and to use them as objectives for the AI crew, but those were scrapped and the tasks only ended up controlling which type of music to play. TODO: implement some kind of logic to determine when to play repair/monster music clips.
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Barotrauma.Tutorials
|
||||
|
||||
GameMain.GameSession.StartShift("tuto");
|
||||
|
||||
GameMain.GameSession.TaskManager.Tasks.Clear();
|
||||
GameMain.GameSession.TaskManager.Events.Clear();
|
||||
|
||||
GameMain.GameScreen.Select();
|
||||
}
|
||||
|
||||
@@ -344,6 +344,13 @@ namespace Barotrauma
|
||||
|
||||
private static List<BackgroundMusic> GetSuitableMusicClips()
|
||||
{
|
||||
|
||||
Submarine targetSubmarine = null;
|
||||
if (Character.Controlled != null)
|
||||
{
|
||||
targetSubmarine = Character.Controlled.Submarine;
|
||||
}
|
||||
|
||||
string musicType = "default";
|
||||
if (OverrideMusicType != null)
|
||||
{
|
||||
@@ -355,37 +362,14 @@ namespace Barotrauma
|
||||
{
|
||||
musicType = "ruins";
|
||||
}
|
||||
else if ((Character.Controlled != null && Character.Controlled.Submarine != null && Character.Controlled.Submarine.AtDamageDepth) ||
|
||||
else if ((targetSubmarine != null && targetSubmarine.AtDamageDepth) ||
|
||||
(Screen.Selected == GameMain.GameScreen && GameMain.GameScreen.Cam.Position.Y < SubmarineBody.DamageDepth))
|
||||
{
|
||||
musicType = "deep";
|
||||
}
|
||||
else
|
||||
else if (targetSubmarine != null)
|
||||
{
|
||||
Task criticalTask = null;
|
||||
if (GameMain.GameSession != null && GameMain.GameSession.TaskManager != null)
|
||||
{
|
||||
foreach (Task task in GameMain.GameSession.TaskManager.Tasks)
|
||||
{
|
||||
if (!task.IsStarted) continue;
|
||||
if (criticalTask == null || task.Priority > criticalTask.Priority)
|
||||
{
|
||||
criticalTask = task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (criticalTask != null)
|
||||
{
|
||||
var suitableClips =
|
||||
musicClips.Where(music =>
|
||||
music != null &&
|
||||
music.type == criticalTask.MusicType &&
|
||||
music.priorityRange.X < criticalTask.Priority &&
|
||||
music.priorityRange.Y > criticalTask.Priority).ToList();
|
||||
|
||||
if (suitableClips.Count > 0) return suitableClips;
|
||||
}
|
||||
//TODO: determine whether to switch to monster or repair musictype
|
||||
}
|
||||
|
||||
return musicClips.Where(music => music != null && music.type == musicType).ToList();
|
||||
|
||||
@@ -1350,18 +1350,14 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\CoroutineManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\DebugConsole.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\ArtifactEvent.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\EventManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\CargoMission.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\CombatMission.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\Mission.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\MonsterMission.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\SalvageMission.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\MonsterEvent.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\PropertyTask.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\RepairTask.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\ScriptedEvent.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\ScriptedTask.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Task.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\TaskManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\FrameCounter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\CargoManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameModes\GameMode.cs" />
|
||||
|
||||
@@ -1,110 +1,142 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Randomevents>
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Crawler/crawler.xml"
|
||||
commonness="15"
|
||||
difficulty="10"
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Crawler/crawler.xml"
|
||||
mineventcount="1" maxeventcount="3"
|
||||
minamount="2" maxamount="3"
|
||||
repeat="true"
|
||||
spawntype="mainpath,cave,ruin"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
<OverrideEventCount leveltype="Ridge" min="5" max="6"/>
|
||||
<OverrideEventCount leveltype="Wastes" min="5" max="6"/>
|
||||
<OverrideEventCount leveltype="Open" min="-5" max="1"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Tigerthresher/tigerthresher.xml"
|
||||
commonness="10"
|
||||
difficulty="20"
|
||||
minamount="1" maxamount="3"
|
||||
mineventcount="0" maxeventcount="2"
|
||||
spawntype="mainpath"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
<OverrideEventCount leveltype="Open" min="-5" max="1"/>
|
||||
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Moloch/moloch.xml"
|
||||
commonness="10"
|
||||
difficulty="30"
|
||||
mineventcount="-1" maxeventcount="2"
|
||||
spawntype="mainpath"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
<OverrideEventCount leveltype="Ridge" min="-5" max="1"/>
|
||||
<OverrideEventCount leveltype="Open" min="1" max="6"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Mantis/mantis.xml"
|
||||
commonness="10"
|
||||
difficulty="15"
|
||||
mineventcount="0" maxeventcount="2"
|
||||
minamount="0" maxamount="2"
|
||||
repeat="true"
|
||||
minamount="1" maxamount="2"
|
||||
spawntype="mainpath,cave,ruin"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
<OverrideEventCount leveltype="Ridge" min="5" max="6"/>
|
||||
<OverrideEventCount leveltype="Wastes" min="5" max="6"/>
|
||||
<OverrideEventCount leveltype="Open" min="-5" max="1"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Coelanth/coelanth.xml"
|
||||
spawndeep="true"
|
||||
commonness="10"
|
||||
difficulty="5"
|
||||
mineventcount="0" maxeventcount="3"
|
||||
minamount="1" maxamount="1"
|
||||
spawndeep="true"
|
||||
spawntype="mainpath"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Charybdis/charybdis.xml"
|
||||
spawndeep="true"
|
||||
commonness="3"
|
||||
difficulty="5"
|
||||
mineventcount="-5" maxeventcount="2"
|
||||
minamount="1" maxamount="1"
|
||||
spawndeep="true"
|
||||
spawntype="deep"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
<OverrideEventCount leveltype="Ridge" max="0"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Charybdis/charybdis.xml"
|
||||
maxamount="0"
|
||||
spawntype="deep"
|
||||
musictype="monster">
|
||||
<OverrideEventCount leveltype="Open" min="0" max="3"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Endworm/endworm.xml"
|
||||
mineventcount="-5" maxeventcount="1"
|
||||
spawndeep="true"
|
||||
commonness="1"
|
||||
difficulty="20"
|
||||
minamount="1" maxamount="1"
|
||||
spawntype="mainpath"
|
||||
musictype="deep"/>
|
||||
musictype="deep">
|
||||
<OverrideEventCount leveltype="Ridge" max="0"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Endworm/endworm.xml"
|
||||
maxeventcount="0"
|
||||
minamount="1" maxamount="1"
|
||||
spawntype="mainpath"
|
||||
musictype="deep">
|
||||
<OverrideEventCount leveltype="Open" min="-1" max="2"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Watcher/watcher.xml"
|
||||
commonness="3"
|
||||
difficulty="5"
|
||||
mineventcount="-3" maxeventcount="1"
|
||||
spawntype="mainpath,cave"
|
||||
minamount="1" maxamount="1"/>
|
||||
minamount="1" maxamount="3">
|
||||
<OverrideEventCount leveltype="Ridge" max="0"/>
|
||||
<OverrideEventCount leveltype="Wastes" max="0"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Husk/husk.xml"
|
||||
commonness="5"
|
||||
difficulty="10"
|
||||
mineventcount="-2" maxeventcount="3"
|
||||
minamount="2" maxamount="3"
|
||||
repeat="true"
|
||||
spawntype="mainpath,cave,ruin"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
<OverrideEventCount leveltype="Wastes" min="1" max="3"/>
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Fractalguardian/fractalguardian.xml"
|
||||
commonness="3"
|
||||
difficulty="1"
|
||||
mineventcount="1" maxeventcount="2"
|
||||
minamount="1" maxamount="1"
|
||||
spawntype="ruin"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
</MonsterEvent>
|
||||
|
||||
<MonsterEvent name="Under attack" description=""
|
||||
characterfile="Content/Characters/Fractalguardian2/fractalguardian2.xml"
|
||||
commonness="3"
|
||||
difficulty="1"
|
||||
mineventcount="1" maxeventcount="2"
|
||||
minamount="1" maxamount="1"
|
||||
spawntype="ruin"
|
||||
musictype="monster"/>
|
||||
musictype="monster">
|
||||
</MonsterEvent>
|
||||
|
||||
<ArtifactEvent name="Artifact" description=""
|
||||
itemname="Skyholder Artifact"
|
||||
commonness="5"
|
||||
difficulty="0"/>
|
||||
mineventcount="0" maxeventcount="5"
|
||||
itemname="Skyholder Artifact"/>
|
||||
|
||||
<ArtifactEvent name="Artifact" description=""
|
||||
itemname="Thermal Artifact"
|
||||
commonness="5"
|
||||
difficulty="0"/>
|
||||
mineventcount="0" maxeventcount="5"
|
||||
itemname="Thermal Artifact"/>
|
||||
|
||||
<ArtifactEvent name="Artifact" description=""
|
||||
itemname="Faraday Artifact"
|
||||
commonness="5"
|
||||
difficulty="0"/>
|
||||
mineventcount="0" maxeventcount="8"
|
||||
itemname="Faraday Artifact"/>
|
||||
|
||||
<ArtifactEvent name="Artifact" description=""
|
||||
mineventcount="0" maxeventcount="2"
|
||||
itemname="Nasonov Artifact"/>
|
||||
|
||||
</Randomevents>
|
||||
54
Barotrauma/BarotraumaShared/Source/Events/EventManager.cs
Normal file
54
Barotrauma/BarotraumaShared/Source/Events/EventManager.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class EventManager
|
||||
{
|
||||
const float CriticalPriority = 50.0f;
|
||||
|
||||
private List<ScriptedEvent> events;
|
||||
|
||||
public List<ScriptedEvent> Events
|
||||
{
|
||||
get { return events; }
|
||||
}
|
||||
|
||||
public EventManager(GameSession session)
|
||||
{
|
||||
events = new List<ScriptedEvent>();
|
||||
}
|
||||
|
||||
public void StartShift(Level level)
|
||||
{
|
||||
CreateScriptedEvents(level);
|
||||
foreach (ScriptedEvent ev in events)
|
||||
{
|
||||
ev.Init();
|
||||
}
|
||||
}
|
||||
|
||||
public void EndShift()
|
||||
{
|
||||
events.Clear();
|
||||
}
|
||||
|
||||
private void CreateScriptedEvents(Level level)
|
||||
{
|
||||
MTRandom rand = new MTRandom(ToolBox.StringToInt(level.Seed));
|
||||
events.AddRange(ScriptedEvent.GenerateLevelEvents(rand, level));
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
events.RemoveAll(t => t.IsFinished);
|
||||
foreach (ScriptedEvent ev in events)
|
||||
{
|
||||
if (!ev.IsFinished)
|
||||
{
|
||||
ev.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
namespace Barotrauma
|
||||
{
|
||||
class PropertyTask : Task
|
||||
{
|
||||
Item item;
|
||||
|
||||
|
||||
public delegate bool IsFinishedHandler();
|
||||
private IsFinishedHandler IsFinishedChecker;
|
||||
|
||||
public PropertyTask(Item item, IsFinishedHandler isFinished, float priority, string name)
|
||||
: base(priority, name)
|
||||
{
|
||||
if (taskManager == null) return;
|
||||
|
||||
this.item = item;
|
||||
IsFinishedChecker = isFinished;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (IsFinishedChecker())
|
||||
{
|
||||
Finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace Barotrauma
|
||||
{
|
||||
class RepairTask : Task
|
||||
{
|
||||
Item item;
|
||||
|
||||
public RepairTask(Item item, float priority, string name)
|
||||
: base(priority, name)
|
||||
{
|
||||
if (taskManager == null) return;
|
||||
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (item.Condition > item.Prefab.Health * 0.5f) Finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -8,15 +7,19 @@ namespace Barotrauma
|
||||
{
|
||||
class ScriptedEvent
|
||||
{
|
||||
protected string name;
|
||||
protected string description;
|
||||
private static List<ScriptedEvent> prefabs;
|
||||
|
||||
protected int commonness;
|
||||
protected int difficulty;
|
||||
protected readonly string name;
|
||||
protected readonly string description;
|
||||
|
||||
private readonly int minEventCount, maxEventCount;
|
||||
|
||||
protected bool isFinished;
|
||||
|
||||
public Dictionary<string, int> OverrideCommonness;
|
||||
private readonly XElement configElement;
|
||||
|
||||
private readonly Dictionary<string, int> overrideMinEventCount;
|
||||
private readonly Dictionary<string, int> overrideMaxEventCount;
|
||||
|
||||
public string Name
|
||||
{
|
||||
@@ -27,12 +30,7 @@ namespace Barotrauma
|
||||
{
|
||||
get { return description; }
|
||||
}
|
||||
|
||||
public int Commonness
|
||||
{
|
||||
get { return commonness; }
|
||||
}
|
||||
|
||||
|
||||
public string MusicType
|
||||
{
|
||||
get;
|
||||
@@ -48,136 +46,43 @@ namespace Barotrauma
|
||||
{
|
||||
get { return isFinished; }
|
||||
}
|
||||
|
||||
public int Difficulty
|
||||
{
|
||||
get { return difficulty; }
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ScriptedEvent ("+name+")";
|
||||
return "ScriptedEvent (" + name + ")";
|
||||
}
|
||||
|
||||
public ScriptedEvent(XElement element)
|
||||
protected ScriptedEvent(XElement element)
|
||||
{
|
||||
configElement = element;
|
||||
|
||||
name = ToolBox.GetAttributeString(element, "name", "");
|
||||
description = ToolBox.GetAttributeString(element, "description", "");
|
||||
|
||||
difficulty = ToolBox.GetAttributeInt(element, "difficulty", 1);
|
||||
commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
|
||||
|
||||
minEventCount = ToolBox.GetAttributeInt(element, "mineventcount", 0);
|
||||
maxEventCount = ToolBox.GetAttributeInt(element, "maxeventcount", 0);
|
||||
|
||||
MusicType = ToolBox.GetAttributeString(element, "musictype", "default");
|
||||
|
||||
OverrideCommonness = new Dictionary<string, int>();
|
||||
overrideMinEventCount = new Dictionary<string, int>();
|
||||
overrideMaxEventCount = new Dictionary<string, int>();
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "overridecommonness":
|
||||
case "overrideeventcount":
|
||||
string levelType = ToolBox.GetAttributeString(subElement, "leveltype", "");
|
||||
if (!OverrideCommonness.ContainsKey(levelType))
|
||||
if (!overrideMinEventCount.ContainsKey(levelType))
|
||||
{
|
||||
OverrideCommonness.Add(levelType, ToolBox.GetAttributeInt(subElement, "commonness", 1));
|
||||
overrideMinEventCount.Add(levelType, ToolBox.GetAttributeInt(subElement, "min", 0));
|
||||
overrideMaxEventCount.Add(levelType, ToolBox.GetAttributeInt(subElement, "max", 0));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static ScriptedEvent LoadRandom(Random rand)
|
||||
{
|
||||
var configFiles = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.RandomEvents);
|
||||
|
||||
if (!configFiles.Any())
|
||||
{
|
||||
DebugConsole.ThrowError("No config files for random events found in the selected content package");
|
||||
return null;
|
||||
}
|
||||
|
||||
string configFile = configFiles[0];
|
||||
|
||||
XDocument doc = ToolBox.TryLoadXml(configFile);
|
||||
if (doc == null) return null;
|
||||
|
||||
int eventCount = doc.Root.Elements().Count();
|
||||
//int[] commonness = new int[eventCount];
|
||||
float[] eventProbability = new float[eventCount];
|
||||
|
||||
float probabilitySum = 0.0f;
|
||||
|
||||
int i = 0;
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
eventProbability[i] = ToolBox.GetAttributeInt(element, "commonness", 1);
|
||||
|
||||
//if the event has been previously selected, it's less likely to be selected now
|
||||
//int previousEventIndex = previousEvents.FindIndex(x => x == i);
|
||||
//if (previousEventIndex >= 0)
|
||||
//{
|
||||
// //how many shifts ago was the event last selected
|
||||
// int eventDist = eventCount - previousEventIndex;
|
||||
|
||||
// float weighting = (1.0f / eventDist) * PreviouslyUsedWeight;
|
||||
|
||||
// eventProbability[i] *= weighting;
|
||||
//}
|
||||
|
||||
probabilitySum += eventProbability[i];
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
float randomNumber = (float)rand.NextDouble() * probabilitySum;
|
||||
|
||||
i = 0;
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
if (randomNumber <= eventProbability[i])
|
||||
{
|
||||
Type t;
|
||||
string type = element.Name.ToString();
|
||||
|
||||
try
|
||||
{
|
||||
t = Type.GetType("Barotrauma." + type, true, true);
|
||||
if (t == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type \"" + type + "\".");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type \"" + type + "\".");
|
||||
continue;
|
||||
}
|
||||
|
||||
ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) });
|
||||
object instance = null;
|
||||
try
|
||||
{
|
||||
instance = constructor.Invoke(new object[] { element });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DebugConsole.ThrowError(ex.InnerException!=null ? ex.InnerException.ToString() : ex.ToString());
|
||||
}
|
||||
|
||||
//previousEvents.Add(i);
|
||||
|
||||
return (ScriptedEvent)instance;
|
||||
}
|
||||
|
||||
randomNumber -= eventProbability[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void Init()
|
||||
{
|
||||
isFinished = false;
|
||||
@@ -191,5 +96,156 @@ namespace Barotrauma
|
||||
{
|
||||
isFinished = true;
|
||||
}
|
||||
|
||||
|
||||
private static void LoadPrefabs()
|
||||
{
|
||||
prefabs = new List<ScriptedEvent>();
|
||||
var configFiles = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.RandomEvents);
|
||||
|
||||
if (configFiles.Count == 0)
|
||||
{
|
||||
DebugConsole.ThrowError("No config files for random events found in the selected content package");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string configFile in configFiles)
|
||||
{
|
||||
XDocument doc = ToolBox.TryLoadXml(configFile);
|
||||
if (doc == null) continue;
|
||||
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
prefabs.Add(new ScriptedEvent(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ScriptedEvent> GenerateLevelEvents(Random random, Level level)
|
||||
{
|
||||
if (prefabs == null)
|
||||
{
|
||||
LoadPrefabs();
|
||||
}
|
||||
|
||||
List<ScriptedEvent> events = new List<ScriptedEvent>();
|
||||
foreach (ScriptedEvent scriptedEvent in prefabs)
|
||||
{
|
||||
int minCount = scriptedEvent.overrideMinEventCount.ContainsKey(level.GenerationParams.Name) ?
|
||||
scriptedEvent.overrideMinEventCount[level.GenerationParams.Name] : scriptedEvent.minEventCount;
|
||||
int maxCount = scriptedEvent.overrideMaxEventCount.ContainsKey(level.GenerationParams.Name) ?
|
||||
scriptedEvent.overrideMaxEventCount[level.GenerationParams.Name] : scriptedEvent.maxEventCount;
|
||||
|
||||
minCount = Math.Min(minCount, maxCount);
|
||||
|
||||
int count = random.Next(maxCount - minCount) + minCount;
|
||||
|
||||
for (int i = 0; i<count; i++)
|
||||
{
|
||||
Type t;
|
||||
|
||||
try
|
||||
{
|
||||
t = Type.GetType("Barotrauma." + scriptedEvent.configElement.Name, true, true);
|
||||
if (t == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Could not find an event class of the type \"" + scriptedEvent.configElement.Name + "\".");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Could not find an event class of the type \"" + scriptedEvent.configElement.Name + "\".");
|
||||
continue;
|
||||
}
|
||||
|
||||
ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) });
|
||||
object instance = null;
|
||||
try
|
||||
{
|
||||
instance = constructor.Invoke(new object[] { scriptedEvent.configElement });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DebugConsole.ThrowError(ex.InnerException != null ? ex.InnerException.ToString() : ex.ToString());
|
||||
}
|
||||
|
||||
events.Add((ScriptedEvent)instance);
|
||||
}
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
|
||||
/*public static ScriptedEvent Load(ScriptedEvent scriptedEvent)
|
||||
{
|
||||
if (prefabs == null)
|
||||
{
|
||||
LoadPrefabs();
|
||||
}
|
||||
|
||||
if (prefabs.Count == 0) return null;
|
||||
|
||||
int eventCount = prefabs.Count;
|
||||
float[] eventProbability = new float[eventCount];
|
||||
float probabilitySum = 0.0f;
|
||||
|
||||
int i = 0;
|
||||
foreach (ScriptedEvent scriptedEvent in prefabs)
|
||||
{
|
||||
eventProbability[i] = scriptedEvent.commonness;
|
||||
if (level != null)
|
||||
{
|
||||
scriptedEvent.OverrideCommonness.TryGetValue(level.GenerationParams.Name, out eventProbability[i]);
|
||||
}
|
||||
probabilitySum += eventProbability[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
float randomNumber = (float)rand.NextDouble() * probabilitySum;
|
||||
|
||||
i = 0;
|
||||
foreach (ScriptedEvent scriptedEvent in prefabs)
|
||||
{
|
||||
if (randomNumber <= eventProbability[i])
|
||||
{
|
||||
Type t;
|
||||
|
||||
try
|
||||
{
|
||||
t = Type.GetType("Barotrauma." + scriptedEvent.configElement.Name, true, true);
|
||||
if (t == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Could not find an event class of the type \"" + scriptedEvent.configElement.Name + "\".");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
DebugConsole.ThrowError("Could not find an event class of the type \"" + scriptedEvent.configElement.Name + "\".");
|
||||
continue;
|
||||
}
|
||||
|
||||
ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) });
|
||||
object instance = null;
|
||||
try
|
||||
{
|
||||
instance = constructor.Invoke(new object[] { scriptedEvent.configElement });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DebugConsole.ThrowError(ex.InnerException != null ? ex.InnerException.ToString() : ex.ToString());
|
||||
}
|
||||
|
||||
return (ScriptedEvent)instance;
|
||||
}
|
||||
|
||||
randomNumber -= eventProbability[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
namespace Barotrauma
|
||||
{
|
||||
class ScriptedTask : Task
|
||||
{
|
||||
private ScriptedEvent scriptedEvent;
|
||||
|
||||
public override bool IsStarted
|
||||
{
|
||||
get
|
||||
{
|
||||
return scriptedEvent.IsActive;
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptedTask(ScriptedEvent scriptedEvent)
|
||||
: base(scriptedEvent.Difficulty, scriptedEvent.Name)
|
||||
{
|
||||
if (taskManager == null) return;
|
||||
|
||||
this.musicType = scriptedEvent.MusicType;
|
||||
|
||||
this.scriptedEvent = scriptedEvent;
|
||||
scriptedEvent.Init();
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
scriptedEvent.Update(deltaTime);
|
||||
if (scriptedEvent.IsFinished) Finished();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class Task
|
||||
{
|
||||
|
||||
protected string name;
|
||||
|
||||
private float priority;
|
||||
|
||||
protected string musicType;
|
||||
|
||||
protected TaskManager taskManager;
|
||||
|
||||
protected bool isFinished;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public float Priority
|
||||
{
|
||||
get { return priority; }
|
||||
}
|
||||
|
||||
public string MusicType
|
||||
{
|
||||
get { return musicType; }
|
||||
}
|
||||
|
||||
public bool IsFinished
|
||||
{
|
||||
get { return isFinished; }
|
||||
}
|
||||
|
||||
public virtual bool IsStarted
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public Task(float priority, string name)
|
||||
{
|
||||
if (GameMain.GameSession==null || GameMain.GameSession.TaskManager == null) return;
|
||||
|
||||
taskManager = GameMain.GameSession.TaskManager;
|
||||
musicType = "repair";
|
||||
this.priority = priority;
|
||||
this.name = name;
|
||||
|
||||
taskManager.AddTask(this);
|
||||
}
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual void Finished()
|
||||
{
|
||||
isFinished = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class TaskManager
|
||||
{
|
||||
const float CriticalPriority = 50.0f;
|
||||
|
||||
private List<Task> tasks;
|
||||
|
||||
public List<Task> Tasks
|
||||
{
|
||||
get { return tasks; }
|
||||
}
|
||||
|
||||
public bool CriticalTasks
|
||||
{
|
||||
get
|
||||
{
|
||||
return tasks.Any(task => task.Priority >= CriticalPriority);
|
||||
}
|
||||
}
|
||||
|
||||
public TaskManager(GameSession session)
|
||||
{
|
||||
tasks = new List<Task>();
|
||||
}
|
||||
|
||||
public void AddTask(Task newTask)
|
||||
{
|
||||
if (tasks.Contains(newTask)) return;
|
||||
|
||||
tasks.Add(newTask);
|
||||
}
|
||||
|
||||
public void StartShift(Level level)
|
||||
{
|
||||
CreateScriptedEvents(level);
|
||||
}
|
||||
|
||||
|
||||
public void EndShift()
|
||||
{
|
||||
tasks.Clear();
|
||||
}
|
||||
|
||||
private void CreateScriptedEvents(Level level)
|
||||
{
|
||||
MTRandom rand = new MTRandom(ToolBox.StringToInt(level.Seed));
|
||||
|
||||
float totalDifficulty = level.Difficulty;
|
||||
|
||||
int tries = 0;
|
||||
while (tries < 5)
|
||||
{
|
||||
ScriptedEvent scriptedEvent = ScriptedEvent.LoadRandom(rand);
|
||||
if (scriptedEvent==null || scriptedEvent.Difficulty > totalDifficulty)
|
||||
{
|
||||
tries++;
|
||||
continue;
|
||||
}
|
||||
DebugConsole.Log("Created scripted event " + scriptedEvent.ToString());
|
||||
|
||||
AddTask(new ScriptedTask(scriptedEvent));
|
||||
totalDifficulty -= scriptedEvent.Difficulty;
|
||||
tries = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
foreach (Task task in tasks)
|
||||
{
|
||||
if (!task.IsFinished)
|
||||
{
|
||||
task.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
tasks.RemoveAll(t => t.IsFinished);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Barotrauma
|
||||
{
|
||||
public enum InfoFrameTab { Crew, Mission, ManagePlayers };
|
||||
|
||||
public readonly TaskManager TaskManager;
|
||||
public readonly EventManager TaskManager;
|
||||
|
||||
public readonly GameMode gameMode;
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Barotrauma
|
||||
|
||||
GameMain.GameSession = this;
|
||||
|
||||
TaskManager = new TaskManager(this);
|
||||
TaskManager = new EventManager(this);
|
||||
|
||||
this.saveFile = saveFile;
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
class OxygenGenerator : Powered
|
||||
{
|
||||
PropertyTask powerUpTask;
|
||||
|
||||
float powerDownTimer;
|
||||
|
||||
bool running;
|
||||
@@ -59,11 +57,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
powerDownTimer += deltaTime;
|
||||
running = false;
|
||||
if ((powerUpTask==null || powerUpTask.IsFinished) && powerDownTimer>5.0f)
|
||||
{
|
||||
powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Turn on the oxygen generator");
|
||||
}
|
||||
return;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -47,8 +47,6 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float load;
|
||||
|
||||
private PropertyTask powerUpTask;
|
||||
|
||||
private bool unsentChanges;
|
||||
private float sendUpdateTimer;
|
||||
|
||||
@@ -218,13 +216,6 @@ namespace Barotrauma.Items.Components
|
||||
MeltDown();
|
||||
return;
|
||||
}
|
||||
else if (temperature == 0.0f)
|
||||
{
|
||||
if (powerUpTask == null || powerUpTask.IsFinished)
|
||||
{
|
||||
powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Power up the reactor");
|
||||
}
|
||||
}
|
||||
|
||||
load = 0.0f;
|
||||
|
||||
@@ -325,7 +316,6 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
GameServer.Log("Reactor meltdown!", ServerLog.MessageType.ItemInteraction);
|
||||
|
||||
new RepairTask(item, 60.0f, "Reactor meltdown!");
|
||||
item.Condition = 0.0f;
|
||||
|
||||
var containedItems = item.ContainedItems;
|
||||
|
||||
Reference in New Issue
Block a user