Skip to content

Commit f869da2

Browse files
Add commands to harvest.
1 parent dbb2868 commit f869da2

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using OpenRP.Framework.Features.Commands.Attributes;
2+
using OpenRP.Framework.Shared.Chat.Enums;
3+
using OpenRP.Framework.Shared;
4+
using SampSharp.Entities.SAMP;
5+
using SampSharp.Entities;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using OpenRP.Framework.Features.Harvestables.Entities;
12+
using OpenRP.Framework.Shared.Chat.Extensions;
13+
14+
namespace OpenRP.Framework.Features.Harvestables.Commands
15+
{
16+
public class HarvestCommands : ISystem
17+
{
18+
private readonly IEnumerable<IHarvestableModel> _harvestableResources;
19+
20+
public HarvestCommands(IEnumerable<IHarvestableModel> harvestableResources)
21+
{
22+
_harvestableResources = harvestableResources;
23+
}
24+
25+
[ServerCommand(PermissionGroups = new string[] { "Default" },
26+
Description = "Harvest a resource.",
27+
CommandGroups = new string[] { "Gathering" })]
28+
public void Harvest(Player player, string resource)
29+
{
30+
// Look for a harvestable provider that matches the resource name.
31+
var harvestable = _harvestableResources.FirstOrDefault(r =>
32+
r.ResourceName.Equals(resource, StringComparison.OrdinalIgnoreCase));
33+
34+
if (harvestable != null)
35+
{
36+
// Delegate to the resource's own harvest logic.
37+
harvestable.BeginHarvest(player);
38+
}
39+
else
40+
{
41+
player.SendPlayerInfoMessage(PlayerInfoMessageType.ERROR, $"No harvestable resource found for '{resource}'.");
42+
}
43+
}
44+
45+
[ServerCommand(PermissionGroups = new string[] { "Default" },
46+
Description = "Harvest a resource.",
47+
CommandGroups = new string[] { "Gathering" })]
48+
public void Harvest(Player player)
49+
{
50+
IEnumerable<string> harvestable = _harvestableResources.Select(i => i.ResourceName);
51+
string options = string.Join($" {ChatColor.Yellow}OR{ChatColor.White} ", harvestable);
52+
player.SendPlayerInfoMessage(PlayerInfoMessageType.SYNTAX, $"/harvest [{options}]");
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)