From 6b8f346868fb98d664710f5e83dc7512b90c1239 Mon Sep 17 00:00:00 2001
From: AxeelAnder <1491773534@qq.com>
Date: Sat, 20 Oct 2018 12:48:05 +0800
Subject: [PATCH] add NPCAddBuff GetDataHandler
---
TShockAPI/GetDataHandlers.cs | 54 ++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index c59ce1a7..b3769e4e 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -1003,6 +1003,46 @@ namespace TShockAPI
NPCHome.Invoke(null, args);
return args.Handled;
}
+
+ ///
+ /// For use in a NPCAddBuff event
+ ///
+ public class NPCAddBuffEventArgs : GetDataHandledEventArgs
+ {
+ ///
+ /// The ID of the npc
+ ///
+ public short ID { get; set; }
+ ///
+ /// Buff Type
+ ///
+ public byte Type { get; set; }
+ ///
+ /// Time the buff lasts
+ ///
+ public short Time { get; set; }
+ }
+ ///
+ /// NPCAddBuff - Called when a npc is buffed
+ ///
+ public static HandlerList NPCAddBuff = new HandlerList();
+
+ private static bool OnNPCAddBuff(TSPlayer player, MemoryStream data, short id, byte type, short time)
+ {
+ if (NPCAddBuff == null)
+ return false;
+
+ var args = new NPCAddBuffEventArgs
+ {
+ Player = player,
+ Data = data,
+ ID = id,
+ Type = type,
+ Time = time
+ };
+ NPCAddBuff.Invoke(null, args);
+ return args.Handled;
+ }
///
/// For use in a PlayerBuff event
@@ -1455,6 +1495,7 @@ namespace TShockAPI
{ PacketTypes.PlayerSlot, HandlePlayerSlot },
{ PacketTypes.TileGetSection, HandleGetSection },
{ PacketTypes.UpdateNPCHome, UpdateNPCHome },
+ { PacketTypes.NpcAddBuff, HandleNPCAddBuff },
{ PacketTypes.PlayerAddBuff, HandlePlayerAddBuff },
{ PacketTypes.ItemDrop, HandleItemDrop },
{ PacketTypes.UpdateItemDrop, HandleItemDrop },
@@ -2627,6 +2668,19 @@ namespace TShockAPI
}
return false;
}
+
+ private static bool HandleNPCAddBuff(GetDataHandlerArgs args)
+ {
+ var id = args.Data.ReadInt16();
+ var type = args.Data.ReadInt8();
+ var time = args.Data.ReadInt16();
+
+ if (OnNPCAddBuff(args.Player, args.Data, id, type, time))
+ return true;
+
+ args.Player.SendData(PacketTypes.NpcAddBuff, "", id);
+ return true;
+ }
private static bool HandlePlayerAddBuff(GetDataHandlerArgs args)
{