Esempio n. 1
0
        internal static void PerformOperation(this StatCollection collection, Statistic statistic, StatisticEffectData data)
        {
            var type    = Type.GetType(data.modType);
            var variant = new Variant(type);

            variant.SetValue(data.modValue);
            variant.statName = data.statName;
            collection.PerformOperation(statistic, data.operation, variant);
        }
        static void Postfix(object data, ref bool __result, BattleTech.UI.Tooltips.TooltipPrefab_Generic __instance)
        {
            if (!__result || ModBase.currentMech == null)
            {
                return;
            }

            if ((ModBase.Sim == null || ModBase.Sim.CurRoomState != DropshipLocation.MECH_BAY) && !ModBase.inMechLab)
            {
                return;
            }

            if (ModBase.combatConstants == null)
            {
                ModBase.combatConstants = CombatGameConstants.CreateFromSaved(UnityGameInstance.BattleTechGame);
            }

            MechDef    currentMech    = ModBase.currentMech;
            ChassisDef currentChassis = currentMech.Chassis;

            BaseDescriptionDef baseDescriptionDef = (BaseDescriptionDef)data;

            string extra_stats = string.Empty;

            switch (baseDescriptionDef.Id)
            {
            case "TooltipMechPerformanceFirepower":

                float alpha_damage      = 0;
                float alpha_instability = 0;
                float alpha_heat        = 0;

                // Calculate alpha strike total damage, heat damage and instability.
                foreach (MechComponentRef mechComponentRef in currentMech.Inventory)
                {
                    if (mechComponentRef.Def is WeaponDef weapon)
                    {
                        alpha_damage      += weapon.Damage * weapon.ShotsWhenFired;
                        alpha_instability += weapon.Instability * weapon.ShotsWhenFired;
                        alpha_heat        += weapon.HeatDamage * weapon.ShotsWhenFired;
                    }
                }

                if (alpha_damage > 0)
                {
                    if (alpha_heat > 0)
                    {
                        extra_stats += string.Format("Alpha strike damage: <b>{0}</b> ( <b>{1} H</b> )\n", alpha_damage, alpha_heat);
                    }
                    else
                    {
                        extra_stats += string.Format("Alpha strike damage: <b>{0}</b>\n", alpha_damage);
                    }
                }

                if (alpha_instability > 0)
                {
                    extra_stats += string.Format("Alpha strike stability damage: <b>{0}</b>\n", alpha_instability);
                }

                break;

            case "TooltipMechPerformanceHeat":
                HeatConstantsDef heatConstants = ModBase.combatConstants.Heat;

                float total_heat_sinking = heatConstants.InternalHeatSinkCount * heatConstants.DefaultHeatSinkDissipationCapacity;
                float heat_sinking_ratio = 1;
                float total_weapon_heat  = 0;
                float weapon_heat_ratio  = 1;

                int max_heat = heatConstants.MaxHeat;

                foreach (MechComponentRef mechComponentRef in currentMech.Inventory)
                {
                    if (mechComponentRef.Def == null)
                    {
                        mechComponentRef.RefreshComponentDef();
                    }

                    // Weapon total heat
                    if (mechComponentRef.Def is WeaponDef weapon)
                    {
                        total_weapon_heat += (float)weapon.HeatGenerated;
                    }

                    // Heat sink total dissipation
                    else if (mechComponentRef.Def is HeatSinkDef heat_sink)
                    {
                        total_heat_sinking += heat_sink.DissipationCapacity;
                    }

                    // Bank/Exchanger effects
                    if (mechComponentRef.Def.statusEffects != null)
                    {
                        foreach (EffectData effect in mechComponentRef.Def.statusEffects)
                        {
                            StatisticEffectData statisticData = effect.statisticData;
                            if (statisticData.statName == "MaxHeat")
                            {
                                BTStatistics.ApplyEffectStatistic(statisticData, ref max_heat);
                            }
                            else if (statisticData.statName == "HeatGenerated" && statisticData.targetCollection == StatisticEffectData.TargetCollection.Weapon)
                            {
                                BTStatistics.ApplyEffectStatistic(statisticData, ref weapon_heat_ratio);
                            }
                        }
                    }
                }

                total_weapon_heat  *= weapon_heat_ratio;
                total_heat_sinking *= heat_sinking_ratio;

                extra_stats += string.Format("Heat dissipation: <b>{0}</b>\n", (int)total_heat_sinking);

                if (total_weapon_heat > 0)
                {
                    extra_stats += string.Format("Alpha strike heat: <b>{0}</b>\n", (int)total_weapon_heat);
                    extra_stats += string.Format("Alpha strike heat delta: <b>{0}</b>\n", (int)(total_weapon_heat - total_heat_sinking));
                }

                extra_stats += string.Format("Max heat capacity: <b>{0}</b>\n", (int)max_heat);

                float jump_distance = BTMechDef.GetJumpJetsMaxDistance(currentMech);
                if (jump_distance > 0)
                {
                    float max_jump_heat = ((jump_distance / heatConstants.JumpHeatUnitSize) + 1) * heatConstants.JumpHeatPerUnit;
                    max_jump_heat *= heatConstants.GlobalHeatIncreaseMultiplier;
                    max_jump_heat  = Mathf.Max(heatConstants.JumpHeatMin, max_jump_heat);

                    extra_stats += string.Format("Max jump heat: <b>{0}</b>\n", (int)max_jump_heat);
                }
                break;

            case "TooltipMechPerformanceSpeed":
                extra_stats += string.Format("Walk distance: <b>{0}m</b>\n", currentChassis.MovementCapDef.MaxWalkDistance);
                extra_stats += string.Format("Sprint distance: <b>{0}m</b>\n", currentChassis.MovementCapDef.MaxSprintDistance);

                float jump_max_distance = BTMechDef.GetJumpJetsMaxDistance(currentMech);
                if (jump_max_distance > 0)
                {
                    extra_stats += string.Format("Jump distance: <b>{0}m</b>\n", jump_max_distance);
                }

                break;

            case "TooltipMechPerformanceMelee":
                float melee_damage      = currentChassis.MeleeDamage;
                float melee_instability = currentChassis.MeleeInstability;

                float dfa_damage      = currentChassis.DFADamage * 2;
                float dfa_instability = currentChassis.DFAInstability;
                float dfa_self_damage = currentChassis.DFASelfDamage;

                float support_damage = 0;
                float support_heat   = 0;

                foreach (MechComponentRef mechComponentRef in currentMech.Inventory)
                {
                    if (mechComponentRef.Def == null)
                    {
                        mechComponentRef.RefreshComponentDef();
                    }

                    // Take Melee/DFA upgrades into account
                    if (mechComponentRef.Def.statusEffects != null)
                    {
                        foreach (EffectData effect in mechComponentRef.Def.statusEffects)
                        {
                            if (effect.effectType != EffectType.StatisticEffect)
                            {
                                continue;
                            }

                            if (effect.statisticData.targetWeaponSubType == WeaponSubType.Melee)
                            {
                                if (effect.statisticData.statName == "DamagePerShot")
                                {
                                    BTStatistics.ApplyEffectStatistic(effect.statisticData, ref melee_damage);
                                }
                                else if (effect.statisticData.statName == "Instability")
                                {
                                    BTStatistics.ApplyEffectStatistic(effect.statisticData, ref melee_instability);
                                }
                            }
                            else if (effect.statisticData.targetWeaponSubType == WeaponSubType.DFA)
                            {
                                if (effect.statisticData.statName == "DamagePerShot")
                                {
                                    BTStatistics.ApplyEffectStatistic(effect.statisticData, ref dfa_damage);
                                }
                                else if (effect.statisticData.statName == "Instability")
                                {
                                    BTStatistics.ApplyEffectStatistic(effect.statisticData, ref dfa_instability);
                                }
                                else if (effect.statisticData.statName == "DFASelfDamage")
                                {
                                    BTStatistics.ApplyEffectStatistic(effect.statisticData, ref dfa_self_damage);
                                }
                            }
                        }
                    }

                    // Calculate support weapon damage
                    else if (mechComponentRef.Def is WeaponDef weapon && weapon.Category == WeaponCategory.AntiPersonnel)
                    {
                        support_damage += weapon.Damage * weapon.ShotsWhenFired;
                        support_heat   += weapon.HeatDamage * weapon.ShotsWhenFired;
                    }
                }

                extra_stats += string.Format("Melee damage: <b>{0}</b> ( Stability: <b>{1}</b> )\n", melee_damage, melee_instability);

                if (BTMechDef.GetJumpJetsAmount(currentMech) > 0)
                {
                    extra_stats += string.Format("DFA damage: <b>{0}</b> ( Stability: <b>{1}</b> )\n", dfa_damage, dfa_instability);
                    extra_stats += string.Format("DFA self-damage: <b>{0}</b> ( per leg )\n", dfa_self_damage);
                }

                if (support_damage > 0)
                {
                    if (support_heat > 0)
                    {
                        extra_stats += string.Format("Support weapons damage: <b>{0}</b> ( <b>{1} H</b> )\n", support_damage, support_heat);
                    }
                    else
                    {
                        extra_stats += string.Format("Support weapons damage: <b>{0}</b>\n", support_damage);
                    }
                }

                break;

            // No idea what to put on those two. Feel free to contribute.
            case "TooltipMechPerformanceRange":
                break;

            case "TooltipMechPerformanceDurability":
                break;
            }

            if (extra_stats.Length != 0)
            {
                TextMeshProUGUI body = (TextMeshProUGUI)ReflectionHelper.GetPrivateField(__instance, "body");
                body.text = string.Format("{0}\n{1}", extra_stats, body.text);
            }
        }