(965c31410a) Unstable v0.10.4.0

This commit is contained in:
Juan Pablo Arce
2020-07-21 08:57:50 -03:00
parent 4f8bd39789
commit 33d3a41104
546 changed files with 45952 additions and 25762 deletions
@@ -9,15 +9,24 @@ using Barotrauma.Extensions;
namespace Barotrauma.Items.Components
{
struct LimbPos
class LimbPos : ISerializableEntity
{
public LimbType limbType;
public Vector2 position;
[Editable]
public LimbType LimbType { get; set; }
[Editable]
public Vector2 Position { get; set; }
public LimbPos(LimbType limbType, Vector2 position)
public bool AllowUsingLimb;
public string Name => LimbType.ToString();
public Dictionary<string, SerializableProperty> SerializableProperties => null;
public LimbPos(LimbType limbType, Vector2 position, bool allowUsingLimb)
{
this.limbType = limbType;
this.position = position;
LimbType = limbType;
Position = position;
AllowUsingLimb = allowUsingLimb;
}
}
@@ -66,11 +75,32 @@ namespace Barotrauma.Items.Components
set;
}
[Serialize(true, false, description: "Should the HUD (inventory, health bar, etc) be hidden when this item is selected.")]
public bool HideHUD
{
get;
set;
}
public enum UseEnvironment
{
Air, Water, Both
};
[Serialize(UseEnvironment.Both, false, description: "Can the item be selected in air, underwater or both.")]
public UseEnvironment UsableIn { get; set; }
public bool ControlCharacterPose
{
get { return limbPositions.Count > 0; }
}
public bool AllowAiming
{
get;
private set;
} = true;
public Controller(Item item, XElement element)
: base(item, element)
{
@@ -79,25 +109,31 @@ namespace Barotrauma.Items.Components
userPos = element.GetAttributeVector2("UserPos", Vector2.Zero);
Enum.TryParse(element.GetAttributeString("direction", "None"), out dir);
foreach (XElement el in element.Elements())
foreach (XElement subElement in element.Elements())
{
if (el.Name != "limbposition") continue;
LimbPos lp = new LimbPos();
try
if (subElement.Name != "limbposition") { continue; }
string limbStr = subElement.GetAttributeString("limb", "");
if (!Enum.TryParse(subElement.Attribute("limb").Value, out LimbType limbType))
{
lp.limbType = (LimbType)Enum.Parse(typeof(LimbType), el.Attribute("limb").Value, true);
DebugConsole.ThrowError($"Error in item \"{item.Name}\" - {limbStr} is not a valid limb type.");
}
catch (Exception e)
else
{
DebugConsole.ThrowError("Error in " + element + ": " + e.Message, e);
LimbPos limbPos = new LimbPos(limbType,
subElement.GetAttributeVector2("position", Vector2.Zero),
subElement.GetAttributeBool("allowusinglimb", false));
limbPositions.Add(limbPos);
if (!limbPos.AllowUsingLimb)
{
if (limbType == LimbType.RightHand || limbType == LimbType.RightForearm || limbType == LimbType.RightArm ||
limbType == LimbType.LeftHand || limbType == LimbType.LeftForearm || limbType == LimbType.LeftArm)
{
AllowAiming = false;
}
}
}
lp.position = el.GetAttributeVector2("position", Vector2.Zero);
limbPositions.Add(lp);
}
IsActive = true;
@@ -115,7 +151,9 @@ namespace Barotrauma.Items.Components
if (user == null
|| user.Removed
|| user.SelectedConstruction != item
|| !user.CanInteractWith(item))
|| !user.CanInteractWith(item)
|| (UsableIn == UseEnvironment.Water && !user.AnimController.InWater)
|| (UsableIn == UseEnvironment.Air && user.AnimController.InWater))
{
if (user != null)
{
@@ -187,12 +225,29 @@ namespace Barotrauma.Items.Components
foreach (LimbPos lb in limbPositions)
{
Limb limb = user.AnimController.GetLimb(lb.limbType);
if (limb == null || !limb.body.Enabled) continue;
Limb limb = user.AnimController.GetLimb(lb.LimbType);
if (limb == null || !limb.body.Enabled) { continue; }
if (lb.AllowUsingLimb)
{
switch (lb.LimbType)
{
case LimbType.RightHand:
case LimbType.RightForearm:
case LimbType.RightArm:
if (user.SelectedItems[0] != null) { continue; }
break;
case LimbType.LeftHand:
case LimbType.LeftForearm:
case LimbType.LeftArm:
if ( user.SelectedItems[1] != null) { continue; }
break;
}
}
limb.Disabled = true;
Vector2 worldPosition = new Vector2(item.WorldRect.X, item.WorldRect.Y) + lb.position * item.Scale;
Vector2 worldPosition = new Vector2(item.WorldRect.X, item.WorldRect.Y) + lb.Position * item.Scale;
Vector2 diff = worldPosition - limb.WorldPosition;
limb.PullJointEnabled = true;
@@ -255,7 +310,7 @@ namespace Barotrauma.Items.Components
Lights.LightManager.ViewTarget = focusTarget;
cam.TargetPos = focusTarget.WorldPosition;
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, (focusTarget as Item).Prefab.OffsetOnSelected, deltaTime * 10.0f);
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, (focusTarget as Item).Prefab.OffsetOnSelected * focusTarget.OffsetOnSelectedMultiplier, deltaTime * 10.0f);
HideHUDs(true);
}
#endif
@@ -326,8 +381,8 @@ namespace Barotrauma.Items.Components
foreach (LimbPos lb in limbPositions)
{
Limb limb = character.AnimController.GetLimb(lb.limbType);
if (limb == null) continue;
Limb limb = character.AnimController.GetLimb(lb.LimbType);
if (limb == null) { continue; }
limb.Disabled = false;
limb.PullJointEnabled = false;
@@ -349,6 +404,12 @@ namespace Barotrauma.Items.Components
{
if (activator == null || activator.Removed) { return false; }
if (UsableIn == UseEnvironment.Water && !activator.AnimController.InWater ||
UsableIn == UseEnvironment.Air && activator.AnimController.InWater)
{
return false;
}
//someone already using the item
if (user != null && !user.Removed)
{
@@ -383,14 +444,13 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < limbPositions.Count; i++)
{
float diff = (item.Rect.X + limbPositions[i].position.X * item.Scale) - item.Rect.Center.X;
float diff = (item.Rect.X + limbPositions[i].Position.X * item.Scale) - item.Rect.Center.X;
Vector2 flippedPos =
new Vector2(
(item.Rect.Center.X - diff - item.Rect.X) / item.Scale,
limbPositions[i].position.Y);
limbPositions[i] = new LimbPos(limbPositions[i].limbType, flippedPos);
limbPositions[i].Position.Y);
limbPositions[i] = new LimbPos(limbPositions[i].LimbType, flippedPos, limbPositions[i].AllowUsingLimb);
}
}
@@ -400,14 +460,13 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < limbPositions.Count; i++)
{
float diff = (item.Rect.Y + limbPositions[i].position.Y) - item.Rect.Center.Y;
float diff = (item.Rect.Y + limbPositions[i].Position.Y) - item.Rect.Center.Y;
Vector2 flippedPos =
new Vector2(
limbPositions[i].position.X,
limbPositions[i].Position.X,
item.Rect.Center.Y - diff - item.Rect.Y);
limbPositions[i] = new LimbPos(limbPositions[i].limbType, flippedPos);
limbPositions[i] = new LimbPos(limbPositions[i].LimbType, flippedPos, limbPositions[i].AllowUsingLimb);
}
}
@@ -23,6 +23,11 @@ namespace Barotrauma.Items.Components
{
get { return outputContainer; }
}
[Editable, Serialize(1.0f, true)]
public float DeconstructionSpeed { get; set; }
public override bool RecreateGUIOnResolutionChange => true;
public Deconstructor(Item item, XElement element)
: base(item, element)
@@ -77,7 +82,7 @@ namespace Barotrauma.Items.Components
var targetItem = inputContainer.Inventory.Items.LastOrDefault(i => i != null);
if (targetItem == null) { return; }
float deconstructTime = targetItem.Prefab.DeconstructItems.Any() ? targetItem.Prefab.DeconstructTime : 1.0f;
float deconstructTime = targetItem.Prefab.DeconstructItems.Any() ? targetItem.Prefab.DeconstructTime / DeconstructionSpeed : 1.0f;
progressState = Math.Min(progressTimer / deconstructTime, 1.0f);
if (progressTimer > deconstructTime)
@@ -7,7 +7,6 @@ using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
partial class Fabricator : Powered, IServerSerializable, IClientSerializable
{
private readonly List<FabricationRecipe> fabricationRecipes = new List<FabricationRecipe>();
@@ -21,6 +20,12 @@ namespace Barotrauma.Items.Components
private Character user;
private ItemContainer inputContainer, outputContainer;
[Serialize(1.0f, true)]
public float FabricationSpeed { get; set; }
[Serialize(1.0f, true)]
public float SkillRequirementMultiplier { get; set; }
private enum FabricatorState
{
@@ -56,6 +61,8 @@ namespace Barotrauma.Items.Components
get { return outputContainer; }
}
public override bool RecreateGUIOnResolutionChange => true;
private float progressState;
public Fabricator(Item item, XElement element)
@@ -287,13 +294,27 @@ namespace Barotrauma.Items.Components
}
}
Character tempUser = user;
if (outputContainer.Inventory.Items.All(i => i != null))
{
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, item.Position, item.Submarine, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition);
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, item.Position, item.Submarine, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition,
onSpawned: (Item spawnedItem) => { onItemSpawned(spawnedItem, tempUser); });
}
else
{
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, outputContainer.Inventory, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition);
Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, outputContainer.Inventory, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition,
onSpawned: (Item spawnedItem) => { onItemSpawned(spawnedItem, tempUser); });
}
static void onItemSpawned(Item spawnedItem, Character user)
{
if (user != null && user.TeamID != Character.TeamType.None)
{
foreach (WifiComponent wifiComponent in spawnedItem.GetComponents<WifiComponent>())
{
wifiComponent.TeamID = user.TeamID;
}
}
}
if (user != null && !user.Removed)
@@ -334,13 +355,28 @@ namespace Barotrauma.Items.Components
private float GetRequiredTime(FabricationRecipe fabricableItem, Character user)
{
float degreeOfSuccess = DegreeOfSuccess(user, fabricableItem.RequiredSkills);
float degreeOfSuccess = FabricationDegreeOfSuccess(user, fabricableItem.RequiredSkills);
float t = degreeOfSuccess < 0.5f ? degreeOfSuccess * degreeOfSuccess : degreeOfSuccess * 2;
//fabricating takes 100 times longer if degree of success is close to 0
//characters with a higher skill than required can fabricate up to 100% faster
return fabricableItem.RequiredTime / MathHelper.Clamp(t, 0.01f, 2.0f);
return fabricableItem.RequiredTime / FabricationSpeed / MathHelper.Clamp(t, 0.01f, 2.0f);
}
public float FabricationDegreeOfSuccess(Character character, List<Skill> skills)
{
if (skills.Count == 0) return 1.0f;
float skillSum = (from t in skills let characterLevel = character.GetSkillLevel(t.Identifier) select (characterLevel - (t.Level * SkillRequirementMultiplier))).Sum();
float average = skillSum / skills.Count;
return ((average + 100.0f) / 2.0f) / 100.0f;
}
public override float GetSkillMultiplier()
{
return SkillRequirementMultiplier;
}
/// <summary>
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
partial class OutpostTerminal : ItemComponent
{
public OutpostTerminal(Item item, XElement element) : base(item, element)
{
InitProjSpecific(element);
}
partial void InitProjSpecific(XElement element);
}
}
@@ -34,6 +34,13 @@ namespace Barotrauma.Items.Components
set { maxFlow = value; }
}
[Editable, Serialize(false, false, alwaysUseInstanceValues: true)]
public bool IsOn
{
get { return IsActive; }
set { IsActive = value; }
}
private float currFlow;
public float CurrFlow
{
@@ -172,6 +172,8 @@ namespace Barotrauma.Items.Components
}
private float prevAvailableFuel;
[Serialize(0.0f, true)]
public float AvailableFuel { get; set; }
public Reactor(Item item, XElement element)
@@ -316,9 +318,12 @@ namespace Barotrauma.Items.Components
if (item.CurrentHull != null)
{
var aiTarget = item.CurrentHull.AiTarget;
float range = Math.Abs(currPowerConsumption) / MaxPowerOutput;
float noise = MathHelper.Lerp(aiTarget.MinSoundRange, aiTarget.MaxSoundRange, range);
aiTarget.SoundRange = Math.Max(aiTarget.SoundRange, noise);
if (aiTarget != null)
{
float range = Math.Abs(currPowerConsumption) / MaxPowerOutput;
float noise = MathHelper.Lerp(aiTarget.MinSoundRange, aiTarget.MaxSoundRange, range);
aiTarget.SoundRange = Math.Max(aiTarget.SoundRange, noise);
}
}
if (item.AiTarget != null)
@@ -447,7 +452,7 @@ namespace Barotrauma.Items.Components
}
}
private void UpdateAutoTemp(float speed, float deltaTime)
public void UpdateAutoTemp(float speed, float deltaTime)
{
float desiredTurbineOutput = (optimalTurbineOutput.X + optimalTurbineOutput.Y) / 2.0f;
targetTurbineOutput += MathHelper.Clamp(desiredTurbineOutput - targetTurbineOutput, -speed, speed) * deltaTime;
@@ -471,6 +476,19 @@ namespace Barotrauma.Items.Components
//for the actual fission rate and temperature to follow
targetFissionRate = MathHelper.Clamp(targetFissionRate, FissionRate - 5, FissionRate + 5);
}
public void PowerUpImmediately()
{
PowerOn = true;
AutoTemp = true;
prevAvailableFuel = AvailableFuel;
for (int i = 0; i < 100; i++)
{
Update((float)(Timing.Step * 10.0f), cam: null);
UpdateAutoTemp(100.0f, (float)(Timing.Step * 10.0f));
AvailableFuel = prevAvailableFuel;
}
}
public override void UpdateBroken(float deltaTime, Camera cam)
{
@@ -557,7 +575,7 @@ namespace Barotrauma.Items.Components
if (objective.SubObjectives.None())
{
int itemCount = item.ContainedItems.Count(i => i != null && container.ContainableItems.Any(ri => ri.MatchesItem(i))) + 1;
AIContainItems<Reactor>(container, character, objective, itemCount, equip: false, removeEmpty: true);
AIContainItems<Reactor>(container, character, objective, itemCount, equip: false, removeEmpty: true, spawnItemIfNotFound: character.TeamID == Character.TeamType.FriendlyNPC);
character.Speak(TextManager.Get("DialogReactorFuel"), null, 0.0f, "reactorfuel", 30.0f);
}
return false;
@@ -641,6 +659,11 @@ namespace Barotrauma.Items.Components
return false;
}
public override void OnMapLoaded()
{
prevAvailableFuel = AvailableFuel;
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power, float signalStrength = 1.0f)
{
switch (connection.Name)
@@ -130,6 +130,8 @@ namespace Barotrauma.Items.Components
}
}
public override bool RecreateGUIOnResolutionChange => true;
public Sonar(Item item, XElement element)
: base(item, element)
{
@@ -230,7 +232,7 @@ namespace Barotrauma.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
return currentPingIndex != -1;
return currentPingIndex != -1 && (character == null || characterUsable);
}
private static readonly Dictionary<string, List<Character>> targetGroups = new Dictionary<string, List<Character>>();
@@ -146,6 +146,8 @@ namespace Barotrauma.Items.Components
set { posToMaintain = value; }
}
public override bool RecreateGUIOnResolutionChange => true;
struct ObstacleDebugInfo
{
public Vector2 Point1;
@@ -330,6 +332,8 @@ namespace Barotrauma.Items.Components
private void IncreaseSkillLevel(Character user, float deltaTime)
{
if (user?.Info == null) { return; }
// Do not increase the helm skill when "steering" the sub in an outpost level
if (GameMain.GameSession?.Campaign != null && Level.IsLoadedOutpost) { return; }
float userSkill = user.GetSkillLevel("helm") / 100.0f;
user.Info.IncreaseSkillLevel(
@@ -21,9 +21,12 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (item.CurrentHull == null) return;
if (item.CurrentHull == null || item.InWater) { return; }
if (item.InWater) return;
if (oxygenFlow > 0.0f)
{
ApplyStatusEffects(ActionType.OnActive, deltaTime);
}
item.CurrentHull.Oxygen += oxygenFlow * deltaTime;
OxygenFlow -= deltaTime * 1000.0f;