From 17e643bb24b2eb59fb312a520fd08e3a0c7f7d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BE=BD=E5=AD=A6?= <1242509682@qq.com> Date: Wed, 19 Jun 2024 19:22:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E5=AE=B5=E7=A6=81?= =?UTF-8?q?=20v2.4.0=20=E5=8A=A0=E5=85=A5=E5=AF=B9=E5=8F=AF=E5=8F=AC?= =?UTF-8?q?=E6=80=AA=E7=89=A9=E7=9A=84=E8=AE=A1=E6=95=B0=E8=A6=81=E6=B1=82?= =?UTF-8?q?=EF=BC=88=E8=87=AA=E5=8A=A8=E5=86=99=E5=85=A5=EF=BC=89=E4=B8=8E?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E9=87=8D=E7=BD=AE=E5=8F=AF=E5=8F=AC=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=80=AA=E7=89=A9ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoodNight/Commands.cs | 36 ++++++++++++--- GoodNight/Configuration.cs | 11 +++-- GoodNight/Goodnight.cs | 91 +++++++++++++++++++++++--------------- GoodNight/README.md | 35 ++++++++++----- 4 files changed, 118 insertions(+), 55 deletions(-) diff --git a/GoodNight/Commands.cs b/GoodNight/Commands.cs index 2b0955d8..08f605ac 100644 --- a/GoodNight/Commands.cs +++ b/GoodNight/Commands.cs @@ -52,7 +52,7 @@ public static void GnCmd(CommandArgs args) } #endregion - #region 修改禁止怪物ID + 修改解禁怪物在线人数 + #region 修改禁止怪物ID + 修改解禁怪物在线人数等等 if (args.Parameters.Count == 2) { NPC npc; @@ -112,6 +112,28 @@ public static void GnCmd(CommandArgs args) break; } + case "boss": + { + if (int.TryParse(args.Parameters[1], out int num)) + { + Goodnight.Config.DeadCount = num; + Goodnight.Config.Write(); + args.Player.SendSuccessMessage("已成功将记录进度击杀次数设置为: {0} 次!", npc.netID); + } + break; + } + + case "reset": + { + if (int.TryParse(args.Parameters[1], out int num)) + { + Goodnight.Config.ResetNpcDead = num; + Goodnight.Config.Write(); + args.Player.SendSuccessMessage("已设置重置允许召唤表的怪物ID为: {0} !", npc.netID); + } + break; + } + default: { HelpCmd(args.Player); @@ -205,11 +227,13 @@ private static void HelpCmd(TSPlayer player) "/gn on --开启或关闭宵禁功能\n" + "/gn kick --开启或关闭断连功能\n" + "/gn time start 或 stop 23:59:59 --设置宵禁开启结束时间\n" + - "/gn add NPC名字 或 ID --添加指定禁止召唤怪物\n" + - "/gn del NPC名字 或 ID --删除指定禁止召唤怪物\n" + - "/gn list --列出禁止怪物表\n" + - "/gn plr 人数 --设置宵禁时间内解禁怪物的在线人数\n" + - "/gn plr add 玩家名字 --添加指定玩家到豁免名单\n" + + "/gn add NPC名字 或 ID --添加《禁止怪物生成表》的指定怪物\n" + + "/gn del NPC名字 或 ID --删除《禁止怪物生成表》的指定怪物\n" + + "/gn list --列出《禁止怪物生成表》\n" + + "/gn boss 次数 --设置加入《允许召唤怪物表》击杀要求次数\n" + + "/gn reset ID --设置重置《允许召唤怪物表》的怪物ID\n" + + "/gn plr 人数 --设置宵禁时段无视《禁止怪物生成表》在线人数\n" + + "/gn plr add 玩家名字 --添加指定玩家到断连豁免名单\n" + "/gn plr del 玩家名字 --把指定玩家从豁免名单移除\n" + "/reload --重载宵禁配置文件\n"); } diff --git a/GoodNight/Configuration.cs b/GoodNight/Configuration.cs index b229b397..1a369709 100644 --- a/GoodNight/Configuration.cs +++ b/GoodNight/Configuration.cs @@ -1,5 +1,4 @@ using Newtonsoft.Json; -using System.Collections; using System.Text; using TShockAPI; @@ -36,9 +35,13 @@ internal class Configuration Stop = TimeSpan.FromHours(5) }; - [JsonProperty("已击败进度限制(NpcID)", Order = -6)] - public HashSet NpcDie = new HashSet(); - [JsonProperty("禁止怪物生成表(NpcID)", Order = -5)] + [JsonProperty("击杀多少次开始记录进度", Order = -6)] + public int DeadCount { get; set; } = 2; + [JsonProperty("击败什么重置允许召唤怪物表", Order = -6)] + public int ResetNpcDead { get; set; } = 398; + [JsonProperty("允许召唤怪物表(自动计数)", Order = -5)] + public HashSet NpcDead = new HashSet(); + [JsonProperty("禁止怪物生成表(NpcID)", Order = -4)] public HashSet Npcs = new HashSet(); #region 读取与创建配置文件方法 diff --git a/GoodNight/Goodnight.cs b/GoodNight/Goodnight.cs index 0d4c6ce1..3fb52b64 100644 --- a/GoodNight/Goodnight.cs +++ b/GoodNight/Goodnight.cs @@ -2,8 +2,8 @@ using TerrariaApi.Server; using TShockAPI; using TShockAPI.Hooks; +using Microsoft.Xna.Framework; using static TShockAPI.GetDataHandlers; -using Terraria.ID; namespace Goodnight { @@ -13,7 +13,7 @@ public class Goodnight : TerrariaPlugin #region 变量与插件信息 public override string Name => "宵禁"; public override string Author => "Jonesn 羽学"; - public override Version Version => new Version(2, 3, 0); + public override Version Version => new Version(2, 4, 0); public override string Description => "设置服务器无法进入或禁止生成怪物的时段"; internal static Configuration Config; #endregion @@ -97,40 +97,37 @@ private void NewProj(object sender, NewProjectileEventArgs e) private void OnSpawn(NpcSpawnEventArgs args) { int PlayerCount = TShock.Utils.GetActivePlayerCount(); - bool Npcs = Config.Npcs.Contains(Main.npc[args.NpcId].netID); - bool NpcDie = Config.NpcDie.Contains(Main.npc[args.NpcId].netID); + bool NpcList = Config.Npcs.Contains(Main.npc[args.NpcId].netID); + bool NpcDead = Config.NpcDead.Contains(Main.npc[args.NpcId].netID); bool NoPlr = PlayerCount < Config.MaxPlayers && Config.MaxPlayers > 0; - + var NpcListInfo = string.Join(", ", Config.NpcDead.Select(x => TShock.Utils.GetNPCById(x)?.FullName + $"({x})")); if (args.Handled || !Config.Enabled) return; else if (DateTime.Now.TimeOfDay >= Config.Time.Start && DateTime.Now.TimeOfDay < Config.Time.Stop) { if (NoPlr) { - if (NpcDie) + if (NpcDead) { args.Handled = false; Main.npc[args.NpcId].active = true; - TShock.Utils.Broadcast($"允许召唤已击败的怪物为:" - + string.Join(", ", Config.NpcDie.Select - (x => TShock.Utils.GetNPCById(x)?.FullName + "({0})".SFormat(x))), - Microsoft.Xna.Framework.Color.AntiqueWhite); + TShock.Utils.Broadcast($"允许召唤的已击败怪物为:\n[c/6EABE9:{NpcListInfo}]",Color.AntiqueWhite); } - else if (Npcs) + else if (NpcList) { args.Handled = true; Main.npc[args.NpcId].active = false; TShock.Utils.Broadcast($"【宵禁】当前服务器处于维护时间\n" + $"在线人数少于[c/FF3A4B:{Config.MaxPlayers}人]或该怪物[c/338AE1:不允许召唤]\n" + - $"禁止召唤怪物时间: " + - $"[c/DF95EC:{Config.Time.Start}] — [c/FF9187:{Config.Time.Stop}]", Microsoft.Xna.Framework.Color.AntiqueWhite); + $"禁止召唤怪物时段: " + + $"[c/DF95EC:{Config.Time.Start}] — [c/FF9187:{Config.Time.Stop}]", Color.AntiqueWhite); } } else { - if (Npcs) + if (NpcList) args.Handled = false; Main.npc[args.NpcId].active = true; } @@ -140,8 +137,8 @@ private void OnSpawn(NpcSpawnEventArgs args) private void OnTransform(NpcTransformationEventArgs args) { int PlayerCount = TShock.Utils.GetActivePlayerCount(); - bool NpcDie = Config.NpcDie.Contains(Main.npc[args.NpcId].netID); - bool Npcs = Config.Npcs.Contains(Main.npc[args.NpcId].netID); + bool NpcDead = Config.NpcDead.Contains(Main.npc[args.NpcId].netID); + bool NpcList = Config.Npcs.Contains(Main.npc[args.NpcId].netID); bool NoPlr = PlayerCount <= Config.MaxPlayers && Config.MaxPlayers > 0; if (args.Handled || !Config.Enabled) return; @@ -149,12 +146,12 @@ private void OnTransform(NpcTransformationEventArgs args) { if (NoPlr) { - if (NpcDie) + if (NpcDead) { Main.npc[args.NpcId].active = true; } - else if (Npcs) + else if (NpcList) { Main.npc[args.NpcId].active = false; } @@ -162,33 +159,57 @@ private void OnTransform(NpcTransformationEventArgs args) else { - if (Npcs) - Main.npc[args.NpcId].active = true; + if (NpcList) + Main.npc[args.NpcId].active = true; } } } + private Dictionary KillCounters = new Dictionary(); private void OnNPCKilled(NpcKilledEventArgs args) { - int killNpc = args.npc.netID; + if (!Config.Enabled || args.npc == null) return; - if (killNpc == 398) - { - Config.NpcDie.Clear(); - Config.Write(); - TShock.Utils.Broadcast($"玩家已击败了月亮领主,清空已击败进度记录", Microsoft.Xna.Framework.Color.AntiqueWhite); - } - else if (Config.Npcs.Contains(killNpc)) + int KillNpc = args.npc.netID; + string npcName = TShock.Utils.GetNPCById(KillNpc)?.FullName ?? "未知NPC"; + + if (Config.Npcs.Contains(KillNpc)) { - if (!Config.NpcDie.Contains(killNpc)) + if (!KillCounters.ContainsKey(KillNpc)) + { + KillCounters[KillNpc] = 1; + } + else + { + KillCounters[KillNpc]++; + } + + if (!Config.NpcDead.Contains(KillNpc)) { - Config.NpcDie.Add(killNpc); - Config.Write(); - TShock.Utils.Broadcast($"NPC: {killNpc} 已被击败并记录可召唤怪物中:\n" - + string.Join(", ", Config.NpcDie.Select - (x => TShock.Utils.GetNPCById(x)?.FullName + "({0})".SFormat(x))), - Microsoft.Xna.Framework.Color.AntiqueWhite); + TShock.Utils.Broadcast($"【宵禁】击败NPC【[c/FF9187:{npcName}({KillNpc})]】\n记录击败进度要求次数:[c/FF3A4B:{KillCounters[KillNpc]}]/[c/E2FA75:{Config.DeadCount}次]", Color.AntiqueWhite); } + + if (KillCounters[KillNpc] >= Config.DeadCount) + { + if (!Config.NpcDead.Contains(KillNpc)) + { + Config.NpcDead.Add(KillNpc); + Config.Write(); + var NpcListInfo = string.Join(", ", Config.NpcDead.Select(x => TShock.Utils.GetNPCById(x)?.FullName + $"({x})")); + TShock.Utils.Broadcast($"因击杀次数达到[c/E2FA75:{Config.DeadCount}次] 将不再播报计数\n" + + $"已记录进宵禁时段允许召唤怪物表:\n[c/6EABE9:{NpcListInfo}]\n" + + $"宵禁时段:[c/DF95EC:{Config.Time.Start}] — [c/FF9187:{Config.Time.Stop}]", Color.AntiqueWhite); + KillCounters[KillNpc] = 0; + } + } + } + + else if (KillNpc == Config.ResetNpcDead) + { + Config.NpcDead.Clear(); + KillCounters.Clear(); + Config.Write(); + TShock.Utils.Broadcast($"【宵禁】玩家已击败:[c/FF9187:{npcName}({KillNpc})],现清空宵禁时段中的允许召唤怪物表", Color.AntiqueWhite); } } #endregion diff --git a/GoodNight/README.md b/GoodNight/README.md index cec242ce..d2af6695 100644 --- a/GoodNight/README.md +++ b/GoodNight/README.md @@ -2,11 +2,22 @@ - 作者: Jonesn、羽学 - 出处: 无 +- 本插件整合了白名单、宵禁、禁止召唤怪物等插件功能 - 每天指定时间禁止进服或禁止召唤怪物(满足在线人数自动解禁召唤怪物) +- 在规定时间内根据在线人数来判断是否允许召唤未击败的怪物 +- 如果超过宵禁时间则不做任何处理,通过NPC死亡事件判断取值【禁止怪物表】里的ID到【允许召唤怪物表】 +- 方便下次宵禁时间判断哪些怪物允许在宵禁时间内召唤,避免单人推服务器进度的情况。 ## 更新日志 ``` +v2.4.0 +加入了根据击杀《禁止怪物生成表》计数, +写入《允许召唤怪物表》与其相关指令 +计数要求则在满足在线人数或不在宵禁时间段 +由玩家主动击杀存在《禁止怪物生成表》的怪物自动计入(无需手写) +加个配置项与指令,控制击杀什么怪物ID来重置《允许召唤怪物表》 + v2.3.0 加入宵禁时间内可召唤已击败怪物 通过监听怪物死亡事件从禁止怪物表中 @@ -43,13 +54,15 @@ v2.0.0 | /gn | /宵禁 | goodnight.admin | 查看宵禁指令菜单 | | /gn on | 无 | goodnight.admin | 开启或关闭宵禁功能 | | /gn kick | 无 | goodnight.admin | 开启或关闭断连功能 | -| /gn time start & stop 23:59:59 | 无 | goodnight.admin | 设置宵禁开启结束时间 | -| /gn list | 无 | goodnight.admin | 列出禁止怪物表 | -| /gn add 怪名 或 id| 无 | goodnight.admin | 添加指定禁止召唤怪物 | -| /gn del 怪名 或 id| 无 | goodnight.admin | 删除指定禁止召唤怪物 | -| /gn plr 人数 | 无 | goodnight.admin | 设置宵禁时间内解禁怪物的在线人数 | -| /gn plr add 玩家名 | 无 | goodnight.admin | 添加指定玩家到豁免名单 | -| /gn plr del 玩家名 | 无 | goodnight.admin | 把指定玩家从豁免名单移除 | +| /gn time start & stop 23:59:59 | /gn time set & end | goodnight.admin | 设置宵禁开启结束时间 | +| /gn list | 无 | goodnight.admin | 列出《禁止怪物生成表》 | +| /gn add 怪名 或 id| 无 | goodnight.admin | 添加《禁止怪物生成表》的指定怪物 | +| /gn del 怪名 或 id| 无 | goodnight.admin | 删除《禁止怪物生成表》的指定怪物 | +| /gn boss 次数 | 无 | goodnight.admin | 设置加入《允许召唤怪物表》击杀要求次数 | +| /gn reset 怪物ID | 无 | goodnight.admin | 设置重置《允许召唤怪物表》的怪物ID | +| /gn plr 人数 | 无 | goodnight.admin | 设置宵禁时段无视《禁止怪物生成表》在线人数 | +| /gn plr add 玩家名 | 无 | goodnight.admin | 添加指定玩家到断连豁免名单 | +| /gn plr del 玩家名 | 无 | goodnight.admin | 把指定玩家从断连豁免名单移除 | | /reload | 无 | tshock.cfg.reload | 重载配置文件 | @@ -65,14 +78,16 @@ v2.0.0 "玩家进服拦截消息": "当前为宵禁时间,无法加入游戏。", "踢出玩家断连消息": "到点了,晚安", "断连豁免玩家": [ - "羽学" + "羽学" ], "禁怪少于人数(设1为关闭禁怪)": 2, "宵禁时间设置(禁怪/断连)": { "Start": "00:00:00", - "Stop": "05:00:00" + "Stop": "06:59:59" }, - "已击败进度限制(NpcID)": [], + "击杀多少次开始记录进度": 3, + "击败什么重置允许召唤怪物表": 398, + "允许召唤怪物表(自动计数)": [], "禁止怪物生成表(NpcID)": [ 4, 13,