Files
CalamityModPublic/NPCs/CalClone/CalamitasClone.cs
T
GinYuH ba50bb246f split client and server configs
rebased by Ozzatron 15AUG2024 to fix conflicts
2024-08-15 16:54:43 -04:00

324 lines
14 KiB
C#

using System.IO;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Dusts;
using CalamityMod.Events;
using CalamityMod.Items.Accessories;
using CalamityMod.Items.Armor.Vanity;
using CalamityMod.Items.LoreItems;
using CalamityMod.Items.Materials;
using CalamityMod.Items.Placeables.Furniture.BossRelics;
using CalamityMod.Items.Placeables.Furniture.DevPaintings;
using CalamityMod.Items.Placeables.Furniture.Trophies;
using CalamityMod.Items.TreasureBags;
using CalamityMod.Items.Weapons.Magic;
using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Items.Weapons.Ranged;
using CalamityMod.Items.Weapons.Summon;
using CalamityMod.NPCs.CalamityAIs.CalamityBossAIs;
using CalamityMod.NPCs.TownNPCs;
using CalamityMod.Sounds;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using ReLogic.Utilities;
using Terraria;
using Terraria.Audio;
using Terraria.GameContent;
using Terraria.GameContent.Bestiary;
using Terraria.GameContent.ItemDropRules;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.NPCs.CalClone
{
[AutoloadBossHead]
public class CalamitasClone : ModNPC
{
public static Asset<Texture2D> GlowTexture;
public static readonly SoundStyle BulletHellWarning = new("CalamityMod/Sounds/Custom/CalamitasClone/BulletHellEnding");
public static readonly SoundStyle BulletHellEnd = new("CalamityMod/Sounds/Custom/CalamitasClone/BulletHellEnd");
public static readonly SoundStyle ChargeSound = new("CalamityMod/Sounds/Custom/CalamitasClone/CalCloneDash", 3);
public SlotId BulletHellWarnSlot;
public override void SetStaticDefaults()
{
Main.npcFrameCount[NPC.type] = 6;
NPCID.Sets.TrailingMode[NPC.type] = 1;
NPCID.Sets.BossBestiaryPriority.Add(Type);
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers()
{
Scale = 0.65f,
PortraitScale = 0.65f
};
value.Position.Y -= 10f;
NPCID.Sets.NPCBestiaryDrawOffset[Type] = value;
NPCID.Sets.MPAllowedEnemies[Type] = true;
if (!Main.dedServ)
{
GlowTexture = ModContent.Request<Texture2D>(Texture + "Glow", AssetRequestMode.AsyncLoad);
}
}
public override void SetDefaults()
{
NPC.Calamity().canBreakPlayerDefense = true;
NPC.GetNPCDamage();
NPC.npcSlots = 14f;
NPC.width = 120;
NPC.height = 120;
if (CalamityWorld.death || BossRushEvent.BossRushActive)
NPC.scale *= 0.8f;
NPC.defense = (CalamityWorld.death || BossRushEvent.BossRushActive) ? 12 : 25;
NPC.value = Item.buyPrice(0, 50, 0, 0);
NPC.DR_NERD((CalamityWorld.death || BossRushEvent.BossRushActive) ? 0.075f : 0.15f);
NPC.LifeMaxNERB(37500, 45000, 520000);
NPC.aiStyle = -1;
AIType = -1;
NPC.knockBackResist = 0f;
NPC.boss = true;
NPC.noGravity = true;
NPC.noTileCollide = true;
NPC.HitSound = SoundID.NPCHit4;
NPC.DeathSound = SoundID.NPCDeath14;
NPC.Calamity().VulnerableToHeat = false;
NPC.Calamity().VulnerableToCold = true;
NPC.Calamity().VulnerableToWater = true;
// Scale HP in Master
CalamityGlobalNPC.AdjustMasterModeStatScaling(NPC, true);
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
{
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Times.NightTime,
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface,
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Calamitas")
});
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(NPC.dontTakeDamage);
writer.Write(NPC.localAI[0]);
writer.Write(NPC.localAI[1]);
writer.Write(NPC.localAI[2]);
writer.Write(NPC.localAI[3]);
for (int i = 0; i < 4; i++)
writer.Write(NPC.Calamity().newAI[i]);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
NPC.dontTakeDamage = reader.ReadBoolean();
NPC.localAI[0] = reader.ReadSingle();
NPC.localAI[1] = reader.ReadSingle();
NPC.localAI[2] = reader.ReadSingle();
NPC.localAI[3] = reader.ReadSingle();
for (int i = 0; i < 4; i++)
NPC.Calamity().newAI[i] = reader.ReadSingle();
}
public override void FindFrame(int frameHeight)
{
NPC.frameCounter += 0.15f;
NPC.frameCounter %= Main.npcFrameCount[NPC.type];
int frame = (int)NPC.frameCounter;
NPC.frame.Y = frame * frameHeight;
}
public override void AI()
{
CalamitasCloneAI.VanillaCalamitasCloneAI(NPC, Mod, BulletHellWarnSlot);
}
public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
SpriteEffects spriteEffects = SpriteEffects.None;
if (NPC.spriteDirection == 1)
spriteEffects = SpriteEffects.FlipHorizontally;
Texture2D texture = TextureAssets.Npc[NPC.type].Value;
Vector2 origin = new Vector2((float)(texture.Width / 2), (float)(texture.Height / Main.npcFrameCount[NPC.type] / 2));
Color white = Color.White;
float colorLerpAmt = 0.5f;
int afterimageAmt = 7;
if (CalamityClientConfig.Instance.Afterimages)
{
for (int i = 1; i < afterimageAmt; i += 2)
{
Color afterimageColor = drawColor;
afterimageColor = Color.Lerp(afterimageColor, white, colorLerpAmt);
afterimageColor = NPC.GetAlpha(afterimageColor);
afterimageColor *= (float)(afterimageAmt - i) / 15f;
Vector2 offset = NPC.oldPos[i] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos;
offset -= new Vector2((float)texture.Width, (float)(texture.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
offset += origin * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture, offset, NPC.frame, afterimageColor, NPC.rotation, origin, NPC.scale, spriteEffects, 0f);
}
}
Vector2 npcOffset = NPC.Center - screenPos;
npcOffset -= new Vector2((float)texture.Width, (float)(texture.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
npcOffset += origin * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture, npcOffset, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, origin, NPC.scale, spriteEffects, 0f);
texture = GlowTexture.Value;
Color color = Color.Lerp(Color.White, Color.Red, 0.5f);
if (Main.zenithWorld)
{
color = Color.CornflowerBlue;
}
if (CalamityClientConfig.Instance.Afterimages)
{
for (int i = 1; i < afterimageAmt; i++)
{
Color extraAfterimageColor = color;
extraAfterimageColor = Color.Lerp(extraAfterimageColor, white, colorLerpAmt);
extraAfterimageColor *= (float)(afterimageAmt - i) / 15f;
Vector2 offset = NPC.oldPos[i] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos;
offset -= new Vector2((float)texture.Width, (float)(texture.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
offset += origin * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture, offset, NPC.frame, extraAfterimageColor, NPC.rotation, origin, NPC.scale, spriteEffects, 0f);
}
}
spriteBatch.Draw(texture, npcOffset, NPC.frame, color, NPC.rotation, origin, NPC.scale, spriteEffects, 0f);
return false;
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
npcLoot.Add(ItemDropRule.BossBag(ModContent.ItemType<CalamitasCloneBag>()));
// Normal drops: Everything that would otherwise be in the bag
var normalOnly = npcLoot.DefineNormalOnlyDropSet();
{
// Items
int[] items = new int[]
{
ModContent.ItemType<Oblivion>(),
ModContent.ItemType<Animosity>(),
ModContent.ItemType<LashesofChaos>(),
ModContent.ItemType<EntropysVigil>()
};
normalOnly.Add(DropHelper.CalamityStyle(DropHelper.NormalWeaponDropRateFraction, items));
// Equipment
normalOnly.Add(DropHelper.PerPlayer(ModContent.ItemType<VoidofCalamity>()));
normalOnly.Add(ModContent.ItemType<ChaosStone>(), DropHelper.NormalWeaponDropRateFraction);
normalOnly.Add(ModContent.ItemType<Regenator>(), 10);
// Materials
normalOnly.Add(ModContent.ItemType<EssenceofHavoc>(), 1, 8, 10);
normalOnly.Add(ModContent.ItemType<AshesofCalamity>(), 1, 25, 30);
// Vanity
normalOnly.Add(ModContent.ItemType<CalamitasCloneMask>(), 7);
var calVanity = ItemDropRule.Common(ModContent.ItemType<HoodOfCalamity>(), 10);
calVanity.OnSuccess(ItemDropRule.Common(ModContent.ItemType<RobesOfCalamity>()));
normalOnly.Add(calVanity);
normalOnly.Add(ModContent.ItemType<ThankYouPainting>(), ThankYouPainting.DropInt);
}
npcLoot.Add(ModContent.ItemType<CalamitasCloneTrophy>(), 10);
// Relic
npcLoot.DefineConditionalDropSet(DropHelper.RevAndMaster).Add(ModContent.ItemType<CalamitasCloneRelic>());
// GFB Ashes of Annihilation drop
npcLoot.DefineConditionalDropSet(DropHelper.GFB).Add(ModContent.ItemType<AshesofAnnihilation>(), 1, 6, 9, true);
// Lore
npcLoot.AddConditionalPerPlayer(() => !DownedBossSystem.downedCalamitasClone, ModContent.ItemType<LoreCalamitasClone>(), desc: DropHelper.FirstKillText);
}
public override void OnKill()
{
// Don't bother running any of this in Boss Rush.
if (BossRushEvent.BossRushActive)
return;
CalamityGlobalNPC.SetNewBossJustDowned(NPC);
CalamityGlobalNPC.SetNewShopVariable(new int[] { ModContent.NPCType<THIEF>() }, DownedBossSystem.downedCalamitasClone);
// Mark the Calamitas Clone as dead
DownedBossSystem.downedCalamitasClone = true;
CalamityNetcode.SyncWorld();
}
public override void BossLoot(ref string name, ref int potionType) => potionType = ItemID.GreaterHealingPotion;
public override void HitEffect(NPC.HitInfo hit)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, hit.HitDirection, -1f, 0, default, 1f);
}
if (NPC.life <= 0)
{
if (Main.netMode != NetmodeID.Server)
{
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Calamitas").Type, NPC.scale);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Calamitas2").Type, NPC.scale);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Calamitas3").Type, NPC.scale);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Calamitas4").Type, NPC.scale);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Calamitas5").Type, NPC.scale);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Calamitas6").Type, NPC.scale);
}
NPC.position.X = NPC.position.X + (float)(NPC.width / 2);
NPC.position.Y = NPC.position.Y + (float)(NPC.height / 2);
NPC.width = 100;
NPC.height = 100;
NPC.position.X = NPC.position.X - (float)(NPC.width / 2);
NPC.position.Y = NPC.position.Y - (float)(NPC.height / 2);
for (int i = 0; i < 40; i++)
{
int brimDust = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f);
Main.dust[brimDust].velocity *= 3f;
if (Main.rand.NextBool())
{
Main.dust[brimDust].scale = 0.5f;
Main.dust[brimDust].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
}
}
for (int j = 0; j < 70; j++)
{
int brimDust2 = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 3f);
Main.dust[brimDust2].noGravity = true;
Main.dust[brimDust2].velocity *= 5f;
brimDust2 = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f);
Main.dust[brimDust2].velocity *= 2f;
}
}
}
public override void ApplyDifficultyAndPlayerScaling(int numPlayers, float balance, float bossAdjustment)
{
NPC.lifeMax = (int)(NPC.lifeMax * 0.8f * balance * bossAdjustment);
NPC.damage = (int)(NPC.damage * NPC.GetExpertDamageMultiplier());
}
public override bool CanHitPlayer(Player target, ref int cooldownSlot)
{
cooldownSlot = ImmunityCooldownID.Bosses;
return true;
}
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
{
if (hurtInfo.Damage > 0)
target.AddBuff(ModContent.BuffType<BrimstoneFlames>(), 150, true);
}
}
}