2f107db...5202af9
This commit is contained in:
@@ -47,7 +47,6 @@ namespace Barotrauma
|
||||
|
||||
const float LeakThreshold = 0.1f;
|
||||
|
||||
private StructurePrefab prefab;
|
||||
private SpriteEffects SpriteEffects = SpriteEffects.None;
|
||||
|
||||
//dimensions of the wall sections' physics bodies (only used for debug rendering)
|
||||
@@ -69,7 +68,7 @@ namespace Barotrauma
|
||||
|
||||
public bool IsPlatform
|
||||
{
|
||||
get { return prefab.Platform; }
|
||||
get { return Prefab.Platform; }
|
||||
}
|
||||
|
||||
public Direction StairDirection
|
||||
@@ -85,14 +84,14 @@ namespace Barotrauma
|
||||
|
||||
public bool HasBody
|
||||
{
|
||||
get { return prefab.Body; }
|
||||
get { return Prefab.Body; }
|
||||
}
|
||||
|
||||
public List<Body> Bodies { get; private set; }
|
||||
|
||||
public bool CastShadow
|
||||
{
|
||||
get { return prefab.CastShadow; }
|
||||
get { return Prefab.CastShadow; }
|
||||
}
|
||||
|
||||
public bool IsHorizontal { get; private set; }
|
||||
@@ -104,14 +103,14 @@ namespace Barotrauma
|
||||
|
||||
public float Health
|
||||
{
|
||||
get { return prefab.Health; }
|
||||
get { return Prefab.Health; }
|
||||
}
|
||||
|
||||
public override bool DrawBelowWater
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.DrawBelowWater || prefab.BackgroundSprite != null;
|
||||
return base.DrawBelowWater || Prefab.BackgroundSprite != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,18 +126,15 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
return prefab.Body;
|
||||
return Prefab.Body;
|
||||
}
|
||||
}
|
||||
|
||||
public StructurePrefab Prefab
|
||||
{
|
||||
get { return prefab; }
|
||||
}
|
||||
public StructurePrefab Prefab => prefab as StructurePrefab;
|
||||
|
||||
public HashSet<string> Tags
|
||||
{
|
||||
get { return prefab.Tags; }
|
||||
get { return prefab; }
|
||||
}
|
||||
|
||||
protected Color spriteColor;
|
||||
@@ -159,7 +155,7 @@ namespace Barotrauma
|
||||
{
|
||||
Rectangle oldRect = Rect;
|
||||
base.Rect = value;
|
||||
if (prefab.Body) CreateSections();
|
||||
if (Prefab.Body) CreateSections();
|
||||
else
|
||||
{
|
||||
foreach (WallSection sec in Sections)
|
||||
@@ -179,11 +175,11 @@ namespace Barotrauma
|
||||
|
||||
public float BodyWidth
|
||||
{
|
||||
get { return prefab.BodyWidth > 0.0f ? prefab.BodyWidth : rect.Width; }
|
||||
get { return Prefab.BodyWidth > 0.0f ? Prefab.BodyWidth : rect.Width; }
|
||||
}
|
||||
public float BodyHeight
|
||||
{
|
||||
get { return prefab.BodyHeight > 0.0f ? prefab.BodyHeight : rect.Height; }
|
||||
get { return Prefab.BodyHeight > 0.0f ? Prefab.BodyHeight : rect.Height; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,7 +189,7 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
float rotation = MathHelper.ToRadians(prefab.BodyRotation);
|
||||
float rotation = MathHelper.ToRadians(Prefab.BodyRotation);
|
||||
if (FlippedX) rotation = -MathHelper.Pi - rotation;
|
||||
if (FlippedY) rotation = -rotation;
|
||||
return rotation;
|
||||
@@ -206,7 +202,7 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
Vector2 bodyOffset = prefab.BodyOffset;
|
||||
Vector2 bodyOffset = Prefab.BodyOffset;
|
||||
if (FlippedX) { bodyOffset.X = -bodyOffset.X; }
|
||||
if (FlippedY) { bodyOffset.Y = -bodyOffset.Y; }
|
||||
return bodyOffset;
|
||||
@@ -255,7 +251,6 @@ namespace Barotrauma
|
||||
System.Diagnostics.Debug.Assert(rectangle.Width > 0 && rectangle.Height > 0);
|
||||
|
||||
rect = rectangle;
|
||||
prefab = sp;
|
||||
#if CLIENT
|
||||
TextureScale = sp.TextureScale;
|
||||
#endif
|
||||
@@ -280,11 +275,11 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
StairDirection = prefab.StairDirection;
|
||||
StairDirection = Prefab.StairDirection;
|
||||
|
||||
SerializableProperties = SerializableProperty.GetProperties(this);
|
||||
|
||||
if (prefab.Body)
|
||||
if (Prefab.Body)
|
||||
{
|
||||
Bodies = new List<Body>();
|
||||
WallList.Add(this);
|
||||
@@ -313,11 +308,11 @@ namespace Barotrauma
|
||||
|
||||
public override MapEntity Clone()
|
||||
{
|
||||
var clone = new Structure(rect, prefab, Submarine);
|
||||
var clone = new Structure(rect, Prefab, Submarine);
|
||||
foreach (KeyValuePair<string, SerializableProperty> property in SerializableProperties)
|
||||
{
|
||||
if (!property.Value.Attributes.OfType<Editable>().Any()) continue;
|
||||
clone.SerializableProperties[property.Key].TrySetValue(property.Value.GetValue());
|
||||
clone.SerializableProperties[property.Key].TrySetValue(clone, property.Value.GetValue(this));
|
||||
}
|
||||
if (FlippedX) clone.FlipX(false);
|
||||
if (FlippedY) clone.FlipY(false);
|
||||
@@ -571,19 +566,9 @@ namespace Barotrauma
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsVisible(Rectangle worldView)
|
||||
{
|
||||
Rectangle worldRect = WorldRect;
|
||||
|
||||
if (worldRect.X > worldView.Right || worldRect.Right < worldView.X) return false;
|
||||
if (worldRect.Y < worldView.Y - worldView.Height || worldRect.Y - worldRect.Height > worldView.Y) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool OnWallCollision(Fixture f1, Fixture f2, Contact contact)
|
||||
{
|
||||
if (prefab.Platform)
|
||||
if (Prefab.Platform)
|
||||
{
|
||||
if (f2.Body.UserData is Limb limb)
|
||||
{
|
||||
@@ -597,7 +582,7 @@ namespace Barotrauma
|
||||
if (character.DisableImpactDamageTimer > 0.0f || ((Limb)f2.Body.UserData).Mass < 100.0f) return true;
|
||||
}
|
||||
|
||||
if (!prefab.Platform && prefab.StairDirection == Direction.None)
|
||||
if (!Prefab.Platform && Prefab.StairDirection == Direction.None)
|
||||
{
|
||||
Vector2 pos = ConvertUnits.ToDisplayUnits(f2.Body.Position);
|
||||
|
||||
@@ -631,7 +616,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (sectionIndex < 0 || sectionIndex >= Sections.Length) return false;
|
||||
|
||||
return (Sections[sectionIndex].damage >= prefab.Health);
|
||||
return (Sections[sectionIndex].damage >= Prefab.Health);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -641,7 +626,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (sectionIndex < 0 || sectionIndex >= Sections.Length) return false;
|
||||
|
||||
return (Sections[sectionIndex].damage >= prefab.Health * LeakThreshold);
|
||||
return (Sections[sectionIndex].damage >= Prefab.Health * LeakThreshold);
|
||||
}
|
||||
|
||||
public int SectionLength(int sectionIndex)
|
||||
@@ -653,7 +638,7 @@ namespace Barotrauma
|
||||
|
||||
public void AddDamage(int sectionIndex, float damage, Character attacker = null)
|
||||
{
|
||||
if (!prefab.Body || prefab.Platform || Indestructible) return;
|
||||
if (!Prefab.Body || Prefab.Platform || Indestructible) return;
|
||||
|
||||
if (sectionIndex < 0 || sectionIndex > Sections.Length - 1) return;
|
||||
|
||||
@@ -676,7 +661,14 @@ namespace Barotrauma
|
||||
}
|
||||
#endif
|
||||
|
||||
if (GameMain.Client == null) SetDamage(sectionIndex, section.damage + damage, attacker);
|
||||
#if CLIENT
|
||||
if (GameMain.Client == null)
|
||||
{
|
||||
#endif
|
||||
SetDamage(sectionIndex, section.damage + damage, attacker);
|
||||
#if CLIENT
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public int FindSectionIndex(Vector2 displayPos, bool world = false, bool clamp = false)
|
||||
@@ -721,7 +713,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (sectionIndex < 0 || sectionIndex >= Sections.Length) return Vector2.Zero;
|
||||
|
||||
if (prefab.BodyRotation == 0.0f)
|
||||
if (Prefab.BodyRotation == 0.0f)
|
||||
{
|
||||
Vector2 sectionPos = new Vector2(
|
||||
Sections[sectionIndex].rect.X + Sections[sectionIndex].rect.Width / 2.0f,
|
||||
@@ -754,31 +746,12 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
private void AdjustKarma(IDamageable attacker, float amount)
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
if (Submarine == null) return;
|
||||
if (attacker == null) return;
|
||||
if (attacker is Character)
|
||||
{
|
||||
Character attackerCharacter = attacker as Character;
|
||||
Barotrauma.Networking.Client attackerClient = GameMain.Server.ConnectedClients.Find(c => c.Character == attackerCharacter);
|
||||
if (attackerClient != null)
|
||||
{
|
||||
if (attackerCharacter.TeamID == Submarine.TeamID)
|
||||
{
|
||||
attackerClient.Karma -= amount * 0.001f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
partial void AdjustKarma(IDamageable attacker, float amount);
|
||||
|
||||
public AttackResult AddDamage(Character attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
|
||||
{
|
||||
if (Submarine != null && Submarine.GodMode) return new AttackResult(0.0f, null);
|
||||
if (!prefab.Body || prefab.Platform || Indestructible) return new AttackResult(0.0f, null);
|
||||
if (!Prefab.Body || Prefab.Platform || Indestructible) return new AttackResult(0.0f, null);
|
||||
|
||||
Vector2 transformedPos = worldPosition;
|
||||
if (Submarine != null) transformedPos -= Submarine.Position;
|
||||
@@ -811,16 +784,16 @@ namespace Barotrauma
|
||||
private void SetDamage(int sectionIndex, float damage, Character attacker = null, bool createNetworkEvent = true)
|
||||
{
|
||||
if (Submarine != null && Submarine.GodMode || Indestructible) return;
|
||||
if (!prefab.Body) return;
|
||||
if (!Prefab.Body) return;
|
||||
if (!MathUtils.IsValid(damage)) return;
|
||||
|
||||
damage = MathHelper.Clamp(damage, 0.0f, prefab.Health);
|
||||
|
||||
damage = MathHelper.Clamp(damage, 0.0f, Prefab.Health);
|
||||
|
||||
#if SERVER
|
||||
if (GameMain.Server != null && createNetworkEvent && damage != Sections[sectionIndex].damage)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(this);
|
||||
}
|
||||
|
||||
bool noGaps = true;
|
||||
for (int i = 0; i < Sections.Length; i++)
|
||||
{
|
||||
@@ -830,17 +803,20 @@ namespace Barotrauma
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (damage < prefab.Health * LeakThreshold)
|
||||
|
||||
if (damage < Prefab.Health * LeakThreshold)
|
||||
{
|
||||
if (Sections[sectionIndex].gap != null)
|
||||
{
|
||||
#if SERVER
|
||||
//the structure doesn't have any other gap, log the structure being fixed
|
||||
if (noGaps && attacker != null)
|
||||
{
|
||||
GameServer.Log((Sections[sectionIndex].gap.IsRoomToRoom ? "Inner" : "Outer") + " wall repaired by " + attacker.Name, ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
|
||||
#endif
|
||||
DebugConsole.Log("Removing gap (ID " + Sections[sectionIndex].gap.ID + ", section: " + sectionIndex + ") from wall " + ID);
|
||||
|
||||
//remove existing gap if damage is below leak threshold
|
||||
@@ -884,7 +860,7 @@ namespace Barotrauma
|
||||
gapRect.Height += 20;
|
||||
|
||||
bool horizontalGap = !IsHorizontal;
|
||||
if (prefab.BodyRotation != 0.0f)
|
||||
if (Prefab.BodyRotation != 0.0f)
|
||||
{
|
||||
//rotation within a 90 deg sector (e.g. 100 -> 10, 190 -> 10, -10 -> 80)
|
||||
float sectorizedRotation = MathUtils.WrapAngleTwoPi(BodyRotation) % MathHelper.PiOver2;
|
||||
@@ -908,31 +884,40 @@ namespace Barotrauma
|
||||
DebugConsole.Log("Created gap (ID " + Sections[sectionIndex].gap.ID + ", section: " + sectionIndex + ") on wall " + ID);
|
||||
//AdjustKarma(attacker, 300);
|
||||
|
||||
#if SERVER
|
||||
//the structure didn't have any other gaps yet, log the breach
|
||||
if (noGaps && attacker != null)
|
||||
{
|
||||
GameServer.Log((Sections[sectionIndex].gap.IsRoomToRoom ? "Inner" : "Outer") + " wall breached by " + attacker.Name, ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
float gapOpen = (damage / prefab.Health - LeakThreshold) * (1.0f / (1.0f - LeakThreshold));
|
||||
float gapOpen = (damage / Prefab.Health - LeakThreshold) * (1.0f / (1.0f - LeakThreshold));
|
||||
Sections[sectionIndex].gap.Open = gapOpen;
|
||||
}
|
||||
|
||||
float damageDiff = damage - Sections[sectionIndex].damage;
|
||||
bool hadHole = SectionBodyDisabled(sectionIndex);
|
||||
Sections[sectionIndex].damage = MathHelper.Clamp(damage, 0.0f, prefab.Health);
|
||||
Sections[sectionIndex].damage = MathHelper.Clamp(damage, 0.0f, Prefab.Health);
|
||||
|
||||
//otherwise it's possible to infinitely gain karma by welding fixed things
|
||||
if (attacker != null && damageDiff != 0.0f)
|
||||
{
|
||||
AdjustKarma(attacker, damageDiff);
|
||||
if (damageDiff < 0.0f && GameMain.Client == null)
|
||||
#if CLIENT
|
||||
if (GameMain.Client == null)
|
||||
{
|
||||
attacker.Info.IncreaseSkillLevel("mechanical",
|
||||
-damageDiff * SkillIncreaseMultiplier / Math.Max(attacker.GetSkillLevel("mechanical"), 1.0f),
|
||||
SectionPosition(sectionIndex, true));
|
||||
#endif
|
||||
if (damageDiff < 0.0f)
|
||||
{
|
||||
attacker.Info.IncreaseSkillLevel("mechanical",
|
||||
-damageDiff * SkillIncreaseMultiplier / Math.Max(attacker.GetSkillLevel("mechanical"), 1.0f),
|
||||
SectionPosition(sectionIndex, true));
|
||||
}
|
||||
#if CLIENT
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool hasHole = SectionBodyDisabled(sectionIndex);
|
||||
@@ -1018,7 +1003,7 @@ namespace Barotrauma
|
||||
}
|
||||
if (FlippedX) diffFromCenter = -diffFromCenter;
|
||||
|
||||
Vector2 bodyOffset = ConvertUnits.ToSimUnits(prefab.BodyOffset);
|
||||
Vector2 bodyOffset = ConvertUnits.ToSimUnits(Prefab.BodyOffset);
|
||||
if (FlippedX) { bodyOffset.X = -bodyOffset.X; }
|
||||
if (FlippedY) { bodyOffset.Y = -bodyOffset.Y; }
|
||||
|
||||
@@ -1030,7 +1015,7 @@ namespace Barotrauma
|
||||
//newBody.Position = ConvertUnits.ToSimUnits(new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f));
|
||||
newBody.Friction = 0.5f;
|
||||
newBody.OnCollision += OnWallCollision;
|
||||
newBody.CollisionCategories = (prefab.Platform) ? Physics.CollisionPlatform : Physics.CollisionWall;
|
||||
newBody.CollisionCategories = (Prefab.Platform) ? Physics.CollisionPlatform : Physics.CollisionWall;
|
||||
newBody.UserData = this;
|
||||
|
||||
Vector2 structureCenter = ConvertUnits.ToSimUnits(Position);
|
||||
@@ -1059,27 +1044,11 @@ namespace Barotrauma
|
||||
|
||||
partial void CreateConvexHull(Vector2 position, Vector2 size, float rotation);
|
||||
|
||||
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
|
||||
{
|
||||
for (int i = 0; i < Sections.Length; i++)
|
||||
{
|
||||
msg.WriteRangedSingle(Sections[i].damage / Health, 0.0f, 1.0f, 8);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||
{
|
||||
for (int i = 0; i < Sections.Length; i++)
|
||||
{
|
||||
float damage = msg.ReadRangedSingle(0.0f, 1.0f, 8) * Health;
|
||||
SetDamage(i, damage);
|
||||
}
|
||||
}
|
||||
public override void FlipX(bool relativeToSub)
|
||||
{
|
||||
base.FlipX(relativeToSub);
|
||||
|
||||
if (prefab.CanSpriteFlipX)
|
||||
if (Prefab.CanSpriteFlipX)
|
||||
{
|
||||
SpriteEffects ^= SpriteEffects.FlipHorizontally;
|
||||
}
|
||||
@@ -1105,7 +1074,7 @@ namespace Barotrauma
|
||||
{
|
||||
base.FlipY(relativeToSub);
|
||||
|
||||
if (prefab.CanSpriteFlipY)
|
||||
if (Prefab.CanSpriteFlipY)
|
||||
{
|
||||
SpriteEffects ^= SpriteEffects.FlipVertically;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user