static void Prefix(ref BallisticEffect __instance) { try { bool allbullets = (bool)ReflectionHelper.InvokePrivateMethode(__instance, "AllBulletsComplete", null); if (__instance.currentState == WeaponEffect.WeaponEffectState.WaitingForImpact && allbullets) { ReflectionHelper.SetPrivateField(__instance, "hitIndex", shotcount - 1); if (shotcount == __instance.hitInfo.numberOfShots) { shotcount = 1; ReflectionHelper.InvokePrivateMethode(__instance, "OnImpact", new object[] { __instance.weapon.DamagePerShot }); } else { shotcount++; ReflectionHelper.InvokePrivateMethode(__instance, "OnImpact", new object[] { __instance.weapon.DamagePerShot }); __instance.Fire(__instance.hitInfo, 0, 0); } } } catch (Exception e) { Logger.LogError(e); } }
static void Prefix(ref BallisticEffect __instance) { try { bool allbullets = (bool)ReflectionHelper.InvokePrivateMethode(__instance, "AllBulletsComplete", null); if (__instance.currentState == WeaponEffect.WeaponEffectState.WaitingForImpact && allbullets) { int effectId = __instance.GetInstanceID(); if (!shotcountHolder.ContainsKey(effectId)) { shotcountHolder[effectId] = 1; //Logger.LogLine("effectId: " + effectId + " added"); } ReflectionHelper.SetPrivateField(__instance, "hitIndex", shotcountHolder[effectId] - 1); if (shotcountHolder[effectId] >= __instance.hitInfo.numberOfShots) { shotcountHolder[effectId] = 1; ReflectionHelper.InvokePrivateMethode(__instance, "OnImpact", new object[] { __instance.weapon.DamagePerShot }); //Logger.LogLine("effectId: " + effectId + " shotcount reset"); } else { shotcountHolder[effectId]++; ReflectionHelper.InvokePrivateMethode(__instance, "OnImpact", new object[] { __instance.weapon.DamagePerShot }); __instance.Fire(__instance.hitInfo, 0, 0); // Logger.LogLine("effectId: " + effectId + " shotcount incremented to:" + shotcountHolder[effectId]); } } } catch (Exception e) { Logger.LogError(e); } }
static void Postfix(ref BallisticEffect __instance, float __state) { try { Weapon weapon = __instance.weapon; StatCollection collection = weapon.StatCollection; collection.Set <float>("DamagePerShot", __state); } catch (Exception e) { Logger.LogError(e); } }
private static bool IsClustered(BallisticEffect effect) { var effectId = effect.GetInstanceID(); if (!_isClustered.ContainsKey(effectId)) { _isClustered[effectId] = Core.ModSettings.ClusteredBallistics && effect.weapon.weaponDef.ComponentTags.Contains(ClusteredShotEnabler.CLUSTER_TAG, StringComparer.InvariantCultureIgnoreCase); } return(_isClustered[effectId]); }
static void Postfix(BallisticEffect __instance, float __state) { try { Logger.Debug($"Setting damagepershot back to {__state}"); __instance.weapon.StatCollection.Set("DamagePerShot", __state); } catch (Exception e) { Logger.Error(e); } }
static void Prefix(BallisticEffect __instance, ref float __state) { try { Logger.Debug("Setting damagepershot to zero"); var weapon = __instance.weapon; __state = weapon.DamagePerShot; weapon.StatCollection.Set("DamagePerShot", 0f); } catch (Exception e) { Logger.Error(e); } }
static void Prefix(BallisticEffect __instance) { try { var ballisticEffect = __instance; var instance = Traverse.Create(ballisticEffect); var effectId = ballisticEffect.GetInstanceID(); var allBullets = instance.Method("AllBulletsComplete").GetValue <bool>(); //Logger.Debug($"all bullets? {allBullets}"); if (ballisticEffect.currentState != WeaponEffect.WeaponEffectState.WaitingForImpact || !allBullets) { return; } if (!_shotCountHolder.ContainsKey(effectId)) { _shotCountHolder[effectId] = 1; Logger.Debug($"effectId: shotcount for {effectId} added"); } var hitIndex = instance.Field("hitIndex"); Logger.Debug($"hitIndex before: {hitIndex.GetValue<int>()}"); instance.Field("hitIndex").SetValue(_shotCountHolder[effectId] - 1); Logger.Debug($"hitIndex after: {hitIndex.GetValue<int>()}"); if (_shotCountHolder[effectId] >= ballisticEffect.hitInfo.numberOfShots) { _shotCountHolder[effectId] = 1; instance.Method("OnImpact", new object[] { VariantWeapon.VariantDamage(ballisticEffect, ballisticEffect.weapon.parent.occupiedDesignMask) }).GetValue(); Logger.Debug($"effectId: {effectId} shotcount reset"); } else { _shotCountHolder[effectId]++; instance.Method("OnImpact", new object[] { VariantWeapon.VariantDamage(ballisticEffect, ballisticEffect.weapon.parent.occupiedDesignMask) }).GetValue(); ballisticEffect.Fire(ballisticEffect.hitInfo, 0, 0); Logger.Debug($"effectId: {effectId} shotcount incremented to: {_shotCountHolder[effectId]}"); } } catch (Exception e) { Logger.Error(e); } }
static bool Prefix(ref int ___hitIndex, BallisticEffect __instance) { var damage = __instance.weapon.DamagePerShotAdjusted(__instance.weapon.parent.occupiedDesignMask); BallisticEffect_OnImpact.Invoke(__instance, new object[] { damage }); if (___hitIndex >= __instance.hitInfo.toHitRolls.Length - 1) { WeaponEffect_OnComplete(__instance); return(false); } ___hitIndex++; if (ShouldFire(__instance, ___hitIndex)) { __instance.Fire(__instance.hitInfo, ___hitIndex, 0); } return(false); }
// we only fire when multishot ballistics are enabled and we're not in clustered mode private static bool ShouldFire(BallisticEffect effect, int hitIndex) { return(Core.ModSettings.BallisticNumberOfShots && hitIndex % effect.weapon.ProjectilesPerShot == 0); }