Summon finished and balanced.

This commit is contained in:
Memes committed 2024-03-23 13:51:01 +01:00
1 parent 1fd05f842d
commit 3a49e20524
26 files changed
+1392 -69

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
using CalamityMod.CalPlayer;
using CalamityMod.Projectiles.Summon;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Buffs.Summon
{
public class LiliesOfFinalityBuff : ModBuff
{
public override void SetStaticDefaults()
{
Main.buffNoTimeDisplay[Type] = true;
Main.buffNoSave[Type] = true;
}
public override void Update(Player player, ref int buffIndex)
{
CalamityPlayer modPlayer = player.Calamity();
if (player.ownedProjectileCounts[ModContent.ProjectileType<LiliesOfFinalityElster>()] > 0)
modPlayer.LiliesOfFinalityBool = true;
if (!modPlayer.LiliesOfFinalityBool)
{
player.DelBuff(buffIndex);
buffIndex--;
}
else
player.buffTime[buffIndex] = 18000;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

+2
View File
@@ -1079,6 +1079,7 @@ namespace CalamityMod.CalPlayer
public bool celestialDragons = false;
public bool KalandraMirror = false;
public bool StellarTorus = false;
public bool LiliesOfFinalityBool = false;
#endregion
#region Biome
@@ -2118,6 +2119,7 @@ namespace CalamityMod.CalPlayer
celestialDragons = false;
KalandraMirror = false;
StellarTorus = false;
LiliesOfFinalityBool = false;
disableVoodooSpawns = false;
disablePerfCystSpawns = false;
+81
View File
@@ -0,0 +1,81 @@
using CalamityMod.Projectiles.Summon;
using CalamityMod.Rarities;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
namespace CalamityMod.Items.Weapons.Summon
{
public class LiliesOfFinality : ModItem, ILocalizedModType
{
public new string LocalizationCategory => "Items.Weapons.Summon";
#region Other Stats
public static float MaxEnemyDistanceDetection = 2000f;
public static int CommonDustID = 114;
public static float Elster_DistanceFromTarget = 280f;
public static float Elster_TargettingFlySpeed = 35f;
public static float Elster_BulletProjectileSpeed = 40f;
public static float Ariane_BoltFireRate = 60f;
public static float Ariane_TargettingFlySpeed = 20f;
public static float Ariane_BoltProjectileSpeed = 15f;
public static int Ariane_BoltTimeHoming = 300;
public static float Ariane_MinTurnRate = 0.05f;
public static float Ariane_MaxTurnRate = 0.2f;
public static int Ariane_AoESize = 1000;
public static float Ariane_AoEDMGMultiplier = 0.1f;
#endregion
public override void SetDefaults()
{
Item.damage = 550;
Item.DamageType = DamageClass.Summon;
Item.shoot = ProjectileType<LiliesOfFinalityElster>();
Item.knockBack = 5f;
Item.mana = 10;
Item.useTime = Item.useAnimation = 15;
Item.width = 36;
Item.height = 50;
Item.noMelee = true;
Item.value = CalamityGlobalItem.Rarity15BuyPrice;
Item.rare = RarityType<Violet>();
Item.useStyle = ItemUseStyleID.HoldUp;
}
public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] == 0;
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
if (player.maxMinions - player.slotsMinions >= 2)
{
Projectile.NewProjectileDirect(source, Main.MouseWorld, new Vector2(-1f, -1f) * 3f, type, damage, knockback, player.whoAmI);
Projectile.NewProjectileDirect(source, Main.MouseWorld, new Vector2(1f, -1f) * 3f, ProjectileType<LiliesOfFinalityAriane>(), damage, knockback, player.whoAmI);
if (Main.dedServ)
return false;
int dustAmount = Main.rand.Next(30, 40 + 1);
for (int i = 0; i < dustAmount; i++)
{
float angle = MathHelper.TwoPi / dustAmount * i;
Vector2 dustVelocity = angle.ToRotationVector2() * Main.rand.NextFloat(3f, 6f);
Dust spawnDust = Dust.NewDustPerfect(
Main.MouseWorld,
CommonDustID,
dustVelocity,
Scale: Main.rand.NextFloat(1.2f, 1.5f));
spawnDust.noGravity = true;
}
}
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -1520,3 +1520,8 @@ YoungDukeBuff: {
DisplayName: Young Duke Buff
Description: Mods.CalamityMod.Buffs.YoungDukeBuff.Description
}
LiliesOfFinalityBuff: {
DisplayName: Finality
Description: Remember our promise
}
@@ -830,3 +830,8 @@ HarvestStaff: {
'No thoughts behind those eyes'
'''
}
LiliesOfFinality: {
DisplayName: Lilies of Finality
Tooltip: ""
}
@@ -325,3 +325,9 @@ HopeShredderArrow.DisplayName: Hope Shredder Arrow
HopeShredderArrowSplit.DisplayName: Hope Shredder Split Arrow
HarvestStaffMinion.DisplayName: Harvest Staff Minion
HarvestStaffSentry.DisplayName: Harvest Staff Sentry
LiliesOfFinalityAoE.DisplayName: Bioresonance Aura
LiliesOfFinalityAriane.DisplayName: Ariane
LiliesOfFinalityBullet.DisplayName: Einhorn Bullet
LiliesOfFinalityBolt.DisplayName: Bioresonance Bolt
LiliesOfFinalityElster.DisplayName: Elster
LiliesOfEternityBullet.DisplayName: Lilies Of Eternity Bullet
+55
View File
@@ -0,0 +1,55 @@
using System;
using CalamityMod.Projectiles.Summon;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class ArianeFakeDust : Particle
{
public override string Texture => "CalamityMod/Particles/FakeDust";
public override bool UseAdditiveBlend => true;
public override bool UseCustomDraw => true;
public override bool SetLifetime => true;
private Projectile Projectile;
private Vector2 RelativePosition;
private float Spin;
private float Opacity;
private bool Big;
public ArianeFakeDust(Projectile proj, Vector2 relativePosition, Vector2 velocity, Color color, float scale, int lifeTime, float rotationSpeed = 1f, bool bigSize = false)
{
Projectile = proj;
RelativePosition = relativePosition;
Velocity = velocity;
Color = color;
Scale = scale;
Lifetime = lifeTime;
Rotation = Main.rand.NextFloat(MathHelper.TwoPi);
Spin = rotationSpeed;
Big = bigSize;
Variant = Main.rand.Next(3);
}
public override void Update()
{
if (Projectile != null && Projectile.active && Projectile.type == ModContent.ProjectileType<LiliesOfFinalityAoE>())
Position = Projectile.Center + RelativePosition;
Velocity *= 0.95f;
Scale *= 0.98f;
Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f);
Opacity = (float)Math.Sin(LifetimeCompletion * MathHelper.Pi);
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
Texture2D dustTexture = Big ? ModContent.Request<Texture2D>("CalamityMod/Particles/FakeDustBig").Value : ModContent.Request<Texture2D>(Texture).Value;
Rectangle frame = new Rectangle(0, (Big ? 8 : 6) * Variant, (Big ? 8 : 6), (Big ? 8 : 6));
spriteBatch.Draw(dustTexture, Position - Main.screenPosition, frame, Color * Opacity, Rotation, frame.Size() / 2f, Scale, SpriteEffects.None, 0);
}
}
}
@@ -0,0 +1,39 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class LiliesOfFinalityHeartParticle : Particle
{
public override string Texture => "CalamityMod/Particles/LiliesOfFinalityHeartParticle";
public override bool UseCustomDraw => true;
public override bool SetLifetime => true;
public LiliesOfFinalityHeartParticle(Vector2 position, Vector2 velocity, int lifeTime, float scale = 1f)
{
Position = position;
Velocity = velocity;
Lifetime = lifeTime;
Scale = scale;
Rotation = velocity.ToRotation() + MathHelper.PiOver2;
Color = Color.White;
}
public override void Update()
{
Velocity *= 0.96f;
Scale *= 0.97f;
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
Texture2D emoteTexture = ModContent.Request<Texture2D>(Texture).Value;
Vector2 origin = emoteTexture.Size() * 0.5f;
float opacity = 1f - MathF.Pow(LifetimeCompletion, 4f);
spriteBatch.Draw(emoteTexture, Position - Main.screenPosition, null, Color * opacity * 0.7f, Rotation, origin, Scale, SpriteEffects.None, 0);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

@@ -224,14 +224,14 @@ namespace CalamityMod.Projectiles.BaseProjectiles
{
Owner = Main.player[Projectile.owner];
ModdedOwner = Owner.Calamity();
Target = Owner.Center.MinionHoming(AdaptiveEnemyDistanceDetection, Owner, !PreHardmodeMinionTileVision || CalamityPlayer.areThereAnyDamnBosses);
Target = Owner.Center.MinionHoming(AdaptiveEnemyDistanceDetection, Owner, !PreHardmodeMinionTileVision || (CalamityPlayer.areThereAnyDamnBosses && !Grounded));
// When minions are grounded, they are affected by tiles, meaning they have a much limited movement.
// Pre-Hardmode minions are affected the most since they can't see through walls.
// In consequence, some targets that may seem valid, aren't detected due to this.
// If the minion hasn't detected any targets with the center being the player, we give them a second chance with the center being the minion itself.
// If there are bosses on the world, we don't do this check because if there wasn't any targets with tile X-Ray, this won't do anything.
if (Grounded && Target is null && PreHardmodeMinionTileVision && !CalamityPlayer.areThereAnyDamnBosses)
if (Grounded && Target is null && PreHardmodeMinionTileVision)
Target = Projectile.Center.MinionHoming(AdaptiveEnemyDistanceDetection, Owner, false);
}
@@ -300,74 +300,13 @@ namespace CalamityMod.Projectiles.BaseProjectiles
public bool IsTileBetweenTargetAndMinionVertically(bool platformCheckDownwards = false) => IsTileBetweenTwoVectorsVertically(Target.Center, Projectile.Center, platformCheckDownwards);
/// <summary>
/// Checks if the minion has a tile in front of him, at their left or right.
/// </summary>
/// <param name="leftFluff">The extra distance it'll check at the left, not all minions are perfectly sized 1 tile, so you'll need to tweak this. Defaults to 0.</param>
/// <param name="rightFluff">The extra distance it'll check at the right, not all minions are perfectly sized 1 tile, so you'll need to tweak this. Defaults to 0.</param>
/// <returns><see langword="true"/> if there's a tile at the left or right, otherwise <see langword="false"/></returns>
public bool IsMinionFacingTile(int leftFluff = 0, int rightFluff = 0)
public bool IsMinionFacingTile()
{
Point topLeft = CalamityUtils.ToSafeTileCoordinates(Projectile.TopLeft);
Point bottomLeft = CalamityUtils.ToSafeTileCoordinates(Projectile.BottomLeft);
for (int coordY = topLeft.Y; coordY < bottomLeft.Y; coordY++)
{
if (Main.tile[topLeft.X - leftFluff, coordY].IsTileSolid())
return true;
}
Point topRight = CalamityUtils.ToSafeTileCoordinates(Projectile.TopRight);
Point bottomRight = CalamityUtils.ToSafeTileCoordinates(Projectile.BottomRight);
for (int coordY = topRight.Y; coordY <= bottomRight.Y; coordY++)
{
if (Main.tile[topRight.X + rightFluff, coordY].IsTileSolid())
return true;
}
return false;
}
/// <summary>
/// Checks whether the minion is standing on a tile or not.
/// </summary>
/// <returns><see langword="true"/> if the minion's standing on a tile, otherwise <see langword="false"/></returns>
public bool IsMinionStandingOnTile()
{
Point minionPointLeft = CalamityUtils.ToSafeTileCoordinates(Projectile.BottomLeft);
Point minionPointRight = CalamityUtils.ToSafeTileCoordinates(Projectile.BottomRight);
for (int coordX = minionPointLeft.X; coordX <= minionPointRight.X; coordX++)
{
if (Main.tile[coordX, minionPointLeft.Y].IsTileSolidGround())
return true;
}
return false;
}
/// <summary>
/// Checks whether the minion is inside a tile or not.<br/>
/// It checks if there's tiles in the diagonals of the minion's hitbox.
/// </summary>
/// <returns><see langword="true"/> if there's a tile inside the minion, otherwise <see langword="false"/></returns>
public bool IsMinionInsideTile()
{
Point topLeft = CalamityUtils.ToSafeTileCoordinates(Projectile.TopLeft);
Point bottomRight = CalamityUtils.ToSafeTileCoordinates(Projectile.BottomRight);
for (int coordX = topLeft.X; coordX <= bottomRight.X; coordX++)
{
if (Main.tile[coordX, (int)Utils.Remap(coordX, topLeft.X, bottomRight.X, topLeft.Y, bottomRight.Y)].IsTileSolid())
return true;
}
Point topRight = CalamityUtils.ToSafeTileCoordinates(Projectile.TopRight);
Point bottomLeft = CalamityUtils.ToSafeTileCoordinates(Projectile.BottomLeft);
for (int coordX = bottomLeft.X; coordX >= topRight.X; coordX--)
{
if (Main.tile[coordX, (int)Utils.Remap(coordX, bottomLeft.X, topRight.X, bottomLeft.Y, bottomRight.Y)].IsTileSolid())
return true;
}
return false;
Rectangle inflatedMinionHitbox = Projectile.getRect();
inflatedMinionHitbox.Inflate(1, 0);
bool stuckOnLeftTile = Main.tile[new Vector2(inflatedMinionHitbox.X, inflatedMinionHitbox.Y + inflatedMinionHitbox.Height - 17).ToSafeTileCoordinates()].IsTileSolid();
bool stuckOnRightTile = Main.tile[new Vector2(inflatedMinionHitbox.X + inflatedMinionHitbox.Width, inflatedMinionHitbox.Y + inflatedMinionHitbox.Height - 17).ToSafeTileCoordinates()].IsTileSolid();
return stuckOnLeftTile || stuckOnRightTile;
}
#endregion
@@ -0,0 +1,69 @@
using CalamityMod.Graphics.Primitives;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon
{
public class LiliesOfEternityBullet : ModProjectile, ILocalizedModType, IPixelatedPrimitiveRenderer
{
public new string LocalizationCategory => "Projectiles.Summon";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetStaticDefaults()
{
ProjectileID.Sets.MinionShot[Type] = true;
ProjectileID.Sets.TrailingMode[Type] = 2;
ProjectileID.Sets.TrailCacheLength[Type] = 8;
}
public override void SetDefaults()
{
Projectile.DamageType = DamageClass.Summon;
Projectile.width = Projectile.height = 16;
Projectile.timeLeft = 300;
Projectile.penetrate = -1;
Projectile.localNPCHitCooldown = -1;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.usesLocalNPCImmunity = true;
}
public override void AI()
{
if (Main.dedServ)
return;
Dust trailDust = Dust.NewDustPerfect(
Projectile.Center + Main.rand.NextVector2Circular(8f, 8f),
64,
Projectile.velocity * Main.rand.NextFloat(0.01f, 0.05f),
Scale: Main.rand.NextFloat(1f, 1.2f));
trailDust.noGravity = true;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
Projectile.velocity = Vector2.Zero;
Projectile.timeLeft = 10;
}
private float PrimitiveWidthFunction(float completionRatio)
{
float trailPoint = 0.1f;
return completionRatio > trailPoint ? Utils.Remap(completionRatio, trailPoint, 1f, 12f, 0f) : Utils.Remap(completionRatio, trailPoint, 0f, 12f, 0f);
}
private Color PrimitiveColorFunction(float completionRatio) => Color.Lerp(Color.DarkGoldenrod, Color.LightGoldenrodYellow, completionRatio);
public void RenderPixelatedPrimitives(SpriteBatch spriteBatch)
{
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, pixelate: true, shader: GameShaders.Misc["CalamityMod:TrailStreak"]));
}
}
}
+107
View File
@@ -0,0 +1,107 @@
using System;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using static CalamityMod.Items.Weapons.Summon.LiliesOfFinality;
namespace CalamityMod.Projectiles.Summon
{
public class LiliesOfFinalityAoE : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Summon";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
private ref float ArianeID => ref Projectile.ai[0];
private ref float Timer => ref Projectile.ai[1];
private Projectile Ariane;
private const int TimeToFullScale = 120;
public override void SetDefaults()
{
Projectile.DamageType = DamageClass.Summon;
Projectile.width = Projectile.height = Ariane_AoESize;
Projectile.localNPCHitCooldown = 30;
Projectile.penetrate = -1;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.usesLocalNPCImmunity = true;
Projectile.netImportant = true;
}
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, Projectile.width / 2f, targetHitbox);
public override void AI()
{
if (Ariane != null && Ariane.active && Ariane.owner == Projectile.owner && Ariane.type == ModContent.ProjectileType<LiliesOfFinalityAriane>() && Ariane.ModProjectile<LiliesOfFinalityAriane>().State == LiliesOfFinalityAriane.AIState.Attack)
Projectile.timeLeft = 2;
Projectile.Center = Ariane.Center;
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (!Main.dedServ)
{
float currentScale = Utils.Remap(Timer, 0f, TimeToFullScale, 0f, Projectile.width / 2f);
int circleDustAmount = (int)Utils.Remap(Timer, 0f, TimeToFullScale, 5f, 40f) + Main.rand.Next(20);
for (int i = 0; i < circleDustAmount; i++)
{
if (Main.rand.NextBool(20))
{
float angle = MathHelper.TwoPi / circleDustAmount * i;
Vector2 position = angle.ToRotationVector2() * (currentScale + Main.rand.NextFloat(10f));
Particle fakeDust = new ArianeFakeDust(
Projectile,
position + Main.rand.NextVector2Circular(15f, 15f),
Vector2.Zero,
Color.Red,
Main.rand.NextFloat(1.5f, 2.5f),
120);
GeneralParticleHandler.SpawnParticle(fakeDust);
}
}
int eyeDustAmount = (int)Utils.Remap(Timer, 0f, TimeToFullScale, 0f, 20f);
for (int i = 0; i < eyeDustAmount; i++)
{
if (Main.rand.NextBool(15))
{
float interpolator = Main.rand.NextFloat();
float maxOffsetX = Utils.Remap(Timer, 0f, TimeToFullScale, 0f, 450f);
float maxOffsetY = Utils.Remap(Timer, 0f, TimeToFullScale, 0f, 200f);
Vector2 xPosition = Vector2.UnitX * MathHelper.Lerp(-maxOffsetX, maxOffsetX, interpolator);
Vector2 yPosition = Vector2.UnitY * MathHelper.Lerp(0f, maxOffsetY, MathF.Pow(CalamityUtils.Convert01To010(interpolator), 0.7f)) * Main.rand.NextBool().ToDirectionInt();
Particle fakeDust = new ArianeFakeDust(
Projectile,
xPosition + yPosition + Main.rand.NextVector2Circular(15f, 15f),
Vector2.Zero,
Color.Crimson * 0.8f,
Main.rand.NextFloat(2f, 2.5f),
120);
GeneralParticleHandler.SpawnParticle(fakeDust);
}
}
Dust insideDust = Dust.NewDustPerfect(
Projectile.Center + Main.rand.NextVector2Circular(currentScale, currentScale),
CommonDustID,
Main.rand.NextVector2Circular(3f, 3f),
Scale: Main.rand.NextFloat(0.8f, 1.2f));
insideDust.noGravity = true;
}
Timer++;
}
public override void OnSpawn(IEntitySource source) => Ariane = Main.projectile[(int)ArianeID];
public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) => modifiers.SourceDamage *= Ariane_AoEDMGMultiplier;
}
}
@@ -0,0 +1,381 @@
using System.IO;
using CalamityMod.Buffs.Summon;
using CalamityMod.Particles;
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using static System.MathF;
using static CalamityMod.Items.Weapons.Summon.LiliesOfFinality;
using static Terraria.ModLoader.ModContent;
namespace CalamityMod.Projectiles.Summon
{
public class LiliesOfFinalityAriane : BaseMinionProjectile
{
#region Members
public enum AIState { Idle, ReturnToOwner, Attack }
public AIState State
{
get => (AIState)Projectile.ai[0];
set
{
Projectile.ai[0] = (float)value;
// The minion'll be able to walk on tiles when they're not in a flying state.
Projectile.tileCollide = value == AIState.Idle;
// Because some states mess with the rotation, we reset it so it doesn't cause visual issues on the states that don't deal with rotation.
Projectile.rotation = 0f;
// When the minion goes into its attack state, it spawns a lingering AoE.
if (value == AIState.Attack && Main.myPlayer == Projectile.owner)
Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ProjectileType<LiliesOfFinalityAoE>(), Projectile.damage, 0f, Projectile.owner, Projectile.whoAmI);
Timer = 0f;
NetUpdate();
}
}
public enum AnimationState { Still, Walk, Fly }
public AnimationState Animation
{
get => (AnimationState)Projectile.ai[1];
set
{
Projectile.ai[1] = (float)value;
switch (value)
{
case AnimationState.Still:
Projectile.width = 32;
FrameAmount = 1;
break;
case AnimationState.Walk:
Projectile.width = 32;
FrameAmount = 9;
break;
case AnimationState.Fly:
Projectile.width = 56;
FrameAmount = 8;
break;
}
// If the animation state is being set to the same thing every frame, don't reset the animation.
// Or if the current frame of animation is outside the amount of frames that the next animation will have, reset it.
if (Animation != value || Projectile.frame + 1 > FrameAmount)
{
Projectile.frame = 0;
Projectile.frameCounter = 0;
}
}
}
private ref float Timer => ref Projectile.ai[2];
/// <summary>
/// The amount of animation frames there is in the current animation.
/// </summary>
private int FrameAmount = 1;
private Projectile Elster;
#endregion
#region Overridden Members
public override int AssociatedProjectileTypeID => ProjectileType<LiliesOfFinalityAriane>();
public override int AssociatedBuffTypeID => BuffType<LiliesOfFinalityBuff>();
public override ref bool AssociatedMinionBool => ref ModdedOwner.LiliesOfFinalityBool;
public override float EnemyDistanceDetection => MaxEnemyDistanceDetection;
public override int AnimationFrames => 18;
public override bool Grounded => true;
public override void SetDefaults()
{
Projectile.width = 32;
Projectile.height = 66;
base.SetDefaults();
}
public override void CheckMinionExistence()
{
Projectile.timeLeft = 2;
if (Elster is null || !Elster.active || Elster.owner != Projectile.owner || Elster.type != ProjectileType<LiliesOfFinalityElster>())
Projectile.Kill();
}
public override void OnSpawn(IEntitySource source)
{
for (int i = 0; i < Main.maxProjectiles; i++)
{
Projectile p = Main.projectile[i];
if (p == null || !p.active || p.owner != Projectile.owner || p.type != ProjectileType<LiliesOfFinalityElster>())
continue;
Elster = p;
break;
}
}
public override bool OnTileCollide(Vector2 oldVelocity) => false;
public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac)
{
// If the projectile's above the player, it can fall through platforms to reach the player.
if (State == AIState.Idle)
fallThrough = Projectile.Bottom.Y < Owner.Top.Y;
return true;
}
public override bool? CanDamage() => false;
#endregion
#region AI
public override void MinionAI()
{
switch (State)
{
case AIState.Idle:
IdleState();
break;
case AIState.ReturnToOwner:
ReturnToOwnerState();
break;
case AIState.Attack:
AttackState();
break;
}
Timer++;
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (Main.dedServ)
return;
if (Elster.ModProjectile<LiliesOfFinalityElster>().State == LiliesOfFinalityElster.AIState.ReturnToOwner || Elster.ModProjectile<LiliesOfFinalityElster>().State == LiliesOfFinalityElster.AIState.AttackFlying)
{
Dust connectionArianeElster = Dust.NewDustPerfect(
Vector2.Lerp(Projectile.Center, Elster.Center, Main.rand.NextFloat()) + Main.rand.NextVector2Circular(5f, 5f),
CommonDustID,
Vector2.Zero,
Scale: Main.rand.NextFloat(0.8f, 1f));
connectionArianeElster.noGravity = true;
}
}
private void IdleState()
{
if (Timer > 15f)
{
if (Target is not null)
{
State = AIState.Attack;
return;
}
if (IsTileBetweenOwnerAndMinionVertically() || !Collision.CanHitLine(Projectile.Center, 1, 1, Owner.Center, 1, 1) || !Projectile.WithinRange(Owner.Center, 960f))
{
State = AIState.ReturnToOwner;
return;
}
if (!Projectile.getRect().Intersects(Elster.getRect()))
{
int walkDirection = Sign(Elster.Center.X - Projectile.Center.X);
float maxSpeed = Utils.Remap(Abs(Elster.Center.X - Projectile.Center.X), 160f, 0f, 6f, 0f);
Projectile.velocity.X += 0.08f * walkDirection;
if (Abs(Projectile.velocity.X) > maxSpeed)
Projectile.velocity.X = maxSpeed * walkDirection;
}
else
{
Projectile.velocity.X *= 0.8f;
Projectile.spriteDirection = Sign(Elster.Center.X - Projectile.Center.X);
Elster.spriteDirection = Sign(Projectile.Center.X - Elster.Center.X);
if (!Main.dedServ && Main.rand.NextBool(100))
{
Vector2 emoteDirection = -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2 * 0.7f);
Particle heart = new LiliesOfFinalityHeartParticle((Main.rand.NextBool() ? Projectile.Center : Elster.Center) + emoteDirection * 15f, emoteDirection * Main.rand.NextFloat(1f, 2f), Main.rand.Next(30, 45), Main.rand.NextFloat(0.6f, 1f));
GeneralParticleHandler.SpawnParticle(heart);
}
}
}
DoGravity();
Collision.StepUp(ref Projectile.position, ref Projectile.velocity, Projectile.width, Projectile.height, ref Projectile.stepSpeed, ref Projectile.gfxOffY);
Projectile.spriteDirection = Sign(Projectile.velocity.X);
Animation = Abs(Projectile.velocity.X) < 0.04f || IsMinionFacingTile() ? AnimationState.Still : AnimationState.Walk;
}
private void ReturnToOwnerState()
{
if (Target is not null)
{
State = AIState.Attack;
return;
}
if (!IsTileBetweenOwnerAndMinionVertically() && Collision.CanHitLine(Projectile.Center, 1, 1, Owner.Center, 1, 1) && Projectile.WithinRange(Owner.Center, 960f))
{
State = AIState.Idle;
Projectile.velocity.Y = 5f * Sign(Projectile.velocity.Y);
return;
}
FlyTowardsPlace(Owner.velocity.Length() + 6f, Owner.Center, Sign(Projectile.velocity.X));
Animation = AnimationState.Fly;
}
private void AttackState()
{
if (Target is not null)
{
Vector2 targetSpot = Elster.Center + new Vector2(-100f * Projectile.spriteDirection, -60f);
if (!Projectile.WithinRange(targetSpot, 8f))
FlyTowardsPlace(Ariane_TargettingFlySpeed, targetSpot, Sign(Target.Center.X - Projectile.Center.X));
else
Projectile.velocity *= 0.8f;
if (Timer >= Ariane_BoltFireRate)
ShootBolt();
Animation = AnimationState.Fly;
}
else
State = AIState.Idle;
}
private void ShootBolt()
{
if (Main.myPlayer != Projectile.owner)
return;
Vector2 shootDirection = Projectile.SafeDirectionTo(Target.Center).RotatedByRandom(MathHelper.PiOver4);
Projectile.NewProjectileDirect(
Projectile.GetSource_FromThis(),
Projectile.Center,
shootDirection * Ariane_BoltProjectileSpeed,
ProjectileType<LiliesOfFinalityBolt>(),
Projectile.damage,
Projectile.knockBack,
Projectile.owner);
Timer = 0f;
NetUpdate();
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (Main.dedServ)
return;
Vector2 visualBoltSpawn = Projectile.Center + shootDirection * Projectile.Size.Length() / 2f;
for (int i = 0; i < 10; i++)
{
Dust shootDust = Dust.NewDustPerfect(
visualBoltSpawn + (Vector2.UnitY * MathHelper.Lerp(-8f, 8f, Main.rand.NextFloat())).RotatedBy(visualBoltSpawn.ToRotation()),
CommonDustID,
shootDirection * Main.rand.NextFloat(3f, 6f),
Scale: Main.rand.NextFloat(0.6f, 0.8f));
shootDust.noGravity = true;
}
Particle outerRing = new DirectionalPulseRing(
visualBoltSpawn,
Vector2.Zero,
Color.Red,
new Vector2(0.4f, 1f),
shootDirection.ToRotation(),
0.05f,
0.3f,
20);
Particle innerRing = new DirectionalPulseRing(
visualBoltSpawn,
Vector2.Zero,
Color.Fuchsia,
new Vector2(0.5f, 1f),
shootDirection.ToRotation(),
0.05f,
0.15f,
20);
GeneralParticleHandler.SpawnParticle(outerRing);
GeneralParticleHandler.SpawnParticle(innerRing);
SoundEngine.PlaySound(new("CalamityMod/Sounds/Custom/SCalSounds/BrimstoneHellblastSound") { Pitch = 0.4f }, Projectile.Center);
}
private void FlyTowardsPlace(float speed, Vector2 place, int spriteDirection)
{
Projectile.velocity = (Projectile.velocity * 20f + Projectile.SafeDirectionTo(place) * speed) / 21f;
Projectile.spriteDirection = spriteDirection;
}
private void NetUpdate()
{
Projectile.netUpdate = true;
if (Projectile.netSpam >= 10)
Projectile.netSpam = 9;
}
#endregion
#region Syncing
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(FrameAmount);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
FrameAmount = reader.ReadInt32();
}
#endregion
#region Drawing & Animation
public override void DoAnimation()
{
if (Animation == AnimationState.Still)
return;
FramesUntilNextAnimationFrame = Animation == AnimationState.Walk ? (int)Utils.Remap(Abs(Projectile.velocity.X), 0f, 6f, 8f, 4f) : 5;
Projectile.frameCounter++;
if (Projectile.frameCounter >= FramesUntilNextAnimationFrame)
{
Projectile.frameCounter = 0;
Projectile.frame = (Projectile.frame + 1) % FrameAmount;
}
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = Request<Texture2D>(Texture).Value;
Texture2D glowTexture = Request<Texture2D>(GlowTexture).Value;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
Rectangle frame = texture.Frame(3, 9, (int)Animation, Projectile.frame);
Vector2 origin = frame.Size() * 0.5f;
SpriteEffects flipSprite = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, flipSprite);
Main.EntitySpriteDraw(glowTexture, drawPosition, frame, Color.White, Projectile.rotation, origin, Projectile.scale, flipSprite);
return false;
}
#endregion
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

+134
View File
@@ -0,0 +1,134 @@
using System;
using CalamityMod.Graphics.Primitives;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Utilities;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
using static CalamityMod.Items.Weapons.Summon.LiliesOfFinality;
namespace CalamityMod.Projectiles.Summon
{
public class LiliesOfFinalityBolt : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Summon";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
private ref float RandomColorOffset => ref Projectile.localAI[0];
private const int TimeBeforeHoming = 10;
private const int TimeDying = 15;
private SlotId LoopingSound;
public override void SetStaticDefaults()
{
ProjectileID.Sets.MinionShot[Type] = true;
ProjectileID.Sets.TrailingMode[Type] = 2;
ProjectileID.Sets.TrailCacheLength[Type] = 6;
}
public override void SetDefaults()
{
Projectile.DamageType = DamageClass.Summon;
Projectile.width = Projectile.height = 16;
Projectile.timeLeft = TimeBeforeHoming + Ariane_BoltTimeHoming + TimeDying;
Projectile.localNPCHitCooldown = -1;
Projectile.penetrate = -1;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.usesLocalNPCImmunity = true;
}
public override void AI()
{
NPC target = Projectile.Center.MinionHoming(MaxEnemyDistanceDetection, Main.player[Projectile.owner]);
if (target is not null && Projectile.timeLeft > TimeDying && Projectile.timeLeft < Ariane_BoltTimeHoming)
{
float turnRate = Utils.Remap(Projectile.timeLeft, Ariane_BoltTimeHoming, TimeDying, Ariane_MinTurnRate, Ariane_MaxTurnRate);
Projectile.velocity = Projectile.velocity.ToRotation().AngleTowards(Projectile.SafeDirectionTo(target.Center).ToRotation(), turnRate).ToRotationVector2() * Ariane_BoltProjectileSpeed;
}
// When the projectile's abut to die, it'll stop in place and spawn some dust to cover the shader suddenly cutting off.
if (Projectile.timeLeft < TimeDying - 1)
{
Projectile.velocity = Vector2.Zero;
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (!Main.dedServ)
{
for (int i = 0; i < 2; i++)
{
Dust fadingDust = Dust.NewDustDirect(
Projectile.position,
Projectile.width,
Projectile.height,
CommonDustID,
Scale: Main.rand.NextFloat(0.8f, 1.2f));
fadingDust.noGravity = true;
}
}
}
Projectile.rotation = Projectile.velocity.ToRotation();
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (Main.dedServ)
return;
if (Main.rand.NextBool())
{
Dust trailDust = Dust.NewDustPerfect(
Projectile.Center + Main.rand.NextVector2Circular(10f, 10f),
CommonDustID,
Projectile.velocity * Main.rand.NextFloat(0.01f, 0.05f),
Scale: Main.rand.NextFloat(0.4f, 0.6f));
trailDust.noGravity = true;
}
if (SoundEngine.TryGetActiveSound(LoopingSound, out var sound) && sound.IsPlaying)
sound.Position = Projectile.Center;
}
public override void OnSpawn(IEntitySource source)
{
// Since we don't want all the projectiles on screen to cycle through the same colors at the same time, we set an initial offset to the color.
RandomColorOffset = Main.rand.NextFloat(100f);
LoopingSound = SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Custom/ArianeShot") with { Volume = 0.2f }, Projectile.Center);
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
// Since we don't want the trail to instantly disappear on hit, we'll make reduce its time alive to near death.
Projectile.timeLeft = TimeDying;
SoundEngine.PlaySound(SoundID.Item70 with { Volume = 0.5f, Pitch = 0.4f }, Projectile.Center);
if (SoundEngine.TryGetActiveSound(LoopingSound, out var sound))
sound.Stop();
}
private float WidthFunction(float completionRatio) => MathHelper.Lerp(0f, 32f, MathF.Pow(completionRatio, 1f / 2.5f));
private Color ColorFunction(float completionRatio)
{
float offsetTime = Main.GlobalTimeWrappedHourly + RandomColorOffset;
float fadeToEnd = MathHelper.Lerp(0.65f, 1f, (float)Math.Cos(-offsetTime * 3f) * 0.5f + 0.5f);
float fadeOpacity = Utils.GetLerpValue(1f, 0.64f, completionRatio, true) * Projectile.Opacity;
Color endColor = Color.Lerp(Color.Fuchsia, Color.Red, (float)Math.Sin(completionRatio * MathHelper.Pi * 1.6f - offsetTime * 4f) * 0.5f + 0.5f);
return Color.Lerp(Color.White, endColor, fadeToEnd) * fadeOpacity;
}
public override bool PreDraw(ref Color lightColor)
{
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak"));
PrimitiveRenderer.RenderTrail(Projectile.oldPos, new PrimitiveSettings(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, pixelate: false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 32);
return false;
}
}
}
@@ -0,0 +1,71 @@
using CalamityMod.Graphics.Primitives;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon
{
public class LiliesOfFinalityBullet : ModProjectile, ILocalizedModType, IPixelatedPrimitiveRenderer
{
public new string LocalizationCategory => "Projectiles.Summon";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override void SetStaticDefaults()
{
ProjectileID.Sets.MinionShot[Type] = true;
ProjectileID.Sets.TrailingMode[Type] = 2;
ProjectileID.Sets.TrailCacheLength[Type] = 8;
}
public override void SetDefaults()
{
Projectile.DamageType = DamageClass.Summon;
Projectile.width = Projectile.height = 16;
Projectile.timeLeft = 300;
Projectile.localNPCHitCooldown = -1;
Projectile.penetrate = -1;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.usesLocalNPCImmunity = true;
}
public override void AI()
{
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (Main.dedServ)
return;
Dust trailDust = Dust.NewDustPerfect(
Projectile.Center + Main.rand.NextVector2Circular(8f, 8f),
64,
Projectile.velocity * Main.rand.NextFloat(0.01f, 0.05f),
Scale: Main.rand.NextFloat(1f, 1.2f));
trailDust.noGravity = true;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
// Since we don't want the trail to instantly disappear on hit, we'll make it stop and reduce its time alive to near death.
Projectile.velocity = Vector2.Zero;
Projectile.timeLeft = 10;
}
private float PrimitiveWidthFunction(float completionRatio)
{
float trailPoint = 0.1f;
return completionRatio > trailPoint ? Utils.Remap(completionRatio, trailPoint, 1f, 16f, 0f) : Utils.Remap(completionRatio, trailPoint, 0f, 16f, 0f);
}
private Color PrimitiveColorFunction(float completionRatio) => Color.Lerp(Color.DarkGoldenrod, Color.LightGoldenrodYellow, completionRatio);
public void RenderPixelatedPrimitives(SpriteBatch spriteBatch)
{
GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Trails/FabstaffStreak"));
PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, pixelate: true, shader: GameShaders.Misc["CalamityMod:TrailStreak"]));
}
}
}
@@ -0,0 +1,398 @@
using System.IO;
using CalamityMod.Buffs.Summon;
using CalamityMod.Particles;
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.Audio;
using static System.MathF;
using static CalamityMod.Items.Weapons.Summon.LiliesOfFinality;
using static Terraria.ModLoader.ModContent;
namespace CalamityMod.Projectiles.Summon
{
public class LiliesOfFinalityElster : BaseMinionProjectile
{
#region Members
public enum AIState { Idle, ReturnToOwner, AttackOnGround, AttackFlying }
public AIState State
{
get => (AIState)Projectile.ai[0];
set
{
Projectile.ai[0] = (float)value;
// Just in case it doesn't reset properly.
HasShotOnce = false;
// The minion'll be able to walk on tiles when they're not in a flying state.
Projectile.tileCollide = value == AIState.Idle || value == AIState.AttackOnGround;
// Because some states mess with the rotation, we reset it so it doesn't cause visual issues on the states that don't deal with rotation.
Projectile.rotation = 0f;
NetUpdate();
}
}
public enum AnimationState { Still, Walk, Fly, Shoot, FlyShoot }
public AnimationState Animation
{
get => (AnimationState)Projectile.ai[1];
set
{
Projectile.ai[1] = (float)value;
switch (value)
{
case AnimationState.Still:
Projectile.width = 32;
Projectile.frame = 0;
FrameAmount = 1;
break;
case AnimationState.Walk:
Projectile.width = 32;
FrameAmount = 9;
break;
case AnimationState.Fly:
Projectile.width = 36;
FrameAmount = 4;
break;
case AnimationState.Shoot:
case AnimationState.FlyShoot:
Projectile.width = 56;
FrameAmount = 7;
break;
}
// If the animation state is being set to the same thing every frame, don't reset the animation.
// Or if the current frame of animation is outside the amount of frames that the next animation will have, reset it.
if (Animation != value || Projectile.frame + 1 > FrameAmount)
{
Projectile.frame = 0;
Projectile.frameCounter = 0;
}
}
}
private ref float Timer => ref Projectile.ai[2];
/// <summary>
/// Because the fire rate is animation frame dependent, it can stay on the same animation for multiple ticks.<br/>
/// We use this bool to only fire once in that span of time.
/// </summary>
private bool HasShotOnce;
/// <summary>
/// The amount of animation frames there is in the current animation.
/// </summary>
private int FrameAmount = 1;
#endregion
#region Overridden Members
public override int AssociatedProjectileTypeID => ProjectileType<LiliesOfFinalityElster>();
public override int AssociatedBuffTypeID => BuffType<LiliesOfFinalityBuff>();
public override ref bool AssociatedMinionBool => ref ModdedOwner.LiliesOfFinalityBool;
public override float EnemyDistanceDetection => MaxEnemyDistanceDetection;
public override int AnimationFrames => 28;
public override bool Grounded => true;
public override void SetDefaults()
{
Projectile.width = 32;
Projectile.height = 56;
base.SetDefaults();
}
public override void CheckMinionExistence()
{
base.CheckMinionExistence();
if (Timer > 10f && Main.player[Projectile.owner].ownedProjectileCounts[ProjectileType<LiliesOfFinalityAriane>()] == 0)
Projectile.Kill();
}
public override bool OnTileCollide(Vector2 oldVelocity) => false;
public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac)
{
// If the projectile's above the player, it can fall through platforms to reach the player.
if (State == AIState.Idle)
fallThrough = Projectile.Bottom.Y < Owner.Top.Y;
return true;
}
public override bool? CanDamage() => false;
#endregion
#region AI
public override void MinionAI()
{
switch (State)
{
case AIState.Idle:
IdleState();
break;
case AIState.ReturnToOwner:
ReturnToOwnerState();
break;
case AIState.AttackOnGround:
AttackOnGroundState();
break;
case AIState.AttackFlying:
AttackFlyingState();
break;
}
Timer++;
}
private void IdleState()
{
if (Timer > 15f)
{
if (Target is not null)
{
State = AIState.AttackOnGround;
return;
}
if (IsTileBetweenOwnerAndMinionVertically() || !Collision.CanHitLine(Projectile.Center, 1, 1, Owner.Center, 1, 1) || !Projectile.WithinRange(Owner.Center, 960f))
{
State = AIState.ReturnToOwner;
return;
}
Vector2 idlePosition = Owner.Center - Vector2.UnitX * 60f * Owner.direction;
if (!Projectile.WithinRange(idlePosition, 8f))
{
int walkDirection = Sign(idlePosition.X - Projectile.Center.X);
float maxSpeed = Utils.Remap(Abs(idlePosition.X - Projectile.Center.X), 160f, 0f, 6f, 0f);
Projectile.velocity.X += 0.08f * walkDirection;
if (Abs(Projectile.velocity.X) > maxSpeed)
Projectile.velocity.X = maxSpeed * walkDirection;
}
else
Projectile.velocity.X = 0f;
}
DoGravity();
Collision.StepUp(ref Projectile.position, ref Projectile.velocity, Projectile.width, Projectile.height, ref Projectile.stepSpeed, ref Projectile.gfxOffY);
Projectile.spriteDirection = Sign(Projectile.velocity.X);
Animation = Abs(Projectile.velocity.X) < 0.04f || IsMinionFacingTile() ? AnimationState.Still : AnimationState.Walk;
}
private void ReturnToOwnerState()
{
if (Target is not null)
{
State = AIState.AttackOnGround;
return;
}
if (!IsTileBetweenOwnerAndMinionVertically() && Collision.CanHitLine(Projectile.Center, 1, 1, Owner.Center, 1, 1) && Projectile.WithinRange(Owner.Center, 960f))
{
State = AIState.Idle;
// Does a little hop to confirm the minion reaches the desired height.
Projectile.velocity.Y = 5f * Sign(Projectile.velocity.Y);
return;
}
FlyTowardsPlace(Owner.velocity.Length() + 6f, Owner.Center, Sign(Projectile.velocity.X), AnimationState.Fly);
Projectile.rotation = MathHelper.ToRadians(Projectile.velocity.Length()) * Sign(Projectile.velocity.X);
ElevationDust(false);
}
private void AttackOnGroundState()
{
if (Target is not null)
{
if (Projectile.Center.Y > Target.Bottom.Y || Projectile.Center.Y < Target.Top.Y)
{
State = AIState.AttackFlying;
return;
}
// If the frame of the animation is the shooting one (and hasn't shot once yet): shoot.
if (Projectile.frame == 2 && !HasShotOnce)
ShootBullet();
// Reset the bool for the next shot.
if (Projectile.frame != 2 && HasShotOnce)
HasShotOnce = false;
DoGravity();
Projectile.velocity.X = 0f;
Projectile.spriteDirection = Sign(Target.Center.X - Projectile.Center.X);
Animation = AnimationState.Shoot;
}
else
State = AIState.Idle;
}
private void AttackFlyingState()
{
if (Target is not null)
{
Vector2 targetSpot = Target.Center - Vector2.UnitX * (Elster_DistanceFromTarget + Target.width / 2f) * Sign(Target.Center.X - Projectile.Center.X);
if (!Projectile.WithinRange(targetSpot, 5f))
FlyTowardsPlace(Elster_TargettingFlySpeed, targetSpot, Sign(Target.Center.X - Projectile.Center.X), AnimationState.FlyShoot);
else
Projectile.velocity *= 0.8f;
// If the frame of the animation is the shooting one (and hasn't shot once yet): shoot.
if (Projectile.frame == 2 && !HasShotOnce)
ShootBullet();
// Reset the bool for the next shot.
if (Projectile.frame != 2 && HasShotOnce)
HasShotOnce = false;
ElevationDust(true);
}
else
State = AIState.Idle;
}
private void FlyTowardsPlace(float speed, Vector2 place, int spriteDirection, AnimationState spriteAnimation)
{
Projectile.velocity = (Projectile.velocity * 20f + Projectile.SafeDirectionTo(place) * speed) / 21f;
Projectile.spriteDirection = spriteDirection;
Animation = spriteAnimation;
}
private void ShootBullet()
{
if (Main.myPlayer != Projectile.owner)
return;
Vector2 bulletSpawnPosition = Projectile.Center - Vector2.UnitX * 15f * Projectile.spriteDirection;
Projectile.NewProjectileDirect(
Projectile.GetSource_FromThis(),
bulletSpawnPosition,
Vector2.UnitX * Elster_BulletProjectileSpeed * Projectile.spriteDirection,
ProjectileType<LiliesOfFinalityBullet>(),
Projectile.damage,
Projectile.knockBack,
Projectile.owner);
HasShotOnce = true;
NetUpdate();
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (Main.dedServ)
return;
Particle shootRing = new DirectionalPulseRing(
Projectile.Center + Vector2.UnitX * Projectile.width / 2f * Projectile.spriteDirection,
Vector2.Zero,
Color.Goldenrod,
new Vector2(0.5f, 1f),
0f,
0.05f,
0.25f,
7);
GeneralParticleHandler.SpawnParticle(shootRing);
SoundEngine.PlaySound(new("CalamityMod/Sounds/Custom/ElsterShot", 4) { Volume = 0.3f }, Projectile.Center);
}
private void ElevationDust(bool shootingState)
{
// If on a dedicated server, don't bother running the visuals and sounds to save resources.
if (Main.dedServ)
return;
Vector2 leftLeg = shootingState ? Projectile.BottomLeft + Vector2.UnitX * (Projectile.spriteDirection == -1 ? 28f : 10f) : Projectile.BottomLeft;
Vector2 rightLeg = shootingState ? Projectile.BottomRight - Vector2.UnitX * (Projectile.spriteDirection == -1 ? 10f : 28f) : Projectile.BottomRight;
if (Main.rand.NextBool())
{
float interpolant = Main.rand.NextFloat();
Dust elevationDust = Dust.NewDustPerfect(
Vector2.Lerp(leftLeg, rightLeg, interpolant),
CommonDustID,
Vector2.UnitY.RotatedByRandom(MathHelper.Lerp(-MathHelper.ToRadians(15f), MathHelper.ToRadians(15f), interpolant) * Main.rand.NextFloat(8f, 12f)),
Scale: Main.rand.NextFloat(1f, 1.2f));
elevationDust.noGravity = true;
}
if (Main.rand.NextBool(4))
{
float interpolant = Main.rand.NextFloat();
Dust elevationDust = Dust.NewDustPerfect(
Vector2.Lerp(leftLeg, rightLeg, interpolant),
CommonDustID,
-Vector2.UnitY * Main.rand.NextFloat(3f, 6f),
Scale: Main.rand.NextFloat(1f, 1.2f));
elevationDust.noGravity = true;
}
}
private void NetUpdate()
{
Projectile.netUpdate = true;
if (Projectile.netSpam >= 10)
Projectile.netSpam = 9;
}
#endregion
#region Syncing
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(HasShotOnce);
writer.Write(FrameAmount);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
HasShotOnce = reader.ReadBoolean();
FrameAmount = reader.ReadInt32();
}
#endregion
#region Drawing & Animation
public override void DoAnimation()
{
if (Animation == AnimationState.Still)
return;
FramesUntilNextAnimationFrame = Animation == AnimationState.Walk ? (int)Utils.Remap(Abs(Projectile.velocity.X), 0f, 6f, 8f, 4f) : 5;
Projectile.frameCounter++;
if (Projectile.frameCounter >= FramesUntilNextAnimationFrame)
{
Projectile.frameCounter = 0;
Projectile.frame = (Projectile.frame + 1) % FrameAmount;
}
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = Request<Texture2D>(Texture).Value;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
Rectangle frame = texture.Frame(5, 9, (int)Animation, Projectile.frame);
Vector2 origin = frame.Size() * 0.5f;
SpriteEffects flipSprite = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, flipSprite);
return false;
}
#endregion
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.