Added Player Framework and some commands

This commit is contained in:
2026-04-06 13:47:06 +02:00
parent 22108bb58d
commit 2fca1281a7
19 changed files with 333 additions and 2 deletions
+5
View File
@@ -15,6 +15,11 @@ namespace TextRPG.Commands
RegisterCommand(new HelpCommand());
RegisterCommand(new ClearCommand());
RegisterCommand(new TimeCommand());
RegisterCommand(new StatusCommand());
RegisterCommand(new InventoryCommand());
RegisterCommand(new TakeCommand());
RegisterCommand(new DropCommand());
RegisterCommand(new HealCommand());
}
+33
View File
@@ -0,0 +1,33 @@
// DropCommand.cs
using System;
using TextRPG.PlayerSystem;
namespace TextRPG.Commands
{
public class DropCommand : Command
{
public override string Name => "drop";
public override string Description => "Removes an item from your inventory.";
public override string Usage => "drop <item_name>";
public override void Execute(string[] args, Action<string> outputCallback)
{
if (args.Length == 0)
{
outputCallback($"Usage: {Usage}");
return;
}
string itemName = string.Join(" ", args);
var item = Player.Instance.GetItem(itemName);
if (item == null)
{
outputCallback($"You don't have '{itemName}'.");
return;
}
Player.Instance.RemoveItem(item);
outputCallback($"You dropped: {itemName}.");
}
}
}
+1
View File
@@ -0,0 +1 @@
uid://bfa36j6ca7bj6
+26
View File
@@ -0,0 +1,26 @@
// HealCommand.cs
using System;
using TextRPG.PlayerSystem;
namespace TextRPG.Commands
{
public class HealCommand : Command
{
public override string Name => "heal";
public override string Description => "Heals the player by a given amount (max 50).";
public override string Usage => "heal <amount>";
public override void Execute(string[] args, Action<string> outputCallback)
{
if (args.Length == 0 || !int.TryParse(args[0], out int amount))
{
outputCallback($"Usage: {Usage}");
return;
}
amount = Math.Min(amount, 50);
Player.Instance.Heal(amount);
outputCallback($"You healed {amount} HP. Current health: {Player.Instance.CurrentHealth}/{Player.Instance.MaxHealth}");
}
}
}
+1
View File
@@ -0,0 +1 @@
uid://crubvxtr4u1ya
+18
View File
@@ -0,0 +1,18 @@
// InventoryCommand.cs
using System;
using TextRPG.PlayerSystem;
namespace TextRPG.Commands
{
public class InventoryCommand : Command
{
public override string Name => "inventory";
public override string Description => "Lists all items in your inventory.";
public override string Usage => "inventory";
public override void Execute(string[] args, Action<string> outputCallback)
{
outputCallback(Player.Instance.GetInventoryString());
}
}
}
+1
View File
@@ -0,0 +1 @@
uid://c2m6vnugsmxgg
+24
View File
@@ -0,0 +1,24 @@
using System;
using TextRPG.PlayerSystem;
namespace TextRPG.Commands
{
public class StatusCommand : Command
{
public override string Name => "status";
public override string Description => "Shows player status (health, attributes, inventory count).";
public override string Usage => "status";
public override void Execute(string[] args, Action<string> outputCallback)
{
// Use the singleton instance directly
var player = Player.Instance;
if (player == null)
{
outputCallback("Player system not initialized.");
return;
}
outputCallback(player.GetStatusString());
}
}
}
+1
View File
@@ -0,0 +1 @@
uid://c2ig5hu00nyql
+28
View File
@@ -0,0 +1,28 @@
// TakeCommand.cs
using System;
using TextRPG.PlayerSystem;
namespace TextRPG.Commands
{
public class TakeCommand : Command
{
public override string Name => "take";
public override string Description => "Picks up an item from the current location.";
public override string Usage => "take <item_name>";
public override void Execute(string[] args, Action<string> outputCallback)
{
if (args.Length == 0)
{
outputCallback($"Usage: {Usage}");
return;
}
string itemName = string.Join(" ", args);
// For demo, create a predefined item. In a real game, you'd fetch from the current room/zone.
var item = new Item(itemName, "A mysterious object.", 10, "misc");
Player.Instance.AddItem(item);
outputCallback($"You picked up: {itemName}.");
}
}
}
+1
View File
@@ -0,0 +1 @@
uid://b6trmclox3caa