This commit is contained in:
Evil Factory
2022-07-14 12:25:44 -03:00
86 changed files with 839 additions and 412 deletions
@@ -191,7 +191,7 @@ namespace Barotrauma.Items.Components
while (impactQueue.Count > 0)
{
var impact = impactQueue.Dequeue();
HandleImpact(impact.Body);
HandleImpact(impact);
}
//in case handling the impact does something to the picker
if (picker == null) { return; }
@@ -342,7 +342,7 @@ namespace Barotrauma.Items.Components
}
hitTargets.Add(targetCharacter);
}
else if (f2.Body.UserData is Structure targetStructure)
else if ((f2.Body.UserData as Structure ?? f2.UserData as Structure) is Structure targetStructure)
{
if (AllowHitMultiple)
{
@@ -380,8 +380,9 @@ namespace Barotrauma.Items.Components
return true;
}
private void HandleImpact(Body target)
private void HandleImpact(Fixture targetFixture)
{
var target = targetFixture.Body;
if (User == null || User.Removed || target == null)
{
RestoreCollision();
@@ -411,7 +412,7 @@ namespace Barotrauma.Items.Components
targetCharacter.LastDamageSource = item;
Attack.DoDamage(User, targetCharacter, item.WorldPosition, 1.0f);
}
else if (target.UserData is Structure targetStructure)
else if ((target.UserData as Structure ?? targetFixture.UserData as Structure) is Structure targetStructure)
{
if (targetStructure.Removed) { return; }
Attack.DoDamage(User, targetStructure, item.WorldPosition, 1.0f);
@@ -193,6 +193,9 @@ namespace Barotrauma.Items.Components
private Vector2 prevContainedItemPositions;
private float autoInjectCooldown = 1.0f;
const float AutoInjectInterval = 1.0f;
public bool ShouldBeContained(string[] identifiersOrTags, out bool isRestrictionsDefined)
{
@@ -412,7 +415,15 @@ namespace Barotrauma.Items.Components
if (AutoInject)
{
if (ownerInventory?.Owner is Character ownerCharacter &&
//normally autoinjection should delete the (medical) item, so it only gets applied once
//but in multiplayer clients aren't allowed to remove items themselves, so they may be able to trigger this dozens of times
//before the server notifies them of the item being removed, leading to a sharp lag spike.
//this can also happen with mods, if there's a way to autoinject something that doesn't get removed On Use.
//so let's ensure the item is only applied once per second at most.
autoInjectCooldown -= deltaTime;
if (autoInjectCooldown <= 0.0f &&
ownerInventory?.Owner is Character ownerCharacter &&
ownerCharacter.HealthPercentage / 100f <= AutoInjectThreshold &&
ownerCharacter.HasEquippedItem(item))
{
@@ -420,6 +431,7 @@ namespace Barotrauma.Items.Components
{
item.ApplyStatusEffects(ActionType.OnUse, 1.0f, ownerCharacter);
item.GetComponent<GeneticMaterial>()?.Equip(ownerCharacter);
autoInjectCooldown = AutoInjectInterval;
}
}
}
@@ -338,9 +338,7 @@ namespace Barotrauma.Items.Components
if (user == null) { return; }
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign)
{
#if CLIENT
mpCampaign.TryPurchase(null, fabricatedItem.RequiredMoney);
#elif SERVER
#if SERVER
if (GetUsingClient() is { } client)
{
mpCampaign.TryPurchase(client, fabricatedItem.RequiredMoney);
@@ -142,9 +142,8 @@ namespace Barotrauma.Items.Components
//less effective when in a bad condition
currFlow *= MathHelper.Lerp(0.5f, 1.0f, item.Condition / item.MaxCondition);
item.CurrentHull.WaterVolume += currFlow * deltaTime * Timing.FixedUpdateRate;
item.CurrentHull.WaterVolume += currFlow * deltaTime * Timing.FixedUpdateRate;
if (item.CurrentHull.WaterVolume > item.CurrentHull.Volume) { item.CurrentHull.Pressure += 30.0f * deltaTime; }
}
public void InfectBallast(Identifier identifier, bool allowMultiplePerShip = false)
@@ -742,7 +742,7 @@ namespace Barotrauma.Items.Components
limb.body?.ApplyLinearImpulse(item.body.LinearVelocity * item.body.Mass * 0.1f, item.SimPosition);
return false;
}
if (!FriendlyFire && User != null && limb.character.IsFriendly(User))
if (!FriendlyFire && User != null && limb.character.IsFriendly(User) && HumanAIController.IsOnFriendlyTeam(limb.character, User))
{
return false;
}
@@ -789,6 +789,11 @@ namespace Barotrauma.Items.Components
private bool ShouldIgnoreSubmarineCollision(ref Fixture target, Contact contact)
{
//not in the projectile category: the projectile has not been launched (e.g. just dropped from an inventory)
if (item.body.CollisionCategories != Physics.CollisionProjectile)
{
return false;
}
if (target.Body.UserData is Submarine sub)
{
Vector2 dir = item.body.LinearVelocity.LengthSquared() < 0.001f ?
@@ -238,6 +238,12 @@ namespace Barotrauma.Items.Components
base.OnItemLoaded();
SetLightSourceState(IsActive, lightBrightness);
turret = item.GetComponent<Turret>();
#if CLIENT
if (Screen.Selected.IsEditor)
{
OnMapLoaded();
}
#endif
}
public override void OnMapLoaded()
@@ -1,12 +1,11 @@
using System;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class RegExFindComponent : ItemComponent
{
private static readonly TimeSpan timeout = TimeSpan.FromSeconds(Timing.Step);
private static readonly TimeSpan timeout = TimeSpan.FromMilliseconds(1);
private string expression;
@@ -63,10 +62,9 @@ namespace Barotrauma.Items.Components
get { return expression; }
set
{
if (expression == value) return;
if (expression == value) { return; }
expression = value;
previousReceivedSignal = "";
try
{
regex = new Regex(
@@ -74,11 +72,12 @@ namespace Barotrauma.Items.Components
options: RegexOptions.None,
matchTimeout: timeout);
}
catch
{
return;
}
//reactivate the component, in case some faulty/malicious expression caused it to time out and deactivate itself
IsActive = true;
}
}
@@ -105,11 +104,16 @@ namespace Barotrauma.Items.Components
}
catch (Exception e)
{
item.SendSignal(
e is RegexMatchTimeoutException
? "TIMEOUT"
: "ERROR",
"signal_out");
if (e is RegexMatchTimeoutException)
{
item.SendSignal("TIMEOUT", "signal_out");
//deactivate the component if the expression caused it to time out
IsActive = false;
}
else
{
item.SendSignal("ERROR", "signal_out");
}
previousResult = false;
return;
}