From 1a0451d0a87ac1cf66f58dd7cd3e66564cd681d2 Mon Sep 17 00:00:00 2001 From: Regalis Date: Fri, 29 Jul 2016 21:22:08 +0300 Subject: [PATCH] - items can be equipped/unequipped by double clicking - items inside the respawn shuttle - using the teleport method when moving a character into or out from a sub - removing dropped items from the respawn shuttle when respawning --- .../Source/Characters/Animation/Ragdoll.cs | 8 ++++---- Subsurface/Source/Characters/Character.cs | 5 +++++ Subsurface/Source/Items/CharacterInventory.cs | 18 ++++++++++++++++-- Subsurface/Source/Networking/RespawnManager.cs | 12 +++++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 6e98e400f..0e55b948d 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -586,18 +586,18 @@ namespace Barotrauma if (Gap.FindAdjacent(currentHull.ConnectedGaps, findPos, 150.0f) != null) return; - Teleport(ConvertUnits.ToSimUnits(currentHull.Submarine.Position), currentHull.Submarine.Velocity, true); + Teleport(ConvertUnits.ToSimUnits(currentHull.Submarine.Position), currentHull.Submarine.Velocity); } //out -> in else if (currentHull == null && newHull.Submarine != null) { - Teleport(-ConvertUnits.ToSimUnits(newHull.Submarine.Position), -newHull.Submarine.Velocity, false); + Teleport(-ConvertUnits.ToSimUnits(newHull.Submarine.Position), -newHull.Submarine.Velocity); } //from one sub to another else if (newHull != null && currentHull != null && newHull.Submarine != currentHull.Submarine) { Teleport(ConvertUnits.ToSimUnits(currentHull.Submarine.Position - newHull.Submarine.Position), - Vector2.Zero, false); + Vector2.Zero); } } @@ -608,7 +608,7 @@ namespace Barotrauma UpdateCollisionCategories(); } - private void Teleport(Vector2 moveAmount, Vector2 velocityChange, bool inToOut) + public void Teleport(Vector2 moveAmount, Vector2 velocityChange) { foreach (Limb limb in Limbs) { diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 955d8c6ad..83ad90d67 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1782,6 +1782,11 @@ namespace Barotrauma pos.X = message.ReadFloat(); pos.Y = message.ReadFloat(); + if (inSub != (Submarine != null)) + { + AnimController.Teleport(pos - SimPosition, Vector2.Zero); + } + if (inSub) { //AnimController.FindHull(ConvertUnits.ToDisplayUnits(pos) - Submarine.Loaded.WorldPosition); diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 2052283bb..0bfcad17f 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -81,7 +82,7 @@ namespace Barotrauma default: SlotPositions[i] = new Vector2( spacing * 2 + rectWidth + (spacing + rectWidth) * ((i - 6)%5), - GameMain.GraphicsHeight - (spacing + rectHeight) * ((i>10) ? 2 : 1)); + GameMain.GraphicsHeight - (spacing + rectHeight) * ((i>10) ? 1 : 2)); break; } } @@ -143,7 +144,7 @@ namespace Barotrauma /// public override bool TryPutItem(Item item, List allowedSlots = null, bool createNetworkEvent = true) { - if (allowedSlots == null) return false; + if (allowedSlots == null || ! allowedSlots.Any()) return false; //try to place the item in LimBlot.Any slot if that's allowed if (allowedSlots.Contains(InvSlotType.Any)) @@ -303,6 +304,19 @@ namespace Barotrauma { character.SelectedCharacter.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true); } + else //doubleclicked and no other inventory is selected + { + //not equipped -> attempt to equip + if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any)) + { + TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true); + } + //equipped -> attempt to unequip + else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any)) + { + TryPutItem(doubleClickedItem, new List() { InvSlotType.Any }, true); + } + } } } diff --git a/Subsurface/Source/Networking/RespawnManager.cs b/Subsurface/Source/Networking/RespawnManager.cs index 08584b5e7..0d2dfa017 100644 --- a/Subsurface/Source/Networking/RespawnManager.cs +++ b/Subsurface/Source/Networking/RespawnManager.cs @@ -314,6 +314,16 @@ namespace Barotrauma.Networking shuttleTransportTimer = maxTransportTime; shuttleReturnTimer = maxTransportTime; + foreach (Item item in Item.ItemList) + { + if (item.Submarine != respawnShuttle) continue; + + if (item.body != null && item.body.Enabled && item.ParentInventory == null) + { + Item.Remover.QueueItem(item); + } + } + foreach (Structure wall in Structure.WallList) { if (wall.Submarine != respawnShuttle) continue; @@ -397,7 +407,7 @@ namespace Barotrauma.Networking var divingSuit = new Item(divingSuitPrefab, pos, respawnShuttle); var oxyTank = new Item(oxyPrefab, pos, respawnShuttle); - oxyTank.Combine(divingSuit); + divingSuit.Combine(oxyTank); spawnedItems.Add(divingSuit); spawnedItems.Add(oxyTank);