Esempio n. 1
0
        private static ConditionTableManager.ConditionTableType GetConditionTableType(ModComponent modComponent)
        {
            if (modComponent is ModFoodComponent)
            {
                ModFoodComponent modFoodComponent = (ModFoodComponent)modComponent;
                if (modFoodComponent.Canned)
                {
                    return(ConditionTableManager.ConditionTableType.CannedFood);
                }

                if (modFoodComponent.Meat)
                {
                    return(ConditionTableManager.ConditionTableType.Meat);
                }

                if (!modFoodComponent.Natural && !modFoodComponent.Drink)
                {
                    return(ConditionTableManager.ConditionTableType.DryFood);
                }

                return(ConditionTableManager.ConditionTableType.Unknown);
            }

            return(ConditionTableManager.ConditionTableType.Unknown);
        }
Esempio n. 2
0
        public static void Prefix(FoodItem fi, ref float calories)
        {
            ModFoodComponent modFoodComponent = ModUtils.GetComponent <ModFoodComponent>(fi);

            if (modFoodComponent != null && modFoodComponent.Servings > 1)
            {
                calories = Math.Min(calories, (float)modFoodComponent.Calories / modFoodComponent.Servings);
            }
        }
Esempio n. 3
0
        private static void InitializeFoodComponent(ModFoodComponent modFood, ProxyObject dict, string className = "ModFoodComponent")
        {
            InitializeCookableComponent(modFood, dict, className);
            modFood.DaysToDecayOutdoors = dict[className]["DaysToDecayOutdoors"];
            modFood.DaysToDecayIndoors  = dict[className]["DaysToDecayIndoors"];

            modFood.Calories   = dict[className]["Calories"];
            modFood.EatingTime = dict[className]["EatingTime"];

            modFood.EatingAudio         = dict[className]["EatingAudio"];
            modFood.EatingPackagedAudio = dict[className]["EatingPackagedAudio"];

            modFood.ThirstEffect = dict[className]["ThirstEffect"];

            modFood.FoodPoisoning             = dict[className]["FoodPoisoning"];
            modFood.FoodPoisoningLowCondition = dict[className]["FoodPoisoningLowCondition"];
            modFood.ParasiteRiskIncrements    = JsonUtils.MakeFloatArray(dict[className]["ParasiteRiskIncrements"] as ProxyArray);

            modFood.Natural = dict[className]["Natural"];
            modFood.Raw     = dict[className]["Raw"];
            modFood.Drink   = dict[className]["Drink"];
            modFood.Meat    = dict[className]["Meat"];
            modFood.Fish    = dict[className]["Fish"];

            modFood.Canned  = dict[className]["Canned"];
            modFood.Opening = dict[className]["Opening"];
            modFood.OpeningWithCanOpener = dict[className]["OpeningWithCanOpener"];
            modFood.OpeningWithKnife     = dict[className]["OpeningWithKnife"];
            modFood.OpeningWithHatchet   = dict[className]["OpeningWithHatchet"];
            modFood.OpeningWithSmashing  = dict[className]["OpeningWithSmashing"];

            modFood.AffectCondition      = dict[className]["AffectCondition"];
            modFood.ConditionRestBonus   = dict[className]["ConditionRestBonus"];
            modFood.ConditionRestMinutes = dict[className]["ConditionRestMinutes"];

            modFood.AffectRest        = dict[className]["AffectRest"];
            modFood.InstantRestChange = dict[className]["InstantRestChange"];
            modFood.RestFactor        = dict[className]["RestFactor"];
            modFood.RestFactorMinutes = dict[className]["RestFactorMinutes"];

            modFood.AffectCold        = dict[className]["AffectCold"];
            modFood.InstantColdChange = dict[className]["InstantColdChange"];
            modFood.ColdFactor        = dict[className]["ColdFactor"];
            modFood.ColdFactorMinutes = dict[className]["ColdFactorMinutes"];

            modFood.ContainsAlcohol      = dict[className]["ContainsAlcohol"];
            modFood.AlcoholPercentage    = dict[className]["AlcoholPercentage"];
            modFood.AlcoholUptakeMinutes = dict[className]["AlcoholUptakeMinutes"];
        }
Esempio n. 4
0
        internal static void Configure(ModComponent modComponent)
        {
            ModFoodComponent modFoodComponent = modComponent.TryCast <ModFoodComponent>();

            if (modFoodComponent is null)
            {
                return;
            }

            FoodItem foodItem = ModComponentUtils.ComponentUtils.GetOrCreateComponent <FoodItem>(modFoodComponent);

            foodItem.m_CaloriesTotal     = modFoodComponent.Calories;
            foodItem.m_CaloriesRemaining = modFoodComponent.Calories;
            foodItem.m_ReduceThirst      = modFoodComponent.ThirstEffect;

            foodItem.m_ChanceFoodPoisoning             = Mathf.Clamp01(modFoodComponent.FoodPoisoning / 100f);
            foodItem.m_ChanceFoodPoisoningLowCondition = Mathf.Clamp01(modFoodComponent.FoodPoisoningLowCondition / 100f);
            foodItem.m_ChanceFoodPoisoningRuined       = Mathf.Clamp01(modFoodComponent.FoodPoisoningLowCondition / 100f);
            foodItem.m_DailyHPDecayInside  = Mapper.GetDecayPerStep(modFoodComponent.DaysToDecayIndoors, modFoodComponent.MaxHP);
            foodItem.m_DailyHPDecayOutside = Mapper.GetDecayPerStep(modFoodComponent.DaysToDecayOutdoors, modFoodComponent.MaxHP);

            foodItem.m_TimeToEatSeconds        = Mathf.Clamp(1, modFoodComponent.EatingTime, 10);
            foodItem.m_TimeToOpenAndEatSeconds = Mathf.Clamp(1, modFoodComponent.EatingTime, 10) + 5;
            foodItem.m_EatingAudio             = modFoodComponent.EatingAudio;
            foodItem.m_OpenAndEatingAudio      = modFoodComponent.EatingPackagedAudio;
            foodItem.m_Packaged = !string.IsNullOrEmpty(foodItem.m_OpenAndEatingAudio);

            foodItem.m_IsDrink        = modFoodComponent.Drink;
            foodItem.m_IsFish         = modFoodComponent.Fish;
            foodItem.m_IsMeat         = modFoodComponent.Meat;
            foodItem.m_IsRawMeat      = modFoodComponent.Raw;
            foodItem.m_IsNatural      = modFoodComponent.Natural;
            foodItem.m_MustConsumeAll = false;
            foodItem.m_ParasiteRiskPercentIncrease = ModComponentUtils.ModUtils.NotNull(modFoodComponent.ParasiteRiskIncrements);

            foodItem.m_PercentHeatLossPerMinuteIndoors  = 1;
            foodItem.m_PercentHeatLossPerMinuteOutdoors = 2;

            if (modFoodComponent.Opening)
            {
                foodItem.m_GearRequiredToOpen  = true;
                foodItem.m_OpenedWithCanOpener = modFoodComponent.OpeningWithCanOpener;
                foodItem.m_OpenedWithHatchet   = modFoodComponent.OpeningWithHatchet;
                foodItem.m_OpenedWithKnife     = modFoodComponent.OpeningWithKnife;

                if (modFoodComponent.OpeningWithSmashing)
                {
                    SmashableItem smashableItem = ModComponentUtils.ComponentUtils.GetOrCreateComponent <SmashableItem>(modFoodComponent);
                    smashableItem.m_MinPercentLoss = 10;
                    smashableItem.m_MaxPercentLoss = 30;
                    smashableItem.m_TimeToSmash    = 6;
                    smashableItem.m_SmashAudio     = "Play_EatingSmashCan";
                }

                if (modFoodComponent.Canned)
                {
                    foodItem.m_GearPrefabHarvestAfterFinishEatingNormal = Resources.Load <GameObject>("GEAR_RecycledCan");
                }
            }

            if (modFoodComponent.AffectRest)
            {
                FatigueBuff fatigueBuff = ModComponentUtils.ComponentUtils.GetOrCreateComponent <FatigueBuff>(modFoodComponent);
                fatigueBuff.m_InitialPercentDecrease = modFoodComponent.InstantRestChange;
                fatigueBuff.m_RateOfIncreaseScale    = modFoodComponent.RestFactor;
                fatigueBuff.m_DurationHours          = modFoodComponent.RestFactorMinutes / 60f;
            }

            if (modFoodComponent.AffectCold)
            {
                FreezingBuff freezingBuff = ModComponentUtils.ComponentUtils.GetOrCreateComponent <FreezingBuff>(modFoodComponent);
                freezingBuff.m_InitialPercentDecrease = modFoodComponent.InstantColdChange;
                freezingBuff.m_RateOfIncreaseScale    = modFoodComponent.ColdFactor;
                freezingBuff.m_DurationHours          = modFoodComponent.ColdFactorMinutes / 60f;
            }

            if (modFoodComponent.AffectCondition)
            {
                ConditionRestBuff conditionRestBuff = ModComponentUtils.ComponentUtils.GetOrCreateComponent <ConditionRestBuff>(modFoodComponent);
                conditionRestBuff.m_ConditionRestBonus   = modFoodComponent.ConditionRestBonus;
                conditionRestBuff.m_NumHoursRestAffected = modFoodComponent.ConditionRestMinutes / 60f;
            }

            if (modFoodComponent.ContainsAlcohol)
            {
                AlcoholComponent alcohol = ModComponentUtils.ComponentUtils.GetOrCreateComponent <AlcoholComponent>(modFoodComponent);
                alcohol.AmountTotal     = modFoodComponent.WeightKG * modFoodComponent.AlcoholPercentage * 0.01f;
                alcohol.AmountRemaining = alcohol.AmountTotal;
                alcohol.UptakeSeconds   = modFoodComponent.AlcoholUptakeMinutes * 60;
            }

            HoverIconsToShow hoverIconsToShow = ModComponentUtils.ComponentUtils.GetOrCreateComponent <HoverIconsToShow>(modFoodComponent);

            hoverIconsToShow.m_HoverIcons = new HoverIconsToShow.HoverIcons[] { HoverIconsToShow.HoverIcons.Food };
        }
Esempio n. 5
0
        public static void InitializeComponents(ref GameObject prefab, ProxyObject dict)
        {
            if (ComponentUtils.GetModComponent(prefab) != null || dict is null)
            {
                return;
            }

            #region Mod Components
            if (JsonUtils.ContainsKey(dict, "ModBedComponent"))
            {
                ModBedComponent newComponent = ComponentUtils.GetOrCreateComponent <ModBedComponent>(prefab);
                InitializeBedComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModBodyHarvestComponent"))
            {
                ModBodyHarvestComponent newComponent = ComponentUtils.GetOrCreateComponent <ModBodyHarvestComponent>(prefab);
                InitializeBodyHarvestComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModCharcoalComponent"))
            {
                ModCharcoalComponent newComponent = ComponentUtils.GetOrCreateComponent <ModCharcoalComponent>(prefab);
                InitializeCharcoalComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModClothingComponent"))
            {
                ModClothingComponent newComponent = ComponentUtils.GetOrCreateComponent <ModClothingComponent>(prefab);
                InitializeClothingComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModCollectibleComponent"))
            {
                ModCollectibleComponent newComponent = ComponentUtils.GetOrCreateComponent <ModCollectibleComponent>(prefab);
                InitializeCollectibleComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModCookableComponent"))
            {
                ModCookableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModCookableComponent>(prefab);
                InitializeCookableComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModCookingPotComponent"))
            {
                ModCookingPotComponent newComponent = ComponentUtils.GetOrCreateComponent <ModCookingPotComponent>(prefab);
                InitializeCookingPotComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModExplosiveComponent"))
            {
                ModExplosiveComponent newComponent = ComponentUtils.GetOrCreateComponent <ModExplosiveComponent>(prefab);
                InitializeExplosiveComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModFirstAidComponent"))
            {
                ModFirstAidComponent newComponent = ComponentUtils.GetOrCreateComponent <ModFirstAidComponent>(prefab);
                InitializeFirstAidComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModFoodComponent"))
            {
                ModFoodComponent newComponent = ComponentUtils.GetOrCreateComponent <ModFoodComponent>(prefab);
                InitializeFoodComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModGenericComponent"))
            {
                ModGenericComponent newComponent = ComponentUtils.GetOrCreateComponent <ModGenericComponent>(prefab);
                InitializeGenericComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModGenericEquippableComponent"))
            {
                ModGenericEquippableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModGenericEquippableComponent>(prefab);
                InitializeGenericEquippableComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModLiquidComponent"))
            {
                ModLiquidComponent newComponent = ComponentUtils.GetOrCreateComponent <ModLiquidComponent>(prefab);
                InitializeLiquidComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModPowderComponent"))
            {
                ModPowderComponent newComponent = ComponentUtils.GetOrCreateComponent <ModPowderComponent>(prefab);
                InitializePowderComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModPurificationComponent"))
            {
                ModPurificationComponent newComponent = ComponentUtils.GetOrCreateComponent <ModPurificationComponent>(prefab);
                InitializePurificationComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModRandomItemComponent"))
            {
                ModRandomItemComponent newComponent = ComponentUtils.GetOrCreateComponent <ModRandomItemComponent>(prefab);
                InitializeRandomItemComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModRandomWeightedItemComponent"))
            {
                ModRandomWeightedItemComponent newComponent = ComponentUtils.GetOrCreateComponent <ModRandomWeightedItemComponent>(prefab);
                InitializeRandomWeightedItemComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModResearchComponent"))
            {
                ModResearchComponent newComponent = ComponentUtils.GetOrCreateComponent <ModResearchComponent>(prefab);
                InitializeResearchComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModRifleComponent"))
            {
                ModRifleComponent newComponent = ComponentUtils.GetOrCreateComponent <ModRifleComponent>(prefab);
                InitializeRifleComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModToolComponent"))
            {
                ModToolComponent newComponent = ComponentUtils.GetOrCreateComponent <ModToolComponent>(prefab);
                InitializeToolComponent(newComponent, dict);
            }
            #endregion

            #region Behaviour Components
            if (JsonUtils.ContainsKey(dict, "ModAccelerantComponent"))
            {
                ModAccelerantComponent newComponent = ComponentUtils.GetOrCreateComponent <ModAccelerantComponent>(prefab);
                InitializeAccelerantComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModBurnableComponent"))
            {
                ModBurnableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModBurnableComponent>(prefab);
                InitializeBurnableComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModFireStarterComponent"))
            {
                ModFireStarterComponent newComponent = ComponentUtils.GetOrCreateComponent <ModFireStarterComponent>(prefab);
                InitializeFireStarterComponent(newComponent, dict);
            }
            else if (JsonUtils.ContainsKey(dict, "ModTinderComponent"))
            {
                ModTinderComponent newComponent = ComponentUtils.GetOrCreateComponent <ModTinderComponent>(prefab);
                InitializeTinderComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModCarryingCapacityComponent"))
            {
                ModCarryingCapacityComponent newComponent = ComponentUtils.GetOrCreateComponent <ModCarryingCapacityComponent>(prefab);
                InitializeCarryingCapacityComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModEvolveComponent"))
            {
                ModEvolveComponent newComponent = ComponentUtils.GetOrCreateComponent <ModEvolveComponent>(prefab);
                InitializeEvolveComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModHarvestableComponent"))
            {
                ModHarvestableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModHarvestableComponent>(prefab);
                InitializeHarvestableComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModMillableComponent"))
            {
                ModMillableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModMillableComponent>(prefab);
                InitializeMillableComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModRepairableComponent"))
            {
                ModRepairableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModRepairableComponent>(prefab);
                InitializeRepairableComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModScentComponent"))
            {
                ModScentComponent newComponent = ComponentUtils.GetOrCreateComponent <ModScentComponent>(prefab);
                InitializeScentComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModSharpenableComponent"))
            {
                ModSharpenableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModSharpenableComponent>(prefab);
                InitializeSharpenableComponent(newComponent, dict);
            }
            if (JsonUtils.ContainsKey(dict, "ModStackableComponent"))
            {
                ModStackableComponent newComponent = ComponentUtils.GetOrCreateComponent <ModStackableComponent>(prefab);
                InitializeStackableComponent(newComponent, dict);
            }
            #endregion

            #region Modifications
            if (JsonUtils.ContainsKey(dict, "ChangeLayer"))
            {
                ChangeLayer newComponent = ComponentUtils.GetOrCreateComponent <ChangeLayer>(prefab);
                InitializeChangeLayer(newComponent, dict);
            }
            #endregion
        }