Beispiel #1
0
        public static bool HandleItemBeingUsed(Character.Models.Character player, Items foundItem, string playerInput)
        {
            if (foundItem?.WeaponItems?.First() != null)
            {
                Console.WriteLine();
                TypingAnimation.Animate($"You swing your {foundItem.WeaponItems.First().WeaponName} around wildly.\n", Color.ForestGreen);
                return(true);
            }

            if (foundItem?.InventoryItems?.First() != null)
            {
                var item = foundItem.InventoryItems.First();
                if (item.TreatItemAs == ItemUseTypes.Default || item.TreatItemAs == ItemUseTypes.Key)
                {
                    Console.WriteLine();
                    TypingAnimation.Animate($"You {playerInput} the {item.ItemName} but nothing happens...\n",
                                            Color.ForestGreen);
                    return(true);
                }

                if (item.TreatItemAs == ItemUseTypes.Wearable)
                {
                    Console.WriteLine();
                    TypingAnimation.Animate($"You're already wearing the {item.ItemName}...\n", Color.ForestGreen);
                    return(true);
                }

                if (item.TreatItemAs == ItemUseTypes.Document)
                {
                    var traitsAdded = "";
                    foreach (var trait in item.ItemTraits)
                    {
                        if (!string.IsNullOrEmpty(trait.RelevantCharacterAttribute))
                        {
                            if (trait.TraitValue > 0)
                            {
                                traitsAdded += $"\n\t{trait.RelevantCharacterAttribute} + ({trait.TraitValue})!";
                                AttributeHandler.AddCharacterAttributesByTrait(player, trait);
                                trait.TraitName  = "";
                                trait.TraitValue = 0;
                            }
                        }
                    }

                    Console.WriteLine();
                    TypingAnimation.Animate($"You read the {item.ItemName}: {traitsAdded}\n \n\n{item.DocumentText}\n",
                                            Color.GhostWhite);
                    return(true);
                }

                if (item.TreatItemAs == ItemUseTypes.ConsumableAttribute)
                {
                    var traitsAdded = "";
                    foreach (var trait in item.ItemTraits)
                    {
                        if (!string.IsNullOrEmpty(trait.RelevantCharacterAttribute))
                        {
                            traitsAdded += $"\n\t{trait.RelevantCharacterAttribute} + ({trait.TraitValue})!";
                            AttributeHandler.AddCharacterAttributesByTrait(player, trait);
                        }
                    }

                    player.Attributes.CarriedItemsCount -= item.InventorySpaceConsumed;
                    player.CarriedItems.Remove(item);
                    Console.WriteLine();
                    TypingAnimation.Animate($"You use the {item.ItemName}: \n{traitsAdded}\n", Color.ForestGreen);
                    return(true);
                }

                if (item.TreatItemAs == ItemUseTypes.ConsumableBattery)
                {
                    var flashlight = player.CarriedItems.SingleOrDefault(i =>
                                                                         i.ItemName == Program.ItemCreator.Flashlight.ItemName);
                    var traitsAdded = "";
                    foreach (var trait in item.ItemTraits)
                    {
                        if (!string.IsNullOrEmpty(flashlight?.ItemName))
                        {
                            traitsAdded += $"\n\tFlashlight battery: ({trait.TraitValue}%)!";
                            FlashlightBatteryUpdate.FlashlightBatteryChange(flashlight,
                                                                            percentToSet: trait.TraitValue);
                        }
                    }

                    if (!string.IsNullOrEmpty(flashlight?.ItemName))
                    {
                        player.Attributes.CarriedItemsCount -= item.InventorySpaceConsumed;
                        player.CarriedItems.Remove(item);
                        Console.WriteLine();
                        TypingAnimation.Animate($"You use the {item.ItemName}: \n{traitsAdded}\n", Color.ForestGreen);
                        return(true);
                    }

                    Console.WriteLine();
                    TypingAnimation.Animate($"You don't have anything to use the {item.ItemName} on...\n",
                                            Color.DarkOliveGreen);
                    return(true);
                }

                if (item.TreatItemAs == ItemUseTypes.ConsumableHealth)
                {
                    var traitsAdded = "";
                    if (player.HealthPoints < player.MaximumHealthPoints)
                    {
                        foreach (var trait in item.ItemTraits)
                        {
                            if (string.IsNullOrEmpty(trait.RelevantCharacterAttribute))
                            {
                                if (player.HealthPoints + trait.TraitValue > player.MaximumHealthPoints)
                                {
                                    player.HealthPoints = player.MaximumHealthPoints;
                                }
                                else
                                {
                                    player.HealthPoints += trait.TraitValue;
                                }

                                traitsAdded += $"\n\tHealth Points: + ({trait.TraitValue})!";
                            }
                            else
                            {
                                traitsAdded += trait.TraitValue >= 0 ? $"\n\t{trait.RelevantCharacterAttribute} + ({trait.TraitValue})!" : $"\n\t{trait.RelevantCharacterAttribute} - ({-1 * trait.TraitValue})";
                                AttributeHandler.AddCharacterAttributesByTrait(player, trait);
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(traitsAdded))
                    {
                        player.Attributes.CarriedItemsCount -= item.InventorySpaceConsumed;
                        player.CarriedItems.Remove(item);
                        Console.WriteLine();
                        TypingAnimation.Animate($"You consume the {item.ItemName}: \n{traitsAdded}\n",
                                                Color.ForestGreen);
                        return(true);
                    }

                    Console.WriteLine();
                    TypingAnimation.Animate(
                        $"You don't need to use the {item.ItemName}, you have full Health Points...\n",
                        Color.DarkOliveGreen);
                    return(true);
                }

                if (item.TreatItemAs == ItemUseTypes.ConsumableAmmo)
                {
                    var traitsAdded = "";

                    if (!string.IsNullOrEmpty(player.WeaponItem?.WeaponName) &&
                        !string.IsNullOrEmpty(player.WeaponItem?.AmmunitionType) &&
                        player.WeaponItem.AmmunitionType == item.AmmunitionType)
                    {
                        player.WeaponItem.AmmunitionAmount += item.AmmunitionAmount;
                        traitsAdded += $"\n\t{player.WeaponItem.WeaponName} Ammo + ({item.AmmunitionAmount}) = ({player.WeaponItem.AmmunitionAmount})!";
                        player.Attributes.CarriedItemsCount -= item.InventorySpaceConsumed;
                        player.CarriedItems.Remove(item);
                        Console.WriteLine();
                        TypingAnimation.Animate($"You use the {item.ItemName}: \n{traitsAdded}\n", Color.ForestGreen);
                        return(true);
                    }

                    Console.WriteLine();
                    TypingAnimation.Animate($"You don't have a weapon that uses {item.AmmunitionType}...\n",
                                            Color.DarkOliveGreen);
                    return(true);
                }
            }

            return(false);
        }