(ae643deeb) Added alive checks to a couple of diving gear status effects (don't consume tanks when dead)

This commit is contained in:
Joonas Rikkonen
2019-04-01 22:47:22 +03:00
parent ec7e23061b
commit 2eaf22683d
129 changed files with 2451 additions and 1336 deletions
@@ -4,11 +4,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Items.Components;
#if CLIENT
using Barotrauma.Particles;
using Barotrauma.Sounds;
#endif
namespace Barotrauma
{
@@ -91,52 +86,10 @@ namespace Barotrauma
}
}
private TargetType targetTypes;
protected HashSet<string> targetIdentifiers;
public readonly ItemPrefab ItemPrefab;
public readonly SpawnPositionType SpawnPosition;
public readonly float Speed;
public readonly float Rotation;
public ItemSpawnInfo(XElement element, string parentDebugName)
{
if (element.Attribute("name") != null)
{
//backwards compatibility
DebugConsole.ThrowError("Error in StatusEffect config (" + element.ToString() + ") - use item identifier instead of the name.");
string itemPrefabName = element.GetAttributeString("name", "");
ItemPrefab = MapEntityPrefab.List.Find(m => m is ItemPrefab && (m.NameMatches(itemPrefabName) || m.Tags.Contains(itemPrefabName))) as ItemPrefab;
if (ItemPrefab == null)
{
DebugConsole.ThrowError("Error in StatusEffect \""+ parentDebugName + "\" - item prefab \"" + itemPrefabName + "\" not found.");
}
}
else
{
string itemPrefabIdentifier = element.GetAttributeString("identifier", "");
if (string.IsNullOrEmpty(itemPrefabIdentifier)) itemPrefabIdentifier = element.GetAttributeString("identifiers", "");
if (string.IsNullOrEmpty(itemPrefabIdentifier))
{
DebugConsole.ThrowError("Invalid item spawn in StatusEffect \"" + parentDebugName + "\" - identifier not found in the element \"" + element.ToString() + "\"");
}
ItemPrefab = MapEntityPrefab.List.Find(m => m is ItemPrefab && m.Identifier == itemPrefabIdentifier) as ItemPrefab;
if (ItemPrefab == null)
{
DebugConsole.ThrowError("Error in StatusEffect config - item prefab with the identifier \"" + itemPrefabIdentifier + "\" not found.");
return;
}
}
Speed = element.GetAttributeFloat("speed", 0.0f);
Rotation = MathHelper.ToRadians(element.GetAttributeFloat("rotation", 0.0f));
private List<RoundSound> sounds = new List<RoundSound>();
private SoundSelectionMode soundSelectionMode;
private SoundChannel soundChannel;
private bool loopSound;
#endif
private List<RelatedItem> requiredItems;
public string[] propertyNames;
@@ -228,10 +181,6 @@ namespace Barotrauma
Range = element.GetAttributeFloat("range", 0.0f);
#if CLIENT
particleEmitters = new List<ParticleEmitter>();
#endif
IEnumerable<XAttribute> attributes = element.Attributes();
List<XAttribute> propertyAttributes = new List<XAttribute>();
propertyConditionals = new List<PropertyConditional>();
@@ -408,25 +357,6 @@ namespace Barotrauma
var newSpawnItem = new ItemSpawnInfo(subElement, parentDebugName);
if (newSpawnItem.ItemPrefab != null) spawnItems.Add(newSpawnItem);
break;
#if CLIENT
case "particleemitter":
particleEmitters.Add(new ParticleEmitter(subElement));
break;
case "sound":
var sound = Submarine.LoadRoundSound(subElement);
if (sound != null)
{
loopSound = subElement.GetAttributeBool("loop", false);
if (subElement.Attribute("selectionmode") != null)
{
if (Enum.TryParse(subElement.GetAttributeString("selectionmode", "Random"), out SoundSelectionMode selectionMode))
{
soundSelectionMode = selectionMode;
}
}
sounds.Add(sound);
}
break;
}
}
InitProjSpecific(element, parentDebugName);
@@ -439,11 +369,6 @@ namespace Barotrauma
return (targetTypes & targetType) != 0;
}
public bool HasTargetType(TargetType targetType)
{
return (targetTypes & targetType) != 0;
}
public virtual bool HasRequiredItems(Entity entity)
{
if (requiredItems == null) return true;
@@ -643,46 +568,10 @@ namespace Barotrauma
{
hull = ((Item)entity).CurrentHull;
}
#if CLIENT
if (entity != null && sounds.Count > 0)
{
if (soundChannel == null || !soundChannel.IsPlaying)
{
if (soundSelectionMode == SoundSelectionMode.All)
{
foreach (RoundSound sound in sounds)
{
soundChannel = SoundPlayer.PlaySound(sound.Sound, sound.Volume, sound.Range, entity.WorldPosition, hull);
if (soundChannel != null) soundChannel.Looping = loopSound;
}
}
else
{
int selectedSoundIndex = 0;
if (soundSelectionMode == SoundSelectionMode.ItemSpecific && entity is Item item)
{
selectedSoundIndex = item.ID % sounds.Count;
}
else if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && entity is Character user)
{
selectedSoundIndex = user.ID % sounds.Count;
}
else
{
selectedSoundIndex = Rand.Int(sounds.Count);
}
var selectedSound = sounds[selectedSoundIndex];
soundChannel = SoundPlayer.PlaySound(selectedSound.Sound, selectedSound.Volume, selectedSound.Range, entity.WorldPosition, hull);
if (soundChannel != null) soundChannel.Looping = loopSound;
}
}
}
#endif
foreach (ISerializableEntity serializableEntity in targets)
{
Item item = serializableEntity as Item;
if (item == null) continue;
if (!(serializableEntity is Item item)) continue;
Character targetCharacter = targets.FirstOrDefault(t => t is Character character && !character.Removed) as Character;
if (targetCharacter == null)
@@ -782,11 +671,7 @@ namespace Barotrauma
fire.Size = new Vector2(FireSize, fire.Size.Y);
}
bool isNotClient = true;
#if CLIENT
isNotClient = GameMain.Client == null;
#endif
bool isNotClient = GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient;
if (isNotClient && entity != null && Entity.Spawner != null) //clients are not allowed to spawn items
{
foreach (ItemSpawnInfo itemSpawnInfo in spawnItems)
@@ -843,27 +728,11 @@ namespace Barotrauma
}
}
#if CLIENT
if (entity != null)
{
foreach (ParticleEmitter emitter in particleEmitters)
{
float angle = 0.0f;
if (emitter.Prefab.CopyEntityAngle)
{
if (entity is Item it)
{
angle = it.body == null ? 0.0f : it.body.Rotation;
}
}
emitter.Emit(deltaTime, entity.WorldPosition, hull, angle);
}
}
ApplyProjSpecific(deltaTime, entity, targets, hull);
}
partial void ApplyProjSpecific(float deltaTime, Entity entity, List<ISerializableEntity> targets, Hull currentHull);
private void ApplyToProperty(ISerializableEntity target, SerializableProperty property, object value, float deltaTime)
{
if (disableDeltaTime || setValue) deltaTime = 1.0f;