Exemple #1
0
        public static void applyPlantDamage(Plant plantItem, float baseDamage)
        {
            // Clamp temps outside of the 0-40, below 0 and above 40 there is spoiling
            float tempC = PerishableItemsHelpers.unClamp(plantItem.WorldAtmosphere.Temperature - 273.15f, 0.0f, 40.0f);

            // Clamp again between 0 and 40
            tempC = PerishableItemsHelpers.Clamp(tempC, 0, 40);
            float damage = baseDamage * (tempC / 40.0f);

            plantItem.DamageState.Brute += 0.010f * damage;
            plantItem.DamageState.Toxic += 0.001f * damage;
            plantItem.NutritionValue    -= 0.001f * damage;
#if DEBUG
            if (damage > 0.0f)
            {
                UnityEngine.Debug.Log(
                    " Plant ID: " + plantItem.ReferenceId +
                    " Name: " + plantItem.DisplayName +
                    " Temp: " + plantItem.WorldAtmosphere.Temperature +
                    " Damage: " + damage +
                    " CO2: " + plantItem.WorldAtmosphere.GasMixture.CarbonDioxide.Quantity
                    );
            }
#endif
        }
Exemple #2
0
        public static void applyFoodDamage(Food foodItem, float baseDamage)
        {
            // TODO: maybe move these settings to the config file?
            // Clamp the temperature value between 0C and 40C, below 0C there is no spoiling, beyond 40C takes max damage.
            float tempC  = PerishableItemsHelpers.Clamp(foodItem.WorldAtmosphere.Temperature - 273.15f, 0.0f, 40.0f);
            float damage = baseDamage * (tempC / 40.0f) * Math.Max(foodItem.WorldAtmosphere.ParticalPressureO2, 0.01f) / 1000f;

            // Damage applied based on the type of food container
            switch (foodItem.PrefabHash)
            {
            // Canned food has a special treatment, it will last longer while the container hasn't been opened, after
            // that it will be treated as any other food (spoiling time based on the item heatpoints).
            case 1327248310:     // Milk
            case 791746840:      // Cereal Bar
            case 688734890:      // Tomato Soup
                if (foodItem.RemainingRatio >= 1)
                {
                    damage *= PerishableItemsPlugin.PluginCannedMultiplier.Value;
                }
                break;

            case 1387403148:     // Soy oil
                damage *= PerishableItemsPlugin.PluginBottledMultiplier.Value;
                break;
            }

            // Add a little toxicity to the food, modified by the nutrition value of the item, the toxicity
            // will be used later to apply stun damage to the player ingesting this food item.
            // foodItem.NutritionValue *= 0.98f; // to make food lose nutrients
            foodItem.DamageState.Brute += 0.002f * damage;
            foodItem.DamageState.Toxic += 0.001f * damage;
            foodItem.NutritionValue    -= 0.001f * damage;
#if DEBUG
            if (damage > 0.0f)
            {
                UnityEngine.Debug.Log(
                    " Food ID: " + foodItem.ReferenceId +
                    " Name: " + foodItem.DisplayName +
                    " Temp: " + foodItem.WorldAtmosphere.Temperature +
                    " Damage: " + damage +
                    " O2: " + foodItem.WorldAtmosphere.GasMixture.Oxygen.Quantity +
                    " O2p: " + foodItem.WorldAtmosphere.ParticalPressureO2
                    );
            }
#endif
        }