Host can spawn in team 2 + relay component state syncing
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
public override bool AssignTeamIDs(List<Client> clients)
|
||||
public override bool AssignTeamIDs(List<Client> clients,out int hostTeam)
|
||||
{
|
||||
List<Client> randList = new List<Client>(clients);
|
||||
for (int i = 0; i < randList.Count; i++)
|
||||
@@ -51,6 +51,18 @@ namespace Barotrauma
|
||||
randList[i].TeamID = 2;
|
||||
}
|
||||
}
|
||||
if (halfPlayers*2==randList.Count)
|
||||
{
|
||||
hostTeam = Rand.Range(1, 2);
|
||||
}
|
||||
else if (halfPlayers*2<randList.Count)
|
||||
{
|
||||
hostTeam = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostTeam = 2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace Barotrauma
|
||||
|
||||
public virtual void Update(float deltaTime) { }
|
||||
|
||||
public virtual bool AssignTeamIDs(List<Networking.Client> clients) { clients.ForEach(client => { client.TeamID = 1; }); return false; }
|
||||
public virtual bool AssignTeamIDs(List<Networking.Client> clients,out int hostTeam) { clients.ForEach(client => { client.TeamID = 1; }); hostTeam = 1; return false; }
|
||||
|
||||
public void ShowMessage(int index)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
private float maxPower;
|
||||
|
||||
private float lastReceivedMessage;
|
||||
|
||||
[Editable, HasDefaultValue(1000.0f, true)]
|
||||
public float MaxPower
|
||||
{
|
||||
@@ -73,13 +75,43 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else if (connection.Name == "toggle")
|
||||
{
|
||||
IsOn = !IsOn;
|
||||
SetState(!IsOn,false,true);
|
||||
}
|
||||
else if (connection.Name == "set_state")
|
||||
{
|
||||
IsOn = signal != "0";
|
||||
SetState(signal != "0", false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(bool on, bool isNetworkMessage, bool sendNetworkMessage = false)
|
||||
{
|
||||
if (GameMain.Client != null && !isNetworkMessage) return;
|
||||
|
||||
IsOn = on;
|
||||
if (sendNetworkMessage)
|
||||
{
|
||||
item.NewComponentEvent(this, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
|
||||
{
|
||||
message.Write(IsOn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime)
|
||||
{
|
||||
if (sendingTime < lastReceivedMessage) return;
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastReceivedMessage = sendingTime;
|
||||
|
||||
SetState(message.ReadBoolean(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -892,8 +892,9 @@ namespace Barotrauma.Networking
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
int teamCount = 1;
|
||||
int hostTeam = 1;
|
||||
if (GameMain.GameSession.gameMode.Mission != null &&
|
||||
GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients))
|
||||
GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients,out hostTeam))
|
||||
{
|
||||
teamCount = 2;
|
||||
}
|
||||
@@ -913,7 +914,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (!teamClients.Any() && teamID > 1) continue;
|
||||
|
||||
AssignJobs(teamClients, teamID==1);
|
||||
AssignJobs(teamClients, teamID==hostTeam);
|
||||
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
|
||||
@@ -931,7 +932,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
//host's character
|
||||
if (characterInfo != null && teamID == 1)
|
||||
if (characterInfo != null && teamID == hostTeam)
|
||||
{
|
||||
characterInfo.Job = new Job(GameMain.NetLobbyScreen.JobPreferences[0]);
|
||||
characterInfos.Add(characterInfo);
|
||||
@@ -951,7 +952,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
//host plays in team 1
|
||||
if (characterInfo != null && teamID == 1)
|
||||
if (characterInfo != null && teamID == hostTeam)
|
||||
{
|
||||
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
|
||||
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
|
||||
|
||||
Reference in New Issue
Block a user