38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -1,47 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class ScriptedEvent
|
||||
{
|
||||
private static List<ScriptedEvent> prefabs;
|
||||
|
||||
protected readonly string name;
|
||||
protected readonly string description;
|
||||
|
||||
private readonly int minEventCount, maxEventCount;
|
||||
|
||||
{
|
||||
protected bool isFinished;
|
||||
|
||||
private readonly XElement configElement;
|
||||
|
||||
private readonly Dictionary<string, int> overrideMinEventCount;
|
||||
private readonly Dictionary<string, int> overrideMaxEventCount;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return description; }
|
||||
}
|
||||
|
||||
public string MusicType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public virtual bool IsActive
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
private readonly ScriptedEventPrefab prefab;
|
||||
|
||||
public bool IsFinished
|
||||
{
|
||||
get { return isFinished; }
|
||||
@@ -49,43 +15,24 @@ namespace Barotrauma
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ScriptedEvent (" + name + ")";
|
||||
return "ScriptedEvent (" + prefab.EventType.ToString() +")";
|
||||
}
|
||||
|
||||
protected ScriptedEvent(XElement element)
|
||||
public virtual Vector2 DebugDrawPos
|
||||
{
|
||||
configElement = element;
|
||||
|
||||
name = element.GetAttributeString("name", "");
|
||||
description = element.GetAttributeString("description", "");
|
||||
|
||||
minEventCount = element.GetAttributeInt("mineventcount", 0);
|
||||
maxEventCount = element.GetAttributeInt("maxeventcount", 0);
|
||||
|
||||
MusicType = element.GetAttributeString("musictype", "default");
|
||||
|
||||
overrideMinEventCount = new Dictionary<string, int>();
|
||||
overrideMaxEventCount = new Dictionary<string, int>();
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
get
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "overrideeventcount":
|
||||
string levelType = subElement.GetAttributeString("leveltype", "");
|
||||
if (!overrideMinEventCount.ContainsKey(levelType))
|
||||
{
|
||||
overrideMinEventCount.Add(levelType, subElement.GetAttributeInt("min", 0));
|
||||
overrideMaxEventCount.Add(levelType, subElement.GetAttributeInt("max", 0));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Init()
|
||||
|
||||
public ScriptedEvent(ScriptedEventPrefab prefab)
|
||||
{
|
||||
this.prefab = prefab;
|
||||
}
|
||||
|
||||
public virtual void Init(bool affectSubImmediately)
|
||||
{
|
||||
isFinished = false;
|
||||
}
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
@@ -96,156 +43,37 @@ namespace Barotrauma
|
||||
{
|
||||
isFinished = true;
|
||||
}
|
||||
|
||||
|
||||
private static void LoadPrefabs()
|
||||
|
||||
public virtual bool CanAffectSubImmediately(Level level)
|
||||
{
|
||||
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 = XMLExtensions.TryLoadXml(configFile);
|
||||
if (doc == null) continue;
|
||||
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
prefabs.Add(new ScriptedEvent(element));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<ScriptedEvent> GenerateLevelEvents(Random random, Level level)
|
||||
/*public static List<ScriptedEvent> GenerateInitialEvents(Random random, Level level)
|
||||
{
|
||||
if (prefabs == null)
|
||||
if (ScriptedEventPrefab.List == null)
|
||||
{
|
||||
LoadPrefabs();
|
||||
ScriptedEventPrefab.LoadPrefabs();
|
||||
}
|
||||
|
||||
List<ScriptedEvent> events = new List<ScriptedEvent>();
|
||||
foreach (ScriptedEvent scriptedEvent in prefabs)
|
||||
foreach (ScriptedEventPrefab scriptedEvent in ScriptedEventPrefab.List)
|
||||
{
|
||||
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;
|
||||
int minCount = scriptedEvent.MinEventCount.ContainsKey(level.GenerationParams.Name) ?
|
||||
scriptedEvent.MinEventCount[level.GenerationParams.Name] : scriptedEvent.MinEventCount[""];
|
||||
int maxCount = scriptedEvent.MaxEventCount.ContainsKey(level.GenerationParams.Name) ?
|
||||
scriptedEvent.MaxEventCount[level.GenerationParams.Name] : scriptedEvent.MaxEventCount[""];
|
||||
|
||||
minCount = Math.Min(minCount, maxCount);
|
||||
|
||||
int count = random.Next(maxCount - minCount) + minCount;
|
||||
|
||||
for (int i = 0; i<count; i++)
|
||||
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);
|
||||
ScriptedEvent eventInstance = scriptedEvent.CreateInstance();
|
||||
events.Add(eventInstance);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user