Skip to content

Commit

Permalink
Fixed projectile related compatibility issues.
Browse files Browse the repository at this point in the history
- Fixed wrong if scope in Projectile functionality.
- Added additional error handling, just in case.
  • Loading branch information
nxPublic committed Jan 26, 2022
1 parent a9f2d0d commit be70bf5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ValheimPlus/GameClasses/Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ private static void Prefix(ref Attack __instance)
{
if (Configuration.Current.PlayerProjectile.IsEnabled && __instance.m_character.IsPlayer())
{
// This might not be required but i wanted to add this non the less to be sure that no missing properties are causing issues.
if (__instance?.m_projectileVel == null || __instance?.m_projectileAccuracy == null || __instance?.m_projectileVelMin == null || __instance?.m_projectileAccuracyMin == null)
return;

float playerProjVelMinMod = Helper.applyModifierValue(__instance.m_projectileVelMin, Configuration.Current.PlayerProjectile.playerMinChargeVelocityMultiplier);
float playerProjVelMaxMod = Helper.applyModifierValue(__instance.m_projectileVel, Configuration.Current.PlayerProjectile.playerMaxChargeVelocityMultiplier);

Expand All @@ -82,6 +86,7 @@ private static void Prefix(ref Attack __instance)

if (Configuration.Current.PlayerProjectile.enableScaleWithSkillLevel)
{

Player player = (Player)__instance.m_character;
Skills.Skill skill = player.m_skills.GetSkill(__instance.m_weapon.m_shared.m_skillType);
float maxLevelPercentage = skill.m_level * 0.01f;
Expand All @@ -104,17 +109,24 @@ private static void Prefix(ref Attack __instance)

if (Configuration.Current.MonsterProjectile.IsEnabled && !__instance.m_character.IsPlayer())
{

// This might not be required but i wanted to add this non the less to be sure that no missing properties are causing issues.
if (__instance?.m_projectileVel == null || __instance?.m_projectileAccuracy == null || __instance?.m_projectileVelMin == null || __instance?.m_projectileAccuracyMin == null)
return;

__instance.m_projectileVel = Helper.applyModifierValue(__instance.m_projectileVel, Configuration.Current.MonsterProjectile.monsterMaxChargeVelocityMultiplier);

// negate value to handle increasing accuracy means decreasing variance
__instance.m_projectileAccuracy = Helper.applyModifierValue(__instance.m_projectileAccuracy, -Configuration.Current.MonsterProjectile.monsterMaxChargeAccuracyMultiplier);
}

__instance.m_projectileVelMin = Mathf.Clamp(__instance.m_projectileVelMin, 0f, maxClampValue);
__instance.m_projectileVel = Mathf.Clamp(__instance.m_projectileVel, 0f, maxClampValue);
__instance.m_projectileVelMin = Mathf.Clamp(__instance.m_projectileVelMin, 0f, maxClampValue);
__instance.m_projectileVel = Mathf.Clamp(__instance.m_projectileVel, 0f, maxClampValue);

__instance.m_projectileAccuracyMin = Mathf.Clamp(__instance.m_projectileAccuracyMin, 0f, maxClampValue);
__instance.m_projectileAccuracy = Mathf.Clamp(__instance.m_projectileAccuracy, 0f, maxClampValue);
}

__instance.m_projectileAccuracyMin = Mathf.Clamp(__instance.m_projectileAccuracyMin, 0f, maxClampValue);
__instance.m_projectileAccuracy = Mathf.Clamp(__instance.m_projectileAccuracy, 0f, maxClampValue);

}
}
}

0 comments on commit be70bf5

Please sign in to comment.