Expose some stuff to sub editor, fix alien doors openable with use key, fixed some decon recipes

Beginnings of a Conditional system
This commit is contained in:
Alex Noir
2017-12-27 18:00:18 +03:00
parent 156ff292e3
commit f5e785df60
5 changed files with 123 additions and 17 deletions

View File

@@ -1354,9 +1354,24 @@
<None Include="$(MSBuildThisFileDirectory)Content\watershader_opengl.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Submarines\Nehalennia.sub" />
<None Include="$(MSBuildThisFileDirectory)Submarines\TutorialSub.sub" />
<None Include="$(MSBuildThisFileDirectory)Submarines\Vellamo.sub" />
<None Include="$(MSBuildThisFileDirectory)Submarines\Aegir Mark III.sub">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Submarines\Nehalennia.sub">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Submarines\The Blind Carp.sub">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Submarines\The Nibbler.sub">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Submarines\TutorialSub.sub">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)Submarines\Vellamo.sub">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\AICharacter.cs" />

View File

@@ -98,9 +98,9 @@
<Deconstruct time="20">
<Item name="Steel Bar"/>
<Item name="Liquid Oxygenite"/>
<Item name="Liquid Oxygenite"/>
<Item name="Liquid Oxygenite"/>
<Item name="Liquid Oxygenite" mincondition="0.1"/>
<Item name="Liquid Oxygenite" mincondition="0.5"/>
<Item name="Liquid Oxygenite" mincondition="0.9"/>
</Deconstruct>
<Sprite texture="artifact.png" depth="0.7" sourcerect="119,0,9,32"/>
@@ -127,9 +127,9 @@
<Deconstruct time="20">
<Item name="Steel Bar"/>
<Item name="Sulphuric Acid"/>
<Item name="Sulphuric Acid"/>
<Item name="Sulphuric Acid"/>
<Item name="Sulphuric Acid" mincondition="0.1"/>
<Item name="Sulphuric Acid" mincondition="0.5"/>
<Item name="Sulphuric Acid" mincondition="0.9"/>
</Deconstruct>
<Sprite texture="artifact.png" depth="0.7" sourcerect="119,0,9,32"/>
@@ -201,7 +201,7 @@
<Sprite texture="Content/Map/ruins.png" sourcerect="747,0,260,95" depth="0.8" origin="0.5,0.5"/>
<Door canbeselected="true" horizontal="true">
<Door canbepicked="false" canbeselected="true" horizontal="true">
<Sprite texture="Content/Map/ruins.png" sourcerect="0,842,260,54" depth="0.6" origin="0.0,0.5"/>
<sound file="aliendoor.ogg" type="OnUse" range="1000.0"/>
</Door>
@@ -223,7 +223,7 @@
<Sprite texture="Content/Map/ruins.png" sourcerect="746,101,93,259" depth="0.8" origin="0.5,0.5"/>
<Door canbeselected="true">
<Door canbepicked="false" canbeselected="true">
<Sprite texture="Content/Map/ruins.png" sourcerect="842,192,54,259" depth="0.6" origin="0.5,0.0"/>
<sound file="aliendoor.ogg" type="OnUse" range="3000.0"/>
</Door>

View File

@@ -32,6 +32,8 @@ namespace Barotrauma
public string[] propertyNames;
private object[] propertyEffects;
List<Tuple<string, string, object>> propertyConditionals;
private bool setValue;
private bool disableDeltaTime;
@@ -83,7 +85,8 @@ namespace Barotrauma
IEnumerable<XAttribute> attributes = element.Attributes();
List<XAttribute> propertyAttributes = new List<XAttribute>();
propertyConditionals = new List<Tuple<string, string, object>>();
foreach (XAttribute attribute in attributes)
{
switch (attribute.Name.ToString())
@@ -138,7 +141,20 @@ namespace Barotrauma
" - sounds should be defined as child elements of the StatusEffect, not as attributes.");
break;
default:
propertyAttributes.Add(attribute);
object attributeObject = XMLExtensions.GetAttributeObject(attribute);
Type type = attributeObject.GetType();
string op = ((string)attributeObject).Substring(0, 2);
if (op != "!=" && op != ">=" && op != "<=" && op != "==" && (op.StartsWith(">") || op.StartsWith("<")))
op = op.Substring(0, 1);
if (op == "!=" || op == ">=" || op == "<=" || op == "==" || op == ">" || op == "<") //Oh shit this is a conditional!
{
attributeObject = ((string)attributeObject).Substring(op.Length, ((string)attributeObject).Length);
propertyConditionals.Add(new Tuple<string, string, object>(attribute.Name.ToString().ToLowerInvariant(), op, attributeObject));
}
else
propertyAttributes.Add(attribute);
break;
}
}
@@ -209,6 +225,80 @@ namespace Barotrauma
return true;
}
public virtual bool HasRequiredConditions(List<ISerializableEntity> targets)
{
if (!propertyConditionals.Any()) return true;
foreach (ISerializableEntity target in targets)
{
foreach (Tuple<string, string, object> con in propertyConditionals)
{
string name = con.Item1;
string op = con.Item2;
object value = con.Item3;
SerializableProperty property;
if (target == null || target.SerializableProperties == null || !target.SerializableProperties.TryGetValue(name, out property)) continue;
Type type = value.GetType();
float? floatValue = null;
if ((type == typeof(float) || type == typeof(int)) && (property.GetValue() is float || property.GetValue() is int))
{
floatValue = Convert.ToSingle(value);
}
switch (op)
{
case "==":
if (!(property == value))
return false;
break;
case "!=":
if (!(property != value))
return false;
break;
case ">":
if (floatValue == null)
{
DebugConsole.ThrowError("Couldn't compare " + value.ToString() + " (" + type + ") to property \"" + property.Name + "\" (" + property.GetValue().GetType() + ")! "
+ "Make sure the type of the value set in the config files matches the type of the property.");
}
else if (!((float)property.GetValue() > floatValue))
return false;
break;
case "<":
if (floatValue == null)
{
DebugConsole.ThrowError("Couldn't compare " + value.ToString() + " (" + type + ") to property \"" + property.Name + "\" (" + property.GetValue().GetType() + ")! "
+ "Make sure the type of the value set in the config files matches the type of the property.");
}
else if (!((float)property.GetValue() < floatValue))
return false;
break;
case ">=":
if (floatValue == null)
{
DebugConsole.ThrowError("Couldn't compare " + value.ToString() + " (" + type + ") to property \"" + property.Name + "\" (" + property.GetValue().GetType() + ")! "
+ "Make sure the type of the value set in the config files matches the type of the property.");
}
else if (!((float)property.GetValue() >= floatValue))
return false;
break;
case "<=":
if (floatValue == null)
{
DebugConsole.ThrowError("Couldn't compare " + value.ToString() + " (" + type + ") to property \"" + property.Name + "\" (" + property.GetValue().GetType() + ")! "
+ "Make sure the type of the value set in the config files matches the type of the property.");
}
else if (!((float)property.GetValue() <= floatValue))
return false;
break;
}
}
}
return true;
}
public virtual void Apply(ActionType type, float deltaTime, Entity entity, ISerializableEntity target)
{
if (this.type != type || !HasRequiredItems(entity)) return;

View File

@@ -207,7 +207,8 @@ namespace Barotrauma.Items.Components
{
if (item.Condition <= 0.0f) return true; //For repairing
return base.HasRequiredItems(character, addMessage);
//this is a bit pointless atm because if canBePicked is false it won't allow you to do Pick() anyway, however it's still good for future-proofing.
return requiredItems.Any() ? base.HasRequiredItems(character, addMessage) : canBePicked;
}
public override bool Pick(Character picker)

View File

@@ -49,7 +49,7 @@ namespace Barotrauma.Items.Components
private string msg;
[Serialize(0.0f, false)]
[Editable, Serialize(0.0f, false)]
public float PickingTime
{
get;
@@ -105,7 +105,7 @@ namespace Barotrauma.Items.Components
}
}
[Serialize(false, false)]
[Editable, Serialize(false, false)] //Editable for doors to do their magic
public bool CanBePicked
{
get { return canBePicked; }
@@ -171,7 +171,7 @@ namespace Barotrauma.Items.Components
get { return name; }
}
[Serialize("", false)]
[Editable, Serialize("", false)]
public string Msg
{
get { return msg; }