Move OnNPCStrike to Bouncer
This commit is contained in:
parent
e8a3f87e23
commit
007c685c19
3 changed files with 64 additions and 39 deletions
|
|
@ -75,6 +75,7 @@ Putting this stuff down here so things don't conflict as often.
|
||||||
* Fixed chest item changes not triggering any range checks, tile checks, or correct chest checks. (@hakusaro)
|
* Fixed chest item changes not triggering any range checks, tile checks, or correct chest checks. (@hakusaro)
|
||||||
* Added `TSPlayer` to `GetDataHandlers.PlayerBuff`. (@hakusaro)
|
* Added `TSPlayer` to `GetDataHandlers.PlayerBuff`. (@hakusaro)
|
||||||
* Added `TSPlayer` and `PlayerDeathReason` to `GetDataHandlers.PlayerDamage`. (@hakusaro)
|
* Added `TSPlayer` and `PlayerDeathReason` to `GetDataHandlers.PlayerDamage`. (@hakusaro)
|
||||||
|
* Added `TSPlayer` to `GetDataHandlers.NPCStrike`. (@hakusaro)
|
||||||
|
|
||||||
## TShock 4.3.25
|
## TShock 4.3.25
|
||||||
* Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6.
|
* Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6.
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
// Setup hooks
|
// Setup hooks
|
||||||
|
|
||||||
|
GetDataHandlers.NPCStrike.Register(OnNPCStrike);
|
||||||
GetDataHandlers.ItemDrop.Register(OnItemDrop);
|
GetDataHandlers.ItemDrop.Register(OnItemDrop);
|
||||||
GetDataHandlers.PlayerBuff.Register(OnPlayerBuff);
|
GetDataHandlers.PlayerBuff.Register(OnPlayerBuff);
|
||||||
GetDataHandlers.ChestItemChange.Register(OnChestItemChange);
|
GetDataHandlers.ChestItemChange.Register(OnChestItemChange);
|
||||||
|
|
@ -58,6 +59,63 @@ namespace TShockAPI
|
||||||
GetDataHandlers.TileEdit.Register(OnTileEdit);
|
GetDataHandlers.TileEdit.Register(OnTileEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Handles the NPC Strike event for Bouncer.</summary>
|
||||||
|
/// <param name="sender">The object that triggered the event.</param>
|
||||||
|
/// <param name="args">The packet arguments that the event has.</param>
|
||||||
|
internal void OnNPCStrike(object sender, GetDataHandlers.NPCStrikeEventArgs args)
|
||||||
|
{
|
||||||
|
short id = args.ID;
|
||||||
|
byte direction = args.Direction;
|
||||||
|
short dmg = args.Damage;
|
||||||
|
float knockback = args.Knockback;
|
||||||
|
byte crit = args.Critical;
|
||||||
|
|
||||||
|
if (Main.npc[id] == null)
|
||||||
|
{
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dmg > TShock.Config.MaxDamage && !args.Player.HasPermission(Permissions.ignoredamagecap))
|
||||||
|
{
|
||||||
|
if (TShock.Config.KickOnDamageThresholdBroken)
|
||||||
|
{
|
||||||
|
TShock.Utils.Kick(args.Player, string.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage));
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
args.Player.Disable(String.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage), DisableFlags.WriteToLogAndConsole);
|
||||||
|
}
|
||||||
|
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TShock.CheckIgnores(args.Player))
|
||||||
|
{
|
||||||
|
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TShock.Config.RangeChecks &&
|
||||||
|
TShock.CheckRangePermission(args.Player, (int)(Main.npc[id].position.X / 16f), (int)(Main.npc[id].position.Y / 16f), 128))
|
||||||
|
{
|
||||||
|
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
||||||
|
{
|
||||||
|
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Called when a player is damaged.</summary>
|
/// <summary>Called when a player is damaged.</summary>
|
||||||
/// <param name="sender">The object that triggered the event.</param>
|
/// <param name="sender">The object that triggered the event.</param>
|
||||||
/// <param name="args">The packet arguments that the event has.</param>
|
/// <param name="args">The packet arguments that the event has.</param>
|
||||||
|
|
|
||||||
|
|
@ -1214,6 +1214,8 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class NPCStrikeEventArgs : HandledEventArgs
|
public class NPCStrikeEventArgs : HandledEventArgs
|
||||||
{
|
{
|
||||||
|
/// <summary>The TSPlayer that triggered the event.</summary>
|
||||||
|
public TSPlayer Player { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ???
|
/// ???
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -1240,13 +1242,14 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static HandlerList<NPCStrikeEventArgs> NPCStrike;
|
public static HandlerList<NPCStrikeEventArgs> NPCStrike;
|
||||||
|
|
||||||
private static bool OnNPCStrike(short id, byte dir, short dmg, float knockback, byte crit)
|
private static bool OnNPCStrike(TSPlayer player, short id, byte dir, short dmg, float knockback, byte crit)
|
||||||
{
|
{
|
||||||
if (NPCStrike == null)
|
if (NPCStrike == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var args = new NPCStrikeEventArgs
|
var args = new NPCStrikeEventArgs
|
||||||
{
|
{
|
||||||
|
Player = player,
|
||||||
ID = id,
|
ID = id,
|
||||||
Direction = dir,
|
Direction = dir,
|
||||||
Damage = dmg,
|
Damage = dmg,
|
||||||
|
|
@ -2593,33 +2596,9 @@ namespace TShockAPI
|
||||||
var direction = (byte)(args.Data.ReadInt8() - 1);
|
var direction = (byte)(args.Data.ReadInt8() - 1);
|
||||||
var crit = args.Data.ReadInt8();
|
var crit = args.Data.ReadInt8();
|
||||||
|
|
||||||
if (OnNPCStrike(id, direction, dmg, knockback, crit))
|
if (OnNPCStrike(args.Player, id, direction, dmg, knockback, crit))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (Main.npc[id] == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (dmg > TShock.Config.MaxDamage && !args.Player.HasPermission(Permissions.ignoredamagecap))
|
|
||||||
{
|
|
||||||
if (TShock.Config.KickOnDamageThresholdBroken)
|
|
||||||
{
|
|
||||||
TShock.Utils.Kick(args.Player, string.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
args.Player.Disable(String.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage), DisableFlags.WriteToLogAndConsole);
|
|
||||||
}
|
|
||||||
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TShock.CheckIgnores(args.Player))
|
|
||||||
{
|
|
||||||
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Main.npc[id].townNPC && !args.Player.HasPermission(Permissions.hurttownnpc))
|
if (Main.npc[id].townNPC && !args.Player.HasPermission(Permissions.hurttownnpc))
|
||||||
{
|
{
|
||||||
args.Player.SendErrorMessage("You do not have permission to hurt this NPC.");
|
args.Player.SendErrorMessage("You do not have permission to hurt this NPC.");
|
||||||
|
|
@ -2627,19 +2606,6 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TShock.Config.RangeChecks &&
|
|
||||||
TShock.CheckRangePermission(args.Player, (int)(Main.npc[id].position.X / 16f), (int)(Main.npc[id].position.Y / 16f), 128))
|
|
||||||
{
|
|
||||||
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
|
||||||
{
|
|
||||||
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue