using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader.IO;
using Terraria.UI;
using Terraria.Utilities;
using NewJourney.Tiles;
using Terraria;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using NewJourney.Projectiles;
namespace NewJourney.NPCs
{
public class StuffedSlime : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Stuffed Slime");
}
public override void SetDefaults()
{
npc.width = 20;
npc.height = 20;
npc.damage = 6;
npc.defense = 4;
npc.lifeMax = 60;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.value = 50f;
npc.knockBackResist = 1f;
npc.noGravity = false;
npc.scale = 1f;
npc.aiStyle = -1;
npc.buffImmune[20] = true;
npc.buffImmune[24] = true;
Main.npcFrameCount[npc.type] = 2;
animationType = 535;
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.player.ZoneOverworldHeight && Main.dayTime)
return SpawnCondition.OverworldDaySlime.Chance * 0.1f;
return SpawnCondition.OverworldNight.Chance * 0.05f;
}
public override void NPCLoot()
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 23, Main.rand.Next(1, 20));
}
private const int AI_State_Slot = 0;
private const int AI_Timer_Slot = 1;
private const int AI_Shoot_Time_Slot = 2;
private const int State_Asleep = 0;
private const int State_Slime = 1;
private const int State_ShootSlime = 2;
public float AI_State {
get => npc.ai[AI_State_Slot];
set => npc.ai[AI_State_Slot] = value;
}
public float AI_Timer {
get => npc.ai[AI_Timer_Slot];
set => npc.ai[AI_Timer_Slot] = value;
}
public float AI_ShootTime {
get => npc.ai[AI_Shoot_Time_Slot];
set => npc.ai[AI_Shoot_Time_Slot] = value;
}
public override void AI()
{
if (AI_State == State_Asleep) {
npc.TargetClosest(true);
if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f) {
AI_State = State_Slime;
AI_Timer = 0;
Main.PlaySound(SoundID.NPCHit1, npc.position);
}
}
else if (AI_State == State_Slime) {
if (Main.player[npc.target].Distance(npc.Center) < 750f) {
AI_Timer++;
if (AI_Timer == 1) {
npc.TargetClosest(true);
npc.velocity = new Vector2(npc.direction * 2, -2f);
}
else if (AI_Timer >= 360) {
Vector2 velocity = player.Center - npc.Center;
float magnitude = Magnitude(velocity);
int type = 468;
if (magnitude > 0)
{
velocity *= 18 / magnitude;
}
else
{
velocity = new Vector2(0f, 5f);
}
Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, mod.ProjectileType("SlimeBall"), 30, 3f, Main.myPlayer, 1, 8);
Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, 605, 30, 3f, Main.myPlayer, 4, 4);
AI_State = State_ShootSlime;
AI_Timer = 0;
Main.PlaySound(SoundID.NPCHit1, npc.position);
}
}
}
else if (AI_State == State_ShootSlime) {
npc.aiStyle = -1;
AI_Timer += 1;
if (AI_Timer == 1 && Main.netMode != NetmodeID.MultiplayerClient) {
AI_ShootTime = Main.rand.NextBool() ? 150 : 200;
npc.netUpdate = true;
Vector2 velocity = player.Center - npc.Center;
float magnitude = Magnitude(velocity);
int type = 468;
if (magnitude > 0)
{
velocity *= 18 / magnitude;
}
else
{
velocity = new Vector2(0f, 5f);
}
Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, mod.ProjectileType("SlimeBall"), 30, 3f, Main.myPlayer, 1, 8);
Projectile.NewProjectile((int)npc.position.X, (int)npc.position.Y, 0, -1, 605, 30, 3f, Main.myPlayer, 4, 4);
}
if (AI_Timer > AI_ShootTime) {
AI_State = State_Slime;
AI_Timer = 0;
Main.PlaySound(SoundID.NPCHit1, npc.position);
}
}
}
private const int Frame_Slime_1 = 0;
private const int Frame_Slime_2 = 1;
public override void FindFrame(int frameHeight) {
npc.spriteDirection = npc.direction;
npc.frameCounter++;
if (npc.frameCounter < 10) {
npc.frame.Y = Frame_Slime_1 * frameHeight;
}
else if (npc.frameCounter < 20) {
npc.frame.Y = Frame_Slime_2 * frameHeight;
}
else {
npc.frameCounter = 0;
}
}
}
}