(5218c43a0) Server sends the IDs of both selected characters and selected items to the clients. Previously this wasn't needed, because it wasn't possible to have both a character and an item selected at the same time. Fixes characters floating mid-air client-side when dragging others up stairs, and probably some other undiscovered bugs as well.

This commit is contained in:
Joonas Rikkonen
2019-04-01 22:50:11 +03:00
parent ae6b797d73
commit d511ecd4e3
7 changed files with 97 additions and 70 deletions

View File

@@ -44,25 +44,29 @@ namespace Barotrauma
return;
}
if (character.MemState[0].Interact == null || character.MemState[0].Interact.Removed)
if (character.MemState[0].SelectedCharacter == null || character.MemState[0].SelectedCharacter.Removed)
{
character.DeselectCharacter();
}
else if (character.MemState[0].SelectedCharacter != null)
{
character.SelectCharacter(character.MemState[0].SelectedCharacter);
}
if (character.MemState[0].SelectedItem == null || character.MemState[0].SelectedItem.Removed)
{
character.SelectedConstruction = null;
}
else if (character.MemState[0].Interact is Character)
else
{
character.SelectCharacter((Character)character.MemState[0].Interact);
}
else if (character.MemState[0].Interact is Item newSelectedConstruction)
{
if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction)
if (character.SelectedConstruction != character.MemState[0].SelectedItem)
{
foreach (var ic in newSelectedConstruction.Components)
foreach (var ic in character.MemState[0].SelectedItem.Components)
{
if (ic.CanBeSelected) ic.Select(character);
}
}
character.SelectedConstruction = newSelectedConstruction;
character.SelectedConstruction = character.MemState[0].SelectedItem;
}
if (character.MemState[0].Animation == AnimController.Animation.CPR)
@@ -169,25 +173,30 @@ namespace Barotrauma
CharacterStateInfo localPos = character.MemLocalState[localPosIndex];
//the entity we're interacting with doesn't match the server's
if (localPos.Interact != serverPos.Interact)
if (localPos.SelectedCharacter != serverPos.SelectedCharacter)
{
if (serverPos.Interact == null || serverPos.Interact.Removed)
if (serverPos.SelectedCharacter == null || serverPos.SelectedCharacter.Removed)
{
character.DeselectCharacter();
}
else if (serverPos.SelectedCharacter != null)
{
character.SelectCharacter(serverPos.SelectedCharacter);
}
}
if (localPos.SelectedItem != serverPos.SelectedItem)
{
if (serverPos.SelectedItem == null || serverPos.SelectedItem.Removed)
{
character.SelectedConstruction = null;
}
else if (serverPos.Interact is Character)
else if (serverPos.SelectedItem != null)
{
character.SelectCharacter((Character)serverPos.Interact);
}
else
{
var newSelectedConstruction = (Item)serverPos.Interact;
if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction)
if (character.SelectedConstruction != serverPos.SelectedItem)
{
newSelectedConstruction.TryInteract(character, true, true);
serverPos.SelectedItem.TryInteract(character, true, true);
}
character.SelectedConstruction = newSelectedConstruction;
character.SelectedConstruction = serverPos.SelectedItem;
}
}

View File

@@ -30,12 +30,13 @@ namespace Barotrauma
else
{
var posInfo = new CharacterStateInfo(
SimPosition,
AnimController.Collider.Rotation,
LastNetworkUpdateID,
AnimController.TargetDir,
SelectedCharacter == null ? (Entity)SelectedConstruction : (Entity)SelectedCharacter,
AnimController.Anim);
SimPosition,
AnimController.Collider.Rotation,
LastNetworkUpdateID,
AnimController.TargetDir,
SelectedCharacter,
SelectedConstruction,
AnimController.Anim);
memLocalState.Add(posInfo);
@@ -187,14 +188,17 @@ namespace Barotrauma
}
bool entitySelected = msg.ReadBoolean();
Entity selectedEntity = null;
Character selectedCharacter = null;
Item selectedItem = null;
AnimController.Animation animation = AnimController.Animation.None;
if (entitySelected)
{
ushort entityID = msg.ReadUInt16();
selectedEntity = FindEntityByID(entityID);
if (selectedEntity is Character)
ushort characterID = msg.ReadUInt16();
ushort itemID = msg.ReadUInt16();
selectedCharacter = FindEntityByID(characterID) as Character;
selectedItem = FindEntityByID(itemID) as Item;
if (selectedCharacter != null)
{
bool doingCpr = msg.ReadBoolean();
if (doingCpr && SelectedCharacter != null)
@@ -235,7 +239,11 @@ namespace Barotrauma
int index = 0;
if (GameMain.Client.Character == this && AllowInput)
{
var posInfo = new CharacterStateInfo(pos, rotation, networkUpdateID, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
var posInfo = new CharacterStateInfo(
pos, rotation,
networkUpdateID,
facingRight ? Direction.Right : Direction.Left,
selectedCharacter, selectedItem, animation);
while (index < memState.Count && NetIdUtils.IdMoreRecent(posInfo.ID, memState[index].ID))
index++;
@@ -243,7 +251,11 @@ namespace Barotrauma
}
else
{
var posInfo = new CharacterStateInfo(pos, rotation, linearVelocity, angularVelocity, sendingTime, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
var posInfo = new CharacterStateInfo(
pos, rotation,
linearVelocity, angularVelocity,
sendingTime, facingRight ? Direction.Right : Direction.Left,
selectedCharacter, selectedItem, animation);
while (index < memState.Count && posInfo.Timestamp > memState[index].Timestamp)
index++;

View File

@@ -656,13 +656,6 @@ namespace Barotrauma
msg.Timer -= deltaTime;
msg.Pos += msg.Velocity * deltaTime;
}
foreach (GUIMessage msg in messages)
{
if (!msg.WorldSpace) continue;
msg.Timer -= deltaTime;
msg.Pos += msg.Velocity * deltaTime;
}
}
messages.RemoveAll(m => m.Timer <= 0.0f);

View File

@@ -362,7 +362,8 @@ namespace Barotrauma
if (SelectedCharacter != null || SelectedConstruction != null)
{
tempBuffer.Write(true);
tempBuffer.Write(SelectedCharacter != null ? SelectedCharacter.ID : SelectedConstruction.ID);
tempBuffer.Write(SelectedCharacter != null ? SelectedCharacter.ID : NullEntityID);
tempBuffer.Write(SelectedConstruction != null ? SelectedConstruction.ID : NullEntityID);
if (SelectedCharacter != null)
{
tempBuffer.Write(AnimController.Anim == AnimController.Animation.CPR);

View File

@@ -1217,20 +1217,6 @@ namespace Barotrauma
valueModifier *= isOpen ? 5 : 1;
}
}
else
{
// Ignore disabled walls
bool isDisabled = true;
for (int i = 0; i < s.Sections.Length; i++)
{
valueModifier = isOutdoor ? 0 : 1;
valueModifier *= isOpen ? 0 : 1;
}
if (isDisabled)
{
valueModifier = 0;
}
}
}
else
{
@@ -1249,11 +1235,6 @@ namespace Barotrauma
if (aggressiveBoarding)
{
if (character.CurrentHull == null)
{
valueModifier = isOutdoor ? 1 : 0;
valueModifier *= isOpen ? 5 : 1;
}
else if (targetCharacter.CurrentHull != Character.CurrentHull)
{
valueModifier = isOutdoor ? 0 : 1;
valueModifier *= isOpen ? 0 : 1;
@@ -1263,10 +1244,6 @@ namespace Barotrauma
{
continue;
}
else if (isOpen) //ignore broken and open doors
{
continue;
}
}
else if (target.Entity is IDamageable targetDamageable && targetDamageable.Health <= 0.0f)
{

View File

@@ -9,25 +9,27 @@ namespace Barotrauma
{
public readonly Direction Direction;
public readonly Entity Interact; //the entity being interacted with
public readonly Character SelectedCharacter;
public readonly Item SelectedItem;
public readonly AnimController.Animation Animation;
public CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, velocity, angularVelocity, 0, time, dir, interact, animation)
public CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, float time, Direction dir, Character selectedCharacter, Item selectedItem, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, velocity, angularVelocity, 0, time, dir, selectedCharacter, selectedItem, animation)
{
}
public CharacterStateInfo(Vector2 pos, float? rotation, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, Vector2.Zero, 0.0f, ID, 0.0f, dir, interact, animation)
public CharacterStateInfo(Vector2 pos, float? rotation, UInt16 ID, Direction dir, Character selectedCharacter, Item selectedItem, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, Vector2.Zero, 0.0f, ID, 0.0f, dir, selectedCharacter, selectedItem, animation)
{
}
protected CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, UInt16 ID, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
protected CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, UInt16 ID, float time, Direction dir, Character selectedCharacter, Item selectedItem, AnimController.Animation animation = AnimController.Animation.None)
: base(pos, rotation, velocity, angularVelocity, ID, time)
{
Direction = dir;
Interact = interact;
SelectedCharacter = selectedCharacter;
SelectedItem = selectedItem;
Animation = animation;
}

View File

@@ -950,6 +950,39 @@ namespace Barotrauma
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
if (sprite == null)
{
DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!");
#if SERVER
sprite = new Sprite("", Vector2.Zero);
sprite.SourceRect = new Rectangle(0, 0, 32, 32);
#else
sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null)
{
Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2
};
#endif
size = sprite.size;
sprite.EntityID = identifier;
}
if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier))
{
DebugConsole.ThrowError(
"Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading.");
}
if (!string.IsNullOrEmpty(identifier))
{
MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier);
if (existingPrefab != null)
{
DebugConsole.ThrowError(
"Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!");
}
}
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
List.Add(this);
}