XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

DeathMod

【Terraria】DeathMod (now aka Soul Harvest)

公开
关注 0 Fork 0 Star 0
UTF-8
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace SoulHarvest.Projectiles;

public class FrostShardProjectile : ModProjectile
{
    public override void SetStaticDefaults()
    {
        ProjectileID.Sets.TrailCacheLength[Type] = 14;
        ProjectileID.Sets.TrailingMode[Type] = 2;
    }

    public override void SetDefaults()
    {
        Projectile.width = 32;
        Projectile.height = 32;
        Projectile.friendly = true;
        Projectile.tileCollide = true;
        Projectile.ignoreWater = true;
        Projectile.penetrate = 4;
        Projectile.timeLeft = 240;
        Projectile.DamageType = DamageClass.Melee;
        Projectile.netImportant = true;
    }

    public override void AI()
    {
        Projectile.localAI[0]++;
        if (Projectile.localAI[0] == 1f && Projectile.ai[0] > 0f)
            Projectile.penetrate = 7;
        Projectile.rotation += 0.24f * System.Math.Sign(Projectile.velocity.X);
        if (Projectile.localAI[0] > 28f)
        {
            NPC? target = ReaperProjectileHelper.FindTarget(Projectile, Projectile.ai[0] > 0f ? 700f : 480f);
            if (target is not null)
            {
                float speed = System.Math.Max(9f, Projectile.velocity.Length());
                Vector2 desired = (target.Center - Projectile.Center).SafeNormalize(Vector2.UnitX) * speed;
                Projectile.velocity = Vector2.Lerp(Projectile.velocity, desired, 0.035f + Projectile.ai[1] * 0.045f);
            }
        }
        if (!Main.dedServ)
        {
            Lighting.AddLight(Projectile.Center, new Vector3(0.12f, 0.45f, 0.72f));
            if (Main.rand.NextBool(2))
            {
                Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.IceTorch, -Projectile.velocity * 0.09f, 60, new Color(125, 210, 255), 0.95f + Projectile.ai[1] * 0.2f);
                dust.noGravity = true;
            }
        }
    }

    public override bool OnTileCollide(Vector2 oldVelocity)
    {
        Projectile.localAI[1]++;
        if (Projectile.localAI[1] > (Projectile.ai[0] > 0f ? 4f : 2f))
            return true;
        if (Projectile.velocity.X != oldVelocity.X)
            Projectile.velocity.X = -oldVelocity.X;
        if (Projectile.velocity.Y != oldVelocity.Y)
            Projectile.velocity.Y = -oldVelocity.Y;
        Projectile.velocity *= 0.92f;
        return false;
    }

    public override bool PreDraw(ref Color lightColor) => ReaperProjectileHelper.DrawTrail(Projectile, new Color(105, 205, 255), scaleMultiplier: 1f + Projectile.ai[1] * 0.2f, copies: 12);
}