-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer_NapCha_API
335 lines (299 loc) · 12 KB
/
Server_NapCha_API
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using Exiled.API.Features;
using HintServiceMeow.Core.Enum;
using HintServiceMeow.Core.Models.Hints;
using HintServiceMeow.Core.Utilities;
using MEC;
using System;
using System.Collections.Generic;
using static HintServiceMeow.Core.Utilities.PlayerDisplay;
using System.Threading;
using System.Linq;
namespace Server_NapCha_API
{
public class Server_NapCha_API
{
// 各阵营的玩家列表
public static List<Player> SCPs = new List<Player>();
public static List<Player> ntf = new List<Player>();
public static List<Player> cs = new List<Player>();
public static List<Player> zl = new List<Player>();
public static List<Player> 无伤害 = new List<Player>();
public static List<Player> 特殊角色列表 = new List<Player>();
/// <summary>
/// 显示一个固定的提示
/// 使用示例:
/// var hint = 提示服务_固定提示hint(player, "你的提示内容");
/// </summary>
public HintServiceMeow.Core.Models.Hints.Hint 提示服务_固定提示hint(Player 玩家, string 内容)
{
var hint = CreateHint(内容, 0, 25, 950, HintAlignment.Center, "gdtshint");
PlayerDisplay.Get(玩家).AddHint(hint); // 添加提示到玩家显示
return hint;
}
/// <summary>
/// 取消显示玩家的提示
/// 示例:取消提示(player);
/// </summary>
public void 取消提示(Player 玩家)
{
// 检查玩家是否为空并记录错误
if (玩家 == null)
{
Log.Error("取消提示失败:玩家对象为空。");
return;
}
// 获取玩家显示并清除提示
PlayerDisplay.Get(玩家)?.ClearHint();
}
/// <summary>
/// 显示一个自定义提示
/// 使用示例:
/// var hint = 提示服务(player, 30, 200, "提示内容", HintAlignment.Center);
/// </summary>
public HintServiceMeow.Core.Models.Hints.Hint 提示服务(Player 玩家, int 大小 = 25, int 高度 = 100, string 内容 = "Server_NapCha_ui_API_FileName_null_text", HintAlignment 位置 = HintAlignment.Left)
{
if (玩家 == null)
{
Log.Error("Server_NapCha_ui_API_FileName 提示服务 玩家为空");
return null;
}
var hint = CreateHint(内容, 0, 大小, 高度, 位置);
PlayerDisplay.Get(玩家).AddHint(hint); // 添加提示到玩家显示
return hint;
}
/// <summary>
/// 显示一个定时提示,指定时间后移除
/// 使用示例:
/// 提示服务0(player, 25, 5, 100, "定时提示内容", HintAlignment.Left);
/// </summary>
public void 提示服务0(Player 玩家, int 大小 = 25, int 时间 = 5, int 高度 = 100, string 内容 = "Server_NapCha_ui_API_FileName_null_text", HintAlignment 位置 = HintAlignment.Left)
{
if (玩家 == null)
{
Log.Error("Server_NapCha_ui_API_FileName 提示服务 玩家为空");
return;
}
var hint = CreateHint(内容, 0, 大小, 高度, 位置);
PlayerDisplay.Get(玩家).AddHint(hint); // 添加提示到玩家显示
// 设置延迟移除提示
Timing.CallDelayed(时间, () => PlayerDisplay.Get(玩家).RemoveHint(hint));
}
// 存储每个玩家的定时器
public static Dictionary<Player, Timer> lastCancelTimer0 = new Dictionary<Player, Timer>();
/// <summary>
/// 显示动态更新的提示
/// 使用示例:
/// var hint = 提示服务1(player, "新提示内容", 8);
/// </summary>
public HintServiceMeow.Core.Models.Hints.AbstractHint 提示服务1(Player player, string text, int 时间 = 5)
{
return HandleDynamicHint(player, text, 时间, lastCancelTimer0);
}
// 存储每个玩家的定时器(第二个提示)
public static Dictionary<Player, Timer> lastCancelTimer1 = new Dictionary<Player, Timer>();
/// <summary>
/// 显示动态更新的提示(带自定义字体大小)
/// 使用示例:
/// var hint = 提示服务2(player, "提示内容", 10, 32);
/// </summary>
public HintServiceMeow.Core.Models.Hints.AbstractHint 提示服务2(Player player, string text, int 时间 = 5, int 字体大小 = 32)
{
return HandleDynamicHint(player, text, 时间, lastCancelTimer1, 字体大小);
}
/// <summary>
/// 更新存在的提示
/// 使用示例:
/// 更新提示(player, existingHint, "更新后的提示内容");
/// </summary>
public HintServiceMeow.Core.Models.Hints.Hint 更新提示(Player 玩家, HintServiceMeow.Core.Models.Hints.Hint existingHint, string newText = "Server_NapCha_ui_API_FileName_null_text")
{
if (existingHint != null)
{
existingHint.Text = newText; // 更新提示文本
return existingHint;
}
Log.Error("Server_NapCha_ui_API_FileName 提示不存在,无法更新");
return null;
}
/// <summary>
/// 设置玩家的阵营
/// 使用示例:
/// 设置阵营(player, PlayerRoles.Team.SCPs);
/// </summary>
public void 设置阵营(Player 玩家, PlayerRoles.Team 阵营 = PlayerRoles.Team.Dead)
{
if (玩家 == null)
{
Log.Error("Server_NapCha_ui_API_FileName 设置阵营 玩家为空");
return;
}
// 获取阵营对应的玩家列表
var teamList = GetTeamList(阵营);
if (teamList != null && !teamList.Contains(玩家))
teamList.Add(玩家); // 添加玩家到相应的阵营列表
}
/// <summary>
/// 清空玩家的阵营信息
/// 使用示例:
/// 清空阵营(player);
/// </summary>
public void 清空阵营(Player 玩家)
{
// 从所有阵营中移除玩家
foreach (var teamList in new List<List<Player>> { SCPs, ntf, cs, zl, 无伤害 })
{
if (teamList.Contains(玩家))
teamList.Remove(玩家);
}
}
/// <summary>
/// 获取回合的持续时间
/// 使用示例:
/// var roundTime = 获取回合时间();
/// </summary>
public System.TimeSpan 获取回合时间() => Round.ElapsedTime;
/// <summary>
/// 设置玩家的血量
/// 使用示例:
/// 设置血量(player, 100);
/// </summary>
public void 设置血量(Player ev, int 血量 = 100)
{
if (ev == null)
{
Log.Error("Server_NapCha_ui_API_FileName 设置血量 玩家为空");
return;
}
// 延迟设置玩家的最大和当前血量
Timing.CallDelayed(0.5f, () =>
{
ev.MaxHealth = 血量;
ev.Health = 血量;
});
}
/// <summary>
/// 获取当前回合人数
/// 使用示例:
/// int playerCount = 获取回合人数();
/// </summary>
public int 获取回合人数() => Player.List.Count;
/// <summary>
/// 获取当前观察者人数
/// 使用示例:
/// int observerCount = 获取观察者人数();
/// </summary>
public int 获取观察者人数() => Player.List.Count(player => player.Role.Type == PlayerRoles.RoleTypeId.Spectator);
/// <summary>
/// 添加特殊角色到列表
/// 使用示例:
/// 添加特殊角色列表(player);
/// </summary>
public void 添加特殊角色列表(Player ev)
{
if (!特殊角色列表.Contains(ev))
特殊角色列表.Add(ev);
}
/// <summary>
/// 从特殊角色列表中移除
/// 使用示例:
/// 移除特殊角色列表(player);
/// </summary>
public void 移除特殊角色列表(Player ev)
{
if (特殊角色列表.Contains(ev))
特殊角色列表.Remove(ev);
}
/// <summary>
/// 检查角色是否在特殊角色列表中
/// 使用示例:
/// bool isSpecial = 检查角色是否在特殊角色列表中(player);
/// </summary>
public bool 检查角色是否在特殊角色列表中(Player ev) => 特殊角色列表.Contains(ev);
/// <summary>
/// 获取 SCP-173 的生命值
/// 使用示例:
/// float health = SCPs173();
/// </summary>
public float SCPs173()
{
foreach (Player player in Player.List)
{
if (player.Role.Type == PlayerRoles.RoleTypeId.Scp173)
return player.Health; // 返回 SCP-173 的生命值
}
return 0; // 如果没有找到 SCP-173,返回 0
}
/// <summary>
/// SCP 身份的恢复方法
/// 使用示例:
/// SCP恢复满盾(player);
/// </summary>
public void SCP恢复满盾(Player ev)
{
// 根据角色类型添加恢复逻辑
}
// 辅助方法:创建提示对象
private HintServiceMeow.Core.Models.Hints.Hint CreateHint(string text, int xCoordinate, int fontSize, int yCoordinate, HintAlignment alignment, string id = null)
{
return new HintServiceMeow.Core.Models.Hints.Hint()
{
Text = text,
XCoordinate = xCoordinate,
FontSize = fontSize,
YCoordinate = yCoordinate,
Alignment = alignment,
Id = id
};
}
// 辅助方法:处理动态提示
private HintServiceMeow.Core.Models.Hints.AbstractHint HandleDynamicHint(Player player, string text, int time, Dictionary<Player, Timer> timerDictionary, int fontSize = 25)
{
PlayerDisplay playerDisplay = PlayerDisplay.Get(player);
var hint = playerDisplay.GetHint("your_hint_id");
// 取消上一个提示的定时器
if (timerDictionary.TryGetValue(player, out var lastCancelTimer))
{
lastCancelTimer.Dispose();
}
if (hint != null)
{
hint.Text = text; // 更新提示文本
}
else
{
hint = CreateHint(text, 0, fontSize, 249, HintAlignment.Center); // 创建新的提示
playerDisplay.AddHint(hint); // 添加到玩家显示
}
// 设置延迟移除提示
lastCancelTimer = new Timer((state) =>
{
playerDisplay.RemoveHint(hint);
}, null, time * 1000, Timeout.Infinite);
// 添加当前玩家的定时器
if (!timerDictionary.ContainsKey(player))
{
timerDictionary.Add(player, lastCancelTimer);
}
return hint; // 返回当前提示对象
}
//辅助方法:获取对应阵营的玩家列表
private List<Player> GetTeamList(PlayerRoles.Team team)
{
switch (team)
{
case PlayerRoles.Team.SCPs:
return SCPs;
case PlayerRoles.Team.FoundationForces:
return ntf;
case PlayerRoles.Team.ChaosInsurgency:
return cs;
case PlayerRoles.Team.OtherAlive:
return zl;
case PlayerRoles.Team.Dead:
return 无伤害;
default:
return null;
}
}
}
}