Unstable v0.1100.0.4 (November 11th 2020)

This commit is contained in:
Joonas Rikkonen
2020-11-06 20:12:15 +02:00
parent 6b36bf809d
commit b772654326
297 changed files with 12502 additions and 4277 deletions
@@ -89,6 +89,16 @@ namespace Barotrauma.Items.Components
}
}
/// <summary>
/// Automatically cleared after docking -> no need to unregister
/// </summary>
public event Action OnDocked;
/// <summary>
/// Automatically cleared after undocking -> no need to unregister
/// </summary>
public event Action OnUnDocked;
public DockingPort(Item item, XElement element)
: base(item, element)
{
@@ -213,6 +223,9 @@ namespace Barotrauma.Items.Components
item.CreateServerEvent(this);
}
#endif
OnDocked?.Invoke();
OnDocked = null;
}
@@ -817,6 +830,9 @@ namespace Barotrauma.Items.Components
docked = false;
Item.Submarine.EnableObstructedWaypoints(DockingTarget.Item.Submarine);
obstructedWayPointsDisabled = false;
DockingTarget.Undock();
DockingTarget = null;
@@ -860,9 +876,6 @@ namespace Barotrauma.Items.Components
outsideBlocker?.Body.Remove(outsideBlocker);
outsideBlocker = null;
Item.Submarine.EnableObstructedWaypoints();
obstructedWayPointsDisabled = false;
#if SERVER
if (GameMain.Server != null && (!item.Submarine?.Loading ?? true))
{
@@ -870,6 +883,8 @@ namespace Barotrauma.Items.Components
item.CreateServerEvent(this);
}
#endif
OnUnDocked?.Invoke();
OnUnDocked = null;
}
public override void Update(float deltaTime, Camera cam)
@@ -1034,7 +1049,6 @@ namespace Barotrauma.Items.Components
Dock(dockingPort);
}
}
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
@@ -23,6 +23,20 @@ namespace Barotrauma.Items.Components
private readonly Sprite doorSprite, weldedSprite, brokenSprite;
private readonly bool scaleBrokenSprite, fadeBrokenSprite;
private readonly bool autoOrientGap;
private bool isJammed;
public bool IsJammed
{
get { return isJammed; }
set
{
if (isJammed == value) { return; }
isJammed = value;
#if SERVER
item.CreateServerEvent(this);
#endif
}
}
private bool isStuck;
public bool IsStuck
@@ -297,7 +311,7 @@ namespace Barotrauma.Items.Components
{
if (toggleCooldownTimer > 0.0f && user != lastUser) { OnFailedToOpen(); return; }
toggleCooldownTimer = ToggleCoolDown;
if (IsStuck) { toggleCooldownTimer = 1.0f; OnFailedToOpen(); return; }
if (IsStuck || IsJammed) { toggleCooldownTimer = 1.0f; OnFailedToOpen(); return; }
lastUser = user;
SetState(PredictedState == null ? !isOpen : !PredictedState.Value, false, true, forcedOpen: actionType == ActionType.OnPicked);
}
@@ -341,7 +355,7 @@ namespace Barotrauma.Items.Components
}
bool isClosing = false;
if (!IsStuck)
if ((!IsStuck && !IsJammed) || !isOpen)
{
if (PredictedState == null)
{
@@ -630,7 +644,7 @@ namespace Barotrauma.Items.Components
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
{
if (IsStuck) { return; }
if (IsStuck || IsJammed) { return; }
bool wasOpen = PredictedState == null ? isOpen : PredictedState.Value;
@@ -193,7 +193,7 @@ namespace Barotrauma.Items.Components
partial void DischargeProjSpecific();
private void FindNodes(Vector2 worldPosition, float range)
public void FindNodes(Vector2 worldPosition, float range)
{
//see which submarines are within range so we can skip structures that are in far-away subs
List<Submarine> submarinesInRange = new List<Submarine>();
@@ -5,6 +5,7 @@ using System.Linq;
using System.Numerics;
using System.Xml.Linq;
using Barotrauma.Extensions;
using Barotrauma.MapCreatures.Behavior;
using Barotrauma.Networking;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
@@ -138,19 +139,25 @@ namespace Barotrauma.Items.Components
public TileSide Sides = TileSide.None;
public TileSide BlockedSides = TileSide.None;
public readonly FoliageConfig FlowerConfig;
public readonly FoliageConfig LeafConfig;
public FoliageConfig FlowerConfig;
public FoliageConfig LeafConfig;
public int FailedGrowthAttempts;
public Rectangle Rect;
public Vector2 Position;
public Color HealthColor = Color.Transparent;
public float DecayDelay;
private float VineStep;
private float FlowerStep;
private readonly float diameter;
public Vector2 offset;
public VineTileType Type;
public readonly Dictionary<TileSide, Vector2> AdjacentPositions;
public static int Size = 32;
public float VineStep;
public float FlowerStep;
private float growthStep;
public float GrowthStep
{
get => growthStep;
@@ -166,17 +173,12 @@ namespace Barotrauma.Items.Components
}
}
private readonly float diameter;
private Vector2 offset;
public Color HealthColor = Color.Transparent;
public float DecayDelay;
private readonly Growable Parent;
public VineTileType Type;
private readonly Growable? Parent;
public readonly Dictionary<TileSide, Vector2> AdjacentPositions;
public static int Size = 32;
public VineTile(Growable parent, Vector2 position, VineTileType type, FoliageConfig? flowerConfig = null, FoliageConfig? leafConfig = null, Rectangle? rect = null)
public VineTile(Growable? parent, Vector2 position, VineTileType type, FoliageConfig? flowerConfig = null, FoliageConfig? leafConfig = null, Rectangle? rect = null)
{
FlowerConfig = flowerConfig ?? FoliageConfig.EmptyConfig;
LeafConfig = leafConfig ?? FoliageConfig.EmptyConfig;
@@ -197,7 +199,9 @@ namespace Barotrauma.Items.Components
public void UpdateScale(float deltaTime)
{
if (Parent.Decayed && GrowthStep > 1.0f)
bool decayed = Parent?.Decayed ?? false;
if (decayed && GrowthStep > 1.0f)
{
if (DecayDelay > 0)
{
@@ -209,7 +213,7 @@ namespace Barotrauma.Items.Components
}
}
if (GrowthStep >= 2.0f || Parent.Decayed) { return; }
if (GrowthStep >= 2.0f || decayed) { return; }
GrowthStep += deltaTime;
@@ -289,6 +293,8 @@ namespace Barotrauma.Items.Components
public bool CanGrowMore() => (Sides | BlockedSides).Count() < 4;
public bool IsSideBlocked(TileSide side) => BlockedSides.IsBitSet(side) || Sides.IsBitSet(side);
public static Rectangle CreatePlantRect(Vector2 pos) => new Rectangle((int) pos.X - Size / 2, (int) pos.Y + Size / 2, Size, Size);
}
@@ -313,6 +319,11 @@ namespace Barotrauma.Items.Components
return count;
}
public static TileSide GetOppositeSide(this TileSide side)
{
return (TileSide) (1 << ((int) Math.Log2((int) side) + 2) % 4);
}
}
internal partial class Growable : ItemComponent, IServerSerializable
@@ -705,8 +716,7 @@ namespace Barotrauma.Items.Components
// if the X value is bigger than Y it's to the left or right of us and then check if X is negative or positive to determine if it's right or left
TileSide connectingSide = absDistX > absDistY ? distX > 0 ? TileSide.Right : TileSide.Left : distY > 0 ? TileSide.Top : TileSide.Bottom;
// We use log2 to find the index and offset that index by 2 since the opposite side is always 2 offsets away
TileSide oppositeSide = (TileSide) (1 << ((int) Math.Log2((int) connectingSide) + 2) % 4);
TileSide oppositeSide = connectingSide.GetOppositeSide();
if (otherVine.BlockedSides.IsBitSet(connectingSide))
{
@@ -810,9 +820,9 @@ namespace Barotrauma.Items.Components
return element;
}
public override void Load(XElement componentElement, bool usePrefabValues)
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues);
base.Load(componentElement, usePrefabValues, idRemap);
flowerTiles = componentElement.GetAttributeIntArray("flowertiles", new int[0]);
Decayed = componentElement.GetAttributeBool("decayed", false);
@@ -195,7 +195,9 @@ namespace Barotrauma.Items.Components
}
}
}
}
}
characterUsable = element.GetAttributeBool("characterusable", true);
}
private bool OnPusherCollision(Fixture sender, Fixture other, Contact contact)
@@ -211,9 +213,9 @@ namespace Barotrauma.Items.Components
}
}
public override void Load(XElement componentElement, bool usePrefabValues)
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues);
base.Load(componentElement, usePrefabValues, idRemap);
if (usePrefabValues)
{
@@ -514,9 +516,10 @@ namespace Barotrauma.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (!attachable || item.body == null) { return character == null || character.IsKeyDown(InputType.Aim); }
if (!attachable || item.body == null) { return character == null || (character.IsKeyDown(InputType.Aim) && characterUsable); }
if (character != null)
{
if (!characterUsable && !attachable) { return false; }
if (!character.IsKeyDown(InputType.Aim)) { return false; }
if (!CanBeAttached(character)) { return false; }
@@ -0,0 +1,54 @@
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
partial class IdCard : Pickable
{
public IdCard(Item item, XElement element) : base(item, element)
{
}
public void Initialize(CharacterInfo info)
{
if (info == null) return;
if (info.Job?.Prefab != null)
{
item.AddTag("jobid:" + info.Job.Prefab.Identifier);
}
var head = info.Head;
if (info != null && head != null)
{
item.AddTag("gender:" + head.gender.ToString().ToLowerInvariant());
item.AddTag("race:" + head.race.ToString());
item.AddTag("headspriteid:" + info.HeadSpriteId.ToString());
item.AddTag("hairindex:" + head.HairIndex);
item.AddTag("beardindex:" + head.BeardIndex);
item.AddTag("moustacheindex:" + head.MoustacheIndex);
item.AddTag("faceattachmentindex:" + head.FaceAttachmentIndex);
if (head.SheetIndex != null)
{
item.AddTag("sheetindex:" + head.SheetIndex.Value.X + ";" + head.SheetIndex.Value.Y);
}
}
}
public override void Equip(Character character)
{
base.Equip(character);
character.Info.CheckDisguiseStatus(true, this);
}
public override void Unequip(Character character)
{
base.Unequip(character);
character.Info.CheckDisguiseStatus(true, this);
}
}
}
@@ -33,6 +33,9 @@ namespace Barotrauma.Items.Components
{
return;
}
if (holdable == null) { return; }
deattachTimer = Math.Max(0.0f, value);
#if SERVER
if (deattachTimer >= DeattachDuration)
@@ -57,7 +60,7 @@ namespace Barotrauma.Items.Components
public bool Attached
{
get { return holdable == null ? false : holdable.Attached; }
get { return holdable != null && holdable.Attached; }
}
public LevelResource(Item item, XElement element) : base(item, element)
@@ -67,7 +70,7 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (!holdable.Attached)
if (holdable != null && !holdable.Attached)
{
trigger.Enabled = false;
IsActive = false;
@@ -87,7 +90,6 @@ namespace Barotrauma.Items.Components
holdable = item.GetComponent<Holdable>();
if (holdable == null)
{
DebugConsole.ThrowError("Error while initializing item \"" + item.Name + "\". Level resources require a Holdable component.");
IsActive = false;
return;
}
@@ -5,6 +5,7 @@ using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
@@ -128,54 +129,19 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < ProjectileCount; i++)
{
Projectile projectile = FindProjectile(triggerOnUseOnContainers: true);
if (projectile == null) { return true; }
float spread = GetSpread(character);
float rotation = (item.body.Dir == 1.0f) ? item.body.Rotation : item.body.Rotation - MathHelper.Pi;
rotation += spread * Rand.Range(-0.5f, 0.5f);
projectile.User = character;
//add the limbs of the shooter to the list of bodies to be ignored
//so that the player can't shoot himself
projectile.IgnoredBodies = new List<Body>(limbBodies);
Vector2 projectilePos = item.SimPosition;
Vector2 sourcePos = character?.AnimController == null ? item.SimPosition : character.AnimController.AimSourceSimPos;
Vector2 barrelPos = TransformedBarrelPos + item.body.SimPosition;
//make sure there's no obstacles between the base of the weapon (or the shoulder of the character) and the end of the barrel
if (Submarine.PickBody(sourcePos, barrelPos, projectile.IgnoredBodies, Physics.CollisionWall | Physics.CollisionLevel | Physics.CollisionItemBlocking) == null)
if (projectile != null)
{
//no obstacles -> we can spawn the projectile at the barrel
projectilePos = barrelPos;
}
else if ((sourcePos - barrelPos).LengthSquared() > 0.0001f)
{
//spawn the projectile body.GetMaxExtent() away from the position where the raycast hit the obstacle
projectilePos = sourcePos - Vector2.Normalize(barrelPos - projectilePos) * Math.Max(projectile.Item.body.GetMaxExtent(), 0.1f);
}
projectile.Item.body.ResetDynamics();
projectile.Item.SetTransform(projectilePos, rotation);
projectile.Use(deltaTime);
projectile.Item.GetComponent<Rope>()?.Attach(item, projectile.Item);
if (projectile.Item.Removed) { continue; }
projectile.User = character;
projectile.Item.body.ApplyTorque(projectile.Item.body.Mass * degreeOfFailure * Rand.Range(-10.0f, 10.0f));
//set the rotation of the projectile again because dropping the projectile resets the rotation
projectile.Item.SetTransform(projectilePos,
rotation + (projectile.Item.body.Dir * projectile.LaunchRotationRadians));
item.RemoveContained(projectile.Item);
if (i == 0)
{
//recoil
item.body.ApplyLinearImpulse(
new Vector2((float)Math.Cos(projectile.Item.body.Rotation), (float)Math.Sin(projectile.Item.body.Rotation)) * item.body.Mass * -50.0f,
maxVelocity: NetConfig.MaxPhysicsBodyVelocity);
Vector2 barrelPos = TransformedBarrelPos + item.body.SimPosition;
float rotation = (Item.body.Dir == 1.0f) ? Item.body.Rotation : Item.body.Rotation - MathHelper.Pi;
float spread = GetSpread(character) * Rand.Range(-0.5f, 0.5f);
projectile.Shoot(character, character.AnimController.AimSourceSimPos, barrelPos, rotation + spread, ignoredBodies: limbBodies.ToList(), createNetworkEvent: false);
projectile.Item.GetComponent<Rope>()?.Attach(Item, projectile.Item);
if (i == 0)
{
Item.body.ApplyLinearImpulse(new Vector2((float)Math.Cos(projectile.Item.body.Rotation), (float)Math.Sin(projectile.Item.body.Rotation)) * Item.body.Mass * -50.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity);
}
projectile.Item.body.ApplyTorque(projectile.Item.body.Mass * degreeOfFailure * Rand.Range(-10.0f, 10.0f));
Item.RemoveContained(projectile.Item);
}
}
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Extensions;
using Barotrauma.MapCreatures.Behavior;
namespace Barotrauma.Items.Components
{
@@ -53,6 +54,18 @@ namespace Barotrauma.Items.Components
get; set;
}
[Serialize(0.0f, false, description: "How much damage is applied to ballast flora.")]
public float FireDamage
{
get; set;
}
[Serialize(0.0f, false, description: "How many units of damage the item removes from destructible level walls per second.")]
public float LevelWallFixAmount
{
get; set;
}
[Serialize(0.0f, false, description: "How much the item decreases the size of fires per second.")]
public float ExtinguishAmount
{
@@ -183,23 +196,40 @@ namespace Barotrauma.Items.Components
}
Vector2 rayStart;
Vector2 rayStartWorld;
Vector2 sourcePos = character?.AnimController == null ? item.SimPosition : character.AnimController.AimSourceSimPos;
Vector2 barrelPos = item.SimPosition + ConvertUnits.ToSimUnits(TransformedBarrelPos);
//make sure there's no obstacles between the base of the item (or the shoulder of the character) and the end of the barrel
if (Submarine.PickBody(sourcePos, barrelPos, collisionCategory: Physics.CollisionWall | Physics.CollisionLevel | Physics.CollisionItemBlocking) == null)
{
//no obstacles -> we start the raycast at the end of the barrel
rayStart = ConvertUnits.ToSimUnits(item.WorldPosition + TransformedBarrelPos);
rayStart = ConvertUnits.ToSimUnits(item.Position + TransformedBarrelPos);
rayStartWorld = ConvertUnits.ToSimUnits(item.WorldPosition + TransformedBarrelPos);
}
else
{
rayStart = Submarine.LastPickedPosition + Submarine.LastPickedNormal * 0.1f;
if (item.Submarine != null) { rayStart += item.Submarine.SimPosition; }
rayStart = rayStartWorld = Submarine.LastPickedPosition + Submarine.LastPickedNormal * 0.1f;
if (item.Submarine != null) { rayStartWorld += item.Submarine.SimPosition; }
}
//if the calculated barrel pos is in another hull, use the origin of the item to make sure the particles don't end up in an incorrect hull
if (item.CurrentHull != null)
{
var barrelHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(rayStartWorld), item.CurrentHull, useWorldCoordinates: true);
if (barrelHull != null && barrelHull != item.CurrentHull)
{
if (MathUtils.GetLineRectangleIntersection(ConvertUnits.ToDisplayUnits(sourcePos), ConvertUnits.ToDisplayUnits(rayStart), item.CurrentHull.Rect, out Vector2 hullIntersection))
{
Vector2 rayDir = rayStart.NearlyEquals(sourcePos) ? Vector2.Zero : Vector2.Normalize(rayStart - sourcePos);
rayStartWorld = ConvertUnits.ToSimUnits(hullIntersection - rayDir * 5.0f);
if (item.Submarine != null) { rayStartWorld += item.Submarine.SimPosition; }
}
}
}
float spread = MathHelper.ToRadians(MathHelper.Lerp(UnskilledSpread, Spread, degreeOfSuccess));
float angle = item.body.Rotation + MathHelper.ToRadians(BarrelRotation) + spread * Rand.Range(-0.5f, 0.5f);
Vector2 rayEnd = rayStart +
Vector2 rayEnd = rayStartWorld +
ConvertUnits.ToSimUnits(new Vector2(
(float)Math.Cos(angle),
(float)Math.Sin(angle)) * Range * item.body.Dir);
@@ -218,7 +248,7 @@ namespace Barotrauma.Items.Components
IsActive = true;
activeTimer = 0.1f;
debugRayStartPos = ConvertUnits.ToDisplayUnits(rayStart);
debugRayStartPos = ConvertUnits.ToDisplayUnits(rayStartWorld);
debugRayEndPos = ConvertUnits.ToDisplayUnits(rayEnd);
Submarine parentSub = character?.Submarine ?? item.Submarine;
@@ -232,16 +262,16 @@ namespace Barotrauma.Items.Components
{
continue;
}
Repair(rayStart - sub.SimPosition, rayEnd - sub.SimPosition, deltaTime, character, degreeOfSuccess, ignoredBodies);
Repair(rayStartWorld - sub.SimPosition, rayEnd - sub.SimPosition, deltaTime, character, degreeOfSuccess, ignoredBodies);
}
Repair(rayStart, rayEnd, deltaTime, character, degreeOfSuccess, ignoredBodies);
Repair(rayStartWorld, rayEnd, deltaTime, character, degreeOfSuccess, ignoredBodies);
}
else
{
Repair(rayStart - parentSub.SimPosition, rayEnd - parentSub.SimPosition, deltaTime, character, degreeOfSuccess, ignoredBodies);
Repair(rayStartWorld - parentSub.SimPosition, rayEnd - parentSub.SimPosition, deltaTime, character, degreeOfSuccess, ignoredBodies);
}
UseProjSpecific(deltaTime, rayStart);
UseProjSpecific(deltaTime, rayStartWorld);
return true;
}
@@ -289,6 +319,7 @@ namespace Barotrauma.Items.Components
{
if (RepairThroughHoles && f.IsSensor && f.Body?.UserData is Structure || (f.Body?.UserData is Item it && it.GetComponent<Planter>() != null)) { return false; }
if (f.Body?.UserData as string == "ruinroom") { return false; }
if (f.Body?.UserData is VineTile && !(FireDamage > 0)) { return false; }
return true;
},
allowInsideFixture: true);
@@ -324,9 +355,16 @@ namespace Barotrauma.Items.Components
hitCharacters.Add(hitCharacter);
}
//if repairing through walls is not allowed and the next wall is more than 100 pixels away from the previous one, stop here
//(= repairing multiple overlapping walls is allowed as long as the edges of the walls are less than 100 pixels apart)
float thisBodyFraction = Submarine.LastPickedBodyDist(body);
if (!RepairThroughWalls && lastHitType == typeof(Structure) && Range * (thisBodyFraction - lastPickedFraction) > 100.0f)
{
break;
}
if (FixBody(user, deltaTime, degreeOfSuccess, body))
{
lastPickedFraction = Submarine.LastPickedBodyDist(body);
lastPickedFraction = thisBodyFraction;
if (bodyType != null) { lastHitType = bodyType; }
}
}
@@ -341,6 +379,8 @@ namespace Barotrauma.Items.Components
{
if (RepairThroughHoles && f.IsSensor && f.Body?.UserData is Structure) { return false; }
if (f.Body?.UserData as string == "ruinroom") { return false; }
if (f.Body?.UserData is VineTile && !(FireDamage > 0)) { return false; }
if (f.Body?.UserData is Item targetItem)
{
if (!HitItems) { return false; }
@@ -479,6 +519,15 @@ namespace Barotrauma.Items.Components
}
return true;
}
else if (targetBody.UserData is Voronoi2.VoronoiCell cell)
{
var levelWall = Level.Loaded?.ExtraWalls.Find(w => w.Body == cell.Body) as DestructibleLevelWall;
if (levelWall != null)
{
levelWall.AddDamage(-LevelWallFixAmount * deltaTime, item.WorldPosition);
}
return true;
}
else if (targetBody.UserData is Character targetCharacter)
{
if (targetCharacter.Removed) { return false; }
@@ -569,6 +618,13 @@ namespace Barotrauma.Items.Components
FixItemProjSpecific(user, deltaTime, targetItem);
return true;
}
else if (targetBody.UserData is BallastFloraBranch branch)
{
if (branch.ParentBallastFlora is { } ballastFlora)
{
ballastFlora.DamageBranch(branch, FireDamage * deltaTime, BallastFloraBehavior.AttackType.Fire, user);
}
}
return false;
}
@@ -769,7 +825,8 @@ namespace Barotrauma.Items.Components
object value = property.GetValue(target);
if (door.Stuck > 0)
{
var progressBar = user.UpdateHUDProgressBar(door, door.Item.WorldPosition, door.Stuck / 100, Color.DarkGray * 0.5f, Color.White, "progressbar.welding");
var progressBar = user.UpdateHUDProgressBar(door, door.Item.WorldPosition, door.Stuck / 100, Color.DarkGray * 0.5f, Color.White,
effect.propertyEffects[i].GetType() == typeof(float) && (float)effect.propertyEffects[i] < 0 ? "progressbar.cutting" : "progressbar.welding");
if (progressBar != null) { progressBar.Size = new Vector2(60.0f, 20.0f); }
}
}
@@ -63,14 +63,14 @@ namespace Barotrauma.Items.Components
if (item.body.LinearVelocity.LengthSquared() < 0.01f)
{
CurrentThrower = null;
if (statusEffectLists.ContainsKey(ActionType.OnImpact))
if (statusEffectLists?.ContainsKey(ActionType.OnImpact) ?? false)
{
foreach (var statusEffect in statusEffectLists[ActionType.OnImpact])
{
statusEffect.SetUser(null);
}
}
if (statusEffectLists.ContainsKey(ActionType.OnBroken))
if (statusEffectLists?.ContainsKey(ActionType.OnBroken) ?? false)
{
foreach (var statusEffect in statusEffectLists[ActionType.OnBroken])
{
@@ -135,14 +135,14 @@ namespace Barotrauma.Items.Components
GameServer.Log(GameServer.CharacterLogName(picker) + " threw " + item.Name, ServerLog.MessageType.ItemInteraction);
#endif
CurrentThrower = picker;
if (statusEffectLists.ContainsKey(ActionType.OnImpact))
if (statusEffectLists?.ContainsKey(ActionType.OnImpact) ?? false)
{
foreach (var statusEffect in statusEffectLists[ActionType.OnImpact])
{
statusEffect.SetUser(CurrentThrower);
}
}
if (statusEffectLists.ContainsKey(ActionType.OnBroken))
if (statusEffectLists?.ContainsKey(ActionType.OnBroken) ?? false)
{
foreach (var statusEffect in statusEffectLists[ActionType.OnBroken])
{
@@ -763,7 +763,7 @@ namespace Barotrauma.Items.Components
}
}
public virtual void Load(XElement componentElement, bool usePrefabValues)
public virtual void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
if (componentElement != null)
{
@@ -1011,6 +1011,7 @@ namespace Barotrauma.Items.Components
if (FindSuitableContainer(character,
i =>
{
if (i.IsThisOrAnyContainerIgnoredByAI()) { return 0; }
var container = i.GetComponent<ItemContainer>();
if (container == null) { return 0; }
if (container.Inventory.IsFull()) { return 0; }
@@ -415,17 +415,17 @@ namespace Barotrauma.Items.Components
}
}
public override void Load(XElement componentElement, bool usePrefabValues)
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues);
base.Load(componentElement, usePrefabValues, idRemap);
string containedString = componentElement.GetAttributeString("contained", "");
string[] itemIdStrings = containedString.Split(',');
itemIds = new ushort[itemIdStrings.Length];
for (int i = 0; i < itemIdStrings.Length; i++)
{
if (!ushort.TryParse(itemIdStrings[i], out ushort id)) { continue; }
itemIds[i] = id;
if (!int.TryParse(itemIdStrings[i], out int id)) { continue; }
itemIds[i] = idRemap.GetOffsetId(id);
}
}
@@ -318,16 +318,12 @@ namespace Barotrauma.Items.Components
if (!character.IsRemotePlayer || character.ViewTarget == focusTarget)
{
Vector2 centerPos = new Vector2(item.WorldRect.Center.X, item.WorldRect.Center.Y);
Vector2 centerPos = new Vector2(focusTarget.WorldRect.Center.X, focusTarget.WorldRect.Center.Y);
Item targetItem = focusTarget as Item;
if (targetItem != null)
Turret turret = focusTarget.GetComponent<Turret>();
if (turret != null)
{
Turret turret = targetItem.GetComponent<Turret>();
if (turret != null)
{
centerPos = new Vector2(targetItem.WorldRect.X + turret.TransformedBarrelPos.X, targetItem.WorldRect.Y - turret.TransformedBarrelPos.Y);
}
centerPos = new Vector2(focusTarget.WorldRect.X + turret.TransformedBarrelPos.X, focusTarget.WorldRect.Y - turret.TransformedBarrelPos.Y);
}
Vector2 offset = character.CursorWorldPosition - centerPos;
@@ -356,6 +352,9 @@ namespace Barotrauma.Items.Components
public override bool Pick(Character picker)
{
#if CLIENT
if (Screen.Selected == GameMain.SubEditorScreen) { return false; }
#endif
if (IsToggle)
{
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
@@ -113,7 +113,7 @@ namespace Barotrauma.Items.Components
forceMultiplier *= MathHelper.Lerp(0.5f, 2.0f, (float)Math.Sqrt(User.GetSkillLevel("helm") / 100));
}
float voltageFactor = MinVoltage <= 0.0f ? 1.0f : Math.Min(Voltage / MinVoltage, 1.0f);
float voltageFactor = MinVoltage <= 0.0f ? 1.0f : Math.Min(Voltage, 1.0f);
Vector2 currForce = new Vector2(force * maxForce * forceMultiplier * voltageFactor, 0.0f);
//less effective when in a bad condition
currForce *= MathHelper.Lerp(0.5f, 2.0f, item.Condition / item.MaxCondition);
@@ -121,7 +121,7 @@ namespace Barotrauma.Items.Components
UpdatePropellerDamage(deltaTime);
float maxChangeSpeed = 0.5f;
float modifier = 2;
float noise = currForce.Length() * forceMultiplier * modifier / maxForce;
float noise = MathUtils.NearlyEqual(0.0f, maxForce) ? 0.0f : currForce.Length() * forceMultiplier * modifier / maxForce;
float min = Math.Max(1 - maxChangeSpeed, 0);
float max = 1 + maxChangeSpeed;
UpdateAITargets(Math.Clamp(noise, min, max), deltaTime);
@@ -482,9 +482,9 @@ namespace Barotrauma.Items.Components
return componentElement;
}
public override void Load(XElement componentElement, bool usePrefabValues)
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues);
base.Load(componentElement, usePrefabValues, idRemap);
savedFabricatedItem = componentElement.GetAttributeString("fabricateditemidentifier", "");
savedTimeUntilReady = componentElement.GetAttributeFloat("savedtimeuntilready", 0.0f);
savedRequiredTime = componentElement.GetAttributeFloat("savedrequiredtime", 0.0f);
@@ -8,11 +8,10 @@ namespace Barotrauma.Items.Components
{
class OxygenGenerator : Powered
{
private float powerDownTimer;
private float generatedAmount;
private List<Vent> ventList;
//key = vent, float = total volume of the hull the vent is in and the hulls connected to it
private Dictionary<Vent, float> ventList;
private float totalHullVolume;
@@ -49,17 +48,12 @@ namespace Barotrauma.Items.Components
Voltage = 1.0f;
}
if (item.CurrentHull == null) return;
if (item.CurrentHull == null) { return; }
if (Voltage < MinVoltage)
{
powerDownTimer += deltaTime;
return;
}
else
{
powerDownTimer = 0.0f;
}
CurrFlow = Math.Min(Voltage, 1.0f) * generatedAmount * 100.0f;
@@ -76,24 +70,25 @@ namespace Barotrauma.Items.Components
public override void UpdateBroken(float deltaTime, Camera cam)
{
base.UpdateBroken(deltaTime, cam);
powerDownTimer += deltaTime;
CurrFlow = 0.0f;
}
private void GetVents()
{
ventList.Clear();
ventList = new Dictionary<Vent, float>();
foreach (MapEntity entity in item.linkedTo)
{
Item linkedItem = entity as Item;
if (linkedItem == null) continue;
if (!(entity is Item linkedItem)) { continue; }
Vent vent = linkedItem.GetComponent<Vent>();
if (vent == null) continue;
if (vent?.Item.CurrentHull == null) { continue; }
ventList.Add(vent);
if (linkedItem.CurrentHull != null) totalHullVolume += linkedItem.CurrentHull.Volume;
ventList.Add(vent, 0.0f);
foreach (Hull connectedHull in vent.Item.CurrentHull.GetConnectedHulls(includingThis: true, searchDepth: 10, ignoreClosedGaps: true))
{
totalHullVolume += connectedHull.Volume;
ventList[vent] += connectedHull.Volume;
}
}
}
@@ -101,18 +96,17 @@ namespace Barotrauma.Items.Components
{
if (ventList == null)
{
ventList = new List<Vent>();
GetVents();
}
if (!ventList.Any() || totalHullVolume <= 0.0f) return;
if (!ventList.Any() || totalHullVolume <= 0.0f) { return; }
foreach (Vent v in ventList)
foreach (KeyValuePair<Vent, float> v in ventList)
{
if (v.Item.CurrentHull == null) continue;
if (v.Key?.Item.CurrentHull == null) { continue; }
v.OxygenFlow = deltaOxygen * (v.Item.CurrentHull.Volume / totalHullVolume);
v.IsActive = true;
v.Key.OxygenFlow = deltaOxygen * (v.Value / totalHullVolume);
v.Key.IsActive = true;
}
}
}
@@ -2,7 +2,9 @@
using Microsoft.Xna.Framework;
using System;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.MapCreatures.Behavior;
namespace Barotrauma.Items.Components
{
@@ -11,10 +13,38 @@ namespace Barotrauma.Items.Components
private float flowPercentage;
private float maxFlow;
private float? targetLevel;
public float? TargetLevel;
private bool hijacked;
public bool Hijacked
{
get { return hijacked; }
set
{
if (value == hijacked) { return; }
hijacked = value;
#if SERVER
item.CreateServerEvent(this);
#endif
}
}
private float pumpSpeedLockTimer, isActiveLockTimer;
private bool infected;
[Serialize(false, true, description: "Whether or not the pump is infected with ballast flora spores.")]
public bool Infected
{
get => infected;
set
{
infected = value;
}
}
public string InfectIdentifier;
[Serialize(0.0f, true, description: "How fast the item is currently pumping water (-100 = full speed out, 100 = full speed in). Intended to be used by StatusEffect conditionals (setting this value in XML has no effect).")]
public float FlowPercentage
{
@@ -66,12 +96,12 @@ namespace Barotrauma.Items.Components
{
currFlow = 0.0f;
if (targetLevel != null)
if (TargetLevel != null)
{
pumpSpeedLockTimer -= deltaTime;
float hullPercentage = 0.0f;
if (item.CurrentHull != null) { hullPercentage = (item.CurrentHull.WaterVolume / item.CurrentHull.Volume) * 100.0f; }
FlowPercentage = ((float)targetLevel - hullPercentage) * 10.0f;
FlowPercentage = ((float)TargetLevel - hullPercentage) * 10.0f;
}
currPowerConsumption = powerConsumption * Math.Abs(flowPercentage / 100.0f);
@@ -92,14 +122,41 @@ namespace Barotrauma.Items.Components
//less effective when in a bad condition
currFlow *= MathHelper.Lerp(0.5f, 1.0f, item.Condition / item.MaxCondition);
if (currFlow < 0 && Infected)
{
InfectBallast(InfectIdentifier);
}
Infected = false;
item.CurrentHull.WaterVolume += currFlow;
if (item.CurrentHull.WaterVolume > item.CurrentHull.Volume) { item.CurrentHull.Pressure += 0.5f; }
}
public void InfectBallast(string identifier)
{
Hull hull = item.CurrentHull;
if (hull == null) { return; }
// if the ship is already infected then do nothing
if (Hull.hullList.Where(h => h.Submarine == hull.Submarine).Any(h => h.BallastFlora != null)) { return; }
if (hull.BallastFlora != null) { return; }
Vector2 offset = item.WorldPosition - hull.WorldPosition;
hull.BallastFlora = new BallastFloraBehavior(hull, BallastFloraPrefab.Find(identifier), offset, firstGrowth: true);
#if SERVER
hull.BallastFlora.SendNetworkMessage(hull.BallastFlora, BallastFloraBehavior.NetworkHeader.Spawn);
#endif
}
partial void UpdateProjSpecific(float deltaTime);
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
{
if (Hijacked) { return; }
if (connection.Name == "toggle")
{
IsActive = !IsActive;
@@ -115,7 +172,7 @@ namespace Barotrauma.Items.Components
if (float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out float tempSpeed))
{
flowPercentage = MathHelper.Clamp(tempSpeed, -100.0f, 100.0f);
targetLevel = null;
TargetLevel = null;
pumpSpeedLockTimer = 0.1f;
}
}
@@ -123,7 +180,7 @@ namespace Barotrauma.Items.Components
{
if (float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out float tempTarget))
{
targetLevel = MathHelper.Clamp(tempTarget + 50.0f, 0.0f, 100.0f);
TargetLevel = MathHelper.Clamp(tempTarget + 50.0f, 0.0f, 100.0f);
pumpSpeedLockTimer = 0.1f;
}
}
@@ -64,6 +64,7 @@ namespace Barotrauma.Items.Components
private bool useDirectionalPing = false;
private Vector2 pingDirection = new Vector2(1.0f, 0.0f);
private bool useMineralScanner;
private bool aiPingCheckPending;
@@ -103,6 +104,9 @@ namespace Barotrauma.Items.Components
set;
}
[Editable, Serialize(false, false, description: "Does the sonar have mineral scanning mode?")]
public bool HasMineralScanner { get; set; }
public float Zoom
{
get { return zoom; }
@@ -343,6 +347,7 @@ namespace Barotrauma.Items.Components
bool isActive = msg.ReadBoolean();
bool directionalPing = useDirectionalPing;
float zoomT = zoom, pingDirectionT = 0.0f;
bool mineralScanner = useMineralScanner;
if (isActive)
{
zoomT = msg.ReadRangedSingle(0.0f, 1.0f, 8);
@@ -351,6 +356,7 @@ namespace Barotrauma.Items.Components
{
pingDirectionT = msg.ReadRangedSingle(0.0f, 1.0f, 8);
}
mineralScanner = msg.ReadBoolean();
}
if (!item.CanClientAccess(c)) { return; }
@@ -366,9 +372,14 @@ namespace Barotrauma.Items.Components
float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, pingDirectionT);
pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle));
}
useMineralScanner = mineralScanner;
#if CLIENT
zoomSlider.BarScroll = zoomT;
directionalModeSwitch.Selected = useDirectionalPing;
if (mineralScannerSwitch != null)
{
mineralScannerSwitch.Selected = useMineralScanner;
}
#endif
}
#if SERVER
@@ -388,6 +399,7 @@ namespace Barotrauma.Items.Components
float pingAngle = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(pingDirection));
msg.WriteRangedSingle(MathUtils.InverseLerp(0.0f, MathHelper.TwoPi, pingAngle), 0.0f, 1.0f, 8);
}
msg.Write(useMineralScanner);
}
}
}
@@ -417,6 +417,7 @@ namespace Barotrauma.Items.Components
Math.Max(1000.0f * Math.Abs(controlledSub.Velocity.Y), controlledSub.Borders.Height * 0.75f));
float avoidRadius = avoidDist.Length();
float damagingWallAvoidRadius = avoidRadius * 1.5f;
Vector2 newAvoidStrength = Vector2.Zero;
@@ -426,12 +427,26 @@ namespace Barotrauma.Items.Components
var closeCells = Level.Loaded.GetCells(controlledSub.WorldPosition, 4);
foreach (VoronoiCell cell in closeCells)
{
if (Level.Loaded?.ExtraWalls.Any(w => w.WallDamageOnTouch > 0.0f && w.Cells.Contains(cell)) ?? false)
{
foreach (GraphEdge edge in cell.Edges)
{
Vector2 closestPoint = MathUtils.GetClosestPointOnLineSegment(edge.Point1 + cell.Translation, edge.Point2 + cell.Translation, controlledSub.WorldPosition);
float dist = Vector2.Distance(closestPoint, controlledSub.WorldPosition);
if (dist > damagingWallAvoidRadius) { continue; }
Vector2 diff = controlledSub.WorldPosition - cell.Center;
Vector2 avoid = Vector2.Normalize(diff) * (damagingWallAvoidRadius - dist) / damagingWallAvoidRadius;
newAvoidStrength += avoid;
debugDrawObstacles.Add(new ObstacleDebugInfo(edge, edge.Center, 1.0f, avoid, cell.Translation));
}
continue;
}
foreach (GraphEdge edge in cell.Edges)
{
if (MathUtils.GetLineIntersection(edge.Point1 + cell.Translation, edge.Point2 + cell.Translation, controlledSub.WorldPosition, cell.Center, out Vector2 intersection))
{
Vector2 diff = controlledSub.WorldPosition - intersection;
//far enough -> ignore
if (Math.Abs(diff.X) > avoidDist.X && Math.Abs(diff.Y) > avoidDist.Y)
{
@@ -13,11 +13,7 @@ namespace Barotrauma.Items.Components
set { oxygenFlow = Math.Max(value, 0.0f); }
}
public Vent (Item item, XElement element)
: base(item, element)
{
}
public Vent (Item item, XElement element) : base(item, element) { }
public override void Update(float deltaTime, Camera cam)
{
@@ -1,8 +1,4 @@
using Barotrauma.Networking;
using System.Xml.Linq;
#if CLIENT
using Microsoft.Xna.Framework.Graphics;
#endif
namespace Barotrauma.Items.Components
{
@@ -55,6 +55,22 @@ namespace Barotrauma.Items.Components
set;
}
private float extraLoad;
private float extraLoadSetTime;
/// <summary>
/// Additional load coming from somewhere else than the devices connected to the junction box (e.g. ballast flora or piezo crystals).
/// Goes back to zero automatically if you stop setting the value.
/// </summary>
public float ExtraLoad
{
get { return extraLoad; }
set
{
extraLoad = Math.Max(value, 0.0f);
extraLoadSetTime = (float)Timing.TotalTime;
}
}
//can the component transfer power
private bool canTransfer;
public bool CanTransfer
@@ -135,6 +151,11 @@ namespace Barotrauma.Items.Components
{
RefreshConnections();
if (Timing.TotalTime > extraLoadSetTime + 1.0)
{
extraLoad = Math.Max(extraLoad - 1000.0f * deltaTime, 0);
}
if (!CanTransfer) { return; }
if (isBroken)
@@ -231,8 +231,16 @@ namespace Barotrauma.Items.Components
//and send out a "probe signal" which the PowerTransfer components use to add up the grid power/load
foreach (Powered powered in poweredList)
{
if (powered is PowerTransfer) { continue; }
if (powered.currPowerConsumption > 0.0f)
if (powered is PowerTransfer pt)
{
if (pt.ExtraLoad > 0.0f)
{
lastPowerProbeRecipients.Clear();
powered.powerIn?.SendPowerProbeSignal(powered.item, -pt.ExtraLoad);
}
continue;
}
else if (powered.currPowerConsumption > 0.0f)
{
//consuming power
lastPowerProbeRecipients.Clear();
@@ -60,14 +60,14 @@ namespace Barotrauma.Items.Components
public List<Body> IgnoredBodies;
private Character user;
private Character _user;
public Character User
{
get { return user; }
get { return _user; }
set
{
user = value;
Attack?.SetUser(user);
_user = value;
Attack?.SetUser(_user);
}
}
@@ -211,7 +211,51 @@ namespace Barotrauma.Items.Components
}
}
public override bool Use(float deltaTime, Character character = null)
private void Launch(Character user, Vector2 simPosition, float rotation)
{
//User = user;
Item.body.ResetDynamics();
Item.SetTransform(simPosition, rotation);
Use();
if (Item.Removed) { return; }
User = user;
launchPos = simPosition;
//set the rotation of the projectile again because dropping the projectile resets the rotation
Item.SetTransform(simPosition, rotation + (Item.body.Dir * LaunchRotationRadians));
}
public void Shoot(Character user, Vector2 weaponPos, Vector2 spawnPos, float rotation, List<Body> ignoredBodies, bool createNetworkEvent)
{
//add the limbs of the shooter to the list of bodies to be ignored
//so that the player can't shoot himself
IgnoredBodies = ignoredBodies;
Vector2 projectilePos = weaponPos;
//make sure there's no obstacles between the base of the weapon (or the shoulder of the character) and the end of the barrel
if (Submarine.PickBody(weaponPos, spawnPos, IgnoredBodies, Physics.CollisionWall | Physics.CollisionLevel | Physics.CollisionItemBlocking) == null)
{
//no obstacles -> we can spawn the projectile at the barrel
projectilePos = spawnPos;
}
else if ((weaponPos - spawnPos).LengthSquared() > 0.0001f)
{
//spawn the projectile body.GetMaxExtent() away from the position where the raycast hit the obstacle
Vector2 newPos = weaponPos - Vector2.Normalize(spawnPos - projectilePos) * Math.Max(Item.body.GetMaxExtent(), 0.1f);
if (MathUtils.IsValid(newPos))
{
projectilePos = newPos;
}
}
Launch(user, projectilePos, rotation);
if (createNetworkEvent && !Item.Removed && GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
#if SERVER
launchRot = rotation;
Item.CreateServerEvent(this, new object[] { true }); //true = indicate that this is a launch event
#endif
}
}
public bool Use(Character character = null)
{
if (character != null && !characterUsable) { return false; }
@@ -230,16 +274,16 @@ namespace Barotrauma.Items.Components
}
else
{
Launch(launchDir * LaunchImpulse * item.body.Mass);
DoLaunch(launchDir * LaunchImpulse * item.body.Mass);
}
}
User = character;
return true;
}
private void Launch(Vector2 impulse)
public override bool Use(float deltaTime, Character character = null) => Use(character);
private void DoLaunch(Vector2 impulse)
{
hits.Clear();
@@ -360,6 +404,7 @@ namespace Barotrauma.Items.Components
{
//ignore sensors and items
if (fixture?.Body == null || fixture.IsSensor) { return true; }
if (fixture.Body.UserData is VineTile) { return true; }
if (fixture.Body.UserData is Item item && (item.GetComponent<Door>() == null && !item.Prefab.DamagedByProjectiles || item.Condition <= 0)) { return true; }
if (fixture.Body?.UserData as string == "ruinroom") { return true; }
@@ -381,6 +426,7 @@ namespace Barotrauma.Items.Components
{
//ignore sensors and items
if (fixture?.Body == null || fixture.IsSensor) { return -1; }
if (fixture.Body.UserData is VineTile) { return -1; }
if (fixture.Body.UserData is Item item && (item.GetComponent<Door>() == null && !item.Prefab.DamagedByProjectiles || item.Condition <= 0)) { return -1; }
if (fixture.Body?.UserData as string == "ruinroom") { return -1; }
@@ -577,20 +623,27 @@ namespace Barotrauma.Items.Components
{
if (Attack != null) { attackResult = Attack.DoDamage(User, damageable, item.WorldPosition, 1.0f); }
}
else if (target.Body.UserData is VoronoiCell voronoiCell && Attack != null && Math.Abs(Attack.StructureDamage) > 0.0f)
{
if (Level.Loaded?.ExtraWalls.Find(w => w.Body == target.Body) is DestructibleLevelWall destructibleWall)
{
attackResult = Attack.DoDamage(User, destructibleWall, item.WorldPosition, 1.0f);
}
}
if (character != null) { character.LastDamageSource = item; }
#if CLIENT
PlaySound(ActionType.OnUse, user: user);
PlaySound(ActionType.OnImpact, user: user);
PlaySound(ActionType.OnUse, user: _user);
PlaySound(ActionType.OnImpact, user: _user);
#endif
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
{
if (target.Body.UserData is Limb targetLimb)
{
ApplyStatusEffects(ActionType.OnUse, 1.0f, character, targetLimb, user: user);
ApplyStatusEffects(ActionType.OnImpact, 1.0f, character, targetLimb, user: user);
ApplyStatusEffects(ActionType.OnUse, 1.0f, character, targetLimb, user: _user);
ApplyStatusEffects(ActionType.OnImpact, 1.0f, character, targetLimb, user: _user);
var attack = targetLimb.attack;
if (attack != null)
{
@@ -626,8 +679,8 @@ namespace Barotrauma.Items.Components
}
else
{
ApplyStatusEffects(ActionType.OnUse, 1.0f, useTarget: target.Body.UserData as Entity, user: user);
ApplyStatusEffects(ActionType.OnImpact, 1.0f, useTarget: target.Body.UserData as Entity, user: user);
ApplyStatusEffects(ActionType.OnUse, 1.0f, useTarget: target.Body.UserData as Entity, user: _user);
ApplyStatusEffects(ActionType.OnImpact, 1.0f, useTarget: target.Body.UserData as Entity, user: _user);
#if SERVER
if (GameMain.NetworkMember.IsServer)
{
@@ -639,6 +692,7 @@ namespace Barotrauma.Items.Components
}
target.Body.ApplyLinearImpulse(velocity * item.body.Mass);
target.Body.LinearVelocity = target.Body.LinearVelocity.ClampLength(NetConfig.MaxPhysicsBodyVelocity * 0.5f);
if (hits.Count() >= MaxTargetsToHit || hits.LastOrDefault()?.UserData is VoronoiCell)
{
@@ -702,7 +756,7 @@ namespace Barotrauma.Items.Components
if (RemoveOnHit)
{
Entity.Spawner.AddToRemoveQueue(item);
Entity.Spawner?.AddToRemoveQueue(item);
}
return true;
@@ -446,7 +446,7 @@ namespace Barotrauma.Items.Components
//oxygen generators don't deteriorate if they're not running
if (oxyGenerator.CurrFlow > 0.1f) { return true; }
}
else if (ic is Powered powered)
else if (ic is Powered powered && !(powered is LightComponent))
{
if (powered.Voltage >= powered.MinVoltage) { return true; }
}
@@ -477,6 +477,7 @@ namespace Barotrauma.Items.Components
private void UpdateFixAnimation(Character character)
{
if (character == null || character.IsDead || character.IsIncapacitated) { return; }
character.AnimController.UpdateUseItem(false, item.WorldPosition + new Vector2(0.0f, 100.0f) * ((item.Condition / item.MaxCondition) % 0.1f));
}
@@ -40,7 +40,7 @@ namespace Barotrauma.Items.Components
{
get
{
if (recipientsDirty) RefreshRecipients();
if (recipientsDirty) { RefreshRecipients(); }
return recipients;
}
}
@@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components
return "Connection (" + item.Name + ", " + Name + ")";
}
public Connection(XElement element, ConnectionPanel connectionPanel)
public Connection(XElement element, ConnectionPanel connectionPanel, IdRemap idRemap)
{
#if CLIENT
@@ -150,8 +150,11 @@ namespace Barotrauma.Items.Components
if (index == -1) break;
int id = subElement.GetAttributeInt("w", 0);
if (id < 0) id = 0;
wireId[index] = (ushort)id;
if (id < 0)
{
id = 0;
}
wireId[index] = idRemap.GetOffsetId(id);
break;
@@ -162,6 +165,11 @@ namespace Barotrauma.Items.Components
}
}
public void SetRecipientsDirty()
{
recipientsDirty = true;
}
private void RefreshRecipients()
{
recipients.Clear();
@@ -304,6 +312,7 @@ namespace Barotrauma.Items.Components
{
if (wires[i].Item.body != null) wires[i].Item.body.Enabled = false;
wires[i].Connect(this, false, false);
wires[i].FixNodeEnds();
}
}
}
@@ -50,10 +50,10 @@ namespace Barotrauma.Items.Components
switch (subElement.Name.ToString())
{
case "input":
Connections.Add(new Connection(subElement, this));
Connections.Add(new Connection(subElement, this, IdRemap.DiscardId));
break;
case "output":
Connections.Add(new Connection(subElement, this));
Connections.Add(new Connection(subElement, this, IdRemap.DiscardId));
break;
}
}
@@ -218,9 +218,9 @@ namespace Barotrauma.Items.Components
return false;
}
public override void Load(XElement element, bool usePrefabValues)
public override void Load(XElement element, bool usePrefabValues, IdRemap idRemap)
{
base.Load(element, usePrefabValues);
base.Load(element, usePrefabValues, idRemap);
List<Connection> loadedConnections = new List<Connection>();
@@ -229,10 +229,10 @@ namespace Barotrauma.Items.Components
switch (subElement.Name.ToString())
{
case "input":
loadedConnections.Add(new Connection(subElement, this));
loadedConnections.Add(new Connection(subElement, this, idRemap));
break;
case "output":
loadedConnections.Add(new Connection(subElement, this));
loadedConnections.Add(new Connection(subElement, this, idRemap));
break;
}
}
@@ -14,12 +14,12 @@ namespace Barotrauma.Items.Components
private Color lightColor;
private float lightBrightness;
private float blinkFrequency;
private float pulseFrequency, pulseAmount;
private float range;
private float flicker, flickerState;
private float flicker, flickerSpeed;
private bool castShadows;
private bool drawBehindSubs;
private float blinkTimer;
private double lastToggleSignalTime;
@@ -90,14 +90,49 @@ namespace Barotrauma.Items.Components
set
{
flicker = MathHelper.Clamp(value, 0.0f, 1.0f);
#if CLIENT
if (light != null) { light.LightSourceParams.Flicker = flicker; }
#endif
}
}
[Editable, Serialize(1.0f, false, description: "How fast the light flickers.")]
public float FlickerSpeed
{
get;
set;
get { return flickerSpeed; }
set
{
flickerSpeed = value;
#if CLIENT
if (light != null) { light.LightSourceParams.FlickerSpeed = flickerSpeed; }
#endif
}
}
[Editable, Serialize(0.0f, true, description: "How rapidly the light pulsates (in Hz). 0 = no blinking.")]
public float PulseFrequency
{
get { return pulseFrequency; }
set
{
pulseFrequency = MathHelper.Clamp(value, 0.0f, 60.0f);
#if CLIENT
if (light != null) { light.LightSourceParams.PulseFrequency = pulseFrequency; }
#endif
}
}
[Editable(MinValueFloat = 0.0f, MaxValueFloat = 1.0f, DecimalCount = 2), Serialize(0.0f, true, description: "How much light pulsates (in Hz). 0 = not at all, 1 = alternates between full brightness and off.")]
public float PulseAmount
{
get { return pulseAmount; }
set
{
pulseAmount = MathHelper.Clamp(value, 0.0f, 1.0f);
#if CLIENT
if (light != null) { light.LightSourceParams.PulseAmount = pulseAmount; }
#endif
}
}
[Editable, Serialize(0.0f, true, description: "How rapidly the light blinks on and off (in Hz). 0 = no blinking.")]
@@ -107,6 +142,9 @@ namespace Barotrauma.Items.Components
set
{
blinkFrequency = MathHelper.Clamp(value, 0.0f, 60.0f);
#if CLIENT
if (light != null) { light.LightSourceParams.BlinkFrequency = blinkFrequency; }
#endif
}
}
@@ -161,11 +199,16 @@ namespace Barotrauma.Items.Components
{
ParentSub = item.CurrentHull?.Submarine,
Position = item.Position,
CastShadows = castShadows,
CastShadows = castShadows,
IsBackground = drawBehindSubs,
SpriteScale = Vector2.One * item.Scale,
Range = range
};
light.LightSourceParams.Flicker = flicker;
light.LightSourceParams.FlickerSpeed = FlickerSpeed;
light.LightSourceParams.PulseAmount = pulseAmount;
light.LightSourceParams.PulseFrequency = pulseFrequency;
light.LightSourceParams.BlinkFrequency = blinkFrequency;
#endif
IsActive = IsOn;
@@ -229,22 +272,7 @@ namespace Barotrauma.Items.Components
lightBrightness = MathHelper.Lerp(lightBrightness, powerConsumption <= 0.0f ? 1.0f : Math.Min(Voltage, 1.0f), 0.1f);
}
if (blinkFrequency > 0.0f)
{
blinkTimer = (blinkTimer + deltaTime * blinkFrequency) % 1.0f;
}
if (blinkTimer > 0.5f)
{
SetLightSourceState(false, lightBrightness);
}
else
{
flickerState += deltaTime * FlickerSpeed;
flickerState %= 255;
float noise = PerlinNoise.GetPerlin(flickerState, flickerState * 0.5f) * flicker;
SetLightSourceState(true, lightBrightness * (1.0f - noise));
}
SetLightSourceState(true, lightBrightness);
if (powerIn == null && powerConsumption > 0.0f) { Voltage -= deltaTime; }
}
@@ -1,4 +1,5 @@
using Barotrauma.Networking;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
@@ -7,6 +8,10 @@ namespace Barotrauma.Items.Components
{
private const int MaxMessageLength = ChatMessage.MaxLength;
private const int MaxMessages = 60;
private List<string> messageHistory = new List<string>(MaxMessages);
public string DisplayedWelcomeMessage
{
get;
@@ -50,5 +55,41 @@ namespace Barotrauma.Items.Components
string inputSignal = signal.Replace("\\n", "\n");
ShowOnDisplay(inputSignal);
}
public override void OnItemLoaded()
{
base.OnItemLoaded();
if (!string.IsNullOrEmpty(DisplayedWelcomeMessage))
{
ShowOnDisplay(DisplayedWelcomeMessage);
DisplayedWelcomeMessage = "";
//remove welcome message if a game session is running so it doesn't reappear on successive rounds
if (GameMain.GameSession != null)
{
welcomeMessage = null;
}
}
}
public override XElement Save(XElement parentElement)
{
var componentElement = base.Save(parentElement);
for (int i = 0; i < messageHistory.Count; i++)
{
componentElement.Add(new XAttribute("msg" + i, messageHistory[i]));
}
return componentElement;
}
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues, idRemap);
for (int i = 0; i < MaxMessages; i++)
{
string msg = componentElement.GetAttributeString("msg" + i, null);
if (msg == null) { break; }
ShowOnDisplay(msg);
}
}
}
}
@@ -17,7 +17,8 @@ namespace Barotrauma.Items.Components
Atan,
}
protected float[] receivedSignal = new float[2];
private float[] receivedSignal = new float[2];
private float[] timeSinceReceived = new float[2];
[Serialize(FunctionType.Sin, false, description: "Which kind of function to run the input through.", alwaysUseInstanceValues: true)]
public FunctionType Function
@@ -41,12 +42,25 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
//reset received signals
receivedSignal[0] = float.NaN;
receivedSignal[1] = float.NaN;
if (Function == FunctionType.Atan)
{
for (int i = 0; i < 2; i++)
{
timeSinceReceived[i] += deltaTime;
if (timeSinceReceived[i] > 0.1f)
{
receivedSignal[i] = float.NaN;
}
}
if (!float.IsNaN(receivedSignal[0]) && !float.IsNaN(receivedSignal[1]))
{
float angle = (float)Math.Atan2(receivedSignal[1], receivedSignal[0]);
if (!UseRadians) { angle = MathHelper.ToDegrees(angle); }
item.SendSignal(0, angle.ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
}
}
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0, float signalStrength = 1)
{
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out float value);
@@ -89,17 +103,13 @@ namespace Barotrauma.Items.Components
case FunctionType.Atan:
if (connection.Name == "signal_in_x")
{
timeSinceReceived[0] = 0.0f;
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[0]);
}
else if (connection.Name == "signal_in_y")
{
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]);
if (!float.IsNaN(receivedSignal[0]) && !float.IsNaN(receivedSignal[1]))
{
float angle = (float)Math.Atan2(receivedSignal[1], receivedSignal[0]);
if (!UseRadians) { angle = MathHelper.ToDegrees(angle); }
item.SendSignal(0, angle.ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
}
timeSinceReceived[1] = 0.0f;
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]);
}
else
{
@@ -1,4 +1,6 @@
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using System;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
@@ -59,6 +61,12 @@ namespace Barotrauma.Items.Components
{
item.SendSignal(0, signalOut, "signal_out", null);
}
if (item.CurrentHull != null)
{
int waterPercentage = MathHelper.Clamp((int)Math.Round(item.CurrentHull.WaterPercentage), 0, 100);
item.SendSignal(0, waterPercentage.ToString(), "water_%", null);
}
}
}
}
@@ -63,7 +63,7 @@ namespace Barotrauma.Items.Components
public bool Hidden;
private float removeNodeDelay;
private float editNodeDelay;
private bool locked;
public bool Locked
@@ -200,14 +200,16 @@ namespace Barotrauma.Items.Components
{
if (connections[0] != null && connections[0] != newConnection)
{
if (Vector2.DistanceSquared(nodes[0], connections[0].Item.Position - (refSub?.HiddenSubPosition ?? Vector2.Zero)) < Vector2.DistanceSquared(nodes[nodes.Count - 1], nodePos))
if (Vector2.DistanceSquared(nodes[0], connections[0].Item.Position - (refSub?.HiddenSubPosition ?? Vector2.Zero)) <
Vector2.DistanceSquared(nodes[nodes.Count - 1], connections[0].Item.Position - (refSub?.HiddenSubPosition ?? Vector2.Zero)))
{
newNodeIndex = nodes.Count;
}
}
else if (connections[1] != null && connections[1] != newConnection)
{
if (Vector2.DistanceSquared(nodes[0], connections[1].Item.Position - (refSub?.HiddenSubPosition ?? Vector2.Zero)) < Vector2.DistanceSquared(nodes[nodes.Count - 1], nodePos))
if (Vector2.DistanceSquared(nodes[0], connections[1].Item.Position - (refSub?.HiddenSubPosition ?? Vector2.Zero)) <
Vector2.DistanceSquared(nodes[nodes.Count - 1], connections[1].Item.Position - (refSub?.HiddenSubPosition ?? Vector2.Zero)))
{
newNodeIndex = nodes.Count;
}
@@ -290,7 +292,7 @@ namespace Barotrauma.Items.Components
if (nodes.Count == 0) { return; }
Character user = item.ParentInventory?.Owner as Character;
removeNodeDelay = (user?.SelectedConstruction == null) ? removeNodeDelay - deltaTime : 0.5f;
editNodeDelay = (user?.SelectedConstruction == null) ? editNodeDelay - deltaTime : 0.5f;
Submarine sub = item.Submarine;
if (connections[0] != null && connections[0].Item.Submarine != null) { sub = connections[0].Item.Submarine; }
@@ -416,7 +418,9 @@ namespace Barotrauma.Items.Components
#endif
//clients communicate node addition/removal with network events
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer) { return false; }
if (newNodePos != Vector2.Zero && canPlaceNode && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > MinNodeDistance)
if (newNodePos != Vector2.Zero && canPlaceNode && editNodeDelay <= 0.0f && nodes.Count > 0 &&
Vector2.DistanceSquared(newNodePos, nodes[nodes.Count - 1]) > MinNodeDistance * MinNodeDistance)
{
if (nodes.Count >= MaxNodeCount)
{
@@ -440,6 +444,7 @@ namespace Barotrauma.Items.Components
}
#endif
}
editNodeDelay = 0.1f;
return true;
}
@@ -450,7 +455,7 @@ namespace Barotrauma.Items.Components
//clients communicate node addition/removal with network events
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer) { return false; }
if (nodes.Count > 1 && removeNodeDelay <= 0.0f)
if (nodes.Count > 1 && editNodeDelay <= 0.0f)
{
nodes.RemoveAt(nodes.Count - 1);
UpdateSections();
@@ -466,7 +471,7 @@ namespace Barotrauma.Items.Components
}
#endif
}
removeNodeDelay = 0.1f;
editNodeDelay = 0.1f;
Drawable = IsActive || sections.Count > 0;
return true;
@@ -617,8 +622,8 @@ namespace Barotrauma.Items.Components
{
if (connections[i]?.Item != null)
{
var pt = connections[i].Item.GetComponent<PowerTransfer>();
if (pt != null) pt.SetConnectionDirty(connections[i]);
connections[i].Item.GetComponent<PowerTransfer>()?.SetConnectionDirty(connections[i]);
connections[i].SetRecipientsDirty();
}
}
}
@@ -648,17 +653,29 @@ namespace Barotrauma.Items.Components
} while (removed);
}
private void FixNodeEnds()
public void FixNodeEnds()
{
if (connections[0] == null || connections[1] == null || nodes.Count == 0) { return; }
Item item0 = connections[0]?.Item;
Item item1 = connections[1]?.Item;
if (item0 == null && item1 != null)
{
item0 = Item.ItemList.Find(it => it.GetComponent<ConnectionPanel>()?.DisconnectedWires.Contains(this) ?? false);
}
else if (item0 != null && item1 == null)
{
item1 = Item.ItemList.Find(it => it.GetComponent<ConnectionPanel>()?.DisconnectedWires.Contains(this) ?? false);
}
if (item0 == null || item1 == null || nodes.Count == 0) { return; }
Vector2 nodePos = nodes[0];
Submarine refSub = connections[0].Item.Submarine ?? connections[1].Item.Submarine;
Submarine refSub = item0.Submarine ?? item1.Submarine;
if (refSub != null) { nodePos += refSub.HiddenSubPosition; }
float dist1 = Vector2.DistanceSquared(connections[0].Item.Position, nodePos);
float dist2 = Vector2.DistanceSquared(connections[1].Item.Position, nodePos);
float dist1 = Vector2.DistanceSquared(item0.Position, nodePos);
float dist2 = Vector2.DistanceSquared(item1.Position, nodePos);
//first node is closer to the second item
//= the nodes are "backwards", need to reverse them
@@ -747,9 +764,9 @@ namespace Barotrauma.Items.Components
UpdateSections();
}
public override void Load(XElement componentElement, bool usePrefabValues)
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues);
base.Load(componentElement, usePrefabValues, idRemap);
string nodeString = componentElement.GetAttributeString("nodes", "");
if (nodeString == "") return;
@@ -441,9 +441,9 @@ namespace Barotrauma.Items.Components
}
private int loadedVariant = -1;
public override void Load(XElement componentElement, bool usePrefabValues)
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues);
base.Load(componentElement, usePrefabValues, idRemap);
loadedVariant = componentElement.GetAttributeInt("variant", -1);
}
public override void OnItemLoaded()