(bcb06cc5c) Unstable v0.9.9.0

This commit is contained in:
Juan Pablo Arce
2020-03-27 15:22:59 -03:00
parent c81486a993
commit b143329701
326 changed files with 9692 additions and 4364 deletions
@@ -1,17 +1,27 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Extensions;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
class DelayedListElement
{
public DelayedEffect Parent;
public Entity Entity;
public Vector2? WorldPosition;
public List<ISerializableEntity> Targets;
public readonly DelayedEffect Parent;
public readonly Entity Entity;
public readonly Vector2? WorldPosition;
public readonly List<ISerializableEntity> Targets;
public float StartTimer;
public DelayedListElement(DelayedEffect parentEffect, Entity parentEntity, IEnumerable<ISerializableEntity> targets, float delay, Vector2? worldPosition)
{
Parent = parentEffect;
Entity = parentEntity;
Targets = new List<ISerializableEntity>(targets);
StartTimer = delay;
WorldPosition = worldPosition;
}
}
class DelayedEffect : StatusEffect
{
@@ -27,28 +37,18 @@ namespace Barotrauma
public override void Apply(ActionType type, float deltaTime, Entity entity, ISerializableEntity target, Vector2? worldPosition = null)
{
if (this.type != type || !HasRequiredItems(entity)) return;
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Targets.FirstOrDefault() == target)) return;
if (targetIdentifiers != null && !IsValidTarget(target)) return;
if (!HasRequiredConditions(new List<ISerializableEntity>() { target })) return;
if (this.type != type || !HasRequiredItems(entity)) { return; }
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Targets.FirstOrDefault() == target)) { return; }
if (targetIdentifiers != null && !IsValidTarget(target)) { return; }
if (!HasRequiredConditions(target.ToEnumerable())) { return; }
DelayedListElement element = new DelayedListElement
{
Parent = this,
StartTimer = delay,
Entity = entity,
WorldPosition = worldPosition,
Targets = new List<ISerializableEntity>() { target }
};
DelayList.Add(element);
DelayList.Add(new DelayedListElement(this, entity, target.ToEnumerable(), delay, worldPosition));
}
public override void Apply(ActionType type, float deltaTime, Entity entity, IEnumerable<ISerializableEntity> targets, Vector2? worldPosition = null)
{
if (this.type != type || !HasRequiredItems(entity)) return;
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Targets.SequenceEqual(targets))) return;
if (this.type != type || !HasRequiredItems(entity)) { return; }
if (!Stackable && DelayList.Any(d => d.Parent == this && d.Targets.SequenceEqual(targets))) { return; }
currentTargets.Clear();
foreach (ISerializableEntity target in targets)
@@ -61,18 +61,9 @@ namespace Barotrauma
currentTargets.Add(target);
}
if (!HasRequiredConditions(currentTargets)) return;
if (!HasRequiredConditions(currentTargets)) { return; }
DelayedListElement element = new DelayedListElement
{
Parent = this,
StartTimer = delay,
Entity = entity,
WorldPosition = worldPosition,
Targets = currentTargets
};
DelayList.Add(element);
DelayList.Add(new DelayedListElement(this, entity, currentTargets, delay, worldPosition));
}
public static void Update(float deltaTime)
@@ -88,7 +79,7 @@ namespace Barotrauma
element.StartTimer -= deltaTime;
if (element.StartTimer > 0.0f) continue;
if (element.StartTimer > 0.0f) { continue; }
element.Parent.Apply(1.0f, element.Entity, element.Targets, element.WorldPosition);
DelayList.Remove(element);
@@ -21,7 +21,8 @@ namespace Barotrauma
HasTag,
HasStatusTag,
Affliction,
EntityType
EntityType,
LimbType
}
public enum Comparison
@@ -51,7 +52,8 @@ namespace Barotrauma
// Only used by attacks
public readonly bool TargetSelf;
private readonly string[] afflictionNames = new string[] { "internaldamage", "bleeding", "burn", "oxygenlow", "bloodloss", "pressure", "stun", "husk", "afflictionhusk", "huskinfection" };
// Only used by conditionals targeting an item (makes the conditional check the item/character whose inventory this item is inside)
public readonly bool TargetContainer;
private readonly int cancelStatusEffect;
@@ -62,6 +64,7 @@ namespace Barotrauma
{
case "targetitemcomponent":
case "targetself":
case "targetcontainer":
return false;
default:
return true;
@@ -132,6 +135,7 @@ namespace Barotrauma
}
TargetItemComponentName = attribute.Parent.GetAttributeString("targetitemcomponent", "");
TargetContainer = attribute.Parent.GetAttributeBool("targetcontainer", false);
TargetSelf = attribute.Parent.GetAttributeBool("targetself", false);
foreach (XElement subElement in attribute.Parent.Elements())
@@ -150,13 +154,9 @@ namespace Barotrauma
if (!Enum.TryParse(AttributeName, true, out Type))
{
if (afflictionNames.Any(n => n == AttributeName))
if (AfflictionPrefab.Prefabs.Any(p => p.Identifier.Equals(AttributeName, StringComparison.OrdinalIgnoreCase)))
{
Type = ConditionType.Affliction;
if (AttributeName == "husk" || AttributeName == "huskaffliction")
{
AttributeName = "huskinfection";
}
}
else
{
@@ -173,8 +173,7 @@ namespace Barotrauma
public bool Matches(ISerializableEntity target)
{
string valStr = AttributeValue.ToString();
string valStr = AttributeValue.ToString();
switch (Type)
{
case ConditionType.PropertyValue:
@@ -264,34 +263,47 @@ namespace Barotrauma
default:
return false;
}
case ConditionType.Affliction:
if (target == null) { return Operator == OperatorType.NotEquals; }
Character targetChar = target as Character;
if (target is Limb limb) { targetChar = limb.character; }
if (targetChar != null)
case ConditionType.LimbType:
{
var health = targetChar.CharacterHealth;
if (health == null) { return false; }
var affliction = health.GetAffliction(AttributeName);
float afflictionStrength = affliction == null ? 0.0f : affliction.Strength;
if (FloatValue.HasValue)
if (!(target is Limb limb))
{
float value = FloatValue.Value;
switch (Operator)
return false;
}
else
{
return limb.type.ToString().Equals(valStr, StringComparison.OrdinalIgnoreCase);
}
}
case ConditionType.Affliction:
{
if (target == null) { return Operator == OperatorType.NotEquals; }
Character targetChar = target as Character;
if (target is Limb limb) { targetChar = limb.character; }
if (targetChar != null)
{
var health = targetChar.CharacterHealth;
if (health == null) { return false; }
var affliction = health.GetAffliction(AttributeName);
float afflictionStrength = affliction == null ? 0.0f : affliction.Strength;
if (FloatValue.HasValue)
{
case OperatorType.Equals:
return afflictionStrength == value;
case OperatorType.GreaterThan:
return afflictionStrength > value;
case OperatorType.GreaterThanEquals:
return afflictionStrength >= value;
case OperatorType.LessThan:
return afflictionStrength < value;
case OperatorType.LessThanEquals:
return afflictionStrength <= value;
case OperatorType.NotEquals:
return afflictionStrength != value;
float value = FloatValue.Value;
switch (Operator)
{
case OperatorType.Equals:
return afflictionStrength == value;
case OperatorType.GreaterThan:
return afflictionStrength > value;
case OperatorType.GreaterThanEquals:
return afflictionStrength >= value;
case OperatorType.LessThan:
return afflictionStrength < value;
case OperatorType.LessThanEquals:
return afflictionStrength <= value;
case OperatorType.NotEquals:
return afflictionStrength != value;
}
}
}
}
@@ -1,4 +1,5 @@
using Barotrauma.Items.Components;
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
@@ -9,13 +10,29 @@ namespace Barotrauma
{
class DurationListElement
{
public StatusEffect Parent;
public Entity Entity;
public List<ISerializableEntity> Targets;
public readonly StatusEffect Parent;
public readonly Entity Entity;
public readonly List<ISerializableEntity> Targets;
public Character User { get; private set; }
public float Timer;
public Character User;
public DurationListElement(StatusEffect parentEffect, Entity parentEntity, IEnumerable<ISerializableEntity> targets, float duration, Character user)
{
Parent = parentEffect;
Entity = parentEntity;
Targets = new List<ISerializableEntity>(targets);
Timer = duration;
User = user;
}
public void Reset(float duration, Character newUser)
{
Timer = duration;
User = newUser;
}
}
partial class StatusEffect
{
[Flags]
@@ -54,10 +71,10 @@ namespace Barotrauma
//backwards compatibility
DebugConsole.ThrowError("Error in StatusEffect config (" + element.ToString() + ") - use item identifier instead of the name.");
string itemPrefabName = element.GetAttributeString("name", "");
ItemPrefab = ItemPrefab.Prefabs.Find(m => m.NameMatches(itemPrefabName) || m.Tags.Contains(itemPrefabName));
ItemPrefab = ItemPrefab.Prefabs.Find(m => m.NameMatches(itemPrefabName, StringComparison.InvariantCultureIgnoreCase) || m.Tags.Contains(itemPrefabName));
if (ItemPrefab == null)
{
DebugConsole.ThrowError("Error in StatusEffect \""+ parentDebugName + "\" - item prefab \"" + itemPrefabName + "\" not found.");
DebugConsole.ThrowError("Error in StatusEffect \"" + parentDebugName + "\" - item prefab \"" + itemPrefabName + "\" not found.");
}
}
else
@@ -75,7 +92,7 @@ namespace Barotrauma
return;
}
}
Speed = element.GetAttributeFloat("speed", 0.0f);
Rotation = MathHelper.ToRadians(element.GetAttributeFloat("rotation", 0.0f));
@@ -94,11 +111,16 @@ namespace Barotrauma
[Serialize("", false)]
public string SpeciesName { get; private set; }
[Serialize(1, false)]
public int Count { get; private set; }
[Serialize(0f, false)]
public float Spread { get; private set; }
[Serialize("0,0", false)]
public Vector2 Offset { get; private set; }
public CharacterSpawnInfo(XElement element, string parentDebugName)
{
SerializableProperties = SerializableProperty.DeserializeProperties(this, element);
@@ -113,7 +135,7 @@ namespace Barotrauma
protected HashSet<string> targetIdentifiers;
private readonly List<RelatedItem> requiredItems;
public readonly string[] propertyNames;
private readonly object[] propertyEffects;
@@ -121,11 +143,11 @@ namespace Barotrauma
private readonly List<PropertyConditional> propertyConditionals;
private readonly bool setValue;
private readonly bool disableDeltaTime;
private readonly HashSet<string> tags;
private readonly float duration;
private readonly float lifeTime;
private float lifeTimer;
@@ -137,7 +159,7 @@ namespace Barotrauma
public readonly bool Stackable = true; //Can the same status effect be applied several times to the same targets?
private readonly int useItemCount;
private readonly bool removeItem, removeCharacter;
public readonly ActionType type = ActionType.OnActive;
@@ -151,15 +173,15 @@ namespace Barotrauma
public readonly float FireSize;
public readonly LimbType targetLimb;
public readonly LimbType[] targetLimbs;
public readonly float SeverLimbsProbability;
public HashSet<string> TargetIdentifiers
{
get { return targetIdentifiers; }
}
public List<Affliction> Afflictions
{
get;
@@ -189,7 +211,6 @@ namespace Barotrauma
string newTag = tag.Trim();
if (!tags.Contains(newTag)) tags.Add(newTag);
}
}
}
@@ -213,10 +234,15 @@ namespace Barotrauma
tags = new HashSet<string>(element.GetAttributeString("tags", "").Split(','));
Range = element.GetAttributeFloat("range", 0.0f);
string targetLimbName = element.GetAttributeString("targetlimb", null);
if (targetLimbName != null)
string[] targetLimbNames = element.GetAttributeStringArray("targetlimb", null) ?? element.GetAttributeStringArray("targetlimbs", null);
if (targetLimbNames != null)
{
Enum.TryParse(targetLimbName, out targetLimb);
List<LimbType> targetLimbs = new List<LimbType>();
foreach (string targetLimbName in targetLimbNames)
{
if (Enum.TryParse(targetLimbName, out LimbType targetLimb)) { targetLimbs.Add(targetLimb); }
}
if (targetLimbs.Count > 0) { this.targetLimbs = targetLimbs.ToArray(); }
}
IEnumerable<XAttribute> attributes = element.Attributes();
@@ -377,7 +403,7 @@ namespace Barotrauma
float afflictionStrength = subElement.GetAttributeFloat(1.0f, "amount", "strength");
Afflictions.Add(afflictionPrefab.Instantiate(afflictionStrength));
break;
case "reduceaffliction":
if (subElement.Attribute("name") != null)
@@ -476,10 +502,15 @@ namespace Barotrauma
}
}
public virtual bool HasRequiredConditions(List<ISerializableEntity> targets)
public bool HasRequiredConditions(IEnumerable<ISerializableEntity> targets)
{
return HasRequiredConditions(targets, targetingContainer: false);
}
private bool HasRequiredConditions(IEnumerable<ISerializableEntity> targets, bool targetingContainer)
{
if (!propertyConditionals.Any()) { return true; }
if (requiredItems.Any() && requiredItems.All(ri => ri.MatchOnEmpty) && targets.Count == 0) { return true; }
if (requiredItems.Any() && requiredItems.All(ri => ri.MatchOnEmpty) && !targets.Any()) { return true; }
switch (conditionalComparison)
{
case PropertyConditional.Comparison.Or:
@@ -560,33 +591,26 @@ namespace Barotrauma
public virtual void Apply(ActionType type, float deltaTime, Entity entity, ISerializableEntity target, Vector2? worldPosition = null)
{
if (this.type != type || !HasRequiredItems(entity)) return;
if (this.type != type || !HasRequiredItems(entity)) { return; }
if (targetIdentifiers != null && !IsValidTarget(target)) { return; }
if (targetIdentifiers != null && !IsValidTarget(target)) return;
if (duration > 0.0f && !Stackable)
{
//ignore if not stackable and there's already an identical statuseffect
DurationListElement existingEffect = DurationList.Find(d => d.Parent == this && d.Targets.FirstOrDefault() == target);
if (existingEffect != null)
{
existingEffect.Timer = Math.Max(existingEffect.Timer, duration);
existingEffect.User = user;
return;
}
existingEffect?.Reset(Math.Max(existingEffect.Timer, duration), user);
return;
}
List<ISerializableEntity> targets = new List<ISerializableEntity> { target };
if (!HasRequiredConditions(targets)) return;
Apply(deltaTime, entity, targets, worldPosition);
if (!HasRequiredConditions(target.ToEnumerable())) { return; }
Apply(deltaTime, entity, target.ToEnumerable(), worldPosition);
}
protected readonly List<ISerializableEntity> currentTargets = new List<ISerializableEntity>();
public virtual void Apply(ActionType type, float deltaTime, Entity entity, IEnumerable<ISerializableEntity> targets, Vector2? worldPosition = null)
{
if (this.type != type) return;
if (this.type != type) { return; }
currentTargets.Clear();
foreach (ISerializableEntity target in targets)
@@ -601,7 +625,7 @@ namespace Barotrauma
if (targetIdentifiers != null && currentTargets.Count == 0) { return; }
if (!HasRequiredItems(entity) || !HasRequiredConditions(currentTargets)) return;
if (!HasRequiredItems(entity) || !HasRequiredConditions(currentTargets)) { return; }
if (duration > 0.0f && !Stackable)
{
@@ -609,8 +633,7 @@ namespace Barotrauma
DurationListElement existingEffect = DurationList.Find(d => d.Parent == this && d.Targets.SequenceEqual(currentTargets));
if (existingEffect != null)
{
existingEffect.Timer = Math.Max(existingEffect.Timer, duration);
existingEffect.User = user;
existingEffect?.Reset(Math.Max(existingEffect.Timer, duration), user);
return;
}
}
@@ -618,7 +641,7 @@ namespace Barotrauma
Apply(deltaTime, entity, currentTargets, worldPosition);
}
protected void Apply(float deltaTime, Entity entity, List<ISerializableEntity> targets, Vector2? worldPosition = null)
protected void Apply(float deltaTime, Entity entity, IEnumerable<ISerializableEntity> targets, Vector2? worldPosition = null)
{
if (lifeTime > 0)
{
@@ -637,11 +660,11 @@ namespace Barotrauma
}
Vector2 position = worldPosition ?? entity.WorldPosition;
if (targetLimb != LimbType.None)
if (targetLimbs?.FirstOrDefault(l => l != LimbType.None) is LimbType l)
{
if (entity is Character c)
{
Limb limb = c.AnimController.GetLimb(targetLimb);
Limb limb = c.AnimController.GetLimb(l);
if (limb != null && !limb.Removed)
{
position = limb.WorldPosition;
@@ -666,13 +689,13 @@ namespace Barotrauma
if (item.Removed) continue;
item.Use(deltaTime, targetCharacter, targets.FirstOrDefault(t => t is Limb) as Limb);
}
}
}
if (removeItem)
{
foreach (var target in targets)
{
if (target is Item item) { Entity.Spawner?.AddToRemoveQueue(item); }
if (target is Item item) { Entity.Spawner?.AddToRemoveQueue(item); }
}
}
if (removeCharacter)
@@ -685,16 +708,7 @@ namespace Barotrauma
if (duration > 0.0f)
{
DurationListElement element = new DurationListElement
{
Parent = this,
Timer = duration,
Entity = entity,
Targets = targets,
User = user
};
DurationList.Add(element);
DurationList.Add(new DurationListElement(this, entity, targets, duration, user));
}
else
{
@@ -707,11 +721,11 @@ namespace Barotrauma
for (int i = 0; i < propertyNames.Length; i++)
{
if (target == null || target.SerializableProperties == null ||
if (target == null || target.SerializableProperties == null ||
!target.SerializableProperties.TryGetValue(propertyNames[i], out SerializableProperty property)) continue;
ApplyToProperty(target, property, propertyEffects[i], deltaTime);
}
}
}
}
if (explosion != null && entity != null)
@@ -732,7 +746,8 @@ namespace Barotrauma
character.LastDamageSource = entity;
foreach (Limb limb in character.AnimController.Limbs)
{
limb.character.DamageLimb(position, limb, new List<Affliction>() { multipliedAffliction }, stun: 0.0f, playSound: false, attackImpulse: 0.0f, attacker: affliction.Source);
if (targetLimbs != null && !targetLimbs.Contains(limb.type)) { continue; }
limb.character.DamageLimb(position, limb, multipliedAffliction.ToEnumerable(), stun: 0.0f, playSound: false, attackImpulse: 0.0f, attacker: affliction.Source);
limb.character.TrySeverLimbJoints(limb, SeverLimbsProbability);
//only apply non-limb-specific afflictions to the first limb
if (!affliction.Prefab.LimbSpecific) { break; }
@@ -741,7 +756,7 @@ namespace Barotrauma
else if (target is Limb limb)
{
if (limb.character.Removed || limb.Removed) { continue; }
limb.character.DamageLimb(position, limb, new List<Affliction>() { multipliedAffliction }, stun: 0.0f, playSound: false, attackImpulse: 0.0f, attacker: affliction.Source);
limb.character.DamageLimb(position, limb, multipliedAffliction.ToEnumerable(), stun: 0.0f, playSound: false, attackImpulse: 0.0f, attacker: affliction.Source);
limb.character.TrySeverLimbJoints(limb, SeverLimbsProbability);
}
}
@@ -776,7 +791,7 @@ namespace Barotrauma
var fire = new FireSource(position, hull);
fire.Size = new Vector2(FireSize, fire.Size.Y);
}
bool isNotClient = GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient;
if (isNotClient && entity != null && Entity.Spawner != null) //clients are not allowed to spawn entities
{
@@ -785,15 +800,15 @@ namespace Barotrauma
var characters = new List<Character>();
for (int i = 0; i < characterSpawnInfo.Count; i++)
{
Entity.Spawner.AddToSpawnQueue(characterSpawnInfo.SpeciesName, position + Rand.Vector(characterSpawnInfo.Spread, Rand.RandSync.Server),
Entity.Spawner.AddToSpawnQueue(characterSpawnInfo.SpeciesName, position + Rand.Vector(characterSpawnInfo.Spread, Rand.RandSync.Server) + characterSpawnInfo.Offset,
onSpawn: newCharacter =>
{
characters.Add(newCharacter);
if (characters.Count == characterSpawnInfo.Count)
{
SwarmBehavior.CreateSwarm(characters.Cast<AICharacter>());
}
});
characters.Add(newCharacter);
if (characters.Count == characterSpawnInfo.Count)
{
SwarmBehavior.CreateSwarm(characters.Cast<AICharacter>());
}
});
}
}
foreach (ItemSpawnInfo itemSpawnInfo in spawnItems)
@@ -804,7 +819,7 @@ namespace Barotrauma
Entity.Spawner.AddToSpawnQueue(itemSpawnInfo.ItemPrefab, position);
break;
case ItemSpawnInfo.SpawnPositionType.ThisInventory:
{
{
if (entity is Character character)
{
if (character.Inventory != null && character.Inventory.Items.Any(it => it == null))
@@ -843,7 +858,7 @@ namespace Barotrauma
Entity.Spawner.AddToSpawnQueue(itemSpawnInfo.ItemPrefab, containedInventory);
break;
}
}
}
}
break;
}
@@ -853,7 +868,7 @@ namespace Barotrauma
ApplyProjSpecific(deltaTime, entity, targets, hull, position);
}
partial void ApplyProjSpecific(float deltaTime, Entity entity, List<ISerializableEntity> targets, Hull currentHull, Vector2 worldPosition);
partial void ApplyProjSpecific(float deltaTime, Entity entity, IEnumerable<ISerializableEntity> targets, Hull currentHull, Vector2 worldPosition);
private void ApplyToProperty(ISerializableEntity target, SerializableProperty property, object value, float deltaTime)
{
@@ -904,8 +919,8 @@ namespace Barotrauma
continue;
}
element.Targets.RemoveAll(t =>
(t is Entity entity && entity.Removed) ||
element.Targets.RemoveAll(t =>
(t is Entity entity && entity.Removed) ||
(t is Limb limb && (limb.character == null || limb.character.Removed)));
if (element.Targets.Count == 0)
{
@@ -934,12 +949,12 @@ namespace Barotrauma
if (target is Character character)
{
if (character.Removed) { continue; }
character.AddDamage(character.WorldPosition, new List<Affliction>() { multipliedAffliction }, stun: 0.0f, playSound: false, attacker: element.User);
character.AddDamage(character.WorldPosition, multipliedAffliction.ToEnumerable(), stun: 0.0f, playSound: false, attacker: element.User);
}
else if (target is Limb limb)
{
if (limb.character.Removed || limb.Removed) { continue; }
limb.character.DamageLimb(limb.WorldPosition, limb, new List<Affliction>() { multipliedAffliction }, stun: 0.0f, playSound: false, attackImpulse: 0.0f, attacker: element.User);
limb.character.DamageLimb(limb.WorldPosition, limb, multipliedAffliction.ToEnumerable(), stun: 0.0f, playSound: false, attackImpulse: 0.0f, attacker: element.User);
}
}