diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Attack.cs b/Barotrauma/BarotraumaShared/Source/Characters/Attack.cs index 78bfb3145..bc498df98 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Attack.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Attack.cs @@ -52,7 +52,7 @@ namespace Barotrauma public float Range { get; private set; } [Serialize(0.0f, false)] - public float DamageRange { get; private set; } + public float DamageRange { get; set; } [Serialize(0.0f, false)] public float Duration { get; private set; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs index 3d6e36af4..5ee79b5d7 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs @@ -93,6 +93,26 @@ namespace Barotrauma.Items.Components } } + public override void OnItemLoaded() + { + if (attack != null && attack.DamageRange <= 0.0f && item.body != null) + { + switch (item.body.BodyShape) + { + case PhysicsBody.Shape.Circle: + attack.DamageRange = item.body.radius; + break; + case PhysicsBody.Shape.Capsule: + attack.DamageRange = item.body.height / 2 + item.body.radius; + break; + case PhysicsBody.Shape.Rectangle: + attack.DamageRange = new Vector2(item.body.width / 2.0f, item.body.height / 2.0f).Length(); + break; + } + attack.DamageRange = ConvertUnits.ToDisplayUnits(attack.DamageRange); + } + } + public override bool Use(float deltaTime, Character character = null) { if (character != null && !characterUsable) return false; @@ -196,7 +216,6 @@ namespace Barotrauma.Items.Components if (OnProjectileCollision(fixture, normal)) { hitSomething = true; - //Character.Controlled.AnimController.Teleport(point - Character.Controlled.SimPosition, Vector2.Zero); break; } } @@ -281,8 +300,7 @@ namespace Barotrauma.Items.Components Character character = null; if (attack != null) { - var submarine = target.Body.UserData as Submarine; - if (submarine != null) + if (target.Body.UserData is Submarine submarine) { item.Move(-submarine.Position); item.Submarine = submarine; @@ -290,9 +308,8 @@ namespace Barotrauma.Items.Components return true; } - Limb limb = target.Body.UserData as Limb; Structure structure; - if (limb != null) + if (target.Body.UserData is Limb limb) { attackResult = attack.DoDamageToLimb(User, limb, item.WorldPosition, 1.0f); if (limb.character != null) @@ -350,13 +367,12 @@ namespace Barotrauma.Items.Components { contained.SetTransform(item.SimPosition, contained.body.Rotation); } - //contained.Condition = 0.0f; //Let the freaking .xml handle it jeez } } if (RemoveOnHit) { - Item.Spawner.AddToRemoveQueue(item); + Entity.Spawner.AddToRemoveQueue(item); } return true; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index 1b5a52e8a..7348e0aa5 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -664,19 +664,20 @@ namespace Barotrauma float damageAmount = 0.0f; for (int i = 0; i < SectionCount; i++) { - if (Vector2.DistanceSquared(SectionPosition(i, true), worldPosition) <= attack.DamageRange * attack.DamageRange) + Rectangle sectionRect = sections[i].rect; + sectionRect.Y -= sections[i].rect.Height; + if (MathUtils.CircleIntersectsRectangle(transformedPos, attack.DamageRange, sectionRect)) { damageAmount = attack.GetStructureDamage(deltaTime); AddDamage(i, damageAmount, attacker); - #if CLIENT - GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f); + GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f); #endif } } #if CLIENT - if (playSound)// && !SectionBodyDisabled(i)) + if (playSound) { string damageSoundType = (attack.DamageType == DamageType.Blunt) ? "StructureBlunt" : "StructureSlash"; SoundPlayer.PlayDamageSound(damageSoundType, damageAmount, worldPosition, tags: Tags);