(e42047dc1) Tester's build, January 30th 2020

This commit is contained in:
Juan Pablo Arce
2020-01-30 15:56:31 -03:00
parent eaa18a20a3
commit 15499cb704
203 changed files with 8274 additions and 4950 deletions
@@ -9,10 +9,14 @@ namespace Barotrauma
{
public static List<AITarget> List = new List<AITarget>();
private Entity entity;
public Entity Entity
{
get;
private set;
get
{
if (entity != null && entity.Removed) { return null; }
return entity;
}
}
private float soundRange;
@@ -28,13 +32,29 @@ namespace Barotrauma
public float SoundRange
{
get { return soundRange; }
set { soundRange = MathHelper.Clamp(value, MinSoundRange, MaxSoundRange); }
set
{
if (float.IsNaN(value))
{
DebugConsole.ThrowError("Attempted to set the SoundRange of an AITarget to NaN.\n" + Environment.StackTrace);
return;
}
soundRange = MathHelper.Clamp(value, MinSoundRange, MaxSoundRange);
}
}
public float SightRange
{
get { return sightRange; }
set { sightRange = MathHelper.Clamp(value, MinSightRange, MaxSightRange); }
set
{
if (float.IsNaN(value))
{
DebugConsole.ThrowError("Attempted to set the SightRange of an AITarget to NaN.\n" + Environment.StackTrace);
return;
}
sightRange = MathHelper.Clamp(value, MinSightRange, MaxSightRange);
}
}
private float sectorRad = MathHelper.TwoPi;
@@ -54,7 +74,7 @@ namespace Barotrauma
{
string errorMsg = "Invalid AITarget sector direction (" + value + ")\n" + Environment.StackTrace;
DebugConsole.ThrowError(errorMsg);
GameAnalyticsManager.AddErrorEventOnce("AITarget.SectorDir:" + Entity?.ToString(), GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
GameAnalyticsManager.AddErrorEventOnce("AITarget.SectorDir:" + entity?.ToString(), GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
return;
}
sectorDir = value;
@@ -88,7 +108,7 @@ namespace Barotrauma
{
get
{
if (Entity == null || Entity.Removed)
if (entity == null || entity.Removed)
{
#if DEBUG
DebugConsole.ThrowError("Attempted to access a removed AITarget\n" + Environment.StackTrace);
@@ -99,7 +119,7 @@ namespace Barotrauma
return Vector2.Zero;
}
return Entity.WorldPosition;
return entity.WorldPosition;
}
}
@@ -107,7 +127,7 @@ namespace Barotrauma
{
get
{
if (Entity == null || Entity.Removed)
if (entity == null || entity.Removed)
{
#if DEBUG
DebugConsole.ThrowError("Attempted to access a removed AITarget\n" + Environment.StackTrace);
@@ -118,7 +138,7 @@ namespace Barotrauma
return Vector2.Zero;
}
return Entity.SimPosition;
return entity.SimPosition;
}
}
@@ -156,7 +176,7 @@ namespace Barotrauma
public AITarget(Entity e)
{
Entity = e;
entity = e;
List.Add(this);
}
@@ -181,7 +201,7 @@ namespace Barotrauma
public void Remove()
{
List.Remove(this);
Entity = null;
entity = null;
}
}
}
@@ -89,6 +89,9 @@ namespace Barotrauma
private readonly float memoryFadeTime = 0.5f;
private readonly float avoidTime = 3;
//Has the character been attacked since the last Update.
private bool wasAttacked;
private float avoidTimer;
public LatchOntoAI LatchOntoAI { get; private set; }
@@ -231,7 +234,15 @@ namespace Barotrauma
public override void Update(float deltaTime)
{
if (wasAttacked)
{
LatchOntoAI?.DeattachFromBody();
Character.AnimController.ReleaseStuckLimbs();
wasAttacked = false;
}
if (DisableEnemyAI) { return; }
base.Update(deltaTime);
bool ignorePlatforms = (-Character.AnimController.TargetMovement.Y > Math.Abs(Character.AnimController.TargetMovement.X));
@@ -630,7 +641,7 @@ namespace Barotrauma
if (pickable != null)
{
var target = pickable.Picker?.AiTarget;
if (target != null)
if (target?.Entity != null && !target.Entity.Removed)
{
SelectedAiTarget = target;
}
@@ -1224,14 +1235,13 @@ namespace Barotrauma
}
return isDisabled;
}
public override void OnAttacked(Character attacker, AttackResult attackResult)
{
float reactionTime = Rand.Range(0.1f, 0.3f);
updateTargetsTimer = Math.Min(updateTargetsTimer, reactionTime);
LatchOntoAI?.DeattachFromBody();
Character.AnimController.ReleaseStuckLimbs();
wasAttacked = true;
if (attacker == null || attacker.AiTarget == null) { return; }
@@ -131,6 +131,8 @@ namespace Barotrauma
}
coroutine = CoroutineManager.InvokeAfter(() =>
{
//round ended before the coroutine finished
if (GameMain.GameSession == null || Level.Loaded == null) { return; }
DelayedObjectives.Remove(objective);
AddObjective(objective);
callback?.Invoke();
@@ -2,15 +2,30 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using System.Linq;
namespace Barotrauma
{
public enum OrderCategory
{
Emergency,
Movement,
Power,
Maintenance,
Operate,
Undefined
}
class Order
{
public static Dictionary<string, Order> Prefabs { get; private set; }
public static Dictionary<OrderCategory, Sprite> OrderCategoryIcons { get; private set; }
public static Sprite StartNode { get; private set; }
public static Sprite ShortcutNode { get; private set; }
public static Sprite ExpandNode { get; private set; }
public static Sprite NodeContainer { get; private set; }
public static Sprite CommandBackground { get; private set; }
public static List<Order> PrefabList { get; private set; }
public static Order GetPrefab(string identifier)
{
@@ -49,15 +64,20 @@ namespace Barotrauma
public Controller ConnectedController;
public Character OrderGiver;
public readonly OrderCategory Category;
//legacy support
public readonly string[] AppropriateJobs;
public readonly string[] Options;
public readonly string[] OptionNames;
public readonly Dictionary<string, Sprite> OptionSprites;
static Order()
{
Prefabs = new Dictionary<string, Order>();
OrderCategoryIcons = new Dictionary<OrderCategory, Sprite>();
foreach (ContentFile file in GameMain.Instance.GetFilesOfType(ContentType.Orders))
{
@@ -72,11 +92,11 @@ namespace Barotrauma
}
foreach (XElement sourceElement in mainElement.Elements())
{
var orderElement = sourceElement.IsOverride() ? sourceElement.FirstElement() : sourceElement;
string name = orderElement.Name.ToString();
var element = sourceElement.IsOverride() ? sourceElement.FirstElement() : sourceElement;
string name = element.Name.ToString();
if (name.Equals("order", StringComparison.OrdinalIgnoreCase))
{
string identifier = orderElement.GetAttributeString("identifier", null);
string identifier = element.GetAttributeString("identifier", null);
if (string.IsNullOrWhiteSpace(identifier))
{
DebugConsole.ThrowError($"Error in file {file.Path}: The order element '{name}' does not have an identifier! All orders must have a unique identifier.");
@@ -95,10 +115,58 @@ namespace Barotrauma
continue;
}
}
var newOrder = new Order(orderElement);
var newOrder = new Order(element);
newOrder.Prefab = newOrder;
Prefabs.Add(identifier, newOrder);
}
else if (name.Equals("ordercategory", StringComparison.OrdinalIgnoreCase))
{
var category = (OrderCategory)Enum.Parse(typeof(OrderCategory), element.GetAttributeString("category", "undefined"), true);
if (OrderCategoryIcons.TryGetValue(category, out Sprite duplicate))
{
if (allowOverriding || sourceElement.IsOverride())
{
DebugConsole.NewMessage($"Overriding an existing icon for the '{category}' order category with another one defined in '{file}'", Color.Yellow);
OrderCategoryIcons.Remove(category);
}
else
{
DebugConsole.ThrowError($"Error in file {file}: Duplicate element for the '{category}' order category found in '{file}'! All order categories must be unique. Use <override></override> tags to override an order category.");
continue;
}
}
var spriteElement = element.GetChildElement("sprite");
if (spriteElement != null)
{
var sprite = new Sprite(spriteElement, lazyLoad: true);
OrderCategoryIcons.Add(category, sprite);
}
}
else
{
var spriteElement = element.GetChildElement("sprite");
if (spriteElement != null)
{
switch (name.ToLowerInvariant())
{
case "startnode":
StartNode = new Sprite(spriteElement, lazyLoad: true);
break;
case "shortcutnode":
ShortcutNode = new Sprite(spriteElement, lazyLoad: true);
break;
case "expandnode":
ExpandNode = new Sprite(spriteElement, lazyLoad: true);
break;
case "nodecontainer":
NodeContainer = new Sprite(spriteElement, lazyLoad: true);
break;
case "commandbackground":
CommandBackground = new Sprite(spriteElement, lazyLoad: true);
break;
}
}
}
}
}
PrefabList = new List<Order>(Prefabs.Values);
@@ -130,6 +198,7 @@ namespace Barotrauma
TargetAllCharacters = orderElement.GetAttributeBool("targetallcharacters", false);
AppropriateJobs = orderElement.GetAttributeStringArray("appropriatejobs", new string[0]);
Options = orderElement.GetAttributeStringArray("options", new string[0]);
Category = (OrderCategory)Enum.Parse(typeof(OrderCategory), orderElement.GetAttributeString("category", "undefined"), true);
string translatedOptionNames = TextManager.Get("OrderOptions." + Identifier, true);
if (translatedOptionNames == null)
@@ -152,13 +221,24 @@ namespace Barotrauma
OptionNames = Options;
}
foreach (XElement subElement in orderElement.Elements())
var spriteElement = orderElement.GetChildElement("sprite");
if (spriteElement != null)
{
switch (subElement.Name.ToString().ToLowerInvariant())
SymbolSprite = new Sprite(spriteElement, lazyLoad: true);
}
OptionSprites = new Dictionary<string, Sprite>();
if (Options != null && Options.Length > 0)
{
var optionSpriteElements = orderElement.GetChildElement("optionsprites")?.GetChildElements("sprite");
if (optionSpriteElements != null && optionSpriteElements.Any())
{
case "sprite":
SymbolSprite = new Sprite(subElement, lazyLoad: true);
break;
for (int i = 0; i < Options.Length; i++)
{
if (i >= optionSpriteElements.Count()) { break; };
var sprite = new Sprite(optionSpriteElements.ElementAt(i), lazyLoad: true);
OptionSprites.Add(Options[i], sprite);
}
}
}
}
@@ -226,5 +306,4 @@ namespace Barotrauma
return msg;
}
}
}