Merge pull request #120 from Crystalwarrior/fixes

Fixed Throwable component breaking chemicals and other things
This commit is contained in:
Joonas Rikkonen
2017-12-12 17:18:59 +02:00
committed by GitHub
7 changed files with 53 additions and 23 deletions
@@ -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
@@ -27,18 +28,14 @@ namespace Barotrauma.Items.Components
public override bool Use(float deltaTime, Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
if (character == null) return false; return true; //We do the actual throwing in Aim because Use might be used by chems
if (!character.IsKeyDown(InputType.Aim) || throwing) return false;
throwing = true;
IsActive = true;
return true;
} }
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) public override void Drop(Character dropper)
@@ -57,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;
@@ -103,7 +107,8 @@ 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"
throwing = false; throwing = false;
} }
} }
@@ -291,7 +291,10 @@ namespace Barotrauma.Items.Components
} }
//called when the item is equipped and right mouse button is pressed //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" //called when the item is placed in a "limbslot"
public virtual void Equip(Character character) { } public virtual void Equip(Character character) { }
@@ -160,20 +160,20 @@ namespace Barotrauma.Items.Components
return true; 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)) 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()
@@ -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; bool first = true;
for (int i = 0; i < ropeBodies.Length - 1; i++) 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); //ropeBodies[i + 1].ApplyForce(dist / length * pullForce * 0.1f);
} }
} }
return true;
} }
private void NextSection(int i) private void NextSection(int i)
@@ -242,7 +242,7 @@ namespace Barotrauma.Items.Components
return true; return true;
} }
public override void SecondaryUse(float deltaTime, Character character = null) public override bool SecondaryUse(float deltaTime, Character character = null)
{ {
if (nodes.Count > 1) if (nodes.Count > 1)
{ {
@@ -251,6 +251,7 @@ namespace Barotrauma.Items.Components
} }
Drawable = IsActive || sections.Count > 0; Drawable = IsActive || sections.Count > 0;
return true;
} }
public override bool Pick(Character picker) public override bool Pick(Character picker)
@@ -800,6 +800,7 @@ namespace Barotrauma
if (!ic.WasUsed) if (!ic.WasUsed)
{ {
ic.StopSounds(ActionType.OnUse); ic.StopSounds(ActionType.OnUse);
ic.StopSounds(ActionType.OnSecondaryUse);
} }
#endif #endif
ic.WasUsed = false; ic.WasUsed = false;
@@ -1167,11 +1168,28 @@ namespace Barotrauma
public void SecondaryUse(float deltaTime, Character character = null) public void SecondaryUse(float deltaTime, Character character = null)
{ {
if (condition == 0.0f) return;
bool remove = false;
foreach (ItemComponent ic in components) foreach (ItemComponent ic in components)
{ {
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue; 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<ColoredText> GetHUDTexts(Character character) public List<ColoredText> GetHUDTexts(Character character)