Skip to content

Commit

Permalink
Merge pull request #236 from 1242509682/master
Browse files Browse the repository at this point in the history
更新:宵禁 v2.4.0 加入对可召怪物的计数要求
  • Loading branch information
Controllerdestiny authored Jun 19, 2024
2 parents 36fea50 + a8d587f commit 471c106
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 55 deletions.
36 changes: 30 additions & 6 deletions GoodNight/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void GnCmd(CommandArgs args)
}
#endregion

#region 修改禁止怪物ID + 修改解禁怪物在线人数
#region 修改禁止怪物ID + 修改解禁怪物在线人数等等
if (args.Parameters.Count == 2)
{
NPC npc;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down
11 changes: 7 additions & 4 deletions GoodNight/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
using System.Collections;
using System.Text;
using TShockAPI;

Expand Down Expand Up @@ -36,9 +35,13 @@ internal class Configuration
Stop = TimeSpan.FromHours(5)
};

[JsonProperty("已击败进度限制(NpcID)", Order = -6)]
public HashSet<int> NpcDie = new HashSet<int>();
[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<int> NpcDead = new HashSet<int>();
[JsonProperty("禁止怪物生成表(NpcID)", Order = -4)]
public HashSet<int> Npcs = new HashSet<int>();

#region 读取与创建配置文件方法
Expand Down
91 changes: 56 additions & 35 deletions GoodNight/Goodnight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -140,55 +137,79 @@ 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;
else if (DateTime.Now.TimeOfDay >= Config.Time.Start && DateTime.Now.TimeOfDay < Config.Time.Stop)
{
if (NoPlr)
{
if (NpcDie)
if (NpcDead)
{
Main.npc[args.NpcId].active = true;
}

else if (Npcs)
else if (NpcList)
{
Main.npc[args.NpcId].active = false;
}
}

else
{
if (Npcs)
Main.npc[args.NpcId].active = true;
if (NpcList)
Main.npc[args.NpcId].active = true;
}
}
}

private Dictionary<int, int> KillCounters = new Dictionary<int, int>();
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
Expand Down
35 changes: 25 additions & 10 deletions GoodNight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

- 作者: Jonesn、羽学
- 出处: 无
- 本插件整合了白名单、宵禁、禁止召唤怪物等插件功能
- 每天指定时间禁止进服或禁止召唤怪物(满足在线人数自动解禁召唤怪物)
- 在规定时间内根据在线人数来判断是否允许召唤未击败的怪物
- 如果超过宵禁时间则不做任何处理,通过NPC死亡事件判断取值【禁止怪物表】里的ID到【允许召唤怪物表】
- 方便下次宵禁时间判断哪些怪物允许在宵禁时间内召唤,避免单人推服务器进度的情况。

## 更新日志

```
v2.4.0
加入了根据击杀《禁止怪物生成表》计数,
写入《允许召唤怪物表》与其相关指令
计数要求则在满足在线人数或不在宵禁时间段
由玩家主动击杀存在《禁止怪物生成表》的怪物自动计入(无需手写)
加个配置项与指令,控制击杀什么怪物ID来重置《允许召唤怪物表》
v2.3.0
加入宵禁时间内可召唤已击败怪物
通过监听怪物死亡事件从禁止怪物表中
Expand Down Expand Up @@ -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 | 重载配置文件 |


Expand All @@ -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,
Expand Down

0 comments on commit 471c106

Please sign in to comment.