Move the projectile refresh to Bouncer.

Bouncer now has an OnSecondUpdate().
Move projectile created tracking to GetDataHandler from Bouncer.
This commit is contained in:
Olink 2020-05-24 04:27:12 -04:00
parent 9209ac0b73
commit b73088306d
3 changed files with 33 additions and 27 deletions

View file

@ -19,18 +19,17 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.ID;
using TShockAPI.DB;
using TShockAPI.Net;
using Terraria;
using Microsoft.Xna.Framework;
using OTAPI.Tile;
using TShockAPI.Localization;
using static TShockAPI.GetDataHandlers;
using TerrariaApi.Server;
using Terraria.ObjectData;
using Terraria.DataStructures;
using Terraria.Localization;
using TShockAPI.Models.PlayerUpdate;
using System.Threading.Tasks;
namespace TShockAPI
{
@ -962,18 +961,6 @@ namespace TShockAPI
// Denotes that the player has recently set a fuse - used for cheat detection.
args.Player.RecentFuse = 10;
}
if (projectileCreatesLiquid.ContainsKey(type))
{
lock (args.Player.RecentlyCreatedProjectiles)
{
args.Player.RecentlyCreatedProjectiles.Add(new ProjectileStruct()
{
Index = ident,
CreatedAt = DateTime.Now
});
}
}
}
/// <summary>Handles the NPC Strike event for Bouncer.</summary>
@ -2069,6 +2056,24 @@ namespace TShockAPI
}
}
internal void OnSecondUpdate()
{
Task.Run(() =>
{
foreach (var player in TShock.Players)
{
if (player != null && player.TPlayer.whoAmI >= 0)
{
var threshold = DateTime.Now.AddSeconds(-5);
lock (player.RecentlyCreatedProjectiles)
{
player.RecentlyCreatedProjectiles = player.RecentlyCreatedProjectiles.Where(s => s.CreatedAt > threshold).ToList();
}
}
}
});
}
// These time values are references from Projectile.cs, at npc.AddBuff() calls.
private static Dictionary<int, short> NPCAddBuffTimeMax = new Dictionary<int, short>()
{

View file

@ -2322,6 +2322,18 @@ namespace TShockAPI
if (OnNewProjectile(args.Data, ident, pos, vel, knockback, dmg, owner, type, index, args.Player))
return true;
if (projectileCreatesLiquid.ContainsKey(type))
{
lock (args.Player.RecentlyCreatedProjectiles)
{
args.Player.RecentlyCreatedProjectiles.Add(new ProjectileStruct()
{
Index = ident,
CreatedAt = DateTime.Now
});
}
}
return false;
}

View file

@ -44,7 +44,6 @@ using Microsoft.Xna.Framework;
using TShockAPI.Sockets;
using TShockAPI.CLI;
using TShockAPI.Localization;
using System.Threading.Tasks;
namespace TShockAPI
{
@ -1065,19 +1064,9 @@ namespace TShockAPI
}
}
}
Task.Run(() =>
{
if (player != null && player.TPlayer.whoAmI >= 0)
{
var threshold = DateTime.Now.AddSeconds(-5);
lock (player.RecentlyCreatedProjectiles)
{
player.RecentlyCreatedProjectiles = player.RecentlyCreatedProjectiles.Where(s => s.CreatedAt > threshold).ToList();
}
}
});
}
Bouncer.OnSecondUpdate();
Utils.SetConsoleTitle(false);
}