Assignment: Extend the Combat System with Equipment Using Entity Framework Core and SOLID Principles
This assignment aims to extend the existing combat system by implementing an Equipment system that includes Weapons and Armor. Using the principles of Entity Framework Core and SOLID, you will create additional entities and integrate them into your ConsoleRPG project. This assignment will build on your previous work with the Player.cs
and Goblin.cs
classes, enhancing the combat system to use these new features.
- Add Equipment Properties: Create a new class,
Equipment
, that will contain properties for bothWeapon
andArmor
. Ensure thePlayer
class has a property forEquipment
. - Integrate Weapon and Armor in Combat:
- Modify the
Attack
method inPlayer
to factor in theWeapon
’s attack power. - Ensure that the
Armor
property reduces the damage the player takes when attacked.
- Modify the
- Entity Configuration: Update setup in
GameContext
so that it supports theEquipment
entity structure. - Migrations: Create and apply migrations to update the database schema.
- Enhance Attack Logic: In the
GameEngine
class, update theAttackCharacter
method to:- Use the player’s
Weapon
attack value when attacking. - Calculate the effect of the player’s
Armor
to reduce incoming damage from the Goblin. - Ensure that the updated logic supports flexible changes in the player’s equipment.
- Use the player’s
- Entity Framework Configuration: Update
GameContext
to manage the new entities.- Ensure relationships are established correctly, using navigation properties where appropriate.
- Set up any necessary one-to-one or one-to-many relationships between
Player
andEquipment
.
Create an abstract Item
class, and derive Weapon
and Armor
classes from it. This will help modularize the game’s inventory system and make combat more extensible.
-
Create an
Item
Abstract Class (10 points)- Define common properties such as
Name
,Value
, andDescription
. - Include an abstract
Use
method to allow custom behavior for different item types.
- Define common properties such as
-
Concrete Classes for
Weapon
andArmor
(10 points)- Weapon Class: Define properties such as
AttackPower
andDurability
. - Armor Class: Define properties like
DefenseRating
andDurability
. - Implement specific behavior for
Use
in each subclass.
- Weapon Class: Define properties such as
-
Modify
Player
andGoblin
to UseItem
Hierarchy (10 points)- Update
Player
to hold anItem
collection, associating specific items (e.g., a sword or shield) for dynamic inventory. - Allow
Goblin
to drop an item upon defeat, or have them interact withPlayer
items in combat.
- Update
-
Update
GameContext
(10 points)- Configure TPH in
GameContext
for theItem
hierarchy using.HasDiscriminator()
. - Ensure relationships between
Player
and their items are set up for many-to-many with an intermediary table if needed.
- Configure TPH in
Task | Points |
---|---|
Player Class Modifications | 20 |
Equipment Integration in Classes | 20 |
GameEngine Modifications | 20 |
GameContext Configuration | 20 |
Stretch Goal | +10 |
Total Possible Points | 100 (+10%) |
-
Connection Strings:
- Set up the connection string in your
appsettings.json
orConfigurationHelper
file. - Use SQL Server connection strings as a reference.
- Set up the connection string in your
-
Migrations:
- To create the initial migration:
dotnet ef migrations add InitialCreate
- To update the database:
dotnet ef database update
- To create the initial migration:
-
Testing:
- Ensure your game runs correctly after implementing the changes.
- Test all functionalities, especially new combat modifications.
Good luck, and enjoy enhancing the ConsoleRPG combat experience!