Unstable 0.1300.0.3

This commit is contained in:
Markus Isberg
2021-03-25 15:40:24 +02:00
parent 874616027b
commit 58c50a235d
136 changed files with 2486 additions and 1008 deletions
@@ -150,6 +150,44 @@ namespace Barotrauma
return false;
}
public override void RemoveItem(Item item)
{
RemoveItem(item, tryEquipFromSameStack: false);
}
public void RemoveItem(Item item, bool tryEquipFromSameStack)
{
if (!Contains(item)) { return; }
bool wasEquipped = character.HasEquippedItem(item);
var indices = FindIndices(item);
base.RemoveItem(item);
#if CLIENT
CreateSlots();
#endif
//if the item was equipped and there are more items in the same stack, equip one of those items
if (tryEquipFromSameStack && wasEquipped)
{
int limbSlot = indices.Find(j => SlotTypes[j] != InvSlotType.Any);
foreach (int i in indices)
{
var itemInSameSlot = GetItemAt(i);
if (itemInSameSlot != null)
{
if (TryPutItem(itemInSameSlot, limbSlot, allowSwapping: false, allowCombine: false, character))
{
#if CLIENT
visualSlots[i].ShowBorderHighlight(GUI.Style.Green, 0.1f, 0.412f);
#endif
}
break;
}
}
}
}
/// <summary>
/// If there is no room in the generic inventory (InvSlotType.Any), check if the item can be auto-equipped into its respective limbslot
/// </summary>
@@ -165,6 +203,19 @@ namespace Barotrauma
}
}
if (allowedSlots != null && !allowedSlots.Contains(InvSlotType.Any))
{
int slot = FindLimbSlot(allowedSlots.First());
if (slot > -1 && slots[slot].Items.Any(it => it != item) && slots[slot].First().Prefab.AllowDroppingOnSwap)
{
foreach (Item existingItem in slots[slot].Items.ToList())
{
existingItem.Drop(user);
if (existingItem.ParentInventory != null) { existingItem.ParentInventory.RemoveItem(existingItem); }
}
}
}
return TryPutItem(item, user, allowedSlots, createNetworkEvent);
}
@@ -62,6 +62,7 @@ namespace Barotrauma.Items.Components
{
if (!subElement.Name.ToString().Equals("attack", StringComparison.OrdinalIgnoreCase)) { continue; }
Attack = new Attack(subElement, item.Name + ", MeleeWeapon");
Attack.DamageRange = item.body == null ? 10.0f : ConvertUnits.ToDisplayUnits(item.body.GetMaxExtent());
}
item.IsShootable = true;
// TODO: should define this in xml if we have melee weapons that don't require aim to use
@@ -175,7 +175,7 @@ namespace Barotrauma.Items.Components
Vector2 propellerWorldPos = item.WorldPosition + PropellerPos * item.Scale;
foreach (Character character in Character.CharacterList)
{
if (character.Submarine != null || !character.Enabled || character.Removed) { continue; }
if (!character.Enabled || character.Removed) { continue; }
float distSqr = Vector2.DistanceSquared(character.WorldPosition, propellerWorldPos);
if (distSqr > scaledDamageRange * scaledDamageRange) { continue; }
character.LastDamageSource = item;
@@ -121,11 +121,10 @@ namespace Barotrauma.Items.Components
inputContainer = containers[0];
outputContainer = containers[1];
foreach (var recipe in fabricationRecipes)
{
int ingredientCount = recipe.RequiredItems.Sum(it => it.Amount);
if (ingredientCount > inputContainer.Capacity)
if (recipe.RequiredItems.Count > inputContainer.Capacity)
{
DebugConsole.ThrowError("Error in item \"" + item.Name + "\": There's not enough room in the input inventory for the ingredients of \"" + recipe.TargetItem.Name + "\"!");
}
@@ -581,10 +581,9 @@ namespace Barotrauma.Items.Components
return false;
}
aiUpdateTimer = AIUpdateInterval;
// load more fuel if the current maximum output is only 50% of the current load
// or if the fuel rod is (almost) deplenished
float minCondition = fuelConsumptionRate * MathUtils.Pow((degreeOfSuccess - refuelLimit) * 2, 2);
float minCondition = fuelConsumptionRate * MathUtils.Pow2((degreeOfSuccess - refuelLimit) * 2);
if (NeedMoreFuel(minimumOutputRatio: 0.5f, minCondition: minCondition))
{
bool outOfFuel = false;
@@ -360,7 +360,7 @@ namespace Barotrauma.Items.Components
//other junction boxes don't need to receive the signal in the pass-through signal connections
//because we relay it straight to the connected items without going through the whole chain of junction boxes
if (ic is PowerTransfer && !(ic is RelayComponent) && connection.Name.Contains("signal")) { continue; }
ic.ReceiveSignal(signal, connection);
ic.ReceiveSignal(signal, recipient);
}
foreach (StatusEffect effect in recipient.Effects)
@@ -65,10 +65,10 @@ namespace Barotrauma.Items.Components
}
base.IsActive = true;
InitProjSpecific(element);
InitProjSpecific();
}
partial void InitProjSpecific(XElement element);
partial void InitProjSpecific();
private bool linksInitialized;
public override void OnMapLoaded()
@@ -62,7 +62,7 @@ namespace Barotrauma.Items.Components
{
case "signal_in":
string signalOut = (signal.value == TargetSignal) ? Output : FalseOutput;
if (string.IsNullOrWhiteSpace(signalOut)) { return; }
if (string.IsNullOrEmpty(signalOut)) { return; }
signal.value = signalOut;
item.SendSignal(signal, "signal_out");
break;
@@ -83,7 +83,8 @@ namespace Barotrauma.Items.Components
fireInRange = IsFireInRange();
fireCheckTimer = FireCheckInterval;
}
item.SendSignal(fireInRange ? Output : FalseOutput, "signal_out");
string signalOut = fireInRange ? Output : FalseOutput;
if (!string.IsNullOrEmpty(signalOut)) { item.SendSignal(signalOut, "signal_out"); }
}
}
}
@@ -42,7 +42,7 @@ namespace Barotrauma.Items.Components
partial void InitProjSpecific(XElement element);
partial void ShowOnDisplay(string input);
partial void ShowOnDisplay(string input, bool addToHistory = true);
public override void ReceiveSignal(Signal signal, Connection connection)
{
@@ -58,13 +58,18 @@ namespace Barotrauma.Items.Components
public override void OnItemLoaded()
{
bool isSubEditor = false;
#if CLIENT
isSubEditor = Screen.Selected != GameMain.SubEditorScreen || GameMain.GameSession?.GameMode is TestGameMode;
#endif
base.OnItemLoaded();
if (!string.IsNullOrEmpty(DisplayedWelcomeMessage))
{
ShowOnDisplay(DisplayedWelcomeMessage);
ShowOnDisplay(DisplayedWelcomeMessage, addToHistory: !isSubEditor);
DisplayedWelcomeMessage = "";
//remove welcome message if a game session is running so it doesn't reappear on successive rounds
if (GameMain.GameSession != null)
if (GameMain.GameSession != null && !isSubEditor)
{
welcomeMessage = null;
}
@@ -102,6 +102,13 @@ namespace Barotrauma.Items.Components
set;
}
[Editable, Serialize(false, true, "If enabled, this wire will use the sprite depth instead of a constant depth.")]
public bool UseSpriteDepth
{
get;
set;
}
public Wire(Item item, XElement element)
: base(item, element)
{
@@ -436,23 +436,28 @@ namespace Barotrauma.Items.Components
Projectile launchedProjectile = null;
for (int i = 0; i < ProjectileCount; i++)
{
foreach (MapEntity e in item.linkedTo)
var projectiles = GetLoadedProjectiles(true);
if (projectiles.Any())
{
//use linked projectile containers in case they have to react to the turret being launched somehow
//(play a sound, spawn more projectiles)
if (!(e is Item linkedItem)) { continue; }
ItemContainer projectileContainer = linkedItem.GetComponent<ItemContainer>();
if (projectileContainer != null)
ItemContainer projectileContainer = projectiles.First().Item.Container?.GetComponent<ItemContainer>();
projectileContainer?.Item.Use(deltaTime, null);
}
else
{
foreach (MapEntity e in item.linkedTo)
{
linkedItem.Use(deltaTime, null);
var repairable = linkedItem.GetComponent<Repairable>();
if (repairable != null && failedLaunchAttempts < 2)
//use linked projectile containers in case they have to react to the turret being launched somehow
//(play a sound, spawn more projectiles)
if (!(e is Item linkedItem)) { continue; }
ItemContainer projectileContainer = linkedItem.GetComponent<ItemContainer>();
if (projectileContainer != null)
{
repairable.LastActiveTime = (float)Timing.TotalTime + 1.0f;
linkedItem.Use(deltaTime, null);
projectiles = GetLoadedProjectiles(true);
if (projectiles.Any()) { break; }
}
}
}
var projectiles = GetLoadedProjectiles(true);
if (projectiles.Count == 0 && !LaunchWithoutProjectile)
{
//coilguns spawns ammo in the ammo boxes with the OnUse statuseffect when the turret is launched,
@@ -471,7 +476,6 @@ namespace Barotrauma.Items.Components
}
failedLaunchAttempts = 0;
launchedProjectile = projectiles.FirstOrDefault();
if (!ignorePower)
{
var batteries = item.GetConnectedComponents<PowerContainer>();
@@ -492,6 +496,15 @@ namespace Barotrauma.Items.Components
}
}
if (launchedProjectile?.Item.Container != null)
{
var repairable = launchedProjectile?.Item.Container.GetComponent<Repairable>();
if (repairable != null)
{
repairable.LastActiveTime = (float)Timing.TotalTime + 1.0f;
}
}
if (launchedProjectile != null || LaunchWithoutProjectile)
{
Launch(launchedProjectile?.Item, character);
@@ -663,13 +663,29 @@ namespace Barotrauma
existingItems.Count == 1 && otherInventory.TryPutItem(existingItems.First(),user, CharacterInventory.anySlot, createNetworkEvent))
&&
stackedItems.Distinct().All(stackedItem => TryPutItem(stackedItem, index, false, false, user, createNetworkEvent));
if (!swapSuccessful && existingItems.Count == 1 && existingItems[0].Prefab.AllowDroppingOnSwap)
{
existingItems[0].Drop(user, createNetworkEvent);
swapSuccessful = stackedItems.Distinct().Any(stackedItem => TryPutItem(stackedItem, index, false, false, user, createNetworkEvent));
#if CLIENT
if (swapSuccessful)
{
SoundPlayer.PlayUISound(GUISoundType.DropItem);
if (otherInventory.visualSlots != null && otherIndex > -1)
{
otherInventory.visualSlots[otherIndex].ShowBorderHighlight(Color.Transparent, 0.1f, 0.1f);
}
}
#endif
}
}
//if the item in the slot can be moved to the slot of the moved item
if (swapSuccessful)
{
System.Diagnostics.Debug.Assert(slots[index].Contains(item), "Something when wrong when swapping items, item is not present in the inventory.");
System.Diagnostics.Debug.Assert(otherInventory.Contains(existingItems.FirstOrDefault()), "Something when wrong when swapping items, item is not present in the other inventory.");
System.Diagnostics.Debug.Assert(!existingItems.Any(it => !it.Prefab.AllowDroppingOnSwap && !otherInventory.Contains(it)), "Something when wrong when swapping items, item is not present in the other inventory.");
#if CLIENT
if (visualSlots != null)
{
@@ -2807,7 +2807,14 @@ namespace Barotrauma
if (parentInventory != null)
{
parentInventory.RemoveItem(this);
if (parentInventory is CharacterInventory characterInventory)
{
characterInventory.RemoveItem(this, tryEquipFromSameStack: true);
}
else
{
parentInventory.RemoveItem(this);
}
parentInventory = null;
}
@@ -517,6 +517,9 @@ namespace Barotrauma
set { maxStackSize = MathHelper.Clamp(value, 1, Inventory.MaxStackSize); }
}
[Serialize(false, false)]
public bool AllowDroppingOnSwap { get; private set; }
public Vector2 Size => size;
public bool CanBeBought => (DefaultPrice != null && DefaultPrice.CanBeBought) || (locationPrices != null && locationPrices.Any(p => p.Value.CanBeBought));