Added a method for changing a client's controlled character. Clients now get back control if their character is revived via the debug console.

+ It's possible to give clients control of monsters, which should add some new gameplay possibilitie. ;)
This commit is contained in:
Joonas Rikkonen
2017-06-10 15:07:10 +03:00
parent 8886409d56
commit 9b0d7c1020
6 changed files with 151 additions and 46 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ namespace Barotrauma
{
base.Update(cam, deltaTime);
if (!Enabled) return;
if (!Enabled || IsRemotePlayer) return;
float dist = Vector2.DistanceSquared(cam.WorldViewCenter, WorldPosition);
if (dist > 8000.0f * 8000.0f)
+4 -4
View File
@@ -64,7 +64,7 @@ namespace Barotrauma
public Hull PreviousHull = null;
public Hull CurrentHull = null;
public readonly bool IsRemotePlayer;
public bool IsRemotePlayer;
private CharacterInventory inventory;
@@ -810,7 +810,7 @@ namespace Barotrauma
ViewTarget = null;
if (!AllowInput) return;
if (!(this is AICharacter) || controlled == this)
if (!(this is AICharacter) || controlled == this || IsRemotePlayer)
{
Vector2 targetMovement = GetTargetMovement();
@@ -1289,7 +1289,7 @@ namespace Barotrauma
{
foreach (Character c in CharacterList)
{
if (!(c is AICharacter)) continue;
if (!(c is AICharacter) && !c.IsRemotePlayer) continue;
if (GameMain.Server != null)
{
@@ -1432,7 +1432,7 @@ namespace Barotrauma
selectedConstruction = null;
}
if (controlled != this && !(this is AICharacter))
if (controlled != this && (!(this is AICharacter) || IsRemotePlayer))
{
if (!LockHands)
{
@@ -82,7 +82,7 @@ namespace Barotrauma
private bool networkUpdateSent;
public bool isSynced = false;
public List<CharacterStateInfo> MemState
{
get { return memState; }
@@ -93,6 +93,16 @@ namespace Barotrauma
get { return memLocalState; }
}
public void ResetNetState()
{
memInput.Clear();
memState.Clear();
memLocalState.Clear();
LastNetworkUpdateID = 0;
LastProcessedID = 0;
}
private void UpdateNetInput()
{
if (this != Character.Controlled)
@@ -112,7 +122,7 @@ namespace Barotrauma
}
}
}
else if (GameMain.Server != null && !(this is AICharacter))
else if (GameMain.Server != null && (!(this is AICharacter) || IsRemotePlayer))
{
if (!AllowInput)
{
@@ -387,17 +397,24 @@ namespace Barotrauma
if (extraData != null)
{
switch ((NetEntityEvent.Type)extraData[0])
{
case NetEntityEvent.Type.InventoryState:
msg.Write(true);
msg.WriteRangedInteger(0, 2, 0);
inventory.ClientWrite(msg, extraData);
break;
case NetEntityEvent.Type.Control:
msg.WriteRangedInteger(0, 2, 1);
Client owner = ((Client)extraData[1]);
msg.Write(owner == null ? (byte)0 : owner.ID);
break;
case NetEntityEvent.Type.Status:
msg.Write(false);
msg.WriteRangedInteger(0, 2, 2);
WriteStatus(msg);
break;
}
msg.WritePadBits();
}
else
{
@@ -573,15 +590,36 @@ namespace Barotrauma
break;
case ServerNetObject.ENTITY_EVENT:
bool isInventoryUpdate = msg.ReadBoolean();
int eventType = msg.ReadRangedInteger(0, 2);
switch (eventType)
{
case 0:
inventory.ClientRead(type, msg, sendingTime);
break;
case 1:
byte ownerID = msg.ReadByte();
ResetNetState();
if (ownerID == GameMain.Client.ID)
{
if (controlled != null)
{
LastNetworkUpdateID = controlled.LastNetworkUpdateID;
}
if (isInventoryUpdate)
{
inventory.ClientRead(type, msg, sendingTime);
}
else
{
ReadStatus(msg);
controlled = this;
IsRemotePlayer = false;
GameMain.Client.Character = this;
}
else if (controlled == this)
{
controlled = null;
IsRemotePlayer = ownerID > 0;
}
break;
case 2:
ReadStatus(msg);
break;
}
break;