v0.11.0.9

This commit is contained in:
Joonas Rikkonen
2020-12-09 16:34:16 +02:00
parent bbf06f0984
commit f433a7ba10
325 changed files with 13947 additions and 3652 deletions
@@ -30,6 +30,7 @@ namespace Barotrauma.Items.Components
private float swingState;
private bool attachable, attached, attachedByDefault;
private Voronoi2.VoronoiCell attachTargetCell;
private readonly PhysicsBody body;
public PhysicsBody Pusher
{
@@ -213,9 +214,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)
{
@@ -255,6 +256,7 @@ namespace Barotrauma.Items.Components
if (Pusher != null) { Pusher.Enabled = false; }
if (item.body != null) { item.body.Enabled = true; }
IsActive = false;
attachTargetCell = null;
if (picker == null || picker.Removed)
{
@@ -359,7 +361,7 @@ namespace Barotrauma.Items.Components
public override void Unequip(Character character)
{
if (picker == null) return;
if (picker == null) { return; }
picker.DeselectItem(item);
#if SERVER
@@ -383,9 +385,9 @@ namespace Barotrauma.Items.Components
//can be attached anywhere inside hulls
if (item.CurrentHull != null && Submarine.RectContains(item.CurrentHull.WorldRect, attachPos)) { return true; }
return Structure.GetAttachTarget(attachPos) != null;
return Structure.GetAttachTarget(attachPos) != null || GetAttachTargetCell(100.0f) != null;
}
public bool CanBeDeattached()
{
if (!attachable || !attached) { return true; }
@@ -406,7 +408,7 @@ namespace Barotrauma.Items.Components
if (item.CurrentHull == null)
{
return Structure.GetAttachTarget(item.WorldPosition) != null;
return attachTargetCell != null && Structure.GetAttachTarget(item.WorldPosition) != null;
}
else
{
@@ -464,7 +466,7 @@ namespace Barotrauma.Items.Components
public void AttachToWall()
{
if (!attachable) return;
if (!attachable) { return; }
//outside hulls/subs -> we need to check if the item is being attached on a structure outside the sub
if (item.CurrentHull == null && item.Submarine == null)
@@ -479,6 +481,11 @@ namespace Barotrauma.Items.Components
}
item.Submarine = attachTarget.Submarine;
}
else
{
attachTargetCell = GetAttachTargetCell(150.0f);
if (attachTargetCell != null) { IsActive = true; }
}
}
var containedItems = item.OwnInventory?.Items;
@@ -507,6 +514,7 @@ namespace Barotrauma.Items.Components
if (!attachable) return;
Attached = false;
attachTargetCell = null;
//make the item pickable with the default pick key and with no specific tools/items when it's deattached
requiredItems.Clear();
@@ -568,9 +576,47 @@ namespace Barotrauma.Items.Components
Vector2 userPos = useWorldCoordinates ? user.WorldPosition : user.Position;
return new Vector2(
MathUtils.RoundTowardsClosest(userPos.X + mouseDiff.X, Submarine.GridSize.X),
MathUtils.RoundTowardsClosest(userPos.Y + mouseDiff.Y, Submarine.GridSize.Y));
Vector2 attachPos = userPos + mouseDiff;
if (user.Submarine == null)
{
bool edgeFound = false;
foreach (var cell in Level.Loaded.GetCells(attachPos))
{
if (cell.CellType != Voronoi2.CellType.Solid) { continue; }
foreach (var edge in cell.Edges)
{
if (!edge.IsSolid) { continue; }
if (MathUtils.GetLineIntersection(edge.Point1, edge.Point2, user.WorldPosition, attachPos, out Vector2 intersection))
{
attachPos = intersection;
edgeFound = true;
break;
}
}
if (edgeFound) { break; }
}
}
return
new Vector2(
MathUtils.RoundTowardsClosest(attachPos.X, Submarine.GridSize.X),
MathUtils.RoundTowardsClosest(attachPos.Y, Submarine.GridSize.Y));
}
private Voronoi2.VoronoiCell GetAttachTargetCell(float maxDist)
{
foreach (var cell in Level.Loaded.GetCells(item.WorldPosition, searchDepth: 1))
{
if (cell.CellType != Voronoi2.CellType.Solid) { continue; }
Vector2 diff = cell.Center - item.WorldPosition;
if (diff.LengthSquared() > 0.0001f) { diff = Vector2.Normalize(diff); }
if (cell.IsPointInside(item.WorldPosition + diff * maxDist))
{
return cell;
}
}
return null;
}
public override void UpdateBroken(float deltaTime, Camera cam)
@@ -580,14 +626,28 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (attachTargetCell != null)
{
if (attachTargetCell.CellType != Voronoi2.CellType.Solid)
{
Drop(dropConnectedWires: true, dropper: null);
}
return;
}
if (item.body == null || !item.body.Enabled) { return; }
if (picker == null || !picker.HasEquippedItem(item))
{
if (Pusher != null) { Pusher.Enabled = false; }
IsActive = false;
if (attachTargetCell == null) { IsActive = false; }
return;
}
if (picker == Character.Controlled && picker.IsKeyDown(InputType.Aim) && CanBeAttached(picker))
{
Drawable = true;
}
Vector2 swing = Vector2.Zero;
if (swingAmount != Vector2.Zero && !picker.IsUnconscious && picker.Stun <= 0.0f)
{
@@ -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,14 +70,14 @@ 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;
}
else
{
if (Vector2.DistanceSquared(item.SimPosition, trigger.SimPosition) > 0.01f)
if (trigger != null && Vector2.DistanceSquared(item.SimPosition, trigger.SimPosition) > 0.01f)
{
trigger.SetTransform(item.SimPosition, 0.0f);
}
@@ -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;
}
@@ -143,13 +143,15 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (!item.body.Enabled) { impactQueue.Clear(); return; }
if (!picker.HasSelectedItem(item)) { impactQueue.Clear(); IsActive = false; }
if (picker == null && !picker.HasSelectedItem(item)) { impactQueue.Clear(); IsActive = false; }
while (impactQueue.Count > 0)
{
var impact = impactQueue.Dequeue();
HandleImpact(impact.Body);
}
//in case handling the impact does something to the picker
if (picker == null) { return; }
reloadTimer -= deltaTime;
if (reloadTimer < 0) { reloadTimer = 0; }
@@ -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 && cell.IsDestructible)
{
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); }
}
}