Melee weapons don't stop the swing when they hit the first target (but only damage each target once per swing). Fixes weapons not hitting the target in tight spaces due to touching the ceiling/walls first, and allows hitting multiple characters with one swing. Closes #622
This commit is contained in:
@@ -3,6 +3,7 @@ using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.Dynamics.Contacts;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -24,6 +25,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float reloadTimer;
|
||||
|
||||
private HashSet<Entity> hitTargets = new HashSet<Entity>();
|
||||
|
||||
[Serialize(0.0f, false)]
|
||||
public float Range
|
||||
{
|
||||
@@ -94,6 +97,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
hitting = true;
|
||||
hitTargets.Clear();
|
||||
|
||||
IsActive = true;
|
||||
return false;
|
||||
@@ -131,8 +135,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (picker.IsKeyDown(InputType.Aim))
|
||||
{
|
||||
hitPos = Math.Min(hitPos+deltaTime*5.0f, MathHelper.Pi*0.7f);
|
||||
|
||||
hitPos = Math.Min(hitPos + deltaTime * 5.0f, MathHelper.Pi * 0.7f);
|
||||
ac.HoldItem(deltaTime, item, handlePos, new Vector2(0.6f, -0.1f), new Vector2(-0.3f, 0.2f), false, hitPos);
|
||||
}
|
||||
else
|
||||
@@ -142,28 +145,13 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
//Vector2 diff = Vector2.Normalize(picker.CursorPosition - ac.RefLimb.Position);
|
||||
//diff.X = diff.X * ac.Dir;
|
||||
|
||||
hitPos -= deltaTime*15.0f;
|
||||
|
||||
//angl = -hitPos * 2.0f;
|
||||
// System.Diagnostics.Debug.WriteLine("<1.0f "+hitPos);
|
||||
|
||||
|
||||
|
||||
hitPos -= deltaTime * 15.0f;
|
||||
ac.HoldItem(deltaTime, item, handlePos, new Vector2(0.6f, -0.1f), new Vector2(-0.3f, 0.2f), false, hitPos);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// System.Diagnostics.Debug.WriteLine(">1.0f " + hitPos);
|
||||
// ac.HoldItem(deltaTime, item, handlePos, new Vector2(0.5f, 0.2f), new Vector2(1.0f, 0.2f), false, 0.0f);
|
||||
//}
|
||||
|
||||
if (hitPos < -MathHelper.PiOver4*1.2f)
|
||||
if (hitPos < -MathHelper.PiOver4 * 1.2f)
|
||||
{
|
||||
RestoreCollision();
|
||||
hitting = false;
|
||||
hitTargets.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,15 +218,22 @@ namespace Barotrauma.Items.Components
|
||||
targetLimb = (Limb)f2.Body.UserData;
|
||||
if (targetLimb.IsSevered || targetLimb.character == null) return false;
|
||||
targetCharacter = targetLimb.character;
|
||||
|
||||
if (hitTargets.Contains(targetCharacter)) return false;
|
||||
hitTargets.Add(targetCharacter);
|
||||
}
|
||||
else if (f2.Body.UserData is Character)
|
||||
{
|
||||
targetCharacter = (Character)f2.Body.UserData;
|
||||
targetLimb = targetCharacter.AnimController.GetLimb(LimbType.Torso); //Otherwise armor can be bypassed in strange ways
|
||||
if (hitTargets.Contains(targetCharacter)) return false;
|
||||
hitTargets.Add(targetCharacter);
|
||||
}
|
||||
else if (f2.Body.UserData is Structure)
|
||||
{
|
||||
targetStructure = (Structure)f2.Body.UserData;
|
||||
if (hitTargets.Contains(targetStructure)) return false;
|
||||
hitTargets.Add(targetStructure);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -266,10 +261,7 @@ namespace Barotrauma.Items.Components
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RestoreCollision();
|
||||
hitting = false;
|
||||
|
||||
|
||||
if (GameMain.Client != null) return true;
|
||||
|
||||
if (GameMain.Server != null && targetCharacter != null) //TODO: Log structure hits
|
||||
|
||||
Reference in New Issue
Block a user