/// <summary> /// we are using the precondition that only 1 scrapshot hook can exist for a player in order to find and assign the hook in multiplayer /// </summary> /// <returns></returns> private void findHook(Player player) { for (int i = 0; i < Main.maxProjectiles; i++) { Projectile proj = Main.projectile[i]; if (proj.active && proj.owner == player.whoAmI && proj.type == ModContent.ProjectileType <ScrapshotHook>()) { hook = (proj.modProjectile as ScrapshotHook); return; } } }
public override bool UseItem(Player player) { //even though this is a "gun" we are using useitem so that it runs on all clients. need to deconstruct the useammo and damage modifiers ourselves here int damage = 0; float speed = item.shootSpeed; float speedX = 0; float speedY = 0; float knockback = 0; if (Main.myPlayer == player.whoAmI) { damage = (int)(item.damage * player.rangedDamage); float rotation = (player.Center - Main.MouseWorld).ToRotation() - 1.57f; speedX = speed * (float)Math.Sin(rotation); speedY = speed * -(float)Math.Cos(rotation); knockback = item.knockBack; } if (player.altFunctionUse == 2) { if (Main.myPlayer == player.whoAmI) { int i = Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ModContent.ProjectileType <ScrapshotHook>(), item.damage, item.knockBack, player.whoAmI); hook = Main.projectile[i].modProjectile as ScrapshotHook; } Helper.PlayPitched("Guns/ChainShoot", 0.5f, 0, player.Center); } else { float spread = 0.5f; int type = ProjectileID.Bullet; Item sample = new Item(); sample.SetDefaults(type); sample.useAmmo = AmmoID.Bullet; bool shoot = true; player.PickAmmo(sample, ref type, ref speed, ref shoot, ref damage, ref knockback, !ConsumeAmmo(player)); shoot = player.HasAmmo(sample, shoot); if (!shoot) { return(false); } if (type == ProjectileID.Bullet) { type = ModContent.ProjectileType <ScrapshotShrapnel>(); } if (Main.myPlayer == player.whoAmI) { Main.LocalPlayer.GetModPlayer <StarlightPlayer>().Shake += 8; } if (hook != null && hook.projectile.type == ModContent.ProjectileType <ScrapshotHook>() && hook.projectile.active && hook.isHooked) { hook.struck = true; NPC hooked = Main.npc[hook.hookedNpcIndex]; hook.projectile.timeLeft = 20; player.velocity = Vector2.Normalize(hook.startPos - hooked.Center) * 12; Helper.PlayPitched("ChainHit", 0.5f, 0, player.Center); for (int k = 0; k < 20; k++) { var direction = Vector2.One.RotatedByRandom(6.28f); Dust.NewDustPerfect(player.Center + direction * 10, ModContent.DustType <Dusts.Glow>(), direction * Main.rand.NextFloat(2, 4), 0, new Color(150, 80, 40), Main.rand.NextFloat(0.2f, 0.5f)); } if (Main.myPlayer == player.whoAmI) { spread = 0.05f; damage += 4; player.GetModPlayer <StarlightPlayer>().Shake += 12; } } float rot = new Vector2(speedX, speedY).ToRotation(); if (Main.myPlayer != player.whoAmI) { hook = null; } for (int k = 0; k < 6; k++) { Vector2 offset = Vector2.UnitX.RotatedBy(rot); var direction = offset.RotatedByRandom(spread); if (Main.myPlayer == player.whoAmI) { int i = Projectile.NewProjectile(player.Center + (offset * 25), direction * item.shootSpeed, type, damage, item.knockBack, player.whoAmI); if (type != ModContent.ProjectileType <ScrapshotShrapnel>()) { Main.projectile[i].timeLeft = 30; } //don't know direction for other players so we only add these for self. Dust.NewDustPerfect(player.Center + direction * 60, ModContent.DustType <Dusts.Glow>(), direction * Main.rand.NextFloat(20), 0, new Color(150, 80, 40), Main.rand.NextFloat(0.2f, 0.5f)); Dust.NewDustPerfect(player.Center + direction * 60, ModContent.DustType <Dusts.Smoke>(), Vector2.UnitY * -2 + direction * 5, 0, new Color(60, 55, 50) * 0.5f, Main.rand.NextFloat(0.5f, 1)); } } Helper.PlayPitched("Guns/Scrapshot", 0.4f, 0, player.Center); } return(true); }