62 lines
No EOL
2 KiB
C#
62 lines
No EOL
2 KiB
C#
public class Player : Character
|
|
{
|
|
public List<Item> Inventory { get; set; }
|
|
public List<Move> Moves { get; set; }
|
|
|
|
public Player(string name, int maxhealth, int currenthealth, int maxmpoints, int currentmpoints, List<Item> inventory, List<Move> moves) : base(name, maxhealth, currenthealth, maxmpoints, currentmpoints)
|
|
{
|
|
Inventory = inventory;
|
|
Moves = moves;
|
|
}
|
|
|
|
//Returns the players inventory in a Dictionary.
|
|
public Dictionary<string, int> RetrieveInventory()
|
|
{
|
|
if (Inventory == null || Inventory.Count == 0)
|
|
{
|
|
Console.WriteLine("Empty");
|
|
return new Dictionary<string, int>();
|
|
}
|
|
return Inventory
|
|
.GroupBy(item => item.Name)
|
|
.ToDictionary(group => group.Key, group => group.Count());
|
|
}
|
|
|
|
//For using a healing item. Doesn't allow you to overheal.
|
|
public void UseHealingItem(HealingItem item)
|
|
{
|
|
if (Inventory.FirstOrDefault(m => m.Name == item?.Name) != null){
|
|
Inventory.Remove(Inventory.FirstOrDefault(m => m.Name == item.Name));
|
|
if ((CurrentHealth + item.HealingAmount) > MaxHealth)
|
|
{
|
|
CurrentHealth = MaxHealth;
|
|
}
|
|
else
|
|
{
|
|
CurrentHealth += item.HealingAmount;
|
|
}
|
|
Console.WriteLine($"Used one {item.Name}. Regained {item.HealingAmount} Health.\n");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"{Name} does not have any of that in their inventory.");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//#####DEBUG METHODS#####//
|
|
|
|
//Display stats about the Player.
|
|
public void DisplayStats(){
|
|
Console.WriteLine($"Player Name: {Name}");
|
|
Console.WriteLine($"Health: {CurrentHealth}/{MaxHealth}");
|
|
Console.WriteLine($"Mana: {CurrentMPoints}/{MaxMPoints}\n");
|
|
Console.WriteLine("Current Inventory: ");
|
|
foreach (var inv in RetrieveInventory())
|
|
{
|
|
Console.WriteLine($"{inv.Key}: {inv.Value}");
|
|
}
|
|
}
|
|
} |