(5a377a8ee) Unstable v0.9.1000.0
This commit is contained in:
@@ -237,6 +237,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
StopPicking(null);
|
||||
PlaySound(forcedOpen ? ActionType.OnPicked : ActionType.OnUse);
|
||||
if (isOpen) { stuck = MathHelper.Clamp(stuck - StuckReductionOnOpen, 0.0f, 100.0f); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,7 +246,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
base.ClientRead(type, msg, sendingTime);
|
||||
|
||||
bool open = msg.ReadBoolean();
|
||||
bool open = msg.ReadBoolean();
|
||||
bool broken = msg.ReadBoolean();
|
||||
bool forcedOpen = msg.ReadBoolean();
|
||||
SetState(open, isNetworkMessage: true, sendNetworkMessage: false, forcedOpen: forcedOpen);
|
||||
Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||
@@ -258,6 +260,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
if (isStuck) { OpenState = 0.0f; }
|
||||
IsBroken = broken;
|
||||
PredictedState = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
@@ -52,5 +53,13 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
CurrPowerConsumption = powerConsumption;
|
||||
charging = true;
|
||||
timer = Duration;
|
||||
IsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ namespace Barotrauma.Items.Components
|
||||
base.ClientRead(type, msg, sendingTime);
|
||||
bool shouldBeAttached = msg.ReadBoolean();
|
||||
Vector2 simPosition = new Vector2(msg.ReadSingle(), msg.ReadSingle());
|
||||
UInt16 submarineID = msg.ReadUInt16();
|
||||
Submarine sub = Entity.FindEntityByID(submarineID) as Submarine;
|
||||
|
||||
if (!attachable)
|
||||
{
|
||||
@@ -84,6 +86,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
Drop(false, null);
|
||||
item.SetTransform(simPosition, 0.0f);
|
||||
item.Submarine = sub;
|
||||
AttachToWall();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -436,8 +436,7 @@ namespace Barotrauma.Items.Components
|
||||
if (subElement.Attribute("color") != null) color = subElement.GetAttributeColor("color", Color.White);
|
||||
string style = subElement.Attribute("style") == null ?
|
||||
null : subElement.GetAttributeString("style", "");
|
||||
|
||||
GuiFrame = new GUIFrame(RectTransform.Load(subElement, GUI.Canvas, Anchor.Center), style, color);
|
||||
GuiFrame = new GUIFrame(RectTransform.Load(subElement, GUI.Canvas.ItemComponentHolder, Anchor.Center), style, color);
|
||||
DefaultLayout = GUILayoutSettings.Load(subElement);
|
||||
break;
|
||||
case "alternativelayout":
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
private string text;
|
||||
[Serialize("", true, translationTextTag: "Label.", description: "The text displayed in the label."), Editable(100)]
|
||||
[Serialize("", true, translationTextTag: "Label.", description: "The text displayed in the label.", alwaysUseInstanceValues: true), Editable(100)]
|
||||
public string Text
|
||||
{
|
||||
get { return text; }
|
||||
@@ -58,7 +58,7 @@ namespace Barotrauma.Items.Components
|
||||
private set;
|
||||
}
|
||||
|
||||
[Editable, Serialize("0,0,0,255", true, description: "The color of the text displayed on the label (R,G,B,A).")]
|
||||
[Editable, Serialize("0,0,0,255", true, description: "The color of the text displayed on the label (R,G,B,A).", alwaysUseInstanceValues: true)]
|
||||
public Color TextColor
|
||||
{
|
||||
get { return textColor; }
|
||||
@@ -69,7 +69,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[Editable(0.0f, 10.0f), Serialize(1.0f, true, description: "The scale of the text displayed on the label.")]
|
||||
[Editable(0.0f, 10.0f), Serialize(1.0f, true, description: "The scale of the text displayed on the label.", alwaysUseInstanceValues: true)]
|
||||
public float TextScale
|
||||
{
|
||||
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
|
||||
|
||||
@@ -48,7 +48,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (light.LightSprite != null && (item.body == null || item.body.Enabled) && lightBrightness > 0.0f && IsOn)
|
||||
{
|
||||
light.LightSprite.Draw(spriteBatch, new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), lightColor * lightBrightness, 0.0f, item.Scale, SpriteEffects.None, item.SpriteDepth - 0.0001f);
|
||||
Vector2 origin = light.LightSprite.Origin;
|
||||
if (light.LightSpriteEffect == SpriteEffects.FlipHorizontally) { origin.X = light.LightSprite.SourceRect.Width - origin.X; }
|
||||
if (light.LightSpriteEffect == SpriteEffects.FlipVertically) { origin.Y = light.LightSprite.SourceRect.Height - origin.Y; }
|
||||
light.LightSprite.Draw(spriteBatch, new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), lightColor * lightBrightness, origin, -light.Rotation, item.Scale, light.LightSpriteEffect, item.SpriteDepth - 0.0001f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
state = msg.ReadBoolean();
|
||||
State = msg.ReadBoolean();
|
||||
ushort userID = msg.ReadUInt16();
|
||||
if (userID == 0)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,10 @@ namespace Barotrauma.Items.Components
|
||||
private GUIScrollBar forceSlider;
|
||||
private GUITickBox autoControlIndicator;
|
||||
|
||||
private int particlesPerSec = 60;
|
||||
private float particleTimer;
|
||||
|
||||
|
||||
public float AnimSpeed
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -318,10 +318,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (item.ParentInventory.slots[availableSlotIndex].HighlightTimer <= 0.0f)
|
||||
{
|
||||
item.ParentInventory.slots[availableSlotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f);
|
||||
item.ParentInventory.slots[availableSlotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f, 0.2f);
|
||||
if (slotIndex < inputContainer.Capacity)
|
||||
{
|
||||
inputContainer.Inventory.slots[slotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f);
|
||||
inputContainer.Inventory.slots[slotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f, 0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,10 +337,22 @@ namespace Barotrauma.Items.Components
|
||||
slotRect.Center.ToVector2(),
|
||||
color: requiredItem.ItemPrefab.InventoryIconColor * 0.3f,
|
||||
scale: Math.Min(slotRect.Width / itemIcon.size.X, slotRect.Height / itemIcon.size.Y));
|
||||
|
||||
|
||||
if (requiredItem.UseCondition && requiredItem.MinCondition < 1.0f)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(slotRect.X, slotRect.Bottom - 8, slotRect.Width, 8), Color.Black * 0.8f, true);
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Rectangle(slotRect.X, slotRect.Bottom - 8, (int)(slotRect.Width * requiredItem.MinCondition), 8),
|
||||
GUI.Style.Green * 0.8f, true);
|
||||
}
|
||||
|
||||
if (slotRect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
string toolTipText = requiredItem.ItemPrefab.Name;
|
||||
if (requiredItem.UseCondition && requiredItem.MinCondition < 1.0f)
|
||||
{
|
||||
toolTipText += " " + (int)Math.Round(requiredItem.MinCondition * 100) + "%";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(requiredItem.ItemPrefab.Description))
|
||||
{
|
||||
toolTipText += '\n' + requiredItem.ItemPrefab.Description;
|
||||
|
||||
@@ -91,6 +91,7 @@ namespace Barotrauma.Items.Components
|
||||
if ((item.Submarine == null && displayedSubs.Count > 0) || //item not inside a sub anymore, but display is still showing subs
|
||||
!displayedSubs.Contains(item.Submarine) || //current sub not displayer
|
||||
item.Submarine.DockedTo.Any(s => !displayedSubs.Contains(s)) || //some of the docked subs not diplayed
|
||||
!submarineContainer.Children.Any() || // We lack a GUI
|
||||
displayedSubs.Any(s => s != item.Submarine && !item.Submarine.DockedTo.Contains(s))) //displaying a sub that shouldn't be displayed
|
||||
{
|
||||
CreateHUD();
|
||||
@@ -116,15 +117,17 @@ namespace Barotrauma.Items.Components
|
||||
private void DrawHUDFront(SpriteBatch spriteBatch, GUICustomComponent container)
|
||||
{
|
||||
if (Voltage < MinVoltage)
|
||||
{
|
||||
{
|
||||
Vector2 textSize = GUI.Font.MeasureString(noPowerTip);
|
||||
Vector2 textPos = GuiFrame.Rect.Center.ToVector2();
|
||||
|
||||
GUI.DrawString(spriteBatch, textPos - textSize / 2, noPowerTip,
|
||||
GUI.Style.Orange * (float)Math.Abs(Math.Sin(Timing.TotalTime)), Color.Black * 0.8f, font: GUI.SubHeadingFont);
|
||||
GUI.Style.Orange * (float)Math.Abs(Math.Sin(Timing.TotalTime)), Color.Black * 0.8f, font: GUI.SubHeadingFont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!submarineContainer.Children.Any()) { return; }
|
||||
|
||||
foreach (GUIComponent child in submarineContainer.Children.First().Children)
|
||||
{
|
||||
if (child.UserData is Hull hull)
|
||||
@@ -151,7 +154,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
foreach (Hull hull in Hull.hullList)
|
||||
{
|
||||
var hullFrame = submarineContainer.Children.First().FindChild(hull);
|
||||
var hullFrame = submarineContainer.Children.FirstOrDefault()?.FindChild(hull);
|
||||
if (hullFrame == null) { continue; }
|
||||
|
||||
if (GUI.MouseOn == hullFrame || hullFrame.IsParentOf(GUI.MouseOn))
|
||||
@@ -175,7 +178,7 @@ namespace Barotrauma.Items.Components
|
||||
foreach (Hull hull in Hull.hullList)
|
||||
{
|
||||
if (hull.Submarine == null) continue;
|
||||
var hullFrame = submarineContainer.Children.First().FindChild(hull);
|
||||
var hullFrame = submarineContainer.Children.FirstOrDefault()?.FindChild(hull);
|
||||
if (hullFrame == null) continue;
|
||||
|
||||
hullDatas.TryGetValue(hull, out HullData hullData);
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
pumpSpeedLockTimer -= deltaTime;
|
||||
isActiveLockTimer -= deltaTime;
|
||||
autoControlIndicator.Selected = pumpSpeedLockTimer > 0.0f || isActiveLockTimer > 0.0f;
|
||||
autoControlIndicator.Selected = IsAutoControlled;
|
||||
PowerButton.Enabled = isActiveLockTimer <= 0.0f;
|
||||
if (HasPower)
|
||||
{
|
||||
|
||||
@@ -192,9 +192,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
RelativeOffset = new Vector2(0, fissionMeter.RectTransform.RelativeOffset.Y + meterSize.Y)
|
||||
},
|
||||
style: "DeviceSlider", barSize: 0.1f)
|
||||
style: "DeviceSlider", barSize: 0.15f)
|
||||
{
|
||||
Enabled = false,
|
||||
Step = 1.0f / 255,
|
||||
OnMoved = (GUIScrollBar bar, float scrollAmount) =>
|
||||
{
|
||||
LastUser = Character.Controlled;
|
||||
@@ -209,9 +210,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
RelativeOffset = new Vector2(0, turbineMeter.RectTransform.RelativeOffset.Y + meterSize.Y)
|
||||
},
|
||||
style: "DeviceSlider", barSize: 0.1f, isHorizontal: true)
|
||||
style: "DeviceSlider", barSize: 0.15f, isHorizontal: true)
|
||||
{
|
||||
Enabled = false,
|
||||
Step = 1.0f / 255,
|
||||
OnMoved = (GUIScrollBar bar, float scrollAmount) =>
|
||||
{
|
||||
LastUser = Character.Controlled;
|
||||
@@ -715,8 +717,14 @@ namespace Barotrauma.Items.Components
|
||||
targetTurbineOutput = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||
degreeOfSuccess = msg.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
|
||||
FissionRateScrollBar.BarScroll = targetFissionRate / 100.0f;
|
||||
TurbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f;
|
||||
if (Math.Abs(FissionRateScrollBar.BarScroll - targetFissionRate / 100.0f) > 0.01f)
|
||||
{
|
||||
FissionRateScrollBar.BarScroll = targetFissionRate / 100.0f;
|
||||
}
|
||||
if (Math.Abs(TurbineOutputScrollBar.BarScroll - targetTurbineOutput / 100.0f) > 0.01f)
|
||||
{
|
||||
TurbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f;
|
||||
}
|
||||
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace Barotrauma.Items.Components
|
||||
Disruption
|
||||
}
|
||||
|
||||
private PathFinder pathFinder;
|
||||
|
||||
private bool dynamicDockingIndicator = true;
|
||||
|
||||
private bool unsentChanges;
|
||||
@@ -45,7 +47,7 @@ namespace Barotrauma.Items.Components
|
||||
private Sprite sonarBlip;
|
||||
private Sprite lineSprite;
|
||||
|
||||
private Dictionary<string, Sprite> targetIcons = new Dictionary<string, Sprite>();
|
||||
private readonly Dictionary<string, Sprite> targetIcons = new Dictionary<string, Sprite>();
|
||||
|
||||
private float displayBorderSize;
|
||||
|
||||
@@ -65,7 +67,23 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
//Vector2 = vector from the ping source to the position of the disruption
|
||||
//float = strength of the disruption, between 0-1
|
||||
List<Pair<Vector2, float>> disruptedDirections = new List<Pair<Vector2, float>>();
|
||||
private readonly List<Pair<Vector2, float>> disruptedDirections = new List<Pair<Vector2, float>>();
|
||||
|
||||
class CachedDistance
|
||||
{
|
||||
public readonly Vector2 TransducerWorldPos;
|
||||
public readonly Vector2 WorldPos;
|
||||
public readonly float Distance;
|
||||
|
||||
public CachedDistance(Vector2 transducerWorldPos, Vector2 worldPos, float dist)
|
||||
{
|
||||
TransducerWorldPos = transducerWorldPos;
|
||||
WorldPos = worldPos;
|
||||
Distance = dist;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<object, CachedDistance> markerDistances = new Dictionary<object, CachedDistance>();
|
||||
|
||||
private readonly Color positiveColor = Color.Green;
|
||||
private readonly Color warningColor = Color.Orange;
|
||||
@@ -74,7 +92,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public static readonly Vector2 controlBoxSize = new Vector2(0.33f, 0.32f);
|
||||
public static readonly Vector2 controlBoxOffset = new Vector2(0.025f, 0);
|
||||
public static readonly float sonarAreaSize = 1.09f;
|
||||
private static readonly float sonarAreaSize = 1.09f;
|
||||
|
||||
private static readonly Dictionary<BlipType, Color[]> blipColorGradient = new Dictionary<BlipType, Color[]>()
|
||||
{
|
||||
@@ -94,6 +112,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public float DisplayRadius { get; private set; }
|
||||
|
||||
public static Vector2 GUISizeCalculation => Vector2.One * Math.Min(GUI.RelativeHorizontalAspectRatio, 1f) * sonarAreaSize;
|
||||
|
||||
partial void InitProjSpecific(XElement element)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(Enum.GetValues(typeof(BlipType)).Cast<BlipType>().All(t => blipColorGradient.ContainsKey(t)));
|
||||
@@ -254,7 +274,7 @@ namespace Barotrauma.Items.Components
|
||||
controlContainer.RectTransform.SetPosition(Anchor.TopLeft);
|
||||
sonarView.RectTransform.ScaleBasis = ScaleBasis.Smallest;
|
||||
sonarView.RectTransform.SetPosition(Anchor.CenterRight);
|
||||
sonarView.RectTransform.Resize(Vector2.One * GUI.RelativeHorizontalAspectRatio * sonarAreaSize);
|
||||
sonarView.RectTransform.Resize(GUISizeCalculation);
|
||||
GUITextBlock.AutoScaleAndNormalize(passiveTickBox.TextBlock, activeTickBox.TextBlock, zoomText, directionalModeSwitchText);
|
||||
}
|
||||
}
|
||||
@@ -490,6 +510,7 @@ namespace Barotrauma.Items.Components
|
||||
disruptedDirections.Clear();
|
||||
foreach (AITarget t in AITarget.List)
|
||||
{
|
||||
if (t.Entity is Character c && c.Params.HideInSonar) { continue; }
|
||||
if (t.SoundRange <= 0.0f || float.IsNaN(t.SoundRange) || float.IsInfinity(t.SoundRange)) { continue; }
|
||||
|
||||
float distSqr = Vector2.DistanceSquared(t.WorldPosition, transducerCenter);
|
||||
@@ -652,12 +673,16 @@ namespace Barotrauma.Items.Components
|
||||
DrawMarker(spriteBatch,
|
||||
GameMain.GameSession.StartLocation.Name,
|
||||
"outpost",
|
||||
(Level.Loaded.StartPosition - transducerCenter), displayScale, center, DisplayRadius);
|
||||
GameMain.GameSession.StartLocation.Name,
|
||||
Level.Loaded.StartPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
|
||||
DrawMarker(spriteBatch,
|
||||
GameMain.GameSession.EndLocation.Name,
|
||||
"outpost",
|
||||
(Level.Loaded.EndPosition - transducerCenter), displayScale, center, DisplayRadius);
|
||||
GameMain.GameSession.EndLocation.Name,
|
||||
Level.Loaded.EndPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius);
|
||||
|
||||
foreach (AITarget aiTarget in AITarget.List)
|
||||
{
|
||||
@@ -669,7 +694,9 @@ namespace Barotrauma.Items.Components
|
||||
DrawMarker(spriteBatch,
|
||||
aiTarget.SonarLabel,
|
||||
aiTarget.SonarIconIdentifier,
|
||||
aiTarget.WorldPosition - transducerCenter, displayScale, center, DisplayRadius * 0.975f);
|
||||
aiTarget,
|
||||
aiTarget.WorldPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius * 0.975f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,7 +711,9 @@ namespace Barotrauma.Items.Components
|
||||
DrawMarker(spriteBatch,
|
||||
mission.SonarLabel,
|
||||
mission.SonarIconIdentifier,
|
||||
sonarPosition - transducerCenter, displayScale, center, DisplayRadius * 0.95f);
|
||||
mission,
|
||||
sonarPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius * 0.95f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -701,9 +730,10 @@ namespace Barotrauma.Items.Components
|
||||
if (sub.WorldPosition.Y > Level.Loaded.Size.Y) { continue; }
|
||||
|
||||
DrawMarker(spriteBatch,
|
||||
sub.Info.Name,
|
||||
sub.Info.DisplayName,
|
||||
sub.Info.HasTag(SubmarineTag.Shuttle) ? "shuttle" : "submarine",
|
||||
sub.WorldPosition - transducerCenter,
|
||||
sub,
|
||||
sub.WorldPosition, transducerCenter,
|
||||
displayScale, center, DisplayRadius * 0.95f);
|
||||
}
|
||||
|
||||
@@ -801,8 +831,11 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (Level.Loaded != null && dockingPort.Item.Submarine.WorldPosition.Y > Level.Loaded.Size.Y) { continue; }
|
||||
|
||||
if (dockingPort.Item.Submarine == null) { continue; }
|
||||
if (dockingPort.Item.Submarine.Info.IsWreck) { continue; }
|
||||
|
||||
//don't show the docking ports of the opposing team on the sonar
|
||||
if (item.Submarine != null && dockingPort.Item.Submarine != null)
|
||||
if (item.Submarine != null)
|
||||
{
|
||||
if ((dockingPort.Item.Submarine.TeamID == Character.TeamType.Team1 && item.Submarine.TeamID == Character.TeamType.Team2) ||
|
||||
(dockingPort.Item.Submarine.TeamID == Character.TeamType.Team2 && item.Submarine.TeamID == Character.TeamType.Team1))
|
||||
@@ -947,14 +980,13 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
foreach (AITarget aiTarget in AITarget.List)
|
||||
{
|
||||
if (aiTarget.SonarDisruption <= 0.0f || !aiTarget.Enabled) { continue; }
|
||||
float disruption = aiTarget.Entity is Character c ? c.Params.SonarDisruption : aiTarget.SonarDisruption;
|
||||
if (disruption <= 0.0f || !aiTarget.Enabled) { continue; }
|
||||
float distSqr = Vector2.DistanceSquared(aiTarget.WorldPosition, pingSource);
|
||||
if (distSqr > worldPingRadiusSqr) { continue; }
|
||||
|
||||
float disruptionDist = (float)Math.Sqrt(distSqr);
|
||||
disruptedDirections.Add(new Pair<Vector2, float>((aiTarget.WorldPosition - pingSource) / disruptionDist, aiTarget.SonarDisruption));
|
||||
|
||||
CreateBlipsForDisruption(aiTarget.WorldPosition, aiTarget.SonarDisruption);
|
||||
CreateBlipsForDisruption(aiTarget.WorldPosition, disruption);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1127,6 +1159,7 @@ namespace Barotrauma.Items.Components
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
if (c.AnimController.CurrentHull != null || !c.Enabled) { continue; }
|
||||
if (c.Params.HideInSonar) { continue; }
|
||||
if (DetectSubmarineWalls && c.AnimController.CurrentHull == null && item.CurrentHull != null) { continue; }
|
||||
|
||||
if (c.AnimController.SimplePhysicsEnabled)
|
||||
@@ -1298,9 +1331,42 @@ namespace Barotrauma.Items.Components
|
||||
sonarBlip.Draw(spriteBatch, center + pos, color * 0.5f, sonarBlip.Origin, 0, scale * 0.08f, SpriteEffects.None, 0);
|
||||
}
|
||||
|
||||
private void DrawMarker(SpriteBatch spriteBatch, string label, string iconIdentifier, Vector2 position, float scale, Vector2 center, float radius)
|
||||
private void DrawMarker(SpriteBatch spriteBatch, string label, string iconIdentifier, object targetIdentifier, Vector2 worldPosition, Vector2 transducerPosition, float scale, Vector2 center, float radius)
|
||||
{
|
||||
float dist = position.Length();
|
||||
float dist = Vector2.Distance(worldPosition, transducerPosition);
|
||||
if (Vector2.DistanceSquared(worldPosition, transducerPosition) > Range * Range)
|
||||
{
|
||||
if (markerDistances.TryGetValue(targetIdentifier, out CachedDistance cachedDistance))
|
||||
{
|
||||
if (Vector2.DistanceSquared(cachedDistance.TransducerWorldPos, transducerPosition) > 500 * 500 ||
|
||||
Vector2.DistanceSquared(cachedDistance.WorldPos, worldPosition) > 500 * 500)
|
||||
{
|
||||
markerDistances.Remove(targetIdentifier);
|
||||
CalculateDistance();
|
||||
}
|
||||
else
|
||||
{
|
||||
dist = cachedDistance.Distance;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CalculateDistance();
|
||||
}
|
||||
}
|
||||
|
||||
void CalculateDistance()
|
||||
{
|
||||
pathFinder ??= new PathFinder(WayPoint.WayPointList, indoorsSteering: false);
|
||||
var path = pathFinder.FindPath(ConvertUnits.ToSimUnits(transducerPosition), ConvertUnits.ToSimUnits(worldPosition));
|
||||
if (!path.Unreachable)
|
||||
{
|
||||
markerDistances.Add(targetIdentifier, new CachedDistance(transducerPosition, worldPosition, path.TotalLength));
|
||||
dist = path.TotalLength;
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 position = worldPosition - transducerPosition;
|
||||
|
||||
position *= zoom;
|
||||
position *= scale;
|
||||
|
||||
@@ -390,7 +390,7 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
|
||||
// Sonar area
|
||||
steerArea = new GUICustomComponent(new RectTransform(Vector2.One * GUI.RelativeHorizontalAspectRatio * Sonar.sonarAreaSize, GuiFrame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.Smallest),
|
||||
steerArea = new GUICustomComponent(new RectTransform(Sonar.GUISizeCalculation, GuiFrame.RectTransform, Anchor.CenterRight, scaleBasis: ScaleBasis.Smallest),
|
||||
(spriteBatch, guiCustomComponent) => { DrawHUD(spriteBatch, guiCustomComponent.Rect); }, null);
|
||||
steerRadius = steerArea.Rect.Width / 2;
|
||||
|
||||
@@ -667,7 +667,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (Vector2.DistanceSquared(PlayerInput.MousePosition, steerArea.Rect.Center.ToVector2()) < steerRadius * steerRadius)
|
||||
{
|
||||
if (PlayerInput.PrimaryMouseButtonHeld() && !CrewManager.IsCommandInterfaceOpen && !GameSession.IsInfoFrameOpen)
|
||||
if (PlayerInput.PrimaryMouseButtonHeld() && !CrewManager.IsCommandInterfaceOpen && !GameSession.IsTabMenuOpen)
|
||||
{
|
||||
Vector2 displaySubPos = (-sonar.DisplayOffset * sonar.Zoom) / sonar.Range * sonar.DisplayRadius * sonar.Zoom;
|
||||
displaySubPos.Y = -displaySubPos.Y;
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Barotrauma.Items.Components
|
||||
bool isStuck = msg.ReadBoolean();
|
||||
if (isStuck)
|
||||
{
|
||||
ushort submarineID = msg.ReadUInt16();
|
||||
ushort hullID = msg.ReadUInt16();
|
||||
Vector2 simPosition = new Vector2(
|
||||
msg.ReadSingle(),
|
||||
msg.ReadSingle());
|
||||
@@ -20,7 +22,12 @@ namespace Barotrauma.Items.Components
|
||||
msg.ReadSingle(),
|
||||
msg.ReadSingle());
|
||||
UInt16 entityID = msg.ReadUInt16();
|
||||
Entity entity = Entity.FindEntityByID(entityID);
|
||||
|
||||
Entity entity = Entity.FindEntityByID(entityID);
|
||||
Submarine submarine = Entity.FindEntityByID(submarineID) as Submarine;
|
||||
Hull hull = Entity.FindEntityByID(hullID) as Hull;
|
||||
item.Submarine = submarine;
|
||||
item.CurrentHull = hull;
|
||||
item.body.SetTransform(simPosition, item.body.Rotation);
|
||||
if (entity is Character character)
|
||||
{
|
||||
@@ -30,12 +37,14 @@ namespace Barotrauma.Items.Components
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Limb index out of bounds ({limbIndex}, character: {character.ToString()})");
|
||||
return;
|
||||
}
|
||||
if (character.Removed) { return; }
|
||||
var limb = character.AnimController.Limbs[limbIndex];
|
||||
StickToTarget(limb.body.FarseerBody, axis);
|
||||
}
|
||||
else if (entity is Structure structure)
|
||||
{
|
||||
byte bodyIndex = msg.ReadByte();
|
||||
if (bodyIndex == 255) { bodyIndex = 0; }
|
||||
if (bodyIndex >= structure.Bodies.Count)
|
||||
{
|
||||
DebugConsole.ThrowError($"Failed to read a projectile update from the server. Structure body index out of bounds ({bodyIndex}, structure: {structure.ToString()})");
|
||||
@@ -46,6 +55,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else if (entity is Item item)
|
||||
{
|
||||
if (item.Removed) { return; }
|
||||
StickToTarget(item.body.FarseerBody, axis);
|
||||
}
|
||||
else if (entity is Submarine sub)
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private FixActions requestStartFixAction;
|
||||
|
||||
public float FakeBrokenTimer;
|
||||
|
||||
[Serialize("", false, description: "An optional description of the needed repairs displayed in the repair interface.")]
|
||||
public string Description
|
||||
{
|
||||
@@ -117,9 +119,18 @@ namespace Barotrauma.Items.Components
|
||||
case "emitter":
|
||||
case "particleemitter":
|
||||
particleEmitters.Add(new ParticleEmitter(subElement));
|
||||
particleEmitterConditionRanges.Add(new Vector2(
|
||||
subElement.GetAttributeFloat("mincondition", 0.0f),
|
||||
subElement.GetAttributeFloat("maxcondition", 100.0f)));
|
||||
float minCondition = subElement.GetAttributeFloat("mincondition", 0.0f);
|
||||
float maxCondition = subElement.GetAttributeFloat("maxcondition", 100.0f);
|
||||
|
||||
if (maxCondition < minCondition)
|
||||
{
|
||||
DebugConsole.ThrowError("Invalid damage particle configuration in the Repairable component of " + item.Name + ". MaxCondition needs to be larger than MinCondition.");
|
||||
float temp = maxCondition;
|
||||
maxCondition = minCondition;
|
||||
minCondition = temp;
|
||||
}
|
||||
particleEmitterConditionRanges.Add(new Vector2(minCondition, maxCondition));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -127,6 +138,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
partial void UpdateProjSpecific(float deltaTime)
|
||||
{
|
||||
FakeBrokenTimer -= deltaTime;
|
||||
item.FakeBroken = FakeBrokenTimer > 0.0f;
|
||||
|
||||
if (!GameMain.IsMultiplayer)
|
||||
{
|
||||
switch (requestStartFixAction)
|
||||
@@ -141,10 +155,10 @@ namespace Barotrauma.Items.Components
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < particleEmitters.Count; i++)
|
||||
{
|
||||
if (item.ConditionPercentage >= particleEmitterConditionRanges[i].X && item.ConditionPercentage <= particleEmitterConditionRanges[i].Y)
|
||||
if ((item.ConditionPercentage >= particleEmitterConditionRanges[i].X && item.ConditionPercentage <= particleEmitterConditionRanges[i].Y) || FakeBrokenTimer > 0.0f)
|
||||
{
|
||||
particleEmitters[i].Emit(deltaTime, item.WorldPosition, item.CurrentHull);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,15 @@ namespace Barotrauma.Items.Components
|
||||
if (target == null) { return; }
|
||||
|
||||
Vector2 startPos = new Vector2(source.DrawPosition.X, -source.DrawPosition.Y);
|
||||
var turret = source?.GetComponent<Turret>();
|
||||
if (turret != null)
|
||||
{
|
||||
startPos = new Vector2(source.WorldRect.X + turret.TransformedBarrelPos.X, -(source.WorldRect.Y - turret.TransformedBarrelPos.Y));
|
||||
if (turret.BarrelSprite != null)
|
||||
{
|
||||
startPos += new Vector2((float)Math.Cos(turret.Rotation), (float)Math.Sin(turret.Rotation)) * turret.BarrelSprite.size.Y * turret.BarrelSprite.RelativeOrigin.Y * item.Scale * 0.9f;
|
||||
}
|
||||
}
|
||||
Vector2 endPos = new Vector2(target.DrawPosition.X, -target.DrawPosition.Y);
|
||||
|
||||
if (Snapped)
|
||||
|
||||
@@ -379,7 +379,7 @@ namespace Barotrauma.Items.Components
|
||||
ConnectionPanel.HighlightedWire = wire;
|
||||
|
||||
bool allowRewiring = GameMain.NetworkMember?.ServerSettings == null || GameMain.NetworkMember.ServerSettings.AllowRewiring;
|
||||
if (allowRewiring && !wire.Locked && (!panel.Locked || Screen.Selected == GameMain.SubEditorScreen))
|
||||
if (allowRewiring && (!wire.Locked && !panel.Locked || Screen.Selected == GameMain.SubEditorScreen))
|
||||
{
|
||||
//start dragging the wire
|
||||
if (PlayerInput.PrimaryMouseButtonHeld()) { DraggingConnected = wire; }
|
||||
|
||||
@@ -56,15 +56,6 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnItemLoaded()
|
||||
{
|
||||
base.OnItemLoaded();
|
||||
if (!string.IsNullOrEmpty(DisplayedWelcomeMessage))
|
||||
{
|
||||
ShowOnDisplay(DisplayedWelcomeMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendOutput(string input)
|
||||
{
|
||||
if (input.Length > MaxMessageLength)
|
||||
@@ -123,6 +114,11 @@ namespace Barotrauma.Items.Components
|
||||
public override void AddToGUIUpdateList()
|
||||
{
|
||||
base.AddToGUIUpdateList();
|
||||
if (!string.IsNullOrEmpty(DisplayedWelcomeMessage))
|
||||
{
|
||||
ShowOnDisplay(DisplayedWelcomeMessage);
|
||||
DisplayedWelcomeMessage = "";
|
||||
}
|
||||
if (shouldSelectInputBox)
|
||||
{
|
||||
inputBox.Select();
|
||||
|
||||
@@ -17,14 +17,60 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
partial class WireSection
|
||||
{
|
||||
public VertexPositionColorTexture[] vertices;
|
||||
public VertexPositionColorTexture[] shiftedVertices;
|
||||
|
||||
private float cachedWidth = 0f;
|
||||
|
||||
private void RecalculateVertices(Wire wire, float width)
|
||||
{
|
||||
if (MathUtils.NearlyEqual(cachedWidth, width)) { return; }
|
||||
cachedWidth = width;
|
||||
|
||||
vertices = new VertexPositionColorTexture[4];
|
||||
|
||||
Vector2 expandDir = start-end;
|
||||
expandDir.Normalize();
|
||||
float temp = expandDir.X;
|
||||
expandDir.X = -expandDir.Y;
|
||||
expandDir.Y = -temp;
|
||||
|
||||
Rectangle srcRect = wire.wireSprite.SourceRect;
|
||||
|
||||
expandDir *= width * srcRect.Height * 0.5f;
|
||||
|
||||
Vector2 rectLocation = srcRect.Location.ToVector2();
|
||||
Vector2 rectSize = srcRect.Size.ToVector2();
|
||||
Vector2 textureSize = new Vector2(wire.wireSprite.Texture.Width, wire.wireSprite.Texture.Height);
|
||||
|
||||
Vector2 topLeftUv = rectLocation / textureSize;
|
||||
Vector2 bottomRightUv = (rectLocation + rectSize) / textureSize;
|
||||
|
||||
Vector2 invStart = new Vector2(start.X, -start.Y);
|
||||
Vector2 invEnd = new Vector2(end.X, -end.Y);
|
||||
|
||||
vertices[0] = new VertexPositionColorTexture(new Vector3(invStart + expandDir, 0f), Color.White, topLeftUv);
|
||||
vertices[2] = new VertexPositionColorTexture(new Vector3(invEnd + expandDir, 0f), Color.White, new Vector2(bottomRightUv.X, topLeftUv.Y));
|
||||
vertices[1] = new VertexPositionColorTexture(new Vector3(invStart - expandDir, 0f), Color.White, new Vector2(topLeftUv.X, bottomRightUv.Y));
|
||||
vertices[3] = new VertexPositionColorTexture(new Vector3(invEnd - expandDir, 0f), Color.White, bottomRightUv);
|
||||
|
||||
shiftedVertices = (VertexPositionColorTexture[])vertices.Clone();
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Wire wire, Color color, Vector2 offset, float depth, float width = 0.3f)
|
||||
{
|
||||
if (width <= 0f) { return; }
|
||||
RecalculateVertices(wire, width);
|
||||
|
||||
for (int i=0;i<vertices.Length;i++)
|
||||
{
|
||||
shiftedVertices[i].Color = color;
|
||||
shiftedVertices[i].Position = vertices[i].Position;
|
||||
shiftedVertices[i].Position.X += offset.X;
|
||||
shiftedVertices[i].Position.Y -= offset.Y;
|
||||
}
|
||||
spriteBatch.Draw(wire.wireSprite.Texture,
|
||||
new Vector2(start.X + offset.X, -(start.Y + offset.Y)), wire.wireSprite.SourceRect, color,
|
||||
-angle,
|
||||
new Vector2(0.0f, wire.wireSprite.size.Y / 2.0f),
|
||||
new Vector2(length / wire.wireSprite.size.X, width),
|
||||
SpriteEffects.None,
|
||||
shiftedVertices,
|
||||
depth);
|
||||
}
|
||||
|
||||
@@ -110,7 +156,7 @@ namespace Barotrauma.Items.Components
|
||||
drawOffset = sub.DrawPosition + sub.HiddenSubPosition;
|
||||
}
|
||||
|
||||
float depth = item.IsSelected ? 0.0f : wireSprite.Depth + ((item.ID % 100) * 0.00001f);
|
||||
float depth = item.IsSelected ? 0.0f : Screen.Selected is SubEditorScreen editor && editor.WiringMode ? 0.00002f : wireSprite.Depth + ((item.ID % 100) * 0.00001f);
|
||||
|
||||
if (item.IsHighlighted)
|
||||
{
|
||||
@@ -239,10 +285,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public static void UpdateEditing(List<Wire> wires)
|
||||
{
|
||||
var doubleClicked = PlayerInput.DoubleClicked();
|
||||
|
||||
Wire equippedWire =
|
||||
Character.Controlled?.SelectedItems[0]?.GetComponent<Wire>() ??
|
||||
Character.Controlled?.SelectedItems[1]?.GetComponent<Wire>();
|
||||
if (equippedWire != null)
|
||||
if (equippedWire != null && GUI.MouseOn == null)
|
||||
{
|
||||
if (PlayerInput.PrimaryMouseButtonClicked() && Character.Controlled.SelectedConstruction == null)
|
||||
{
|
||||
@@ -252,7 +300,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
//dragging a node of some wire
|
||||
if (draggingWire != null)
|
||||
if (draggingWire != null && !doubleClicked)
|
||||
{
|
||||
if (Character.Controlled != null)
|
||||
{
|
||||
@@ -283,15 +331,18 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (selectedNodeIndex.HasValue)
|
||||
{
|
||||
nodeWorldPos.X = MathUtils.Round(nodeWorldPos.X, Submarine.GridSize.X / 2.0f);
|
||||
nodeWorldPos.Y = MathUtils.Round(nodeWorldPos.Y, Submarine.GridSize.Y / 2.0f);
|
||||
if (!PlayerInput.IsShiftDown())
|
||||
{
|
||||
nodeWorldPos.X = MathUtils.Round(nodeWorldPos.X, Submarine.GridSize.X / 2.0f);
|
||||
nodeWorldPos.Y = MathUtils.Round(nodeWorldPos.Y, Submarine.GridSize.Y / 2.0f);
|
||||
}
|
||||
|
||||
draggingWire.nodes[(int)selectedNodeIndex] = nodeWorldPos;
|
||||
draggingWire.UpdateSections();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector2.DistanceSquared(nodeWorldPos, draggingWire.nodes[(int)highlightedNodeIndex]) > Submarine.GridSize.X * Submarine.GridSize.X)
|
||||
if (Vector2.DistanceSquared(nodeWorldPos, draggingWire.nodes[(int)highlightedNodeIndex]) > Submarine.GridSize.X * Submarine.GridSize.X || PlayerInput.IsShiftDown())
|
||||
{
|
||||
selectedNodeIndex = highlightedNodeIndex;
|
||||
}
|
||||
@@ -304,6 +355,8 @@ namespace Barotrauma.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
bool updateHighlight = true;
|
||||
|
||||
//a wire has been selected -> check if we should start dragging one of the nodes
|
||||
float nodeSelectDist = 10, sectionSelectDist = 5;
|
||||
highlightedNodeIndex = null;
|
||||
@@ -359,6 +412,37 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
selectedWire.nodes.RemoveAt(closestIndex);
|
||||
selectedWire.UpdateSections();
|
||||
}
|
||||
// if only one end of the wire is disconnect pick it back up with double click
|
||||
else if (doubleClicked && equippedWire == null && Character.Controlled != null && selectedWire.connections.Any(conn => conn != null))
|
||||
{
|
||||
if (selectedWire.connections[0] == null && closestIndex == 0 || selectedWire.connections[1] == null && closestIndex == selectedWire.nodes.Count - 1)
|
||||
{
|
||||
selectedWire.IsActive = true;
|
||||
selectedWire.nodes.RemoveAt(closestIndex);
|
||||
selectedWire.UpdateSections();
|
||||
|
||||
// flip the wire
|
||||
if (closestIndex == 0)
|
||||
{
|
||||
selectedWire.nodes.Reverse();
|
||||
selectedWire.connections[0] = selectedWire.connections[1];
|
||||
selectedWire.connections[1] = null;
|
||||
}
|
||||
|
||||
selectedWire.shouldClearConnections = false;
|
||||
Character.Controlled.Inventory.TryPutItem(selectedWire.item, Character.Controlled, new List<InvSlotType> { InvSlotType.LeftHand, InvSlotType.RightHand });
|
||||
foreach (var entity in MapEntity.mapEntityList)
|
||||
{
|
||||
if (entity is Item item)
|
||||
{
|
||||
item.GetComponent<ConnectionPanel>()?.DisconnectedWires.Remove(selectedWire);
|
||||
}
|
||||
}
|
||||
MapEntity.SelectedList.Clear();
|
||||
selectedWire.shouldClearConnections = true;
|
||||
updateHighlight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,7 +484,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (highlighted != null)
|
||||
if (highlighted != null && updateHighlight)
|
||||
{
|
||||
highlighted.item.IsHighlighted = true;
|
||||
if (PlayerInput.PrimaryMouseButtonClicked())
|
||||
@@ -411,6 +495,20 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsMouseOn()
|
||||
{
|
||||
if (GUI.MouseOn == null)
|
||||
{
|
||||
Vector2 mousePos = GameMain.SubEditorScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
if (item.Submarine != null) { mousePos -= (item.Submarine.Position + item.Submarine.HiddenSubPosition); }
|
||||
|
||||
if (GetClosestNodeIndex(mousePos, 10, out _) > -1) { return true; }
|
||||
if (GetClosestSectionIndex(mousePos, 10, out _) > -1) { return true; }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
int eventIndex = msg.ReadRangedInteger(0, (int)Math.Ceiling(MaxNodeCount / (float)MaxNodesPerNetworkEvent));
|
||||
|
||||
@@ -5,7 +5,7 @@ using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float recoilTimer;
|
||||
|
||||
private float RetractionTime => Math.Max(Reload * RetractionDurationMultiplier, RecoilTime);
|
||||
|
||||
private RoundSound startMoveSound, endMoveSound, moveSound;
|
||||
|
||||
private SoundChannel moveSoundChannel;
|
||||
@@ -83,6 +85,11 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite BarrelSprite
|
||||
{
|
||||
get { return barrelSprite; }
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element)
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
@@ -126,7 +133,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
partial void LaunchProjSpecific()
|
||||
{
|
||||
recoilTimer = Math.Max(Reload, 0.1f);
|
||||
recoilTimer = RetractionTime;
|
||||
PlaySound(ActionType.OnUse);
|
||||
Vector2 particlePos = new Vector2(item.WorldRect.X + transformedBarrelPos.X, item.WorldRect.Y - transformedBarrelPos.Y);
|
||||
foreach (ParticleEmitter emitter in particleEmitters)
|
||||
@@ -135,6 +142,12 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
{
|
||||
base.UpdateBroken(deltaTime, cam);
|
||||
recoilTimer -= deltaTime;
|
||||
}
|
||||
|
||||
partial void UpdateProjSpecific(float deltaTime)
|
||||
{
|
||||
recoilTimer -= deltaTime;
|
||||
@@ -232,15 +245,21 @@ namespace Barotrauma.Items.Components
|
||||
float recoilOffset = 0.0f;
|
||||
if (Math.Abs(RecoilDistance) > 0.0f && recoilTimer > 0.0f)
|
||||
{
|
||||
//move the barrel backwards 0.1 seconds after launching
|
||||
if (recoilTimer >= Math.Max(Reload, 0.1f) - 0.1f)
|
||||
float diff = RetractionTime - RecoilTime;
|
||||
if (recoilTimer >= diff)
|
||||
{
|
||||
recoilOffset = RecoilDistance * (1.0f - (recoilTimer - (Math.Max(Reload, 0.1f) - 0.1f)) / 0.1f);
|
||||
//move the barrel backwards 0.1 seconds (defined by RecoilTime) after launching
|
||||
recoilOffset = RecoilDistance * (1.0f - (recoilTimer - diff) / RecoilTime);
|
||||
}
|
||||
else if (recoilTimer <= diff - RetractionDelay)
|
||||
{
|
||||
//move back to normal position while reloading
|
||||
float t = diff - RetractionDelay;
|
||||
recoilOffset = RecoilDistance * recoilTimer / t;
|
||||
}
|
||||
//move back to normal position while reloading
|
||||
else
|
||||
{
|
||||
recoilOffset = RecoilDistance * recoilTimer / (Math.Max(Reload, 0.1f) - 0.1f);
|
||||
recoilOffset = RecoilDistance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,7 +523,7 @@ namespace Barotrauma.Items.Components
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
UInt16 projectileID = msg.ReadUInt16();
|
||||
float newTargetRotation = msg.ReadRangedSingle(minRotation, maxRotation, 8);
|
||||
float newTargetRotation = msg.ReadRangedSingle(minRotation, maxRotation, 16);
|
||||
|
||||
if (Character.Controlled == null || user != Character.Controlled)
|
||||
{
|
||||
@@ -514,13 +533,21 @@ namespace Barotrauma.Items.Components
|
||||
//projectile removed, do nothing
|
||||
if (projectileID == 0) { return; }
|
||||
|
||||
if (!(Entity.FindEntityByID(projectileID) is Item projectile))
|
||||
//ID ushort.MaxValue = launched without a projectile
|
||||
if (projectileID == ushort.MaxValue)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to launch a projectile - item with the ID \"" + projectileID + " not found");
|
||||
return;
|
||||
Launch(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(Entity.FindEntityByID(projectileID) is Item projectile))
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to launch a projectile - item with the ID \"" + projectileID + " not found");
|
||||
return;
|
||||
}
|
||||
Launch(projectile, launchRotation: newTargetRotation);
|
||||
}
|
||||
|
||||
Launch(projectile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user