public static bool DoesPlayerMeetRequirementsToEnter(Character.Models.Character player, Models.Room currentRoom, Models.Room foundRoom) { Console.WriteLine(); var meetsRequirements = foundRoom?.AttributeRequirementToEnter == null && foundRoom?.ItemRequirementToEnter == null; if (!meetsRequirements) { if (foundRoom?.AttributeRequirementToEnter != null && foundRoom?.ItemRequirementToEnter == null && CanPlayerEnterRoom(player, foundRoom, attrReq: foundRoom.AttributeRequirementToEnter)) { Console.WriteLine($"<{foundRoom.AttributeRequirementToEnter.RequirementName}>! \n", Color.Gold); meetsRequirements = true; } else if (foundRoom?.ItemRequirementToEnter != null && foundRoom?.AttributeRequirementToEnter == null && CanPlayerEnterRoom(player, foundRoom, foundRoom.ItemRequirementToEnter)) { if (foundRoom.ItemRequirementToEnter.RelevantItem.ItemName == Program.ItemCreator.Flashlight.ItemName && Program.ItemCreator.Flashlight.ItemTraits.First().TraitValue == 0) { Console.WriteLine($"It's too dark. Your flashlight battery is dead... \nPut in a new battery to enter {foundRoom.RoomName}.\n", Color.DarkGoldenrod); return(false); } Console.WriteLine($"Carrying: <{foundRoom.ItemRequirementToEnter.RequirementName}>! \n", Color.Gold); meetsRequirements = true; } else { if (CanPlayerEnterRoom(player, foundRoom, attrReq: foundRoom.AttributeRequirementToEnter) && CanPlayerEnterRoom(player, foundRoom, itemReq: foundRoom.ItemRequirementToEnter)) { if (foundRoom.ItemRequirementToEnter.RelevantItem.ItemName == Program.ItemCreator.Flashlight.ItemName) { foreach (var item in Program.CharacterCreator.Player.CarriedItems) { if (item.ItemName == Program.ItemCreator.Flashlight.ItemName && item.ItemTraits.First().TraitValue == 0) { Console.WriteLine($"It's too dark. Your flashlight battery is dead... \nPut in a new battery to enter {foundRoom.RoomName}.\n", Color.DarkGoldenrod); return(false); } } } Console.WriteLine($"<{foundRoom.AttributeRequirementToEnter.RequirementName}>! \n", Color.Gold); Console.WriteLine($"Carrying: <{foundRoom.ItemRequirementToEnter.RequirementName}>! \n", Color.Gold); meetsRequirements = true; } } } if (meetsRequirements) { TypingAnimation.Animate("You go to " + foundRoom.RoomName + "... \n", Color.Chartreuse, 40); if (foundRoom.ItemRequirementToEnter?.RelevantItem.ItemName == Program.ItemCreator.Flashlight.ItemName) { var consoleInfo = "Used Flashlight: battery dropped by 2% \n"; var light = player.CarriedItems.Single(i => i.ItemName == Program.ItemCreator.Flashlight.ItemName); var batteryBefore = light.ItemTraits.First().TraitValue; var hasBattery = FlashlightBatteryUpdate.FlashlightBatteryChange(light, batteryBefore, 2); if (!hasBattery) { consoleInfo = "Used Flashlight: now the battery is dead! \n"; } TypingAnimation.Animate(consoleInfo, Color.Chartreuse, 40); } Console.WriteWithGradient(ConsoleStrings.PressEnterPrompt, Color.Yellow, Color.DarkRed, 4); Console.ReadLine(); if (!currentRoom.RoomEntered) { currentRoom.RoomEntered = true; } foundRoom.AttributeRequirementToEnter = null; foundRoom.AttributeRequirementToSee = null; foundRoom.ItemRequirementToEnter = null; foundRoom.ItemRequirementToSee = null; } return(meetsRequirements); }
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); }