Add HealOtherPlayer hook; integrate with Bouncer
This commit is contained in:
parent
0d2d50b3de
commit
f065e99a0e
2 changed files with 78 additions and 21 deletions
|
|
@ -49,6 +49,46 @@ namespace TShockAPI
|
||||||
// Setup hooks
|
// Setup hooks
|
||||||
|
|
||||||
GetDataHandlers.SendTileSquare.Register(OnSendTileSquare);
|
GetDataHandlers.SendTileSquare.Register(OnSendTileSquare);
|
||||||
|
GetDataHandlers.HealOtherPlayer.Register(OnHealOtherPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>OnHealOtherPlayer - The handler for the HealOther events in Bouncer</summary>
|
||||||
|
/// <param name="sender">sender</param>
|
||||||
|
/// <param name="args">args</param>
|
||||||
|
internal void OnHealOtherPlayer(object sender, GetDataHandlers.HealOtherPlayerEventArgs args)
|
||||||
|
{
|
||||||
|
short amount = args.Amount;
|
||||||
|
byte plr = args.TargetPlayerIndex;
|
||||||
|
|
||||||
|
if (amount <= 0 || Main.player[plr] == null || !Main.player[plr].active)
|
||||||
|
{
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount > TShock.Config.MaxDamage * 0.2)
|
||||||
|
{
|
||||||
|
args.Player.Disable("HealOtherPlayer cheat attempt!", DisableFlags.WriteToLogAndConsole);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.Player.HealOtherThreshold > TShock.Config.HealOtherThreshold)
|
||||||
|
{
|
||||||
|
args.Player.Disable("Reached HealOtherPlayer threshold.", DisableFlags.WriteToLogAndConsole);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TShock.CheckIgnores(args.Player) || (DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
||||||
|
{
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
args.Player.HealOtherThreshold++;
|
||||||
|
args.Handled = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>OnSendTileSquare - The handler for SendTileSquare events in Bouncer</summary>
|
/// <summary>OnSendTileSquare - The handler for SendTileSquare events in Bouncer</summary>
|
||||||
|
|
|
||||||
|
|
@ -532,6 +532,43 @@ namespace TShockAPI
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>HandledEventArgs - The event args object for the HealOtherPlayer event</summary>
|
||||||
|
public class HealOtherPlayerEventArgs : HandledEventArgs
|
||||||
|
{
|
||||||
|
/// <summary>Player - The TSPlayer object that caused the event</summary>
|
||||||
|
public TSPlayer Player { get; set; }
|
||||||
|
|
||||||
|
/// <summary>TargetPlayerIndex - The Terraria player index of the target player</summary>
|
||||||
|
public byte TargetPlayerIndex { get; set; }
|
||||||
|
|
||||||
|
/// <summary>Amount - The amount to heal by</summary>
|
||||||
|
public short Amount { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>HealOtherPlayer - When a player heals another player</summary>
|
||||||
|
public static HandlerList<HealOtherPlayerEventArgs> HealOtherPlayer;
|
||||||
|
|
||||||
|
/// <summary>OnHealOtherPlayer - Fires the HealOtherPlayer event</summary>
|
||||||
|
/// <param name="player">player - The TSPlayer that started the event</param>
|
||||||
|
/// <param name="targetPlayerIndex">targetPlayerIndex - The Terraria player index that the event targets</param>
|
||||||
|
/// <param name="amount">amount - The amount to heal</param>
|
||||||
|
/// <returns>bool</returns>
|
||||||
|
private static bool OnHealOtherPlayer(TSPlayer player, byte targetPlayerIndex, short amount)
|
||||||
|
{
|
||||||
|
if (HealOtherPlayer == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var args = new HealOtherPlayerEventArgs
|
||||||
|
{
|
||||||
|
Player = player,
|
||||||
|
TargetPlayerIndex = targetPlayerIndex,
|
||||||
|
Amount = amount,
|
||||||
|
};
|
||||||
|
|
||||||
|
HealOtherPlayer.Invoke(null, args);
|
||||||
|
return args.Handled;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For use in a SendTileSquare event
|
/// For use in a SendTileSquare event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -1312,29 +1349,9 @@ namespace TShockAPI
|
||||||
byte plr = args.Data.ReadInt8();
|
byte plr = args.Data.ReadInt8();
|
||||||
short amount = args.Data.ReadInt16();
|
short amount = args.Data.ReadInt16();
|
||||||
|
|
||||||
if (amount <= 0 || Main.player[plr] == null || !Main.player[plr].active)
|
if (OnHealOtherPlayer(args.Player, plr, amount))
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
if (amount > TShock.Config.MaxDamage * 0.2)
|
|
||||||
{
|
|
||||||
args.Player.Disable("HealOtherPlayer cheat attempt!", DisableFlags.WriteToLogAndConsole);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.Player.HealOtherThreshold > TShock.Config.HealOtherThreshold)
|
|
||||||
{
|
|
||||||
args.Player.Disable("Reached HealOtherPlayer threshold.", DisableFlags.WriteToLogAndConsole);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TShock.CheckIgnores(args.Player) || (DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
args.Player.HealOtherThreshold++;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue