Exemple #1
0
 // reduce upgrade components for the center torso that are 3 or larger
 public static void Postfix(HeatSinkDef __instance)
 {
     try
     {
         HeatSinkDef_FromJSON(__instance);
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
Exemple #2
0
 public static float DissipationCapacity(this HeatSinkDef @this)
 {
     try
     {
         if (@this.IsEngineCore())
         {
             return(EngineHeat.GetEngineHeatDissipation(mechDef.Inventory));
         }
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
     return(@this.DissipationCapacity);
 }
Exemple #3
0
        internal static void HeatSinkDef_FromJSON(HeatSinkDef def)
        {
            if (Mathf.Approximately(def.DissipationCapacity, 0))
            {
                return;
            }

            var statisticData = StatCollectionExtension
                                .HeatSinkCapacity(null)
                                .CreateStatisticData(
                StatCollection.StatOperation.Int_Add,
                (int)def.DissipationCapacity
                );

            def.AddPassiveStatisticEffectIfMissing(statisticData);
        }
Exemple #4
0
        public static float OverrideDissipationCapacity(this HeatSinkDef @this)
        {
            try
            {
                if (def != null && @this.Is <EngineCoreDef>())
                {
                    return(EngineHeat.GetEngineHeatDissipation(def.Inventory));
                }
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }

            return(@this.DissipationCapacity);
        }
            public static void Postfix(StatTooltipData __instance, MechDef def)
            {
                try
                {
                    if (!def.Chassis.ChassisTags.Contains("chassis_heatsinks"))
                    {
                        return;
                    }

                    Logger.Debug("[StatTooltipData_SetHeatData_POSTFIX] (" + def.Description.Id + ") def.Chassis.Heatsinks: " + def.Chassis.Heatsinks);

                    CombatGameConstants cgc = CombatGameConstants.GetInstance(UnityGameInstance.BattleTechGame);
                    float num = ((float)def.Chassis.Heatsinks + (float)cgc.Heat.InternalHeatSinkCount) * cgc.Heat.DefaultHeatSinkDissipationCapacity;
                    Logger.Debug("[StatTooltipData_SetHeatData_POSTFIX] (" + def.Description.Id + ") ChassisDissipationCapacity: " + num);

                    for (int i = 0; i < def.Inventory.Length; i++)
                    {
                        if (def.Inventory[i].ComponentDefType == ComponentType.HeatSink)
                        {
                            HeatSinkDef heatSinkDef = def.Inventory[i].Def as HeatSinkDef;
                            if (heatSinkDef != null)
                            {
                                num += heatSinkDef.DissipationCapacity;
                            }
                        }
                    }
                    Logger.Debug("[StatTooltipData_SetHeatData_POSTFIX] (" + def.Description.Id + ") TotalDissipationCapacity: " + num);

                    __instance.dataList.Remove("Heat Sinking");
                    __instance.dataList.Add(Strings.T("Heat Sinking"), Strings.T("{0} Heat", new object[]
                    {
                        num.ToString()
                    }));
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
Exemple #6
0
 public static float MatchingCount(IEnumerable <MechComponentRef> heatSinks, HeatSinkDef heatSinkDef)
 {
     return(heatSinks.Select(r => r.Def).Count(d => d == heatSinkDef));
 }
Exemple #7
0
        public TypedShopDefItem(ShopDefItem item)
        {
            try
            {
                Control.LogDebug(DInfo.TypedItemDef, "TypedShopDefItem.ctor");
                this.Count            = item.Count;
                this.ID               = item.ID;
                this.Type             = item.Type;
                this.DiscountModifier = item.DiscountModifier;
                this.Count            = item.Count;
                this.IsInfinite       = item.IsInfinite;
                this.IsDamaged        = item.IsDamaged;
                this.SellCost         = item.SellCost;
                this.SetGuid(item.GUID);
                Control.LogDebug(DInfo.TypedItemDef, "data copied");

                var dm = Control.State.Sim.DataManager;

                switch (item.Type)
                {
                case ShopItemType.Weapon:
                    Control.LogDebug(DInfo.TypedItemDef, "Weapon");
                    WeaponDef weaponDef = null;
                    if (dm.WeaponDefs.Exists(GUID))
                    {
                        weaponDef = dm.WeaponDefs.Get(GUID);
                    }
                    Component   = weaponDef;
                    Description = weaponDef.Description;
                    break;

                case ShopItemType.AmmunitionBox:
                    Control.LogDebug(DInfo.TypedItemDef, "AmmunitionBox");
                    AmmunitionBoxDef ammoboxDef = null;
                    if (dm.AmmoBoxDefs.Exists(GUID))
                    {
                        ammoboxDef = dm.AmmoBoxDefs.Get(GUID);
                    }
                    Component   = ammoboxDef;
                    Description = ammoboxDef.Description;
                    break;

                case ShopItemType.HeatSink:
                    Control.LogDebug(DInfo.TypedItemDef, "HeatSink");
                    HeatSinkDef hsDef = null;
                    if (dm.HeatSinkDefs.Exists(GUID))
                    {
                        hsDef = dm.HeatSinkDefs.Get(GUID);
                    }
                    Component   = hsDef;
                    Description = hsDef.Description;
                    break;

                case ShopItemType.JumpJet:
                    Control.LogDebug(DInfo.TypedItemDef, "JumpJet");
                    JumpJetDef jjDef = null;
                    if (dm.JumpJetDefs.Exists(GUID))
                    {
                        jjDef = dm.JumpJetDefs.Get(GUID);
                    }
                    Component   = jjDef;
                    Description = jjDef.Description;
                    break;

                case ShopItemType.Upgrade:
                    Control.LogDebug(DInfo.TypedItemDef, "Upgrade");
                    UpgradeDef upgradeDef = null;
                    if (dm.UpgradeDefs.Exists(GUID))
                    {
                        upgradeDef = dm.UpgradeDefs.Get(GUID);
                    }
                    Component   = upgradeDef;
                    Description = upgradeDef.Description;
                    break;

                case ShopItemType.MechPart:
                case ShopItemType.Mech:
                    Control.LogDebug(DInfo.TypedItemDef, item.Type.ToString());

                    var id = Control.GetMDefFromCDef(GUID);


                    Control.LogDebug(DInfo.TypedItemDef, $"MechPart/Mech {GUID} {ID} {id}");

                    if (dm.MechDefs.Exists(id))
                    {
                        Mech = dm.MechDefs.Get(id);
                    }
                    else
                    {
                        Control.LogError($"Cannot find Mech for {id}");
                    }

                    Description = Type == ShopItemType.MechPart ? Mech.Description : Mech.Chassis.Description;
                    break;
                }
                Control.LogDebug(DInfo.TypedItemDef, "done");
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
        }
Exemple #8
0
 internal static bool IsDHSKit(this HeatSinkDef def)
 {
     return(def.Description.Id == Control.settings.EngineKitDHS);
 }
Exemple #9
0
 internal static bool IsSingle(this HeatSinkDef def)
 {
     return(def.Description.Id == Control.settings.GearHeatSinkStandard);
 }
Exemple #10
0
 internal static bool IsDouble(this HeatSinkDef def)
 {
     return(def.Description.Id == Control.settings.GearHeatSinkDouble);
 }
            public static bool Prefix(MechDef mechDef, ref float currentValue, ref float maxValue)
            {
                try
                {
                    if (!mechDef.Chassis.ChassisTags.Contains("chassis_heatsinks"))
                    {
                        return(true);
                    }
                    Logger.Debug("[MechStatisticsRules_CalculateHeatEfficiencyStat_PREFIX] (" + mechDef.Description.Id + ") mechDef.Chassis.Heatsinks: " + mechDef.Chassis.Heatsinks);



                    // This is a complete copy of the original method except marked parts...

                    // BEN: Add Chassis.Heatsinks to equation...
                    //float num = (float)MechStatisticsRules.Combat.Heat.InternalHeatSinkCount * MechStatisticsRules.Combat.Heat.DefaultHeatSinkDissipationCapacity;
                    float num = ((float)mechDef.Chassis.Heatsinks + (float)MechStatisticsRules.Combat.Heat.InternalHeatSinkCount) * MechStatisticsRules.Combat.Heat.DefaultHeatSinkDissipationCapacity;
                    // :NEB

                    float num2 = 0f;
                    float num3 = 0f;
                    float num4 = (float)MechStatisticsRules.Combat.Heat.MaxHeat;
                    float num5 = 0f;
                    int   num6 = 0;
                    for (int i = 0; i < mechDef.Inventory.Length; i++)
                    {
                        MechComponentRef mechComponentRef = mechDef.Inventory[i];
                        if (mechComponentRef.DamageLevel == ComponentDamageLevel.Functional || mechComponentRef.DamageLevel == ComponentDamageLevel.Installing)
                        {
                            if (mechComponentRef.Def == null)
                            {
                                mechComponentRef.RefreshComponentDef();
                            }
                            if (mechComponentRef.ComponentDefType == ComponentType.Weapon)
                            {
                                WeaponDef weaponDef = mechComponentRef.Def as WeaponDef;
                                num3 += (float)weaponDef.HeatGenerated;
                            }
                            else if (mechComponentRef.ComponentDefType == ComponentType.JumpJet)
                            {
                                if (mechComponentRef.DamageLevel < ComponentDamageLevel.NonFunctional)
                                {
                                    num6++;
                                }
                            }
                            else if (mechComponentRef.ComponentDefType == ComponentType.HeatSink)
                            {
                                HeatSinkDef heatSinkDef = mechComponentRef.Def as HeatSinkDef;
                                num += heatSinkDef.DissipationCapacity;
                                if (heatSinkDef.statusEffects != null)
                                {
                                    for (int j = 0; j < heatSinkDef.statusEffects.Length; j++)
                                    {
                                        if (heatSinkDef.statusEffects[j].effectType == EffectType.StatisticEffect)
                                        {
                                            if (heatSinkDef.statusEffects[j].statisticData.statName == "MaxHeat")
                                            {
                                                num4 += float.Parse(heatSinkDef.statusEffects[j].statisticData.modValue, NumberFormatInfo.InvariantInfo);
                                            }
                                            if (heatSinkDef.statusEffects[j].statisticData.statName == "HeatGenerated" && heatSinkDef.statusEffects[j].statisticData.targetCollection == StatisticEffectData.TargetCollection.Weapon)
                                            {
                                                num5 -= 1f - float.Parse(heatSinkDef.statusEffects[j].statisticData.modValue, NumberFormatInfo.InvariantInfo);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (mechComponentRef.ComponentDefType == ComponentType.Upgrade)
                            {
                                UpgradeDef upgradeDef = mechComponentRef.Def as UpgradeDef;
                                if (upgradeDef.statusEffects != null)
                                {
                                    for (int k = 0; k < upgradeDef.statusEffects.Length; k++)
                                    {
                                        if (upgradeDef.statusEffects[k].effectType == EffectType.StatisticEffect)
                                        {
                                            if (upgradeDef.statusEffects[k].statisticData.statName == "MaxHeat")
                                            {
                                                num4 += float.Parse(upgradeDef.statusEffects[k].statisticData.modValue, NumberFormatInfo.InvariantInfo);
                                            }
                                            if (upgradeDef.statusEffects[k].statisticData.statName == "HeatGenerated" && upgradeDef.statusEffects[k].statisticData.targetCollection == StatisticEffectData.TargetCollection.Weapon)
                                            {
                                                num5 -= 1f - float.Parse(upgradeDef.statusEffects[k].statisticData.modValue, NumberFormatInfo.InvariantInfo);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (num6 >= MechStatisticsRules.Combat.MoveConstants.MoveTable.Length)
                    {
                        num6 = MechStatisticsRules.Combat.MoveConstants.MoveTable.Length - 1;
                    }
                    int num7 = 3;
                    if (num6 > 0)
                    {
                        num2 += (float)num6 * MechStatisticsRules.Combat.Heat.JumpHeatUnitSize / (float)num7;
                    }
                    else
                    {
                        num2 = 0f;
                    }
                    num3 += num3 * num5;
                    num  *= MechStatisticsRules.Combat.Heat.GlobalHeatSinkMultiplier;
                    float num8 = (num3 + num2) * MechStatisticsRules.Combat.Heat.GlobalHeatIncreaseMultiplier;
                    float num9 = Mathf.Min(num / num8 * 100f, 100f);
                    currentValue = Mathf.Round((num9 - UnityGameInstance.BattleTechGame.MechStatisticsConstants.MinHeatEfficiency) / (UnityGameInstance.BattleTechGame.MechStatisticsConstants.MaxHeatEfficiency - UnityGameInstance.BattleTechGame.MechStatisticsConstants.MinHeatEfficiency) * 10f + (num4 - (float)MechStatisticsRules.Combat.Heat.MaxHeat) / 2f);
                    currentValue = Mathf.Max(currentValue, 1f);
                    maxValue     = 10f;

                    // Skip original method
                    return(false);
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                    return(true);
                }
            }
Exemple #12
0
        public static void CritComponent(this MechComponent component, ref WeaponHitInfo hitInfo)
        {
            Weapon        weapon1      = component as Weapon;
            AmmunitionBox ammoBox      = component as AmmunitionBox;
            Jumpjet       jumpjet      = component as Jumpjet;
            HeatSinkDef   componentDef = component.componentDef as HeatSinkDef;
            bool          flag         = weapon1 != null;

            if (component.parent != null)
            {
                if (component.parent.GameRep != null)
                {
                    WwiseManager.SetSwitch <AudioSwitch_weapon_type>(AudioSwitch_weapon_type.laser_medium, component.parent.GameRep.audioObject);
                    WwiseManager.SetSwitch <AudioSwitch_surface_type>(AudioSwitch_surface_type.mech_critical_hit, component.parent.GameRep.audioObject);
                    int num1 = (int)WwiseManager.PostEvent <AudioEventList_impact>(AudioEventList_impact.impact_weapon, component.parent.GameRep.audioObject, (AkCallbackManager.EventCallback)null, (object)null);
                    int num2 = (int)WwiseManager.PostEvent <AudioEventList_explosion>(AudioEventList_explosion.explosion_small, component.parent.GameRep.audioObject, (AkCallbackManager.EventCallback)null, (object)null);
                    if (component.parent.team.LocalPlayerControlsTeam)
                    {
                        AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "critical_hit_friendly ", (AkGameObj)null, (AkCallbackManager.EventCallback)null);
                    }
                    else if (!component.parent.team.IsFriendly(component.parent.Combat.LocalPlayerTeam))
                    {
                        AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "critical_hit_enemy", (AkGameObj)null, (AkCallbackManager.EventCallback)null);
                    }
                    if (jumpjet == null && componentDef == null && (ammoBox == null && component.DamageLevel > ComponentDamageLevel.Functional))
                    {
                        if (component.parent is Mech mech)
                        {
                            mech.GameRep.PlayComponentCritVFX(component.Location);
                        }
                    }
                    if (ammoBox != null && component.DamageLevel > ComponentDamageLevel.Functional)
                    {
                        component.parent.GameRep.PlayVFX(component.Location, (string)component.parent.Combat.Constants.VFXNames.componentDestruction_AmmoExplosion, true, Vector3.zero, true, -1f);
                    }
                }
            }
            ComponentDamageLevel damageLevel = component.DamageLevel;

            switch (damageLevel)
            {
            case ComponentDamageLevel.Functional:
                if (flag)
                {
                    damageLevel = ComponentDamageLevel.Penalized;
                    component.parent.Combat.MessageCenter.PublishMessage((MessageCenterMessage) new AddSequenceToStackMessage((IStackSequence) new ShowActorInfoSequence((ICombatant)component.parent, new Text("{0} CRIT", new object[1]
                    {
                        (object)component.UIName
                    }), FloatieMessage.MessageNature.CriticalHit, true)));
                    goto case ComponentDamageLevel.Destroyed;
                }
                else
                {
                    damageLevel = ComponentDamageLevel.Destroyed;
                    component.parent.Combat.MessageCenter.PublishMessage((MessageCenterMessage) new AddSequenceToStackMessage((IStackSequence) new ShowActorInfoSequence((ICombatant)component.parent, new Text("{0} DESTROYED", new object[1]
                    {
                        (object)component.UIName
                    }), FloatieMessage.MessageNature.ComponentDestroyed, true)));
                    goto case ComponentDamageLevel.Destroyed;
                }

            case ComponentDamageLevel.Destroyed:
                component.DamageComponent(hitInfo, damageLevel, true);
                break;

            default:
                damageLevel = ComponentDamageLevel.Destroyed;
                component.parent.Combat.MessageCenter.PublishMessage((MessageCenterMessage) new AddSequenceToStackMessage((IStackSequence) new ShowActorInfoSequence((ICombatant)component.parent, new Text("{0} DESTROYED", new object[1]
                {
                    (object)component.UIName
                }), FloatieMessage.MessageNature.ComponentDestroyed, true)));
                goto case ComponentDamageLevel.Destroyed;
            }
        }
Exemple #13
0
        // Helper
        internal static bool HasOverrideColor(MechComponentDef mechComponentDef, out Color overrideColor)
        {
            bool result = false;

            overrideColor = Color.red;

            if (mechComponentDef.ComponentType == ComponentType.Weapon)
            {
                WeaponDef weaponDef = mechComponentDef as WeaponDef;

                if (weaponDef.ComponentTags.Contains("component_type_lostech"))
                {
                    if (weaponDef.WeaponCategoryValue.IsBallistic)
                    {
                        overrideColor = ballisticColorLosTech;
                        result        = true;
                    }
                    else if (weaponDef.WeaponCategoryValue.IsMissile)
                    {
                        overrideColor = missileColorLosTech;
                        result        = true;
                    }
                    else if (weaponDef.WeaponCategoryValue.IsEnergy)
                    {
                        overrideColor = energyColorLosTech;
                        result        = true;
                    }
                    else if (weaponDef.WeaponCategoryValue.IsSupport)
                    {
                        overrideColor = supportColorLosTech;
                        result        = true;
                    }
                }
            }
            else if (mechComponentDef.ComponentType == ComponentType.AmmunitionBox)
            {
                AmmunitionBoxDef ammunitionBoxDef = mechComponentDef as AmmunitionBoxDef;

                if (ammunitionBoxDef.ComponentTags.Contains("component_type_lostech"))
                {
                    if (ammunitionBoxDef.AmmoID == "Ammunition_GAUSS" || ammunitionBoxDef.AmmoID == "Ammunition_LB2X" || ammunitionBoxDef.AmmoID == "Ammunition_LB5X" || ammunitionBoxDef.AmmoID == "Ammunition_LB10X" || ammunitionBoxDef.AmmoID == "Ammunition_LB20X")
                    {
                        overrideColor = ballisticColorLosTech;
                        result        = true;
                    }
                    else if (ammunitionBoxDef.AmmoID == "Ammunition_SRMStreak" || ammunitionBoxDef.AmmoID == "Ammunition_Narc")
                    {
                        overrideColor = missileColorLosTech;
                        result        = true;
                    }
                }
            }
            else if (mechComponentDef.ComponentType == ComponentType.HeatSink)
            {
                HeatSinkDef heatSinkDef = mechComponentDef as HeatSinkDef;

                if (heatSinkDef.ComponentTags.Contains("component_type_lostech"))
                {
                    overrideColor = equipmentColorLosTech;
                    result        = true;
                }
            }
            else if (mechComponentDef.ComponentType == ComponentType.Upgrade)
            {
                UpgradeDef upgradeDef = mechComponentDef as UpgradeDef;

                if (upgradeDef.ComponentTags.Contains("component_type_lostech") || upgradeDef.ComponentTags.Contains("component_type_prototype"))
                {
                    overrideColor = equipmentColorLosTech;
                    result        = true;
                }
            }

            if (result)
            {
                Logger.Debug($"[CustomColors.HasOverrideColor] Overriding color for {mechComponentDef.Description.UIName}");
            }

            return(result);
        }