558 lines
19 KiB
C#
558 lines
19 KiB
C#
public interface IAction
|
|
{
|
|
void DoAction(Character character, Action action);
|
|
}
|
|
|
|
public sealed class Actions
|
|
{
|
|
|
|
public static readonly Lazy<Actions> _instance = new Lazy<Actions> (() => new Actions());
|
|
private Actions() {}
|
|
public static Actions Instance
|
|
{
|
|
get {return _instance.Value;}
|
|
}
|
|
|
|
public int GetAction(Character character)
|
|
{
|
|
if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == false)
|
|
{
|
|
int input;
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
input = Int32.Parse(ColoredConsole.Prompt("Select an action"));
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
if (input <= 0 || input > character.CharacterEnabledActions.Count)
|
|
{
|
|
ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
return input - 1;
|
|
}
|
|
else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == false)
|
|
{
|
|
int input;
|
|
while (true)
|
|
{
|
|
input = Int32.Parse(ColoredConsole.Prompt("Select an action"));
|
|
if (input <= 0 || input > character.CharacterEnabledActions.Count)
|
|
{
|
|
ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
return input - 1;
|
|
}
|
|
else if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == true)
|
|
{
|
|
if (character.currentHP < character.maxHP / 2)
|
|
{
|
|
Random random = new Random();
|
|
int roll = random.Next(1, 5);
|
|
if (roll == 1)
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == true)
|
|
{
|
|
Random random = new Random();
|
|
if (character.currentHP < character.maxHP / 2)
|
|
{
|
|
int roll = random.Next(1, 5);
|
|
if (roll == 1)
|
|
{
|
|
return roll;
|
|
}
|
|
else
|
|
{
|
|
while (true)
|
|
{
|
|
int notPotionAction = random.Next(0, character.CharacterEnabledActions.Count);
|
|
if (notPotionAction != 1)
|
|
{
|
|
return notPotionAction;
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while (true)
|
|
{
|
|
int notPotionAction = random.Next(0, character.CharacterEnabledActions.Count);
|
|
if (notPotionAction != 1)
|
|
{
|
|
return notPotionAction;
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else return 0;
|
|
}
|
|
|
|
public bool DoAction(Character character, int action)
|
|
{
|
|
string actionToDo = character.CharacterEnabledActions[action];
|
|
if (actionToDo == "Do Nothing")
|
|
{
|
|
DoNothing(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Punch")
|
|
{
|
|
Punch(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Sword Attack")
|
|
{
|
|
SwordAttack(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Health Potion")
|
|
{
|
|
HealthPotion(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Items")
|
|
{
|
|
bool useItem = Items(character);
|
|
return useItem;
|
|
}
|
|
if (actionToDo == "Bone Crunch")
|
|
{
|
|
BoneCrunch(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Unraveling")
|
|
{
|
|
Unraveling(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Bow Shot")
|
|
{
|
|
BowShot(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Quick Shot")
|
|
{
|
|
QuickShot(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Hero's Sword")
|
|
{
|
|
HerosSword(character);
|
|
return true;
|
|
}
|
|
if (actionToDo == "Bite")
|
|
{
|
|
Bite(character);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void DoNothing(Character character)
|
|
{
|
|
ColoredConsole.WriteLine($"\n{character.name} does NOTHING.", ConsoleColor.Yellow);
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
|
|
public void Punch(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage = character.damageModifier + 1 - target.damageReduction;
|
|
ColoredConsole.WriteLine($"\n{character.name} uses PUNCH!", ConsoleColor.Yellow);
|
|
if (target.name == "Amarok")
|
|
{
|
|
ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red);
|
|
}
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write("HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
|
|
public void SwordAttack(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage;
|
|
Random random = new Random();
|
|
|
|
if (character.equipedItems.Any())
|
|
{
|
|
damage = character.damageModifier + character.equipedItems[0].ItemDamageModifier - target.damageReduction;
|
|
}
|
|
else
|
|
{
|
|
damage = character.damageModifier - target.damageReduction;
|
|
}
|
|
ColoredConsole.WriteLine($"\n{character.name} uses SWORD ATTACK!", ConsoleColor.Yellow);
|
|
if (target.name == "Amarok")
|
|
{
|
|
ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red);
|
|
}
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write("HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
|
|
public void HerosSword(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage;
|
|
Random random = new Random();
|
|
|
|
damage = random.Next(1, 4) + character.equipedItems[0].ItemDamageModifier - target.damageReduction;
|
|
ColoredConsole.WriteLine($"\n{character.name} uses HERO'S SWORD!", ConsoleColor.Yellow);
|
|
if (target.name == "Amarok")
|
|
{
|
|
ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red);
|
|
}
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write("HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
|
|
}
|
|
|
|
public void BoneCrunch(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage;
|
|
|
|
ColoredConsole.WriteLine($"\n{character.name} uses BONE CRUNCH!", ConsoleColor.Yellow);
|
|
Random random = new Random();
|
|
if (character.equipedItems.Any())
|
|
{
|
|
damage = random.Next(0, 2) + character.damageModifier + character.equipedItems[0].ItemDamageModifier - target.damageReduction;
|
|
}
|
|
else
|
|
{
|
|
damage = random.Next(0, 2) - target.damageReduction;
|
|
}
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write("HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
|
|
public void HealthPotion(Character character)
|
|
{
|
|
if (GameState.Instance.heros.Contains(character))
|
|
{
|
|
if (GameState.Instance.heroPotionsAvailable > 0)
|
|
{
|
|
ColoredConsole.WriteLine($"\n{character.name} uses a HEALTH POTION!", ConsoleColor.Yellow);
|
|
GameState.Instance.heroPotionsAvailable -= 1;
|
|
if (character.currentHP + 5 > character.maxHP)
|
|
{
|
|
character.currentHP = character.maxHP;
|
|
ColoredConsole.WriteLine($"{character.name}'s HP is now {character.maxHP}.", ConsoleColor.Green);
|
|
}
|
|
else
|
|
{
|
|
character.currentHP += 5;
|
|
ColoredConsole.WriteLine($"{character.name}'s HP is now {character.currentHP}.", ConsoleColor.Green);
|
|
}
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
ColoredConsole.WriteLine("There are no more potions!", ConsoleColor.Red);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (GameState.Instance.monsterPotionsAvailable > 0)
|
|
{
|
|
ColoredConsole.WriteLine($"\n{character.name} uses a HEALTH POTION!", ConsoleColor.Yellow);
|
|
GameState.Instance.monsterPotionsAvailable -= 1;
|
|
if (character.currentHP + 5 > character.maxHP)
|
|
{
|
|
character.currentHP = character.maxHP;
|
|
ColoredConsole.WriteLine($"{character.name}'s HP is now {character.maxHP}.", ConsoleColor.Green);
|
|
}
|
|
else
|
|
{
|
|
character.currentHP += 5;
|
|
ColoredConsole.WriteLine($"{character.name}'s HP is now {character.currentHP}.", ConsoleColor.Green);
|
|
}
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
ColoredConsole.WriteLine("There are no more potions!", ConsoleColor.Red);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool Items(Character character)
|
|
{
|
|
while (true)
|
|
{
|
|
Console.Clear();
|
|
GameState.Instance.DisplayStatus();
|
|
Menu.BuildItemsMenu(character);
|
|
Item item = GetItem(character);
|
|
if (item is null)
|
|
{
|
|
return false;
|
|
}
|
|
//Console.WriteLine(ItemDamageModifier);
|
|
if (item != null)
|
|
{
|
|
Item.EquipItem(character, item);
|
|
return true;
|
|
}
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public Item? GetItem(Character character)
|
|
{
|
|
int selection;
|
|
while (true)
|
|
{
|
|
selection = Int32.Parse(ColoredConsole.Prompt("Select an item")) - 1;
|
|
if (character.equipedItems.Any() && selection == 0)
|
|
{
|
|
Item.UnequipItem(character, character.equipedItems[selection]);
|
|
return null;
|
|
}
|
|
if (!character.equipedItems.Any() && selection >= 0 && selection < GameState.Instance.heroInventory.Count)
|
|
{
|
|
break;
|
|
}
|
|
if (selection == GameState.Instance.heroInventory.Count)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
}
|
|
Item item = GameState.Instance.heroInventory[selection];
|
|
return item;
|
|
}
|
|
|
|
public void Unraveling(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage;
|
|
Random random = new Random();
|
|
|
|
ColoredConsole.WriteLine($"\n{character.name} uses UNRAVELING!", ConsoleColor.Yellow);
|
|
damage = random.Next(0, 6) - target.damageReduction;
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write("HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
|
|
public void Bite(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage;
|
|
|
|
ColoredConsole.WriteLine($"\n{character.name} uses BITE!", ConsoleColor.Yellow);
|
|
damage = character.damageModifier + 1 - target.damageReduction;
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write("HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
|
|
public void BowShot(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage;
|
|
|
|
ColoredConsole.WriteLine($"\n{character.name} uses BOW SHOT!", ConsoleColor.Yellow);
|
|
if (target.name == "Amarok")
|
|
{
|
|
ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red);
|
|
}
|
|
damage = character.equipedItems[0].ItemDamageModifier - target.damageReduction;
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write($"HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
|
|
public void QuickShot(Character character)
|
|
{
|
|
var target = GetTarget(character);
|
|
int damage;
|
|
Random random = new Random();
|
|
|
|
ColoredConsole.WriteLine($"\n{character.name} uses QUICK SHOT!", ConsoleColor.Yellow);
|
|
int roll = random.Next(1, 101);
|
|
if (roll < 50)
|
|
{
|
|
ColoredConsole.WriteLine("Nothing happened!", ConsoleColor.Yellow);
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (target.name == "Amarok")
|
|
{
|
|
ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red);
|
|
}
|
|
damage = random.Next(2,6) - target.damageReduction;
|
|
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
|
|
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
|
|
ColoredConsole.Write($"HP.", ConsoleColor.Cyan);
|
|
target.currentHP -= damage;
|
|
Thread.Sleep(1500);
|
|
return;
|
|
}
|
|
}
|
|
|
|
public Character GetTarget(Character character)
|
|
{
|
|
if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == false)
|
|
{
|
|
while (true)
|
|
{
|
|
foreach (Character monster in GameState.Instance.monsters)
|
|
{
|
|
int index = GameState.Instance.monsters.IndexOf(monster) + 1;
|
|
int indexOf = GameState.Instance.monsters.IndexOf(monster);
|
|
int indexLast = GameState.Instance.monsters.IndexOf(GameState.Instance.monsters[^1]);
|
|
Console.Write($"{index}. {monster.name}");
|
|
if (indexOf != indexLast && index != GameState.Instance.monsters.Count())
|
|
{
|
|
Console.Write("\n");
|
|
}
|
|
}
|
|
try
|
|
{
|
|
int target = Int32.Parse(ColoredConsole.Prompt("\nSelect a target"));
|
|
return GameState.Instance.monsters[target - 1];
|
|
}
|
|
catch (ArgumentOutOfRangeException)
|
|
{
|
|
ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == false)
|
|
{
|
|
while (true)
|
|
{
|
|
foreach (Character hero in GameState.Instance.heros)
|
|
{
|
|
int index = GameState.Instance.heros.IndexOf(hero) + 1;
|
|
Console.Write($"{index}. {hero.name}");
|
|
}
|
|
try
|
|
{
|
|
int target = Int32.Parse(ColoredConsole.Prompt("\nSelect a target"));
|
|
return GameState.Instance.heros[target - 1];
|
|
}
|
|
catch (ArgumentOutOfRangeException)
|
|
{
|
|
ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red);
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
else if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == true)
|
|
{
|
|
while (true)
|
|
{
|
|
Random random = new Random();
|
|
int index = random.Next(0, GameState.Instance.monsters.Count);
|
|
if (GameState.Instance.monsters.Contains(GameState.Instance.monsters[index]))
|
|
{
|
|
return GameState.Instance.monsters[index];
|
|
}
|
|
else continue;
|
|
}
|
|
}
|
|
else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == true)
|
|
{
|
|
while (true)
|
|
{
|
|
Random random = new Random();
|
|
int index = random.Next(0, GameState.Instance.heros.Count);
|
|
if (GameState.Instance.heros.Contains(GameState.Instance.heros[index]))
|
|
{
|
|
return GameState.Instance.heros[index];
|
|
}
|
|
else continue;
|
|
}
|
|
}
|
|
else return GameState.Instance.heros[0];
|
|
}
|
|
}
|