Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override bool PreAI()
- {
- if (npc.ai[3] > 0)
- npc.realLife = (int)npc.ai[3];
- if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead)
- npc.TargetClosest(true);
- if (Main.player[npc.target].dead && npc.timeLeft > 300)
- npc.timeLeft = 300;
- if (Main.netMode != 1)
- {
- if (!Main.npc[(int)npc.ai[1]].active)
- {
- npc.life = 0;
- npc.HitEffect(0, 10.0);
- npc.active = false;
- NetMessage.SendData(28, -1, -1, "", npc.whoAmI, -1f, 0.0f, 0.0f, 0, 0, 0);
- }
- }
- if (npc.ai[1] < (double)Main.npc.Length)
- {
- // We're getting the center of this NPC.
- Vector2 npcCenter = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
- // Then using that center, we calculate the direction towards the 'parent NPC' of this NPC.
- float dirX = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - npcCenter.X;
- float dirY = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - npcCenter.Y;
- // We then use Atan2 to get a correct rotation towards that parent NPC.
- npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f;
- // We also get the length of the direction vector.
- float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY);
- // We calculate a new, correct distance.
- float dist = (length - (float)npc.width) / length;
- float posX = dirX * dist;
- float posY = dirY * dist;
- // Reset the velocity of this NPC, because we don't want it to move on its own
- npc.velocity = Vector2.Zero;
- // And set this NPCs position accordingly to that of this NPCs parent NPC.
- npc.position.X = npc.position.X + posX;
- npc.position.Y = npc.position.Y + posY;
- }
- return false;
- }
- public override void AI()
- {
- npc.ai[0]++;
- Player P = Main.player[npc.target];
- if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
- {
- npc.TargetClosest(true);
- }
- npc.netUpdate = true;
- npc.ai[1]++;
- if (npc.ai[1] >= Main.rand.Next(800, 1200)) //800 is projectile fire rate
- {
- Main.NewText("DEBUG");
- float Speed = 10f; //projectile speed
- Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
- int damage = 100; //projectile damage
- int type = mod.ProjectileType("SuperVileSpit"); //put your projectile name here
- Main.PlaySound(SoundID.NPCHit8);
- float rotation = (float)Math.Atan2(npc.Center.Y - (P.position.Y + (P.height * 0.5f)), npc.Center.X - (P.position.X + (P.width * 0.5f)));
- int num54 = Projectile.NewProjectile(npc.Center.X, npc.Center.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
- npc.ai[1] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement