Projectile damage range is set to the radius of the item's collider if the range is not given in the xml. Structure.AddDamage uses the edges of the sections to calculate the distance to a damage source, i.e. the damage area only has to "touch" the section to do damage. Closes #479
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user