feat: implement claimlink link
This commit is contained in:
@@ -57,8 +57,8 @@ public static class ClaimLinkChatCommand
|
||||
new(new[] { "new", "n" }, "Promote a group you own into a claim link (enters pending state).",
|
||||
new ICommandArgumentParser[] { p.Word("groupname") }, true, New),
|
||||
|
||||
new(new[] { "link", "l" }, "Link a claim you own into the pending or committed claim link.",
|
||||
new ICommandArgumentParser[] { p.Word("claim") }, true, Link),
|
||||
new(new[] { "link", "l" }, "Link a claim you own into a claim link.",
|
||||
new ICommandArgumentParser[] { p.Word("groupname"), p.IntRange("claim", 0, 999) }, true, Link),
|
||||
|
||||
new(new[] { "confirm", "c" }, "Commit your pending claim link.",
|
||||
Array.Empty<ICommandArgumentParser>(), true, Confirm),
|
||||
@@ -130,7 +130,43 @@ public static class ClaimLinkChatCommand
|
||||
ClaimLinkModSystem.Registry.Add(new ClaimLink { GroupId = group.Uid });
|
||||
return TextCommandResult.Success($"'{groupName}' is now a claim link.");
|
||||
}
|
||||
public static TextCommandResult Link(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink link");
|
||||
public static TextCommandResult Link(TextCommandCallingArgs args)
|
||||
{
|
||||
string groupName = (string)args[0];
|
||||
int claimIndex = (int)args[1];
|
||||
|
||||
PlayerGroup? group = ClaimLinkModSystem.Groups.GetPlayerGroupByName(groupName);
|
||||
if (group == null)
|
||||
return TextCommandResult.Error($"No group named '{groupName}' exists.");
|
||||
|
||||
ClaimLink? link = ClaimLinkModSystem.Registry.Get(group.Uid);
|
||||
if (link == null)
|
||||
return TextCommandResult.Error($"'{groupName}' is not a claim link.");
|
||||
|
||||
IPlayer player = args.Caller.Player;
|
||||
if (player.GetGroup(group.Uid) == null)
|
||||
return TextCommandResult.Error($"You are not a member of '{groupName}'.");
|
||||
|
||||
string playerUid = player.PlayerUID;
|
||||
|
||||
if (!ClaimLinkModSystem.TryResolveOwnedClaim(playerUid, claimIndex, out _, out _))
|
||||
return TextCommandResult.Error("You do not own a claim with that index.");
|
||||
|
||||
if (ClaimLinkModSystem.Registry.IsClaimLinked(playerUid, claimIndex))
|
||||
return TextCommandResult.Error("That claim is already part of a claim link.");
|
||||
|
||||
ClaimLinkMember? member = link.Members.Find(m => m.OwnerPlayerUid == playerUid);
|
||||
if (member == null)
|
||||
{
|
||||
member = new ClaimLinkMember { OwnerPlayerUid = playerUid };
|
||||
link.Members.Add(member);
|
||||
}
|
||||
|
||||
member.LocalClaimIndices.Add(claimIndex);
|
||||
ClaimLinkModSystem.Registry.Save();
|
||||
|
||||
return TextCommandResult.Success($"Linked claim {claimIndex} into '{groupName}'.");
|
||||
}
|
||||
public static TextCommandResult Confirm(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink confirm");
|
||||
public static TextCommandResult Cancel(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink cancel");
|
||||
public static TextCommandResult Unlink(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink unlink");
|
||||
|
||||
Reference in New Issue
Block a user