diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs index c19c9fa5e..f3b542df7 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs @@ -360,11 +360,6 @@ namespace Barotrauma.Items.Components } 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"; foreach (Skill skill in selectedItem.RequiredSkills) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveCombat.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveCombat.cs index 8aac40d42..0d4f621fd 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveCombat.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveCombat.cs @@ -204,7 +204,10 @@ namespace Barotrauma private void Attack(float deltaTime) { 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 (Vector2.DistanceSquared(character.Position, Enemy.Position) <= meleeWeapon.Range * meleeWeapon.Range) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs index 8d65800fd..51668ae2a 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs @@ -161,7 +161,10 @@ namespace Barotrauma private void OperateRepairTool(float deltaTime) { 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; if (fromToolToTarget.LengthSquared() < MathUtils.Pow(repairTool.Range / 2, 2)) { diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index d2d481a1c..e986a8341 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -1276,14 +1276,20 @@ namespace Barotrauma if (i == 1 && selectedItems[0] == selectedItems[1]) { continue; } var item = selectedItems[i]; if (item == null) { continue; } - if (IsKeyDown(InputType.Use) && !item.IsShootable) - { - item.Use(deltaTime, this); - } if (IsKeyDown(InputType.Aim)) { 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); } @@ -1293,14 +1299,20 @@ namespace Barotrauma if (SelectedConstruction != null) { - if (IsKeyDown(InputType.Use) && !SelectedConstruction.IsShootable) - { - SelectedConstruction.Use(deltaTime, this); - } if (IsKeyDown(InputType.Aim)) { 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); } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs index 21aca7faf..d46a5878f 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs @@ -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) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs index add256819..daa4a5a89 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs @@ -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) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs index 27b24d595..5cd310ad7 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs @@ -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. diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs index 71e24b8f6..6a24898c0 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs @@ -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; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs index 14c6f99f7..202f33fd1 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs @@ -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; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 29a7267a9..26d896afb 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -241,6 +241,15 @@ namespace Barotrauma [Serialize(false, false)] public bool IsShootable { get; set; } + /// + /// If true, the user has to hold the "aim" key before use is registered. + /// + [Serialize(false, false)] + public bool RequireAimToUse + { + get; set; + } + public Color Color { get { return spriteColor; } @@ -1459,6 +1468,11 @@ namespace Barotrauma public void Use(float deltaTime, Character character = null, Limb targetLimb = null) { + if (RequireAimToUse && !character.IsKeyDown(InputType.Aim)) + { + return; + } + if (condition == 0.0f) return; bool remove = false;