public override void UpdateEffects(Player player) { MyPlayer modPlayer = player.GetSpiritPlayer(); modPlayer.copterBrake = false; float tilt = player.fullRotation; if (player.wet || player.honeyWet || player.lavaWet) { player.mount.Dismount(player); return; } //Only keep flying, when the player is holding up if (player.controlUp || player.controlJump) { player.mount._abilityCharging = true; player.mount._flyTime = 0; player.mount._fatigue = -verticalSpeed; } else { player.mount._abilityCharging = false; } //Slow down the helicopter, if it's on the ground if (modPlayer.onGround) { if (player.controlUp || player.controlJump) { player.position.Y -= mountData.acceleration; } else { modPlayer.copterBrake = true; } } //tilt the helicopter tilt = player.velocity.X * (MathHelper.PiOver2 * 0.125f); tilt = (float)Math.Sin(tilt) * maxTilt; player.fullRotation = tilt; player.fullRotationOrigin = new Vector2(10f, 14f); //If you change this, also change the x and y values below. //Scan for enemies and fire at them if (player.mount._abilityCooldown == 0) { //Don't change these values, unless you want to adjust the nozzle position. float x = 20f * player.direction; float y = 12f; float sin = (float)Math.Sin(tilt); float cos = (float)Math.Cos(tilt); Vector2 muzzle = new Vector2(x * cos - y * sin, x * sin + y * cos); muzzle = muzzle + player.fullRotationOrigin + player.position; //Readjust the scanning cone to the current position. float direction; if (player.direction == 1) { direction = FOVHelper.POS_X_DIR + tilt; } else { direction = FOVHelper.NEG_X_DIR - tilt; } helper.AdjustCone(muzzle, fov, direction); //Look for the nearest, unobscured enemy inside the cone NPC nearest = null; float distNearest = rangeSquare; for (int i = 0; i < 200; i++) { NPC npc = Main.npc[i]; Vector2 npcCenter = npc.Center; if (npc.CanBeChasedBy() && helper.IsInCone(npcCenter)) //first param of canBeChasedBy has no effect { float distCurrent = Vector2.DistanceSquared(muzzle, npcCenter); if (distCurrent < distNearest && Collision.CanHitLine(muzzle, 0, 0, npc.position, npc.width, npc.height)) { nearest = npc; distNearest = distCurrent; } } } //Shoot 'em dead if (nearest != null) { if (player.whoAmI == Main.myPlayer) { Vector2 aim = nearest.Center - muzzle; aim.Normalize(); aim *= velocity; float vX = aim.X; float vY = aim.Y; //This precisely mimics the Gatligators spread //Random rand = Main.rand; commenting this out because I changed the rand lines here and waiting on more experienced help- Jenosis vX += Main.rand.Next(-50, 51) * 0.03f; vY += Main.rand.Next(-50, 51) * 0.03f; vX += Main.rand.Next(-40, 41) * 0.05f; vY += Main.rand.Next(-40, 41) * 0.05f; if (Main.rand.Next(3) == 0) { vX += Main.rand.Next(-30, 31) * 0.02f; vY += Main.rand.Next(-30, 31) * 0.02f; } Terraria.Projectile.NewProjectile(muzzle.X, muzzle.Y, vX, vY, ModContent.ProjectileType <CandyCopterBullet>(), (int)(damage * player.minionDamage), knockback * player.minionKB, player.whoAmI); //CandyCopterBullet } Point point = player.Center.ToTileCoordinates(); Lighting.AddLight(point.X, point.Y, lightColor.X, lightColor.Y, lightColor.Z); modPlayer.copterFiring = true; modPlayer.copterFireFrame = 0; player.mount._abilityCooldown = cooldown - 1; } else { modPlayer.copterFiring = false; } return; } else if (player.mount._abilityCooldown > cooldown) { player.mount._abilityCooldown = cooldown; } }
public override void AI() { if (++animationCounter >= 5) { animationCounter = 0; if (++frame >= Main.projFrames[projectile.type]) { frame = 0; } } projectile.frameCounter = 0; projectile.frame = frame; var owner = Main.player[projectile.owner]; if (owner.active && owner.HasBuff(ModContent.BuffType <HarpyPetBuff>())) { projectile.timeLeft = 2; } if (projectile.owner != Main.myPlayer) { return; } if (Timer > 0) { --Timer; return; } float direction; if (projectile.direction < 0) { direction = FOVHelper.POS_X_DIR + projectile.rotation; } else { direction = FOVHelper.NEG_X_DIR - projectile.rotation; } var origin = projectile.Center; var fov = new FOVHelper(); fov.AdjustCone(origin, FOV, direction); float maxDistSquared = Max_Range * Max_Range; for (int i = 0; i < Main.maxNPCs; ++i) { NPC npc = Main.npc[i]; Vector2 npcPos = npc.Center; if (npc.CanBeChasedBy() && fov.IsInCone(npcPos) && Vector2.DistanceSquared(origin, npcPos) < maxDistSquared && Collision.CanHitLine(origin, 0, 0, npc.position, npc.width, npc.height)) { if (Main.rand.NextBool(10)) { ShootFeathersAt(npcPos); } Timer = 140; break; } } }