I DID IT HOLY SHIT I GONE AND DONE IT

OnSecondaryUse is what throwing uses for doing things SPECIFICALLY on throw. This way, you can theoretically have grenades on which you'll have to pull the pin before throwing.
This also lets flares be used without the need to throw them.
did i mention my brain hurts
This commit is contained in:
Alex Noir
2017-12-10 15:56:34 +03:00
parent 231a38f71d
commit 55dd58579f
5 changed files with 22 additions and 10 deletions
@@ -96,7 +96,7 @@
<DockingPort IsHorizontal="true" DistanceTolerance="128,64" DockedDistance="64"> <DockingPort IsHorizontal="true" DistanceTolerance="128,64" DockedDistance="64">
<Sprite texture ="dockingport.png" sourcerect="127,0,112,144" depth="0.05" origin="0.5,0.5"/> <Sprite texture ="dockingport.png" sourcerect="127,0,112,144" depth="0.05" origin="0.5,0.5"/>
<sound file="dockingport1.ogg" type="OnUse" range="1000.0"/> <sound file="dockingport1.ogg" type="OnUse" range="1000.0"/>
<sound file="dockingport2.ogg" type="OnAim" range="1000.0"/> <sound file="dockingport2.ogg" type="OnSecondaryUse" range="1000.0"/>
</DockingPort> </DockingPort>
<PowerTransfer/> <PowerTransfer/>
@@ -127,7 +127,7 @@
<DockingPort IsHorizontal="false" DistanceTolerance="64,128" DockedDistance="64"> <DockingPort IsHorizontal="false" DistanceTolerance="64,128" DockedDistance="64">
<Sprite texture ="dockingport.png" sourcerect="127,144,48,112" depth="0.05" origin="0.5,0.5"/> <Sprite texture ="dockingport.png" sourcerect="127,144,48,112" depth="0.05" origin="0.5,0.5"/>
<sound file="dockingport1.ogg" type="OnUse" range="1000.0"/> <sound file="dockingport1.ogg" type="OnUse" range="1000.0"/>
<sound file="dockingport2.ogg" type="OnAim" range="1000.0"/> <sound file="dockingport2.ogg" type="OnSecondaryUse" range="1000.0"/>
</DockingPort> </DockingPort>
<fixrequirement name="Electrical repairs"> <fixrequirement name="Electrical repairs">
@@ -117,7 +117,7 @@
<Body width="11" height="24" density="30"/> <Body width="11" height="24" density="30"/>
<Throwable slots="Any,RightHand,LeftHand" holdpos="0,0" handle1="0,0" throwforce="4.0" aimpos="35,-10"> <Throwable slots="Any,RightHand,LeftHand" holdpos="0,0" handle1="0,0" throwforce="4.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="This" Condition="-100.0" delay="3.0"> <StatusEffect type="OnSecondaryUse" target="This" Condition="-100.0" delay="3.0">
<sound file="Content/Items/Weapons/stungrenade.ogg"/> <sound file="Content/Items/Weapons/stungrenade.ogg"/>
<Explosion range="500" damage="5" stun="25" force="0.1" smoke="false"/> <Explosion range="500" damage="5" stun="25" force="0.1" smoke="false"/>
</StatusEffect> </StatusEffect>
@@ -134,7 +134,7 @@
<Body width="11" height="24" density="30"/> <Body width="11" height="24" density="30"/>
<Throwable slots="Any,RightHand,LeftHand" holdpos="0,0" handle1="0,0" throwforce="4.0" aimpos="35,-10"> <Throwable slots="Any,RightHand,LeftHand" holdpos="0,0" handle1="0,0" throwforce="4.0" aimpos="35,-10">
<StatusEffect type="OnUse" target="This" Condition="-100.0" delay="3.0"> <StatusEffect type="OnSecondaryUse" target="This" Condition="-100.0" delay="3.0">
<sound file="Content/Items/Weapons/stungrenade.ogg"/> <sound file="Content/Items/Weapons/stungrenade.ogg"/>
<Explosion range="500" damage="5" stun="1" force="0.1"/> <Explosion range="500" damage="5" stun="1" force="0.1"/>
<Fire size="300.0"/> <Fire size="300.0"/>
@@ -11,6 +11,7 @@ namespace Barotrauma.Items.Components
float throwPos; float throwPos;
bool throwing; bool throwing;
bool throwDone;
[Serialize(1.0f, false)] [Serialize(1.0f, false)]
public float ThrowForce public float ThrowForce
@@ -32,7 +33,8 @@ namespace Barotrauma.Items.Components
public override bool SecondaryUse(float deltaTime, Character character = null) public override bool SecondaryUse(float deltaTime, Character character = null)
{ {
if (!throwing) return false; //This should only be triggered if (!throwDone) return false; //This should only be triggered in update
throwDone = false;
return true; return true;
} }
@@ -52,7 +54,14 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
if (!item.body.Enabled) return; 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; if (!picker.IsKeyDown(InputType.Aim) && !throwing) throwPos = 0.0f;
@@ -98,6 +107,7 @@ namespace Barotrauma.Items.Components
Limb rightHand = ac.GetLimb(LimbType.RightHand); Limb rightHand = ac.GetLimb(LimbType.RightHand);
item.body.AngularVelocity = rightHand.body.AngularVelocity; 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" ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, picker); //Stun grenades, flares, etc. all have their throw-related things handled in "onSecondaryUse"
throwing = false; throwing = false;
} }
@@ -165,15 +165,15 @@ namespace Barotrauma.Items.Components
if (this.character == null || this.character != character || this.character.SelectedConstruction != item || !character.CanInteractWith(item)) if (this.character == null || this.character != character || this.character.SelectedConstruction != item || !character.CanInteractWith(item))
{ {
character = null; character = null;
return; return false;
} }
if (character == null) return; if (character == null) return false;
Entity focusTarget = GetFocusTarget(); Entity focusTarget = GetFocusTarget();
if (focusTarget == null) if (focusTarget == null)
{ {
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character); item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
return; return false;
} }
character.ViewTarget = focusTarget; character.ViewTarget = focusTarget;
@@ -191,6 +191,8 @@ namespace Barotrauma.Items.Components
{ {
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character); item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
} }
return true;
} }
private Item GetFocusTarget() private Item GetFocusTarget()
@@ -1175,7 +1175,7 @@ namespace Barotrauma
foreach (ItemComponent ic in components) foreach (ItemComponent ic in components)
{ {
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue; if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue;
if (ic.Use(deltaTime, character)) if (ic.SecondaryUse(deltaTime, character))
{ {
ic.WasUsed = true; ic.WasUsed = true;