(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
@@ -360,11 +360,6 @@ namespace Barotrauma.Items.Components
} }
if (GameMain.Client != null) if (GameMain.Client != null)
{
inadequateSkills = selectedItem.RequiredSkills.FindAll(skill => user.GetSkillLevel(skill.Identifier) < skill.Level);
}
if (selectedItem.RequiredSkills.Any())
{ {
string text = TextManager.Get("FabricatorRequiredSkills") + ":\n"; string text = TextManager.Get("FabricatorRequiredSkills") + ":\n";
foreach (Skill skill in selectedItem.RequiredSkills) foreach (Skill skill in selectedItem.RequiredSkills)
@@ -204,7 +204,10 @@ namespace Barotrauma
private void Attack(float deltaTime) private void Attack(float deltaTime)
{ {
character.CursorPosition = Enemy.Position; character.CursorPosition = Enemy.Position;
character.SetInput(InputType.Aim, false, true); if (Weapon.RequireAimToUse)
{
character.SetInput(InputType.Aim, false, true);
}
if (WeaponComponent is MeleeWeapon meleeWeapon) if (WeaponComponent is MeleeWeapon meleeWeapon)
{ {
if (Vector2.DistanceSquared(character.Position, Enemy.Position) <= meleeWeapon.Range * meleeWeapon.Range) if (Vector2.DistanceSquared(character.Position, Enemy.Position) <= meleeWeapon.Range * meleeWeapon.Range)
@@ -161,7 +161,10 @@ namespace Barotrauma
private void OperateRepairTool(float deltaTime) private void OperateRepairTool(float deltaTime)
{ {
character.CursorPosition = Item.Position; character.CursorPosition = Item.Position;
character.SetInput(InputType.Aim, false, true); if (Item.RequireAimToUse)
{
character.SetInput(InputType.Aim, false, true);
}
Vector2 fromToolToTarget = Item.Position - repairTool.Item.Position; Vector2 fromToolToTarget = Item.Position - repairTool.Item.Position;
if (fromToolToTarget.LengthSquared() < MathUtils.Pow(repairTool.Range / 2, 2)) if (fromToolToTarget.LengthSquared() < MathUtils.Pow(repairTool.Range / 2, 2))
{ {
@@ -1276,14 +1276,20 @@ namespace Barotrauma
if (i == 1 && selectedItems[0] == selectedItems[1]) { continue; } if (i == 1 && selectedItems[0] == selectedItems[1]) { continue; }
var item = selectedItems[i]; var item = selectedItems[i];
if (item == null) { continue; } if (item == null) { continue; }
if (IsKeyDown(InputType.Use) && !item.IsShootable)
{
item.Use(deltaTime, this);
}
if (IsKeyDown(InputType.Aim)) if (IsKeyDown(InputType.Aim))
{ {
item.SecondaryUse(deltaTime, this); item.SecondaryUse(deltaTime, this);
if (IsKeyDown(InputType.Shoot) && item.IsShootable) }
if (IsKeyDown(InputType.Use) && !item.IsShootable)
{
if (!item.RequireAimToUse || IsKeyDown(InputType.Aim))
{
item.Use(deltaTime, this);
}
}
if (IsKeyDown(InputType.Shoot) && item.IsShootable)
{
if (!item.RequireAimToUse || IsKeyDown(InputType.Aim))
{ {
item.Use(deltaTime, this); item.Use(deltaTime, this);
} }
@@ -1293,14 +1299,20 @@ namespace Barotrauma
if (SelectedConstruction != null) if (SelectedConstruction != null)
{ {
if (IsKeyDown(InputType.Use) && !SelectedConstruction.IsShootable)
{
SelectedConstruction.Use(deltaTime, this);
}
if (IsKeyDown(InputType.Aim)) if (IsKeyDown(InputType.Aim))
{ {
SelectedConstruction.SecondaryUse(deltaTime, this); SelectedConstruction.SecondaryUse(deltaTime, this);
if (IsKeyDown(InputType.Shoot) && SelectedConstruction.IsShootable) }
if (IsKeyDown(InputType.Use) && !SelectedConstruction.IsShootable)
{
if (!SelectedConstruction.RequireAimToUse || IsKeyDown(InputType.Aim))
{
SelectedConstruction.Use(deltaTime, this);
}
}
if (IsKeyDown(InputType.Shoot) && SelectedConstruction.IsShootable)
{
if (!SelectedConstruction.RequireAimToUse || IsKeyDown(InputType.Aim))
{ {
SelectedConstruction.Use(deltaTime, this); SelectedConstruction.Use(deltaTime, this);
} }
@@ -64,6 +64,7 @@ namespace Barotrauma.Items.Components
attack = new Attack(subElement, item.Name + ", MeleeWeapon"); attack = new Attack(subElement, item.Name + ", MeleeWeapon");
} }
item.IsShootable = true; item.IsShootable = true;
item.RequireAimToUse = true;
} }
public override bool Use(float deltaTime, Character character = null) public override bool Use(float deltaTime, Character character = null)
@@ -57,6 +57,7 @@ namespace Barotrauma.Items.Components
: base(item, element) : base(item, element)
{ {
item.IsShootable = true; item.IsShootable = true;
item.RequireAimToUse = true;
} }
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
@@ -80,6 +80,7 @@ namespace Barotrauma.Items.Components
} }
} }
item.IsShootable = true; item.IsShootable = true;
item.RequireAimToUse = true;
InitProjSpecific(element); InitProjSpecific(element);
} }
@@ -311,7 +312,10 @@ namespace Barotrauma.Items.Components
sinTime += deltaTime; sinTime += deltaTime;
character.CursorPosition = leak.Position + VectorExtensions.Forward(Item.body.TransformedRotation + (float)Math.Sin(sinTime), dist); 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. // 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. // 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; } set { userPos = value; }
} }
[Serialize(false, true)]
public bool RequireAimToUse
{
get; set;
}
public Controller(Item item, XElement element) public Controller(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
@@ -152,7 +146,12 @@ namespace Barotrauma.Items.Components
limb.PullJointEnabled = true; limb.PullJointEnabled = true;
limb.PullJointWorldAnchorB = limb.SimPosition + ConvertUnits.ToSimUnits(diff); limb.PullJointWorldAnchorB = limb.SimPosition + ConvertUnits.ToSimUnits(diff);
} }
if (!item.RequireAimToUse)
{
Control(deltaTime, character);
}
} }
public override bool Use(float deltaTime, Character activator = null) public override bool Use(float deltaTime, Character activator = null)
@@ -169,8 +168,6 @@ namespace Barotrauma.Items.Components
return false; return false;
} }
if (RequireAimToUse && !activator.IsKeyDown(InputType.Aim)) return false;
item.SendSignal(0, "1", "trigger_out", character); item.SendSignal(0, "1", "trigger_out", character);
ApplyStatusEffects(ActionType.OnUse, 1.0f, activator); ApplyStatusEffects(ActionType.OnUse, 1.0f, activator);
@@ -179,6 +176,15 @@ namespace Barotrauma.Items.Components
} }
public override bool SecondaryUse(float deltaTime, Character character = null) 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) if (this.character != character)
{ {
@@ -191,7 +197,7 @@ namespace Barotrauma.Items.Components
this.character = null; this.character = null;
return false; return false;
} }
if (character == null) return false; if (character == null) return false;
focusTarget = GetFocusTarget(); focusTarget = GetFocusTarget();
if (focusTarget == null) if (focusTarget == null)
@@ -204,7 +210,7 @@ namespace Barotrauma.Items.Components
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset)); targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
return false; return false;
} }
character.ViewTarget = focusTarget; character.ViewTarget = focusTarget;
#if CLIENT #if CLIENT
if (character == Character.Controlled && cam != null) 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); cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, (focusTarget as Item).Prefab.OffsetOnSelected, deltaTime * 10.0f);
} }
#endif #endif
if (!character.IsRemotePlayer || character.ViewTarget == focusTarget) if (!character.IsRemotePlayer || character.ViewTarget == focusTarget)
{ {
Vector2 centerPos = new Vector2(item.WorldRect.Center.X, item.WorldRect.Center.Y); 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)); targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
} }
return true; return true;
} }
@@ -164,6 +164,7 @@ namespace Barotrauma.Items.Components
} }
} }
item.IsShootable = true; item.IsShootable = true;
item.RequireAimToUse = false;
InitProjSpecific(element); InitProjSpecific(element);
} }
@@ -488,7 +489,10 @@ namespace Barotrauma.Items.Components
character.CursorPosition = closestEnemy.WorldPosition; character.CursorPosition = closestEnemy.WorldPosition;
if (item.Submarine != null) character.CursorPosition -= item.Submarine.Position; 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 enemyAngle = MathUtils.VectorToAngle(closestEnemy.WorldPosition - item.WorldPosition);
float turretAngle = -rotation; float turretAngle = -rotation;
@@ -241,6 +241,15 @@ namespace Barotrauma
[Serialize(false, false)] [Serialize(false, false)]
public bool IsShootable { get; set; } public bool IsShootable { get; set; }
/// <summary>
/// If true, the user has to hold the "aim" key before use is registered.
/// </summary>
[Serialize(false, false)]
public bool RequireAimToUse
{
get; set;
}
public Color Color public Color Color
{ {
get { return spriteColor; } get { return spriteColor; }
@@ -1459,6 +1468,11 @@ namespace Barotrauma
public void Use(float deltaTime, Character character = null, Limb targetLimb = null) public void Use(float deltaTime, Character character = null, Limb targetLimb = null)
{ {
if (RequireAimToUse && !character.IsKeyDown(InputType.Aim))
{
return;
}
if (condition == 0.0f) return; if (condition == 0.0f) return;
bool remove = false; bool remove = false;