This commit is contained in:
EvilFactory
2025-04-29 07:27:36 -03:00
26 changed files with 198 additions and 76 deletions
@@ -635,6 +635,8 @@ namespace Barotrauma.Items.Components
autoInjectCooldown -= deltaTime;
if (autoInjectCooldown <= 0.0f &&
ownerInventory?.Owner is Character ownerCharacter &&
//no point in trying to heal if the character is already dead
!ownerCharacter.IsDead &&
ownerCharacter.HealthPercentage / 100f <= AutoInjectThreshold &&
ownerCharacter.HasEquippedItem(item))
{
@@ -399,7 +399,7 @@ namespace Barotrauma.Items.Components
LaunchSub = item.Submarine;
//set the rotation of the projectile again because dropping the projectile in Use
//resets the rotation and moves it to the position of the parent item
Item.SetTransform(simPosition, rotation + (Item.body.Dir * LaunchRotationRadians), findNewHull: false);
Item.SetTransform(simPosition, GetLaunchRotation(rotation), findNewHull: false);
if (DeactivationTime > 0)
{
deactivationTimer = DeactivationTime;
@@ -489,12 +489,7 @@ namespace Barotrauma.Items.Components
float modifiedLaunchImpulse = (LaunchImpulse + launchImpulseModifier) * (1 + Rand.Range(-ImpulseSpread, ImpulseSpread));
DoLaunch(launchDir * modifiedLaunchImpulse);
//needs to be set after DoLaunch, because dropping the item resets the rotation and dir
float afterLaunchAngle = launchAngle + (item.body.Dir * LaunchRotationRadians);
if (item.body.Dir < 0)
{
afterLaunchAngle -= MathHelper.Pi;
}
item.SetTransform(item.body.SimPosition, afterLaunchAngle, findNewHull: false);
item.SetTransform(item.body.SimPosition, GetLaunchRotation(launchAngle), findNewHull: false);
}
}
User = character;
@@ -502,6 +497,20 @@ namespace Barotrauma.Items.Components
return true;
}
/// <summary>
/// Gets the final rotation of the projectile after being launched, taking <see cref="LaunchRotationRadians"/>
/// and the orientation of the projectile's physics body into account.
/// </summary>
private float GetLaunchRotation(float unmodifiedLaunchRotation)
{
float launchRotation = unmodifiedLaunchRotation + (item.body.Dir * LaunchRotationRadians);
if (item.body.Dir < 0)
{
launchRotation -= MathHelper.Pi;
}
return launchRotation;
}
public override bool Use(float deltaTime, Character character = null) => Use(character);
private void DoLaunch(Vector2 impulse)