public override void PostUpdateMiscEffects() { if (controlled) { player.noFallDmg = true; player.GetModPlayer <ShapeShifterPlayer>().noDraw = true; player.GetModPlayer <ShapeShifterPlayer>().hovercraft = true; Mount mount = player.mount; player.GetModPlayer <ShapeShifterPlayer>().morphed = true; player.GetModPlayer <ShapeShifterPlayer>().overrideWidth = 40; //player.height = 30; player.noItems = true; hoverDrift += (float)Math.PI / 60; player.statDefense = 14 + player.GetModPlayer <ShapeShifterPlayer>().morphDef; if ((player.controlUp || player.controlJump) && hoverHeight < maxHoverHeight) { hoverHeight++; } else if (player.controlDown && hoverHeight > minHoverHeight) { hoverHeight--; } for (; currentHeight < (maxHoverHeight + 10); currentHeight++) { if (!Collision.CanHit(player.Center, 0, 0, player.Center + new Vector2(0, currentHeight), 0, 0)) { break; } } hoverTo = hoverHeight + (float)Math.Sin(hoverDrift) * 16; //player.velocity.Y = ( currentHeight-hoverHeight) * .1f; if (Math.Abs(currentHeight - hoverTo) > hoverSpeed * 4) { if (currentHeight - hoverTo > 0) { player.velocity.Y = hoverSpeed; hoverSpeed = 6f; } if (currentHeight - hoverTo < 0) { player.velocity.Y = -hoverSpeed; hoverSpeed = 6f; } } else { player.velocity.Y = (currentHeight - hoverTo) * .1f; } Vector2 shootFrom = player.Top; shootFrom.Y += 8; float pointAt = (QwertysRandomContent.LocalCursor[player.whoAmI] - shootFrom).ToRotation(); player.GetModPlayer <ShapeShifterPlayer>().tankCannonRotation = QwertyMethods.SlowRotation(player.GetModPlayer <ShapeShifterPlayer>().tankCannonRotation, pointAt, 3); //Main.NewText(player.GetModPlayer<ShapeShifterPlayer>().tankCannonRotation); if (shotCooldown > 0) { shotCooldown--; } if (player.whoAmI == Main.myPlayer && Main.mouseLeft && !player.HasBuff(mod.BuffType("MorphSickness")) && shotCooldown == 0) { shotCooldown = 12; Projectile p = Main.projectile[Projectile.NewProjectile(shootFrom + QwertyMethods.PolarVector(19, player.GetModPlayer <ShapeShifterPlayer>().tankCannonRotation), QwertyMethods.PolarVector(12, player.GetModPlayer <ShapeShifterPlayer>().tankCannonRotation), ProjectileID.GreenLaser, (int)(HovercraftShift.dmg * player.GetModPlayer <ShapeShifterPlayer>().morphDamage), HovercraftShift.kb, player.whoAmI)]; p.magic = false; p.GetGlobalProjectile <MorphProjectile>().morph = true; p.penetrate = 1; p.alpha = 0; if (Main.netMode == 1) { QwertysRandomContent.UpdateProjectileClass(p); } Main.PlaySound(SoundID.Item12, player.Center); } currentHeight = 0; //reset hoverTo = 0; hoverSpeed = 3f; } }
public override void AI() { int num58; int num59; int dust = Dust.NewDust(new Vector2((float)npc.position.X, (float)npc.position.Y), npc.width, npc.height, 6, npc.velocity.X - 6f, npc.velocity.Y, 150, Color.Red, 2f); Main.dust[dust].noGravity = true; int num3 = 60; bool flag2 = false; int num5 = 60; bool flag3 = true; if (npc.velocity.Y == 0f && (npc.velocity.X == 0f && npc.direction < 0)) { npc.velocity.Y -= 8f; npc.velocity.X -= 2f; } else if (npc.velocity.Y == 0f && (npc.velocity.X == 0f && npc.direction > 0)) { npc.velocity.Y -= 8f; npc.velocity.X += 2f; } if (npc.velocity.Y == 0f && ((npc.velocity.X > 0f && npc.direction < 0) || (npc.velocity.X < 0f && npc.direction > 0))) { flag2 = true; } if (npc.position.X == npc.oldPosition.X || npc.ai[3] >= (float)num5 || flag2) { npc.ai[3] += 1f; } else { if ((double)Math.Abs(npc.velocity.X) > 0.9 && npc.ai[3] > 0f) { npc.ai[3] -= 1f; } } if (npc.ai[3] > (float)(num5 * 10)) { npc.ai[3] = 0f; } if (npc.justHit) { npc.ai[3] = 0f; } if (npc.ai[3] == (float)num5) { npc.netUpdate = true; } if ((!Main.dayTime || (double)npc.position.Y > Main.worldSurface * 16.0 || npc.type == 26 || npc.type == 27 || npc.type == 28 || npc.type == 31 || npc.type == 47 || npc.type == 67 || npc.type == 73 || npc.type == 77 || npc.type == 78 || npc.type == 79 || npc.type == 80 || npc.type == 110 || npc.type == 111 || npc.type == 120) && npc.ai[3] < (float)num5) { if ((npc.type == 3 || npc.type == 21 || npc.type == 31 || npc.type == 77 || npc.type == 110 || npc.type == 132) && Main.rand.Next(1000) == 0) { Main.PlaySound(14, (int)npc.position.X, (int)npc.position.Y, 1); } if ((npc.type == 78 || npc.type == 79 || npc.type == 80) && Main.rand.Next(500) == 0) { Main.PlaySound(26, (int)npc.position.X, (int)npc.position.Y, 1); } npc.TargetClosest(true); } else { if (npc.velocity.X == 0f) { if (npc.velocity.Y == 0f) { npc.ai[0] += 1f; if (npc.ai[0] >= 2f) { npc.direction *= -1; npc.spriteDirection = npc.direction; npc.ai[0] = 0f; } } } else { npc.ai[0] = 0f; } if (npc.direction == 0) { npc.direction = 1; } } if (npc.velocity.X < -1.5f || npc.velocity.X > 1.5f) { if (npc.velocity.Y == 0f) { npc.velocity *= 0.8f; } } else { if (npc.velocity.X < 1.5f && npc.direction == 1) { npc.velocity.X = npc.velocity.X + 0.07f; if (npc.velocity.X > 1.5f) { npc.velocity.X = 1.5f; } } else { if (npc.velocity.X > -1.5f && npc.direction == -1) { npc.velocity.X = npc.velocity.X - 0.07f; if (npc.velocity.X < -1.5f) { npc.velocity.X = -1.5f; } } } } bool flag4 = false; if (npc.velocity.Y == 0f) { int num29 = (int)(npc.position.Y + (float)npc.height + 8f) / 16; int num30 = (int)npc.position.X / 16; int num31 = (int)(npc.position.X + (float)npc.width) / 16; for (int l = num30; l <= num31; l++) { if (Main.tile[l, num29] == null) { return; } if (Main.tileSolid[(int)Main.tile[l, num29].type]) { flag4 = true; break; } } } if (flag4) { int num32 = (int)((npc.position.X + (float)(npc.width / 2) + (float)(15 * npc.direction)) / 16f); int num33 = (int)((npc.position.Y + (float)npc.height - 15f) / 16f); if (npc.type == 109) { num32 = (int)((npc.position.X + (float)(npc.width / 2) + (float)((npc.width / 2 + 16) * npc.direction)) / 16f); } if (Main.tile[num32, num33] == null) { Main.tile[num32, num33] = new Tile(); } if (Main.tile[num32, num33 - 1] == null) { Main.tile[num32, num33 - 1] = new Tile(); } if (Main.tile[num32, num33 - 2] == null) { Main.tile[num32, num33 - 2] = new Tile(); } if (Main.tile[num32, num33 - 3] == null) { Main.tile[num32, num33 - 3] = new Tile(); } if (Main.tile[num32, num33 + 1] == null) { Main.tile[num32, num33 + 1] = new Tile(); } if (Main.tile[num32 + npc.direction, num33 - 1] == null) { Main.tile[num32 + npc.direction, num33 - 1] = new Tile(); } if (Main.tile[num32 + npc.direction, num33 + 1] == null) { Main.tile[num32 + npc.direction, num33 + 1] = new Tile(); } if (Main.tile[num32, num33 - 1].type == 10 && flag3) { npc.ai[2] += 1f; npc.ai[3] = 0f; if (npc.ai[2] >= 60f) { npc.velocity.X = 0.5f * (float)(-(float)npc.direction); npc.ai[1] += 1f; npc.ai[2] = 0f; bool flag5 = false; if (npc.ai[1] >= 10f) { flag5 = true; npc.ai[1] = 10f; } WorldGen.KillTile(num32, num33 - 1, true, false, false); if ((Main.netMode != 1 || !flag5) && flag5 && Main.netMode != 1) { if (npc.type == 26) { WorldGen.KillTile(num32, num33 - 1, false, false, false); if (Main.netMode == 2) { } } else { bool flag6 = WorldGen.OpenDoor(num32, num33, npc.direction); if (!flag6) { npc.ai[3] = (float)num5; npc.netUpdate = true; } if (Main.netMode == 2 && flag6) { } } } } } else { if ((npc.velocity.X < 0f && npc.spriteDirection == -1) || (npc.velocity.X > 0f && npc.spriteDirection == 1)) { if (Main.tileSolid[(int)Main.tile[num32, num33 - 2].type]) { if (Main.tileSolid[(int)Main.tile[num32, num33 - 3].type]) { npc.velocity.Y = -8f; npc.netUpdate = true; } else { npc.velocity.Y = -7f; npc.netUpdate = true; } } else { if (Main.tileSolid[(int)Main.tile[num32, num33 - 1].type]) { npc.velocity.Y = -6f; npc.netUpdate = true; } else { if (Main.tileSolid[(int)Main.tile[num32, num33].type]) { npc.velocity.Y = -5f; npc.netUpdate = true; } else { if (npc.directionY < 0 && npc.type != 67) { npc.velocity.Y = -8f; npc.velocity.X = npc.velocity.X * 1.5f; npc.netUpdate = true; } else { if (flag3) { npc.ai[1] = 0f; npc.ai[2] = 0f; } } } } } } } } else { if (flag3) { npc.ai[1] = 0f; npc.ai[2] = 0f; } } if (Main.netMode != 1) { if (Main.rand.Next(80) == 1) { chargeDamageFlag = true; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float rotation = (float)Math.Atan2(vector8.Y - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), vector8.X - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f))); npc.velocity.X = (float)(Math.Cos(rotation) * 10) * -1; npc.velocity.Y = (float)(Math.Sin(rotation) * 10) * -1; npc.ai[1] = 1f; npc.netUpdate = true; } if (chargeDamageFlag == true) { npc.damage = 150; chargeDamage++; } if (chargeDamage >= 106) { chargeDamageFlag = false; npc.damage = 105; chargeDamage = 0; } } if (Main.netMode != 1) { customAi1 += (Main.rand.Next(2, 5) * 0.1f) * npc.scale; if (customAi1 >= 10f) { npc.TargetClosest(true); if ((customspawn1 < 16) && Main.rand.Next(200) == 1) { int Spawned = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), NPCID.Hellbat, 0); Main.npc[Spawned].velocity.Y = -8; Main.npc[Spawned].velocity.X = Main.rand.Next(-10, 10) / 10; npc.ai[0] = 20 - Main.rand.Next(80); customspawn1 += 1f; if (Main.netMode == 2) { } } if ((customspawn2 < 5) && Main.rand.Next(350) == 1) { int Spawned = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), mod.NPCType("BlackKnight"), 0); Main.npc[Spawned].velocity.Y = -8; Main.npc[Spawned].velocity.X = Main.rand.Next(-10, 10) / 10; npc.ai[0] = 20 - Main.rand.Next(80); customspawn2 += 1f; if (Main.netMode == 2) { } } if ((customspawn3 < 1) && Main.rand.Next(550) == 1) { int Spawned = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), mod.NPCType("SwordofLordGwyn"), 0); Main.npc[Spawned].velocity.Y = -8; Main.npc[Spawned].velocity.X = Main.rand.Next(-10, 10) / 10; npc.ai[0] = 20 - Main.rand.Next(80); customspawn3 += 1f; if (Main.netMode == 2) { } } if (Main.rand.Next(100) == 1) { float num48 = 10f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 120; //(int) (14f * npc.scale); int type = mod.ProjectileType("SuddenDeathBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 150; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(200) == 1) { num58 = Projectile.NewProjectile(this.npc.position.X + 20, this.npc.position.Y + 50, Main.rand.Next(-5, 5), Main.rand.Next(-5, 5), mod.ProjectileType("BurningPhantomSeeker"), 90, 0f, Main.myPlayer); Main.projectile[num58].timeLeft = 460; Main.projectile[num58].rotation = Main.rand.Next(700) / 100f; Main.projectile[num58].ai[0] = this.npc.target; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; npc.netUpdate = true; } if (Main.rand.Next(900) == 1) { float num48 = 8f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 170; int type = mod.ProjectileType("ArmageddonBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 0; Main.projectile[num54].aiStyle = -1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(220) == 1) { Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float rotation = (float)Math.Atan2(vector8.Y - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), vector8.X - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f))); npc.velocity.X = (float)(Math.Cos(rotation) * 14) * -1; npc.velocity.Y = (float)(Math.Sin(rotation) * 14) * -1; npc.ai[1] = 1f; npc.netUpdate = true; } if (Main.rand.Next(250) == 1) { float num48 = 18f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y - 100 + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 70; //(int) (14f * npc.scale); int type = mod.ProjectileType("HoldBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 115; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); npc.ai[1] = 1f; } npc.netUpdate = true; } if (Main.rand.Next(500) == 1) { float num48 = 8f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 200; //(int) (14f * npc.scale); int type = mod.ProjectileType("SuddenDeathBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 100; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(150) == 1) { float num48 = 15f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-10, 20); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-10, 30); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 90; int type = mod.ProjectileType("GreatFireballBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 90; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(150) == 1) { float num48 = 15f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-10, 20); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-10, 30); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 90; int type = mod.ProjectileType("GreatFireballBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 90; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(60) == 1) { float num48 = 8f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 100; int type = mod.ProjectileType("BlazeBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 0; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); npc.ai[1] = 1f; } npc.netUpdate = true; } if (Main.rand.Next(200) == 1) { float num48 = 8f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 160; //(int) (14f * npc.scale); int type = mod.ProjectileType("BlackBreath"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 10; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(400) == 1) { float num48 = 13f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y - 1000 + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 90; //(int) (14f * npc.scale); int type = mod.ProjectileType("CrazedPurpleCrush"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 600; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(26) == 1) { float num48 = 14f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y - 400 + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 100; //(int) (14f * npc.scale); int type = mod.ProjectileType("FireBreath"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 3000; Main.projectile[num54].aiStyle = 23; //was 23 Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(66) == 1) //might remove { float num48 = 14f; Vector2 vector8 = new Vector2(npc.position.X - 1800 + (npc.width * 0.5f), npc.position.Y - 600 + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 100; //(int) (14f * npc.scale); int type = mod.ProjectileType("FireBreath"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 200; Main.projectile[num54].aiStyle = 23; //was 23 Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(66) == 1) // might remove { float num48 = 14f; Vector2 vector8 = new Vector2(npc.position.X + 1800 + (npc.width * 0.5f), npc.position.Y - 600 + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 100; //(int) (14f * npc.scale); int type = mod.ProjectileType("FireBreath"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 200; Main.projectile[num54].aiStyle = 23; //was 23 Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(250) == 1) { float num48 = 8f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 75; int type = mod.ProjectileType("IcestormBall"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 0; //was 70 Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); npc.ai[1] = 1f; } npc.netUpdate = true; } if (Main.rand.Next(305) == 1) { float num48 = 7f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 100; //(int) (14f * npc.scale); int type = mod.ProjectileType("FireBreath"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 1900; Main.projectile[num54].aiStyle = 23; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } if (Main.rand.Next(800) == 1) { float num48 = 12f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float speedX = ((Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)) - vector8.X) + Main.rand.Next(-20, 0x15); float speedY = ((Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)) - vector8.Y) + Main.rand.Next(-20, 0x15); if (((speedX < 0f) && (npc.velocity.X < 0f)) || ((speedX > 0f) && (npc.velocity.X > 0f))) { float num51 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY))); num51 = num48 / num51; speedX *= num51; speedY *= num51; int damage = 0; //(int) (14f * npc.scale); int type = mod.ProjectileType("Gravity4Ball"); //44;//0x37; //14; int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, speedX, speedY, type, damage, 0f, Main.myPlayer); Main.projectile[num54].timeLeft = 60; Main.projectile[num54].aiStyle = 1; Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 0x11); customAi1 = 1f; } npc.netUpdate = true; } } } if ((Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height))) { npc.noTileCollide = false; npc.noGravity = false; } if ((!Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height))) { npc.noTileCollide = true; npc.noGravity = true; npc.velocity.Y = 0f; if (npc.position.Y > Main.player[npc.target].position.Y) { npc.velocity.Y -= 3f; } if (npc.position.Y < Main.player[npc.target].position.Y) { npc.velocity.Y += 8f; } } if (Main.player[npc.target].dead) { if (npc.timeLeft > 10) { npc.timeLeft = 5; return; } } }
public override void AI() //this will run every frame { npc.GetGlobalNPC <FortressNPCGeneral>().fortressNPC = true; if (runOnce) { //I put stuff here I want to only run once runOnce = false; } Player player = Main.player[npc.target]; // sets the variable player needed to locate the player npc.TargetClosest(true); // give the npc a target playerDistance = (player.Center - npc.Center).Length(); // finds the distance between this enemy and player timer++; if (clinged) //run when the enemy is clinged to the wall { npc.velocity.X = 0; // set velocity to 0 (no movement) npc.velocity.Y = 0; // set velocity to 0 (no movement) if (timer > 10 && playerDistance < 200 && Collision.CanHit(npc.Center, 0, 0, player.Center, 0, 0)) // this checks if the player is too close and not behind tiles, the timer is so it doesn't immediatly stick to a wall it jumps off { clinged = false; // stop sticking to the wall timer = 0; //reset timer } else if (Collision.CanHit(npc.Center, 0, 0, player.Center, 0, 0) && playerDistance < 600) // this checks if the player is close but not too close and not behind tiles { attackTimer++; // this timer is used so the attack isn't every frame if (attackTimer >= 60) //this will be true when the timer is above 60 frames (1 second) { float shootDirection = (player.Center - npc.Center).ToRotation(); // find the direction the player is in for (int p = -1; p < 2; p++) //this will repeat 3 times for 3 projectiles { Projectile.NewProjectile(npc.Center, QwertyMethods.PolarVector(6, shootDirection + ((float)Math.PI / 8 * p)), mod.ProjectileType("FortressHarpyProjectile"), damage, player.whoAmI); // shoots a projectile } attackTimer = 0; // resets attackTimer needer for the once per second effect } else if (attackTimer > 45) //this will be true when the timer is above 45 frames (.75 seconds) { frame = 3; // change the frame to signal it's about to attack } else { frame = 2; // change the frame to normal cling } } else // player too far away or can't be seen { attackTimer = 0; frame = 2; } } else { //this is for flying animaion it cycles through 2 frames frameTimer++; if (frameTimer % 10 == 0) // true every 10th frame the % gives the remainder of the division problem frameTimer/10 { if (frame == 0) { frame = 1; } else { frame = 0; } } ////////////// verticalFlightTimer += (float)Math.PI / 60; //add this amount to the flight timer every frame, it is used as a radian value so this means it will go 180 degrees every second npc.velocity.Y = (float)Math.Cos(verticalFlightTimer) * verticalSpeed; //the up and down flying motion uses a cosine function, //It is based on a sine wave on a graph as x continually increases Y goes from 1 - -1 //Cosine is the derivitive of Sine the harpy flies in a sine wave pattern //Vertical speed increases the speed it flies up and down othersie it'll just range from 1 - -1 npc.velocity.X = flySpeed * faceDirection; // much simpler than the vertical movement this simply moves in the direction of face direction at the flySpeed if (npc.collideX && timer > 10) { faceDirection *= -1; //flips the direction it faces clinged = true; //start clinging to the wall timer = 0; // reset pattern } } }
public override bool PreAI() { for (int index1 = 0; index1 < 5; ++index1) { float x = projectile.position.X - projectile.velocity.X / 10f * (float)index1; float y = projectile.position.Y - projectile.velocity.Y / 10f * (float)index1; int index2 = Dust.NewDust(new Vector2(x, y), 1, 1, 182, 0.0f, 0.0f, 0, new Color(), 1f); Main.dust[index2].color = new Color(255, 0, 200); Main.dust[index2].alpha = projectile.alpha; Main.dust[index2].position.X = x; Main.dust[index2].position.Y = y; Main.dust[index2].velocity *= 0.0f; Main.dust[index2].noGravity = true; } float direction = (float)Math.Sqrt(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.X); float ai = projectile.localAI[0]; if (ai == 0.0F) { projectile.localAI[0] = direction; ai = direction; } float X = projectile.position.X; float Y = projectile.position.Y; float num5 = 300F; bool flag2 = false; int targetID = 0; if (projectile.ai[1] == 0.0F) { for (int i = 0; i < 200; ++i) { if (Main.npc[i].CanBeChasedBy((object)this, false) && (projectile.ai[1] == 0.0 || projectile.ai[1] == (i + 1))) { float targetPosX = Main.npc[i].position.X + (Main.npc[i].width / 2); float targetPosY = Main.npc[i].position.Y + (Main.npc[i].height / 2); float newDir = Math.Abs(projectile.position.X + (projectile.width / 2) - targetPosX) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - targetPosY); if (newDir < num5 && Collision.CanHit(new Vector2(projectile.position.X + (projectile.width / 2), projectile.position.Y + (projectile.height / 2)), 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) { num5 = newDir; X = targetPosX; Y = targetPosY; flag2 = true; targetID = i; } } } if (flag2) { projectile.ai[1] = (float)(targetID + 1); } flag2 = false; } if (projectile.ai[1] > 0.0) { int index = (int)(projectile.ai[1] - 1.0); if (Main.npc[index].active && Main.npc[index].CanBeChasedBy((object)this, true) && !Main.npc[index].dontTakeDamage) { if ((Math.Abs(projectile.position.X + (projectile.width / 2) - (Main.npc[index].position.X + (Main.npc[index].width / 2))) + Math.Abs(projectile.position.Y + (projectile.height / 2) - (Main.npc[index].position.Y + (float)(Main.npc[index].height / 2)))) < 1000.0) { flag2 = true; X = Main.npc[index].position.X + (float)(Main.npc[index].width / 2); Y = Main.npc[index].position.Y + (float)(Main.npc[index].height / 2); } } else { projectile.ai[1] = 0.0f; } } if (!projectile.friendly) { flag2 = false; } if (flag2) { float newAI = ai; Vector2 vector2 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num8 = X - vector2.X; float num9 = Y - vector2.Y; float num10 = (float)Math.Sqrt((double)num8 * (double)num8 + (double)num9 * (double)num9); float num11 = newAI / num10; float num12 = num8 * num11; float num13 = num9 * num11; int num14 = 8; projectile.velocity.X = (projectile.velocity.X * (float)(num14 - 1) + num12) / (float)num14; projectile.velocity.Y = (projectile.velocity.Y * (float)(num14 - 1) + num13) / (float)num14; } return(false); }
public override void AI() { npc.TargetClosest(true); float num1164 = 4f; float num1165 = 0.75f; Vector2 vector133 = new Vector2(npc.Center.X, npc.Center.Y); float num1166 = Main.player[npc.target].Center.X - vector133.X; float num1167 = Main.player[npc.target].Center.Y - vector133.Y - 200f; float num1168 = (float)Math.Sqrt((double)(num1166 * num1166 + num1167 * num1167)); if (num1168 < 20f) { num1166 = npc.velocity.X; num1167 = npc.velocity.Y; } else { num1168 = num1164 / num1168; num1166 *= num1168; num1167 *= num1168; } if (npc.velocity.X < num1166) { npc.velocity.X = npc.velocity.X + num1165; if (npc.velocity.X < 0f && num1166 > 0f) { npc.velocity.X = npc.velocity.X + num1165 * 2f; } } else if (npc.velocity.X > num1166) { npc.velocity.X = npc.velocity.X - num1165; if (npc.velocity.X > 0f && num1166 < 0f) { npc.velocity.X = npc.velocity.X - num1165 * 2f; } } if (npc.velocity.Y < num1167) { npc.velocity.Y = npc.velocity.Y + num1165; if (npc.velocity.Y < 0f && num1167 > 0f) { npc.velocity.Y = npc.velocity.Y + num1165 * 2f; } } else if (npc.velocity.Y > num1167) { npc.velocity.Y = npc.velocity.Y - num1165; if (npc.velocity.Y > 0f && num1167 < 0f) { npc.velocity.Y = npc.velocity.Y - num1165 * 2f; } } if (npc.position.X + (float)npc.width > Main.player[npc.target].position.X && npc.position.X < Main.player[npc.target].position.X + (float)Main.player[npc.target].width && npc.position.Y + (float)npc.height < Main.player[npc.target].position.Y && Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height) && Main.netMode != 1) { npc.ai[0] += 4f; if (npc.ai[0] > 44f) { npc.ai[0] = 0f; int num1169 = (int)(npc.position.X + 10f + (float)Main.rand.Next(npc.width - 20)); int num1170 = (int)(npc.position.Y + (float)npc.height + 4f); int num184 = 26; if (Main.expertMode) { num184 = 14; } Projectile.NewProjectile((float)num1169, (float)num1170, 0f, 5f, mod.ProjectileType("AcidRain"), num184, 0f, Main.myPlayer, 0f, 0f); return; } } if (Main.rand.NextFloat() < 0.131579f) { Dust dust; Vector2 position = npc.Center; int d = Dust.NewDust(npc.position, npc.width, npc.height + 10, 193, 0, 1f, 0, Color.Green, 0.7f); Main.dust[d].velocity *= .1f; } }
public static void Update() { LockOnHelper._canLockOn = false; if (!PlayerInput.UsingGamepad) { LockOnHelper.SetActive(false); } else { if (--LockOnHelper._lifeTimeArrowDisplay < 0) { LockOnHelper._lifeTimeArrowDisplay = 0; } LockOnHelper.Handle3DSTarget(); if (PlayerInput.Triggers.JustPressed.LockOn && !PlayerInput.WritingText) { LockOnHelper._lifeTimeCounter = 40; LockOnHelper._lifeTimeArrowDisplay = 30; LockOnHelper.HandlePressing(); } if (!LockOnHelper._enabled) { return; } if (LockOnHelper.UseMode == LockOnHelper.LockOnMode.FocusTarget && PlayerInput.Triggers.Current.LockOn) { if (LockOnHelper._lifeTimeCounter <= 0) { LockOnHelper.SetActive(false); return; } --LockOnHelper._lifeTimeCounter; } NPC aimedTarget = LockOnHelper.AimedTarget; if (!LockOnHelper.ValidTarget(aimedTarget)) { LockOnHelper.SetActive(false); } if (LockOnHelper.UseMode == LockOnHelper.LockOnMode.TargetClosest) { LockOnHelper.SetActive(false); LockOnHelper.SetActive(LockOnHelper.CanEnable()); } if (!LockOnHelper._enabled) { return; } Player p = Main.player[Main.myPlayer]; Vector2 predictedPosition = LockOnHelper.PredictedPosition; bool flag = false; if (LockOnHelper.ShouldLockOn(p) && (ItemID.Sets.LockOnIgnoresCollision[p.inventory[p.selectedItem].type] || Collision.CanHit(p.Center, 0, 0, predictedPosition, 0, 0) || (Collision.CanHitLine(p.Center, 0, 0, predictedPosition, 0, 0) || Collision.CanHit(p.Center, 0, 0, aimedTarget.Center, 0, 0)) || Collision.CanHitLine(p.Center, 0, 0, aimedTarget.Center, 0, 0))) { flag = true; } if (!flag) { return; } LockOnHelper._canLockOn = true; } }
public override void CustomBehavior() { if (Main.netMode != NetmodeID.MultiplayerClient) { if (attackCounter > 0) { attackCounter--; } Player target = Main.player[npc.target]; if (attackCounter <= 0 && Vector2.Distance(npc.Center, target.Center) < 200 && Collision.CanHit(npc.Center, 1, 1, target.Center, 1, 1)) { Vector2 direction = (target.Center - npc.Center).SafeNormalize(Vector2.UnitX); direction = direction.RotatedByRandom(MathHelper.ToRadians(10)); int projectile = Projectile.NewProjectile(npc.Center, direction * 1, ProjectileID.ShadowBeamHostile, 5, 0, Main.myPlayer); Main.projectile[projectile].timeLeft = 300; attackCounter = 500; npc.netUpdate = true; } } }
public override void AI() { float num1 = (float)Math.Sqrt(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y); float num2 = projectile.localAI[0]; if (num2 == 0.0) { projectile.localAI[0] = num1; num2 = num1; } float num3 = projectile.position.X; float num4 = projectile.position.Y; float num5 = 300f; bool flag2 = false; int num6 = 0; if (projectile.ai[1] == 0.0) { for (int index = 0; index < 200; ++index) { if (Main.npc[index].CanBeChasedBy(this, false) && (projectile.ai[1] == 0.0 || projectile.ai[1] == (double)(index + 1))) { float num7 = Main.npc[index].position.X + (float)(Main.npc[index].width / 2); float num8 = Main.npc[index].position.Y + (float)(Main.npc[index].height / 2); float num9 = Math.Abs(projectile.position.X + (projectile.width / 2) - num7) + Math.Abs(projectile.position.Y + (projectile.height / 2) - num8); if (num9 < num5 && Collision.CanHit(new Vector2(projectile.position.X + (projectile.width / 2), projectile.position.Y + (projectile.height / 2)), 1, 1, Main.npc[index].position, Main.npc[index].width, Main.npc[index].height)) { num5 = num9; num3 = num7; num4 = num8; flag2 = true; num6 = index; } } } if (flag2) { projectile.ai[1] = (float)(num6 + 1); } flag2 = false; } if (projectile.ai[1] > 0.0) { int index = (int)(projectile.ai[1] - 1.0); if (Main.npc[index].active && Main.npc[index].CanBeChasedBy(this, true) && !Main.npc[index].dontTakeDamage) { if ((double)(Math.Abs(projectile.position.X + (projectile.width / 2) - (Main.npc[index].position.X + (float)(Main.npc[index].width / 2))) + Math.Abs(projectile.position.Y + (projectile.height / 2) - (Main.npc[index].position.Y + (float)(Main.npc[index].height / 2)))) < 1000.0) { flag2 = true; num3 = Main.npc[index].position.X + (float)(Main.npc[index].width / 2); num4 = Main.npc[index].position.Y + (float)(Main.npc[index].height / 2); } } else { projectile.ai[1] = 0.0f; } } if (!projectile.friendly) { flag2 = false; } if (flag2) { float num7 = num2; Vector2 vector2 = new Vector2(projectile.position.X + projectile.width * 0.5f, projectile.position.Y + projectile.height * 0.5f); float num8 = num3 - vector2.X; float num9 = num4 - vector2.Y; float num10 = (float)Math.Sqrt(num8 * num8 + num9 * num9); float num11 = num7 / num10; float num12 = num8 * num11; float num13 = num9 * num11; int num14 = 8; projectile.velocity.X = (projectile.velocity.X * (float)(num14 - 1) + num12) / num14; projectile.velocity.Y = (projectile.velocity.Y * (float)(num14 - 1) + num13) / num14; } }
public override void Behavior() { Player player = Main.player[projectile.owner]; BluemagicPlayer modPlayer = player.GetModPlayer <BluemagicPlayer>(mod); if (projectile.ai[1] > 0) { projectile.ai[1]--; } bool moveLeft = false; bool moveRight = false; int targetFollowDist = 40 * (projectile.minionPos + 1) * player.direction; if (player.position.X + (float)(player.width / 2) < projectile.position.X + (float)(projectile.width / 2) + (float)targetFollowDist - 10f) { moveLeft = true; } else if (player.position.X + (float)(player.width / 2) > projectile.position.X + (float)(projectile.width / 2) + (float)targetFollowDist + 10f) { moveRight = true; } if (!Throwing()) { int flyDistance = 500 + 40 * projectile.minionPos; if (player.rocketDelay2 > 0) { projectile.ai[0] = 1f; projectile.netUpdate = true; } Vector2 projCenter = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float xDist = player.position.X + (float)(player.width / 2) - projCenter.X; float yDist = player.position.Y + (float)(player.height / 2) - projCenter.Y; float distance = (float)System.Math.Sqrt((double)(xDist * xDist + yDist * yDist)); if (distance > 2000f) { projectile.position.X = player.position.X + (float)(player.width / 2) - (float)(projectile.width / 2); projectile.position.Y = player.position.Y + (float)(player.height / 2) - (float)(projectile.height / 2); } else if (distance > (float)flyDistance || System.Math.Abs(yDist) > 300f) { if (yDist > 0f && projectile.velocity.Y < 0f) { projectile.velocity.Y = 0f; } if (yDist < 0f && projectile.velocity.Y > 0f) { projectile.velocity.Y = 0f; } projectile.ai[0] = 1f; projectile.netUpdate = true; } } if (Throwing()) { UpdateFrame(); projectile.velocity.X = 0f; } else if (projectile.ai[0] != 0f) { projectile.tileCollide = false; Vector2 projCenter = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float moveDistX = player.position.X + (float)(player.width / 2) - projCenter.X - (float)(40 * player.direction); float viewRange = 600f; bool aggro = false; for (int k = 0; k < 200; k++) { if (Main.npc[k].CanBeChasedBy(this)) { float monsterX = Main.npc[k].position.X + (float)(Main.npc[k].width / 2); float monsterY = Main.npc[k].position.Y + (float)(Main.npc[k].height / 2); float distance = System.Math.Abs(player.position.X + (float)(player.width / 2) - monsterX) + System.Math.Abs(player.position.Y + (float)(player.height / 2) - monsterY); if (distance < viewRange) { aggro = true; break; } } } if (!aggro) { moveDistX -= (float)(40 * projectile.minionPos * player.direction); } float moveDistY = player.position.Y + (float)(player.height / 2) - projCenter.Y; float moveDist = (float)System.Math.Sqrt((double)(moveDistX * moveDistX + moveDistY * moveDistY)); float maxSpeed = 10f; if (moveDist < 200f && player.velocity.Y == 0f && projectile.position.Y + (float)projectile.height <= player.position.Y + (float)player.height && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) { projectile.ai[0] = 0f; if (projectile.velocity.Y < -6f) { projectile.velocity.Y = -6f; } projectile.netUpdate = true; } if (moveDist < 60f) { moveDistX = projectile.velocity.X; moveDistY = projectile.velocity.Y; } else { moveDist = maxSpeed / moveDist; moveDistX *= moveDist; moveDistY *= moveDist; } float acceleration = 0.2f; if (projectile.velocity.X < moveDistX) { projectile.velocity.X += acceleration; if (projectile.velocity.X < 0f) { projectile.velocity.X += acceleration * 1.5f; } } if (projectile.velocity.X > moveDistX) { projectile.velocity.X -= acceleration; if (projectile.velocity.X > 0f) { projectile.velocity.X -= acceleration * 1.5f; } } if (projectile.velocity.Y < moveDistY) { projectile.velocity.Y += acceleration; if (projectile.velocity.Y < 0f) { projectile.velocity.Y += acceleration * 1.5f; } } if (projectile.velocity.Y > moveDistY) { projectile.velocity.Y -= acceleration; if (projectile.velocity.Y > 0f) { projectile.velocity.Y -= acceleration * 1.5f; } } if ((double)projectile.velocity.X > 0.5) { projectile.spriteDirection = -1; } else if ((double)projectile.velocity.X < -0.5) { projectile.spriteDirection = 1; } UpdateFrame(); if (Main.rand.Next(3) == 0) { int dust = Dust.NewDust(projectile.position, projectile.width, projectile.height, mod.DustType("SpectreDust")); Main.dust[dust].velocity /= 2f; } } else { float separation = (float)(40 * projectile.minionPos); if (true) { float moveToX = projectile.position.X; float moveToY = projectile.position.Y; float moveDist = 100000f; int attacking = -1; if (projectile.OwnerMinionAttackTargetNPC != null && projectile.OwnerMinionAttackTargetNPC.CanBeChasedBy(this)) { NPC npc = projectile.OwnerMinionAttackTargetNPC; moveToX = npc.Center.X; moveToY = npc.Center.Y; moveDist = Vector2.Distance(npc.Center, projectile.Center); attacking = npc.whoAmI; } else { float closestDist = moveDist; for (int k = 0; k < 200; k++) { if (Main.npc[k].CanBeChasedBy(this)) { float monsterX = Main.npc[k].position.X + (float)(Main.npc[k].width / 2); float monsterY = Main.npc[k].position.Y + (float)(Main.npc[k].height / 2); float monsterDist = System.Math.Abs(projectile.position.X + (float)(projectile.width / 2) - monsterX) + System.Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - monsterY); if (monsterDist < moveDist) { if (attacking == -1 && monsterDist <= closestDist) { closestDist = monsterDist; moveToX = monsterX; moveToY = monsterY; } if (Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[k].position, Main.npc[k].width, Main.npc[k].height)) { moveDist = monsterDist; moveToX = monsterX; moveToY = monsterY; attacking = k; } } } } if (attacking == -1 && closestDist < moveDist) { moveDist = closestDist; } } if (attacking >= 0 && moveDist < 1000f) { projectile.friendly = true; if (projectile.ai[1] == 0 && projectile.owner == Main.myPlayer) { Vector2 throwSpeed = new Vector2(moveToX, moveToY) - projectile.Center; if (throwSpeed != Vector2.Zero) { throwSpeed.Normalize(); throwSpeed *= 10f; } Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, throwSpeed.X, throwSpeed.Y, mod.ProjectileType("MiniHammer"), projectile.damage, projectile.knockBack, projectile.owner); if (moveToX < projectile.Center.X) { projectile.direction = -1; } else if (moveToX > projectile.Center.X) { projectile.direction = 1; } projectile.ai[1] = 100; projectile.netUpdate = true; } } else { projectile.friendly = false; } } projectile.rotation = 0f; projectile.tileCollide = true; float increment = 0.2f; float maxSpeed = 3f; if (maxSpeed < System.Math.Abs(player.velocity.X) + System.Math.Abs(player.velocity.Y)) { increment = 0.3f; } if (moveLeft) { projectile.velocity.X -= increment; } else if (moveRight) { projectile.velocity.X += increment; } else { projectile.velocity.X *= 0.8f; if (projectile.velocity.X >= -increment && projectile.velocity.X <= increment) { projectile.velocity.X = 0f; } } bool willCollide = false; if (moveLeft || moveRight) { int checkX = (int)(projectile.position.X + (float)(projectile.width / 2)) / 16; int checkY = (int)(projectile.position.Y + (float)(projectile.height / 2)) / 16; if (moveLeft) { checkX--; } if (moveRight) { checkX++; } checkX += (int)projectile.velocity.X; if (WorldGen.SolidTile(checkX, checkY)) { willCollide = true; } } bool playerBelow = player.position.Y + (float)player.height - 8f > projectile.position.Y + (float)projectile.height; Collision.StepUp(ref projectile.position, ref projectile.velocity, projectile.width, projectile.height, ref projectile.stepSpeed, ref projectile.gfxOffY, 1, false); if (projectile.velocity.Y == 0f) { if (!playerBelow && (projectile.velocity.X != 0f)) { int checkX = (int)(projectile.position.X + (float)(projectile.width / 2)) / 16; int checkY = (int)(projectile.position.Y + (float)(projectile.height / 2)) / 16 + 1; if (moveLeft) { checkX--; } if (moveRight) { checkX++; } WorldGen.SolidTile(checkX, checkY); } if (willCollide) { int checkX = (int)(projectile.position.X + (float)(projectile.width / 2)) / 16; int checkY = (int)(projectile.position.Y + (float)projectile.height) / 16 + 1; if (WorldGen.SolidTile(checkX, checkY) || Main.tile[checkX, checkY].halfBrick() || Main.tile[checkX, checkY].slope() > 0) { try { checkY--; if (moveLeft) { checkX--; } if (moveRight) { checkX++; } checkX += (int)projectile.velocity.X; if (!WorldGen.SolidTile(checkX, checkY - 1) && !WorldGen.SolidTile(checkX, checkY - 2)) { projectile.velocity.Y = -5.1f; } else { projectile.velocity.Y = -7.1f; } } catch { projectile.velocity.Y = -7.1f; } } } else if (!projectile.friendly && player.position.Y + player.height + 80f < projectile.position.Y) { projectile.velocity.Y = -7f; } } if (projectile.velocity.X > maxSpeed) { projectile.velocity.X = maxSpeed; } if (projectile.velocity.X < -maxSpeed) { projectile.velocity.X = -maxSpeed; } if (projectile.velocity.X < 0f) { projectile.direction = -1; } if (projectile.velocity.X > 0f) { projectile.direction = 1; } if (projectile.velocity.X != 0f || Throwing()) { projectile.spriteDirection = -projectile.direction; } UpdateFrame(); if (projectile.wet) { projectile.velocity *= 0.9f; projectile.velocity.Y += 0.2f; } else { projectile.velocity.Y += 0.4f; } if (projectile.velocity.Y > 10f) { projectile.velocity.Y = 10f; } } }
public override void AI() { Player player = Main.player[projectile.owner]; CPlayer modPlayer = player.GetModPlayer <CPlayer>(); if (!modPlayer.Starsteel || modPlayer.StarsteelBonus != 4) { projectile.Kill(); return; } Vector2 PlayerPoint; PlayerPoint.X = player.Center.X - projectile.width / 2; PlayerPoint.Y = player.Center.Y - projectile.height / 2 + player.gfxOffY - 60f; projectile.position = PlayerPoint; if (player.gravDir == -1f) { projectile.position.Y = projectile.position.Y + 120f; projectile.rotation = 3.14f; } else { projectile.rotation = 0f; } if (projectile.owner == Main.myPlayer) { if (projectile.ai[0] != 0f) { projectile.ai[0] -= 1f; return; } float num396 = projectile.position.X; float num397 = projectile.position.Y; float num398 = 700f; bool flag11 = false; for (int num399 = 0; num399 < 200; num399++) { if (Main.npc[num399].CanBeChasedBy(this, true)) { float num400 = Main.npc[num399].position.X + Main.npc[num399].width / 2; float num401 = Main.npc[num399].position.Y + Main.npc[num399].height / 2; float num402 = Math.Abs(projectile.position.X + projectile.width / 2 - num400) + Math.Abs(projectile.position.Y + projectile.height / 2 - num401); if (num402 < num398 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num399].position, Main.npc[num399].width, Main.npc[num399].height)) { num398 = num402; num396 = num400; num397 = num401; flag11 = true; } } } if (flag11) { float num403 = 12f; Vector2 vector29 = new Vector2(projectile.position.X + projectile.width * 0.5f, projectile.position.Y + projectile.height * 0.5f); float num404 = num396 - vector29.X; float num405 = num397 - vector29.Y; float num406 = (float)Math.Sqrt(num404 * num404 + num405 * num405); num406 = num403 / num406; num404 *= num406; num405 *= num406; int p = Projectile.NewProjectile(projectile.Center.X - 4f, projectile.Center.Y, num404, num405, ModContent.ProjectileType <StarGuardianShot>(), Player.crystalLeafDamage, Player.crystalLeafKB, projectile.owner, 0f, 0f); Main.projectile[p].melee = false; Main.projectile[p].minion = true; Main.projectile[p].minionSlots = 0; projectile.ai[0] = 160; return; } } }
public static NPCUtils.TargetSearchResults SearchForTarget(NPC searcher, Vector2 position, NPCUtils.TargetSearchFlag flags = NPCUtils.TargetSearchFlag.All, NPCUtils.SearchFilter <Player> playerFilter = null, NPCUtils.SearchFilter <NPC> npcFilter = null) { float num1 = float.MaxValue; int nearestNPCIndex = -1; float adjustedTankDistance = float.MaxValue; float nearestTankDistance = float.MaxValue; int nearestTankIndex = -1; NPCUtils.TargetType tankType = NPCUtils.TargetType.Player; if (flags.HasFlag((Enum)NPCUtils.TargetSearchFlag.NPCs)) { for (int index = 0; index < 200; ++index) { NPC entity = Main.npc[index]; if (entity.active && (npcFilter == null || npcFilter(entity))) { float num2 = Vector2.DistanceSquared(position, entity.Center); if ((double)num2 < (double)num1) { nearestNPCIndex = index; num1 = num2; } } } } if (flags.HasFlag((Enum)NPCUtils.TargetSearchFlag.Players)) { for (int index = 0; index < (int)byte.MaxValue; ++index) { Player entity = Main.player[index]; if (entity.active && !entity.dead && !entity.ghost && (playerFilter == null || playerFilter(entity))) { float num2 = Vector2.Distance(position, entity.Center); float num3 = num2 - (float)entity.aggro; bool flag = searcher != null && entity.npcTypeNoAggro[searcher.type]; if (searcher != null && flag && searcher.direction == 0) { num3 += 1000f; } if ((double)num3 < (double)adjustedTankDistance) { nearestTankIndex = index; adjustedTankDistance = num3; nearestTankDistance = num2; tankType = NPCUtils.TargetType.Player; } if (entity.tankPet >= 0 && !flag) { Vector2 center = Main.projectile[entity.tankPet].Center; float num4 = Vector2.Distance(position, center); float num5 = num4 - 200f; if ((double)num5 < (double)adjustedTankDistance && (double)num5 < 200.0 && Collision.CanHit(position, 0, 0, center, 0, 0)) { nearestTankIndex = index; adjustedTankDistance = num5; nearestTankDistance = num4; tankType = NPCUtils.TargetType.TankPet; } } } } } return(new NPCUtils.TargetSearchResults(searcher, nearestNPCIndex, (float)Math.Sqrt((double)num1), nearestTankIndex, nearestTankDistance, adjustedTankDistance, tankType)); }
public override void Behavior() { Player player = Main.player[projectile.owner]; float num = (float)projectile.width * 1.1f; for (int i = 0; i < 1000; i++) { Projectile current = Main.projectile[i]; if (i != projectile.whoAmI && current.active && current.owner == projectile.owner && current.type == projectile.type && Math.Abs(projectile.position.X - current.position.X) + Math.Abs(projectile.position.Y - current.position.Y) < num) { if (projectile.position.X < Main.projectile[i].position.X) { projectile.velocity.X -= 0.08f; } else { projectile.velocity.X += 0.08f; } if (projectile.position.Y < Main.projectile[i].position.Y) { projectile.velocity.Y -= 0.08f; } else { projectile.velocity.Y += 0.08f; } } } Vector2 value = projectile.position; float num2 = 500f; bool flag = false; projectile.tileCollide = true; for (int j = 0; j < 200; j++) { NPC nPC = Main.npc[j]; if (nPC.CanBeChasedBy(this, false)) { float num3 = Vector2.Distance(nPC.Center, projectile.Center); if ((num3 < num2 || !flag) && Collision.CanHitLine(projectile.position, projectile.width, projectile.height, nPC.position, nPC.width, nPC.height)) { num2 = num3; value = nPC.Center; flag = true; } } } if (Vector2.Distance(player.Center, projectile.Center) > (flag ? 1000f : 500f)) { projectile.ai[0] = 1f; projectile.netUpdate = true; } if (projectile.ai[0] == 1f) { projectile.tileCollide = false; } if (flag && projectile.ai[0] == 0f) { Vector2 value2 = value - projectile.Center; if (value2.Length() > 200f) { value2.Normalize(); projectile.velocity = (projectile.velocity * 20f + value2 * 6f) / 21f; } else { projectile.velocity *= (float)Math.Pow(0.97, 2.0); } } else { if (!Collision.CanHitLine(projectile.Center, 1, 1, player.Center, 1, 1)) { projectile.ai[0] = 1f; } float num4 = 6f; if (projectile.ai[0] == 1f) { num4 = 15f; } Vector2 center = projectile.Center; Vector2 vector = player.Center - center; projectile.ai[1] = 3600f; projectile.netUpdate = true; int num5 = 1; for (int k = 0; k < projectile.whoAmI; k++) { if (Main.projectile[k].active && Main.projectile[k].owner == projectile.owner && Main.projectile[k].type == projectile.type) { num5++; } } vector.X -= (float)((10 + num5 * 40) * player.direction); vector.Y -= 70f; float num6 = vector.Length(); if (num6 > 200f && num4 < 9f) { num4 = 9f; } else if (num6 < 100f && projectile.ai[0] == 1f && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) { projectile.ai[0] = 0f; projectile.netUpdate = true; } if (num6 > 2000f) { projectile.Center = player.Center; } if (num6 > 48f) { vector.Normalize(); vector *= num4; float num7 = 10f; projectile.velocity = (projectile.velocity * num7 + vector) / (num7 + 1f); } else { projectile.direction = Main.player[projectile.owner].direction; projectile.velocity *= (float)Math.Pow(0.9, 2.0); } } projectile.rotation = projectile.velocity.X * 0.05f; if (projectile.velocity.X > 0f) { projectile.spriteDirection = (projectile.direction = -1); } else if (projectile.velocity.X < 0f) { projectile.spriteDirection = (projectile.direction = 1); } if (projectile.ai[1] > 0f) { projectile.ai[1] += 1f; } if (projectile.ai[1] > 140f) { projectile.ai[1] = 0f; projectile.netUpdate = true; } if (projectile.ai[0] == 0f && flag) { if ((value - projectile.Center).X > 0f) { projectile.spriteDirection = (projectile.direction = -1); } else if ((value - projectile.Center).X < 0f) { projectile.spriteDirection = (projectile.direction = 1); } if (projectile.ai[1] == 0f) { projectile.ai[1] = 1f; if (Main.myPlayer == projectile.owner) { Vector2 vector2 = value - projectile.Center; if (vector2 == Vector2.Zero) { vector2 = Vector2.UnitY; } vector2.Normalize(); vector2 *= 9f; int num8 = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, vector2.X, vector2.Y, base.mod.ProjectileType("WitherShard1"), 15, projectile.knockBack, Main.myPlayer, 0f, 0f); Main.projectile[num8].timeLeft = 300; Main.projectile[num8].netUpdate = true; projectile.netUpdate = true; } } } if (projectile.ai[0] == 0f) { if (Main.rand.Next(5) == 0) { int num9 = Dust.NewDust(projectile.position, projectile.width, projectile.height / 2, 60, 0f, 0f, 0, default(Color), 1f); Main.dust[num9].velocity.Y -= 1.2f; } } else if (Main.rand.Next(3) == 0) { Vector2 velocity = projectile.velocity; if (velocity != Vector2.Zero) { velocity.Normalize(); } int num10 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 60, 0f, 0f, 0, default(Color), 1f); Main.dust[num10].velocity -= 1.2f * velocity; } Lighting.AddLight((int)(projectile.Center.X / 16f), (int)(projectile.Center.Y / 16f), 0.2f, 0.2f, 0.9f); if (Main.rand.Next(60) == 0) { float dum = 8000f; int dum2 = -1; for (int i = 0; i < 200; i++) { float dum3 = Vector2.Distance(projectile.Center, Main.npc[i].Center); if (dum3 < dum && dum3 < 640f && Main.npc[i].CanBeChasedBy(projectile, false)) { dum2 = i; dum = dum3; } } if (dum2 != -1) { bool flags = Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[dum2].position, Main.npc[dum2].width, Main.npc[dum2].height); if (flags) { Vector2 values = Main.npc[dum2].Center - projectile.Center; float dum4 = 5f; float dum5 = (float)Math.Sqrt((double)(values.X * values.X + values.Y * values.Y)); if (dum5 > dum4) { dum5 = dum4 / dum5; } values *= dum5; int p = Terraria.Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, values.X, values.Y, mod.ProjectileType("WitherShard1"), 15, projectile.knockBack / 2f, projectile.owner, 0f, 0f); Main.projectile[p].friendly = true; Main.projectile[p].hostile = false; } } } }
public override void AI() { float num486 = projectile.position.X; float num487 = projectile.position.Y; float num488 = 100000f; bool flag17 = false; projectile.ai[0] += 1f; if (projectile.ai[0] > 30f) { projectile.ai[0] = 30f; for (int num489 = 0; num489 < 200; num489++) { if (Main.npc[num489].active && !Main.npc[num489].dontTakeDamage && !Main.npc[num489].friendly && Main.npc[num489].lifeMax > 5 && (!Main.npc[num489].wet || projectile.type == 307)) { float num490 = Main.npc[num489].position.X + (float)(Main.npc[num489].width / 2); float num491 = Main.npc[num489].position.Y + (float)(Main.npc[num489].height / 2); float num492 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num490) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num491); if (num492 < 800f && num492 < num488 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num489].position, Main.npc[num489].width, Main.npc[num489].height)) { num488 = num492; num486 = num490; num487 = num491; flag17 = true; } } } } if (!flag17) { num486 = projectile.position.X + (float)(projectile.width / 2) + projectile.velocity.X * 100f; num487 = projectile.position.Y + (float)(projectile.height / 2) + projectile.velocity.Y * 100f; } float num493 = 6f; float num494 = 0.1f; Vector2 vector36 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num495 = num486 - vector36.X; float num496 = num487 - vector36.Y; float num497 = (float)Math.Sqrt((double)(num495 * num495 + num496 * num496)); num497 = num493 / num497; num495 *= num497; num496 *= num497; if (projectile.velocity.X < num495) { projectile.velocity.X = projectile.velocity.X + num494; if (projectile.velocity.X < 0f && num495 > 0f) { projectile.velocity.X = projectile.velocity.X + num494 * 2f; } } else { if (projectile.velocity.X > num495) { projectile.velocity.X = projectile.velocity.X - num494; if (projectile.velocity.X > 0f && num495 < 0f) { projectile.velocity.X = projectile.velocity.X - num494 * 2f; } } } if (projectile.velocity.Y < num496) { projectile.velocity.Y = projectile.velocity.Y + num494; if (projectile.velocity.Y < 0f && num496 > 0f) { projectile.velocity.Y = projectile.velocity.Y + num494 * 2f; } } else { if (projectile.velocity.Y > num496) { projectile.velocity.Y = projectile.velocity.Y - num494; if (projectile.velocity.Y > 0f && num496 < 0f) { projectile.velocity.Y = projectile.velocity.Y - num494 * 2f; } } } projectile.light = 0.9f; if (projectile.velocity.X > 0f) { projectile.spriteDirection = 1; projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; } else if (projectile.velocity.X < 0f) { projectile.spriteDirection = -1; projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f; } if (projectile.frameCounter < 5) { projectile.frame = 0; } else if (projectile.frameCounter >= 5 && projectile.frameCounter < 10) { projectile.frame = 1; } else { projectile.frameCounter = 0; } projectile.frameCounter++; }
public override void AI() { if (Phase == (int)AIStates.Normal) { if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead) { npc.TargetClosest(true); } float num548 = 2f; float moveSpeed = 0.16f; Vector2 vector70 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); float num550 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2); float num551 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2); num550 = (float)((int)(num550 / 8f) * 8); num551 = (float)((int)(num551 / 8f) * 8); vector70.X = (float)((int)(vector70.X / 8f) * 8); vector70.Y = (float)((int)(vector70.Y / 8f) * 8); num550 -= vector70.X; num551 -= vector70.Y; float num552 = (float)Math.Sqrt((double)(num550 * num550 + num551 * num551)); if (num552 == 0f) { num550 = npc.velocity.X; num551 = npc.velocity.Y; } else { num552 = num548 / num552; num550 *= num552; num551 *= num552; } if (Main.player[npc.target].dead) { num550 = (float)npc.direction * num548 / 2f; num551 = -num548 / 2f; } npc.spriteDirection = -1; if (!Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { npc.ai[0] += 1f; if (npc.ai[0] > 0f) { npc.velocity.Y = npc.velocity.Y + 0.023f; } else { npc.velocity.Y = npc.velocity.Y - 0.023f; } if (npc.ai[0] < -100f || npc.ai[0] > 100f) { npc.velocity.X = npc.velocity.X + 0.023f; } else { npc.velocity.X = npc.velocity.X - 0.023f; } if (npc.ai[0] > 200f) { npc.ai[0] = -200f; } npc.velocity.X = npc.velocity.X + num550 * 0.007f; npc.velocity.Y = npc.velocity.Y + num551 * 0.007f; npc.rotation = (float)Math.Atan2((double)npc.velocity.Y, (double)npc.velocity.X); if ((double)npc.velocity.X > 1.5) { npc.velocity.X = npc.velocity.X * 0.9f; } if ((double)npc.velocity.X < -1.5) { npc.velocity.X = npc.velocity.X * 0.9f; } if ((double)npc.velocity.Y > 1.5) { npc.velocity.Y = npc.velocity.Y * 0.9f; } if ((double)npc.velocity.Y < -1.5) { npc.velocity.Y = npc.velocity.Y * 0.9f; } if (npc.velocity.X > 3f) { npc.velocity.X = 3f; } if (npc.velocity.X < -3f) { npc.velocity.X = -3f; } if (npc.velocity.Y > 3f) { npc.velocity.Y = 3f; } if (npc.velocity.Y < -3f) { npc.velocity.Y = -3f; } } else { Vector2 targetVelocity = npc.DirectionTo(Main.player[npc.target].Center); targetVelocity *= 6f; npc.velocity = Vector2.Lerp(npc.velocity, targetVelocity, 1f / 20f); npc.rotation = (float)Math.Atan2((double)npc.velocity.Y, (double)npc.velocity.X); /*if (npc.velocity.X < num550) * { * npc.velocity.X = npc.velocity.X + moveSpeed; * if (npc.velocity.X < 0f && num550 > 0f) * { * npc.velocity.X = npc.velocity.X + moveSpeed; * } * } * else if (npc.velocity.X > num550) * { * npc.velocity.X = npc.velocity.X - moveSpeed; * if (npc.velocity.X > 0f && num550 < 0f) * { * npc.velocity.X = npc.velocity.X - moveSpeed; * } * } * if (npc.velocity.Y < num551) * { * npc.velocity.Y = npc.velocity.Y + moveSpeed; * if (npc.velocity.Y < 0f && num551 > 0f) * { * npc.velocity.Y = npc.velocity.Y + moveSpeed; * } * } * else if (npc.velocity.Y > num551) * { * npc.velocity.Y = npc.velocity.Y - moveSpeed; * if (npc.velocity.Y > 0f && num551 < 0f) * { * npc.velocity.Y = npc.velocity.Y - moveSpeed; * } * } * //npc.velocity *= 1.5f; * npc.rotation = (float)Math.Atan2((double)num551, (double)num550);*/ } float num553 = 0.5f; if (npc.collideX) { npc.netUpdate = true; npc.velocity.X = npc.oldVelocity.X * -num553; if (npc.direction == -1 && npc.velocity.X > 0f && npc.velocity.X < 2f) { npc.velocity.X = 2f; } if (npc.direction == 1 && npc.velocity.X < 0f && npc.velocity.X > -2f) { npc.velocity.X = -2f; } } if (npc.collideY) { npc.netUpdate = true; npc.velocity.Y = npc.oldVelocity.Y * -num553; if (npc.velocity.Y > 0f && (double)npc.velocity.Y < 1.5) { npc.velocity.Y = 2f; } if (npc.velocity.Y < 0f && (double)npc.velocity.Y > -1.5) { npc.velocity.Y = -2f; } } if (((npc.velocity.X > 0f && npc.oldVelocity.X < 0f) || (npc.velocity.X < 0f && npc.oldVelocity.X > 0f) || (npc.velocity.Y > 0f && npc.oldVelocity.Y < 0f) || (npc.velocity.Y < 0f && npc.oldVelocity.Y > 0f)) && !npc.justHit) { npc.netUpdate = true; } if (Main.netMode != 1) { int num554 = (int)npc.Center.X / 16; int num555 = (int)npc.Center.Y / 16; bool flag36 = false; int num; for (int num556 = num554 - 1; num556 <= num554 + 1; num556 = num + 1) { for (int num557 = num555 - 1; num557 <= num555 + 1; num557 = num + 1) { if (Main.tile[num556, num557] == null) { return; } if (Main.tile[num556, num557].wall > 0) { flag36 = true; } num = num557; } num = num556; } if (!flag36) { npc.Transform(mod.NPCType("Spider")); return; } } } if (Phase == (int)AIStates.Death) { npc.damage = 0; npc.ai[2] += 1f; // increase our death timer. npc.netUpdate = true; npc.velocity.X = 0; npc.velocity.Y += 1.5f; npc.dontTakeDamage = true; npc.rotation = GeneralMethods.ManualMobRotation(npc.rotation, MathHelper.ToRadians(180f), 14f); if (npc.ai[2] >= 110f) { for (int i = 0; i < 20; i++) { int dustIndex = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, DustType <Dusts.Poof>(), 2.25f * Main.rand.Next(-1, 1), 0f, 100, default(Color), 1f); //spawns ender dust Main.dust[dustIndex].noGravity = true; } npc.life = 0; } } }
public override void AI() { projectile.ai[1] += 1f; if (projectile.ai[1] >= 7200f) { projectile.alpha += 5; if (projectile.alpha > 255) { projectile.alpha = 255; projectile.Kill(); } } for (int num526 = 0; num526 < 1000; num526++) { if (num526 != projectile.whoAmI && Main.projectile[num526].active && Main.projectile[num526].owner == projectile.owner && Main.projectile[num526].type == projectile.type && Math.Abs(projectile.position.X - Main.projectile[num526].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num526].position.Y) < (float)projectile.width) { if (projectile.position.X < Main.projectile[num526].position.X) { projectile.velocity.X = projectile.velocity.X - 0.05f; } else { projectile.velocity.X = projectile.velocity.X + 0.05f; } if (projectile.position.Y < Main.projectile[num526].position.Y) { projectile.velocity.Y = projectile.velocity.Y - 0.05f; } else { projectile.velocity.Y = projectile.velocity.Y + 0.05f; } } } float num527 = projectile.position.X; float num528 = projectile.position.Y; float num529 = 900f; bool flag19 = false; int num530 = 500; if (projectile.ai[1] != 0f || projectile.friendly) { num530 = 1400; } //if (Math.Abs(Projectile.Center.X - Main.player[projectile.owner].Center.X) + Math.Abs(Projectile.Center.Y - Main.player[projectile.owner].Center.Y) > (float)num530) //{ // projectile.ai[0] = 1f; //} if (projectile.ai[0] == 0f) { for (int num531 = 0; num531 < 200; num531++) { if (Main.npc[num531].CanBeChasedBy(projectile, false)) { float num532 = Main.npc[num531].position.X + (float)(Main.npc[num531].width / 2); float num533 = Main.npc[num531].position.Y + (float)(Main.npc[num531].height / 2); float num534 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num532) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num533); if (num534 < num529 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num531].position, Main.npc[num531].width, Main.npc[num531].height)) { num529 = num534; num527 = num532; num528 = num533; flag19 = true; } } } } else { projectile.tileCollide = false; } if (!flag19) { projectile.friendly = true; float num535 = 8f; if (projectile.ai[0] == 1f) { num535 = 12f; } Vector2 vector38 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num536 = Main.player[projectile.owner].Center.X - vector38.X; float num537 = Main.player[projectile.owner].Center.Y - vector38.Y - 60f; float num538 = (float)Math.Sqrt((double)(num536 * num536 + num537 * num537)); if (num538 < 100f && projectile.ai[0] == 1f && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) { projectile.ai[0] = 0f; } if (num538 > 2000f) { projectile.position.X = Main.player[projectile.owner].Center.X - (float)(projectile.width / 2); projectile.position.Y = Main.player[projectile.owner].Center.Y - (float)(projectile.width / 2); } if (num538 > 70f) { num538 = num535 / num538; num536 *= num538; num537 *= num538; projectile.velocity.X = (projectile.velocity.X * 20f + num536) / 21f; projectile.velocity.Y = (projectile.velocity.Y * 20f + num537) / 21f; } else { if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) { projectile.velocity.X = -0.15f; projectile.velocity.Y = -0.05f; } projectile.velocity *= 1.01f; } projectile.friendly = false; projectile.rotation = projectile.velocity.X * 0.05f; projectile.frameCounter++; if (projectile.frameCounter >= 5) { projectile.frameCounter = 0; projectile.frame++; } if (projectile.frame > 4) { projectile.frame = 0; } if (Math.Abs(projectile.velocity.X) > 0.2) { projectile.spriteDirection = -projectile.direction; return; } } else { if (projectile.ai[1] == -1f) { projectile.ai[1] = 17f; } if (projectile.ai[1] > 0f) { projectile.ai[1] -= 1f; } if (projectile.ai[1] == 0f) { projectile.friendly = true; float num539 = 8f; Vector2 vector39 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num540 = num527 - vector39.X; float num541 = num528 - vector39.Y; float num542 = (float)Math.Sqrt((double)(num540 * num540 + num541 * num541)); if (num542 < 100f) { num539 = 10f; } num542 = num539 / num542; num540 *= num542; num541 *= num542; projectile.velocity.X = (projectile.velocity.X * 14f + num540) / 15f; projectile.velocity.Y = (projectile.velocity.Y * 14f + num541) / 15f; } else { projectile.friendly = false; if (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y) < 10f) { projectile.velocity *= 1.05f; } } projectile.rotation = projectile.velocity.X * 0.05f; projectile.frameCounter++; if (projectile.frameCounter >= 5) { projectile.frameCounter = 0; projectile.frame++; } if (projectile.frame < 4) { projectile.frame = 2; } else if (projectile.frame > 5) { projectile.frame = 2; } if (Math.Abs(projectile.velocity.X) > 0.2) { projectile.spriteDirection = -projectile.direction; return; } } if (projectile.frameCounter < 5) { projectile.frame = 0; } else if (projectile.frameCounter >= 5 && projectile.frameCounter < 4) { projectile.frame = 1; } else { projectile.frameCounter = 0; } projectile.frameCounter++; }
public override void AI() { Player player = Main.player[projectile.owner]; for (int num363 = 0; num363 < 1; num363++) { float num364 = projectile.velocity.X / 3f * (float)num363; float num365 = projectile.velocity.Y / 3f * (float)num363; int num366 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 229, 0f, 0f, 0, default(Color), 1.15f); Main.dust[num366].position.X = projectile.Center.X - num364; Main.dust[num366].position.Y = projectile.Center.Y - num365; Main.dust[num366].velocity *= 0f; Main.dust[num366].noGravity = true; } if (projectile.timeLeft < 580) { if (projectile.timeLeft >= 600) { for (int k = 0; k < 6; k++) { int num367 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 229, projectile.velocity.X * 0.25f, projectile.velocity.Y * 0.25f, 125, default(Color), 1.15f); Main.dust[num367].noGravity = true; } } timer++; if (timer > 2) { projectile.velocity.Y += Main.rand.NextFloat(-0.75f, 0.75f); projectile.velocity.X += Main.rand.NextFloat(-0.75f, 0.75f); timer = 0; } int num3; float num477 = player.Center.X; float num478 = player.Center.Y; float num479 = 750f; bool flag17 = false; for (int num480 = 0; num480 < 200; num480 = num3 + 1) { if (Main.npc[num480].active && !targets.Contains(Main.npc[num480].whoAmI) && Main.npc[num480].CanBeChasedBy(projectile, false) && projectile.Distance(Main.npc[num480].Center) < num479 && Collision.CanHit(projectile.Center, 1, 1, Main.npc[num480].Center, 1, 1)) { float num481 = Main.npc[num480].position.X + (float)(Main.npc[num480].width / 2); float num482 = Main.npc[num480].position.Y + (float)(Main.npc[num480].height / 2); float num483 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num481) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num482); if (num483 < num479) { num479 = num483; num477 = num481; num478 = num482; flag17 = true; } } num3 = num480; } if (flag17) { float num488 = 2.5f; Vector2 vector38 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num489 = num477 - vector38.X; float num490 = num478 - vector38.Y; float num491 = (float)Math.Sqrt((double)(num489 * num489 + num490 * num490)); num491 = num488 / num491; num489 *= num491; num490 *= num491; projectile.velocity.X = (projectile.velocity.X * 20f + num489) / 21f; projectile.velocity.Y = (projectile.velocity.Y * 20f + num490) / 21f; } else { projectile.velocity = Vector2.Zero; } } }
public static void SpawnOnPlayerButNoTextAndReturnValue(int plr, int Type, out int npc) { npc = -1; if (Main.netMode == 1) { return; } if (Type == 262 && NPC.AnyNPCs(262)) { return; } if (Type == 245) { if (NPC.AnyNPCs(245)) { return; } try { int num = (int)Main.player[plr].Center.X / 16; int num2 = (int)Main.player[plr].Center.Y / 16; int num3 = 0; int num4 = 0; for (int i = num - 20; i < num + 20; i++) { for (int j = num2 - 20; j < num2 + 20; j++) { if (Main.tile[i, j].active() && Main.tile[i, j].type == 237 && Main.tile[i, j].frameX == 18 && Main.tile[i, j].frameY == 0) { num3 = i; num4 = j; } } } if (num3 > 0 && num4 > 0) { int num5 = num4 - 15; int num6 = num4 - 15; for (int k = num4; k > num4 - 100; k--) { if (WorldGen.SolidTile(num3, k)) { num5 = k; break; } } for (int l = num4; l < num4 + 100; l++) { if (WorldGen.SolidTile(num3, l)) { num6 = l; break; } } num4 = (num5 + num5 + num6) / 3; int num7 = NPC.NewNPC(num3 * 16 + 8, num4 * 16, 245, 100, 0f, 0f, 0f, 0f, 255); npc = num7; Main.npc[num7].target = plr; string typeName = Main.npc[num7].TypeName; } } catch { } return; } else if (Type == 370) { Player player = Main.player[plr]; if (!player.active || player.dead) { return; } int m = 0; while (m < 1000) { Projectile projectile = Main.projectile[m]; if (projectile.active && projectile.bobber && projectile.owner == plr) { int num8 = NPC.NewNPC((int)projectile.Center.X, (int)projectile.Center.Y + 100, 370, 0, 0f, 0f, 0f, 0f, 255); string typeName2 = Main.npc[num8].TypeName; if (Main.netMode == 0) { Main.NewText(Language.GetTextValue("Announcement.HasAwoken", typeName2), 175, 75, 255, false); return; } if (Main.netMode == 2) { NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[] { Main.npc[num8].GetTypeNetName() }), new Color(175, 75, 255), -1); return; } break; } else { m++; } } return; } else { if (Type != 398) { bool flag = false; int num9 = 0; int num10 = 0; int num11 = (int)(Main.player[plr].position.X / 16f) - Assist.spawnRangeX * 2; int num12 = (int)(Main.player[plr].position.X / 16f) + Assist.spawnRangeX * 2; int num13 = (int)(Main.player[plr].position.Y / 16f) - Assist.spawnRangeY * 2; int num14 = (int)(Main.player[plr].position.Y / 16f) + Assist.spawnRangeY * 2; int num15 = (int)(Main.player[plr].position.X / 16f) - NPC.safeRangeX; int num16 = (int)(Main.player[plr].position.X / 16f) + NPC.safeRangeX; int num17 = (int)(Main.player[plr].position.Y / 16f) - NPC.safeRangeY; int num18 = (int)(Main.player[plr].position.Y / 16f) + NPC.safeRangeY; if (num11 < 0) { num11 = 0; } if (num12 > Main.maxTilesX) { num12 = Main.maxTilesX; } if (num13 < 0) { num13 = 0; } if (num14 > Main.maxTilesY) { num14 = Main.maxTilesY; } for (int n = 0; n < 1000; n++) { int num19 = 0; while (num19 < 100) { int num20 = Main.rand.Next(num11, num12); int num21 = Main.rand.Next(num13, num14); if (Main.tile[num20, num21].nactive() && Main.tileSolid[(int)Main.tile[num20, num21].type]) { goto IL_730; } if ((!Main.wallHouse[(int)Main.tile[num20, num21].wall] || n >= 999) && (Type != 50 || n >= 500 || Main.tile[num21, num21].wall <= 0)) { int num22 = num21; while (num22 < Main.maxTilesY) { if (Main.tile[num20, num22].nactive() && Main.tileSolid[(int)Main.tile[num20, num22].type]) { if (num20 < num15 || num20 > num16 || num22 < num17 || num22 > num18 || n == 999) { ushort num23 = Main.tile[num20, num22].type; num9 = num20; num10 = num22; flag = true; break; } break; } else { num22++; } } if (flag && Type == 50 && n < 900) { int num24 = 20; if (!Collision.CanHit(new Vector2((float)num9, (float)(num10 - 1)) * 16f, 16, 16, new Vector2((float)num9, (float)(num10 - 1 - num24)) * 16f, 16, 16) || !Collision.CanHit(new Vector2((float)num9, (float)(num10 - 1 - num24)) * 16f, 16, 16, Main.player[plr].Center, 0, 0)) { num9 = 0; num10 = 0; flag = false; } } if (!flag || n >= 999) { goto IL_730; } int num25 = num9 - Assist.spawnSpaceX / 2; int num26 = num9 + Assist.spawnSpaceX / 2; int num27 = num10 - Assist.spawnSpaceY; int num28 = num10; if (num25 < 0) { flag = false; } if (num26 > Main.maxTilesX) { flag = false; } if (num27 < 0) { flag = false; } if (num28 > Main.maxTilesY) { flag = false; } if (flag) { for (int num29 = num25; num29 < num26; num29++) { for (int num30 = num27; num30 < num28; num30++) { if (Main.tile[num29, num30].nactive() && Main.tileSolid[(int)Main.tile[num29, num30].type]) { flag = false; break; } } } goto IL_730; } goto IL_730; } IL_728: num19++; continue; IL_730: if (!flag && !flag) { goto IL_728; } break; } if (flag && n < 999) { Rectangle rectangle = new Rectangle(num9 * 16, num10 * 16, 16, 16); for (int num31 = 0; num31 < 255; num31++) { if (Main.player[num31].active) { Rectangle rectangle2 = new Rectangle((int)(Main.player[num31].position.X + (float)(Main.player[num31].width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.player[num31].position.Y + (float)(Main.player[num31].height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); if (rectangle.Intersects(rectangle2)) { flag = false; } } } } if (flag) { break; } } if (flag) { int num32 = NPC.NewNPC(num9 * 16 + 8, num10 * 16, Type, 1, 0f, 0f, 0f, 0f, 255); npc = num32; if (num32 == 200) { return; } Main.npc[num32].target = plr; Main.npc[num32].timeLeft *= 20; string typeName3 = Main.npc[num32].TypeName; if (Main.netMode == 2 && num32 < 200) { NetMessage.SendData(23, -1, -1, null, num32, 0f, 0f, 0f, 0, 0, 0); } if (Type == 125) { if (Main.netMode == 0) { Main.NewText(Lang.misc[48].Value, 175, 75, 255, false); return; } if (Main.netMode == 2) { NetMessage.BroadcastChatMessage(Lang.misc[48].ToNetworkText(), new Color(175, 75, 255), -1); return; } } else if (Type != 82 && Type != 126 && Type != 50 && Type != 398 && Type != 551) { } } return; } Player player2 = Main.player[plr]; npc = NPC.NewNPC((int)player2.Center.X, (int)player2.Center.Y - 150, Type, 0, 0f, 0f, 0f, 0f, 255); return; } }
public override void AI() { if (--TimeToAnimation <= 0) { if (++CurrentFrame > 2) { CurrentFrame = 1; } TimeToAnimation = 4; npc.frame = GetFrame(CurrentFrame + 0); } Player player = Main.player[npc.target]; int num1305 = 3; npc.noTileCollide = false; npc.noGravity = true; npc.damage = npc.defDamage; if (npc.target < 0 || player.dead || !player.active) { npc.TargetClosest(true); if (player.dead) { npc.ai[0] = -1f; } } else { Vector2 vector205 = player.Center - npc.Center; if (npc.ai[0] > 1f && vector205.Length() > 1000f) { npc.ai[0] = 1f; } } if (npc.ai[0] == -1f) { Vector2 value50 = new Vector2(0f, -8f); npc.velocity = (npc.velocity * 9f + value50) / 10f; npc.noTileCollide = true; npc.dontTakeDamage = true; return; } if (npc.ai[0] == 0f) { npc.TargetClosest(true); if (npc.Center.X < player.Center.X - 2f) { npc.direction = 1; } if (npc.Center.X > player.Center.X + 2f) { npc.direction = -1; } npc.spriteDirection = npc.direction; npc.rotation = (npc.rotation * 9f + npc.velocity.X * 0.1f) / 10f; if (npc.collideX) { npc.velocity.X = npc.velocity.X * (-npc.oldVelocity.X * 0.5f); if (npc.velocity.X > 16f) { npc.velocity.X = 16f; } if (npc.velocity.X < -16f) { npc.velocity.X = -16f; } } if (npc.collideY) { npc.velocity.Y = npc.velocity.Y * (-npc.oldVelocity.Y * 0.5f); if (npc.velocity.Y > 16f) { npc.velocity.Y = 16f; } if (npc.velocity.Y < -16f) { npc.velocity.Y = -16f; } } Vector2 value51 = player.Center - npc.Center; value51.Y -= 200f; if (value51.Length() > 800f) { npc.ai[0] = 1f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; } else if (value51.Length() > 80f) { float scaleFactor15 = 12f; float num1306 = 60f; value51.Normalize(); value51 *= scaleFactor15; npc.velocity = (npc.velocity * (num1306 - 1f) + value51) / num1306; } else if (npc.velocity.Length() > 2f) { npc.velocity *= 0.95f; } else if (npc.velocity.Length() < 1f) { npc.velocity *= 1.05f; } npc.ai[1] += 1f; if (npc.justHit) { npc.ai[1] += (float)Main.rand.Next(10, 30); } if (npc.ai[1] >= 180f && Main.netMode != 1) { npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; npc.netUpdate = true; while (npc.ai[0] == 0f) { int num1307 = Main.rand.Next(3); if (num1307 == 0 && Collision.CanHit(npc.Center, 1, 1, player.Center, 1, 1)) { npc.ai[0] = 2f; } else if (num1307 == 1) { npc.ai[0] = 3f; } else if (num1307 == 2 && NPC.CountNPCS(mod.NPCType("DesertPrincess2")) < num1305) { npc.ai[0] = 4f; } } return; } } else { if (npc.ai[0] == 1f) { npc.collideX = false; npc.collideY = false; npc.noTileCollide = true; if (npc.target < 0 || !player.active || player.dead) { npc.TargetClosest(true); } if (npc.velocity.X < 0f) { npc.direction = -1; } else if (npc.velocity.X > 0f) { npc.direction = 1; } npc.spriteDirection = npc.direction; npc.rotation = (npc.rotation * 9f + npc.velocity.X * 0.08f) / 10f; Vector2 value52 = player.Center - npc.Center; if (value52.Length() < 300f && !Collision.SolidCollision(npc.position, npc.width, npc.height)) { npc.ai[0] = 0f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; } float scaleFactor16 = 14f + value52.Length() / 100f; float num1308 = 25f; value52.Normalize(); value52 *= scaleFactor16; npc.velocity = (npc.velocity * (num1308 - 1f) + value52) / num1308; return; } if (npc.ai[0] == 2f) { npc.damage = (int)((double)npc.defDamage * 0.85); if (npc.target < 0 || !player.active || player.dead) { npc.TargetClosest(true); npc.ai[0] = 0f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; } if (player.Center.X - 10f < npc.Center.X) { npc.direction = -1; } else if (player.Center.X + 10f > npc.Center.X) { npc.direction = 1; } npc.spriteDirection = npc.direction; npc.rotation = (npc.rotation * 4f + npc.velocity.X * 0.1f) / 5f; if (npc.collideX) { npc.velocity.X = npc.velocity.X * (-npc.oldVelocity.X * 0.5f); if (npc.velocity.X > 16f) { npc.velocity.X = 16f; } if (npc.velocity.X < -16f) { npc.velocity.X = -16f; } } if (npc.collideY) { npc.velocity.Y = npc.velocity.Y * (-npc.oldVelocity.Y * 0.5f); if (npc.velocity.Y > 16f) { npc.velocity.Y = 16f; } if (npc.velocity.Y < -16f) { npc.velocity.Y = -16f; } } Vector2 value53 = player.Center - npc.Center; value53.Y -= 20f; npc.ai[2] += 0.0222222228f; if (Main.expertMode) { npc.ai[2] += 0.0166666675f; } float scaleFactor17 = 4f + npc.ai[2] + value53.Length() / 120f; float num1309 = 20f; value53.Normalize(); value53 *= scaleFactor17; npc.velocity = (npc.velocity * (num1309 - 1f) + value53) / num1309; npc.ai[1] += 1f; if (npc.ai[1] > 240f || !Collision.CanHit(npc.Center, 1, 1, player.Center, 1, 1)) { npc.ai[0] = 0f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; return; } } else { if (npc.ai[0] == 3f) { npc.noTileCollide = true; if (npc.velocity.X < 0f) { npc.direction = -1; } else { npc.direction = 1; } npc.spriteDirection = npc.direction; npc.rotation = (npc.rotation * 4f + npc.velocity.X * 0.07f) / 5f; Vector2 value54 = player.Center - npc.Center; value54.Y -= 12f; if (npc.Center.X > player.Center.X) { value54.X += 400f; } else { value54.X -= 400f; } if (Math.Abs(npc.Center.X - player.Center.X) > 350f && Math.Abs(npc.Center.Y - player.Center.Y) < 20f) { npc.ai[0] = 3.1f; npc.ai[1] = 0f; } npc.ai[1] += 0.0333333351f; float scaleFactor18 = 8f + npc.ai[1]; float num1310 = 8f; value54.Normalize(); value54 *= scaleFactor18; npc.velocity = (npc.velocity * (num1310 - 1f) + value54) / num1310; return; } if (npc.ai[0] == 3.1f) { npc.noTileCollide = true; npc.rotation = (npc.rotation * 4f + npc.velocity.X * 0.07f) / 5f; Vector2 vector206 = player.Center - npc.Center; vector206.Y -= 12f; float scaleFactor19 = 16f; float num1311 = 32f; vector206.Normalize(); vector206 *= scaleFactor19; npc.velocity = (npc.velocity * (num1311 - 1f) + vector206) / num1311; if (npc.velocity.X < 0f) { npc.direction = -1; } else { npc.direction = 1; } npc.spriteDirection = npc.direction; npc.ai[1] += 1f; if (npc.ai[1] > 10f) { npc.velocity = vector206; if (npc.velocity.X < 0f) { npc.direction = -1; } else { npc.direction = 1; } npc.ai[0] = 3.2f; npc.ai[1] = 0f; npc.ai[1] = (float)npc.direction; return; } } else { if (npc.ai[0] == 3.2f) { npc.damage = (int)((double)npc.defDamage * 1.3); npc.collideX = false; npc.collideY = false; npc.noTileCollide = true; npc.ai[2] += 0.0333333351f; npc.velocity.X = (16f + npc.ai[2]) * npc.ai[1]; if ((npc.ai[1] > 0f && npc.Center.X > player.Center.X + 260f) || (npc.ai[1] < 0f && npc.Center.X < player.Center.X - 260f)) { if (!Collision.SolidCollision(npc.position, npc.width, npc.height)) { npc.ai[0] = 0f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; } else if (Math.Abs(npc.Center.X - player.Center.X) > 800f) { npc.ai[0] = 1f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; } } npc.rotation = (npc.rotation * 4f + npc.velocity.X * 0.07f) / 5f; return; } if (npc.ai[0] == 4f) { npc.ai[0] = 0f; npc.TargetClosest(true); if (Main.netMode != 1) { npc.ai[1] = -1f; npc.ai[2] = -1f; for (int num1312 = 0; num1312 < 1000; num1312++) { int num1313 = (int)player.Center.X / 16; int num1314 = (int)player.Center.Y / 16; int num1315 = 30 + num1312 / 50; int num1316 = 20 + num1312 / 75; num1313 += Main.rand.Next(-num1315, num1315 + 1); num1314 += Main.rand.Next(-num1316, num1316 + 1); if (!WorldGen.SolidTile(num1313, num1314)) { while (!WorldGen.SolidTile(num1313, num1314) && (double)num1314 < Main.worldSurface) { num1314++; } if ((new Vector2((float)(num1313 * 16 + 8), (float)(num1314 * 16 + 8)) - player.Center).Length() < 600f) { npc.ai[0] = 4.1f; npc.ai[1] = (float)num1313; npc.ai[2] = (float)num1314; break; } } } } npc.netUpdate = true; return; } if (npc.ai[0] == 4.1f) { if (npc.velocity.X < -2f) { npc.direction = -1; } else if (npc.velocity.X > 2f) { npc.direction = 1; } npc.spriteDirection = npc.direction; npc.rotation = (npc.rotation * 9f + npc.velocity.X * 0.1f) / 10f; npc.noTileCollide = true; int num1317 = (int)npc.ai[1]; int num1318 = (int)npc.ai[2]; float x2 = (float)(num1317 * 16 + 8); float y2 = (float)(num1318 * 16 - 20); Vector2 vector207 = new Vector2(x2, y2); vector207 -= npc.Center; float num1319 = 6f + vector207.Length() / 150f; if (num1319 > 10f) { num1319 = 10f; } float num1320 = 40f; if (vector207.Length() < 10f) { npc.ai[0] = 4.2f; } vector207.Normalize(); vector207 *= num1319; npc.velocity = (npc.velocity * (num1320 - 1f) + vector207) / num1320; return; } if (npc.ai[0] == 4.2f) { npc.rotation = (npc.rotation * 9f + npc.velocity.X * 0.1f) / 10f; npc.noTileCollide = true; int num1321 = (int)npc.ai[1]; int num1322 = (int)npc.ai[2]; float x3 = (float)(num1321 * 16 + 8); float y3 = (float)(num1322 * 16 - 20); Vector2 vector208 = new Vector2(x3, y3); vector208 -= npc.Center; float num1323 = 4f; float num1324 = 2f; if (Main.netMode != 1 && vector208.Length() < 4f) { int num1325 = 70; if (Main.expertMode) { num1325 = (int)((double)num1325 * 0.75); } npc.ai[3] += 1f; if (npc.ai[3] == (float)num1325) { NPC.NewNPC(num1321 * 16 + 8, num1322 * 16, mod.NPCType("DesertPrincess2"), npc.whoAmI, 0f, 0f, 0f, 0f, 255); } else if (npc.ai[3] == (float)(num1325 * 2)) { npc.ai[0] = 0f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.ai[3] = 0f; if (NPC.CountNPCS(mod.NPCType("DesertPrincess2")) < num1305 && Main.rand.Next(3) != 0) { npc.ai[0] = 4f; } else if (Collision.SolidCollision(npc.position, npc.width, npc.height)) { npc.ai[0] = 1f; } } } if (vector208.Length() > num1323) { vector208.Normalize(); vector208 *= num1323; } npc.velocity = (npc.velocity * (num1324 - 1f) + vector208) / num1324; return; } } } } }
public override void AI() { npc.TargetClosest(true); npc.spriteDirection = npc.direction; Player player = Main.player[npc.target]; if (!player.active || player.dead) { npc.TargetClosest(false); npc.velocity.Y = 50; timer = 0; timer2 = 0; timer3 = 0; timer4 = 0; } timer++; if (timer <= 1000) { timer2++; } if (timer <= 1000) { timer3++; } if (timer >= 1000) { timer4++; } if (timer == 1500) { timer = 0; } if (timer >= 200 && timer <= 650) { Shoot(); npc.position += npc.velocity * 1.2f; } if (timer >= 650 && timer <= 1000) { Shoot(); int currentLifeP2 = npc.lifeMax * (2 / 3); int currentLifeP3 = npc.lifeMax * (1 / 3); if (npc.life <= currentLifeP2) { phase2 = true; } if (npc.life <= currentLifeP3) { phase3 = true; } if (Main.rand.Next(300) == 0) { Main.PlaySound(29, (int)npc.position.X, (int)npc.position.Y, 35); } //Player player = Main.player[npc.target]; bool playerWet = player.wet; //Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0f, 0.25f, 0.15f); int num1038 = 0; for (int num1039 = 0; num1039 < 255; num1039++) { if (Main.player[num1039].active && !Main.player[num1039].dead && (npc.Center - Main.player[num1039].Center).Length() < 1000f) { num1038++; } } if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active) { npc.TargetClosest(true); } if (Main.player[npc.target].dead) { npc.TargetClosest(false); npc.velocity.Y = npc.velocity.Y + 1f; if (npc.position.Y > Main.worldSurface * 16.0) { npc.velocity.Y = npc.velocity.Y + 1f; } if (npc.position.Y > Main.rockLayer * 16.0) { for (int num957 = 0; num957 < 200; num957++) { if (Main.npc[num957].aiStyle == npc.aiStyle) { Main.npc[num957].active = false; } } } } else if (npc.ai[0] == -1f) { if (Main.netMode != 1) { float num1041 = npc.ai[1]; int num1042; do { num1042 = Main.rand.Next(3); if (num1042 == 1) { num1042 = 2; } else if (num1042 == 2) { num1042 = 3; } }while (num1042 == num1041); npc.ai[0] = num1042; npc.ai[1] = 0f; npc.ai[2] = 0f; return; } } else if (npc.ai[0] == 0f) { int num1043 = 2; //2 not a prob if (npc.life < npc.lifeMax / 2) { num1043++; } if (npc.life < npc.lifeMax / 3) { num1043++; } if (npc.life < npc.lifeMax / 5) { num1043++; } if (npc.ai[1] > 2 * num1043 && npc.ai[1] % 2f == 0f) { npc.ai[0] = -1f; npc.ai[1] = 0f; npc.ai[2] = 0f; npc.netUpdate = true; return; } if (npc.ai[1] % 2f == 0f) { npc.TargetClosest(true); if (Math.Abs(npc.position.Y + npc.height / 2 - (Main.player[npc.target].position.Y + Main.player[npc.target].height / 2)) < 20f) { npc.localAI[0] = 1f; npc.ai[1] += 1f; npc.ai[2] = 0f; float num1044 = 16f; //16 if (npc.life < npc.lifeMax * 0.75) { num1044 += 2f; //2 not a prob } if (npc.life < npc.lifeMax * 0.5) { num1044 += 2f; //2 not a prob } if (npc.life < npc.lifeMax * 0.25) { num1044 += 2f; //2 not a prob } if (npc.life < npc.lifeMax * 0.1) { num1044 += 2f; //2 not a prob } Vector2 vector117 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num1045 = Main.player[npc.target].position.X + Main.player[npc.target].width / 2 - vector117.X; float num1046 = Main.player[npc.target].position.Y + Main.player[npc.target].height / 2 - vector117.Y; float num1047 = (float)Math.Sqrt(num1045 * num1045 + num1046 * num1046); num1047 = num1044 / num1047; npc.velocity.X = num1045 * num1047; npc.velocity.Y = num1046 * num1047; npc.spriteDirection = npc.direction; Main.PlaySound(29, (int)npc.position.X, (int)npc.position.Y, 34); return; } npc.localAI[0] = 0f; float num1048 = 12f; //12 not a prob float num1049 = 0.15f; //0.15 not a prob if (npc.life < npc.lifeMax * 0.75) { num1048 += 1f; //1 not a prob num1049 += 0.05f; //0.05 not a prob } if (npc.life < npc.lifeMax * 0.5) { num1048 += 1f; //1 not a prob num1049 += 0.05f; //0.05 not a prob } if (npc.life < npc.lifeMax * 0.25) { num1048 += 2f; //2 not a prob num1049 += 0.05f; //0.05 not a prob } if (npc.life < npc.lifeMax * 0.1) { num1048 += 2f; //2 not a prob num1049 += 0.1f; //0.1 not a prob } if (npc.position.Y + npc.height / 2 < Main.player[npc.target].position.Y + Main.player[npc.target].height / 2) { npc.velocity.Y = npc.velocity.Y + num1049; } else { npc.velocity.Y = npc.velocity.Y - num1049; } if (npc.velocity.Y < -12f) { npc.velocity.Y = -num1048; } if (npc.velocity.Y > 12f) { npc.velocity.Y = num1048; } if (Math.Abs(npc.position.X + npc.width / 2 - (Main.player[npc.target].position.X + Main.player[npc.target].width / 2)) > 600f) { npc.velocity.X = npc.velocity.X + 0.15f * npc.direction; } else if (Math.Abs(npc.position.X + npc.width / 2 - (Main.player[npc.target].position.X + Main.player[npc.target].width / 2)) < 300f) { npc.velocity.X = npc.velocity.X - 0.15f * npc.direction; } else { npc.velocity.X = npc.velocity.X * 0.8f; } if (npc.velocity.X < -16f) { npc.velocity.X = -16f; } if (npc.velocity.X > 16f) { npc.velocity.X = 16f; } npc.spriteDirection = npc.direction; return; } if (npc.velocity.X < 0f) { npc.direction = -1; } else { npc.direction = 1; } npc.spriteDirection = npc.direction; int num1050 = 600; //600 not a prob if (!playerWet) { num1050 = 350; } else { num1050 = 600; if (npc.life < npc.lifeMax * 0.1) { num1050 = 800; //300 not a prob } else if (npc.life < npc.lifeMax * 0.25) { num1050 = 750; //450 not a prob } else if (npc.life < npc.lifeMax * 0.5) { num1050 = 700; //500 not a prob } else if (npc.life < npc.lifeMax * 0.75) { num1050 = 650; //550 not a prob } } int num1051 = 1; if (npc.position.X + npc.width / 2 < Main.player[npc.target].position.X + Main.player[npc.target].width / 2) { num1051 = -1; } if (npc.direction == num1051 && Math.Abs(npc.position.X + npc.width / 2 - (Main.player[npc.target].position.X + Main.player[npc.target].width / 2)) > num1050) { npc.ai[2] = 1f; } if (npc.ai[2] != 1f) { npc.localAI[0] = 1f; return; } npc.TargetClosest(true); npc.spriteDirection = npc.direction; npc.localAI[0] = 0f; npc.velocity *= 0.9f; float num1052 = 0.1f; //0.1 if (npc.life < npc.lifeMax / 2) { npc.velocity *= 0.9f; num1052 += 0.05f; //0.05 } if (npc.life < npc.lifeMax / 3) { npc.velocity *= 0.9f; num1052 += 0.05f; //0.05 } if (npc.life < npc.lifeMax / 5) { npc.velocity *= 0.9f; num1052 += 0.05f; //0.05 } if (Math.Abs(npc.velocity.X) + Math.Abs(npc.velocity.Y) < num1052) { npc.ai[2] = 0f; npc.ai[1] += 1f; return; } } else if (npc.ai[0] == 2f) { npc.TargetClosest(true); npc.spriteDirection = npc.direction; float num1053 = 12f; //12 found one! dictates speed during bee spawn float num1054 = 0.1f; //0.1 found one! dictates speed during bee spawn Vector2 vector118 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num1055 = Main.player[npc.target].position.X + Main.player[npc.target].width / 2 - vector118.X; float num1056 = Main.player[npc.target].position.Y + Main.player[npc.target].height / 2 - 200f - vector118.Y; float num1057 = (float)Math.Sqrt(num1055 * num1055 + num1056 * num1056); if (num1057 < 800f) { npc.ai[0] = 1f; npc.ai[1] = 0f; npc.netUpdate = true; return; } num1057 = num1053 / num1057; if (npc.velocity.X < num1055) { npc.velocity.X = npc.velocity.X + num1054; if (npc.velocity.X < 0f && num1055 > 0f) { npc.velocity.X = npc.velocity.X + num1054; } } else if (npc.velocity.X > num1055) { npc.velocity.X = npc.velocity.X - num1054; if (npc.velocity.X > 0f && num1055 < 0f) { npc.velocity.X = npc.velocity.X - num1054; } } if (npc.velocity.Y < num1056) { npc.velocity.Y = npc.velocity.Y + num1054; if (npc.velocity.Y < 0f && num1056 > 0f) { npc.velocity.Y = npc.velocity.Y + num1054; return; } } else if (npc.velocity.Y > num1056) { npc.velocity.Y = npc.velocity.Y - num1054; if (npc.velocity.Y > 0f && num1056 < 0f) { npc.velocity.Y = npc.velocity.Y - num1054; return; } } } else if (npc.ai[0] == 1f) { npc.localAI[0] = 0f; npc.TargetClosest(true); Vector2 vector119 = new Vector2(npc.position.X + npc.width / 2 + Main.rand.Next(20) * npc.direction, npc.position.Y + npc.height * 0.8f); Vector2 vector120 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num1058 = Main.player[npc.target].position.X + Main.player[npc.target].width / 2 - vector120.X; float num1059 = Main.player[npc.target].position.Y + Main.player[npc.target].height / 2 - vector120.Y; float num1060 = (float)Math.Sqrt(num1058 * num1058 + num1059 * num1059); npc.ai[1] += 1f; npc.ai[1] += num1038 / 2; if (npc.life < npc.lifeMax * 0.75) { npc.ai[1] += 0.25f; //0.25 not a prob } if (npc.life < npc.lifeMax * 0.5) { npc.ai[1] += 0.25f; //0.25 not a prob } if (npc.life < npc.lifeMax * 0.25) { npc.ai[1] += 0.25f; //0.25 not a prob } if (npc.life < npc.lifeMax * 0.1) { npc.ai[1] += 0.25f; //0.25 not a prob } bool flag103 = false; if (npc.ai[1] > 40f) //changed from 40 not a prob { npc.ai[1] = 0f; npc.ai[2] += 1f; flag103 = true; } if (Collision.CanHit(vector119, 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height) && flag103) { Main.PlaySound(3, (int)npc.position.X, (int)npc.position.Y, 25); if (Main.netMode != 1) { int num1061; if (Main.rand.Next(4) == 0) { num1061 = mod.NPCType("AquaticAberration"); //Aquatic entity spawns } else { num1061 = mod.NPCType("Parasea"); } int num1062 = NPC.NewNPC((int)vector119.X, (int)vector119.Y, num1061, 0, 0f, 0f, 0f, 0f, 255); Main.npc[num1062].velocity.X = Main.rand.Next(-200, 201) * 0.01f; Main.npc[num1062].velocity.Y = Main.rand.Next(-200, 201) * 0.01f; Main.npc[num1062].localAI[0] = 60f; Main.npc[num1062].netUpdate = true; } } if (num1060 > 400f || !Collision.CanHit(new Vector2(vector119.X, vector119.Y - 30f), 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { float num1063 = 14f; //changed from 14 not a prob float num1064 = 0.1f; //changed from 0.1 not a prob vector120 = vector119; num1058 = Main.player[npc.target].position.X + Main.player[npc.target].width / 2 - vector120.X; num1059 = Main.player[npc.target].position.Y + Main.player[npc.target].height / 2 - vector120.Y; num1060 = (float)Math.Sqrt(num1058 * num1058 + num1059 * num1059); num1060 = num1063 / num1060; if (npc.velocity.X < num1058) { npc.velocity.X = npc.velocity.X + num1064; if (npc.velocity.X < 0f && num1058 > 0f) { npc.velocity.X = npc.velocity.X + num1064; } } else if (npc.velocity.X > num1058) { npc.velocity.X = npc.velocity.X - num1064; if (npc.velocity.X > 0f && num1058 < 0f) { npc.velocity.X = npc.velocity.X - num1064; } } if (npc.velocity.Y < num1059) { npc.velocity.Y = npc.velocity.Y + num1064; if (npc.velocity.Y < 0f && num1059 > 0f) { npc.velocity.Y = npc.velocity.Y + num1064; } } else if (npc.velocity.Y > num1059) { npc.velocity.Y = npc.velocity.Y - num1064; if (npc.velocity.Y > 0f && num1059 < 0f) { npc.velocity.Y = npc.velocity.Y - num1064; } } } else { npc.velocity *= 0.9f; } npc.spriteDirection = npc.direction; if (npc.ai[2] > 3f) { npc.ai[0] = -1f; npc.ai[1] = 1f; npc.netUpdate = true; return; } } } if (timer >= 1000 && timer <= 1250) { Shoot(); npc.ai[0]++; 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] >= 100 && npc.ai[1] < 200) { if (Main.rand.Next(10) == 0) { npc.velocity.X *= 5.00f; npc.velocity.Y *= 5.00f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f)); { float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f))); npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1; npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1; } return; } } if (npc.ai[1] >= 280 && npc.ai[1] < 320) { if (Main.rand.Next(5) == 0) { npc.velocity.X *= 10.00f; npc.velocity.Y *= 10.00f; Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f)); { float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f))); npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1; npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1; } return; } } if (npc.ai[1] >= 450) { npc.ai[1] = 0; } } if (timer >= 1250) { npc.velocity.Y = 0; npc.velocity.X = 0; npc.rotation = 0f; if (Main.rand.Next(70) == 0) { NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("PixieQueenGuardian")); } } }
public override void AI() { Player player = Main.player[npc.target]; npc.noGravity = true; if (Main.netMode != 1) { npc.ai[3]++; } if (npc.ai[3] > 240) { if (SelectPoint && Main.netMode != 1) { float Point = 500 * npc.direction; MovePoint = player.Center + new Vector2(Point, 500f); SelectPoint = false; npc.netUpdate = true; } MoveToPoint(MovePoint); if (npc.ai[3] > 300 && Main.netMode != 1) { npc.ai = new float[4]; npc.netUpdate = true; } } else { if (npc.collideX) { npc.velocity.X = npc.oldVelocity.X * -0.5f; if (npc.direction == -1 && npc.velocity.X > 0f && npc.velocity.X < 2f) { npc.velocity.X = 2f; } if (npc.direction == 1 && npc.velocity.X < 0f && npc.velocity.X > -2f) { npc.velocity.X = -2f; } } if (npc.collideY) { npc.velocity.Y = npc.oldVelocity.Y * -0.5f; if (npc.velocity.Y > 0f && npc.velocity.Y < 1f) { npc.velocity.Y = 1f; } if (npc.velocity.Y < 0f && npc.velocity.Y > -1f) { npc.velocity.Y = -1f; } } npc.TargetClosest(true); if (npc.direction == -1 && npc.velocity.X > -4f) { npc.velocity.X = npc.velocity.X - 0.1f; if (npc.velocity.X > 4f) { npc.velocity.X = npc.velocity.X - 0.1f; } else if (npc.velocity.X > 0f) { npc.velocity.X = npc.velocity.X + 0.05f; } if (npc.velocity.X < -4f) { npc.velocity.X = -4f; } } else if (npc.direction == 1 && npc.velocity.X < 4f) { npc.velocity.X = npc.velocity.X + 0.1f; if (npc.velocity.X < -4f) { npc.velocity.X = npc.velocity.X + 0.1f; } else if (npc.velocity.X < 0f) { npc.velocity.X = npc.velocity.X - 0.05f; } if (npc.velocity.X > 4f) { npc.velocity.X = 4f; } } if (npc.directionY == -1 && npc.velocity.Y > -1.5) { npc.velocity.Y = npc.velocity.Y - 0.04f; if (npc.velocity.Y > 1.5) { npc.velocity.Y = npc.velocity.Y - 0.05f; } else if (npc.velocity.Y > 0f) { npc.velocity.Y = npc.velocity.Y + 0.03f; } if (npc.velocity.Y < -1.5) { npc.velocity.Y = -1.5f; } } else if (npc.directionY == 1 && npc.velocity.Y < 1.5) { npc.velocity.Y = npc.velocity.Y + 0.04f; if (npc.velocity.Y < -1.5) { npc.velocity.Y = npc.velocity.Y + 0.05f; } else if (npc.velocity.Y < 0f) { npc.velocity.Y = npc.velocity.Y - 0.03f; } if (npc.velocity.Y > 1.5) { npc.velocity.Y = 1.5f; } } npc.ai[1] += 1f; if (npc.ai[1] > 200f) { if (!Main.player[npc.target].wet && Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { npc.ai[1] = 0f; } float num205 = 0.2f; float num206 = 0.1f; float num207 = 4f; float num208 = 1.5f; if (npc.ai[1] > 1000f) { npc.ai[1] = 0f; } npc.ai[2] += 1f; if (npc.ai[2] > 0f) { if (npc.velocity.Y < num208) { npc.velocity.Y = npc.velocity.Y + num206; } } else if (npc.velocity.Y > -num208) { npc.velocity.Y = npc.velocity.Y - num206; } if (npc.ai[2] < -150f || npc.ai[2] > 150f) { if (npc.velocity.X < num207) { npc.velocity.X = npc.velocity.X + num205; } } else if (npc.velocity.X > -num207) { npc.velocity.X = npc.velocity.X - num205; } if (npc.ai[2] > 300f) { npc.ai[2] = -300f; } } if (Main.netMode != 1) { npc.ai[0] += 1f; if (npc.ai[0] == 20f || npc.ai[0] == 40f || npc.ai[0] == 60f || npc.ai[0] == 80f || npc.ai[0] == 100f) { if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { float num223 = 0.2f; Vector2 value2 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num224 = Main.player[npc.target].position.X + Main.player[npc.target].width * 0.5f - value2.X + Main.rand.Next(-50, 51); float num225 = Main.player[npc.target].position.Y + Main.player[npc.target].height * 0.5f - value2.Y + Main.rand.Next(-50, 51); float num226 = (float)Math.Sqrt(num224 * num224 + num225 * num225); num226 = num223 / num226; num224 *= num226; num225 *= num226; int num227 = 80; value2 += npc.velocity * 5f; int num229 = Projectile.NewProjectile(value2.X + num224 * 100f, value2.Y + num225 * 100f, num224, num225, ModContent.ProjectileType <DynaBlast>(), num227, 0f, Main.myPlayer, 0f, 0f); Main.projectile[num229].timeLeft = 300; return; } } else if (npc.ai[0] >= 250 + Main.rand.Next(250)) { npc.ai[0] = 0f; return; } } } }
public override void AI() { projectile.ai[0] += 1f; if (projectile.ai[0] >= 18f) { projectile.ai[0] = 18f; projectile.velocity.Y = projectile.velocity.Y + 0.38f; } if (projectile.velocity.Y > 19f) { projectile.velocity.Y = 19f; } float num2 = (float)Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)); float num3 = projectile.localAI[0]; if (num3 == 0f) { projectile.localAI[0] = num2; num3 = num2; } float num4 = projectile.position.X; float num5 = projectile.position.Y; float num6 = 300f; bool flag = false; int num7 = 0; if (projectile.ai[1] == 0f) { for (int i = 0; i < 200; i++) { if (Main.npc[i].CanBeChasedBy(this, false) && (projectile.ai[1] == 0f || projectile.ai[1] == (float)(i + 1))) { float num8 = Main.npc[i].position.X + (float)(Main.npc[i].width / 2); float num9 = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2); float num10 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num8) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num9); if (num10 < num6 && Collision.CanHit(new Vector2(projectile.position.X + (float)(projectile.width / 2), projectile.position.Y + (float)(projectile.height / 2)), 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) { num6 = num10; num4 = num8; num5 = num9; flag = true; num7 = i; } } } if (flag) { projectile.ai[1] = (float)(num7 + 1); } flag = false; } if (projectile.ai[1] > 0f) { int num11 = (int)(projectile.ai[1] - 1f); if (Main.npc[num11].active && Main.npc[num11].CanBeChasedBy(this, true) && !Main.npc[num11].dontTakeDamage) { float num12 = Main.npc[num11].position.X + (float)(Main.npc[num11].width / 2); float num13 = Main.npc[num11].position.Y + (float)(Main.npc[num11].height / 2); if (Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num12) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num13) < 1000f) { flag = true; num4 = Main.npc[num11].position.X + (float)(Main.npc[num11].width / 2); num5 = Main.npc[num11].position.Y + (float)(Main.npc[num11].height / 2); } } else { projectile.ai[1] = 0f; } } if (!projectile.friendly) { flag = false; } if (flag) { float num14 = num3; Vector2 vector = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num15 = num4 - vector.X; float num16 = num5 - vector.Y; float num17 = (float)Math.Sqrt((double)(num15 * num15 + num16 * num16)); num17 = num14 / num17; num15 *= num17; num16 *= num17; int num18 = 8; projectile.velocity.X = (projectile.velocity.X * (float)(num18 - 1) + num15) / (float)num18; projectile.velocity.Y = (projectile.velocity.Y * (float)(num18 - 1) + num16) / (float)num18; } if (Main.rand.Next(3) == 0) { int num = Dust.NewDust(projectile.position, projectile.width, projectile.height, 229, projectile.velocity.X, projectile.velocity.Y, 100, default(Color), 1.2f); Main.dust[num].velocity /= 10; Main.dust[num].noGravity = true; Main.dust[num].color = Color.Aqua; } if (Main.rand.Next(5) == 0) { int num168 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 172, projectile.velocity.X, projectile.velocity.Y, 100, default(Color), 1.1f); Main.dust[num168].noGravity = true; Main.dust[num168].velocity /= 20; Main.dust[num168].color = Color.Brown; } }
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { Main.PlaySound(new Terraria.Audio.LegacySoundStyle(2, 124, Terraria.Audio.SoundType.Sound)); projectile.localNPCImmunity[target.whoAmI] = -1; target.immune[projectile.owner] = 0; target.AddBuff(mod.BuffType("Electrified"), 500); if (target.life <= 0) { Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X, projectile.velocity.Y, mod.ProjectileType("ThunderBoom"), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); Main.PlaySound(new Terraria.Audio.LegacySoundStyle(2, 124, Terraria.Audio.SoundType.Sound)); } for (int k = 0; k < 200; k++) { possibleTarget = Main.npc[k]; distance = (possibleTarget.Center - projectile.Center).Length(); if (distance < maxDistance && possibleTarget.active && !possibleTarget.dontTakeDamage && projectile.localNPCImmunity[k] >= 0 && !possibleTarget.friendly && possibleTarget.lifeMax > 5 && !possibleTarget.immortal && Collision.CanHit(projectile.Center, 0, 0, possibleTarget.Center, 0, 0)) { ConfirmedTarget = Main.npc[k]; foundTarget = true; maxDistance = (ConfirmedTarget.Center - projectile.Center).Length(); } } if (foundTarget) { projectile.velocity = PolarVector(maxSpeed, (ConfirmedTarget.Center - projectile.Center).ToRotation()); } else { projectile.Kill(); } foundTarget = false; maxDistance = 1000; }
public override void AI() { float num472 = projectile.Center.X; float num473 = projectile.Center.Y; float num474 = 400f; bool flag17 = false; for (int num475 = 0; num475 < 200; num475++) { if (Main.npc[num475].CanBeChasedBy(projectile, false) && Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1)) { float num476 = Main.npc[num475].position.X + (float)(Main.npc[num475].width / 2); float num477 = Main.npc[num475].position.Y + (float)(Main.npc[num475].height / 2); float num478 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num476) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num477); if (num478 < num474) { num474 = num478; num472 = num476; num473 = num477; flag17 = true; } } } if (flag17) { float num483 = 20f; Vector2 vector35 = new Vector2(projectile.position.X + ((float)projectile.width * 0.5f), projectile.position.Y + ((float)projectile.height * 0.5f)); float num484 = num472 - vector35.X; float num485 = num473 - vector35.Y; float num486 = (float)Math.Sqrt((double)((num484 * num484) + (num485 * num485))); num486 = num483 / num486; num484 *= num486; num485 *= num486; projectile.velocity.X = ((projectile.velocity.X * 20f) + num484) / 21f; projectile.velocity.Y = ((projectile.velocity.Y * 20f) + num485) / 21f; projectile.rotation += projectile.direction * 0.8f; projectile.ai[0] += 1f; if (projectile.ai[0] >= 30f) { if (projectile.ai[0] < 100f) { projectile.velocity *= 1.00f; } else { projectile.ai[0] = 200f; } } for (int num257 = 0; num257 < 2; num257++) { int num258 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, mod.DustType <Dusts.VoidDust>(), 0f, 0f, 100, new Color(120, 0, 30), 1f); Main.dust[num258].noGravity = true; } return; } projectile.rotation += projectile.direction * 0.8f; projectile.ai[0] += 1f; if (projectile.ai[0] >= 30f) { if (projectile.ai[0] < 100f) { projectile.velocity *= 1.00f; } else { projectile.ai[0] = 200f; } } for (int num257 = 0; num257 < 2; num257++) { int num258 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, mod.DustType <Dusts.VoidDust>(), 0f, 0f, 100, new Color(120, 0, 30), 1f); Main.dust[num258].noGravity = true; } return; }
public override void AI() { //PlayAnimation(); if (npc.life > npc.lifeMax / 2) { FirstState = true; } if (npc.life < npc.lifeMax / 2) { FirstState = false; SecondState = true; } if (Main.rand.Next(150) == 0) { for (int num36 = 0; num36 < 25; num36++) { int dust = Dust.NewDust(new Vector2((float)npc.position.X, (float)npc.position.Y), npc.width, npc.height, mod.DustType("CyberDust"), npc.velocity.X + Main.rand.Next(-10, 10), npc.velocity.Y + Main.rand.Next(-10, 10), 1, npc.color, 1f); Main.dust[dust].noGravity = true; } npc.ai[3] = (float)(Main.rand.Next(360) * (Math.PI / 180)); npc.ai[2] = 0; npc.ai[1] = 0; if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active) { npc.TargetClosest(true); } if (Main.player[npc.target].dead) { npc.position.X = 0; npc.position.Y = 0; if (npc.timeLeft > 10) { npc.timeLeft = 10; return; } } else { npc.position.X = Main.player[npc.target].position.X + (float)((250 * Math.Cos(npc.ai[3])) * -1); npc.position.Y = Main.player[npc.target].position.Y + (float)((250 * Math.Sin(npc.ai[3])) * -1); } } if (Main.rand.Next(2) == 0) { int num706 = Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("CyberDust"), 0f, 0f, 200, npc.color, 0.5f); Main.dust[num706].velocity *= 0.6f; } if (FirstState) { npc.TargetClosest(true); Vector2 PTC = Main.player[npc.target].position + new Vector2(npc.width / 2, npc.height / 2); Vector2 NPos = npc.position + new Vector2(npc.width / 2, npc.height / 2); npc.netUpdate = true; if (npc.ai[1] == 0) { if (Main.player[npc.target].position.X < npc.position.X) { if (npc.velocity.X > -8) { npc.velocity.X -= 0.10f; } } if (Main.player[npc.target].position.X > npc.position.X) { if (npc.velocity.X < 8) { npc.velocity.X += 0.10f; } } if (Main.player[npc.target].position.Y < npc.position.Y + 200) { if (npc.velocity.Y < 0) { if (npc.velocity.Y > -4) { npc.velocity.Y -= 0.4f; } } else { npc.velocity.Y -= 0.8f; } } if (Main.player[npc.target].position.Y > npc.position.Y + 200) { if (npc.velocity.Y > 0) { if (npc.velocity.Y < 4) { npc.velocity.Y += 0.4f; } } else { npc.velocity.Y += 0.6f; } } } customAi1 += (Main.rand.Next(2, 5) * 0.1f) * npc.scale; if (customAi1 >= 4f) { if (Main.rand.Next(120) == 1) { Main.PlaySound(16, (int)npc.position.X, (int)npc.position.Y, 12); float Angle = (float)Math.Atan2(NPos.Y - PTC.Y, NPos.X - PTC.X); int SpitShot1 = Projectile.NewProjectile(NPos.X, NPos.Y, (float)((Math.Cos(Angle) * 22f) * -1), (float)((Math.Sin(Angle) * 22f) * -1), mod.ProjectileType("CyberLaserBat"), 30, 0f, 0); //Main.projectile[SpitShot1].friendly = false; Main.projectile[SpitShot1].timeLeft = 500; customAi1 = 1f; } } npc.netUpdate = true; if (Main.rand.Next(6) == 0) { int dust = Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("CyberDust"), 0f, 0f, 200, npc.color, 0.4f); Main.dust[dust].velocity *= 0.4f; } if (npc.ai[1] == 1) { } npc.ai[2] += 1; if (npc.ai[2] >= 600) { if (npc.ai[1] == 0) { npc.ai[1] = 1; } else { npc.ai[1] = 0; } } if (npc.life > 500) { Color color = new Color(); int dust = Dust.NewDust(new Vector2((float)npc.position.X, (float)npc.position.Y), npc.width, npc.height, mod.DustType("CyberDust"), npc.velocity.X, npc.velocity.Y, 100, color, 0.6f); Main.dust[dust].noGravity = true; } else if (npc.life <= 200) { Color color = new Color(); int dust = Dust.NewDust(new Vector2((float)npc.position.X, (float)npc.position.Y), npc.width, npc.height, mod.DustType("CyberDust"), npc.velocity.X, npc.velocity.Y, 50, color, 0.8f); Main.dust[dust].noGravity = true; } } if (SecondState && !FirstState) { Vector2 PTC = Main.player[npc.target].position + new Vector2(npc.width / 2, npc.height / 2); Vector2 NPos = npc.position + new Vector2(npc.width / 2, npc.height / 2); if (Main.rand.Next(70) == 1) { Main.PlaySound(16, (int)npc.position.X, (int)npc.position.Y, 12); float Angle = (float)Math.Atan2(NPos.Y - PTC.Y, NPos.X - PTC.X); int SpitShot1 = Projectile.NewProjectile(NPos.X, NPos.Y, (float)((Math.Cos(Angle) * 22f) * -1), (float)((Math.Sin(Angle) * 22f) * -1), mod.ProjectileType("CyberLaserBat"), 30, 0f, 0); //Main.projectile[SpitShot1].friendly = false; Main.projectile[SpitShot1].timeLeft = 500; customAi1 = 1f; } float npc_to_target_x = npc.position.X + (float)(npc.width / 2) - Main.player[npc.target].position.X - (float)(Main.player[npc.target].width / 2); float npc_to_target_y = npc.position.Y + (float)npc.height - 59f - Main.player[npc.target].position.Y - (float)(Main.player[npc.target].height / 2); // 59(3.7 blocks) above bottom(slightly above center; ht is 110) to target center float npc_to_target_angle = (float)Math.Atan2((double)npc_to_target_y, (double)npc_to_target_x) + 1.57f; // angle+pi/2 if (npc_to_target_angle < 0f) // modulus { npc_to_target_angle += 6.283f; } else if ((double)npc_to_target_angle > 6.283) { npc_to_target_angle -= 6.283f; } float rotation_rate = 0.15f; float top_speed = 4f; float accel = 0.1f; int close_side_of_target = 1; if (npc.position.X + (float)(npc.width / 2) < Main.player[npc.target].position.X + (float)Main.player[npc.target].width) { close_side_of_target = -1; } Vector2 npc_pos = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); npc_to_target_x = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) + (float)(close_side_of_target * 360) - npc_pos.X; npc_to_target_y = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) + (float)(close_side_of_target * 160) - npc_pos.Y; float dist_to_target = (float)Math.Sqrt((double)(npc_to_target_x * npc_to_target_x + npc_to_target_y * npc_to_target_y)); dist_to_target = top_speed / dist_to_target; npc_to_target_x *= dist_to_target; npc_to_target_y *= dist_to_target; if (npc.velocity.X < npc_to_target_x) { npc.velocity.X = npc.velocity.X + accel; if (npc.velocity.X < 0f && npc_to_target_x > 0f) { npc.velocity.X = npc.velocity.X + accel; } } else if (npc.velocity.X > npc_to_target_x) { npc.velocity.X = npc.velocity.X - accel; if (npc.velocity.X > 0f && npc_to_target_x < 0f) { npc.velocity.X = npc.velocity.X - accel; } } if (npc.velocity.Y < npc_to_target_y) { npc.velocity.Y = npc.velocity.Y + accel; if (npc.velocity.Y < 0f && npc_to_target_y > 0f) { npc.velocity.Y = npc.velocity.Y + accel; } } else if (npc.velocity.Y > npc_to_target_y) { npc.velocity.Y = npc.velocity.Y - accel; if (npc.velocity.Y > 0f && npc_to_target_y < 0f) { npc.velocity.Y = npc.velocity.Y - accel; } } bool target_dead = Main.player[npc.target].dead; if (target_dead) { npc.velocity.Y = npc.velocity.Y - 0.04f; if (npc.timeLeft > 10) { npc.timeLeft = 10; return; } } else { if (npc.ai[1] == 0f) { top_speed = 4f; accel = 0.1f; close_side_of_target = 1; if (npc.position.X + (float)(npc.width / 2) < Main.player[npc.target].position.X + (float)Main.player[npc.target].width) { close_side_of_target = -1; } npc_pos = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); npc_to_target_x = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) + (float)(close_side_of_target * 360) - npc_pos.X; //360 pix in front of target npc_to_target_y = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) + (float)(close_side_of_target * 160) - npc_pos.Y; //160 pix above target dist_to_target = (float)Math.Sqrt((double)(npc_to_target_x * npc_to_target_x + npc_to_target_y * npc_to_target_y)); dist_to_target = top_speed / dist_to_target; npc_to_target_x *= dist_to_target; npc_to_target_y *= dist_to_target; if (npc.velocity.X < npc_to_target_x) { npc.velocity.X = npc.velocity.X + accel; if (npc.velocity.X < 0f && npc_to_target_x > 0f) { npc.velocity.X = npc.velocity.X + accel; } } else if (npc.velocity.X > npc_to_target_x) { npc.velocity.X = npc.velocity.X - accel; if (npc.velocity.X > 0f && npc_to_target_x < 0f) { npc.velocity.X = npc.velocity.X - accel; } } if (npc.velocity.Y < npc_to_target_y) { npc.velocity.Y = npc.velocity.Y + accel; if (npc.velocity.Y < 0f && npc_to_target_y > 0f) { npc.velocity.Y = npc.velocity.Y + accel; } } else if (npc.velocity.Y > npc_to_target_y) { npc.velocity.Y = npc.velocity.Y - accel; if (npc.velocity.Y > 0f && npc_to_target_y < 0f) { npc.velocity.Y = npc.velocity.Y - accel; } } npc.ai[2] += 1f; // inc count till charge if (npc.ai[2] >= 400f) // charge after 400 ticks { npc.ai[1] = 1f; // transition state to 'start charge' npc.ai[2] = 0f; npc.ai[3] = 0f; npc.target = 255; // retarget npc.netUpdate = true; } if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { npc.localAI[2] += 1f; // ??? if (Main.netMode != 1) // is server { // localAI[1] grows faster the less life left npc.localAI[1] += 1f; if (npc.localAI[1] > 12f) { npc.localAI[1] = 10f; float projectile_velocity = 15f; int projectile_dmg = 75; npc_pos = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); npc_to_target_x = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - npc_pos.X; npc_to_target_y = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - npc_pos.Y; dist_to_target = (float)Math.Sqrt((double)(npc_to_target_x * npc_to_target_x + npc_to_target_y * npc_to_target_y)); dist_to_target = projectile_velocity / dist_to_target; // prep to normalize by velocity npc_to_target_x *= dist_to_target; // normalize by velocity npc_to_target_y *= dist_to_target; // normalize by velocity npc_to_target_y += npc.velocity.Y * 0.5f; // advance fwd half a tick npc_to_target_x += npc.velocity.X * 0.5f; // advance fwd half a tick npc_pos.X -= npc_to_target_x * 1f; npc_pos.Y -= npc_to_target_y * 1f; //Projectile.NewProjectile(npc_pos.X, npc_pos.Y, npc_to_target_x, npc_to_target_y, ProjDef.byName["Pumpking:TerraGuardLaser"].type, projectile_dmg, 0f, Main.myPlayer); return; } } } } else if (npc.ai[1] == 1f) { npc.rotation = npc_to_target_angle; float speed = 14f; npc_pos = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); npc_to_target_x = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - npc_pos.X; npc_to_target_y = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2) - npc_pos.Y; dist_to_target = (float)Math.Sqrt((double)(npc_to_target_x * npc_to_target_x + npc_to_target_y * npc_to_target_y)); dist_to_target = speed / dist_to_target; npc.velocity.X = npc_to_target_x * dist_to_target; npc.velocity.Y = npc_to_target_y * dist_to_target; npc.ai[1] = 2f; return; } else if (npc.ai[1] == 2f) { npc.ai[2] += 1f; if (npc.ai[2] >= 50f) { npc.velocity.X = npc.velocity.X * 0.93f; npc.velocity.Y = npc.velocity.Y * 0.93f; if ((double)npc.velocity.X > -0.1 && (double)npc.velocity.X < 0.1) { npc.velocity.X = 0f; } if ((double)npc.velocity.Y > -0.1 && (double)npc.velocity.Y < 0.1) { npc.velocity.Y = 0f; } } else { npc.rotation = (float)Math.Atan2((double)npc.velocity.Y, (double)npc.velocity.X) - 1.57f; } if (npc.ai[2] >= 80f) { npc.ai[3] += 1f; npc.ai[2] = 0f; npc.target = 255; npc.rotation = npc_to_target_angle; if (npc.ai[3] >= 6f) { npc.ai[1] = 0f; npc.ai[3] = 0f; return; } npc.ai[1] = 1f; return; } } } } }
public override void AI() { projectile.frameCounter++; if (projectile.frameCounter > 6) { projectile.frame++; projectile.frameCounter = 0; } if (projectile.frame > 5) { projectile.frame = 0; } //Making player variable "p" set as the projectile's owner Player player = Main.player[projectile.owner]; bool flag64 = projectile.type == mod.ProjectileType("EyeofTheStorm"); MyPlayer modPlayer = (MyPlayer)player.GetModPlayer(mod, "MyPlayer"); if (player.dead) { modPlayer.EarthTurret = false; } if (modPlayer.EyeofTheStorm) { projectile.timeLeft = 2; } if (!modPlayer.EyeofTheStorm) { projectile.Kill(); } float num24 = 0.6f; float num25 = 9999f; projectile.tileCollide = false; Vector2 vector4 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num26 = Main.player[projectile.owner].position.X + (float)(Main.player[projectile.owner].width / 2) - vector4.X; float num27 = Main.player[projectile.owner].position.Y + Main.player[projectile.owner].gfxOffY + (float)(Main.player[projectile.owner].height / 2) - vector4.Y; if (Main.player[projectile.owner].direction == -1) { num26 -= 20f; projectile.direction = -1; } else if (Main.player[projectile.owner].direction == 1) { num26 += 20f; projectile.direction = 1; } num27 -= 30f; float num28 = (float)Math.Sqrt((double)(num26 * num26 + num27 * num27)); projectile.position.X = projectile.position.X + num26; projectile.position.Y = projectile.position.Y + num27; int num9; projectile.spriteDirection = projectile.direction; int num3 = projectile.frameCounter; int[] array = new int[20]; int num433 = 0; float num434 = 10000f; bool flag14 = false; for (int num435 = 0; num435 < 200; num435 = num3 + 1) { if (Main.npc[num435].CanBeChasedBy(projectile, false)) { float num436 = Main.npc[num435].position.X + (float)(Main.npc[num435].width / 2); float num437 = Main.npc[num435].position.Y + (float)(Main.npc[num435].height / 2); float num438 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num436) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num437); if (num438 < num434 && Collision.CanHit(projectile.Center, 1, 1, Main.npc[num435].Center, 1, 1)) { if (num433 < 20) { array[num433] = num435; num3 = num433; num433 = num3 + 1; } flag14 = true; } } num3 = num435; } if (flag14) { int num439 = Main.rand.Next(num433); num439 = array[num439]; float num440 = Main.npc[num439].position.X + (float)(Main.npc[num439].width / 2); float num441 = Main.npc[num439].position.Y + (float)(Main.npc[num439].height / 2); projectile.localAI[0] += 1f; if (projectile.localAI[0] == 125f) { projectile.localAI[0] = 0f; } if (projectile.localAI[0] == 80f || projectile.localAI[0] == 90f || projectile.localAI[0] == 100f) { Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 93); //zap sound float num442 = 4f; Vector2 vector32 = new Vector2(projectile.Center.X, projectile.Center.Y); vector32 += projectile.velocity * 4f; float num443 = num440 - vector32.X; float num444 = num441 - vector32.Y; float num445 = (float)Math.Sqrt((double)(num443 * num443 + num444 * num444)); num445 = num442 / num445; num443 *= num445; num444 *= num445; int num666 = 100; int num307 = mod.ProjectileType("ArcSoulBolt"); int data = Projectile.NewProjectile(vector32.X, vector32.Y, num443, num444, num307, num666, projectile.knockBack, projectile.owner, 0f, 0f); Main.projectile[data].melee = false; Main.projectile[data].netUpdate = true; return; } } }
/// <summary> /// The AI of the projectile /// </summary> public override void AI() { Vector2 mousePos = Main.MouseWorld; Player player = Main.player[projectile.owner]; #region Set projectile position if (projectile.owner == Main.myPlayer) // Multiplayer support { Vector2 diff = mousePos - player.Center; diff.Normalize(); projectile.position = player.Center + diff * _moveDist; projectile.timeLeft = 2; int dir = projectile.position.X > player.position.X ? 1 : -1; player.ChangeDir(dir); player.heldProj = projectile.whoAmI; player.itemTime = 2; player.itemAnimation = 2; player.itemRotation = (float)Math.Atan2(diff.Y * dir, diff.X * dir); projectile.soundDelay--; #endregion } #region Charging process // Kill the projectile if the player stops channeling if (!player.channel) { projectile.Kill(); } else { if (Main.time % 10 < 1 && !player.CheckMana(player.inventory[player.selectedItem].mana, true)) { projectile.Kill(); } Vector2 offset = mousePos - player.Center; offset.Normalize(); offset *= _moveDist - 20; Vector2 dustPos = player.Center + offset - new Vector2(10, 10); if (_charge < 50) { _charge++; } int chargeFact = _charge / 20; Vector2 dustVelocity = Vector2.UnitX * 18f; dustVelocity = dustVelocity.RotatedBy(projectile.rotation - 1.57f, default(Vector2)); Vector2 spawnPos = projectile.Center + dustVelocity; for (int k = 0; k < chargeFact + 1; k++) { Vector2 spawn = spawnPos + ((float)Main.rand.NextDouble() * 6.28f).ToRotationVector2() * (12f - (chargeFact * 2)); } } #endregion #region Set laser tail position and dusts if (_charge < 50) { return; } Vector2 start = player.Center; Vector2 unit = (player.Center - mousePos); unit.Normalize(); unit *= -1; for (_moveDist = 95f; _moveDist <= 1600; _moveDist += 5) //this 1600 is the dsitance of the beam { start = player.Center + unit * _moveDist; if (!Collision.CanHit(player.Center, 1, 1, start, 1, 1)) { _moveDist -= 5f; break; } if (projectile.soundDelay <= 0) //this is the proper sound delay for this type of weapon { Main.PlaySound(2, (int)projectile.Center.X, (int)projectile.Center.Y, 15); //this is the sound when the weapon is used cheange 15 for diferent sound projectile.soundDelay = 40; //this is the proper sound delay for this type of weapon } } _targetPos = player.Center + unit * _moveDist; //dust #endregion }
public override void Behavior() { projectile.minionSlots = 0f; projectile.rotation = projectile.velocity.X * 0.25f; trailing = false; projectile.tileCollide = false; Player player = Main.player[projectile.owner]; float num = projectile.width * 1.1f; for (int i = 0; i < 1000; i++) { Projectile current = Main.projectile[i]; if (i != projectile.whoAmI && current.active && projectile.owner == current.owner && projectile.type == current.type && Math.Abs(projectile.position.X - current.position.X) + Math.Abs(projectile.position.Y - current.position.Y) < num) { if (projectile.position.X < Main.projectile[i].position.X) { projectile.velocity.X -= 0.08f; } else { projectile.velocity.X += 0.08f; } if (projectile.position.Y < Main.projectile[i].position.Y) { projectile.velocity.Y -= 0.08f; } else { projectile.velocity.Y += 0.08f; } } } Vector2 value = projectile.position; float num21 = 500f; bool flag = false; projectile.tileCollide = false; for (int j = 0; j < 200; j++) { NPC nPC = Main.npc[j]; if (nPC.CanBeChasedBy(this, false)) { float num3 = Vector2.Distance(nPC.Center, projectile.Center); if ((num3 < num21 || !flag) && Collision.CanHitLine(projectile.position, projectile.width, projectile.height, nPC.position, nPC.width, nPC.height)) { num21 = num3; value = nPC.Center; flag = true; } } } if (Vector2.Distance(player.Center, projectile.Center) > (flag ? 1000f : 500f)) { projectile.ai[0] = 1f; projectile.netUpdate = true; } if (projectile.ai[0] == 1f) { projectile.tileCollide = false; } if (flag && projectile.ai[0] == 0f) { Vector2 value2 = value - projectile.Center; if (value2.Length() > 200f) { value2.Normalize(); projectile.velocity = (projectile.velocity * 20f + value2 * 6f) / 21f; } else { projectile.velocity *= (float)Math.Pow(0.97, 2.0); } trailing = true; projectile.tileCollide = false; projectile.rotation = (float)Math.Atan2(projectile.velocity.Y, projectile.velocity.X) + 1.57f; bool flag25 = false; int jim = 1; for (int index1 = 0; index1 < 200; index1++) { if (Main.npc[index1].CanBeChasedBy(projectile, false) && Collision.CanHit(projectile.Center, 1, 1, Main.npc[index1].Center, 1, 1)) { float num23 = Main.npc[index1].position.X + (float)(Main.npc[index1].width / 2); float num24 = Main.npc[index1].position.Y + (float)(Main.npc[index1].height / 2); float num25 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num23) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num24); if (num25 < 500f) { flag25 = true; jim = index1; } } } if (flag25) { float num1 = 68.5f; Vector2 vector2 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num2 = Main.npc[jim].Center.X - vector2.X; float num3 = Main.npc[jim].Center.Y - vector2.Y; Vector2 direction5 = Main.npc[jim].Center - projectile.Center; direction5.Normalize(); projectile.rotation = projectile.DirectionTo(Main.npc[jim].Center).ToRotation() + 1.57f; float num4 = (float)Math.Sqrt((double)num2 * (double)num2 + (double)num3 * (double)num3); float num5 = num1 / num4; float num6 = num2 * num5; float num7 = num3 * num5; int num8 = 10; if (Main.rand.Next(20) == 0) { projectile.velocity.X = (projectile.velocity.X * (float)(num8 - 1) + num6) / (float)num8; projectile.velocity.Y = (projectile.velocity.Y * (float)(num8 - 1) + num7) / (float)num8; projectile.netUpdate = true; } } } else { if (!Collision.CanHitLine(projectile.Center, 1, 1, player.Center, 1, 1)) { projectile.ai[0] = 1f; } float num4 = 6f; if (projectile.ai[0] == 1f) { num4 = 15f; } Vector2 center = projectile.Center; Vector2 vector = player.Center - center; projectile.ai[1] = 3600f; projectile.netUpdate = true; int num5 = 1; for (int k = 0; k < projectile.whoAmI; k++) { if (Main.projectile[k].active && Main.projectile[k].owner == projectile.owner && Main.projectile[k].type == projectile.type) { num5++; } } vector.X -= (10 + num5 * 40) * player.direction; vector.Y -= 70f; float num6 = vector.Length(); if (num6 > 200f && num4 < 9f) { num4 = 9f; } if (num6 < 100f && projectile.ai[0] == 1f && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) { projectile.ai[0] = 0f; projectile.netUpdate = true; } if (num6 > 2000f) { projectile.Center = player.Center; } if (num6 > 48f) { vector.Normalize(); vector *= num4; float num7 = 10f; projectile.velocity = (projectile.velocity * num7 + vector) / (num7 + 1f); } else { projectile.direction = Main.player[projectile.owner].direction; projectile.velocity *= (float)Math.Pow(0.9, 2.0); } } if (projectile.velocity.X > 0f) { projectile.spriteDirection = (projectile.direction = -1); } else if (projectile.velocity.X < 0f) { projectile.spriteDirection = (projectile.direction = 1); } if (projectile.ai[1] > 0f) { projectile.ai[1] += 1f; } if (projectile.ai[1] > 140f) { projectile.ai[1] = 0f; projectile.netUpdate = true; } }
public override void AI() { Player player = Main.player[projectile.owner]; FargoPlayer modPlayer = player.GetModPlayer <FargoPlayer>(); if (player.whoAmI == Main.myPlayer && (player.dead || !(modPlayer.ChloroEnchant || modPlayer.TerrariaSoul) || !player.GetToggleValue("Chlorophyte"))) { modPlayer.ChloroEnchant = false; projectile.Kill(); projectile.netUpdate = true; return; } projectile.netUpdate = true; float cooldown = 50f; float num395 = Main.mouseTextColor / 200f - 0.35f; num395 *= 0.2f; projectile.scale = num395 + 0.95f; if (true) { //rotation mumbo jumbo float distanceFromPlayer = 75; Lighting.AddLight(projectile.Center, 0.1f, 0.4f, 0.2f); projectile.position = player.Center + new Vector2(distanceFromPlayer, 0f).RotatedBy(projectile.ai[1]); projectile.position.X -= projectile.width / 2; projectile.position.Y -= projectile.height / 2; float rotation = 0.03f; projectile.ai[1] -= rotation; if (projectile.ai[1] > (float)Math.PI) { projectile.ai[1] -= 2f * (float)Math.PI; projectile.netUpdate = true; } projectile.rotation = projectile.ai[1] + (float)Math.PI / 2f; //wait for CD if (projectile.ai[0] != 0f) { projectile.ai[0] -= 1f; return; } //trying to shoot float num396 = projectile.position.X; float num397 = projectile.position.Y; float num398 = 700f; bool flag11 = false; for (int i = 0; i < 200; i++) { if (Main.npc[i].CanBeChasedBy(projectile, true)) { float num400 = Main.npc[i].position.X + Main.npc[i].width / 2; float num401 = Main.npc[i].position.Y + Main.npc[i].height / 2; float num402 = Math.Abs(projectile.position.X + projectile.width / 2 - num400) + Math.Abs(projectile.position.Y + projectile.height / 2 - num401); if (num402 < num398 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) { num398 = num402; num396 = num400; num397 = num401; flag11 = true; } } } //shoot if (flag11) { Vector2 vector29 = new Vector2(projectile.position.X + projectile.width * 0.5f, projectile.position.Y + projectile.height * 0.5f); float num404 = num396 - vector29.X; float num405 = num397 - vector29.Y; float num406 = (float)Math.Sqrt(num404 * num404 + num405 * num405); num406 = 10f / num406; num404 *= num406; num405 *= num406; Projectile.NewProjectile(projectile.Center.X - 4f, projectile.Center.Y, num404, num405, ProjectileID.CrystalLeafShot, projectile.damage, projectile.knockBack, projectile.owner); projectile.ai[0] = cooldown; } } if (Main.netMode == NetmodeID.Server) { projectile.netUpdate = true; } }
public override void AI() { if (!chosenColor) { colorType = Main.rand.Next(0, 2); chosenColor = true; } if (colorType == 0) { colorVer = new Color(133 + Main.rand.Next(-10, 20), 177 + Main.rand.Next(-10, 20), 255 + Main.rand.Next(0, 10)); } else if (colorType == 1) { colorVer = new Color(248 + Main.rand.Next(-13, 6), 148 + Main.rand.Next(-10, 20), 255 + Main.rand.Next(-20, 0)); } bool flag64 = projectile.type == ModContent.ProjectileType <JellyfishMinion>(); Player player = Main.player[projectile.owner]; MyPlayer modPlayer = player.GetSpiritPlayer(); if (flag64) { if (player.dead) { modPlayer.jellyfishMinion = false; } if (modPlayer.jellyfishMinion) { projectile.timeLeft = 2; } } foreach (Projectile p in Main.projectile.Where(x => x.active && x != null && x.type == projectile.type && x.owner == projectile.owner && x != projectile)) { if (p.Hitbox.Intersects(projectile.Hitbox)) { projectile.velocity += projectile.DirectionFrom(p.Center) / 5; } } float num527 = projectile.position.X; float num528 = projectile.position.Y; float num529 = 900f; bool flag19 = false; if (projectile.ai[0] == 0f) { for (int num531 = 0; num531 < 200; num531++) { if (Main.npc[num531].CanBeChasedBy(projectile, false)) { float num532 = Main.npc[num531].position.X + (float)(Main.npc[num531].width / 2); float num533 = Main.npc[num531].position.Y - 150 + (float)(Main.npc[num531].height / 2); float num534 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num532) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num533); if (num534 < num529 && Collision.CanHit(projectile.position, projectile.width, projectile.height, Main.npc[num531].position, Main.npc[num531].width, Main.npc[num531].height)) { num529 = num534; num527 = num532; num528 = num533; flag19 = true; } } } } else { projectile.tileCollide = false; } if (!flag19) { projectile.frameCounter++; if (projectile.frameCounter >= 10f) { projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; projectile.frameCounter = 0; if (projectile.frame >= 2) { projectile.frame = 0; } } projectile.friendly = true; float num535 = 8f; if (projectile.ai[0] == 1f) { num535 = 12f; } Vector2 vector38 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num536 = Main.player[projectile.owner].Center.X - vector38.X; float num537 = Main.player[projectile.owner].Center.Y - vector38.Y - 60f; float num538 = (float)Math.Sqrt((double)(num536 * num536 + num537 * num537)); if (num538 < 100f && projectile.ai[0] == 1f && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) { projectile.ai[0] = 0f; } if (num538 > 2000f) { projectile.position.X = Main.player[projectile.owner].Center.X - (projectile.width * .5f); projectile.position.Y = Main.player[projectile.owner].Center.Y - (projectile.width * .5f); } if (num538 > 70f) { num538 = num535 / num538; num536 *= num538; num537 *= num538; projectile.velocity.X = (projectile.velocity.X * 20f + num536) * (1f / 21f); projectile.velocity.Y = (projectile.velocity.Y * 20f + num537) * (1f / 21f); } else { if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) { projectile.velocity.X = -0.05f; projectile.velocity.Y = -0.025f; } projectile.velocity *= 1.005f; } projectile.friendly = false; projectile.rotation = projectile.velocity.X * 0.05f; if (Math.Abs(projectile.velocity.X) > 0.1) { projectile.spriteDirection = -projectile.direction; return; } } else { projectile.frameCounter++; if (projectile.frameCounter >= 6f) { projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; projectile.frameCounter = 0; if (projectile.frame > 5 || projectile.frame < 4) { projectile.frame = 3; } } timer++; if (timer >= Main.rand.Next(50, 90)) { int range = 100; //How many tiles away the projectile targets NPCs float shootVelocity = 6.5f; //magnitude of the shoot vector (speed of arrows shot) //TARGET NEAREST NPC WITHIN RANGE float lowestDist = float.MaxValue; for (int i = 0; i < 200; ++i) { NPC npc = Main.npc[i]; //if npc is a valid target (active, not friendly, and not a critter) if (npc.active && npc.CanBeChasedBy(projectile) && !npc.friendly) { //if npc is within 50 blocks float dist = projectile.Distance(npc.Center); if (dist / 16 < range) { //if npc is closer than closest found npc if (dist < lowestDist) { lowestDist = dist; //target this npc projectile.ai[1] = npc.whoAmI; projectile.netUpdate = true; } } } } NPC target = (Main.npc[(int)projectile.ai[1]] ?? new NPC()); Main.PlaySound(SoundID.Item, projectile.Center, 12); timer = 0; Vector2 ShootArea = new Vector2(projectile.Center.X, projectile.Center.Y - 13); Vector2 direction = target.Center - ShootArea; direction.Normalize(); direction.X *= shootVelocity; direction.Y *= shootVelocity; for (int i = 0; i < 10; i++) { int num = Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.Electric, 0f, -2f, 0, default, .5f);
public override void AI() { projectile.frameCounter++; if (projectile.frameCounter >= 4) { projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type]; projectile.frameCounter = 0; } Player player = Main.player[projectile.owner]; if (player.GetSpiritPlayer().SoulStone == true && player.active && !player.dead) { projectile.timeLeft = 2; } timer++; int range = 30; //How many tiles away the projectile targets NPCs //TARGET NEAREST NPC WITHIN RANGE float lowestDist = float.MaxValue; foreach (NPC npc in Main.npc) { //if npc is a valid target (active, not friendly, and not a critter) if (npc.active && !npc.friendly && npc.catchItem == 0) { //if npc is within 50 blocks float dist = projectile.Distance(npc.Center); if (dist / 16 < range) { //if npc is closer than closest found npc if (dist < lowestDist) { lowestDist = dist; //target this npc projectile.ai[1] = npc.whoAmI; } } } } int dust = Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 6, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); int dust2 = Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 6, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); Main.dust[dust].noGravity = true; Main.dust[dust2].noGravity = true; Main.dust[dust].velocity *= 0f; Main.dust[dust2].velocity *= 0f; Main.dust[dust2].scale = 1.2f; Main.dust[dust].scale = 1.2f; projectile.rotation = projectile.velocity.ToRotation() + (float)(Math.PI / 2); bool flag25 = false; int jim = 1; for (int index1 = 0; index1 < 200; index1++) { if (Main.npc[index1].CanBeChasedBy(projectile, false) && Collision.CanHit(projectile.Center, 1, 1, Main.npc[index1].Center, 1, 1)) { float num23 = Main.npc[index1].position.X + (float)(Main.npc[index1].width / 2); float num24 = Main.npc[index1].position.Y + (float)(Main.npc[index1].height / 2); float num25 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num23) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num24); if (num25 < 500f) { flag25 = true; jim = index1; } } } if (flag25) { float num1 = 10f; Vector2 vector2 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); float num2 = Main.npc[jim].Center.X - vector2.X; float num3 = Main.npc[jim].Center.Y - vector2.Y; float num4 = (float)Math.Sqrt((double)num2 * (double)num2 + (double)num3 * (double)num3); float num5 = num1 / num4; float num6 = num2 * num5; float num7 = num3 * num5; int num8 = 10; projectile.velocity.X = (projectile.velocity.X * (float)(num8 - 1) + num6) / (float)num8; projectile.velocity.Y = (projectile.velocity.Y * (float)(num8 - 1) + num7) / (float)num8; } else { var list = Main.projectile.Where(x => x.Hitbox.Intersects(projectile.Hitbox)); foreach (var proj in list) { if (projectile != proj && proj.hostile) { proj.Kill(); } projectile.ai[0] += .02f; projectile.Center = player.Center + offset.RotatedBy(projectile.ai[0] + projectile.ai[1] * (Math.PI * 10)); } } }