Add SyncTilePicking event.

This commit is contained in:
Patrikkk 2020-06-01 18:31:30 +02:00
parent c5fcece18d
commit 2177d75066
2 changed files with 77 additions and 18 deletions

View file

@ -151,9 +151,10 @@ namespace TShockAPI
{ PacketTypes.CrystalInvasionStart, HandleOldOnesArmy },
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
{ PacketTypes.SyncTilePicking, HandleSyncTilePicking },
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
{ PacketTypes.FishOutNPC, HandleFishOutNPC },
{ PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing },
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker }
{ PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing }
};
}
@ -1866,6 +1867,51 @@ namespace TShockAPI
return args.Handled;
}
/// <summary>
/// For use in a SyncTilePicking event.
/// </summary>
public class SyncTilePickingEventArgs : GetDataHandledEventArgs
{
/// <summary>
/// The player index in the packet, who sends the tile picking data.
/// </summary>
public byte PlayerIndex { get; set; }
/// <summary>
/// The X world position of the tile that is being picked.
/// </summary>
public short TileX { get; set; }
/// <summary>
/// The Y world position of the tile that is being picked.
/// </summary>
public short TileY { get; set; }
/// <summary>
/// The damage that is being dealt on the tile.
/// </summary>
public byte TileDamage { get; set; }
}
/// <summary>
/// Called when a player hits and damages a tile.
/// </summary>
public static HandlerList<SyncTilePickingEventArgs> SyncTilePicking = new HandlerList<SyncTilePickingEventArgs>();
private static bool OnSyncTilePicking(TSPlayer player, MemoryStream data, byte playerIndex, short tileX, short tileY, byte tileDamage)
{
if (SyncTilePicking == null)
return false;
var args = new SyncTilePickingEventArgs
{
Player = player,
Data = data,
PlayerIndex = playerIndex,
TileX = tileX,
TileY = tileY,
TileDamage = tileDamage
};
SyncTilePicking.Invoke(null, args);
return args.Handled;
}
/// <summary>
/// For use in a FishOutNPC event.
/// </summary>
@ -3671,6 +3717,34 @@ namespace TShockAPI
return false;
}
private static bool HandleSyncTilePicking(GetDataHandlerArgs args)
{
byte playerIndex = args.Data.ReadInt8();
short tileX = args.Data.ReadInt16();
short tileY = args.Data.ReadInt16();
byte damage = args.Data.ReadInt8();
if (OnSyncTilePicking(args.Player, args.Data, playerIndex, tileX, tileY, damage))
return true;
return false;
}
private static bool HandleSyncRevengeMarker(GetDataHandlerArgs args)
{
int uniqueID = args.Data.ReadInt32();
Vector2 location = args.Data.ReadVector2();
int netId = args.Data.ReadInt32();
float npcHpPercent = args.Data.ReadSingle();
int npcTypeAgainstDiscouragement = args.Data.ReadInt32(); //tfw the argument is Type Against Discouragement
int npcAiStyleAgainstDiscouragement = args.Data.ReadInt32(); //see ^
int coinsValue = args.Data.ReadInt32();
float baseValue = args.Data.ReadSingle();
bool spawnedFromStatus = args.Data.ReadBoolean();
return false;
}
private static bool HandleFishOutNPC(GetDataHandlerArgs args)
{
ushort tileX = args.Data.ReadUInt16();
@ -3697,21 +3771,6 @@ namespace TShockAPI
return false;
}
private static bool HandleSyncRevengeMarker(GetDataHandlerArgs args)
{
int uniqueID = args.Data.ReadInt32();
Vector2 location = args.Data.ReadVector2();
int netId = args.Data.ReadInt32();
float npcHpPercent = args.Data.ReadSingle();
int npcTypeAgainstDiscouragement = args.Data.ReadInt32(); //tfw the argument is Type Against Discouragement
int npcAiStyleAgainstDiscouragement = args.Data.ReadInt32(); //see ^
int coinsValue = args.Data.ReadInt32();
float baseValue = args.Data.ReadSingle();
bool spawnedFromStatus = args.Data.ReadBoolean();
return false;
}
public enum EditAction
{
KillTile = 0,