Build 0.20.9.0

This commit is contained in:
Markus Isberg
2022-12-01 21:59:53 +02:00
parent df805574c4
commit 31d2dc658e
66 changed files with 953 additions and 505 deletions
@@ -47,6 +47,13 @@ namespace Barotrauma.Items.Components
{
return ContainableItems == null || ContainableItems.Count == 0 || ContainableItems.Any(c => c.MatchesItem(itemPrefab));
}
public bool MatchesItem(Identifier identifierOrTag)
{
return
ContainableItems == null || ContainableItems.Count == 0 ||
ContainableItems.Any(c => c.Identifiers.Contains(identifierOrTag) && !c.ExcludedIdentifiers.Contains(identifierOrTag));
}
}
public readonly NamedEvent<ItemContainer> OnContainedItemsChanged = new NamedEvent<ItemContainer>();
@@ -374,7 +381,7 @@ namespace Barotrauma.Items.Components
// Set the contained items active if there's an item inserted inside the container. Enables e.g. the rifle flashlight when it's attached to the rifle (put inside of it).
SetContainedActive(true);
}
CharacterHUD.RecreateHudTextsIfFocused(item, containedItem);
OnContainedItemsChanged.Invoke(this);
}
@@ -386,9 +393,9 @@ namespace Barotrauma.Items.Components
public void OnItemRemoved(Item containedItem)
{
activeContainedItems.RemoveAll(i => i.Item == containedItem);
//deactivate if the inventory is empty
IsActive = activeContainedItems.Count > 0 || Inventory.AllItems.Any(it => it.body != null);
CharacterHUD.RecreateHudTextsIfFocused(item, containedItem);
OnContainedItemsChanged.Invoke(this);
}
@@ -664,6 +671,18 @@ namespace Barotrauma.Items.Components
return relatedItem;
}
/// <summary>
/// Returns the index of the first slot whose restrictions match the specified tag or identifier
/// </summary>
public int? FindSuitableSubContainerIndex(Identifier itemTagOrIdentifier)
{
for (int i = 0; i < slotRestrictions.Length; i++)
{
if (slotRestrictions[i].MatchesItem(itemTagOrIdentifier)) { return i; }
}
return null;
}
public override void ReceiveSignal(Signal signal, Connection connection)
{
switch (connection.Name)
@@ -603,6 +603,13 @@ namespace Barotrauma.Items.Components
}
partial void UpdateRequiredTimeProjSpecific();
private static bool AnyOneHasRecipeForItem(Character user, ItemPrefab item)
{
return
(user != null && user.HasRecipeForItem(item.Identifier)) ||
GameSession.GetSessionCrewCharacters(CharacterType.Bot).Any(c => c.HasRecipeForItem(item.Identifier));
}
private bool CanBeFabricated(FabricationRecipe fabricableItem, IReadOnlyDictionary<Identifier, List<Item>> availableIngredients, Character character)
{
@@ -610,8 +617,7 @@ namespace Barotrauma.Items.Components
if (fabricableItem.RequiresRecipe)
{
if (character == null) { return false; }
if (!character.HasRecipeForItem(fabricableItem.TargetItem.Identifier) &&
GameSession.GetSessionCrewCharacters(CharacterType.Bot).None(c => c.HasRecipeForItem(fabricableItem.TargetItem.Identifier)))
if (!AnyOneHasRecipeForItem(character, fabricableItem.TargetItem))
{
return false;
}
@@ -678,9 +684,10 @@ namespace Barotrauma.Items.Components
//fabricating takes 100 times longer if degree of success is close to 0
//characters with a higher skill than required can fabricate up to 100% faster
float time = fabricableItem.RequiredTime / item.StatManager.GetAdjustedValue(ItemTalentStats.FabricationSpeed, FabricationSpeed) / MathHelper.Clamp(t, 0.01f, 2.0f);
if (user is not null && fabricableItem.TargetItem is { } it && it.Tags.Contains("medical"))
if (user?.Info is { } info && fabricableItem.TargetItem is { } it)
{
time *= 1f + user.GetStatValue(StatTypes.FabricateMedicineSpeedMultiplier);
time /= 1f + it.Tags.Sum(tag => info.GetSavedStatValue(StatTypes.FabricationSpeed, tag));
}
return time;
}
@@ -25,12 +25,8 @@ namespace Barotrauma.Items.Components
public List<Hull> LinkedHulls = new List<Hull>();
}
private DateTime resetDataTime;
private bool hasPower;
private readonly Dictionary<Hull, HullData> hullDatas;
[Editable, Serialize(false, IsPropertySaveable.Yes, description: "Does the machine require inputs from water detectors in order to show the water levels inside rooms.")]
public bool RequireWaterDetectors
{
@@ -77,7 +73,6 @@ namespace Barotrauma.Items.Components
: base(item, element)
{
IsActive = true;
hullDatas = new Dictionary<Hull, HullData>();
InitProjSpecific();
}
@@ -85,37 +80,6 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
//reset data if we haven't received anything in a while
//(so that outdated hull info won't be shown if detectors stop sending signals)
if (DateTime.Now > resetDataTime)
{
foreach (HullData hullData in hullDatas.Values)
{
if (!hullData.Distort)
{
if (Timing.TotalTime > hullData.LastOxygenDataTime + 1.0) { hullData.ReceivedOxygenAmount = null; }
if (Timing.TotalTime > hullData.LastWaterDataTime + 1.0) { hullData.ReceivedWaterAmount = null; }
}
}
resetDataTime = DateTime.Now + new TimeSpan(0, 0, 1);
}
#if CLIENT
if (cardRefreshTimer > cardRefreshDelay)
{
if (item.Submarine is { } sub)
{
UpdateIDCards(sub);
}
cardRefreshTimer = 0;
}
else
{
cardRefreshTimer += deltaTime;
}
#endif
hasPower = Voltage > MinVoltage;
if (hasPower)
{
@@ -140,67 +104,5 @@ namespace Barotrauma.Items.Components
{
return picker != null;
}
public override void ReceiveSignal(Signal signal, Connection connection)
{
Item source = signal.source;
if (source == null || source.CurrentHull == null) { return; }
Hull sourceHull = source.CurrentHull;
if (!hullDatas.TryGetValue(sourceHull, out HullData hullData))
{
hullData = new HullData();
hullDatas.Add(sourceHull, hullData);
}
if (hullData.Distort) { return; }
switch (connection.Name)
{
case "water_data_in":
//cheating a bit because water detectors don't actually send the water level
bool fromWaterDetector = source.GetComponent<WaterDetector>() != null;
hullData.ReceivedWaterAmount = null;
hullData.LastWaterDataTime = Timing.TotalTime;
if (fromWaterDetector)
{
hullData.ReceivedWaterAmount = WaterDetector.GetWaterPercentage(sourceHull);
}
foreach (var linked in sourceHull.linkedTo)
{
if (!(linked is Hull linkedHull)) { continue; }
if (!hullDatas.TryGetValue(linkedHull, out HullData linkedHullData))
{
linkedHullData = new HullData();
hullDatas.Add(linkedHull, linkedHullData);
}
linkedHullData.ReceivedWaterAmount = null;
if (fromWaterDetector)
{
linkedHullData.ReceivedWaterAmount = WaterDetector.GetWaterPercentage(linkedHull);
}
}
break;
case "oxygen_data_in":
if (!float.TryParse(signal.value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float oxy))
{
oxy = Rand.Range(0.0f, 100.0f);
}
hullData.ReceivedOxygenAmount = oxy;
hullData.LastOxygenDataTime = Timing.TotalTime;
foreach (var linked in sourceHull.linkedTo)
{
if (linked is not Hull linkedHull) { continue; }
if (!hullDatas.TryGetValue(linkedHull, out HullData linkedHullData))
{
linkedHullData = new HullData();
hullDatas.Add(linkedHull, linkedHullData);
}
linkedHullData.ReceivedOxygenAmount = oxy;
}
break;
}
}
}
}
@@ -11,7 +11,7 @@ namespace Barotrauma.Items.Components
{
const float NetworkUpdateIntervalHigh = 0.5f;
const float TemperatureBoostAmount = 20;
const float TemperatureBoostAmount = 25;
//the rate at which the reactor is being run on (higher rate -> higher temperature)
private float fissionRate;
@@ -26,10 +26,6 @@ namespace Barotrauma.Items.Components
//amount of power generated balanced with the load)
private bool autoTemp;
//automatical adjustment to the power output when
//turbine output and temperature are in the optimal range
private float autoAdjustAmount;
private float fuelConsumptionRate;
private float meltDownTimer, meltDownDelay;
@@ -53,6 +49,8 @@ namespace Barotrauma.Items.Components
private float temperatureBoost;
public bool AllowTemperatureBoost => Math.Abs(temperatureBoost) < TemperatureBoostAmount * 0.9f;
private bool _powerOn;
[Serialize(defaultValue: false, isSaveable: IsPropertySaveable.Yes)]
@@ -314,7 +312,7 @@ namespace Barotrauma.Items.Components
Temperature += MathHelper.Clamp(Math.Sign(temperatureDiff) * 10.0f * deltaTime, -Math.Abs(temperatureDiff), Math.Abs(temperatureDiff));
temperatureBoost = adjustValueWithoutOverShooting(temperatureBoost, 0.0f, deltaTime);
#if CLIENT
temperatureBoostUpButton.Enabled = temperatureBoostDownButton.Enabled = Math.Abs(temperatureBoost) < TemperatureBoostAmount * 0.9f;
temperatureBoostUpButton.Enabled = temperatureBoostDownButton.Enabled = AllowTemperatureBoost;
#endif
FissionRate = MathHelper.Lerp(fissionRate, Math.Min(TargetFissionRate, AvailableFuel), deltaTime);
@@ -248,6 +248,7 @@ namespace Barotrauma.Items.Components
if (container?.Inventory == null) { return; }
bool recreateHudTexts = false;
for (var i = 0; i < container.Inventory.Capacity; i++)
{
if (i < 0 || GrowableSeeds.Length <= i) { continue; }
@@ -257,6 +258,7 @@ namespace Barotrauma.Items.Components
if (growable != null)
{
recreateHudTexts |= GrowableSeeds[i] != growable;
GrowableSeeds[i] = growable;
growable.IsActive = true;
}
@@ -267,11 +269,14 @@ namespace Barotrauma.Items.Components
// Kill the plant if it's somehow removed
oldGrowable.Decayed = true;
oldGrowable.IsActive = false;
recreateHudTexts = true;
}
GrowableSeeds[i] = null;
}
}
#if CLIENT
CharacterHUD.RecreateHudTexts |= recreateHudTexts;
#endif
// server handles this
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
@@ -9,6 +9,7 @@ namespace Barotrauma.Items.Components
{
//[power/min]
private float capacity;
private float adjustedCapacity;
private float charge, prevCharge;
@@ -66,7 +67,11 @@ namespace Barotrauma.Items.Components
public float Capacity
{
get => capacity;
set { capacity = Math.Max(value, 1.0f); }
set
{
capacity = Math.Max(value, 1.0f);
adjustedCapacity = GetCapacity();
}
}
[Editable, Serialize(0.0f, IsPropertySaveable.Yes, description: "The current charge of the device.")]
@@ -76,10 +81,10 @@ namespace Barotrauma.Items.Components
set
{
if (!MathUtils.IsValid(value)) return;
charge = MathHelper.Clamp(value, 0.0f, capacity);
charge = MathHelper.Clamp(value, 0.0f, adjustedCapacity);
//send a network event if the charge has changed by more than 5%
if (Math.Abs(charge - lastSentCharge) / capacity > 0.05f)
if (Math.Abs(charge - lastSentCharge) / adjustedCapacity > 0.05f)
{
#if SERVER
if (GameMain.Server != null && (!item.Submarine?.Loading ?? true)) { item.CreateServerEvent(this); }
@@ -89,7 +94,7 @@ namespace Barotrauma.Items.Components
}
}
public float ChargePercentage => MathUtils.Percentage(Charge, GetCapacity());
public float ChargePercentage => MathUtils.Percentage(Charge, adjustedCapacity);
[Editable, Serialize(10.0f, IsPropertySaveable.Yes, description: "How fast the device can be recharged. For example, a recharge speed of 100 kW and a capacity of 1000 kW*min would mean it takes 10 minutes to fully charge the device.")]
public float MaxRechargeSpeed
@@ -157,6 +162,7 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
adjustedCapacity = GetCapacity();
if (item.Connections == null)
{
IsActive = false;
@@ -164,7 +170,7 @@ namespace Barotrauma.Items.Components
}
isRunning = true;
float chargeRatio = charge / capacity;
float chargeRatio = charge / adjustedCapacity;
if (chargeRatio > 0.0f)
{
@@ -180,7 +186,7 @@ namespace Barotrauma.Items.Components
item.SendSignal(((int)Math.Round(CurrPowerOutput)).ToString(), "power_value_out");
item.SendSignal(((int)Math.Round(loadReading)).ToString(), "load_value_out");
item.SendSignal(((int)Math.Round(Charge)).ToString(), "charge");
item.SendSignal(((int)Math.Round(Charge / capacity * 100)).ToString(), "charge_%");
item.SendSignal(((int)Math.Round(Charge / adjustedCapacity * 100)).ToString(), "charge_%");
item.SendSignal(((int)Math.Round(RechargeSpeed / maxRechargeSpeed * 100)).ToString(), "charge_rate");
}
@@ -193,16 +199,16 @@ namespace Barotrauma.Items.Components
if (connection == powerIn)
{
//Don't draw power if fully charged
if (charge >= capacity)
if (charge >= adjustedCapacity)
{
charge = capacity;
charge = adjustedCapacity;
return 0;
}
else
{
if (item.Condition <= 0.0f) { return 0.0f; }
float missingCharge = capacity - charge;
float missingCharge = adjustedCapacity - charge;
float targetRechargeSpeed = rechargeSpeed;
if (ExponentialRechargeSpeed)
@@ -239,7 +245,7 @@ namespace Barotrauma.Items.Components
if (connection == powerOut)
{
float maxOutput;
float chargeRatio = prevCharge / capacity;
float chargeRatio = prevCharge / adjustedCapacity;
if (chargeRatio < 0.1f)
{
maxOutput = Math.Max(chargeRatio * 10.0f, 0.0f) * MaxOutPut;
@@ -292,7 +298,7 @@ namespace Barotrauma.Items.Components
else
{
//Decrease charge based on how much power is leaving the device
Charge = Math.Clamp(Charge - CurrPowerOutput / 60 * UpdateInterval, 0, GetCapacity());
Charge = Math.Clamp(Charge - CurrPowerOutput / 60 * UpdateInterval, 0, adjustedCapacity);
prevCharge = Charge;
}
}
@@ -639,13 +639,16 @@ namespace Barotrauma.Items.Components
ItemContainer projectileContainer = projectiles.First().Item.Container?.GetComponent<ItemContainer>();
if (projectileContainer != null && projectileContainer.Item != item)
{
projectileContainer.Item.Use(deltaTime, null);
//Use root container (e.g. loader) too in case it needs to react to firing somehow
var rootContainer = projectileContainer.Item.GetRootContainer();
if (rootContainer != projectileContainer.Item)
if (rootContainer != null && rootContainer != projectileContainer.Item)
{
rootContainer.Use(deltaTime, null);
}
else
{
projectileContainer.Item.Use(deltaTime, null);
}
}
}
else