added a way for lua to override people's jobs

This commit is contained in:
Evil Factory
2021-11-30 11:36:00 -03:00
parent 1972772fb3
commit 7c8536127c
3 changed files with 59 additions and 42 deletions
@@ -2260,7 +2260,10 @@ namespace Barotrauma.Networking
AssignJobs(teamClients);
var result = new LuaResult(GameMain.Lua.hook.Call("jobsAssigned"));
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
foreach (Client client in teamClients)
{
client.NeedsMidRoundSync = false;
@@ -2340,59 +2343,61 @@ namespace Barotrauma.Networking
spawnWaypoints = mainSubWaypoints;
}
Debug.Assert(spawnWaypoints.Count == mainSubWaypoints.Count);
for (int i = 0; i < teamClients.Count; i++)
if (!result.Bool())
{
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, isRemotePlayer: true, hasAi: false);
spawnedCharacter.AnimController.Frozen = true;
spawnedCharacter.TeamID = teamID;
teamClients[i].Character = spawnedCharacter;
var characterData = campaign?.GetClientCharacterData(teamClients[i]);
if (characterData == null)
for (int i = 0; i < teamClients.Count; i++)
{
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
if (campaign != null)
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, isRemotePlayer: true, hasAi: false);
spawnedCharacter.AnimController.Frozen = true;
spawnedCharacter.TeamID = teamID;
teamClients[i].Character = spawnedCharacter;
var characterData = campaign?.GetClientCharacterData(teamClients[i]);
if (characterData == null)
{
characterData = campaign.SetClientCharacterData(teamClients[i]);
characterData.HasSpawned = true;
}
}
else
{
if (!characterData.HasItemData && !characterData.CharacterInfo.StartItemsGiven)
{
//clients who've chosen to spawn with the respawn penalty can have CharacterData without inventory data
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
if (campaign != null)
{
characterData = campaign.SetClientCharacterData(teamClients[i]);
characterData.HasSpawned = true;
}
}
else
{
characterData.SpawnInventoryItems(spawnedCharacter, spawnedCharacter.Inventory);
if (!characterData.HasItemData && !characterData.CharacterInfo.StartItemsGiven)
{
//clients who've chosen to spawn with the respawn penalty can have CharacterData without inventory data
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
}
else
{
characterData.SpawnInventoryItems(spawnedCharacter, spawnedCharacter.Inventory);
}
characterData.ApplyHealthData(spawnedCharacter);
characterData.ApplyOrderData(spawnedCharacter);
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
spawnedCharacter.LoadTalents();
characterData.HasSpawned = true;
}
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign && spawnedCharacter.Info != null)
{
spawnedCharacter.Info.SetExperience(Math.Max(spawnedCharacter.Info.ExperiencePoints, mpCampaign.GetSavedExperiencePoints(teamClients[i])));
mpCampaign.ClearSavedExperiencePoints(teamClients[i]);
}
characterData.ApplyHealthData(spawnedCharacter);
characterData.ApplyOrderData(spawnedCharacter);
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
spawnedCharacter.LoadTalents();
characterData.HasSpawned = true;
spawnedCharacter.OwnerClientEndPoint = teamClients[i].Connection.EndPointString;
spawnedCharacter.OwnerClientName = teamClients[i].Name;
}
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign && spawnedCharacter.Info != null)
for (int i = teamClients.Count; i < teamClients.Count + bots.Count; i++)
{
spawnedCharacter.Info.SetExperience(Math.Max(spawnedCharacter.Info.ExperiencePoints, mpCampaign.GetSavedExperiencePoints(teamClients[i])));
mpCampaign.ClearSavedExperiencePoints(teamClients[i]);
Character spawnedCharacter = Character.Create(characterInfos[i], spawnWaypoints[i].WorldPosition, characterInfos[i].Name, isRemotePlayer: false, hasAi: true);
spawnedCharacter.TeamID = teamID;
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
// talents are only avilable for players in online sessions, but modders or someone else might want to have them loaded anyway
spawnedCharacter.LoadTalents();
}
spawnedCharacter.OwnerClientEndPoint = teamClients[i].Connection.EndPointString;
spawnedCharacter.OwnerClientName = teamClients[i].Name;
}
for (int i = teamClients.Count; i < teamClients.Count + bots.Count; i++)
{
Character spawnedCharacter = Character.Create(characterInfos[i], spawnWaypoints[i].WorldPosition, characterInfos[i].Name, isRemotePlayer: false, hasAi: true);
spawnedCharacter.TeamID = teamID;
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
// talents are only avilable for players in online sessions, but modders or someone else might want to have them loaded anyway
spawnedCharacter.LoadTalents();
}
}