public static void LevelUpCheck(Player player) { if (player.Experience < player.ExperienceToLevel || player.Level == 10) { return; } foreach (IEffect effect in player.Effects.ToList()) { effect.IsEffectExpired = true; } player.Level++; player.Experience -= player.ExperienceToLevel; player.ExperienceToLevel = Settings.GetBaseExperienceToLevel() * player.Level; string levelUpString = $"You have leveled! You are now level {player.Level}."; OutputHelper.Display.StoreUserOutput( Settings.FormatLevelUpText(), Settings.FormatDefaultBackground(), levelUpString); int statsToAssign = 5; while (statsToAssign > 0) { string levelUpStatString = $"Please choose {statsToAssign} stats to raise. Your choices are: str, dex, int, const."; const string levelUpStatInfo = "You may raise a stat more than once by putting a number after the stat, IE str 2."; const string levelUpStatStr = "Str will increase your max carrying weight and warrior abilities."; const string levelUpStatDex = "Dex will increase your dodge chance and archer abilities"; const string levelUpStatInt = "Int will increase your mana and decrease your training cost for spells and abilities."; const string levelUpStatConst = "Const will increase your max hit points."; DisplayPlayerStats(player); OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), levelUpStatString); OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), levelUpStatInfo); OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), levelUpStatStr); OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), levelUpStatDex); OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), levelUpStatInt); OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), levelUpStatConst); OutputHelper.Display.RetrieveUserOutput(); OutputHelper.Display.ClearUserOutput(); int statNumber = 0; try { string[] input = InputHelper.GetFormattedInput(Console.ReadLine()); if (input.Length > 1) { if (GameHelper.IsWholeNumber(input[1]) == false) { continue; } statNumber = Convert.ToInt32(input[1]); } switch (input[0]) { case "str": if (statNumber > 0 && statNumber <= statsToAssign) { player.Strength += statNumber; statsToAssign -= statNumber; } else { player.Strength++; statsToAssign--; } break; case "dex": if (statNumber > 0 && statNumber <= statsToAssign) { player.Dexterity += statNumber; statsToAssign -= statNumber; } else { player.Dexterity++; statsToAssign--; } break; case "int": if (statNumber > 0 && statNumber <= statsToAssign) { player.Intelligence += statNumber; statsToAssign -= statNumber; } else { player.Intelligence++; statsToAssign--; } break; case "const": if (statNumber > 0 && statNumber <= statsToAssign) { player.Constitution += statNumber; statsToAssign -= statNumber; } else { player.Constitution++; statsToAssign--; } break; } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), "You did not select an appropriate stat!"); } } OutputHelper.Display.StoreUserOutput( Settings.FormatAnnounceText(), Settings.FormatDefaultBackground(), "All stats have been assigned!"); player.FireResistance += 5; player.FrostResistance += 5; player.ArcaneResistance += 5; CalculatePlayerStats(player); // Leveling sets player back to max stats player.HitPoints = player.MaxHitPoints; player.RagePoints = player.MaxRagePoints; player.ComboPoints = player.MaxComboPoints; player.ManaPoints = player.MaxManaPoints; // Update level for rainbow gear if any in player inventory foreach (IItem item in player.Inventory) { if (item is Armor || item is Weapon) { IRainbowGear rainbowItem = (IRainbowGear)item; if (rainbowItem != null && rainbowItem.IsRainbowGear) { rainbowItem.UpdateRainbowStats(player); } } } }
public static void StartCombat(Player player, Monster monster) { Console.Clear(); string fightStartString = $"{player.Name}, you have encountered a {monster.Name}. Time to fight!"; OutputHelper.Display.StoreUserOutput( Settings.FormatSuccessOutputText(), Settings.FormatDefaultBackground(), fightStartString); while (monster.HitPoints > 0 && player.HitPoints > 0 && player.InCombat && monster.InCombat) { GameHelper.RemovedExpiredEffectsAsync(player); GameHelper.RemovedExpiredEffectsAsync(monster); bool isInputValid = false; // Get input and check to see if input is valid, and if not, keep trying to get input from user while (!isInputValid) { // Show initial output that announces start of fight OutputHelper.ShowUserOutput(player, monster); OutputHelper.Display.ClearUserOutput(); // Player will attack, use ability, cast spells, etc. to cause damage _input = InputHelper.GetFormattedInput(Console.ReadLine()); Console.Clear(); isInputValid = ProcessPlayerInput(player, monster); } if (player.Effects.Any()) { ProcessPlayerEffects(player); } if (_fleeSuccess) { return; } // Check to see if player attack killed monster if (monster.HitPoints <= 0) { monster.MonsterDeath(player); return; } if (monster.Effects.Any()) { ProcessOpponentEffects(monster); } // Check to see if damage over time effects killed monster if (monster.HitPoints <= 0) { monster.MonsterDeath(player); return; } if (monster.IsStunned) { continue; } monster.Attack(player); // Check at end of round to see if monster was killed by combat round if (monster.HitPoints > 0) { continue; } monster.MonsterDeath(player); return; } }
private static void FleeCombat(Player player, Monster monster) { int randomNum = GameHelper.GetRandomNumber(1, 10); if (randomNum > 5) { OutputHelper.Display.StoreUserOutput( Settings.FormatSuccessOutputText(), Settings.FormatDefaultBackground(), "You have fled combat successfully!"); player.InCombat = false; monster.InCombat = false; _fleeSuccess = true; IRoom playerRoom = RoomHelper.Rooms[player.PlayerLocation]; int playerX = player.PlayerLocation.X; int playerY = player.PlayerLocation.Y; int playerZ = player.PlayerLocation.Z; if (playerRoom.Up != null) { Coordinate newCoord = new Coordinate(playerX, playerY, playerZ + 1); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.East != null) { Coordinate newCoord = new Coordinate(playerX + 1, playerY, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.West != null) { Coordinate newCoord = new Coordinate(playerX - 1, playerY, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.North != null) { Coordinate newCoord = new Coordinate(playerX, playerY + 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.South != null) { Coordinate newCoord = new Coordinate(playerX, playerY - 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.NorthEast != null) { Coordinate newCoord = new Coordinate(playerX + 1, playerY + 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.NorthWest != null) { Coordinate newCoord = new Coordinate(playerX - 1, playerY + 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.SouthEast != null) { Coordinate newCoord = new Coordinate(playerX + 1, playerY - 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.SouthWest != null) { Coordinate newCoord = new Coordinate(playerX - 1, playerY - 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); return; } if (playerRoom.Down != null) { Coordinate newCoord = new Coordinate(playerX, playerY, playerZ - 1); RoomHelper.ChangeRoom(player, newCoord); return; } } OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You tried to flee combat but failed!"); }
public static void ProcessUserInput(Player player, string[] input, Timer globalTimer) { IRoom playerRoom = RoomHelper.Rooms[player.PlayerLocation]; TownRoom isTownRoom = playerRoom as TownRoom; int playerX = player.PlayerLocation.X; int playerY = player.PlayerLocation.Y; int playerZ = player.PlayerLocation.Z; switch (input[0]) { case "a": case "attack": case "kill": playerRoom.AttackOpponent(player, input, globalTimer); break; case "buy": try { if (input[1] != null) { try { bool quantityProvided = int.TryParse(input.Last(), out int quantity); if (!quantityProvided) { quantity = 1; } else { input = input.Take(input.Count() - 1).ToArray(); } isTownRoom?.Vendor.BuyItem(player, input, quantity); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no vendor in the room to buy an item from."); } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Buy what?"); } break; case "cast": try { if (input[1] != null && input[1].Contains("town")) { player.CastSpell(ParseInput(input)); } else if (input[1] != null) { player.CastSpell(ParseInput(input)); } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You don't have that spell."); } catch (NullReferenceException) { if (player.PlayerClass != PlayerClassType.Mage) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You can't cast spells. You're not a mage!"); } } catch (InvalidOperationException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), player.PlayerClass != PlayerClassType.Mage ? "You can't cast spells. You're not a mage!" : "You do not have enough mana to cast that spell!"); } break; case "drop": GearHelper.DropItem(player, input); break; case "pickup": GearHelper.PickupItem(player, input); break; case "use": try { if (input.Contains("distance")) { player.UseAbility(input); } else if (input.Contains("ambush")) { player.UseAbility(playerRoom.Monster, input); playerRoom.AttackOpponent(player, input, globalTimer); } else if (input[1] != null) { player.UseAbility(input); } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You don't have that ability."); Console.WriteLine(); } catch (ArgumentOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You don't have that ability."); } catch (NullReferenceException) { if (player.PlayerClass == PlayerClassType.Mage) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You can't use abilities. You're not a warrior or archer!"); } } catch (InvalidOperationException) { switch (player.PlayerClass) { case PlayerClassType.Warrior: OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You do not have enough rage to use that ability!"); break; case PlayerClassType.Archer: OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), player.PlayerWeapon.WeaponGroup != WeaponType.Bow ? "You do not have a bow equipped!" : "You do not have enough combo points to use that ability!"); break; case PlayerClassType.Mage: OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You can't use abilities. You're not a warrior or archer!"); break; default: throw new ArgumentOutOfRangeException(); } } break; case "equip": case "unequip": GearHelper.EquipItem(player, input); break; case "enhance": int itemIndex = player.Inventory.FindIndex(f => f.Name.Contains(input[1])); switch (player.Inventory[itemIndex]) { case Weapon _: GearHelper.UseWeaponKit(player, input); break; case Armor _: GearHelper.UseArmorKit(player, input); break; default: Messages.InvalidCommand(); break; } break; case "reload": player.ReloadQuiver(); break; case "i": case "inventory": PlayerHelper.ShowInventory(player); break; case "q": case "quit": bool quitConfirm = GameHelper.QuitGame(player); if (quitConfirm) { globalTimer.Dispose(); } break; case "list": switch (input[1]) { case "abilities": try { PlayerHelper.ListAbilities(player); } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "List what?"); } break; case "spells": try { PlayerHelper.ListSpells(player); } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "List what?"); } break; } break; case "ability": try { PlayerHelper.AbilityInfo(player, input); } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "What ability did you want to know about?"); } break; case "spell": try { PlayerHelper.SpellInfo(player, input); } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "What spell did you want to know about?"); } break; case "quest": try { PlayerHelper.QuestInfo(player, input); } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "What quest did you want to know about?"); } break; case "complete": try { if (input[1] != null) { try { if (isTownRoom?.Trainer != null) { isTownRoom?.Trainer.CompleteQuest(player, input); } else { isTownRoom?.Vendor.CompleteQuest(player, input); } } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no one to turn in quests to here."); } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Complete what quest?"); } break; case "l": case "look": try { if (input[1] != null) { PlayerHelper.LookAtObject(player, input); } } catch (IndexOutOfRangeException) { playerRoom.LookRoom(); } break; case "loot": try { if (input[1] != null) { try { playerRoom.LootCorpse(player, input); } catch (Exception) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "An error has occurred while looting."); } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Loot what?"); } break; case "drink": if (input.Last() == "potion") { player.AttemptDrinkPotion(ParseInput(input)); } else { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "You can't drink that!"); } break; case "save": GameHelper.SaveGame(player); break; case "restore": isTownRoom?.Vendor.RestorePlayer(player); break; case "help": Messages.ShowCommandHelp(); break; case "sell": try { if (input[1] != null) { try { isTownRoom?.Vendor.SellItem(player, input); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "The vendor doesn't want that."); } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Sell what?"); } break; case "repair": try { if (input[1] != null) { if (isTownRoom != null) { if (input[1] == "all") { foreach (IItem item in player.Inventory) { if (!(item is IEquipment itemToRepair && itemToRepair.Equipped)) { continue; } string[] itemNameArray = new[] { input[0], item.Name }; isTownRoom.Vendor.RepairItem(player, itemNameArray, true); } break; } isTownRoom.Vendor.RepairItem(player, input, false); } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Repair what?"); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no vendor here!"); } break; case "upgrade": try { if (input[1] != null) { if (isTownRoom != null) { if (player.PlayerClass == PlayerClassType.Mage) { isTownRoom.Trainer.UpgradeSpell(player, ParseInput(input)); } else { isTownRoom.Trainer.UpgradeAbility(player, ParseInput(input)); } } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Upgrade what?"); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no trainer here!"); } break; case "train": try { if (input[1] != null) { if (isTownRoom != null) { if (player.PlayerClass == PlayerClassType.Mage) { isTownRoom.Trainer.TrainSpell(player, ParseInput(input)); } else { isTownRoom.Trainer.TrainAbility(player, ParseInput(input)); } } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Train what?"); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no trainer here!"); } break; case "consider": try { if (isTownRoom?.Trainer != null) { isTownRoom.Trainer.OfferQuest(player, input); } else { isTownRoom?.Vendor.OfferQuest(player, input); } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Consider what quest?"); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no quest giver here!"); } break; case "show": try { if (input[1].Contains("forsale")) { try { isTownRoom?.Vendor.DisplayGearForSale(); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no vendor in the room to show inventory available for sale."); } } if (input[1].Contains("upgrade")) { try { isTownRoom?.Trainer.DisplayAvailableUpgrades(player); } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no trainer in the room to show available upgrades."); } } if (input[1].Contains("quests")) { try { if (isTownRoom?.Trainer != null) { isTownRoom.Trainer.ShowQuestList(player); } else { isTownRoom?.Vendor.ShowQuestList(player); } } catch (NullReferenceException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "There is no one in the room to show quests."); } } } catch (IndexOutOfRangeException) { OutputHelper.Display.StoreUserOutput( Settings.FormatFailureOutputText(), Settings.FormatDefaultBackground(), "Show what?"); } break; case "n": case "north": if (playerRoom.North != null) { try { Coordinate newCoord = new Coordinate(playerX, playerY + 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "s": case "south": if (playerRoom.South != null) { try { Coordinate newCoord = new Coordinate(playerX, playerY - 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "e": case "east": if (playerRoom.East != null) { try { Coordinate newCoord = new Coordinate(playerX + 1, playerY, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "w": case "west": if (playerRoom.West != null) { try { Coordinate newCoord = new Coordinate(playerX - 1, playerY, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "ne": case "northeast": if (playerRoom.NorthEast != null) { try { Coordinate newCoord = new Coordinate(playerX + 1, playerY + 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "nw": case "northwest": if (playerRoom.NorthWest != null) { try { Coordinate newCoord = new Coordinate(playerX - 1, playerY + 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "se": case "southeast": if (playerRoom.SouthEast != null) { try { Coordinate newCoord = new Coordinate(playerX + 1, playerY - 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "sw": case "southwest": if (playerRoom.SouthWest != null) { try { Coordinate newCoord = new Coordinate(playerX - 1, playerY - 1, playerZ); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "u": case "up": if (playerRoom.Up != null) { try { Coordinate newCoord = new Coordinate(playerX, playerY, playerZ + 1); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; case "d": case "down": if (playerRoom.Down != null) { try { Coordinate newCoord = new Coordinate(playerX, playerY, playerZ - 1); RoomHelper.ChangeRoom(player, newCoord); } catch (ArgumentOutOfRangeException) { Messages.InvalidDirection(); } } else { Messages.InvalidDirection(); } break; default: Messages.InvalidCommand(); break; } }