diff --git a/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml b/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml index 454ed82e2..37854344d 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Weapons/weapons.xml @@ -117,7 +117,7 @@ - + @@ -134,7 +134,7 @@ - + diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs index 751a14836..968ece938 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs @@ -11,6 +11,7 @@ namespace Barotrauma.Items.Components float throwPos; bool throwing; + bool throwDone; [Serialize(1.0f, false)] public float ThrowForce @@ -27,18 +28,14 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { - if (character == null) return false; - if (!character.IsKeyDown(InputType.Aim) || throwing) return false; - - throwing = true; - - IsActive = true; - return true; + return true; //We do the actual throwing in Aim because Use might be used by chems } - public override void SecondaryUse(float deltaTime, Character character = null) + public override bool SecondaryUse(float deltaTime, Character character = null) { - if (throwing) return; + if (!throwDone) return false; //This should only be triggered in update + throwDone = false; + return true; } public override void Drop(Character dropper) @@ -57,7 +54,14 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { if (!item.body.Enabled) return; - if (!picker.HasSelectedItem(item)) IsActive = false; + if (!picker.HasSelectedItem(item)) + { + IsActive = false; + return; + } + + if (picker.IsKeyDown(InputType.Aim) && picker.IsKeyHit(InputType.Use)) + throwing = true; if (!picker.IsKeyDown(InputType.Aim) && !throwing) throwPos = 0.0f; @@ -103,7 +107,8 @@ namespace Barotrauma.Items.Components Limb rightHand = ac.GetLimb(LimbType.RightHand); item.body.AngularVelocity = rightHand.body.AngularVelocity; - + throwDone = true; + ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, picker); //Stun grenades, flares, etc. all have their throw-related things handled in "onSecondaryUse" throwing = false; } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs index 26bb3f2ad..f6d7cb494 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs @@ -291,7 +291,10 @@ namespace Barotrauma.Items.Components } //called when the item is equipped and right mouse button is pressed - public virtual void SecondaryUse(float deltaTime, Character character = null) { } + public virtual bool SecondaryUse(float deltaTime, Character character = null) + { + return false; + } //called when the item is placed in a "limbslot" public virtual void Equip(Character character) { } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs index b75f1eb4b..3dbd1799a 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs @@ -160,20 +160,20 @@ namespace Barotrauma.Items.Components return true; } - public override void SecondaryUse(float deltaTime, Character character = null) + public override bool SecondaryUse(float deltaTime, Character character = null) { if (this.character == null || this.character != character || this.character.SelectedConstruction != item || !character.CanInteractWith(item)) { character = null; - return; + return false; } - if (character == null) return; + if (character == null) return false; Entity focusTarget = GetFocusTarget(); if (focusTarget == null) { item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character); - return; + return false; } character.ViewTarget = focusTarget; @@ -191,6 +191,8 @@ namespace Barotrauma.Items.Components { item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character); } + + return true; } private Item GetFocusTarget() diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Rope.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Rope.cs index db4f8068d..feb13df8a 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Rope.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Rope.cs @@ -118,9 +118,9 @@ namespace Barotrauma.Items.Components } - public override void SecondaryUse(float deltaTime, Character character = null) + public override bool SecondaryUse(float deltaTime, Character character = null) { - if (reload > 0.0f) return; + if (reload > 0.0f) return false; bool first = true; for (int i = 0; i < ropeBodies.Length - 1; i++) @@ -157,7 +157,8 @@ namespace Barotrauma.Items.Components //ropeBodies[i + 1].ApplyForce(dist / length * pullForce * 0.1f); } - } + } + return true; } private void NextSection(int i) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs index 086df16b3..99cd54835 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs @@ -242,7 +242,7 @@ namespace Barotrauma.Items.Components return true; } - public override void SecondaryUse(float deltaTime, Character character = null) + public override bool SecondaryUse(float deltaTime, Character character = null) { if (nodes.Count > 1) { @@ -251,6 +251,7 @@ namespace Barotrauma.Items.Components } Drawable = IsActive || sections.Count > 0; + return true; } public override bool Pick(Character picker) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 5405a9816..d6c4d2aad 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -800,6 +800,7 @@ namespace Barotrauma if (!ic.WasUsed) { ic.StopSounds(ActionType.OnUse); + ic.StopSounds(ActionType.OnSecondaryUse); } #endif ic.WasUsed = false; @@ -1167,11 +1168,28 @@ namespace Barotrauma public void SecondaryUse(float deltaTime, Character character = null) { + if (condition == 0.0f) return; + + bool remove = false; + foreach (ItemComponent ic in components) { if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue; - ic.SecondaryUse(deltaTime, character); + if (ic.SecondaryUse(deltaTime, character)) + { + ic.WasUsed = true; + +#if CLIENT + ic.PlaySound(ActionType.OnSecondaryUse, WorldPosition); +#endif + + ic.ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, character); + + if (ic.DeleteOnUse) remove = true; + } } + + if (remove) Remove(); } public List GetHUDTexts(Character character)