Merge pull request #2029 from Pryaxis/bounceronnewproj

Bouncer OnNewProjectile - Add checks on directional projectiles.
This commit is contained in:
Chris 2020-06-10 12:03:58 +09:30 committed by GitHub
commit 704b8430f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 4 deletions

View file

@ -9,6 +9,11 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Including replace action in TilePlace threshold incrementation, so players cannot bypass the threshold while replacing tiles/walls.
* Including check for maxTileSets when player is replacing tiles, so players cannot send invalid tile data through the replace tile action.
* Including a check for ReplaceWall when the tile is a Breakable/CutTile.
* Adding checks in Bouncer OnNewProjectile (@Patrikkk):
* For valid golf club and golf ball creation.
* Renamed stabProjectile to directionalProjectile for a more accurate naming.
* Adding staff projectiles to the directionalProjectiles Dictionary to include staffs in the valid projectile creation check.
* Adding GolfBallItemIDs list in Handlers.LandGolfBallInCupHandler.cs
## TShock 4.4.0 (Pre-release 11)
* New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM)

View file

@ -717,15 +717,32 @@ namespace TShockAPI
return;
}
if (stabProjectile.ContainsKey(type))
/// If the projectile is a directional projectile, check if the player is holding their respected item to validate the projectile creation.
if (directionalProjectiles.ContainsKey(type))
{
if (stabProjectile[type] == args.Player.TPlayer.HeldItem.type)
if (directionalProjectiles[type] == args.Player.TPlayer.HeldItem.type)
{
args.Handled = false;
return;
}
}
/// If the created projectile is a golf club, check if the player is holding one of the golf club items to validate the projectile creation.
if (type == ProjectileID.GolfClubHelper && Handlers.LandGolfBallInCupHandler.GolfClubItemIDs.Contains(args.Player.TPlayer.HeldItem.type))
{
args.Handled = false;
return;
}
/// If the created projectile is a golf ball and the player is not holding a golf club item and neither a golf ball item and neither they have had a golf club projectile created recently.
if (Handlers.LandGolfBallInCupHandler.GolfBallProjectileIDs.Contains(type) &&
!Handlers.LandGolfBallInCupHandler.GolfClubItemIDs.Contains(args.Player.TPlayer.HeldItem.type) &&
!Handlers.LandGolfBallInCupHandler.GolfBallItemIDs.Contains(args.Player.TPlayer.HeldItem.type) &&
!args.Player.RecentlyCreatedProjectiles.Any(p => p.Type == ProjectileID.GolfClubHelper))
{
TShock.Log.ConsoleDebug("Bouncer / OnNewProjectile please report to tshock about this! normally this is a reject from {0} {1} (golf)", args.Player.Name, type);
}
// Main.projHostile contains projectiles that can harm players
// without PvP enabled and belong to enemy mobs, so they shouldn't be
// possible for players to create. (Source: Ijwu, QuiCM)
@ -2118,9 +2135,33 @@ namespace TShockAPI
TileID.Campfire
};
private static Dictionary<int, int> stabProjectile = new Dictionary<int, int>()
/// <summary>
/// These projectiles have been added or modified with Terraria 1.4.
/// They come from normal items, but to have the directional functionality, they must be projectiles.
/// </summary>
private static Dictionary<int, int> directionalProjectiles = new Dictionary<int, int>()
{
{ ProjectileID.GladiusStab, ItemID.Gladius },
///Spears
{ ProjectileID.DarkLance, ItemID.DarkLance},
{ ProjectileID.Trident, ItemID.Trident},
{ ProjectileID.Spear, ItemID.Spear},
{ ProjectileID.MythrilHalberd, ItemID.MythrilHalberd},
{ ProjectileID.AdamantiteGlaive, ItemID.AdamantiteGlaive},
{ ProjectileID.CobaltNaginata, ItemID.CobaltNaginata},
{ ProjectileID.Gungnir, ItemID.Gungnir},
{ ProjectileID.MushroomSpear, ItemID.MushroomSpear},
{ ProjectileID.TheRottedFork, ItemID.TheRottedFork},
{ ProjectileID.PalladiumPike, ItemID.PalladiumPike},
{ ProjectileID.OrichalcumHalberd, ItemID.OrichalcumHalberd},
{ ProjectileID.TitaniumTrident, ItemID.TitaniumTrident},
{ ProjectileID.ChlorophytePartisan, ItemID.ChlorophytePartisan},
{ ProjectileID.NorthPoleWeapon, ItemID.NorthPole},
{ ProjectileID.ObsidianSwordfish, ItemID.ObsidianSwordfish},
{ ProjectileID.Swordfish, ItemID.Swordfish},
{ ProjectileID.MonkStaffT2, ItemID.MonkStaffT2},
{ ProjectileID.ThunderSpear, ItemID.ThunderSpear},
{ ProjectileID.GladiusStab, ItemID.Gladius},
/// ShortSwords
{ ProjectileID.RulerStab, ItemID.Ruler },
{ ProjectileID.CopperShortswordStab, ItemID.CopperShortsword },
{ ProjectileID.TinShortswordStab, ItemID.TinShortsword },

View file

@ -59,6 +59,26 @@ namespace TShockAPI.Handlers
ItemID.GolfClubWedge,
ItemID.GolfClubPutter
};
/// <summary>
/// List of golf ball item IDs.
/// </summary>
public static readonly List<int> GolfBallItemIDs = new List<int>()
{
ItemID.GolfBall,
ItemID.GolfBallDyedBlack,
ItemID.GolfBallDyedBlue,
ItemID.GolfBallDyedBrown,
ItemID.GolfBallDyedCyan,
ItemID.GolfBallDyedGreen,
ItemID.GolfBallDyedLimeGreen,
ItemID.GolfBallDyedOrange,
ItemID.GolfBallDyedPink,
ItemID.GolfBallDyedPurple,
ItemID.GolfBallDyedRed,
ItemID.GolfBallDyedSkyBlue,
ItemID.GolfBallDyedTeal,
ItemID.GolfBallDyedViolet
};
/// <summary>
/// Invoked when a player lands a golf ball in a cup.