Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,25 @@ public bool IsDualWieldingRangedWeapons()

return false;
}


public bool IsDualWieldingMeleeWeapons()
{
int meleeItemCount = 0;
foreach (var item in HeldItems)
{
if (item.GetComponent<MeleeWeapon>() != null)
{
meleeItemCount++;
}

if (meleeItemCount > 1)
{
return true;
}
}

return false;
}
private float lowPassMultiplier;
public float LowPassMultiplier
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ public bool HitOnlyCharacters
{
get;
set;
}

[Serialize(defaultValue: 1f, IsPropertySaveable.Yes, description: "Penalty multiplier to reload time when dual-wielding.")]
public float DualWieldReloadTimePenaltyMultiplier
{
get;
private set;
}

[Editable, Serialize(true, IsPropertySaveable.No)]
public bool Swing { get; set; }

Expand Down Expand Up @@ -88,11 +95,28 @@ public MeleeWeapon(Item item, ContentXElement element)
PreferredContainedItems = element.GetAttributeIdentifierArray("preferredcontaineditems", Array.Empty<Identifier>()).ToImmutableHashSet();
}

/// <summary>
/// Lerps between the original penalty and a neutral value, which should be 1 for multipliers and 0 for additive penalties.
/// </summary>
/// <param name="character">The character to get stat values from</param>
/// <param name="originalPenalty">The original penalty value</param>
/// <param name="neutralValue">Neutral value to lerp towards. Should be 1 for multipliers and 0 for additives.</param>
/// <returns></returns>
private static float ApplyDualWieldPenaltyReduction(Character character, float originalPenalty, float neutralValue)
{
float statAdjustmentPrc = character.GetStatValue(StatTypes.DualWieldingPenaltyReduction);
statAdjustmentPrc = MathHelper.Clamp(statAdjustmentPrc, 0f, 1f);
float reducedPenaltyMultiplier = MathHelper.Lerp(originalPenalty, neutralValue, statAdjustmentPrc);
return reducedPenaltyMultiplier;
}


public override void Equip(Character character)
{
base.Equip(character);
//force a wait of at least 1 second when equipping the weapon, so you can't "rapid-fire" by swapping between weapons
const float forcedDelayOnEquip = 1.0f;

reloadTimer = Math.Max(Math.Min(reload, forcedDelayOnEquip), reloadTimer);
IsActive = true;
}
Expand All @@ -117,6 +141,12 @@ public override bool Use(float deltaTime, Character character = null)

if (Item.RequireAimToUse && hitPos < MathHelper.PiOver4) { return false; }


if (character.IsDualWieldingMeleeWeapons())
{
baseReloadTime *= Math.Max(1f, ApplyDualWieldPenaltyReduction(character, DualWieldReloadTimePenaltyMultiplier, neutralValue: 1f));
}

ActivateNearbySleepingCharacters();
reloadTimer = reload;
reloadTimer /= 1f + character.GetStatValue(StatTypes.MeleeAttackSpeed);
Expand Down