Unstable 0.1500.2.0 (Rokvach's dog edition)

This commit is contained in:
Markus Isberg
2021-09-10 04:52:34 +09:00
parent e7b7c1a748
commit 1231170fce
126 changed files with 2424 additions and 1083 deletions
@@ -67,7 +67,7 @@ namespace Barotrauma.Items.Components
private bool isBroken;
public bool CanBeTraversed => (IsOpen || IsBroken) && !IsJammed && !IsStuck;
public bool CanBeTraversed => (IsOpen || IsBroken) && !IsJammed && !IsStuck && !Impassable;
public bool IsBroken
{
@@ -116,7 +116,11 @@ namespace Barotrauma.Items.Components
#if SERVER
item.CreateServerEvent(this);
#endif
}
}
foreach (Item containedItem in item.ContainedItems)
{
containedItem.GetComponent<GeneticMaterial>()?.Equip(character);
}
}
public override void Update(float deltaTime, Camera cam)
@@ -124,12 +128,16 @@ namespace Barotrauma.Items.Components
base.Update(deltaTime, cam);
if (targetCharacter != null)
{
var rootContainer = item.GetRootContainer();
if (!targetCharacter.HasEquippedItem(item) &&
(item.Container == null || !targetCharacter.HasEquippedItem(item.Container) || !(item.Container.GetComponent<ItemContainer>()?.AutoInject ?? false)))
(rootContainer == null || !targetCharacter.HasEquippedItem(rootContainer) || !targetCharacter.Inventory.IsInLimbSlot(rootContainer, InvSlotType.HealthInterface)))
{
item.ApplyStatusEffects(ActionType.OnSevered, 1.0f, targetCharacter);
var currentEffect = tainted ? selectedTaintedEffect : selectedEffect;
targetCharacter.CharacterHealth.ReduceAffliction(null, currentEffect.Identifier, currentEffect.MaxStrength);
targetCharacter.CharacterHealth.ReduceAffliction(null, selectedEffect.Identifier, selectedEffect.MaxStrength);
if (tainted)
{
targetCharacter.CharacterHealth.ReduceAffliction(null, selectedTaintedEffect.Identifier, selectedTaintedEffect.MaxStrength);
}
targetCharacter = null;
IsActive = false;
}
@@ -1,4 +1,5 @@
using Barotrauma.Networking;
using Barotrauma.Abilities;
using Barotrauma.Networking;
using FarseerPhysics;
using FarseerPhysics.Collision;
using FarseerPhysics.Dynamics;
@@ -158,10 +159,14 @@ namespace Barotrauma.Items.Components
if (currentChargeTime < MaxChargeTime) { return false; }
IsActive = true;
ReloadTimer = reload / (1 + character.GetStatValue(StatTypes.RangedAttackSpeed));
ReloadTimer = reload / (1 + character?.GetStatValue(StatTypes.RangedAttackSpeed) ?? 0f);
currentChargeTime = 0f;
character.CheckTalents(AbilityEffectType.OnUseRangedWeapon, item);
if (character != null)
{
var abilityItem = new AbilityItem(item);
character.CheckTalents(AbilityEffectType.OnUseRangedWeapon, abilityItem);
}
if (item.AiTarget != null)
{
@@ -6,6 +6,7 @@ using System.Xml.Linq;
using Barotrauma.Extensions;
using FarseerPhysics;
using System.Collections.Immutable;
using Barotrauma.Abilities;
namespace Barotrauma.Items.Components
{
@@ -114,6 +115,13 @@ namespace Barotrauma.Items.Components
set;
}
[Serialize(true, false)]
public bool AllowSwappingContainedItems
{
get;
set;
}
[Serialize(false, false, description: "If set to true, interacting with this item will make the character interact with the contained item(s), automatically picking them up if they can be picked up.")]
public bool AutoInteractWithContained
{
@@ -414,7 +422,8 @@ namespace Barotrauma.Items.Components
}
}
}
character.CheckTalents(AbilityEffectType.OnOpenItemContainer, item);
var abilityItem = new AbilityItem(item);
character.CheckTalents(AbilityEffectType.OnOpenItemContainer, abilityItem);
return base.Select(character);
}
@@ -588,6 +597,7 @@ namespace Barotrauma.Items.Components
public override void OnItemLoaded()
{
Inventory.AllowSwappingContainedItems = AllowSwappingContainedItems;
containableItemIdentifiers = slotRestrictions.SelectMany(s => s.ContainableItems?.SelectMany(ri => ri.Identifiers) ?? Enumerable.Empty<string>()).ToImmutableHashSet();
if (item.Submarine == null || !item.Submarine.Loading)
{
@@ -616,7 +626,21 @@ namespace Barotrauma.Items.Components
}
itemIds = null;
}
SpawnAlwaysContainedItems();
//outpost and ruins are loaded in multiple stages (each module is loaded separately)
//spawning items at this point during the generation will cause ID overlaps with the entities in the modules loaded afterwards
//so let's not spawn them at this point, but in the 1st Update()
if (item.Submarine?.Info != null && (item.Submarine.Info.IsOutpost || item.Submarine.Info.IsRuin))
{
if (SpawnWithId.Length > 0)
{
IsActive = true;
}
}
else
{
SpawnAlwaysContainedItems();
}
}
private void SpawnAlwaysContainedItems()
@@ -106,7 +106,7 @@ namespace Barotrauma.Items.Components
if ((Entity.Spawner?.IsInRemoveQueue(targetItem) ?? false) || !inputContainer.Inventory.AllItems.Contains(targetItem)) { continue; }
var validDeconstructItems = targetItem.Prefab.DeconstructItems.FindAll(it =>
(it.RequiredDeconstructor.Length == 0 || it.RequiredDeconstructor.Any(r => item.HasTag(r) || item.Prefab.Identifier.Equals(r, StringComparison.OrdinalIgnoreCase))) &&
(it.RequiredOtherItem.Length == 0 || it.RequiredOtherItem.Any(r => items.Any(it => it.HasTag(r) || it.Prefab.Identifier.Equals(r, StringComparison.OrdinalIgnoreCase)))));
(it.RequiredOtherItem.Length == 0 || it.RequiredOtherItem.Any(r => items.Any(it => it != targetItem && (it.HasTag(r) || it.Prefab.Identifier.Equals(r, StringComparison.OrdinalIgnoreCase))))));
ProcessItem(targetItem, items, validDeconstructItems, allowRemove: validDeconstructItems.Any() || !targetItem.Prefab.DeconstructItems.Any());
}
@@ -148,6 +148,12 @@ namespace Barotrauma.Items.Components
// In multiplayer, the server handles the deconstruction into new items
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
if (user != null && !user.Removed)
{
var abilityTargetItem = new AbilityItem(targetItem);
user.CheckTalents(AbilityEffectType.OnItemDeconstructed, abilityTargetItem);
}
if (targetItem.Prefab.RandomDeconstructionOutput)
{
int amount = targetItem.Prefab.RandomDeconstructionOutputAmount;
@@ -169,8 +175,6 @@ namespace Barotrauma.Items.Components
commonness.RemoveAt(removeIndex);
}
user.CheckTalents(AbilityEffectType.OnItemDeconstructed, targetItem);
foreach (DeconstructItem deconstructProduct in products)
{
CreateDeconstructProduct(deconstructProduct, inputItems);
@@ -225,10 +229,15 @@ namespace Barotrauma.Items.Components
}
}
}
var itemsCreated = new AbilityValue(1f);
user.CheckTalents(AbilityEffectType.OnItemDeconstructedMaterial, (targetItem.Prefab, itemsCreated));
int amount = (int)itemsCreated.Value;
int amount = 1;
if (user != null && !user.Removed)
{
var itemsCreated = new AbilityValueItem(1f, targetItem.Prefab);
user.CheckTalents(AbilityEffectType.OnItemDeconstructedMaterial, itemsCreated);
amount = (int)itemsCreated.Value;
}
for (int i = 0; i < amount; i++)
{
@@ -113,37 +113,35 @@ namespace Barotrauma.Items.Components
Force = MathHelper.Lerp(force, (Voltage < MinVoltage) ? 0.0f : targetForce, 0.1f);
if (Math.Abs(Force) > 1.0f)
{
float voltageFactor = MinVoltage <= 0.0f ? 1.0f : Math.Min(Voltage, 1.0f);
float currForce = force * voltageFactor;
float condition = item.Condition / item.MaxCondition;
// Broken engine makes more noise.
float noise = Math.Abs(currForce) * MathHelper.Lerp(1.5f, 1f, condition);
UpdateAITargets(noise);
//arbitrary multiplier that was added to changes in submarine mass without having to readjust all engines
float forceMultiplier = 0.1f;
if (User != null)
{
forceMultiplier *= MathHelper.Lerp(0.5f, 2.0f, (float)Math.Sqrt(User.GetSkillLevel("helm") / 100));
}
float voltageFactor = MinVoltage <= 0.0f ? 1.0f : Math.Min(Voltage, 1.0f);
Vector2 currForce = new Vector2(force * maxForce * forceMultiplier * voltageFactor, 0.0f);
if (item.GetComponent<Repairable>()?.IsTinkering ?? false)
currForce *= maxForce * forceMultiplier;
if (item.GetComponent<Repairable>() is Repairable repairable && repairable.IsTinkering)
{
currForce *= 2.5f;
}
//less effective when in a bad condition
currForce *= MathHelper.Lerp(0.5f, 2.0f, item.Condition / item.MaxCondition);
currForce *= MathHelper.Lerp(0.5f, 2.0f, condition);
if (item.Submarine.FlippedX) { currForce *= -1; }
item.Submarine.ApplyForce(currForce);
Vector2 forceVector = new Vector2(currForce, 0);
item.Submarine.ApplyForce(forceVector);
UpdatePropellerDamage(deltaTime);
float maxChangeSpeed = 0.5f;
float modifier = 2;
float noise = MathUtils.NearlyEqual(0.0f, maxForce) ? 0.0f : currForce.Length() * forceMultiplier * modifier / maxForce;
float min = Math.Max(1 - maxChangeSpeed, 0);
float max = 1 + maxChangeSpeed;
UpdateAITargets(Math.Clamp(noise, min, max), deltaTime);
#if CLIENT
particleTimer -= deltaTime;
if (particleTimer <= 0.0f)
{
Vector2 particleVel = -currForce.ClampLength(5000.0f) / 5.0f;
Vector2 particleVel = -forceVector.ClampLength(5000.0f) / 5.0f;
GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition + PropellerPos * item.Scale,
particleVel * Rand.Range(0.9f, 1.1f),
0.0f, item.CurrentHull);
@@ -153,14 +151,14 @@ namespace Barotrauma.Items.Components
}
}
private void UpdateAITargets(float increaseSpeed, float deltaTime)
private void UpdateAITargets(float noise)
{
if (item.AiTarget != null)
{
item.AiTarget.IncreaseSoundRange(deltaTime, increaseSpeed);
item.AiTarget.SoundRange = MathHelper.Lerp(item.AiTarget.MinSoundRange, item.AiTarget.MaxSoundRange, noise / 100);
if (item.CurrentHull != null && item.CurrentHull.AiTarget != null)
{
// It's possible that some othe item increases the hull's soundrange more than the engine.
// It's possible that some other item increases the hull's soundrange more than the engine.
item.CurrentHull.AiTarget.SoundRange = Math.Max(item.CurrentHull.AiTarget.SoundRange, item.AiTarget.SoundRange);
}
}
@@ -327,6 +327,7 @@ namespace Barotrauma.Items.Components
int amountFittingContainer = outputContainer.Inventory.HowManyCanBePut(fabricatedItem.TargetItem, fabricatedItem.OutCondition * fabricatedItem.TargetItem.Health);
var fabricationValueItem = new AbilityValueItem(fabricatedItem.Amount, fabricatedItem.TargetItem);
if (user != null)
{
foreach (Character character in Character.CharacterList.Where(c => c.TeamID == user.TeamID))
@@ -369,10 +370,11 @@ namespace Barotrauma.Items.Components
float addedSkill = skill.Level * SkillSettings.Current.SkillIncreasePerFabricatorRequiredSkill / Math.Max(userSkill, 1.0f);
var addedSkillValue = new AbilityValueString(0f, skill.Identifier);
user.CheckTalents(AbilityEffectType.OnItemFabricationSkillGain, addedSkillValue);
addedSkill += addedSkillValue.Value;
user.Info.IncreaseSkillLevel(
skill.Identifier,
addedSkill + addedSkillValue.Value,
addedSkill,
user.Position + Vector2.UnitY * 150.0f);
}
}
@@ -106,7 +106,7 @@ namespace Barotrauma.Items.Components
currFlow = flowPercentage / 100.0f * maxFlow * powerFactor;
if (item.GetComponent<Repairable>()?.IsTinkering ?? false)
if (item.GetComponent<Repairable>() is Repairable repairable && repairable.IsTinkering)
{
currFlow *= 2.5f;
}
@@ -367,23 +367,19 @@ namespace Barotrauma.Items.Components
item.Condition -= fissionRate / 100.0f * fuelConsumptionRate * deltaTime;
}
}
if (item.CurrentHull != null)
{
var aiTarget = item.CurrentHull.AiTarget;
if (aiTarget != null && MaxPowerOutput > 0)
{
float range = Math.Abs(currPowerConsumption) / MaxPowerOutput;
float noise = MathHelper.Lerp(aiTarget.MinSoundRange, aiTarget.MaxSoundRange, range);
aiTarget.SoundRange = Math.Max(aiTarget.SoundRange, noise);
}
}
if (item.AiTarget != null && MaxPowerOutput > 0)
{
var aiTarget = item.AiTarget;
float range = Math.Abs(currPowerConsumption) / MaxPowerOutput;
aiTarget.SoundRange = MathHelper.Lerp(aiTarget.MinSoundRange, aiTarget.MaxSoundRange, range);
if (item.CurrentHull != null)
{
var hullAITarget = item.CurrentHull.AiTarget;
if (hullAITarget != null)
{
hullAITarget.SoundRange = Math.Max(hullAITarget.SoundRange, aiTarget.SoundRange);
}
}
}
}
@@ -85,10 +85,10 @@ namespace Barotrauma.Items.Components
}
private float skillRequirementMultiplier;
[Serialize(1.0f, true)]
public float SkillRequirementMultiplier
{
public float SkillRequirementMultiplier
{
get { return skillRequirementMultiplier; }
set
{
@@ -100,7 +100,7 @@ namespace Barotrauma.Items.Components
RecreateGUI();
}
#endif
}
}
}
public bool IsTinkering { get; private set; } = false;
@@ -113,6 +113,8 @@ namespace Barotrauma.Items.Components
public Character CurrentFixer { get; private set; }
private Item currentRepairItem;
private float tinkeringDuration;
public enum FixActions : int
{
None = 0,
@@ -135,13 +137,13 @@ namespace Barotrauma.Items.Components
canBeSelected = true;
this.item = item;
header =
header =
TextManager.Get(element.GetAttributeString("header", ""), returnNull: true) ??
TextManager.Get(item.Prefab.ConfigElement.GetAttributeString("header", ""), returnNull: true) ??
element.GetAttributeString("name", "");
//backwards compatibility
var repairThresholdAttribute =
var repairThresholdAttribute =
element.Attributes().FirstOrDefault(a => a.Name.ToString().Equals("showrepairuithreshold", StringComparison.OrdinalIgnoreCase)) ??
element.Attributes().FirstOrDefault(a => a.Name.ToString().Equals("airepairthreshold", StringComparison.OrdinalIgnoreCase));
if (repairThresholdAttribute != null)
@@ -197,7 +199,7 @@ namespace Barotrauma.Items.Components
return ((average + 100.0f) / 2.0f) / 100.0f;
}
public bool StartRepairing(Character character, FixActions action)
{
if (character == null || character.IsDead || action == FixActions.None)
@@ -227,6 +229,18 @@ namespace Barotrauma.Items.Components
CurrentFixer = character;
currentRepairItem = bestRepairItem;
CurrentFixerAction = action;
if (action == FixActions.Tinker)
{
if (character.HasAbilityFlag(AbilityFlags.CanTinkerFabricatorsAndDeconstructors) && item.GetComponent<Deconstructor>() != null || item.GetComponent<Fabricator>() != null)
{
// fabricators and deconstructors can be tinkered indefinitely (more or less)
tinkeringDuration = float.MaxValue;
}
else
{
tinkeringDuration = CurrentFixer.GetStatValue(StatTypes.TinkeringDuration);
}
}
return true;
Item GetBestRepairItem(Character character)
@@ -254,13 +268,17 @@ namespace Barotrauma.Items.Components
ic.ApplyStatusEffects(ActionType.OnSuccess, 1.0f, character);
}
}
if (CurrentFixerAction == FixActions.Tinker)
{
CurrentFixer.CheckTalents(AbilityEffectType.OnStopTinkering);
}
CurrentFixer.AnimController.Anim = AnimController.Animation.None;
CurrentFixer = null;
currentRepairItem = null;
currentFixerAction = FixActions.None;
#if CLIENT
repairSoundChannel?.FadeOutAndDispose();
repairSoundChannel = null;
repairSoundChannel = null;
#endif
return true;
}
@@ -290,6 +308,8 @@ namespace Barotrauma.Items.Components
UpdateProjSpecific(deltaTime);
IsTinkering = false;
item.SendSignal($"{(int) item.ConditionPercentage}", "condition_out");
if (CurrentFixer == null)
{
if (deteriorateAlwaysResetTimer > 0.0f)
@@ -339,8 +359,9 @@ namespace Barotrauma.Items.Components
if (currentFixerAction == FixActions.Tinker)
{
tinkeringDuration -= deltaTime;
// not great to interject it here, should be less reliant on returning
if (!CanTinker(CurrentFixer))
if (!CanTinker(CurrentFixer) || tinkeringDuration <= 0f)
{
StopRepairing(CurrentFixer);
}
@@ -396,7 +417,7 @@ namespace Barotrauma.Items.Components
CurrentFixer.CheckTalents(AbilityEffectType.OnRepairComplete);
}
deteriorationTimer = Rand.Range(MinDeteriorationDelay, MaxDeteriorationDelay);
wasBroken = false;
wasBroken = false;
StopRepairing(CurrentFixer);
}
}
@@ -439,9 +460,27 @@ namespace Barotrauma.Items.Components
}
}
private bool CanTinker(Character character)
private bool IsTinkerable(Character character)
{
if (!character.HasAbilityFlag(AbilityFlags.CanTinker)) { return false; }
if (item.GetComponent<Engine>() != null) { return true; }
if (item.GetComponent<Turret>() != null) { return true; }
if (item.GetComponent<Pump>() != null) { return true; }
if (!character.HasAbilityFlag(AbilityFlags.CanTinkerFabricatorsAndDeconstructors)) { return false; }
if (item.GetComponent<Fabricator>() != null) { return true; }
if (item.GetComponent<Deconstructor>() != null) { return true; }
return false;
}
private Affliction GetTinkerExhaustion(Character character)
{
return character.CharacterHealth.GetAffliction("tinkerexhaustion");
}
private bool CanTinker(Character character)
{
if (!IsTinkerable(character)) { return false; }
if (GetTinkerExhaustion(character) is Affliction tinkerExhaustion && tinkerExhaustion.Strength <= tinkerExhaustion.Prefab.MaxStrength) { return false; }
return true;
}
@@ -469,7 +508,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
//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; }
}
else if (ic is Engine engine)
@@ -530,7 +569,7 @@ namespace Barotrauma.Items.Components
public override void ReceiveSignal(Signal signal, Connection connection)
{
//do nothing
//Repairables should always stay active, so we don't want to use the default behavior
//Repairables should always stay active, so we don't want to use the default behavior
//where set_active/set_state signals can disable the component
}
}
@@ -233,6 +233,8 @@ namespace Barotrauma.Items.Components
}
UpdateOnActiveEffects(deltaTime);
if (powerIn == null && powerConsumption > 0.0f) { Voltage -= deltaTime; }
#if CLIENT
Light.ParentSub = item.Submarine;
#endif
@@ -293,8 +295,6 @@ namespace Barotrauma.Items.Components
}
SetLightSourceState(true, lightBrightness);
if (powerIn == null && powerConsumption > 0.0f) { Voltage -= deltaTime; }
}
public override void UpdateBroken(float deltaTime, Camera cam)
@@ -742,10 +742,10 @@ namespace Barotrauma.Items.Components
Projectile projectileComponent = projectile.GetComponent<Projectile>();
if (projectileComponent != null)
{
projectileComponent.Attacker = user;
projectileComponent.Attacker = projectileComponent.User = user;
if (isTinkering)
{
projectileComponent.Attack.DamageMultiplier *= 1.25f;
projectileComponent.Attack.DamageMultiplier = 1.25f;
}
projectileComponent.Use();
projectile.GetComponent<Rope>()?.Attach(item, projectile);