-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTpCommand.cs
More file actions
67 lines (57 loc) · 2.12 KB
/
Copy pathTpCommand.cs
File metadata and controls
67 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Linq;
using NetSimplifiedExample.Packets;
using Terraria;
using Terraria.ModLoader;
namespace NetSimplifiedExample.Commands;
// 发送请求:/rtp [玩家名字]
// 接受请求:/rtp accept
// 拒绝请求:/rtp reject [拒绝理由]
// 作范例用,没有考虑玩家就叫accept/reject的情况,没有考虑玩家同时收到多个请求的情况
public class TpCommand : ModCommand
{
public static int PendingRequestTarget = -1; // 这个变量用来存储当前正在等待接受/拒绝的请求的目标玩家的whoAmI
public override void Action(CommandCaller caller, string input, string[] args) {
if (args.Length < 1)
{
caller.Reply("应该有至少一个参数");
return;
}
if (args[0] == "accept") {
if (PendingRequestTarget is -1) {
caller.Reply("没有待处理的传送请求");
return;
}
TpReplyPacket.Get(PendingRequestTarget, true).Send();
PendingRequestTarget = -1;
return;
}
if (args[0] == "reject") {
if (PendingRequestTarget is -1) {
caller.Reply("没有待处理的传送请求");
return;
}
string? reason = args.Length >= 2 ? args[1] : null;
TpReplyPacket.Get(PendingRequestTarget, false, reason).Send();
PendingRequestTarget = -1;
return;
}
Player plr = null;
foreach (var player in Main.ActivePlayers) {
if (!player.name.Equals(args[0], StringComparison.OrdinalIgnoreCase)) continue;
plr = player;
break;
}
if (plr == null) {
caller.Reply($"没有找到这个玩家:{args[0]}");
return;
}
if (plr.whoAmI == Main.myPlayer) {
caller.Reply("你不能传送到自己");
return;
}
TpRequestPacket.Get(plr.whoAmI).Send();
}
public override string Command => "rtp"; // request_teleport
public override CommandType Type => CommandType.Chat;
}