Skip to content

Commit

Permalink
顺便更点私货
Browse files Browse the repository at this point in the history
  • Loading branch information
Controllerdestiny committed Jun 19, 2024
1 parent 2061862 commit 3231998
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 56 deletions.
26 changes: 0 additions & 26 deletions ServerTools/ClearPlayersItem.cs

This file was deleted.

35 changes: 5 additions & 30 deletions ServerTools/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Microsoft.Xna.Framework;
using MonoMod.RuntimeDetour;
using Newtonsoft.Json;
using NuGet.Configuration;
using NuGet.Protocol.Plugins;
using System.Linq;
using Terraria.DataStructures;
using Terraria;
using Terraria.GameContent.Creative;
using TerrariaApi.Server;
Expand All @@ -22,7 +18,7 @@ public partial class Plugin : TerrariaPlugin

public override string Name => "ServerTools";// 插件名字

public override Version Version => new(1, 1, 7, 0);// 插件版本
public override Version Version => new(1, 1, 7, 1);// 插件版本

private static Config Config = new();

Expand All @@ -38,8 +34,6 @@ public partial class Plugin : TerrariaPlugin

public static Hook CmdHook;

private static ClearPlayersItem clear = new();

public Plugin(Main game) : base(game)
{

Expand Down Expand Up @@ -112,30 +106,11 @@ private void OnUpdate(object? sender, GetDataHandlers.PlayerUpdateEventArgs e)
e.Player.SetBuff(156, 180, true);
TShock.Utils.Broadcast($"[ServerTools] 玩家 [{e.Player.Name}] 因多饰品被冻结3秒,自动施行清理多饰品装备[i:{keepArmor.netID}]", Color.DarkRed);
}
if (ArmorGroup.Any() && TimerCount % 20 == 0)
clear.ClearItem(ArmorGroup.ToArray(), e.Player);

if (Config.KeepArmor2 && !Main.hardMode) { Clear7Item(e.Player); }
}
if (ArmorGroup.Any())
Utils.ClearItem(ArmorGroup.ToArray(), e.Player);

private static void Clear7Item(TSPlayer args)
{
if (!args.TPlayer.armor[8].IsAir && TimerCount % 20 == 0)
{
Item i = args.TPlayer.armor[8];
GiveItem(args, i.type, i.stack, i.prefix);
args.TPlayer.armor[8].TurnToAir();
args.SendData(PacketTypes.PlayerSlot, "", args.Index, Terraria.ID.PlayerItemSlotID.Armor0 + 8);
TShock.Utils.Broadcast($"[ServerTools] 世界未开启困难模式,禁止玩家 [{args.Name}]使用恶魔心饰品栏", Color.DarkRed);
}
}

private static void GiveItem(TSPlayer p, int type, int stack, int prefix = 0)
{
int num = Item.NewItem(new EntitySource_DebugCommand(), (int)p.TPlayer.Center.X, (int)p.TPlayer.Center.Y, p.TPlayer.width, p.TPlayer.height, type, stack, true, prefix, true, false);
Main.item[num].playerIndexTheItemIsReservedFor = p.Index;
p.SendData(PacketTypes.ItemDrop, "", num, 1f, 0f, 0f, 0);
p.SendData(PacketTypes.ItemOwner, null, num, 0f, 0f, 0f, 0);
if (Config.KeepArmor2 && !Main.hardMode)
Utils.Clear7Item(e.Player);
}

#endregion
Expand Down
38 changes: 38 additions & 0 deletions ServerTools/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Terraria;
using Microsoft.Xna.Framework;
using TShockAPI;

namespace ServerTools;

internal class Utils
{
public static void Clear7Item(TSPlayer Player)
{
if (!Player.TPlayer.armor[8].IsAir)
{
Item item = Player.TPlayer.armor[8];
Player.GiveItem(item.type, item.stack, item.prefix);
Player.TPlayer.armor[8].TurnToAir();
Player.SendData(PacketTypes.PlayerSlot, "", Player.Index, Terraria.ID.PlayerItemSlotID.Armor0 + 8);
TShock.Utils.Broadcast($"[ServerTools] 世界未开启困难模式,禁止玩家 [{Player.Name}]使用恶魔心饰品栏", Color.DarkRed);
}
}


#region 清理盔甲组逻辑
public static void ClearItem(Item[] items, TSPlayer tSPlayer)
{
for (int i = 0; i < 10; i++)
{
foreach (Item item in items)
{
if (!tSPlayer.TPlayer.armor[i].IsAir && tSPlayer.TPlayer.armor[i].type == item.type)
{
tSPlayer.TPlayer.armor[i].TurnToAir();
tSPlayer.SendData(PacketTypes.PlayerSlot, "", tSPlayer.Index, Terraria.ID.PlayerItemSlotID.Armor0 + i);
}
}
}
}
#endregion
}

0 comments on commit 3231998

Please sign in to comment.