(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:
@@ -44,25 +44,29 @@ namespace Barotrauma
|
|||||||
return;
|
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();
|
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;
|
character.SelectedConstruction = null;
|
||||||
}
|
}
|
||||||
else if (character.MemState[0].Interact is Character)
|
else
|
||||||
{
|
{
|
||||||
character.SelectCharacter((Character)character.MemState[0].Interact);
|
if (character.SelectedConstruction != character.MemState[0].SelectedItem)
|
||||||
}
|
|
||||||
else if (character.MemState[0].Interact is Item newSelectedConstruction)
|
|
||||||
{
|
|
||||||
if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction)
|
|
||||||
{
|
{
|
||||||
foreach (var ic in newSelectedConstruction.Components)
|
foreach (var ic in character.MemState[0].SelectedItem.Components)
|
||||||
{
|
{
|
||||||
if (ic.CanBeSelected) ic.Select(character);
|
if (ic.CanBeSelected) ic.Select(character);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
character.SelectedConstruction = newSelectedConstruction;
|
character.SelectedConstruction = character.MemState[0].SelectedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.MemState[0].Animation == AnimController.Animation.CPR)
|
if (character.MemState[0].Animation == AnimController.Animation.CPR)
|
||||||
@@ -169,25 +173,30 @@ namespace Barotrauma
|
|||||||
CharacterStateInfo localPos = character.MemLocalState[localPosIndex];
|
CharacterStateInfo localPos = character.MemLocalState[localPosIndex];
|
||||||
|
|
||||||
//the entity we're interacting with doesn't match the server's
|
//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();
|
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;
|
character.SelectedConstruction = null;
|
||||||
}
|
}
|
||||||
else if (serverPos.Interact is Character)
|
else if (serverPos.SelectedItem != null)
|
||||||
{
|
{
|
||||||
character.SelectCharacter((Character)serverPos.Interact);
|
if (character.SelectedConstruction != serverPos.SelectedItem)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var newSelectedConstruction = (Item)serverPos.Interact;
|
|
||||||
if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction)
|
|
||||||
{
|
{
|
||||||
newSelectedConstruction.TryInteract(character, true, true);
|
serverPos.SelectedItem.TryInteract(character, true, true);
|
||||||
}
|
}
|
||||||
character.SelectedConstruction = newSelectedConstruction;
|
character.SelectedConstruction = serverPos.SelectedItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,12 +30,13 @@ namespace Barotrauma
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var posInfo = new CharacterStateInfo(
|
var posInfo = new CharacterStateInfo(
|
||||||
SimPosition,
|
SimPosition,
|
||||||
AnimController.Collider.Rotation,
|
AnimController.Collider.Rotation,
|
||||||
LastNetworkUpdateID,
|
LastNetworkUpdateID,
|
||||||
AnimController.TargetDir,
|
AnimController.TargetDir,
|
||||||
SelectedCharacter == null ? (Entity)SelectedConstruction : (Entity)SelectedCharacter,
|
SelectedCharacter,
|
||||||
AnimController.Anim);
|
SelectedConstruction,
|
||||||
|
AnimController.Anim);
|
||||||
|
|
||||||
memLocalState.Add(posInfo);
|
memLocalState.Add(posInfo);
|
||||||
|
|
||||||
@@ -187,14 +188,17 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool entitySelected = msg.ReadBoolean();
|
bool entitySelected = msg.ReadBoolean();
|
||||||
Entity selectedEntity = null;
|
Character selectedCharacter = null;
|
||||||
|
Item selectedItem = null;
|
||||||
|
|
||||||
AnimController.Animation animation = AnimController.Animation.None;
|
AnimController.Animation animation = AnimController.Animation.None;
|
||||||
if (entitySelected)
|
if (entitySelected)
|
||||||
{
|
{
|
||||||
ushort entityID = msg.ReadUInt16();
|
ushort characterID = msg.ReadUInt16();
|
||||||
selectedEntity = FindEntityByID(entityID);
|
ushort itemID = msg.ReadUInt16();
|
||||||
if (selectedEntity is Character)
|
selectedCharacter = FindEntityByID(characterID) as Character;
|
||||||
|
selectedItem = FindEntityByID(itemID) as Item;
|
||||||
|
if (selectedCharacter != null)
|
||||||
{
|
{
|
||||||
bool doingCpr = msg.ReadBoolean();
|
bool doingCpr = msg.ReadBoolean();
|
||||||
if (doingCpr && SelectedCharacter != null)
|
if (doingCpr && SelectedCharacter != null)
|
||||||
@@ -235,7 +239,11 @@ namespace Barotrauma
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
if (GameMain.Client.Character == this && AllowInput)
|
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))
|
while (index < memState.Count && NetIdUtils.IdMoreRecent(posInfo.ID, memState[index].ID))
|
||||||
index++;
|
index++;
|
||||||
@@ -243,7 +251,11 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else
|
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)
|
while (index < memState.Count && posInfo.Timestamp > memState[index].Timestamp)
|
||||||
index++;
|
index++;
|
||||||
|
|||||||
@@ -656,13 +656,6 @@ namespace Barotrauma
|
|||||||
msg.Timer -= deltaTime;
|
msg.Timer -= deltaTime;
|
||||||
msg.Pos += msg.Velocity * 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);
|
messages.RemoveAll(m => m.Timer <= 0.0f);
|
||||||
|
|||||||
@@ -362,7 +362,8 @@ namespace Barotrauma
|
|||||||
if (SelectedCharacter != null || SelectedConstruction != null)
|
if (SelectedCharacter != null || SelectedConstruction != null)
|
||||||
{
|
{
|
||||||
tempBuffer.Write(true);
|
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)
|
if (SelectedCharacter != null)
|
||||||
{
|
{
|
||||||
tempBuffer.Write(AnimController.Anim == AnimController.Animation.CPR);
|
tempBuffer.Write(AnimController.Anim == AnimController.Animation.CPR);
|
||||||
|
|||||||
@@ -1217,20 +1217,6 @@ namespace Barotrauma
|
|||||||
valueModifier *= isOpen ? 5 : 1;
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -1249,11 +1235,6 @@ namespace Barotrauma
|
|||||||
if (aggressiveBoarding)
|
if (aggressiveBoarding)
|
||||||
{
|
{
|
||||||
if (character.CurrentHull == null)
|
if (character.CurrentHull == null)
|
||||||
{
|
|
||||||
valueModifier = isOutdoor ? 1 : 0;
|
|
||||||
valueModifier *= isOpen ? 5 : 1;
|
|
||||||
}
|
|
||||||
else if (targetCharacter.CurrentHull != Character.CurrentHull)
|
|
||||||
{
|
{
|
||||||
valueModifier = isOutdoor ? 0 : 1;
|
valueModifier = isOutdoor ? 0 : 1;
|
||||||
valueModifier *= isOpen ? 0 : 1;
|
valueModifier *= isOpen ? 0 : 1;
|
||||||
@@ -1263,10 +1244,6 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (isOpen) //ignore broken and open doors
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (target.Entity is IDamageable targetDamageable && targetDamageable.Health <= 0.0f)
|
else if (target.Entity is IDamageable targetDamageable && targetDamageable.Health <= 0.0f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,25 +9,27 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
public readonly Direction Direction;
|
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 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)
|
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, interact, animation)
|
: 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)
|
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, interact, animation)
|
: 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)
|
: base(pos, rotation, velocity, angularVelocity, ID, time)
|
||||||
{
|
{
|
||||||
Direction = dir;
|
Direction = dir;
|
||||||
Interact = interact;
|
SelectedCharacter = selectedCharacter;
|
||||||
|
SelectedItem = selectedItem;
|
||||||
|
|
||||||
Animation = animation;
|
Animation = animation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -950,6 +950,39 @@ namespace Barotrauma
|
|||||||
|
|
||||||
AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList();
|
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);
|
List.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user