(883c460d5) Don't require holding the aim key when using the periscope/controller. Move the RequireAimToUse from Controller component to Item. Change the use and shoot logic accordingly. TODO: fix the camera centering.

This commit is contained in:
Joonas Rikkonen
2019-04-04 11:07:14 +03:00
parent c8a7815ef8
commit 2d52a8ddf4
10 changed files with 74 additions and 32 deletions
@@ -64,6 +64,7 @@ namespace Barotrauma.Items.Components
attack = new Attack(subElement, item.Name + ", MeleeWeapon");
}
item.IsShootable = true;
item.RequireAimToUse = true;
}
public override bool Use(float deltaTime, Character character = null)
@@ -57,6 +57,7 @@ namespace Barotrauma.Items.Components
: base(item, element)
{
item.IsShootable = true;
item.RequireAimToUse = true;
}
public override void Update(float deltaTime, Camera cam)
@@ -80,6 +80,7 @@ namespace Barotrauma.Items.Components
}
}
item.IsShootable = true;
item.RequireAimToUse = true;
InitProjSpecific(element);
}
@@ -311,7 +312,10 @@ namespace Barotrauma.Items.Components
sinTime += deltaTime;
character.CursorPosition = leak.Position + VectorExtensions.Forward(Item.body.TransformedRotation + (float)Math.Sin(sinTime), dist);
character.SetInput(InputType.Aim, false, true);
if (item.RequireAimToUse)
{
character.SetInput(InputType.Aim, false, true);
}
// Press the trigger only when the tool is approximately facing the target.
// If the character is climbing, ignore the check, because we cannot aim while climbing.
@@ -43,12 +43,6 @@ namespace Barotrauma.Items.Components
set { userPos = value; }
}
[Serialize(false, true)]
public bool RequireAimToUse
{
get; set;
}
public Controller(Item item, XElement element)
: base(item, element)
{
@@ -152,7 +146,12 @@ namespace Barotrauma.Items.Components
limb.PullJointEnabled = true;
limb.PullJointWorldAnchorB = limb.SimPosition + ConvertUnits.ToSimUnits(diff);
}
}
if (!item.RequireAimToUse)
{
Control(deltaTime, character);
}
}
public override bool Use(float deltaTime, Character activator = null)
@@ -169,8 +168,6 @@ namespace Barotrauma.Items.Components
return false;
}
if (RequireAimToUse && !activator.IsKeyDown(InputType.Aim)) return false;
item.SendSignal(0, "1", "trigger_out", character);
ApplyStatusEffects(ActionType.OnUse, 1.0f, activator);
@@ -179,6 +176,15 @@ namespace Barotrauma.Items.Components
}
public override bool SecondaryUse(float deltaTime, Character character = null)
{
if (item.RequireAimToUse)
{
return Control(deltaTime, character);
}
return false;
}
private bool Control(float deltaTime, Character character = null)
{
if (this.character != character)
{
@@ -191,7 +197,7 @@ namespace Barotrauma.Items.Components
this.character = null;
return false;
}
if (character == null) return false;
if (character == null) return false;
focusTarget = GetFocusTarget();
if (focusTarget == null)
@@ -204,7 +210,7 @@ namespace Barotrauma.Items.Components
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
return false;
}
character.ViewTarget = focusTarget;
#if CLIENT
if (character == Character.Controlled && cam != null)
@@ -215,7 +221,7 @@ namespace Barotrauma.Items.Components
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, (focusTarget as Item).Prefab.OffsetOnSelected, deltaTime * 10.0f);
}
#endif
if (!character.IsRemotePlayer || character.ViewTarget == focusTarget)
{
Vector2 centerPos = new Vector2(item.WorldRect.Center.X, item.WorldRect.Center.Y);
@@ -235,7 +241,6 @@ namespace Barotrauma.Items.Components
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
}
return true;
}
@@ -164,6 +164,7 @@ namespace Barotrauma.Items.Components
}
}
item.IsShootable = true;
item.RequireAimToUse = false;
InitProjSpecific(element);
}
@@ -488,7 +489,10 @@ namespace Barotrauma.Items.Components
character.CursorPosition = closestEnemy.WorldPosition;
if (item.Submarine != null) character.CursorPosition -= item.Submarine.Position;
character.SetInput(InputType.Aim, false, true);
if (item.RequireAimToUse)
{
character.SetInput(InputType.Aim, false, true);
}
float enemyAngle = MathUtils.VectorToAngle(closestEnemy.WorldPosition - item.WorldPosition);
float turretAngle = -rotation;