72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
using ForgottenWawiTech.Content.Projectiles.Protogen;
|
|
|
|
namespace ForgottenWawiTech.Content.Players
|
|
{
|
|
public class ProtogenOperativePlayer : ModPlayer
|
|
{
|
|
private const int NaniteProjectileCount = 3;
|
|
private const int NaniteCooldownTicks = 90;
|
|
private const int NaniteBaseDamage = 90;
|
|
private const float NaniteSpawnRadius = 30f;
|
|
|
|
private int naniteCooldownTimer;
|
|
|
|
public bool NaniteSwarmActive { get; private set; }
|
|
|
|
public override void ResetEffects()
|
|
{
|
|
NaniteSwarmActive = false;
|
|
}
|
|
|
|
public override void UpdateDead()
|
|
{
|
|
NaniteSwarmActive = false;
|
|
naniteCooldownTimer = 0;
|
|
}
|
|
|
|
public override void PostUpdate()
|
|
{
|
|
if (naniteCooldownTimer > 0)
|
|
{
|
|
naniteCooldownTimer--;
|
|
}
|
|
}
|
|
|
|
public void EnableNaniteSwarm()
|
|
{
|
|
NaniteSwarmActive = true;
|
|
}
|
|
|
|
public override void OnHurt(Player.HurtInfo info)
|
|
{
|
|
if (!NaniteSwarmActive || info.Damage <= 0 || naniteCooldownTimer > 0 || Player.whoAmI != Main.myPlayer)
|
|
{
|
|
return;
|
|
}
|
|
|
|
naniteCooldownTimer = NaniteCooldownTicks;
|
|
var source = Player.GetSource_Misc("ProtogenOperativeNanites");
|
|
int damage = (int)Player.GetTotalDamage(DamageClass.Generic).ApplyTo(NaniteBaseDamage);
|
|
|
|
for (int i = 0; i < NaniteProjectileCount; i++)
|
|
{
|
|
float angle = MathHelper.TwoPi * i / NaniteProjectileCount;
|
|
Vector2 spawnOffset = angle.ToRotationVector2() * NaniteSpawnRadius;
|
|
Vector2 spawnVelocity = spawnOffset.SafeNormalize(Vector2.UnitY) * 6f + Player.velocity;
|
|
|
|
Projectile.NewProjectile(
|
|
source,
|
|
Player.Center + spawnOffset,
|
|
spawnVelocity,
|
|
ModContent.ProjectileType<ProtogenOperativeNanite>(),
|
|
damage,
|
|
2f,
|
|
Player.whoAmI);
|
|
}
|
|
}
|
|
}
|
|
}
|