Beispiel #1
0
        public string GetContentNutritionFacts(IWorldAccessor world, ItemSlot inSlotorFirstSlot, ItemStack[] contentStacks, EntityAgent forEntity, bool mulWithStacksize = false)
        {
            FoodNutritionProperties[] props = GetContentNutritionProperties(world, contentStacks, forEntity);

            Dictionary <EnumFoodCategory, float> totalSaturation = new Dictionary <EnumFoodCategory, float>();
            float totalHealth = 0;

            for (int i = 0; i < props.Length; i++)
            {
                FoodNutritionProperties prop = props[i];
                if (prop == null)
                {
                    continue;
                }

                float sat = 0;
                totalSaturation.TryGetValue(prop.FoodCategory, out sat);

                DummySlot       slot       = new DummySlot(contentStacks[i], inSlotorFirstSlot.Inventory);
                TransitionState state      = contentStacks[i].Collectible.UpdateAndGetTransitionState(api.World, slot, EnumTransitionType.Perish);
                float           spoilState = state != null ? state.TransitionLevel : 0;

                float mul = mulWithStacksize ? contentStacks[i].StackSize : 1;

                float satLossMul = GlobalConstants.FoodSpoilageSatLossMul(spoilState, slot.Itemstack, forEntity);
                float healthLoss = GlobalConstants.FoodSpoilageHealthLoss(spoilState, slot.Itemstack, forEntity);

                totalHealth += (prop.Health - healthLoss) * mul;
                totalSaturation[prop.FoodCategory] = (sat + prop.Satiety * satLossMul) * mul;
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Nutrition Facts");

            foreach (var val in totalSaturation)
            {
                sb.AppendLine("- " + Lang.Get("" + val.Key) + ": " + Math.Round(val.Value) + " sat.");
            }

            if (totalHealth != 0)
            {
                sb.AppendLine("- " + Lang.Get("Health: {0}{1} hp", totalHealth > 0 ? "+" : "", totalHealth));
            }

            return(sb.ToString());
        }