-
Notifications
You must be signed in to change notification settings - Fork 0
/
Selections.cs
152 lines (149 loc) · 6.26 KB
/
Selections.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
public static class Selections
{
/// <summary>
/// Returns a Character element.
/// Uses a battlesystem element to select the party.
/// Uses a character element to check to see if that character belongs to the party and to see if it's a computer player.
/// </summary>
/// <param name="battle"></param>
/// <param name="character"></param>
/// <returns></returns>
public static Character SelectTarget(BattleSystem battle, Character character)
{
var computerPlayer = character._playerType == PlayerType.CPU;
var inMonsterParty = battle.MonsterParty.PartyList.Contains(character);
int partyInput;
if (computerPlayer && inMonsterParty) partyInput = 1; //Have the monster party computer select the Hero party
else if (computerPlayer && !inMonsterParty) partyInput = 2; //Have hero party computer select the Monster Party
else
{
while (true)
{
//Select the party you wish to target
//Allows self targeting for various things like attacks, items, etc if needed.
Console.WriteLine("Pick the party you wish to target. 1 for the Hero Party, 2 for the Monster Party.");
if (Int32.TryParse(Console.ReadLine(), out partyInput))
{
Console.Clear();
break;
}
else Console.WriteLine("An invalid key was entered. Please try again.\n");
}
}
var targetParty = partyInput switch
{
1 => battle.HeroParty,
2 => battle.MonsterParty,
_ => battle.MonsterParty
};
//stores the target party list, will eventually become the target character to return
var target = targetParty.PartyList;
while (true)
{
int input = 0;
if (computerPlayer)
{
Random random = new Random();
//random select for monster party based on the length of the chosen party
random.Next(0, target.Count);
}
else
{
while (true)
{
Console.WriteLine("Pick the character you wish to target");
//shows a list of the characters to target
for (int i = 0; i < target.Count; i++)
{
Console.WriteLine($"{i}: {target[i].Name}");
}
//input validation
if (Int32.TryParse(Console.ReadLine(), out input))
{
Console.Clear();
break;
}
else Console.WriteLine("An invalid key was entered. Please try again.\n");
}
}
//check to see if the index is null
var exists = target.ElementAtOrDefault(input) != null;
//returns the character of the target party list
if (exists) return target[input];
else Console.WriteLine("That character doesn't exist. Try again.\n");
}
}
/// <summary>
/// Returns Item element.
/// Takes in a battlesystem element to check the active party's items
/// Takes in a character element to use the item on that character.
/// </summary>
/// <param name="battle"></param>
/// <param name="character"></param>
/// <returns></returns>
public static Item SelectItem(BattleSystem battle, Character character)
{
//check the active party's items
var activePartyItems = battle.ActiveParty.PartyItems;
int partyInput;
while (true)
{
if (character._playerType == PlayerType.CPU)
{
//just uses the first item they have for now
return activePartyItems[0];
}
else
{
while (true)
{
//Pick the item you want to use
Console.WriteLine("Select the item you want to use.");
for (int i = 0; i < activePartyItems.Count; i++)
{
Console.WriteLine($"{i}: {activePartyItems[i].Name} x{activePartyItems[i].Quantity}\n" +
$"{activePartyItems[i].Description}\n");
}
if (Int32.TryParse(Console.ReadLine(), out partyInput)) break;
else Console.WriteLine("An invalid key was entered. Please try again.\n");
}
}
//check to see if the index is null
var exists = activePartyItems.ElementAtOrDefault(partyInput) != null;
//returns the item of the party item list
if (exists) return activePartyItems[partyInput];
else Console.WriteLine("That item doesn't exist. Try again.\n");
}
}
/// <summary>
/// Returns Equipment element.
/// Takes a battle as a paramter to check active party equipment
/// Takes a character to equip the equipment.
/// </summary>
/// <param name="battle"></param>
/// <param name="character"></param>
/// <returns></returns>
public static Equipment SelectEquipment(BattleSystem battle, Character character)
{
//check the active party's equipment
var activePartyEquipment = battle.ActiveParty.PartyEquipment;
int partyInput;
if (character._playerType == PlayerType.CPU)
{
//just equips the first thing they have for now
return activePartyEquipment[0];
}
else
{
//Pick the equipment you want to use.
Console.WriteLine("Select the Equipment you want to equip.");
for (int i = 0; i < activePartyEquipment.Count; i++)
{
Console.WriteLine($"{i}: {activePartyEquipment[i].Name}\n" +
$"{activePartyEquipment[i].Description}\n");
}
partyInput = Convert.ToInt32(Console.ReadLine());
}
return activePartyEquipment[partyInput];
}
}