Merge pull request #9 from Regalis11/master

0.14.9.0
This commit is contained in:
Evil Factory
2021-08-25 13:18:02 -03:00
committed by GitHub
140 changed files with 1448 additions and 621 deletions
@@ -6,6 +6,11 @@ namespace Barotrauma
{
public bool HasSpawned;
public bool HasItemData
{
get { return itemData != null; }
}
partial void InitProjSpecific(Client client)
{
ClientEndPoint = client.Connection.EndPointString;
@@ -32,6 +37,14 @@ namespace Barotrauma
public void SpawnInventoryItems(Character character, Inventory inventory)
{
if (character == null)
{
throw new System.InvalidOperationException($"Failed to spawn inventory items. Character was null.");
}
if (itemData == null)
{
throw new System.InvalidOperationException($"Failed to spawn inventory items for the character \"{character.Name}\". No saved inventory data.");
}
character.SpawnInventoryItems(inventory, itemData);
}
@@ -172,11 +172,25 @@ namespace Barotrauma
//refresh the character data of clients who are still in the server
foreach (Client c in GameMain.Server.ConnectedClients)
{
if (c.HasSpawned && c.CharacterInfo != null && c.CharacterInfo.CauseOfDeath != null && c.CharacterInfo.CauseOfDeath?.Type != CauseOfDeathType.Disconnected)
{
//the client has opted to spawn this round with Reaper's Tax
if (c.WaitForNextRoundRespawn.HasValue && !c.WaitForNextRoundRespawn.Value)
{
c.CharacterInfo.StartItemsGiven = false;
characterData.RemoveAll(cd => cd.MatchesClient(c));
characterData.Add(new CharacterCampaignData(c, giveRespawnPenaltyAffliction: true));
continue;
}
}
if (c.Character?.Info == null) { continue; }
if (c.Character.IsDead && c.Character.CauseOfDeath?.Type != CauseOfDeathType.Disconnected) { continue; }
if (c.Character.IsDead && c.Character.CauseOfDeath?.Type != CauseOfDeathType.Disconnected)
{
continue;
}
c.CharacterInfo = c.Character.Info;
characterData.RemoveAll(cd => cd.MatchesClient(c));
characterData.Add(new CharacterCampaignData(c));
characterData.Add(new CharacterCampaignData(c));
}
//refresh the character data of clients who aren't in the server anymore
@@ -70,18 +70,20 @@ namespace Barotrauma
{
Item droppedItem = item;
Entity prevOwner = Owner;
Inventory previousInventory = droppedItem.ParentInventory;
droppedItem.Drop(null);
droppedItem.PreviousParentInventory = previousInventory;
var previousInventory = prevOwner switch
var previousCharacterInventory = prevOwner switch
{
Item itemInventory => (itemInventory.FindParentInventory(inventory => inventory is CharacterInventory) as CharacterInventory),
Item itemInventory => itemInventory.FindParentInventory(inventory => inventory is CharacterInventory) as CharacterInventory,
Character character => character.Inventory,
_ => null
};
if (previousInventory != null && previousInventory != c.Character?.Inventory)
if (previousCharacterInventory != null && previousCharacterInventory != c.Character?.Inventory)
{
GameMain.Server?.KarmaManager.OnItemTakenFromPlayer(previousInventory, c, droppedItem);
GameMain.Server?.KarmaManager.OnItemTakenFromPlayer(previousCharacterInventory, c, droppedItem);
}
if (droppedItem.body != null && prevOwner != null)
@@ -109,7 +111,8 @@ namespace Barotrauma
var holdable = item.GetComponent<Holdable>();
if (holdable != null && !holdable.CanBeDeattached()) { continue; }
if (!prevItems.Contains(item) && !item.CanClientAccess(c))
if (!prevItems.Contains(item) && !item.CanClientAccess(c) &&
(c.Character == null || item.PreviousParentInventory == null || !c.Character.CanAccessInventory(item.PreviousParentInventory)))
{
#if DEBUG || UNSTABLE
DebugConsole.NewMessage($"Client {c.Name} failed to pick up item \"{item}\" (parent inventory: {(item.ParentInventory?.Owner.ToString() ?? "null")}). No access.", Color.Yellow);
@@ -10,6 +10,8 @@ namespace Barotrauma
{
private CoroutineHandle logPropertyChangeCoroutine;
public Inventory PreviousParentInventory;
public override Sprite Sprite
{
get { return prefab?.sprite; }
@@ -36,21 +36,21 @@ namespace Barotrauma.MapCreatures.Behavior
msg.Write(Offset.X);
msg.Write(Offset.Y);
}
public void ServerWriteBranchGrowth(IWriteMessage msg, BallastFloraBranch branch, int parentId = -1)
{
var (x, y) = branch.Position;
msg.Write(parentId);
msg.Write((int)branch.ID);
msg.WriteRangedInteger((byte) branch.Type, 0b0000, 0b1111);
msg.WriteRangedInteger((byte) branch.Sides, 0b0000, 0b1111);
msg.WriteRangedInteger((byte)branch.Type, 0b0000, 0b1111);
msg.WriteRangedInteger((byte)branch.Sides, 0b0000, 0b1111);
msg.WriteRangedInteger(branch.FlowerConfig.Serialize(), 0, 0xFFF);
msg.WriteRangedInteger(branch.LeafConfig.Serialize(), 0, 0xFFF);
msg.Write((ushort) branch.MaxHealth);
msg.Write((int) (x / VineTile.Size));
msg.Write((int) (y / VineTile.Size));
msg.Write((ushort)branch.MaxHealth);
msg.Write((int)(x / VineTile.Size));
msg.Write((int)(y / VineTile.Size));
}
public void ServerWriteBranchDamage(IWriteMessage msg, BallastFloraBranch branch, float damage)
{
msg.Write((int)branch.ID);
@@ -2346,7 +2346,15 @@ namespace Barotrauma.Networking
}
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]);
@@ -3074,13 +3082,7 @@ namespace Barotrauma.Networking
case ChatMessageType.Radio:
case ChatMessageType.Order:
if (senderCharacter == null) { return; }
//return if senderCharacter doesn't have a working radio
var radio = senderCharacter.Inventory?.AllItems.FirstOrDefault(i => i.GetComponent<WifiComponent>() != null);
if (radio == null || !senderCharacter.HasEquippedItem(radio)) { return; }
senderRadio = radio.GetComponent<WifiComponent>();
if (!senderRadio.CanTransmit()) { return; }
if (!ChatMessage.CanUseRadio(senderCharacter, out senderRadio)) { return; }
break;
case ChatMessageType.Dead:
//character still alive and capable of speaking -> dead chat not allowed
@@ -432,11 +432,7 @@ namespace Barotrauma.Networking
var characterData = campaign?.GetClientCharacterData(clients[i]);
if (characterData != null && Level.Loaded?.Type != LevelData.LevelType.Outpost && characterData.HasSpawned)
{
var respawnPenaltyAffliction = AfflictionPrefab.List.FirstOrDefault(a => a.AfflictionType.Equals("respawnpenalty", StringComparison.OrdinalIgnoreCase));
if (respawnPenaltyAffliction != null)
{
character.CharacterHealth.ApplyAffliction(targetLimb: null, respawnPenaltyAffliction.Instantiate(10.0f));
}
GiveRespawnPenaltyAffliction(character);
}
if (characterData == null || characterData.HasSpawned)
@@ -451,7 +447,14 @@ namespace Barotrauma.Networking
}
else
{
characterData.SpawnInventoryItems(character, character.Inventory);
if (characterData.HasItemData)
{
characterData.SpawnInventoryItems(character, character.Inventory);
}
else
{
character.GiveJobItems(mainSubSpawnPoints[i]);
}
characterData.ApplyHealthData(character);
character.GiveIdCardTags(mainSubSpawnPoints[i]);
characterData.HasSpawned = true;
@@ -78,6 +78,7 @@ namespace Barotrauma
List<Item> suitableItems = new List<Item>();
foreach (Item item in Item.ItemList)
{
if (item.HiddenInGame || item.NonInteractable || item.NonPlayerTeamInteractable) { continue; }
if (item.Submarine == null || traitors.All(traitor => item.Submarine.TeamID != traitor.Character.TeamID))
{
continue;