-
Notifications
You must be signed in to change notification settings - Fork 4
/
ZHIPM.cs
309 lines (274 loc) · 11.9 KB
/
ZHIPM.cs
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
using Microsoft.Xna.Framework;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.Hooks;
namespace ZHIPlayerManager
{
[ApiVersion(2, 1)]
public partial class ZHIPM : TerrariaPlugin
{
public override string Author => "z枳";
public override string Description => "玩家管理,提供修改玩家的任何信息,允许玩家备份,可以回档等操作";
public override string Name => "ZHIPlayerManager";
public override Version Version => new Version(1, 0, 0, 1);
#region 字段或属性
/// <summary>
/// 人物备份数据库
/// </summary>
public static ZplayerDB ZPDataBase { get; set; }
/// <summary>
/// 额外数据库
/// </summary>
public static ZplayerExtraDB ZPExtraDB { get; set; }
/// <summary>
/// 在线玩家的额外数据库的集合
/// </summary>
public static List<ExtraData> edPlayers { get; set; }
/// <summary>
/// 广播颜色
/// </summary>
public readonly static Color broadcastColor = new Color(0, 255, 213);
/// <summary>
/// 计时器,60 Timer = 1 秒
/// </summary>
public static long Timer
{
get;
private set;
}
/// <summary>
/// 清理数据的计时器
/// </summary>
public long cleartime = long.MaxValue;
/// <summary>
/// 记录需要冻结的玩家
/// </summary>
public static List<MessPlayer> frePlayers = new List<MessPlayer>();
/// <summary>
/// 需要记录的被击中的npc
/// </summary>
public static List<StrikeNPC> strikeNPC = new List<StrikeNPC>();
public readonly string noplayer = "该玩家不存在,请重新输入";
public readonly string manyplayer = "该玩家不唯一,请重新输入";
public readonly string offlineplayer = "该玩家不在线,正在查询离线数据";
public static ZhipmConfig config = new ZhipmConfig();
/// <summary>
/// 记录世界吞噬者的数据
/// </summary>
public Dictionary<int, int> Eaterworld = new Dictionary<int, int>();
/// <summary>
/// 记录毁灭者的数据
/// </summary>
public Dictionary<int, int> Destroyer = new Dictionary<int, int>();
/// <summary>
/// 记录血肉墙的数据
/// </summary>
public Dictionary<int, int> FleshWall = new Dictionary<int, int>();
#endregion
public ZHIPM(Main game) : base(game) { }
public override void Initialize()
{
Timer = 0L;
config = ZhipmConfig.LoadConfigFile();
ZPDataBase = new ZplayerDB(TShock.DB);
ZPExtraDB = new ZplayerExtraDB(TShock.DB);
edPlayers = new List<ExtraData>();
//用来对玩家进行额外数据库更新
ServerApi.Hooks.GameUpdate.Register(this, OnGameUpdate);
//限制玩家名字类型
ServerApi.Hooks.ServerJoin.Register(this, OnServerJoin);
//同步玩家的额外数据库
ServerApi.Hooks.ServerLeave.Register(this, OnServerLeave);
//用于统计击杀生物数,击杀别的等等
ServerApi.Hooks.NpcStrike.Register(this, OnNpcStrike);
//用于统计击杀生物数,击杀别的等等
ServerApi.Hooks.NpcKilled.Register(this, OnNPCKilled);
//记录死亡次数
GetDataHandlers.PlayerSpawn.Register(OnSpawn);
GetDataHandlers.PlayerHP.Register(OnHPChange);
//配置文件的更新
GeneralHooks.ReloadEvent += OnReload;
#region 指令
Commands.ChatCommands.Add(new Command("", Help, "zhelp")
{
HelpText = "输入 /zhelp 来查看指令帮助"
});
Commands.ChatCommands.Add(new Command("zhipm.save", MySSCSave, "zsave")
{
HelpText = "输入 /zsave 来备份自己的人物存档"
});
Commands.ChatCommands.Add(new Command("zhipm.save", MySSCSaveAuto, "zsaveauto")
{
HelpText = "输入 /zsaveauto [minute] 来每隔 minute 分钟自动备份自己的人物存档,当 minute 为 0 时关闭该功能"
});
Commands.ChatCommands.Add(new Command("zhipm.save", ViewMySSCSave, "zvisa")
{
HelpText = "输入 /zvisa [num] 来查看自己的第几个人物备份"
});
Commands.ChatCommands.Add(new Command("zhipm.back", MySSCBack, "zback")
{
HelpText = "输入 /zback [name] 来读取该玩家的人物存档\n输入 /zback [name] [num] 来读取该玩家的第几个人物存档"
});
Commands.ChatCommands.Add(new Command("zhipm.clone", SSCClone, "zclone")
{
HelpText = "输入 /zclone [name1] [name2] 将玩家1的人物数据复制给玩家2\n输入 /zclone [name] 将该玩家的人物数据复制给自己"
});
Commands.ChatCommands.Add(new Command("zhipm.modify", SSCModify, "zmodify")
{
HelpText = "输入 /zmodify help 查看修改玩家数据的指令帮助"
});
Commands.ChatCommands.Add(new Command("zhipm.out", ZhiExportPlayer, "zout")
{
HelpText = "输入 /zout [name] 来导出该玩家的人物存档\n输入 /zout all 来导出所有人物的存档"
});
Commands.ChatCommands.Add(new Command("zhipm.sort", ZhiSortPlayer, "zsort")
{
HelpText = "输入 /zsort help 来查看排序系列指令帮助"
});
Commands.ChatCommands.Add(new Command("", HideTips, "zhide")
{
HelpText = "输入 /zhide kill 来取消 kill + 1 的显示,再次使用启用显示\n输入 /zhide point 来取消 + 1 $ 的显示,再次使用启用显示"
});
Commands.ChatCommands.Add(new Command("zhipm.clear", Clear, "zclear")
{
HelpText = "输入 /zclear useless 来清理世界的掉落物品,非城镇或BossNPC,和无用射弹\n输入 /zclear buff [name] 来清理该玩家的所有Buff\n输入 /zclear buff all 来清理所有玩家所有Buff"
});
Commands.ChatCommands.Add(new Command("zhipm.freeze", ZFreeze, "zfre")
{
HelpText = "输入 /zfre [name] 来冻结该玩家"
});
Commands.ChatCommands.Add(new Command("zhipm.freeze", ZUnFreeze, "zunfre")
{
HelpText = "输入 /zunfre [name] 来解冻该玩家\n输入 /zunfre all 来解冻所有玩家"
});
Commands.ChatCommands.Add(new Command("zhipm.reset", ZResetPlayerDB, "zresetdb")
{
HelpText = "输入 /zresetdb [name] 来清理该玩家的备份数据\n输入 /zresetdb all 来清理所有玩家的备份数据"
});
Commands.ChatCommands.Add(new Command("zhipm.reset", ZResetPlayerEX, "zresetex")
{
HelpText = "输入 /zresetex [name] 来清理该玩家的额外数据\n输入 /zresetex all 来清理所有玩家的额外数据"
});
Commands.ChatCommands.Add(new Command("zhipm.reset", ZResetPlayer, "zreset")
{
HelpText = "输入 /zreset [name] 来清理该玩家的人物数据\n输入 /zreset all 来清理所有玩家的人物数据"
});
Commands.ChatCommands.Add(new Command("zhipm.reset", ZResetPlayerAll, "zresetallplayers")
{
HelpText = "输入 /zresetallplayers 来清理所有玩家的所有数据"
});
Commands.ChatCommands.Add(new Command("zhipm.vi", ViewInvent, "vi")
{
HelpText = "输入 /vi [name] 来查看该玩家的库存"
});
Commands.ChatCommands.Add(new Command("zhipm.vi", ViewInventDisorder, "vid")
{
HelpText = "输入 /vid [name] 来查看该玩家的库存,不分类"
});
Commands.ChatCommands.Add(new Command("zhipm.vs", ViewState, "vs")
{
HelpText = "输入 /vs [name] 来查看该玩家的状态"
});
Commands.ChatCommands.Add(new Command("zhipm.ban", SuperBan, "zban")
{
HelpText = "输入 /zban add [name] [reason] 来封禁无论是否在线的玩家,reason 可不填"
});
#endregion
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
ServerApi.Hooks.GameUpdate.Deregister(this, OnGameUpdate);
ServerApi.Hooks.ServerJoin.Deregister(this, OnServerJoin);
ServerApi.Hooks.ServerLeave.Deregister(this, OnServerLeave);
ServerApi.Hooks.NpcStrike.Deregister(this, OnNpcStrike);
ServerApi.Hooks.NpcKilled.Deregister(this, OnNPCKilled);
GeneralHooks.ReloadEvent -= OnReload;
}
base.Dispose(disposing);
}
/// <summary>
/// 用来记录被冻结玩家数据的类
/// </summary>
public class MessPlayer
{
public int account;
public string name;
public string uuid;
public Vector2 pos;
public long clock;
/// <summary>
/// 只接受来自 user 的knowIPs,不是单个ip
/// </summary>
public string IPs;
public MessPlayer()
{
account = 0;
name = "";
uuid = "";
IPs = "";
pos = new Vector2(Main.spawnTileX * 16, Main.spawnTileY * 16);
clock = Timer;
}
public MessPlayer(int account, string name, string uuid, string IPs, Vector2 pos)
{
this.name = name;
this.uuid = uuid;
this.account = account;
this.IPs = IPs;
this.clock = Timer;
if(pos == Vector2.Zero)
this.pos = new Vector2(0, 999999);
else
this.pos = pos;
}
}
/// <summary>
/// 用来记录被玩家击中的npc
/// </summary>
public class StrikeNPC
{
/// <summary>
/// 索引
/// </summary>
public int index;
/// <summary>
/// id
/// </summary>
public int id;
/// <summary>
/// 名字
/// </summary>
public string name = string.Empty;
/// <summary>
/// 是否为boss
/// </summary>
public bool isBoss = false;
/// <summary>
/// 字典,用于记录 <击中他的玩家的id -> 该玩家造成的总伤害>
/// </summary>
public Dictionary<int, int> playerAndDamage = new Dictionary<int, int>();
/// <summary>
/// 受到的总伤害
/// </summary>
public int AllDamage = 0;
/// <summary>
/// 价值
/// </summary>
public float value = 0f;
public StrikeNPC() { }
public StrikeNPC(int index, int id, string name, bool isBoss, Dictionary<int, int> playerAndDamage, int allDamage, float value)
{
this.index = index;
this.id = id;
this.name = name;
this.isBoss = isBoss;
this.playerAndDamage = playerAndDamage;
AllDamage = allDamage;
this.value = value;
}
}
}
}