Reworked the Yharon Kindle Staff

This commit is contained in:
Dominic authored and Cameron Ewell committed 2021-10-22 17:52:43 -04:00
1 parent 78018d1876
commit 62be7d3169
4 files changed
+274 -66

No files matched your search

@@ -9,6 +9,7 @@ namespace CalamityMod.Items.Weapons.Summon
public class AngryChickenStaff : ModItem
{
public const int Damage = 300;
public const float ReboundRamDamageFactor = 6f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Yharon's Kindle Staff");
-2
View File
@@ -127,7 +127,5 @@ namespace CalamityMod.Projectiles.Ranged
Main.dust[d].velocity *= 2f;
}
}
}
}
+174 -64
View File
@@ -1,15 +1,21 @@
using CalamityMod.Buffs.Summon;
using CalamityMod.CalPlayer;
using CalamityMod.Items.Weapons.Summon;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon
{
public class SonOfYharon : ModProjectile
{
public Player Owner => Main.player[projectile.owner];
public ref float AttackTimer => ref projectile.ai[0];
public ref float RamCountdown => ref projectile.ai[1];
public ref float RamReboundCountdown => ref projectile.localAI[1];
public const int FireballShootRate = 20;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Son of Yharon");
@@ -22,92 +28,196 @@ namespace CalamityMod.Projectiles.Summon
{
projectile.width = 100;
projectile.height = 100;
projectile.extraUpdates = 1;
projectile.netImportant = true;
projectile.friendly = true;
projectile.ignoreWater = true;
projectile.usesLocalNPCImmunity = true;
projectile.localNPCHitCooldown = 20;
projectile.extraUpdates = 1;
projectile.localNPCHitCooldown = projectile.MaxUpdates * 9;
projectile.minionSlots = 4f;
projectile.timeLeft = 18000;
projectile.timeLeft = 90000;
projectile.penetrate = -1;
projectile.tileCollide = false;
projectile.timeLeft *= 5;
projectile.minion = true;
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(RamReboundCountdown);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
RamReboundCountdown = reader.ReadSingle();
}
public override void AI()
{
Player player = Main.player[projectile.owner];
CalamityPlayer modPlayer = player.Calamity();
if (projectile.localAI[0] == 0f)
{
projectile.Calamity().spawnedPlayerMinionDamageValue = player.MinionDamage();
projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage;
int num501 = 100;
for (int num502 = 0; num502 < num501; num502++)
{
int num503 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 16f), projectile.width, projectile.height - 16, 244, 0f, 0f, 0, default, 1f);
Main.dust[num503].velocity *= 2f;
Main.dust[num503].scale *= 1.15f;
}
projectile.localAI[0] += 1f;
PerformInitialization();
projectile.localAI[0] = 1f;
}
if (player.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue)
// Perform minion checks.
PerformMinionChecks();
// Dynamically adjust damage if it changes.
if (Owner.MinionDamage() != projectile.Calamity().spawnedPlayerMinionDamageValue)
{
int damage2 = (int)((float)projectile.Calamity().spawnedPlayerMinionProjectileDamageValue /
projectile.Calamity().spawnedPlayerMinionDamageValue *
player.MinionDamage());
projectile.damage = damage2;
int trueDamage = (int)(projectile.Calamity().spawnedPlayerMinionProjectileDamageValue / projectile.Calamity().spawnedPlayerMinionDamageValue * Owner.MinionDamage());
projectile.damage = trueDamage;
}
if (Math.Abs(projectile.velocity.X) > 0.2f)
{
projectile.spriteDirection = -projectile.direction;
}
float lightScalar = (float)Main.rand.Next(90, 111) * 0.01f;
lightScalar *= Main.essScale;
Lighting.AddLight(projectile.Center, 1.2f * lightScalar, 0.8f * lightScalar, 0f * lightScalar);
bool correctMinion = projectile.type == ModContent.ProjectileType<SonOfYharon>();
player.AddBuff(ModContent.BuffType<YharonKindleBuff>(), 3600);
if (correctMinion)
{
if (player.dead)
{
modPlayer.aChicken = false;
}
if (modPlayer.aChicken)
{
projectile.timeLeft = 2;
}
}
if (projectile.ai[0] == 2f)
{
// Handle frame logic.
if (projectile.FinalExtraUpdate())
projectile.frameCounter++;
if (projectile.frameCounter > 3)
{
projectile.frame++;
projectile.frameCounter = 0;
}
if (projectile.frame > 2)
{
projectile.frame = 0;
}
projectile.frame = projectile.frameCounter / 5 % Main.projFrames[projectile.type];
NPC potentialTarget = projectile.Center.MinionHoming(2000f, Owner);
// Teleport to the player if extremely far away.
if (!projectile.WithinRange(Owner.Center, 4000f))
{
projectile.Center = Owner.Center + Main.rand.NextVector2Circular(16f, 16f);
projectile.netUpdate = true;
return;
}
// Rebound for a bit after a ram.
if (RamReboundCountdown > 0f)
{
projectile.velocity *= 0.97f;
RamReboundCountdown--;
return;
}
if (potentialTarget is null)
{
DoPlayerHoverMovement();
AttackTimer = 0f;
}
else
{
projectile.frameCounter++;
if (projectile.frameCounter > 12)
AttackTarget(potentialTarget);
AttackTimer++;
}
}
public void PerformInitialization()
{
projectile.Calamity().spawnedPlayerMinionDamageValue = Owner.MinionDamage();
projectile.Calamity().spawnedPlayerMinionProjectileDamageValue = projectile.damage;
for (int i = 0; i < 45; i++)
{
Dust fire = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(55f, 55f), 244);
fire.velocity *= 2f;
fire.scale *= 1.15f;
}
}
public void PerformMinionChecks()
{
bool correctMinion = projectile.type == ModContent.ProjectileType<SonOfYharon>();
Owner.AddBuff(ModContent.BuffType<YharonKindleBuff>(), 3600);
if (!correctMinion)
return;
if (Owner.dead)
Owner.Calamity().aChicken = false;
if (Owner.Calamity().aChicken)
projectile.timeLeft = 2;
}
public void DoPlayerHoverMovement()
{
// Move away from other minions of the same type.
projectile.MinionAntiClump(0.1f);
Vector2 hoverDestination = Owner.Top - Vector2.UnitY * 50f;
if (!projectile.WithinRange(hoverDestination, 60f))
projectile.velocity = (projectile.velocity * 19f + projectile.SafeDirectionTo(hoverDestination) * 11f) / 20f;
// Adjust the sprite direction to point towards the hover destination. This does not happen if already really close
// horizontally to the destination, to prevent direction changing spam.
if (MathHelper.Distance(projectile.Center.X, hoverDestination.X) > 45f)
projectile.spriteDirection = (projectile.Center.X - hoverDestination.X > 0).ToDirectionInt();
}
public void AttackTarget(NPC target)
{
float distanceFromTarget = projectile.Distance(target.Center);
// Approach the target quickly if far enough away.
// Movement becomes sharper the farther away from the target the minion is.
// Also release fireballs.
if (distanceFromTarget > 220f)
{
float interpolantToIdealVelocity = MathHelper.Lerp(0.05f, 0.3f, Utils.InverseLerp(300f, 560f, distanceFromTarget, true));
Vector2 idealVelocity = projectile.SafeDirectionTo(target.Center) * MathHelper.Min(distanceFromTarget, 14f);
projectile.velocity = Vector2.Lerp(projectile.velocity, idealVelocity, interpolantToIdealVelocity);
// Adjust the sprite direction to point towards the hover destination.
projectile.spriteDirection = (projectile.Center.X - target.Center.X > 0).ToDirectionInt();
// Periodically release fireballs at the target.
// They move faster the farther away from the target the minion is.
if (AttackTimer % FireballShootRate == FireballShootRate - 1f)
{
projectile.frame++;
projectile.frameCounter = 0;
}
if (projectile.frame > 3)
{
projectile.frame = 0;
float shootSpeed = (distanceFromTarget - 300f) * 0.015f + 31f;
Main.PlaySound(SoundID.Item73, projectile.Center);
if (Main.myPlayer == projectile.owner)
{
Vector2 shootPosition = projectile.Center + Vector2.UnitX * projectile.spriteDirection * 10f;
Vector2 shootVelocity = (target.Center - shootPosition).SafeNormalize(Vector2.UnitX * projectile.spriteDirection) * shootSpeed;
Projectile.NewProjectile(shootPosition, shootVelocity, ModContent.ProjectileType<YharonMinionFireball>(), projectile.damage, projectile.knockBack * 0.5f, projectile.owner);
}
}
}
projectile.ChargingMinionAI(1000f, 2000f, 3000f, 500f, 1, 30f, 8f, 4f, new Vector2(0f, -60f), 40f, 15.5f, true, true);
// Otherwise ram at the target.
else if (RamCountdown <= 0f)
{
RamCountdown = 60f;
projectile.velocity = projectile.SafeDirectionTo(target.Center, -Vector2.UnitY) * 23f;
projectile.netUpdate = true;
}
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
// Create an explosion and rebound on hitting an NPC if a ram is happening.
if (RamCountdown > 0f)
{
RamCountdown = 0f;
RamReboundCountdown = 30f;
projectile.velocity *= -0.6f;
// Create an explosion of dust.
for (int i = 0; i < 150; i++)
{
Dust fire = Dust.NewDustPerfect(projectile.Center, 244);
fire.velocity = Main.rand.NextVector2Circular(20f, 20f);
fire.scale *= 3f;
fire.noGravity = true;
fire = Dust.NewDustPerfect(projectile.Center, 244);
fire.velocity *= Main.rand.NextVector2Circular(8f, 8f);
fire.scale *= 2f;
}
projectile.netUpdate = true;
}
}
public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
// Do much more damage during a ram than otherwise.
if (RamCountdown > 0f)
damage = (int)(damage * AngryChickenStaff.ReboundRamDamageFactor);
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
@@ -116,7 +226,7 @@ namespace CalamityMod.Projectiles.Summon
Texture2D texture2D13 = Main.projectileTexture[projectile.type];
int num214 = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type];
int y6 = num214 * projectile.frame;
Main.spriteBatch.Draw(texture2D13, projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, num214)), projectile.GetAlpha(lightColor), projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), projectile.scale, spriteEffects, 0f);
Main.spriteBatch.Draw(texture2D13, projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Rectangle(0, y6, texture2D13.Width, num214), projectile.GetAlpha(lightColor), projectile.rotation, new Vector2(texture2D13.Width / 2f, num214 / 2f), projectile.scale, spriteEffects, 0f);
return false;
}
}
@@ -0,0 +1,99 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon
{
public class YharonMinionFireball : ModProjectile
{
public ref float InitialSpeed => ref projectile.ai[0];
public override string Texture => "CalamityMod/Projectiles/Boss/YharonFireball";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Dragon Fireball");
Main.projFrames[projectile.type] = 5;
ProjectileID.Sets.TrailingMode[projectile.type] = 2;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 8;
}
public override void SetDefaults()
{
projectile.width = 34;
projectile.height = 34;
projectile.friendly = true;
projectile.minion = true;
projectile.ignoreWater = true;
projectile.tileCollide = false;
projectile.minionSlots = 0f;
projectile.alpha = 255;
projectile.penetrate = 1;
projectile.timeLeft = 300;
}
public override void AI()
{
projectile.frameCounter++;
projectile.frame = projectile.frameCounter / 5 % Main.projFrames[projectile.type];
projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2;
projectile.Opacity = MathHelper.Clamp(projectile.Opacity + 0.075f, 0f, 1f);
if (InitialSpeed == 0f)
{
InitialSpeed = projectile.velocity.Length();
projectile.netUpdate = true;
return;
}
NPC potentialTarget = projectile.Center.MinionHoming(600f, Main.player[projectile.owner]);
if (potentialTarget != null)
projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(potentialTarget.Center) * InitialSpeed, 0.1f);
}
public override Color? GetAlpha(Color lightColor) => new Color(200, 200, 200, projectile.alpha);
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D texture = Main.projectileTexture[projectile.type];
Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame);
SpriteEffects direction = SpriteEffects.None;
if (projectile.spriteDirection == -1)
direction = SpriteEffects.FlipHorizontally;
if (CalamityConfig.Instance.Afterimages)
{
for (int i = 0; i < projectile.oldPos.Length; i++)
{
Vector2 afterimageDrawPosition = projectile.oldPos[i] + projectile.Size / 2f - Main.screenPosition + new Vector2(0f, projectile.gfxOffY);
Color afterimageColor = projectile.GetAlpha(lightColor) * ((projectile.oldPos.Length - i) / (float)projectile.oldPos.Length);
spriteBatch.Draw(texture, afterimageDrawPosition, frame, afterimageColor, projectile.rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f);
}
}
Vector2 drawPosition = projectile.Center - Main.screenPosition - Vector2.UnitY * projectile.gfxOffY;
spriteBatch.Draw(texture, drawPosition, frame, projectile.GetAlpha(lightColor), projectile.rotation, frame.Size() * 0.5f, projectile.scale, direction, 0f);
return false;
}
public override void Kill(int timeLeft)
{
Main.PlaySound(SoundID.Item74, projectile.Center);
for (int d = 0; d < 2; d++)
Dust.NewDust(projectile.position, projectile.width, projectile.height, 55, 0f, 0f, 50, default, 1.5f);
for (int d = 0; d < 20; d++)
{
Dust fire = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 244, 0f, 0f, 0, default, 2.2f);
fire.noGravity = true;
fire.velocity *= 4f;
fire = Dust.NewDustDirect(projectile.position, projectile.width, projectile.height, 244, 0f, 0f, 50, default, 1.5f);
fire.velocity *= 5f;
fire.noGravity = true;
}
}
}
}