Exemplo n.º 1
0
        public static bool ReceiveHeatDamageInjury(this StatCollection statCollection, bool set = false)
        {
            const string key = "ReceiveHeatDamageInjury";

            return(statCollection.GetStatistic(key)?.Value <bool>()
                   ?? set && statCollection.AddStatistic(key, false).Value <bool>());
        }
Exemplo n.º 2
0
        public static Statistic GetOrCreateStatisic <StatisticType>(StatCollection collection, string statName, StatisticType defaultValue)
        {
            Statistic statistic = collection.GetStatistic(statName);

            if (statistic == null)
            {
                statistic = collection.AddStatistic <StatisticType>(statName, defaultValue);
            }
            return(statistic);
        }
        public void setCompanyStats(SimGameState simGame)
        {
            companyStats = simGame.CompanyStats;
            int legacyCost = getLegacyCompanyCosts(simGame);

            for (int i = 0; i < DCECore.settings.averagedDrops; i++)
            {
                string statName = $"{DropCostStatPrefix}{i}";
                if (!companyStats.ContainsStatistic(statName))
                {
                    DCECore.modLog.Info?.Write($"Initing Stat: {statName}, Value: {legacyCost}");
                    companyStats.AddStatistic <int>(statName, legacyCost);
                }
            }
            if (!companyStats.ContainsStatistic(DropCostIdxStat))
            {
                companyStats.AddStatistic <int>(DropCostIdxStat, 0);
            }
        }
        private static float AccuracyForKey(StatCollection statCollection, string collectionKey)
        {
            var statistic = statCollection.GetStatistic(collectionKey);

            if (statistic == null)
            {
                const float defaultValue = 0.0f;
                statistic = statCollection.AddStatistic(collectionKey, defaultValue);
            }
            return(statistic.Value <float>());
        }
Exemplo n.º 5
0
        public void setCompanyStats(StatCollection stats)
        {
            companyStats = stats;

            if (!companyStats.ContainsStatistic(PqMechSkillTracker))
            {
                companyStats.AddStatistic <float>(PqMechSkillTracker, 0.0f);
            }
            if (!companyStats.ContainsStatistic(PqMedSkillTracker))
            {
                companyStats.AddStatistic <float>(PqMedSkillTracker, 0.0f);
            }
            if (!companyStats.ContainsStatistic(PqMoraleTracker))
            {
                companyStats.AddStatistic <float>(PqMoraleTracker, 0.0f);
            }
            Main.modLog.LogMessage($"Tracker Stat: {PqMechSkillTracker}, value: {companyStats.GetValue<float>(PqMechSkillTracker)}");
            Main.modLog.LogMessage($"Tracker Stat: {PqMedSkillTracker}, value: {companyStats.GetValue<float>(PqMedSkillTracker)}");
            Main.modLog.LogMessage($"Tracker Stat: {PqMoraleTracker}, value: {companyStats.GetValue<float>(PqMoraleTracker)}");
        }
Exemplo n.º 6
0
        private float MoveMultiplierStat(StatCollection statCollection)
        {
            const string key       = "MoveMultiplier";
            var          statistic = statCollection.GetStatistic(key);

            if (statistic == null)
            {
                const float defaultValue = 1.0f;
                statistic = statCollection.AddStatistic(key, defaultValue);
            }
            return(statistic.Value <float>());
        }
Exemplo n.º 7
0
 public void setCompanyStats(StatCollection stats)
 {
     companyStats = stats;
     if (allowUpgrades)
     {
         if (!companyStats.ContainsStatistic(ADDITIONAL_MECH_STAT))
         {
             companyStats.AddStatistic(ADDITIONAL_MECH_STAT, FadditinalMechSlots);
         }
         ;
         if (!companyStats.ContainsStatistic(ADDITIONAL_PLAYER_MECH_STAT))
         {
             companyStats.AddStatistic(ADDITIONAL_PLAYER_MECH_STAT, FadditinalPlayerMechSlots);
         }
         ;
         if (!companyStats.ContainsStatistic(MAX_TONNAGE_STAT))
         {
             companyStats.AddStatistic(MAX_TONNAGE_STAT, FmaxTonnage);
         }
         ;
     }
 }
Exemplo n.º 8
0
        public static void SetOrCreateStatisic <StatisticType>(this StatCollection collection, string statName, StatisticType value)
        {
            Statistic statistic = collection.GetStatistic(statName);

            if (statistic == null)
            {
                statistic = collection.AddStatistic <StatisticType>(statName, value);
            }
            else
            {
                statistic.SetValue(value);
            }
        }
Exemplo n.º 9
0
 public static void Postfix(Weapon __instance, ref StatCollection ___statCollection)
 {
     try
     {
         if (IsUltraAutocannon(__instance))
         {
             ___statCollection.AddStatistic <bool>("Jammed", false);
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
        public static bool Prefix(MechDef mechDef, ref float currentValue, ref float maxValue)
        {
            try
            {
                var maxSprintDistance = mechDef.Chassis.MovementCapDef.MaxSprintDistance;
                {
                    var stats             = new StatCollection();
                    var runSpeedStatistic = stats.AddStatistic("RunSpeed", maxSprintDistance);

                    foreach (var mechComponentRef in mechDef.Inventory)
                    {
                        if (mechComponentRef.Def == null || mechComponentRef.Def.statusEffects == null)
                        {
                            continue;
                        }

                        var statusEffects = mechComponentRef.Def.statusEffects;
                        foreach (var effect in statusEffects)
                        {
                            switch (effect.statisticData.statName)
                            {
                            case "RunSpeed":
                                stats.PerformOperation(runSpeedStatistic, effect.statisticData);
                                break;
                            }
                        }
                    }

                    maxSprintDistance = runSpeedStatistic.CurrentValue.Value <float>();
                }

                currentValue = Mathf.Floor(
                    (maxSprintDistance - UnityGameInstance.BattleTechGame.MechStatisticsConstants.MinSprintFactor)
                    / (UnityGameInstance.BattleTechGame.MechStatisticsConstants.MaxSprintFactor - UnityGameInstance.BattleTechGame.MechStatisticsConstants.MinSprintFactor)
                    * 10f
                    );
                currentValue = Mathf.Max(currentValue, 1f);
                maxValue     = 10f;
                return(false);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
                return(true);
            }
        }
Exemplo n.º 11
0
        public static void setCompanyStats(StatCollection stats, bool init)
        {
            companyStats = stats;


            if (!companyStats.ContainsStatistic(CLIENT_ID_STAT))
            {
                companyStats.AddStatistic(CLIENT_ID_STAT, Fields.settings.ClientID);
            }
            ;
            if (!companyStats.ContainsStatistic(CAREER_ID_STAT) && init)
            {
                Guid careerId = Guid.NewGuid();
                companyStats.AddStatistic(CAREER_ID_STAT, careerId.ToString());
            }
            else
            {
                if (!companyStats.ContainsStatistic(CAREER_ID_STAT))
                {
                    companyStats.AddStatistic(CAREER_ID_STAT, "");
                }
            }
            if (!companyStats.ContainsStatistic(SEASON_STAT))
            {
                companyStats.AddStatistic(SEASON_STAT, Fields.settings.Season);
            }
            ;
            if (!companyStats.ContainsStatistic(MISSION_COUNT_STAT))
            {
                companyStats.AddStatistic(MISSION_COUNT_STAT, 0);
            }
            ;
            if (!companyStats.ContainsStatistic(CONSOLE_COUNT))
            {
                companyStats.AddStatistic(CONSOLE_COUNT, 0);
            }
            ;
            if (!companyStats.ContainsStatistic(BM_TRANSACTION))
            {
                companyStats.AddStatistic(BM_TRANSACTION, "");
            }
            ;

            Logger.Log($"Career ID Loaded: {companyStats.GetValue<string>(CAREER_ID_STAT)}");
            Logger.Log($"Client issue Token: {RtCore.RTCore.rtData}");
            Logger.Log($"Client Salt: {RtCore.RTCore.rtSalt}");
            Web.forceRefreshServerSettings();
        }
        public static Weapon BuildTestWeapon(float minRange    = 0f, float shortRange = 0f,
                                             float mediumRange = 0f, float longRange  = 0f, float maxRange = 0f)
        {
            Weapon weapon = new Weapon();

            StatCollection statCollection = new StatCollection();

            statCollection.AddStatistic("MinRange", minRange);
            statCollection.AddStatistic("MinRangeMultiplier", 1f);
            statCollection.AddStatistic("LongRangeModifier", 0f);
            statCollection.AddStatistic("MaxRange", maxRange);
            statCollection.AddStatistic("MaxRangeModifier", 0f);
            statCollection.AddStatistic("ShortRange", shortRange);
            statCollection.AddStatistic("MediumRange", mediumRange);
            statCollection.AddStatistic("LongRange", longRange);

            Traverse statCollectionT = Traverse.Create(weapon).Field("statCollection");

            statCollectionT.SetValue(statCollection);

            return(weapon);
        }
        public static void TestStatistic(this StatCollection stats, EffectData effectData)
        {
            if (stats.ContainsStatistic(effectData.statisticData.statName))
            {
                return;
            }
            if (effectData.statisticData.statName.StartsWith(StatisticEffect_OnEffectBegin.ADD_ENCOUNTER_FLAG_STAT_ID) == false)
            {
                return;
            }
            Variant variant = new Variant(System.Type.GetType(effectData.statisticData.modType));

            switch (effectData.statisticData.operation)
            {
            case StatCollection.StatOperation.Set: {
                if (variant.CheckType(Variant.boolType))
                {
                    stats.AddStatistic <bool>(effectData.statisticData.statName, false);
                }
                else
                if (variant.CheckType(Variant.intType))
                {
                    stats.AddStatistic <int>(effectData.statisticData.statName, 0);
                }
                else
                if (variant.CheckType(Variant.floatType))
                {
                    stats.AddStatistic <float>(effectData.statisticData.statName, 0.0f);
                }
                else
                if (variant.CheckType(Variant.stringType))
                {
                    stats.AddStatistic <string>(effectData.statisticData.statName, string.Empty);
                }
            }
            break;

            case StatCollection.StatOperation.Int_Add:
            case StatCollection.StatOperation.Int_Subtract:
            case StatCollection.StatOperation.Int_Multiply:
            case StatCollection.StatOperation.Int_Divide:
            case StatCollection.StatOperation.Int_Divide_Denom:
            case StatCollection.StatOperation.Int_Mod:
            case StatCollection.StatOperation.Int_Multiply_Float:
            case StatCollection.StatOperation.Int_Divide_Float:
            case StatCollection.StatOperation.Int_Divide_Denom_Float:
            case StatCollection.StatOperation.Bitflag_SetBit:
            case StatCollection.StatOperation.Bitflag_FlipBit:
            case StatCollection.StatOperation.Bitflag_Combine: {
                stats.AddStatistic <int>(effectData.statisticData.statName, 0);
            }; break;

            case StatCollection.StatOperation.Float_Add:
            case StatCollection.StatOperation.Float_Subtract:
            case StatCollection.StatOperation.Float_Multiply:
            case StatCollection.StatOperation.Float_Divide:
            case StatCollection.StatOperation.Float_Divide_Denom:
            case StatCollection.StatOperation.Float_Multiply_Int:
            case StatCollection.StatOperation.Float_Divide_Int:
            case StatCollection.StatOperation.Float_Divide_Denom_Int: {
                stats.AddStatistic <float>(effectData.statisticData.statName, 0.0f);
            }; break;

            case StatCollection.StatOperation.String_Append:
            case StatCollection.StatOperation.String_Prepend: {
                stats.AddStatistic <string>(effectData.statisticData.statName, string.Empty);
            }; break;
            }
        }
        public static bool Prefix(MechDef mechDef, ref float currentValue, ref float maxValue)
        {
            try
            {
                if (Combat == null)
                {
                    Combat = CombatGameConstants.CreateFromSaved(UnityGameInstance.BattleTechGame);
                }
                var totalHeatSinkDissipation = Combat.Heat.InternalHeatSinkCount * Combat.Heat.DefaultHeatSinkDissipationCapacity;
                var heatGenerationWeapons    = 0f;
                var numberOfJumpJets         = 0;

                foreach (var mechComponentRef in mechDef.Inventory)
                {
                    if (mechComponentRef.Def == null)
                    {
                        mechComponentRef.RefreshComponentDef();
                    }
                    if (mechComponentRef.Def is WeaponDef)
                    {
                        var weaponDef = (WeaponDef)mechComponentRef.Def;
                        heatGenerationWeapons += weaponDef.HeatGenerated;
                    }
                    else if (mechComponentRef.ComponentDefType == ComponentType.JumpJet)
                    {
                        if (mechComponentRef.DamageLevel < ComponentDamageLevel.NonFunctional)
                        {
                            numberOfJumpJets++;
                        }
                    }
                    else if (mechComponentRef.Def is HeatSinkDef)
                    {
                        var heatSinkDef = (HeatSinkDef)mechComponentRef.Def;
                        totalHeatSinkDissipation += heatSinkDef.DissipationCapacity;
                    }
                }

                Control.mod.Logger.LogDebug("heatGenerationWeapons=" + heatGenerationWeapons);
                Control.mod.Logger.LogDebug("totalHeatSinkDissipation=" + totalHeatSinkDissipation);

                var maxHeat = Combat.Heat.MaxHeat;
                {
                    var stats                  = new StatCollection();
                    var maxHeatStatistic       = stats.AddStatistic("MaxHeat", maxHeat);
                    var heatGeneratedStatistic = stats.AddStatistic("HeatGenerated", heatGenerationWeapons);

                    foreach (var mechComponentRef in mechDef.Inventory)
                    {
                        if (mechComponentRef.Def == null || mechComponentRef.Def.statusEffects == null)
                        {
                            continue;
                        }

                        var statusEffects = mechComponentRef.Def.statusEffects;
                        foreach (var effect in statusEffects)
                        {
                            switch (effect.statisticData.statName)
                            {
                            case "MaxHeat":
                                stats.PerformOperation(maxHeatStatistic, effect.statisticData);
                                break;

                            case "HeatGenerated":
                                if (effect.statisticData.targetCollection == StatisticEffectData.TargetCollection.Weapon)
                                {
                                    stats.PerformOperation(heatGeneratedStatistic, effect.statisticData);
                                }
                                break;
                            }
                        }
                    }

                    maxHeat = maxHeatStatistic.CurrentValue.Value <int>();
                    heatGenerationWeapons = heatGeneratedStatistic.CurrentValue.Value <float>();
                }

                Control.mod.Logger.LogDebug("maxHeat=" + maxHeat);
                Control.mod.Logger.LogDebug("heatGenerationWeapons=" + heatGenerationWeapons);

                if (numberOfJumpJets >= Combat.MoveConstants.MoveTable.Length)
                {
                    numberOfJumpJets = Combat.MoveConstants.MoveTable.Length - 1;
                }

                var heatGenerationJumpJets = 0f;
                var jumpHeatDivisor        = 3;
                if (numberOfJumpJets > 0)
                {
                    heatGenerationJumpJets += numberOfJumpJets * Combat.Heat.JumpHeatUnitSize / jumpHeatDivisor;
                }
                else
                {
                    heatGenerationJumpJets = 0f;
                }

                totalHeatSinkDissipation *= Combat.Heat.GlobalHeatSinkMultiplier;
                var totalHeatGeneration = (heatGenerationWeapons + heatGenerationJumpJets) * Combat.Heat.GlobalHeatIncreaseMultiplier;

                Control.mod.Logger.LogDebug("totalHeatGeneration=" + totalHeatGeneration);

                // rounding steps for heatSinkDissipation
                var heatDissipationPercent = Mathf.Min(totalHeatSinkDissipation / totalHeatGeneration * 100f, UnityGameInstance.BattleTechGame.MechStatisticsConstants.MaxHeatEfficiency);
                heatDissipationPercent = Mathf.Max(heatDissipationPercent, UnityGameInstance.BattleTechGame.MechStatisticsConstants.MinHeatEfficiency);

                Control.mod.Logger.LogDebug("heatDissipationPercent=" + heatDissipationPercent);

                totalHeatSinkDissipation = totalHeatGeneration * (heatDissipationPercent / 100f);

                Control.mod.Logger.LogDebug("totalHeatSinkDissipation=" + totalHeatSinkDissipation);

                var heatLeftOver       = totalHeatGeneration - totalHeatSinkDissipation;
                var unusedHeatCapacity = maxHeat - heatLeftOver;

                Control.mod.Logger.LogDebug("heatLeftOver=" + heatLeftOver);
                Control.mod.Logger.LogDebug("unusedHeatCapacity=" + unusedHeatCapacity);

                currentValue = Mathf.Round((unusedHeatCapacity / maxHeat) * 10f);
                currentValue = Mathf.Max(Mathf.Min(currentValue, 10f), 1f);
                maxValue     = 10f;
                return(false);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
                return(true);
            }
        }
Exemplo n.º 15
0
 internal Statistic Create()
 {
     return(StatCollection.AddStatistic(Key, DefaultValue));
 }
Exemplo n.º 16
0
 internal void SetFixed(StatCollection companyStats)
 {
     companyStats?.AddStatistic(CompanyStatKey, 1);
 }
Exemplo n.º 17
0
        public static void setCompanyStats(StatCollection stats)
        {
            companyStats = stats;
            bool hasCu2 = CustomUnitsAPI.Detected_V2();

            if (BiggerDrops.settings.allowUpgrades)
            {
                if (hasCu2)
                {
                    // one time upgrade of this stat for existing careers
                    if (companyStats.ContainsStatistic(AdditionalMechSlotsStat) && !companyStats.ContainsStatistic(legacyUpgradeDone))
                    {
                        companyStats.AddStatistic(legacyUpgradeDone, 1);
                        companyStats.Int_Add(companyStats.GetStatistic(AdditionalMechSlotsStat), DefaultMechSlots);
                    }
                    if (!companyStats.ContainsStatistic(legacyUpgradeDone))
                    {
                        companyStats.AddStatistic(legacyUpgradeDone, 1);
                    }
                    Dictionary <string, int> SlotCount = new Dictionary <string, int>();
                    foreach (string id in BiggerDrops.settings.CuV2InitialSlots)
                    {
                        if (SlotCount.ContainsKey(id))
                        {
                            SlotCount[id]++;
                        }
                        else
                        {
                            SlotCount.Add(id, 1);
                        }
                    }
                    foreach (string slotId in SlotOrder)
                    {
                        DropSlotDef def = CustomUnitsAPI.GetDropSlotDef(slotId);
                        if (def != null)
                        {
                            if (!companyStats.ContainsStatistic(def.StatName))
                            {
                                int val = 0;
                                if (SlotCount.ContainsKey(slotId))
                                {
                                    val = SlotCount[slotId];
                                }
                                companyStats.AddStatistic(def.StatName, val);

                                Logger.M.WL($"failed to find slotdef: {slotId}");
                            }
                        }
                        else
                        {
                            Logger.M.WL($"failed to find slotdef: {slotId}");
                        }
                    }
                }
                else
                {
                    if (!companyStats.ContainsStatistic(AdditionalMechSlotsStat))
                    {
                        companyStats.AddStatistic(AdditionalMechSlotsStat,
                                                  Math.Max(Math.Min(MaxAdditionalMechSlots, BiggerDrops.settings.additinalMechSlots), 0));
                    }

                    if (!companyStats.ContainsStatistic(AdditionPlayerMechsStat))
                    {
                        companyStats.AddStatistic(AdditionPlayerMechsStat,
                                                  Math.Max(Math.Min(MaxAdditionalMechSlots, BiggerDrops.settings.additinalPlayerMechSlots),
                                                           0));
                    }

                    if (!companyStats.ContainsStatistic(CuVehicleStat))
                    {
                        companyStats.AddStatistic(CuVehicleStat, BiggerDrops.settings.CuInitialVehicles);
                    }
                    ;
                }

                if (!companyStats.ContainsStatistic(MaxTonnageStat))
                {
                    companyStats.AddStatistic(MaxTonnageStat,
                                              Math.Max(BiggerDrops.settings.defaultMaxTonnage, 0));
                }
            }
            UpdateCULances();
        }
        public static void Prefix(StatCollection __instance, string statName, StatCollection.StatOperation op, Variant variant)
        {
            try {
                Dictionary <string, Statistic> stats = Traverse.Create(__instance).Field <Dictionary <string, Statistic> >("stats").Value;
                if (stats.ContainsKey(statName))
                {
                    return;
                }
                Log.Debug?.TWL(0, "StatCollection.ModifyStatistic " + statName + " is absent. Adding");
                switch (op)
                {
                case StatCollection.StatOperation.Set: {
                    if (variant.CheckType(Variant.boolType))
                    {
                        __instance.AddStatistic <bool>(statName, false);
                    }
                    else
                    if (variant.CheckType(Variant.intType))
                    {
                        __instance.AddStatistic <int>(statName, 0);
                    }
                    else
                    if (variant.CheckType(Variant.floatType))
                    {
                        __instance.AddStatistic <float>(statName, 0.0f);
                    }
                    else
                    if (variant.CheckType(Variant.stringType))
                    {
                        __instance.AddStatistic <string>(statName, string.Empty);
                    }
                }
                break;

                case StatCollection.StatOperation.Int_Add:
                case StatCollection.StatOperation.Int_Subtract:
                case StatCollection.StatOperation.Int_Multiply:
                case StatCollection.StatOperation.Int_Divide:
                case StatCollection.StatOperation.Int_Divide_Denom:
                case StatCollection.StatOperation.Int_Mod:
                case StatCollection.StatOperation.Int_Multiply_Float:
                case StatCollection.StatOperation.Int_Divide_Float:
                case StatCollection.StatOperation.Int_Divide_Denom_Float:
                case StatCollection.StatOperation.Bitflag_SetBit:
                case StatCollection.StatOperation.Bitflag_FlipBit:
                case StatCollection.StatOperation.Bitflag_Combine: {
                    __instance.AddStatistic <int>(statName, 0);
                }; break;

                case StatCollection.StatOperation.Float_Add:
                case StatCollection.StatOperation.Float_Subtract:
                case StatCollection.StatOperation.Float_Multiply:
                case StatCollection.StatOperation.Float_Divide:
                case StatCollection.StatOperation.Float_Divide_Denom:
                case StatCollection.StatOperation.Float_Multiply_Int:
                case StatCollection.StatOperation.Float_Divide_Int:
                case StatCollection.StatOperation.Float_Divide_Denom_Int: {
                    __instance.AddStatistic <float>(statName, 0.0f);
                }; break;

                case StatCollection.StatOperation.String_Append:
                case StatCollection.StatOperation.String_Prepend: {
                    __instance.AddStatistic <string>(statName, string.Empty);
                }; break;
                }
            } catch (Exception e) {
                Log.Error?.TWL(0, e.ToString(), true);
            }
        }