Esempio n. 1
0
        static void Postfix(TooltipPrefab_Weapon __instance, object data,
                            TextMeshProUGUI ___rangeType, TextMeshProUGUI ___damage)
        {
            Mod.Log.Debug?.Write("TP_W:SD entered.");

            ___rangeType.enabled = false;
            Transform rangeLabelT = ___rangeType.gameObject.transform.parent;

            rangeLabelT.gameObject.SetActive(false);

            Transform     layoutT  = rangeLabelT.gameObject.transform.parent;
            RectTransform rLayoutT = layoutT.gameObject.GetComponent <RectTransform>();

            LayoutRebuilder.ForceRebuildLayoutImmediate(rLayoutT);

            WeaponDef weaponDef = (WeaponDef)data;

            if (weaponDef != null)
            {
                Mod.Log.Debug?.Write($"  Updating tooltip for weapon: {weaponDef.Description.UIName}");
                if (CustomAmmoCategories.isRegistredWeapon(weaponDef.Description.Id))
                {
                    // Is a CAC weapon, use HasShells
                    ExtWeaponDef extDef = CustomAmmoCategories.getExtWeaponDef(weaponDef.Description.Id);
                    Mod.Log.Debug?.Write($" Found CAC extension for weapon.");
                    if (extDef == null)
                    {
                        Mod.Log.Warn?.Write($"Failed to load CAC ExtWeaponDef for {weaponDef.Description.Id}, but it was registered!");
                        return;
                    }

                    /*
                     * "ImprovedBallistic": true, - whether use or not own ballistic weapon effect engine.
                     *  Difference between "improved" and vanilla engine:
                     *  1. Improved mode uses ShotsWhenFire properly (vanilla had not used them at all)
                     *  3. Improved mode fire ShotsWhenFire volleys with ProjectilesPerShot bullets in each.
                     *      Bullets in one volley fired simultaneously instead of one by one (as in WeaponRealizer)
                     *      But damage still dealt once per volley, not per bullet, to keep compatibility with vanilla.
                     *  NOTE! If ImprovedBallistic is set DisableClustering is forced to true and "wr-clustered_shots" tag removed from definition.
                     *
                     *  "BallisticDamagePerPallet": true - if true damage inflicted per pallet instead of per shot.
                     *  Only working with ImprovedBallistic true, ballistic weapon effect and HasShels false
                     *              Damage will be divided by ProjectilesPerShot value, heat damage and stable damage too.
                     */

                    /*
                     *  PER HARKONNEN HALLOWED BY THINE NAME
                     *  If ImprovedBallistic = false OR
                     *     ImprovedBallistic = true AND (HasShells = true or BallisticDamageperPellet = false) - > damage x shots
                     *  If ImprovedBallistic = true and BallisticDamageperPellet = true and DamageNotDivided = true > damage x projectiles x shots
                     *  If ImprovedBallistic = true and BallisticDamageperPellet = true and DamageNotDivided = false > (damage/projectiles) x  projectiles x shots
                     */

                    if (extDef.ImprovedBallistic)
                    {
                        // Damage is damage * shotsWhenFired (each shot = volley of projectiles, projectiles are visual only)
                        float totalDamage = weaponDef.Damage * weaponDef.ShotsWhenFired;
                        if (weaponDef.ShotsWhenFired != 1)
                        {
                            string localText = $"{weaponDef.Damage} x {weaponDef.ShotsWhenFired} = {totalDamage}";
                            Mod.Log.Debug?.Write($"ImprovedBallistic weapon damage set to: {localText}<page>");
                            ___damage.SetText(localText);
                        }

                        if (extDef.HasShells == TripleBoolean.True || extDef.BallisticDamagePerPallet != TripleBoolean.True)
                        {
                            if (weaponDef.ShotsWhenFired != 1)
                            {
                                // damage x shots = total
                                totalDamage = weaponDef.Damage * weaponDef.ShotsWhenFired;
                                string localText = $"{weaponDef.Damage} x {weaponDef.ShotsWhenFired} = {totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + HasShells || !BallisticDamagePerPallet weapon damage set to: {localText}; ShotsWhenFired != 1");
                                ___damage.SetText(localText);
                            }
                            else
                            {
                                totalDamage = weaponDef.Damage * weaponDef.ShotsWhenFired;
                                string localText = $"{totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + HasShells || !BallisticDamagePerPallet weapon damage set to: {localText}; ShotsWhenFired == 1");
                                ___damage.SetText(localText);
                            }
                        }

                        if (extDef.BallisticDamagePerPallet == TripleBoolean.True && extDef.DamageNotDivided == TripleBoolean.True)
                        {
                            if (weaponDef.ShotsWhenFired != 1 && weaponDef.ProjectilesPerShot != 1)
                            {
                                totalDamage = weaponDef.Damage * weaponDef.ProjectilesPerShot * weaponDef.ShotsWhenFired;
                                string localText = $"{weaponDef.Damage} x {weaponDef.ProjectilesPerShot} x {weaponDef.ShotsWhenFired} = {totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + BallisticDamagePerPallet + DamageNotDivided weapon damage set to: {localText}; ProjectilesPerShot != 1 AND ShotsWhenFired != 1");
                                ___damage.SetText(localText);
                            }
                            else if (weaponDef.ShotsWhenFired == 1 && weaponDef.ProjectilesPerShot != 1)
                            {
                                totalDamage = weaponDef.Damage * weaponDef.ProjectilesPerShot * weaponDef.ShotsWhenFired;
                                string localText = $"{weaponDef.Damage} x {weaponDef.ProjectilesPerShot}= {totalDamage}";
                                Mod.Log.Debug?.Write(
                                    $"ImprovedBallistic + BallisticDamagePerPallet + DamageNotDivided weapon damage set to: {localText}; ProjectilesPerShot != 1 BUT ShotsWhenFired == 1");
                                ___damage.SetText(localText);
                            }
                            else if (weaponDef.ShotsWhenFired != 1 && weaponDef.ProjectilesPerShot == 1)
                            {
                                totalDamage = weaponDef.Damage * weaponDef.ProjectilesPerShot * weaponDef.ShotsWhenFired;
                                string localText = $"{weaponDef.Damage} x {weaponDef.ShotsWhenFired} = {totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + BallisticDamagePerPallet + DamageNotDivided weapon damage set to: {localText}; ProjectilesPerShot == 1 BUT ShotsWhenFired != 1");
                                ___damage.SetText(localText);
                            }
                            else
                            {
                                totalDamage = weaponDef.Damage * weaponDef.ProjectilesPerShot * weaponDef.ShotsWhenFired;
                                string localText = $"{totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + HasShells || !BallisticDamagePerPallet weapon damage set to: {localText}; ShotsWhenFired AND ProjectilesPerShot == 1");
                                ___damage.SetText(localText);
                            }
                        }

                        if (extDef.BallisticDamagePerPallet == TripleBoolean.True && extDef.DamageNotDivided != TripleBoolean.True)
                        {
                            if (weaponDef.ShotsWhenFired != 1 && weaponDef.ProjectilesPerShot != 1)
                            {
                                float damagePerPellet = weaponDef.Damage / weaponDef.ProjectilesPerShot;
                                totalDamage = damagePerPellet * weaponDef.ShotsWhenFired * weaponDef.ProjectilesPerShot;
                                string localText = $"{damagePerPellet} x {weaponDef.ShotsWhenFired} x {weaponDef.ProjectilesPerShot} = {totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + BallisticDamagePerPallet + !DamageNotDivided weapon damage set to: {localText}; ProjectilesPerShot != 1 AND ShotsWhenFired != 1");
                                ___damage.SetText(localText);
                            }
                            else if (weaponDef.ShotsWhenFired == 1 && weaponDef.ProjectilesPerShot != 1)
                            {
                                float damagePerPellet = weaponDef.Damage / weaponDef.ProjectilesPerShot;
                                totalDamage = damagePerPellet * weaponDef.ShotsWhenFired * weaponDef.ProjectilesPerShot;
                                string localText = $"{damagePerPellet} x {weaponDef.ProjectilesPerShot} = {totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + BallisticDamagePerPallet + !DamageNotDivided weapon damage set to: {localText}; ProjectilesPerShot != 1 BUT ShotsWhenFired == 1");
                                ___damage.SetText(localText);
                            }
                            else if (weaponDef.ShotsWhenFired != 1 && weaponDef.ProjectilesPerShot == 1)
                            {
                                float damagePerPellet = weaponDef.Damage / weaponDef.ProjectilesPerShot;
                                totalDamage = damagePerPellet * weaponDef.ShotsWhenFired * weaponDef.ProjectilesPerShot;
                                string localText = $"{damagePerPellet} x {weaponDef.ShotsWhenFired} = {totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + BallisticDamagePerPallet + !DamageNotDivided weapon damage set to: {localText}; ProjectilesPerShot == 1 BUT ShotsWhenFired != 1");
                                ___damage.SetText(localText);
                            }
                            else
                            {
                                float damagePerPellet = weaponDef.Damage / weaponDef.ProjectilesPerShot;
                                totalDamage = damagePerPellet * weaponDef.ShotsWhenFired * weaponDef.ProjectilesPerShot;
                                string localText = $"{totalDamage}";
                                Mod.Log.Debug?.Write($"ImprovedBallistic + BallisticDamagePerPallet + !DamageNotDivided weapon damage set to: {localText}; ProjectilesPerShot == 1 AND ShotsWhenFired == 1");
                                ___damage.SetText(localText);
                            }
                        }
                    }
                    else
                    {
                        // Vanilla calculations, so ProjectilesPerShot is visual only. See https://github.com/BattletechModders/IRTweaks/issues/8
                        float totalDamage = weaponDef.Damage * weaponDef.ShotsWhenFired;
                        if (weaponDef.ShotsWhenFired != 1)
                        {
                            string localText = $"{weaponDef.Damage} x {weaponDef.ShotsWhenFired} shots = {totalDamage}";
                            Mod.Log.Debug?.Write($"Vanilla + ShotsWhenFire > 1 weapon damage set to: {localText}");
                            ___damage.SetText(localText);
                        }
                        else
                        {
                            string localText = $"{weaponDef.Damage}";
                            Mod.Log.Debug?.Write($"Vanilla + 1 ShotsWhenFired weapon damage set to: {localText}");
                            ___damage.SetText(localText);
                        }
                    }

                    /*
                     * "AOEDamage": 0 - if > 0 alternative AoE damage algorithm will be used. Main projectile will not always miss.
                     *  Instead it will inflict damage twice  one for main target - direct hit (this damage can be have variance)
                     *  and second for all targets in AoE range including main.
                     *
                     *  "AOEHeatDamage": 0 - if > 0 alternative AoE damage algorithm will be used. Main projectile will not always miss.
                     *  Instead it will inflict damage twice one for main target - direct hit (this damage can be have variance)
                     *  and second for all targets in AoE range including main.
                     *
                     *  "AOEInstability": 0 - instability AoE damage
                     */
                }
                else
                {
                    // Not a CAC weapon, vanilla, so ProjectilesPerShot is visual only. See https://github.com/BattletechModders/IRTweaks/issues/8
                    float totalDamage = weaponDef.Damage * weaponDef.ShotsWhenFired;
                    if (weaponDef.ShotsWhenFired != 1)
                    {
                        string localText = $"{weaponDef.Damage} x {weaponDef.ShotsWhenFired} shots = {totalDamage}";
                        Mod.Log.Debug?.Write($"Vanilla + ShotsWhenFire > 1 weapon damage set to: {localText}");
                        ___damage.SetText(localText);
                    }
                    else
                    {
                        string localText = $"{weaponDef.Damage}";
                        Mod.Log.Debug?.Write($"Vanilla + 1 ShotsWhenFired weapon damage set to: {localText}");
                        ___damage.SetText(localText);
                    }
                }
            }
        }
Esempio n. 2
0
        public static bool Prefix(AttackDirector.AttackSequence __instance, Weapon weapon, int groupIdx, int weaponIdx, int numberOfShots, bool indirectFire, float dodgedDamage, ref WeaponHitInfo __result)
        {
            WeaponHitInfo hitInfo = new WeaponHitInfo();

            hitInfo.attackerId        = __instance.attacker.GUID;
            hitInfo.targetId          = __instance.target.GUID;
            hitInfo.numberOfShots     = numberOfShots;
            hitInfo.stackItemUID      = __instance.stackItemUID;
            hitInfo.attackSequenceId  = __instance.id;
            hitInfo.attackGroupIndex  = groupIdx;
            hitInfo.attackWeaponIndex = weaponIdx;
            hitInfo.toHitRolls        = new float[numberOfShots];
            hitInfo.locationRolls     = new float[numberOfShots];
            hitInfo.dodgeRolls        = new float[numberOfShots];
            hitInfo.dodgeSuccesses    = new bool[numberOfShots];
            hitInfo.hitLocations      = new int[numberOfShots];
            hitInfo.hitPositions      = new Vector3[numberOfShots];
            hitInfo.hitVariance       = new int[numberOfShots];
            hitInfo.hitQualities      = new AttackImpactQuality[numberOfShots];
            if (AttackDirector.hitLogger.IsLogEnabled)
            {
                Vector3         collisionWorldPos;
                LineOfFireLevel lineOfFire           = __instance.Director.Combat.LOS.GetLineOfFire(__instance.attacker, __instance.attackPosition, __instance.target, __instance.target.CurrentPosition, __instance.target.CurrentRotation, out collisionWorldPos);
                float           allModifiers         = __instance.Director.Combat.ToHit.GetAllModifiers(__instance.attacker, weapon, __instance.target, __instance.attackPosition + __instance.attacker.HighestLOSPosition, __instance.target.TargetPosition, lineOfFire, __instance.isMoraleAttack);
                string          modifiersDescription = __instance.Director.Combat.ToHit.GetAllModifiersDescription(__instance.attacker, weapon, __instance.target, __instance.attackPosition + __instance.attacker.HighestLOSPosition, __instance.target.TargetPosition, lineOfFire, __instance.isMoraleAttack);
                Pilot           pilot = __instance.attacker.GetPilot();
                AttackDirector.hitLogger.Log((object)string.Format("======================================== Unit Firing: {0} | Weapon: {1} | Shots: {2}", (object)__instance.attacker.DisplayName, (object)weapon.Name, (object)numberOfShots));
                AttackDirector.hitLogger.Log((object)string.Format("======================================== Hit Info: GROUP {0} | ID {1}", (object)groupIdx, (object)weaponIdx));
                AttackDirector.hitLogger.Log((object)string.Format("======================================== MODIFIERS: {0}... FINAL: [[ {1} ]] ", (object)modifiersDescription, (object)allModifiers));
                if (pilot != null)
                {
                    AttackDirector.hitLogger.Log((object)__instance.Director.Combat.ToHit.GetBaseToHitChanceDesc(__instance.attacker));
                }
                else
                {
                    AttackDirector.hitLogger.Log((object)string.Format("======================================== Gunnery Check: NO PILOT"));
                }
            }
            float toHitChance = __instance.Director.Combat.ToHit.GetToHitChance(__instance.attacker, weapon, __instance.target, __instance.attackPosition, __instance.target.CurrentPosition, __instance.numTargets, __instance.meleeAttackType, __instance.isMoraleAttack);

            if (Mech.TEST_KNOCKDOWN)
            {
                toHitChance = 1f;
            }
            if (AttackDirector.hitLogger.IsLogEnabled)
            {
                AttackDirector.hitLogger.Log((object)string.Format("======================================== HIT CHANCE: [[ {0:P2} ]]", (object)toHitChance));
            }
            hitInfo.attackDirection       = __instance.Director.Combat.HitLocation.GetAttackDirection(__instance.attackPosition, __instance.target);
            hitInfo.attackDirectionVector = __instance.Director.Combat.HitLocation.GetAttackDirectionVector(__instance.attackPosition, __instance.target);
            object[]         args       = new object[6];
            HitGeneratorType hitGenType = HitGeneratorType.NotSet;

            if (weapon.weaponDef.ComponentTags.Contains("wr-clustered_shots"))
            {
                hitGenType = HitGeneratorType.Individual;
            }
            if (hitGenType == HitGeneratorType.NotSet)
            {
                if (CustomAmmoCategories.checkExistance(weapon.StatCollection, CustomAmmoCategories.AmmoIdStatName) == true)
                {
                    string           ammoId  = weapon.StatCollection.GetStatistic(CustomAmmoCategories.AmmoIdStatName).Value <string>();
                    ExtAmmunitionDef extAmmo = CustomAmmoCategories.findExtAmmo(ammoId);
                    hitGenType = extAmmo.HitGenerator;
                }
                if (hitGenType == HitGeneratorType.NotSet)
                {
                    ExtWeaponDef extWeapon = CustomAmmoCategories.getExtWeaponDef(weapon.weaponDef.Description.Id);
                    hitGenType = extWeapon.HitGenerator;
                }
            }
            if (hitGenType != HitGeneratorType.NotSet)
            {
                switch (hitGenType)
                {
                case HitGeneratorType.Individual:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    break;

                case HitGeneratorType.Cluster:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetClusteredHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetClusteredHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case HitGeneratorType.Streak:
                    //args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    //typeof(AttackDirector.AttackSequence).GetMethod("GetClusteredHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    //hitInfo = (WeaponHitInfo)args[0];
                    AttackSequence_GenerateHitInfo.GetStreakHits(__instance, ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    //__instance.GetClusteredHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                default:
                    AttackDirector.attackLogger.LogError((object)string.Format("GenerateHitInfo found invalid weapon type: {0}, using basic hit info", (object)hitGenType));
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;
                }
            }
            else
            {
                switch (weapon.Type)
                {
                case WeaponType.Autocannon:
                case WeaponType.Gauss:
                case WeaponType.Laser:
                case WeaponType.PPC:
                case WeaponType.Flamer:
                case WeaponType.Melee:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case WeaponType.LRM:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetClusteredHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetClusteredHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case WeaponType.SRM:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                case WeaponType.MachineGun:
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;

                default:
                    AttackDirector.attackLogger.LogError((object)string.Format("GenerateHitInfo found invalid weapon type: {0}, using basic hit info", (object)weapon.Type));
                    args[0] = hitInfo; args[1] = groupIdx; args[2] = weaponIdx; args[3] = weapon; args[4] = toHitChance; args[5] = dodgedDamage;
                    typeof(AttackDirector.AttackSequence).GetMethod("GetIndividualHits", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, args);
                    hitInfo = (WeaponHitInfo)args[0];
                    //__instance.GetIndividualHits(ref hitInfo, groupIdx, weaponIdx, weapon, toHitChance, dodgedDamage);
                    break;
                }
            }
            __result = hitInfo;
            return(false);
            //return hitInfo;
        }