public static float getWeaponForbiddenRange(Weapon weapon) { if (CustomAmmoCategories.Settings.forbiddenRangeEnable == false) { return(0f); } ; ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); float result = 0f; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName)) { string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); result += CustomAmmoCategories.findExtAmmo(ammoId).ForbiddenRange; } if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName)) { string modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); if (extWeapon.Modes.ContainsKey(modeId)) { result += extWeapon.Modes[modeId].ForbiddenRange; } } return(result); }
public static float getWeaponDistantVariance(Weapon weapon) { float result = 0; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId); result += extAmmo.DistantVariance; } ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.Modes.Count > 0) { string modeId = ""; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); } else { modeId = extWeapon.baseModeId; } if (extWeapon.Modes.ContainsKey(modeId)) { result += extWeapon.Modes[modeId].DistantVariance; } } return(result); }
public static void Postfix(AttackDirector __instance, MessageCenterMessage message) { CustomAmmoCategoriesLog.Log.LogWrite($"Try jamm weapon\n"); while (JammingEnabler.jammQueue.Count > 0) { AbstractActor actor = JammingEnabler.jammQueue.Dequeue(); CustomAmmoCategoriesLog.Log.LogWrite($"Try jamm weapon of " + actor.DisplayName + "\n"); foreach (Weapon weapon in actor.Weapons) { CustomAmmoCategoriesLog.Log.LogWrite($" weapon " + weapon.UIName + " rounds since last fire " + weapon.roundsSinceLastFire + "\n"); if (weapon.roundsSinceLastFire > 0) { continue; } float flatJammingChance = CustomAmmoCategories.getWeaponFlatJammingChance(weapon); CustomAmmoCategoriesLog.Log.LogWrite($" flatJammingChance " + flatJammingChance + "\n"); if (flatJammingChance > CustomAmmoCategories.Epsilon) { CustomAmmoCategoriesLog.Log.LogWrite($" Try jamm weapon " + weapon.UIName + "\n"); float Roll = Random.Range(0.0f, 1.0f); CustomAmmoCategoriesLog.Log.LogWrite($" Jamming chance " + flatJammingChance + " roll " + Roll + "\n"); if (Roll < flatJammingChance) { CustomAmmoCategoriesLog.Log.LogWrite($" Jammed!\n"); CustomAmmoCategories.AddJam(actor, weapon); } } if (CustomAmmoCategories.getWeaponCooldown(weapon) > 0) { CustomAmmoCategories.AddCooldown(actor, weapon); } } } }
public static bool getWeaponDistantVarianceReversed(Weapon weapon) { TripleBoolean result = TripleBoolean.NotSet; ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.Modes.Count > 0) { string modeId = ""; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); } else { modeId = extWeapon.baseModeId; } if (extWeapon.Modes.ContainsKey(modeId)) { result = extWeapon.Modes[modeId].DistantVarianceReversed; } } if (result == TripleBoolean.NotSet) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId); result = extAmmo.DistantVarianceReversed; } } return(result == TripleBoolean.True); }
public static List <CustomAmmoCategory> getWeaponAmmoCategories(Weapon weapon) { List <CustomAmmoCategory> result = new List <CustomAmmoCategory>(); ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (weapon.AmmoCategory != AmmoCategory.NotSet) { if (extWeapon.AmmoCategory.BaseCategory == weapon.AmmoCategory) { result.Add(extWeapon.AmmoCategory); } else { result.Add(CustomAmmoCategories.find(weapon.AmmoCategory.ToString())); } } foreach (var mode in extWeapon.Modes) { if (mode.Value.AmmoCategory == null) { continue; } ; if (mode.Value.AmmoCategory.BaseCategory != AmmoCategory.NotSet) { result.Add(mode.Value.AmmoCategory); } ; } return(result); }
public static bool isWeaponCanShootNoAmmo(WeaponDef weaponDef) { ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weaponDef.Description.Id); if (weaponDef.AmmoCategory == AmmoCategory.NotSet) { return(true); } ; if (extWeapon.Modes.Count <= 0) { return(false); } ; foreach (var mode in extWeapon.Modes) { if (mode.Value.AmmoCategory == null) { continue; } ; if (mode.Value.AmmoCategory.BaseCategory == AmmoCategory.NotSet) { return(true); } ; } return(false); }
public static bool isWeaponHasClusterAmmo(Weapon weapon) { if (weapon.ammoBoxes.Count == 0) { return(false); } int ClusterCount = 0; bool ClusterSetted = false; for (int index = 0; index < weapon.ammoBoxes.Count; ++index) { if (weapon.ammoBoxes[index].CurrentAmmo <= 0) { continue; } if (weapon.ammoBoxes[index].IsFunctional == false) { continue; } ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(weapon.ammoBoxes[index].ammoDef.Description.Id); int ammoShots = (weapon.weaponDef.ShotsWhenFired + extAmmo.ShotsWhenFired) * (weapon.weaponDef.ProjectilesPerShot + extAmmo.ProjectilesPerShot); if (ClusterSetted == false) { ClusterSetted = true; ClusterCount = ammoShots; continue; } ; if (ClusterCount != ammoShots) { return(true); } } return(false); }
public static bool isWeaponHasHeatAmmo(Weapon weapon) { if (weapon.ammoBoxes.Count == 0) { return(false); } float HeatPerShot = 0; bool HeatSetted = false; for (int index = 0; index < weapon.ammoBoxes.Count; ++index) { if (weapon.ammoBoxes[index].CurrentAmmo <= 0) { continue; } if (weapon.ammoBoxes[index].IsFunctional == false) { continue; } ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(weapon.ammoBoxes[index].ammoDef.Description.Id); if (HeatSetted == false) { HeatSetted = true; HeatPerShot = extAmmo.HeatDamagePerShot; continue; } ; if (HeatPerShot != extAmmo.HeatDamagePerShot) { return(true); } } return(false); }
public static void applyWeaponAmmoMode(Weapon weapon, string modeId, string ammoId) { ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); CustomAmmoCategoriesLog.Log.LogWrite("applyWeaponAmmoMode(" + weapon.defId + "," + modeId + "," + ammoId + ")\n"); if (extWeapon.Modes.ContainsKey(modeId)) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == false) { weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.WeaponModeStatisticName, modeId); } else { weapon.StatCollection.Set <string>(CustomAmmoCategories.WeaponModeStatisticName, modeId); } } else { CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no mode " + modeId + "\n", true); } if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false) { weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } else { weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } }
public static HitGeneratorType getHitGenerator(Weapon weapon) { HitGeneratorType result = HitGeneratorType.NotSet; if (weapon.weaponDef.ComponentTags.Contains("wr-clustered_shots")) { result = HitGeneratorType.Individual; } if (result == HitGeneratorType.NotSet) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { string modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.Modes.ContainsKey(modeId)) { result = extWeapon.Modes[modeId].HitGenerator; } } } if (result == HitGeneratorType.NotSet) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); result = CustomAmmoCategories.findExtAmmo(ammoId).HitGenerator; } } if (result == HitGeneratorType.NotSet) { switch (weapon.Type) { case WeaponType.Autocannon: case WeaponType.Gauss: case WeaponType.Laser: case WeaponType.PPC: case WeaponType.Flamer: case WeaponType.Melee: result = HitGeneratorType.Individual; break; case WeaponType.LRM: result = HitGeneratorType.Cluster; break; case WeaponType.SRM: result = HitGeneratorType.Individual; break; case WeaponType.MachineGun: result = HitGeneratorType.Individual; break; default: result = HitGeneratorType.Individual; break; } } return(result); }
public static bool getWeaponDamageOnJamming(Weapon weapon) { TripleBoolean result = TripleBoolean.NotSet; ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.Modes.Count > 0) { string modeId = ""; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); } else { modeId = extWeapon.baseModeId; } if (extWeapon.Modes.ContainsKey(modeId)) { result = extWeapon.Modes[modeId].DamageOnJamming; } } if (result == TripleBoolean.NotSet) { result = extWeapon.DamageOnJamming; } return(result == TripleBoolean.True); }
public static bool getWeaponAlwaysIndirectVisuals(Weapon weapon) { bool result = false; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { string CurrentAmmoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); ExtAmmunitionDef extAmmoDef = CustomAmmoCategories.findExtAmmo(CurrentAmmoId); if (extAmmoDef.AlwaysIndirectVisuals != TripleBoolean.NotSet) { result = (extAmmoDef.AlwaysIndirectVisuals == TripleBoolean.True); } } if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); string modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); if (extWeapon.Modes.ContainsKey(modeId)) { WeaponMode mode = extWeapon.Modes[modeId]; if (mode.AlwaysIndirectVisuals != TripleBoolean.NotSet) { result = (mode.AlwaysIndirectVisuals == TripleBoolean.True); } } } return(result); }
public static float calcHeatCoeff(AbstractActor unit, ICombatant target) { AbstractActor targetActor = (target as AbstractActor); //if (targetActor == null) { return 0.0f; }; float result = 0; foreach (Weapon weapon in unit.Weapons) { if (weapon.HeatDamagePerShot == 0) { continue; } float toHit = 0f; if (unit.HasLOFToTargetUnit(target, weapon.MaxRange, CustomAmmoCategories.getIndirectFireCapable(weapon))) { toHit = weapon.GetToHitFromPosition(target, 1, unit.CurrentPosition, target.CurrentPosition, true, (targetActor != null) ? targetActor.IsEvasive : false, false); } result += ( weapon.ShotsWhenFired * weapon.ProjectilesPerShot * weapon.HeatDamagePerShot * toHit ); } return(result); }
public static void AddJam(AbstractActor actor, Weapon weapon) { if (CustomAmmoCategories.getWeaponDamageOnJamming(weapon) == false) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.JammedWeaponStatisticName) == false) { weapon.StatCollection.AddStatistic <bool>(CustomAmmoCategories.JammedWeaponStatisticName, false); } weapon.StatCollection.Set <bool>(CustomAmmoCategories.JammedWeaponStatisticName, true); weapon.StatCollection.Set <bool>(CustomAmmoCategories.TemporarilyDisabledStatisticName, true); actor.Combat.MessageCenter.PublishMessage( new AddSequenceToStackMessage( new ShowActorInfoSequence(actor, $"{weapon.Name} Jammed!", FloatieMessage.MessageNature.Debuff, true))); } else { var isDestroying = weapon.DamageLevel != ComponentDamageLevel.Functional; var damageLevel = isDestroying ? ComponentDamageLevel.Destroyed : ComponentDamageLevel.Penalized; var fakeHit = new WeaponHitInfo(-1, -1, -1, -1, string.Empty, string.Empty, -1, null, null, null, null, null, null, null, AttackDirection.None, Vector2.zero, null); weapon.DamageComponent(fakeHit, damageLevel, true); var message = isDestroying ? $"{weapon.Name} misfire: Destroyed!" : $"{weapon.Name} misfire: Damaged!"; actor.Combat.MessageCenter.PublishMessage( new AddSequenceToStackMessage( new ShowActorInfoSequence(actor, message, FloatieMessage.MessageNature.Debuff, true))); } }
public static float getWeaponFlatJammingChance(Weapon weapon) { float result = 0; float mult = 0; float baseval = 0f; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId); result += extAmmo.FlatJammingChance; mult += extAmmo.GunneryJammingMult; if (extAmmo.GunneryJammingBase > 0) { baseval = extAmmo.GunneryJammingBase; } ; } ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); result += extWeapon.FlatJammingChance; mult += extWeapon.GunneryJammingMult; if ((extWeapon.GunneryJammingBase > 0) && (baseval == 0f)) { baseval = extWeapon.GunneryJammingBase; } ; if (extWeapon.Modes.Count > 0) { string modeId = ""; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); } else { modeId = extWeapon.baseModeId; } if (extWeapon.Modes.ContainsKey(modeId)) { result += extWeapon.Modes[modeId].FlatJammingChance; mult += extWeapon.Modes[modeId].GunneryJammingMult; if ((extWeapon.Modes[modeId].GunneryJammingBase > 0) && (baseval == 0f)) { baseval = extWeapon.Modes[modeId].GunneryJammingBase; } ; } } if (weapon.parent != null) { if (baseval == 0f) { baseval = 5f; } result += ((baseval - weapon.parent.SkillGunnery) * mult); } return(result); }
public static void SetWeaponAmmo(Weapon weapon, string ammoId) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false) { weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } else { weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } }
public static HashSet <string> getWeaponAvaibleAmmoForMode(Weapon weapon, string modeId) { HashSet <string> result = new HashSet <string>(); CustomAmmoCategory ammoCategory = CustomAmmoCategories.find(weapon.AmmoCategory.ToString()); ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.AmmoCategory.BaseCategory == weapon.AmmoCategory) { ammoCategory = extWeapon.AmmoCategory; } if (extWeapon.Modes.Count < 1) { CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no modes. Even base mode. This means something is very very wrong\n", true); return(result); } if (extWeapon.Modes.ContainsKey(modeId) == false) { CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no mode " + modeId + ".\n", true); return(result); } WeaponMode weaponMode = extWeapon.Modes[modeId]; if (weaponMode.AmmoCategory.Index != ammoCategory.Index) { ammoCategory = weaponMode.AmmoCategory; } ; if (ammoCategory.Index == CustomAmmoCategories.NotSetCustomAmmoCategoty.Index) { result.Add(""); return(result); } ; foreach (AmmunitionBox box in weapon.ammoBoxes) { if (box.IsFunctional == false) { continue; } if (box.CurrentAmmo <= 0) { continue; } CustomAmmoCategory boxAmmoCategory = CustomAmmoCategories.getAmmoAmmoCategory(box.ammoDef); if (boxAmmoCategory.Index == ammoCategory.Index) { if (result.Contains(box.ammoDef.Description.Id) == false) { result.Add(box.ammoDef.Description.Id); } } } return(result); }
public static int getWeaponAttackRecoil(Weapon weapon) { CustomAmmoCategoriesLog.Log.LogWrite("getWeaponAttackRecoil " + weapon.UIName + "\n"); if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false) { CustomAmmoCategoriesLog.Log.LogWrite(" weapon has no ammo\n"); return(weapon.weaponDef.AttackRecoil); } string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId); CustomAmmoCategoriesLog.Log.LogWrite(" modified AttackRecoil\n"); return(weapon.weaponDef.AttackRecoil + extAmmo.AttackRecoil); }
public static bool isWeaponCanUseAmmo(WeaponDef weaponDef, AmmunitionDef ammoDef) { ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoDef.Description.Id); CustomAmmoCategory ammoCategory = extAmmo.AmmoCategory; if (ammoCategory.BaseCategory == AmmoCategory.NotSet) { ammoCategory = CustomAmmoCategories.find(ammoDef.Category.ToString()); } ; if (ammoCategory.BaseCategory == AmmoCategory.NotSet) { return(false); } ; ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weaponDef.Description.Id); if (extWeapon.AmmoCategory.BaseCategory != AmmoCategory.NotSet) { if (extWeapon.AmmoCategory.Index == ammoCategory.Index) { return(true); } ; } else if (weaponDef.AmmoCategory != AmmoCategory.NotSet) { CustomAmmoCategory weaponAmmoCategory = CustomAmmoCategories.find(weaponDef.AmmoCategory.ToString()); if ((weaponAmmoCategory.BaseCategory != AmmoCategory.NotSet) && (weaponAmmoCategory.Index == ammoCategory.Index)) { return(true); } } foreach (var mode in extWeapon.Modes) { if (mode.Value.AmmoCategory == null) { continue; } ; if ((mode.Value.AmmoCategory.BaseCategory != AmmoCategory.NotSet) && (mode.Value.AmmoCategory.Index == ammoCategory.Index)) { return(true); } ; } return(false); }
public static CustomAmmoCategory getWeaponCustomAmmoCategory(Weapon weapon) { WeaponMode mode = CustomAmmoCategories.getWeaponMode(weapon); if (mode.AmmoCategory == null) { ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.AmmoCategory.BaseCategory != weapon.AmmoCategory) { return(CustomAmmoCategories.find(weapon.AmmoCategory.ToString())); } return(extWeapon.AmmoCategory); } return(mode.AmmoCategory); }
public static void AddCooldown(AbstractActor actor, Weapon weapon) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.CooldownWeaponStatisticName) == false) { weapon.StatCollection.AddStatistic <int>(CustomAmmoCategories.CooldownWeaponStatisticName, 0); } if (CustomAmmoCategories.getWeaponCooldown(weapon) > 0) { weapon.StatCollection.Set <int>(CustomAmmoCategories.CooldownWeaponStatisticName, CustomAmmoCategories.getWeaponCooldown(weapon)); weapon.StatCollection.Set <bool>(CustomAmmoCategories.TemporarilyDisabledStatisticName, true); actor.Combat.MessageCenter.PublishMessage( new AddSequenceToStackMessage( new ShowActorInfoSequence(actor, $"{weapon.Name} Cooldown!", FloatieMessage.MessageNature.Debuff, true))); } }
public static string getWeaponAmmoId(Weapon weapon) { if (CustomAmmoCategories.getWeaponCustomAmmoCategory(weapon) == CustomAmmoCategories.NotSetCustomAmmoCategoty) { return(""); } if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { return(weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>()); } if (weapon.ammoBoxes.Count == 0) { return(""); } ; return(weapon.ammoBoxes[0].ammoDef.Description.Id); }
public static void switchToMostClusterAmmo(Weapon weapon) { if (weapon.ammoBoxes.Count == 0) { return; } int ClusterShot = 0; string ammoId = ""; for (int index = 0; index < weapon.ammoBoxes.Count; ++index) { if (weapon.ammoBoxes[index].CurrentAmmo <= 0) { continue; } if (weapon.ammoBoxes[index].IsFunctional == false) { continue; } ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(weapon.ammoBoxes[index].ammoDef.Description.Id); int ammoShots = (weapon.weaponDef.ShotsWhenFired + extAmmo.ShotsWhenFired) * (weapon.weaponDef.ProjectilesPerShot + extAmmo.ProjectilesPerShot); if (string.IsNullOrEmpty(ammoId)) { ammoId = weapon.ammoBoxes[index].ammoDef.Description.Id; ClusterShot = ammoShots; continue; } ; if (ClusterShot < ammoShots) { ammoId = weapon.ammoBoxes[index].ammoDef.Description.Id; ClusterShot = ammoShots; } } if (string.IsNullOrEmpty(ammoId) == false) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false) { weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } else { weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } } }
public static void switchToMostHeatAmmo(Weapon weapon) { if (weapon.ammoBoxes.Count == 0) { return; } float HeatPerShot = 0; string ammoId = ""; for (int index = 0; index < weapon.ammoBoxes.Count; ++index) { if (weapon.ammoBoxes[index].CurrentAmmo <= 0) { continue; } if (weapon.ammoBoxes[index].IsFunctional == false) { continue; } ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(weapon.ammoBoxes[index].ammoDef.Description.Id); if (string.IsNullOrEmpty(ammoId)) { ammoId = weapon.ammoBoxes[index].ammoDef.Description.Id; HeatPerShot = extAmmo.HeatDamagePerShot; continue; } ; if (HeatPerShot < extAmmo.HeatDamagePerShot) { ammoId = weapon.ammoBoxes[index].ammoDef.Description.Id; HeatPerShot = extAmmo.HeatDamagePerShot; } } if (string.IsNullOrEmpty(ammoId) == false) { if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == false) { weapon.StatCollection.AddStatistic <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } else { weapon.StatCollection.Set <string>(CustomAmmoCategories.AmmoIdStatName, ammoId); } } }
public static float getWeaponEvasivePipsIgnored(Weapon weapon) { float result = weapon.weaponDef.EvasivePipsIgnored; //CustomAmmoCategoriesLog.Log.LogWrite("getWeaponEvasivePipsIgnored " + weapon.UIName + "\n"); if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId); result += extAmmo.EvasivePipsIgnored; } if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { result += CustomAmmoCategories.getWeaponMode(weapon).EvasivePipsIgnored; } //CustomAmmoCategoriesLog.Log.LogWrite(" modified EvasivePipsIgnored\n"); return(result); }
public static float WeaponDamageRevDistance(ICombatant attacker, ICombatant target, Weapon weapon, float damage, float rawDamage) { var damagePerShot = weapon.DamagePerShot; var adjustment = rawDamage / damagePerShot; float varianceMultiplier; var distance = Vector3.Distance(attacker.TargetPosition, target.TargetPosition); var distanceDifference = weapon.MaxRange - distance; var distanceRatio = distanceDifference / weapon.MinRange; var baseMultiplier = CustomAmmoCategories.getWeaponDistantVariance(weapon); var distanceBasedFunctionMultiplier = (float)Math.Atan(1f / (Pi2 * distanceRatio + baseMultiplier)); if (distance < weapon.MinRange) { varianceMultiplier = 0; } else if (distance <= weapon.MaxRange) { varianceMultiplier = Mathf.Max( baseMultiplier, Mathf.Min( 1.0f, distanceBasedFunctionMultiplier )); } else // out of range ¯\_(ツ)_/¯ { return(damage); } var computedDamage = damage * varianceMultiplier * adjustment; CustomAmmoCategoriesLog.Log.LogWrite($"reverseDistanceBasedFunctionMultiplier: {distanceBasedFunctionMultiplier}\n" + $"defId: {weapon.defId}\n" + $"varianceMultiplier: {varianceMultiplier}\n" + $"adjustment: {adjustment}\n" + $"damage: {damage}\n" + $"distance: {distance}\n" + $"max: {weapon.MaxRange}\n" + $"distanceDifference {distanceDifference}\n" + $"baseMultplier: {baseMultiplier}\n" + $"distanceRatio: {distanceRatio}\n" + $"computedDamage: {computedDamage}\n"); return(computedDamage); }
public static float getDirectFireModifier(Weapon weapon) { ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.weaponDef.Description.Id); float result = extWeapon.DirectFireModifier; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName)) { string ammoId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); result += CustomAmmoCategories.findExtAmmo(ammoId).DirectFireModifier; } if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName)) { string modeId = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); if (extWeapon.Modes.ContainsKey(modeId)) { result += extWeapon.Modes[modeId].DirectFireModifier; } } return(result); }
public static WeaponCategory isWeaponUseInMelee(Weapon weapon) { if (weapon.Category != WeaponCategory.AntiPersonnel) { return(weapon.Category); } ; ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.NotUseInMelee != TripleBoolean.True) { return(weapon.Category); } ; switch (weapon.Type) { case WeaponType.AMS: return(WeaponCategory.AMS); case WeaponType.Autocannon: return(WeaponCategory.Ballistic); case WeaponType.Flamer: return(WeaponCategory.Energy); case WeaponType.Gauss: return(WeaponCategory.Ballistic); case WeaponType.Laser: return(WeaponCategory.Energy); case WeaponType.LRM: return(WeaponCategory.Missile); case WeaponType.MachineGun: return(WeaponCategory.Ballistic); case WeaponType.Melee: return(WeaponCategory.Melee); case WeaponType.NotSet: return(WeaponCategory.NotSet); case WeaponType.PPC: return(WeaponCategory.Energy); case WeaponType.SRM: return(WeaponCategory.Missile); default: return(WeaponCategory.NotSet); } }
public static List <DamagePredictRecord> getWeaponDamagePredict(AbstractActor unit, ICombatant target, Weapon weapon) { List <DamagePredictRecord> result = new List <DamagePredictRecord>(); ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.defId); if (extWeapon.Modes.Count < 1) { CustomAmmoCategoriesLog.Log.LogWrite("WARNING! " + weapon.defId + " has no modes. Even base mode. This means something is very very wrong\n", true); return(result); } string currentMode = extWeapon.baseModeId; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.WeaponModeStatisticName) == true) { currentMode = weapon.StatCollection.GetStatistic(CustomAmmoCategories.WeaponModeStatisticName).Value <string>(); } string currentAmmo = ""; if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true) { currentAmmo = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>(); } foreach (var mode in extWeapon.Modes) { HashSet <string> ammos = CustomAmmoCategories.getWeaponAvaibleAmmoForMode(weapon, mode.Value.Id); List <int> hitLocations = null; float AverageArmor = float.NaN; foreach (var ammo in ammos) { DamagePredictRecord record = new DamagePredictRecord(ammo, mode.Value.Id); CustomAmmoCategories.fillWeaponPredictRecord(ref record, unit, target, weapon, ref hitLocations, ref AverageArmor); result.Add(record); } } CustomAmmoCategories.applyWeaponAmmoMode(weapon, currentMode, currentAmmo); return(result); }
public static bool Prefix(AbstractActor __instance) { var actor = __instance; foreach (Weapon weapon in actor.Weapons) { if (weapon.roundsSinceLastFire <= 0) { continue; } ; if (CustomAmmoCategories.IsCooldown(weapon) > 0) { var removedJam = CustomAmmoCategories.AttemptToRemoveCooldown(actor, weapon); CustomAmmoCategoriesLog.Log.LogWrite($"Removed cooldown? {removedJam}\n"); } } if (actor.IsShutDown) { return(true); } foreach (Weapon weapon in actor.Weapons) { if (weapon.roundsSinceLastFire <= 0) { continue; } ; if (CustomAmmoCategories.IsJammed(weapon)) { var removedJam = CustomAmmoCategories.AttemptToRemoveJam(actor, weapon); CustomAmmoCategoriesLog.Log.LogWrite($"Removed Jam? {removedJam}\n"); } } return(true); }