This commit is contained in:
Evil Factory
2022-04-28 12:36:24 -03:00
91 changed files with 1140 additions and 491 deletions
@@ -3,7 +3,6 @@ using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
@@ -18,6 +17,8 @@ namespace Barotrauma.Items.Components
const int MaxNodes = 100;
const float MaxNodeDistance = 150.0f;
private bool waitForVoltageRecalculation;
public struct Node
{
public Vector2 WorldPosition;
@@ -120,6 +121,7 @@ namespace Barotrauma.Items.Components
CurrPowerConsumption = powerConsumption;
Voltage = 0.0f;
waitForVoltageRecalculation = true;
charging = true;
timer = Duration;
IsActive = true;
@@ -134,6 +136,12 @@ namespace Barotrauma.Items.Components
#if CLIENT
frameOffset = Rand.Int(electricitySprite.FrameCount);
#endif
if (waitForVoltageRecalculation)
{
waitForVoltageRecalculation = false;
return;
}
if (timer <= 0.0f)
{
IsActive = false;
@@ -33,9 +33,6 @@ namespace Barotrauma.Items.Components
set;
}
private JobPrefab cachedJobPrefab;
private string cachedName;
public ImmutableHashSet<Identifier> OwnerTagSet { get; set; }
[Serialize("", IsPropertySaveable.Yes, alwaysUseInstanceValues: true)]
@@ -98,6 +95,7 @@ namespace Barotrauma.Items.Components
OwnerName = info.Name;
OwnerJobId = info.Job?.Prefab.Identifier ?? Identifier.Empty;
item.AddTag($"jobid:{OwnerJobId}");
OwnerTagSet = info.Head.Preset.TagSet;
OwnerHairIndex = head.HairIndex;
OwnerBeardIndex = head.BeardIndex;
@@ -315,6 +315,15 @@ namespace Barotrauma.Items.Components
}
}
private Client GetUsingClient()
{
#if SERVER
return GameMain.Server.ConnectedClients.Find(c => c.Character == user);
#elif CLIENT
return null;
#endif
}
private void Fabricate()
{
RefreshAvailableIngredients();
@@ -327,9 +336,20 @@ namespace Barotrauma.Items.Components
if (fabricatedItem.RequiredMoney > 0)
{
if (user == null) { return; }
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign)
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign)
{
user.Wallet.Deduct(fabricatedItem.RequiredMoney);
#if CLIENT
mpCampaign.TryPurchase(null, fabricatedItem.RequiredMoney);
#elif SERVER
if (GetUsingClient() is { } client)
{
mpCampaign.TryPurchase(client, fabricatedItem.RequiredMoney);
}
else
{
user.Wallet.Deduct(fabricatedItem.RequiredMoney);
}
#endif
}
else if (GameMain.GameSession?.GameMode is CampaignMode campaign)
{
@@ -530,6 +550,10 @@ namespace Barotrauma.Items.Components
{
floatQuality += user.Info.GetSavedStatValue(StatTypes.IncreaseFabricationQuality, tag);
}
if (!fabricatedItem.TargetItem.Tags.Contains(fabricatedItem.TargetItem.Identifier))
{
floatQuality += user.Info.GetSavedStatValue(StatTypes.IncreaseFabricationQuality, fabricatedItem.TargetItem.Identifier);
}
quality = (int)floatQuality;
const int MaxCraftingSkill = 100;
@@ -548,17 +572,22 @@ namespace Barotrauma.Items.Components
if (fabricableItem.RequiredMoney > 0)
{
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign)
switch (GameMain.GameSession?.GameMode)
{
if (character?.Wallet == null || character.Wallet.Balance < fabricableItem.RequiredMoney) { return false; }
}
else if (GameMain.GameSession?.GameMode is CampaignMode campaign)
{
if (campaign.Bank.Balance < fabricableItem.RequiredMoney) { return false; }
}
else
{
return false;
case MultiPlayerCampaign mpCampaign:
{
if (!mpCampaign.CanAfford(fabricableItem.RequiredMoney, GetUsingClient())) { return false; }
break;
}
case CampaignMode campaign:
{
if (campaign.Bank.Balance < fabricableItem.RequiredMoney) { return false; }
break;
}
default:
return false;
}
}
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
@@ -565,16 +565,20 @@ namespace Barotrauma.Items.Components
//Iterate through all connections in the group to get their minmax power and sum them
foreach (Connection c in scrGroup.Connections)
{
Powered device = c.Item.GetComponent<Powered>();
scrGroup.MinMaxPower += device.MinMaxPowerOut(c, grid.Load);
foreach (var device in c.Item.GetComponents<Powered>())
{
scrGroup.MinMaxPower += device.MinMaxPowerOut(c, grid.Load);
}
}
//Iterate through all connections to get their final power out provided the min max information
float addedPower = 0;
foreach (Connection c in scrGroup.Connections)
{
Powered device = c.Item.GetComponent<Powered>();
addedPower += device.GetConnectionPowerOut(c, grid.Power, scrGroup.MinMaxPower, grid.Load);
foreach (var device in c.Item.GetComponents<Powered>())
{
addedPower += device.GetConnectionPowerOut(c, grid.Power, scrGroup.MinMaxPower, grid.Load);
}
}
//Add the power to the grid
@@ -591,10 +595,12 @@ namespace Barotrauma.Items.Components
grid.Voltage = newVoltage;
//Iterate through all connections on that grid and run their gridResolved function
foreach (Connection con in grid.Connections)
foreach (Connection c in grid.Connections)
{
Powered device = con.Item.GetComponent<Powered>();
device?.GridResolved(con);
foreach (var device in c.Item.GetComponents<Powered>())
{
device?.GridResolved(c);
}
}
}
@@ -671,21 +677,18 @@ namespace Barotrauma.Items.Components
/// </summary>
protected float GetAvailableInstantaneousBatteryPower()
{
if (item.Connections == null) { return 0.0f; }
if (item.Connections == null || powerIn == null) { return 0.0f; }
float availablePower = 0.0f;
foreach (Connection c in item.Connections)
var recipients = powerIn.Recipients;
foreach (Connection recipient in recipients)
{
var recipients = c.Recipients;
foreach (Connection recipient in recipients)
{
if (!recipient.IsPower || !recipient.IsOutput) { continue; }
var battery = recipient.Item?.GetComponent<PowerContainer>();
if (battery == null) { continue; }
float maxOutputPerFrame = battery.MaxOutPut / 60.0f;
float framesPerMinute = 3600.0f;
availablePower += Math.Min(battery.Charge * framesPerMinute, maxOutputPerFrame);
}
}
if (!recipient.IsPower || !recipient.IsOutput) { continue; }
var battery = recipient.Item?.GetComponent<PowerContainer>();
if (battery == null || battery.Item.Condition <= 0.0f) { continue; }
float maxOutputPerFrame = battery.MaxOutPut / 60.0f;
float framesPerMinute = 3600.0f;
availablePower += Math.Min(battery.Charge * framesPerMinute, maxOutputPerFrame);
}
return availablePower;
}
@@ -597,7 +597,7 @@ namespace Barotrauma.Items.Components
else if (ic is PowerTransfer pt)
{
//power transfer items (junction boxes, relays) don't deteriorate if they're no carrying any power
if (Math.Abs(pt.CurrPowerConsumption) > 0.1f) { return true; }
if (pt.Voltage > 0.1f) { return true; }
}
else if (ic is PowerContainer pc)
{