Fixed railguns and depth charge tubes being directly usable by characters (= they could be launched simply by selecting them and left clicking, without the need to use a railgun controller). Closes #754

This commit is contained in:
Joonas Rikkonen
2018-08-30 10:42:25 +03:00
parent 105461beb3
commit 2b18a1265a
3 changed files with 20 additions and 6 deletions
@@ -9,11 +9,12 @@
<Sprite texture ="railgunetc.png" depth="0.01" sourcerect="64,180,47,76"/> <Sprite texture ="railgunetc.png" depth="0.01" sourcerect="64,180,47,76"/>
<Turret canbeselected = "true" linkable="true" barrelpos="23, 76" <Turret canbeselected="false" linkable="true" characterusable="false"
barrelpos="23, 76"
rotationlimits="90,90" rotationlimits="90,90"
powerconsumption="0.0"/> powerconsumption="0.0"/>
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]"> <ConnectionPanel selectkey="Action" canbeselected="true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver,Wire" type="Equipped"/> <requireditem name="Screwdriver,Wire" type="Equipped"/>
<input name="trigger_in"/> <input name="trigger_in"/>
</ConnectionPanel> </ConnectionPanel>
@@ -10,7 +10,8 @@
<StaticBody width="80" radius="80"/> <StaticBody width="80" radius="80"/>
<Turret barrelsprite="railgunbarrel.png" canbeselected = "true" linkable="true" origin="0.5, 0.85" barrelpos="128, 128" <Turret barrelsprite="railgunbarrel.png" canbeselected="false" characterusable="false" linkable="true"
origin="0.5, 0.85" barrelpos="128, 128"
rotationlimits="180,360" rotationlimits="180,360"
powerconsumption="20000.0" powerconsumption="20000.0"
showchargeindicator="true" showchargeindicator="true"
@@ -71,7 +71,7 @@ namespace Barotrauma.Items.Components
rotation = (minRotation + maxRotation) / 2; rotation = (minRotation + maxRotation) / 2;
} }
} }
public Turret(Item item, XElement element) public Turret(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
@@ -155,6 +155,12 @@ namespace Barotrauma.Items.Components
} }
public override bool Use(float deltaTime, Character character = null) public override bool Use(float deltaTime, Character character = null)
{
if (!characterUsable && character != null) return false;
return TryLaunch(character);
}
private bool TryLaunch(Character character = null)
{ {
if (GameMain.Client != null) return false; if (GameMain.Client != null) return false;
@@ -164,7 +170,7 @@ namespace Barotrauma.Items.Components
if (projectiles.Count == 0) return false; if (projectiles.Count == 0) return false;
if (GetAvailablePower() < powerConsumption) return false; if (GetAvailablePower() < powerConsumption) return false;
var batteries = item.GetConnectedComponents<PowerContainer>(); var batteries = item.GetConnectedComponents<PowerContainer>();
float availablePower = 0.0f; float availablePower = 0.0f;
@@ -180,7 +186,7 @@ namespace Barotrauma.Items.Components
battery.Item.CreateServerEvent(battery); battery.Item.CreateServerEvent(battery);
} }
} }
Launch(projectiles[0].Item, character); Launch(projectiles[0].Item, character);
if (character != null) if (character != null)
@@ -413,6 +419,12 @@ namespace Barotrauma.Items.Components
break; break;
case "trigger_in": case "trigger_in":
item.Use((float)Timing.Step, sender); item.Use((float)Timing.Step, sender);
//triggering the Use method through item.Use will fail if the item is not characterusable and the signal was sent by a character
//so lets do it manually
if (!characterUsable && sender != null)
{
TryLaunch(sender);
}
break; break;
} }
} }