diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index cde80ccc1..0cdb390bb 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -124,6 +124,8 @@ namespace Barotrauma } set { + if (info != null && info != value) info.Remove(); + info = value; if (info != null) info.Character = this; } @@ -1685,6 +1687,8 @@ namespace Barotrauma { base.Remove(); + if (info != null) info.Remove(); + CharacterList.Remove(this); if (controlled == this) controlled = null; diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index ab8e073b8..0b49799f5 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -325,5 +325,10 @@ namespace Barotrauma parentElement.Add(charElement); return charElement; } + + public void Remove() + { + if (headSprite != null) headSprite.Remove(); + } } } diff --git a/Subsurface/Source/Characters/Limb.cs b/Subsurface/Source/Characters/Limb.cs index af8be0cdc..4463aa0b7 100644 --- a/Subsurface/Source/Characters/Limb.cs +++ b/Subsurface/Source/Characters/Limb.cs @@ -286,7 +286,6 @@ namespace Barotrauma damagedSpritePath = damagedSpritePath.Replace("[HEADID]", character.Info.HeadSpriteId.ToString()); } - damagedSprite = new Sprite(subElement, "", damagedSpritePath); break; case "attack": @@ -546,6 +545,8 @@ namespace Barotrauma public void Remove() { sprite.Remove(); + if (damagedSprite != null) damagedSprite.Remove(); + body.Remove(); if (bodyShapeTexture != null) diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 3eaeed503..8c485b99d 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -349,16 +349,16 @@ namespace Barotrauma.Items.Components UpdateConvexHulls(); } - public override void Remove() + protected override void RemoveComponentSpecific() { - base.Remove(); + base.RemoveComponentSpecific(); GameMain.World.RemoveBody(body.FarseerBody); if (linkedGap!=null) linkedGap.Remove(); doorSprite.Remove(); - weldedSprite.Remove(); + if (weldedSprite != null) weldedSprite.Remove(); if (convexHull!=null) convexHull.Remove(); if (convexHull2 != null) convexHull2.Remove(); diff --git a/Subsurface/Source/Items/Components/ItemComponent.cs b/Subsurface/Source/Items/Components/ItemComponent.cs index 18cf9fcc5..d39882f6c 100644 --- a/Subsurface/Source/Items/Components/ItemComponent.cs +++ b/Subsurface/Source/Items/Components/ItemComponent.cs @@ -470,12 +470,19 @@ namespace Barotrauma.Items.Components return false; } - public virtual void Remove() + public void Remove() { - if (loopingSound!=null) + if (loopingSound != null) { Sounds.SoundManager.Stop(loopingSoundIndex); } + + RemoveComponentSpecific(); + } + + protected virtual void RemoveComponentSpecific() + { + } public bool HasRequiredSkills(Character character) diff --git a/Subsurface/Source/Items/Components/ItemContainer.cs b/Subsurface/Source/Items/Components/ItemContainer.cs index 0f59ed56f..0f529c2d9 100644 --- a/Subsurface/Source/Items/Components/ItemContainer.cs +++ b/Subsurface/Source/Items/Components/ItemContainer.cs @@ -247,9 +247,9 @@ namespace Barotrauma.Items.Components itemIds = null; } - public override void Remove() + protected override void RemoveComponentSpecific() { - base.Remove(); + base.RemoveComponentSpecific(); foreach (Item item in Inventory.Items) { diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index a2fe024df..eee114b86 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -321,6 +321,13 @@ namespace Barotrauma.Items.Components new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen); } + protected override void RemoveComponentSpecific() + { + if (pingCircle!=null) pingCircle.Remove(); + if (screenOverlay != null) screenOverlay.Remove(); + + } + public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message) { message.Write(IsActive); diff --git a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs index bc4cb8490..80f6070d6 100644 --- a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs @@ -118,12 +118,7 @@ namespace Barotrauma.Items.Components loadedConnections[i].wireId.CopyTo(Connections[i].wireId, 0); } } - - public override void Remove() - { - base.Remove(); - } - + public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message) { foreach (Connection c in Connections) diff --git a/Subsurface/Source/Items/Components/Signal/LightComponent.cs b/Subsurface/Source/Items/Components/Signal/LightComponent.cs index 4075c8d8a..da087e47d 100644 --- a/Subsurface/Source/Items/Components/Signal/LightComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/LightComponent.cs @@ -145,9 +145,9 @@ namespace Barotrauma.Items.Components //GUI.DrawLine(spriteBatch, center - Vector2.One * range, center + Vector2.One * range, lightColor); } - public override void Remove() + protected override void RemoveComponentSpecific() { - base.Remove(); + base.RemoveComponentSpecific(); light.Remove(); } diff --git a/Subsurface/Source/Items/Components/Signal/WifiComponent.cs b/Subsurface/Source/Items/Components/Signal/WifiComponent.cs index 870f3ddb3..067c6fcbd 100644 --- a/Subsurface/Source/Items/Components/Signal/WifiComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/WifiComponent.cs @@ -46,9 +46,9 @@ namespace Barotrauma.Items.Components } } - public override void Remove() + protected override void RemoveComponentSpecific() { - base.Remove(); + base.RemoveComponentSpecific(); list.Remove(this); } diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index 8f1821305..6e5831beb 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -461,11 +461,11 @@ namespace Barotrauma.Items.Components } - public override void Remove() + protected override void RemoveComponentSpecific() { ClearConnections(); - base.Remove(); + base.RemoveComponentSpecific(); } public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message) diff --git a/Subsurface/Source/Items/Components/Turret.cs b/Subsurface/Source/Items/Components/Turret.cs index ed9118b46..8cf31b3d5 100644 --- a/Subsurface/Source/Items/Components/Turret.cs +++ b/Subsurface/Source/Items/Components/Turret.cs @@ -294,9 +294,9 @@ namespace Barotrauma.Items.Components return availablePower; } - public override void Remove() + protected override void RemoveComponentSpecific() { - base.Remove(); + base.RemoveComponentSpecific(); barrelSprite.Remove(); } diff --git a/Subsurface/Source/Items/Components/Wearable.cs b/Subsurface/Source/Items/Components/Wearable.cs index 7aba939e4..6f267bc20 100644 --- a/Subsurface/Source/Items/Components/Wearable.cs +++ b/Subsurface/Source/Items/Components/Wearable.cs @@ -23,7 +23,7 @@ namespace Barotrauma.Items.Components class Wearable : Pickable { - WearableSprite[] wearableSprite; + WearableSprite[] wearableSprites; LimbType[] limbType; Limb[] limb; @@ -62,7 +62,7 @@ namespace Barotrauma.Items.Components var sprites = element.Elements().Where(x => x.Name.ToString() == "sprite").ToList(); int spriteCount = sprites.Count(); - wearableSprite = new WearableSprite[spriteCount]; + wearableSprites = new WearableSprite[spriteCount]; limbType = new LimbType[spriteCount]; limb = new Limb[spriteCount]; @@ -85,7 +85,7 @@ namespace Barotrauma.Items.Components spritePath = Path.GetDirectoryName( item.Prefab.ConfigFile)+"/"+spritePath; var sprite = new Sprite(subElement, "", spritePath); - wearableSprite[i] = new WearableSprite(sprite, ToolBox.GetAttributeBool(subElement, "hidelimb", false), + wearableSprites[i] = new WearableSprite(sprite, ToolBox.GetAttributeBool(subElement, "hidelimb", false), (LimbType)Enum.Parse(typeof(LimbType), ToolBox.GetAttributeString(subElement, "depthlimb", "None"), true)); @@ -99,7 +99,7 @@ namespace Barotrauma.Items.Components public override void Equip(Character character) { picker = character; - for (int i = 0; i < wearableSprite.Length; i++ ) + for (int i = 0; i < wearableSprites.Length; i++ ) { Limb equipLimb = character.AnimController.GetLimb(limbType[i]); if (equipLimb == null) continue; @@ -118,7 +118,7 @@ namespace Barotrauma.Items.Components limb[i] = equipLimb; equipLimb.WearingItem = this; - equipLimb.WearingItemSprite = wearableSprite[i]; + equipLimb.WearingItemSprite = wearableSprites[i]; } } @@ -135,7 +135,7 @@ namespace Barotrauma.Items.Components public override void Unequip(Character character) { if (picker == null) return; - for (int i = 0; i < wearableSprite.Length; i++) + for (int i = 0; i < wearableSprites.Length; i++) { Limb equipLimb = character.AnimController.GetLimb(limbType[i]); if (equipLimb == null) continue; @@ -162,18 +162,28 @@ namespace Barotrauma.Items.Components item.SetTransform(picker.SimPosition, 0.0f); Item[] containedItems = item.ContainedItems; - + ApplyStatusEffects(ActionType.OnWearing, deltaTime, picker); PlaySound(ActionType.OnWearing, picker.WorldPosition); if (containedItems == null) return; - for (int j = 0; j