Unstable 0.1400.8.0

This commit is contained in:
Markus Isberg
2021-08-13 17:52:45 +09:00
parent 47707c824a
commit 27dd9e6022
38 changed files with 183 additions and 113 deletions
@@ -2527,9 +2527,8 @@ namespace Barotrauma
// Don't target items that we own.
// This is a rare case, and almost entirely related to Humanhusks, so let's check it last to reduce unnecessary checks (although the check shouldn't be expensive)
if (owner == character) { continue; }
if (owner != null && IsFriendly(Character, owner))
if (owner != null && (IsFriendly(Character, owner) || owner.AiTarget != null && ignoredTargets.Contains(owner.AiTarget)))
{
// If the item is held by a friendly character, ignore it.
continue;
}
}
@@ -480,19 +480,18 @@ namespace Barotrauma
isCurrentObjectiveFindSafety ||
Character.AnimController.InWater ||
Character.AnimController.HeadInWater ||
Character.CurrentHull == null ||
Character.Submarine == null ||
(Character.Submarine.TeamID != Character.TeamID && !Character.IsEscorted) ||
ObjectiveManager.CurrentObjective.GetSubObjectivesRecursive(true).Any(o => o.KeepDivingGearOn);
ObjectiveManager.CurrentObjective.GetSubObjectivesRecursive(true).Any(o => o.KeepDivingGearOn) ||
Character.CurrentHull.OxygenPercentage < HULL_LOW_OXYGEN_PERCENTAGE + 10;
bool IsOrderedToWait() => Character.IsOnPlayerTeam && ObjectiveManager.CurrentOrder is AIObjectiveGoTo goTo && goTo.Target == Character;
bool removeDivingSuit = !shouldKeepTheGearOn && !IsOrderedToWait();
if (oxygenLow && Character.CurrentHull.Oxygen > 0 && (!isCurrentObjectiveFindSafety || Character.OxygenAvailable < 1))
{
shouldKeepTheGearOn = false;
// Remove the suit before we pass out
removeDivingSuit = true;
}
else if (Character.CurrentHull.OxygenPercentage < HULL_LOW_OXYGEN_PERCENTAGE + 10)
{
shouldKeepTheGearOn = true;
}
bool removeDivingSuit = !shouldKeepTheGearOn && Character.Submarine?.TeamID == Character.TeamID && (!(ObjectiveManager.CurrentOrder is AIObjectiveGoTo goTo) || goTo.Target != Character);
bool takeMaskOff = !shouldKeepTheGearOn;
if (!shouldKeepTheGearOn && !oxygenLow)
{
@@ -242,7 +242,7 @@ namespace Barotrauma
Character followTarget = Target as Character;
bool needsDivingSuit = targetIsOutside;
bool needsDivingGear = needsDivingSuit || HumanAIController.NeedsDivingGear(targetHull, out needsDivingSuit);
if (!needsDivingGear && mimic)
if (mimic)
{
if (HumanAIController.HasDivingSuit(followTarget))
{
@@ -312,7 +312,7 @@ namespace Barotrauma
}
}
}
if (itemNameList.Count > 0)
if (itemNameList.Any())
{
string itemListStr = "";
if (itemNameList.Count == 1)
@@ -342,12 +342,17 @@ namespace Barotrauma
}
});
}
else if (cprSuitability <= 0)
{
character.Speak(TextManager.GetWithVariable("dialogcannottreatpatient", "[name]", targetCharacter.DisplayName, formatCapitals: false), identifier: "cannottreatpatient", minDurationBetweenSimilar: 20.0f);
Abandon = true;
}
}
}
else if (!targetCharacter.IsUnconscious)
{
//no suitable treatments found, not inside our own sub (= can't search for more treatments), the target isn't unconscious (= can't give CPR)
// -> abandon
character.Speak(TextManager.GetWithVariable("dialogcannottreatpatient", "[name]", targetCharacter.DisplayName, formatCapitals: false), identifier: "cannottreatpatient", minDurationBetweenSimilar: 20.0f);
Abandon = true;
return;
}
@@ -2708,25 +2708,18 @@ namespace Barotrauma
UpdateAIChatMessages(deltaTime);
//Do ragdoll shenanigans before Stun because it's still technically a stun, innit? Less network updates for us!
bool allowRagdoll = GameMain.NetworkMember != null ? GameMain.NetworkMember.ServerSettings.AllowRagdollButton : true;
bool tooFastToUnragdoll = AnimController.Collider.LinearVelocity.LengthSquared() > 1f;
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient)
{
tooFastToUnragdoll = false;
}
bool allowRagdoll = GameMain.NetworkMember?.ServerSettings?.AllowRagdollButton ?? true;
bool tooFastToUnragdoll = AnimController.Collider.LinearVelocity.LengthSquared() > 5.0f * 5.0f;
if (IsForceRagdolled)
{
IsRagdolled = IsForceRagdolled;
}
else if (IsRemotePlayer)
{
IsRagdolled = IsKeyDown(InputType.Ragdoll);
}
//Keep us ragdolled if we were forced or we're too speedy to unragdoll
else if (allowRagdoll && (!IsRagdolled || !tooFastToUnragdoll))
{
if (ragdollingLockTimer > 0.0f)
{
SetInput(InputType.Ragdoll, false, true);
ragdollingLockTimer -= deltaTime;
}
else
@@ -2908,7 +2901,7 @@ namespace Barotrauma
}
private float despawnTimer;
private void UpdateDespawn(float deltaTime, bool ignoreThresholds = false)
private void UpdateDespawn(float deltaTime, bool ignoreThresholds = false, bool createNetworkEvents = true)
{
if (!EnableDespawn) { return; }
@@ -2979,10 +2972,10 @@ namespace Barotrauma
if (itemContainer == null) { return; }
foreach (Item inventoryItem in Inventory.AllItemsMod)
{
if (!itemContainer.Inventory.TryPutItem(inventoryItem, user: null))
if (!itemContainer.Inventory.TryPutItem(inventoryItem, user: null, createNetworkEvent: createNetworkEvents))
{
//if the item couldn't be put inside the despawn container, just drop it
inventoryItem.Drop(dropper: this);
inventoryItem.Drop(dropper: this, createNetworkEvent: createNetworkEvents);
}
}
}
@@ -2994,7 +2987,7 @@ namespace Barotrauma
public void DespawnNow(bool createNetworkEvents = true)
{
despawnTimer = GameMain.Config.CorpseDespawnDelay;
UpdateDespawn(1.0f, ignoreThresholds: true);
UpdateDespawn(1.0f, ignoreThresholds: true, createNetworkEvents: createNetworkEvents);
Spawner.Update(createNetworkEvents);
}
@@ -3990,7 +3983,7 @@ namespace Barotrauma
//now there's just one, try to put the extra items where they fit (= stack them)
for (int i = 0; i < inventory.Capacity; i++)
{
if (inventory.CanBePut(newItem, i))
if (inventory.CanBePutInSlot(newItem, i))
{
slotIndices[0] = i;
canBePutInOriginalInventory = true;
@@ -4000,7 +3993,7 @@ namespace Barotrauma
}
else
{
canBePutInOriginalInventory = inventory.CanBePut(newItem, slotIndices[0], ignoreCondition: true);
canBePutInOriginalInventory = inventory.CanBePutInSlot(newItem, slotIndices[0], ignoreCondition: true);
}
if (canBePutInOriginalInventory)
@@ -47,7 +47,7 @@ namespace Barotrauma
requiredDeliveryAmount = Math.Min(prefab.ConfigElement.GetAttributeFloat("requireddeliveryamount", 0.98f), 1.0f);
//this can get called between rounds when the client receives a campaign save
//don't attempt to determine cargo if the sub hasn't been fully loaded
if (sub == null || sub.Loading || sub.Removed || Submarine.Unloading)
if (sub == null || sub.Loading || sub.Removed || Submarine.Unloading || !Submarine.Loaded.Contains(sub))
{
return;
}
@@ -18,7 +18,7 @@ namespace Barotrauma
//string = filename, point = min,max
private readonly HashSet<Tuple<CharacterPrefab, Point>> monsterPrefabs = new HashSet<Tuple<CharacterPrefab, Point>>();
private readonly float itemSpawnRadius = 800.0f;
private float itemSpawnRadius = 800.0f;
private readonly float approachItemsRadius = 1000.0f;
private readonly float nestObjectRadius = 1000.0f;
private readonly float monsterSpawnRadius = 3000.0f;
@@ -107,7 +107,8 @@ namespace Barotrauma
//ruin/cave/wreck items are allowed to spawn close to the sub
float minDistance = spawnPositionType == Level.PositionType.Ruin || spawnPositionType == Level.PositionType.Cave || spawnPositionType == Level.PositionType.Wreck ?
0.0f : Level.Loaded.Size.X * 0.3f;
Level.Loaded.TryGetInterestingPosition(true, spawnPositionType, 0.0f, out Vector2 nestPosition);
nestPosition = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, minDistance, 30.0f);
List<GraphEdge> spawnEdges = new List<GraphEdge>();
if (spawnPositionType == Level.PositionType.Cave)
{
@@ -149,20 +150,21 @@ namespace Barotrauma
if (!spawnEdges.Any())
{
GraphEdge closestEdge = null;
float closestDist = float.PositiveInfinity;
float closestDistSqr = float.PositiveInfinity;
foreach (var edge in nearbyCells.SelectMany(c => c.Edges))
{
if (!edge.NextToCave || !edge.IsSolid) { continue; }
float dist = Vector2.DistanceSquared(edge.Center, nestPosition);
if (dist < closestDist)
if (dist < closestDistSqr)
{
closestEdge = edge;
closestDist = dist;
closestDistSqr = dist;
}
}
if (closestEdge != null)
{
spawnEdges.Add(closestEdge);
itemSpawnRadius = Math.Max(itemSpawnRadius, (float)Math.Sqrt(closestDistSqr) * 1.5f);
}
}
}
@@ -427,7 +427,7 @@ namespace Barotrauma
{
if (!(secondLinkedEntity is Item linkedItem) || linkedItem == item) { continue; }
if (linkedItem.AllowSwapping &&
linkedItem.Prefab.SwappableItem != null && linkedItem.Prefab.SwappableItem.CanBeBought &&
linkedItem.Prefab.SwappableItem != null && (linkedItem.Prefab.SwappableItem.CanBeBought || item.Prefab.SwappableItem.ReplacementOnUninstall == linkedItem.prefab.Identifier) &&
linkedItem.Prefab.SwappableItem.SwapIdentifier.Equals(item.Prefab.SwappableItem.SwapIdentifier, StringComparison.OrdinalIgnoreCase))
{
linkedItems.Add(linkedItem);
@@ -132,17 +132,17 @@ namespace Barotrauma
return false;
}
public override bool CanBePut(Item item, int i, bool ignoreCondition = false)
public override bool CanBePutInSlot(Item item, int i, bool ignoreCondition = false)
{
return
base.CanBePut(item, i, ignoreCondition) && item.AllowedSlots.Any(s => s.HasFlag(SlotTypes[i])) &&
base.CanBePutInSlot(item, i, ignoreCondition) && item.AllowedSlots.Any(s => s.HasFlag(SlotTypes[i])) &&
(SlotTypes[i] == InvSlotType.Any || slots[i].ItemCount < 1);
}
public override bool CanBePut(ItemPrefab itemPrefab, int i, float? condition)
public override bool CanBePutInSlot(ItemPrefab itemPrefab, int i, float? condition)
{
return
base.CanBePut(itemPrefab, i, condition) &&
base.CanBePutInSlot(itemPrefab, i, condition) &&
(SlotTypes[i] == InvSlotType.Any || slots[i].ItemCount < 1);
}
@@ -261,7 +261,7 @@ namespace Barotrauma
/// <summary>
/// If there is room, puts the item in the inventory and returns true, otherwise returns false
/// </summary>
public override bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
public override bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true, bool ignoreCondition = false)
{
if (allowedSlots == null || !allowedSlots.Any()) { return false; }
if (item == null)
@@ -326,7 +326,7 @@ namespace Barotrauma
#if CLIENT
if (PersonalSlots.HasFlag(SlotTypes[i])) { hidePersonalSlots = false; }
#endif
if (!slots[i].First().AllowedSlots.Contains(InvSlotType.Any) || !TryPutItem(slots[i].FirstOrDefault(), character, new List<InvSlotType> { InvSlotType.Any }, true))
if (!slots[i].First().AllowedSlots.Contains(InvSlotType.Any) || !TryPutItem(slots[i].FirstOrDefault(), character, new List<InvSlotType> { InvSlotType.Any }, true, ignoreCondition))
{
free = false;
#if CLIENT
@@ -371,7 +371,7 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
if (SlotTypes[i] != InvSlotType.Any) { continue; }
if (!slots[i].Empty() && CanBePut(item, i))
if (!slots[i].Empty() && CanBePutInSlot(item, i))
{
return i;
}
@@ -387,7 +387,7 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
if (SlotTypes[i] != InvSlotType.Any) { continue; }
if (CanBePut(item, i))
if (CanBePutInSlot(item, i))
{
return i;
}
@@ -402,14 +402,14 @@ namespace Barotrauma
}
else
{
if (!CanBePut(item, i)) { continue; }
if (!CanBePutInSlot(item, i)) { continue; }
}
return i;
}
return -1;
}
public override bool TryPutItem(Item item, int index, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
public override bool TryPutItem(Item item, int index, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true, bool ignoreCondition = false)
{
if (index < 0 || index >= slots.Length)
{
@@ -424,7 +424,7 @@ namespace Barotrauma
if (slots[index].Any())
{
if (slots[index].Contains(item)) { return false; }
return base.TryPutItem(item, index, allowSwapping, allowCombine, user, createNetworkEvent);
return base.TryPutItem(item, index, allowSwapping, allowCombine, user, createNetworkEvent, ignoreCondition);
}
if (SlotTypes[index] == InvSlotType.Any)
@@ -460,7 +460,7 @@ namespace Barotrauma
if (!slotsFree) { return false; }
return TryPutItem(item, user, new List<InvSlotType>() { placeToSlots }, createNetworkEvent);
return TryPutItem(item, user, new List<InvSlotType>() { placeToSlots }, createNetworkEvent, ignoreCondition);
}
}
}
@@ -342,7 +342,7 @@ namespace Barotrauma.Items.Components
allowInsideFixture: true);
hitBodies.Clear();
hitBodies.AddRange(bodies);
hitBodies.AddRange(bodies.Distinct());
lastPickedFraction = Submarine.LastPickedFraction;
Type lastHitType = null;
@@ -483,7 +483,7 @@ namespace Barotrauma.Items.Components
foreach (ushort id in itemIds[i])
{
if (!(Entity.FindEntityByID(id) is Item item)) { continue; }
Inventory.TryPutItem(item, i, false, false, null, false);
Inventory.TryPutItem(item, i, false, false, null, createNetworkEvent: false, ignoreCondition: true);
}
}
itemIds = null;
@@ -211,7 +211,7 @@ namespace Barotrauma.Items.Components
{
for (int i = inputContainer.Inventory.Capacity - 2; i >= 0; i--)
{
while (inputContainer.Inventory.GetItemAt(i) is Item item1 && inputContainer.Inventory.CanBePut(item1, i + 1))
while (inputContainer.Inventory.GetItemAt(i) is Item item1 && inputContainer.Inventory.CanBePutInSlot(item1, i + 1))
{
if (!inputContainer.Inventory.TryPutItem(item1, i + 1, allowSwapping: false, allowCombine: false, user: null, createNetworkEvent: true))
{
@@ -170,7 +170,7 @@ namespace Barotrauma.Items.Components
private void StartFabricating(FabricationRecipe selectedItem, Character user, bool addToServerLog = true)
{
if (selectedItem == null) { return; }
if (!outputContainer.Inventory.CanBePut(selectedItem.TargetItem, selectedItem.OutCondition)) { return; }
if (!outputContainer.Inventory.CanBePut(selectedItem.TargetItem, selectedItem.OutCondition * selectedItem.TargetItem.Health)) { return; }
#if CLIENT
itemList.Enabled = false;
@@ -308,7 +308,7 @@ namespace Barotrauma.Items.Components
}
Character tempUser = user;
int amountFittingContainer = outputContainer.Inventory.HowManyCanBePut(fabricatedItem.TargetItem, fabricatedItem.OutCondition);
int amountFittingContainer = outputContainer.Inventory.HowManyCanBePut(fabricatedItem.TargetItem, fabricatedItem.OutCondition * fabricatedItem.TargetItem.Health);
for (int i = 0; i < fabricatedItem.Amount; i++)
{
if (i < amountFittingContainer)
@@ -380,7 +380,7 @@ namespace Barotrauma
return ownerItem.ParentInventory.ItemOwnsSelf(item);
}
public virtual int FindAllowedSlot(Item item)
public virtual int FindAllowedSlot(Item item, bool ignoreCondition = false)
{
if (ItemOwnsSelf(item)) { return -1; }
@@ -392,7 +392,7 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
if (slots[i].CanBePut(item)) { return i; }
if (slots[i].CanBePut(item, ignoreCondition)) { return i; }
}
return -1;
@@ -405,7 +405,7 @@ namespace Barotrauma
{
for (int i = 0; i < capacity; i++)
{
if (CanBePut(item, i)) { return true; }
if (CanBePutInSlot(item, i)) { return true; }
}
return false;
}
@@ -413,7 +413,7 @@ namespace Barotrauma
/// <summary>
/// Can the item be put in the specified slot.
/// </summary>
public virtual bool CanBePut(Item item, int i, bool ignoreCondition = false)
public virtual bool CanBePutInSlot(Item item, int i, bool ignoreCondition = false)
{
if (ItemOwnsSelf(item)) { return false; }
if (i < 0 || i >= slots.Length) { return false; }
@@ -424,12 +424,12 @@ namespace Barotrauma
{
for (int i = 0; i < capacity; i++)
{
if (CanBePut(itemPrefab, i, condition)) { return true; }
if (CanBePutInSlot(itemPrefab, i, condition)) { return true; }
}
return false;
}
public virtual bool CanBePut(ItemPrefab itemPrefab, int i, float? condition = null)
public virtual bool CanBePutInSlot(ItemPrefab itemPrefab, int i, float? condition = null)
{
if (i < 0 || i >= slots.Length) { return false; }
return slots[i].CanBePut(itemPrefab, condition);
@@ -454,16 +454,16 @@ namespace Barotrauma
/// <summary>
/// If there is room, puts the item in the inventory and returns true, otherwise returns false
/// </summary>
public virtual bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
public virtual bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true, bool ignoreCondition = false)
{
int slot = FindAllowedSlot(item);
int slot = FindAllowedSlot(item, ignoreCondition);
if (slot < 0) { return false; }
PutItem(item, slot, user, true, createNetworkEvent);
return true;
}
public virtual bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
public virtual bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true, bool ignoreCondition = false)
{
if (i < 0 || i >= slots.Length)
{
@@ -481,12 +481,12 @@ namespace Barotrauma
//item in the slot removed as a result of combining -> put this item in the now free slot
if (!slots[i].Any())
{
return TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent);
return TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent, ignoreCondition);
}
return true;
}
}
if (CanBePut(item, i))
if (CanBePutInSlot(item, i, ignoreCondition))
{
PutItem(item, i, user, true, createNetworkEvent);
return true;
@@ -21,7 +21,7 @@ namespace Barotrauma
this.container = container;
}
public override int FindAllowedSlot(Item item)
public override int FindAllowedSlot(Item item, bool ignoreCondition = false)
{
if (ItemOwnsSelf(item)) { return -1; }
@@ -32,18 +32,18 @@ namespace Barotrauma
//try to stack first
for (int i = 0; i < capacity; i++)
{
if (slots[i].Any() && CanBePut(item, i)) { return i; }
if (slots[i].Any() && CanBePutInSlot(item, i, ignoreCondition)) { return i; }
}
for (int i = 0; i < capacity; i++)
{
if (CanBePut(item, i)) { return i; }
if (CanBePutInSlot(item, i, ignoreCondition)) { return i; }
}
return -1;
}
public override bool CanBePut(Item item, int i, bool ignoreCondition = false)
public override bool CanBePutInSlot(Item item, int i, bool ignoreCondition = false)
{
if (ItemOwnsSelf(item)) { return false; }
if (i < 0 || i >= slots.Length) { return false; }
@@ -51,7 +51,7 @@ namespace Barotrauma
return item != null && slots[i].CanBePut(item, ignoreCondition) && slots[i].ItemCount < container.MaxStackSize;
}
public override bool CanBePut(ItemPrefab itemPrefab, int i, float? condition)
public override bool CanBePutInSlot(ItemPrefab itemPrefab, int i, float? condition)
{
if (i < 0 || i >= slots.Length) { return false; }
if (!container.CanBeContained(itemPrefab)) { return false; }
@@ -88,9 +88,9 @@ namespace Barotrauma
return true;
}
public override bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
public override bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true, bool ignoreCondition = false)
{
bool wasPut = base.TryPutItem(item, user, allowedSlots, createNetworkEvent);
bool wasPut = base.TryPutItem(item, user, allowedSlots, createNetworkEvent, ignoreCondition);
if (wasPut)
{
@@ -108,9 +108,9 @@ namespace Barotrauma
return wasPut;
}
public override bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
public override bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true, bool ignoreCondition = false)
{
bool wasPut = base.TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent);
bool wasPut = base.TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent, ignoreCondition);
if (wasPut && item.ParentInventory == this)
{
foreach (Character c in Character.CharacterList)
@@ -2724,7 +2724,7 @@ namespace Barotrauma
if (tries == 10)
{
position = EndPosition - Vector2.UnitY * 300.0f;
position = startPos;
}
} while (tries < 10);
@@ -1266,7 +1266,7 @@ namespace Barotrauma
{
List<(ItemContainer container, int freeSlots)> containers = new List<(ItemContainer container, int freeSlots)>();
var connectedSubs = GetConnectedSubs();
foreach (Item item in Item.ItemList)
foreach (Item item in Item.ItemList.ToList())
{
if (!connectedSubs.Contains(item.Submarine)) { continue; }
if (!item.HasTag("cargocontainer")) { continue; }