Files
CalamityModPublic/NPCs/NormalNPCs/MantisShrimp.cs
T

152 lines
5.4 KiB
C#

using CalamityMod.Items.Placeables.Banners;
using CalamityMod.Items.Weapons.Melee;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Utilities;
namespace CalamityMod.NPCs.NormalNPCs
{
public class MantisShrimp : ModNPC
{
public override void SetStaticDefaults()
{
Main.npcFrameCount[NPC.type] = 6;
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers()
{
SpriteDirection = 1
};
NPCID.Sets.NPCBestiaryDrawOffset[Type] = value;
}
public override void SetDefaults()
{
NPC.damage = 200;
NPC.width = 40;
NPC.height = 24;
NPC.defense = 10;
NPC.DR_NERD(0.1f);
NPC.lifeMax = 30;
NPC.aiStyle = NPCAIStyleID.Fighter;
AIType = NPCID.Crab;
NPC.value = Item.buyPrice(0, 0, 1, 0);
NPC.HitSound = SoundID.NPCHit1;
NPC.DeathSound = SoundID.NPCDeath1;
Banner = NPC.type;
BannerItem = ModContent.ItemType<MantisShrimpBanner>();
NPC.Calamity().VulnerableToHeat = false;
NPC.Calamity().VulnerableToSickness = true;
NPC.Calamity().VulnerableToElectricity = true;
NPC.Calamity().VulnerableToWater = false;
// Scale stats in Expert and Master
CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC);
CalamityGlobalNPC.AdjustMasterModeStatScaling(NPC);
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
{
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Ocean,
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.MantisShrimp")
});
}
public override void AI()
{
NPC.spriteDirection = (NPC.direction > 0) ? -1 : 1;
float targetDist = (Main.player[NPC.target].Center - NPC.Center).Length();
targetDist *= 0.0025f;
if ((double)targetDist > 1.5)
{
targetDist = 1.5f;
}
float maxSpeed;
if (Main.expertMode)
{
maxSpeed = 3f - targetDist;
}
else
{
maxSpeed = 2.5f - targetDist;
}
maxSpeed *= (CalamityWorld.death ? 1.2f : CalamityWorld.revenge ? 1f : 0.8f);
if (NPC.velocity.X < -maxSpeed || NPC.velocity.X > maxSpeed)
{
if (NPC.velocity.Y == 0f)
{
NPC.velocity *= 0.8f;
}
}
else if (NPC.velocity.X < maxSpeed && NPC.direction == 1)
{
NPC.velocity.X = NPC.velocity.X + 1f;
if (NPC.velocity.X > maxSpeed)
{
NPC.velocity.X = maxSpeed;
}
}
else if (NPC.velocity.X > -maxSpeed && NPC.direction == -1)
{
NPC.velocity.X = NPC.velocity.X - 1f;
if (NPC.velocity.X < -maxSpeed)
{
NPC.velocity.X = -maxSpeed;
}
}
}
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
{
if (Main.netMode != NetmodeID.MultiplayerClient)
Projectile.NewProjectile(NPC.GetSource_FromAI(), target.Center, Vector2.Zero, ProjectileID.SolarWhipSwordExplosion, 0, 0f, Main.myPlayer);
}
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 float SpawnChance(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.PlayerSafe || !Main.hardMode || spawnInfo.Player.Calamity().ZoneSulphur)
return 0f;
return SpawnCondition.OceanMonster.Chance * 0.2f;
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
npcLoot.AddIf(() => NPC.downedPlantBoss, ModContent.ItemType<MantisClaws>(), 5);
}
public override void HitEffect(NPC.HitInfo hit)
{
for (int k = 0; k < 3; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 1f);
}
if (NPC.life <= 0)
{
for (int k = 0; k < 15; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 1f);
}
if (Main.netMode != NetmodeID.Server)
{
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("MantisShrimp").Type, 1f);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("MantisShrimp2").Type, 1f);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("MantisShrimp3").Type, 1f);
}
}
}
}
}