Clients notify the server when they "give in" (i.e. kill their character when unconscious)
This commit is contained in:
@@ -264,8 +264,15 @@ namespace Barotrauma
|
|||||||
GUIComponent.ForceMouseOn(null);
|
GUIComponent.ForceMouseOn(null);
|
||||||
if (Character.Controlled != null)
|
if (Character.Controlled != null)
|
||||||
{
|
{
|
||||||
Character.Controlled.Kill(Character.Controlled.CauseOfDeath);
|
if (GameMain.Client != null)
|
||||||
Character.Controlled = null;
|
{
|
||||||
|
GameMain.Client.CreateEntityEvent(Character.Controlled, new object[] { NetEntityEvent.Type.Status });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Character.Controlled.Kill(Character.Controlled.CauseOfDeath);
|
||||||
|
Character.Controlled = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -235,15 +235,19 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (extraData != null)
|
if (extraData != null)
|
||||||
{
|
{
|
||||||
if ((NetEntityEvent.Type)extraData[0] == NetEntityEvent.Type.InventoryState)
|
switch ((NetEntityEvent.Type)extraData[0])
|
||||||
{
|
{
|
||||||
msg.Write(true);
|
case NetEntityEvent.Type.InventoryState:
|
||||||
inventory.ClientWrite(msg, extraData);
|
msg.WriteRangedInteger(0, 2, 0);
|
||||||
}
|
inventory.ClientWrite(msg, extraData);
|
||||||
else if ((NetEntityEvent.Type)extraData[0] == NetEntityEvent.Type.Repair)
|
break;
|
||||||
{
|
case NetEntityEvent.Type.Repair:
|
||||||
msg.Write(false);
|
msg.WriteRangedInteger(0, 2, 1);
|
||||||
msg.Write(AnimController.Anim == AnimController.Animation.CPR);
|
msg.Write(AnimController.Anim == AnimController.Animation.CPR);
|
||||||
|
break;
|
||||||
|
case NetEntityEvent.Type.Status:
|
||||||
|
msg.WriteRangedInteger(0, 2, 2);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
msg.WritePadBits();
|
msg.WritePadBits();
|
||||||
}
|
}
|
||||||
@@ -338,24 +342,41 @@ namespace Barotrauma
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ClientNetObject.ENTITY_STATE:
|
case ClientNetObject.ENTITY_STATE:
|
||||||
bool isInventoryUpdate = msg.ReadBoolean();
|
int eventType = msg.ReadRangedInteger(0,2);
|
||||||
if (isInventoryUpdate)
|
switch (eventType)
|
||||||
{
|
{
|
||||||
inventory.ServerRead(type, msg, c);
|
case 0:
|
||||||
}
|
inventory.ServerRead(type, msg, c);
|
||||||
else
|
break;
|
||||||
{
|
case 1:
|
||||||
if (c.Character != this)
|
if (c.Character != this)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
DebugConsole.Log("Received a character update message from a client who's not controlling the character");
|
DebugConsole.Log("Received a character update message from a client who's not controlling the character");
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool doingCPR = msg.ReadBoolean();
|
||||||
|
AnimController.Anim = doingCPR ? AnimController.Animation.CPR : AnimController.Animation.None;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (c.Character != this)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
DebugConsole.Log("Received a character update message from a client who's not controlling the character");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsUnconscious)
|
||||||
|
{
|
||||||
|
Kill(lastAttackCauseOfDeath);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
bool doingCPR = msg.ReadBoolean();
|
|
||||||
AnimController.Anim = doingCPR ? AnimController.Animation.CPR : AnimController.Animation.None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.ReadPadBits();
|
msg.ReadPadBits();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,13 +107,21 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
foreach (BufferedEvent bufferedEvent in bufferedEvents)
|
foreach (BufferedEvent bufferedEvent in bufferedEvents)
|
||||||
{
|
{
|
||||||
if (bufferedEvent.Character == null)
|
if (bufferedEvent.Character == null || bufferedEvent.Character.IsDead)
|
||||||
{
|
{
|
||||||
bufferedEvent.IsProcessed = true;
|
bufferedEvent.IsProcessed = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NetIdUtils.IdMoreRecent(bufferedEvent.CharacterStateID, bufferedEvent.Character.LastProcessedID)) continue;
|
//delay reading the events until the inputs for the corresponding frame have been processed
|
||||||
|
|
||||||
|
//UNLESS the character is unconscious, in which case we'll read the messages immediately (because further inputs will be ignored)
|
||||||
|
//atm the "give in" command is the only thing unconscious characters can do, other types of events are ignored
|
||||||
|
if (!bufferedEvent.Character.IsUnconscious &&
|
||||||
|
NetIdUtils.IdMoreRecent(bufferedEvent.CharacterStateID, bufferedEvent.Character.LastProcessedID))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user