public void HandleFiring(Player player, Vector2 mouseVector) { MyPlayer modPlayer = player.GetModPlayer <MyPlayer>(); // minimum charge level is required to fire in the first place, but once you fire, you can keep firing. if (ShouldFireBeam(modPlayer)) { // kill the charge sound if we're firing ChargeSoundSlotId = SoundUtil.KillTrackedSound(ChargeSoundSlotId); if (!WasSustainingFire && MyProjectile == null) { if (Main.netMode != NetmodeID.MultiplayerClient || Main.myPlayer == player.whoAmI) { // fire the laser! MyProjectile = Projectile.NewProjectileDirect(projectile.position + BeamCreationOffset, projectile.velocity, mod.ProjectileType(BeamProjectileName), GetBeamDamage(), projectile.knockBack, projectile.owner); // set firing time minimum for beams that auto-detach and are stationary, this prevents their self kill routine MyProjectile.ai[1] = MinimumFireFrames; } } // increment the fire time, this handles "IsSustainingFire" as well as stating the beam is no longer firable (it is already being fired) CurrentFireTime++; // if the player has charge left, drain the ball if (ChargeLevel >= FireDecayRate()) { ChargeLevel = Math.Max(0f, ChargeLevel - FireDecayRate()); } else if (!modPlayer.IsKiDepleted()) { if (DBZMOD.IsTickRateElapsed(FIRE_KI_DRAIN_WINDOW)) { modPlayer.AddKi(-FireKiDrainRate(), true, false); } } else { // beam is no longer sustainable KillBeam(); } } else { // player has stopped firing or something else has stopped them KillBeam(); } WasSustainingFire = IsSustainingFire; }
public static bool IsTimeElapsed(int frames) { return(DBZMOD.IsTickRateElapsed(frames)); }
public override void AI() { Player player = Main.player[projectile.owner]; MyPlayer modPlayer = player.GetModPlayer <MyPlayer>(); if (!_isInitialized) { modPlayer.isMassiveBlastCharging = true; //modPlayer.isMassiveBlastInUse = true; HeldTime = 1; _isInitialized = true; } if (player.channel && modPlayer.isMassiveBlastCharging) { projectile.scale = BASE_SCALE + SCALE_INCREASE * (HeldTime / 3f); projectile.position = player.Center + new Vector2(0, -40 - (projectile.scale * 17)); HeldTime++; // reduced from 25. for (int d = 0; d < 15; d++) { // loop hitch for variance. if (Main.rand.NextFloat() < 0.3f) { continue; } float angle = Main.rand.NextFloat(360); float angleRad = MathHelper.ToRadians(angle); Vector2 position = new Vector2((float)Math.Cos(angleRad), (float)Math.Sin(angleRad)); Dust tDust = Dust.NewDustDirect(projectile.position + (position * (20 + 12.5f * projectile.scale)), projectile.width, projectile.height, 230, 0f, 0f, 213, default(Color), 2.0f); tDust.velocity = Vector2.Normalize((projectile.position + (projectile.Size / 2)) - tDust.position) * 2; tDust.noGravity = true; } //Rock effect if (DBZMOD.IsTickRateElapsed(10) && _rocksFloating < MAX_ROCKS) { // only some of the time, keeps it a little more varied. if (Main.rand.NextFloat() < 0.6f) { _rocksFloating++; BaseFloatingDestructionProj.SpawnNewFloatingRock(player, projectile); } } if (projectile.timeLeft < 399) { projectile.timeLeft = 400; } MyPlayer.ModPlayer(player).AddKi(-5, true, false); player.ApplyChannelingSlowdown(); // depleted check, release the ball if (MyPlayer.ModPlayer(player).IsKiDepleted()) { player.channel = false; } if (_soundtimer == 0) { _soundInfo = SoundHelper.PlayCustomSound("Sounds/SpiritBombCharge", player, 0.5f); } _soundtimer++; if (_soundtimer > 120) { _soundtimer = 0; } } else if (modPlayer.isMassiveBlastCharging) { modPlayer.isMassiveBlastCharging = false; float projectileWidthFactor = projectile.width * projectile.scale / TRAVEL_SPEED_COEFFICIENT; projectile.timeLeft = (int)Math.Ceiling(projectileWidthFactor) + 180; projectile.velocity = Vector2.Normalize(Main.MouseWorld - player.Center) * TRAVEL_SPEED_COEFFICIENT; projectile.tileCollide = false; projectile.damage *= (int)projectile.scale / 2; _soundInfo = SoundHelper.KillTrackedSound(_soundInfo); SoundHelper.PlayCustomSound("Sounds/SpiritBombFire", player); } projectile.netUpdate = true; projectile.netUpdate2 = true; }
public void HandleChargingKi(Player player) { bool IsCharging = false; FinalChargeLimit = ChargeLimit + MyPlayer.ModPlayer(player).ChargeLimitAdd; // stop channeling if the player is out of ki if (MyPlayer.ModPlayer(player).IsKiDepleted()) { player.channel = false; } // keep alive routine. if (projectile.timeLeft < 4) { projectile.timeLeft = 10; } MyPlayer modPlayer = MyPlayer.ModPlayer(player); // The energy in the projectile decays if the player stops channeling. if (!player.channel && !modPlayer.IsMouseRightHeld && !IsSustainingFire) { // kill the tracked charge sound if the player let go, immediately ChargeSoundSlotId = SoundUtil.KillTrackedSound(ChargeSoundSlotId); if (ChargeLevel > 0f) { ChargeLevel = Math.Max(0, ChargeLevel - DecayRate()); // don't draw the ball when firing. if (!IsSustainingFire) { ProjectileUtil.DoChargeDust(GetChargeBallPosition(), DustType, DecayDustFrequency, true, ChargeSize.ToVector2()); } } else { // the charge level zeroed out, kill the projectile. projectile.Kill(); } } // charge the ball if the proper keys are held. // increment the charge timer if channeling and apply slowdown effect if (player.channel && projectile.active && modPlayer.IsMouseRightHeld && !IsSustainingFire) { // the player can hold the charge all they like once it's fully charged up. Currently this doesn't incur a movespeed debuff either. if (ChargeLevel < FinalChargeLimit && !modPlayer.IsKiDepleted()) { IsCharging = true; // drain ki from the player when charging if (DBZMOD.IsTickRateElapsed(CHARGE_KI_DRAIN_WINDOW)) { MyPlayer.ModPlayer(player).AddKi(-ChargeKiDrainRate(), true, false); } // increase the charge ChargeLevel = Math.Min(FinalChargeLimit, ChargeRate() + ChargeLevel); // slow down the player while charging. ProjectileUtil.ApplyChannelingSlowdown(player); // shoot some dust into the ball to show it's charging, and to look cool. if (!IsSustainingFire) { ProjectileUtil.DoChargeDust(GetChargeBallPosition(), DustType, ChargeDustFrequency, false, ChargeSize.ToVector2()); } } } // play the sound if the player just started charging and the audio is "off cooldown" if (!WasCharging && IsCharging && ChargeSoundCooldown == 0f) { if (!Main.dedServ) { ChargeSoundSlotId = SoundUtil.PlayCustomSound(ChargeSoundKey, projectile.Center); } ChargeSoundCooldown = ChargeSoundDelay; } else { ChargeSoundCooldown = Math.Max(0f, ChargeSoundCooldown - 1); } // set the wasCharging flag for proper tracking WasCharging = IsCharging; }
public override void AI() { Player player = Main.player[projectile.owner]; if (!isInitialized) { HeldTime = 1; isInitialized = true; } if (player.channel && HeldTime > 0) { projectile.scale = BASE_SCALE + SCALE_INCREASE * HeldTime; projectile.position = player.Center + new Vector2(0, -40 - (projectile.scale * 17)); HeldTime++; // reduced from 25. for (int d = 0; d < 15; d++) { // loop hitch for variance. if (Main.rand.NextFloat() < 0.3f) { continue; } float angle = Main.rand.NextFloat(360); float angleRad = MathHelper.ToRadians(angle); Vector2 position = new Vector2((float)Math.Cos(angleRad), (float)Math.Sin(angleRad)); Dust tDust = Dust.NewDustDirect(projectile.position + (position * (20 + 12.5f * projectile.scale)), projectile.width, projectile.height, 230, 0f, 0f, 213, default(Color), 2.0f); tDust.velocity = Vector2.Normalize((projectile.position + (projectile.Size / 2)) - tDust.position) * 2; tDust.noGravity = true; } //Rock effect if (DBZMOD.IsTickRateElapsed(10) && rocksFloating < MAX_ROCKS) { // only some of the time, keeps it a little more varied. if (Main.rand.NextFloat() < 0.6f) { rocksFloating++; BaseFloatingDestructionProj.SpawnNewFloatingRock(player, projectile); } } projectile.netUpdate = true; if (projectile.timeLeft < 399) { projectile.timeLeft = 400; } MyPlayer.ModPlayer(player).AddKi(-5, true, false); ProjectileUtil.ApplyChannelingSlowdown(player); projectile.netUpdate2 = true; // depleted check, release the ball if (MyPlayer.ModPlayer(player).IsKiDepleted()) { player.channel = false; } int soundtimer = 0; soundtimer++; if (soundtimer > 120) { SoundUtil.PlayCustomSound("Sounds/SpiritBombCharge", player, 0.5f); soundtimer = 0; } } else if (HeldTime > 0) { HeldTime = 0; projectile.timeLeft = (int)Math.Ceiling(projectile.scale * 15) + 600; projectile.velocity = Vector2.Normalize(Main.MouseWorld - player.Center) * 2.8f; projectile.tileCollide = false; projectile.damage *= (int)projectile.scale / 2; SoundUtil.PlayCustomSound("Sounds/SpiritBombFire", player); } }
public void HandleChargingKi(Player player) { bool isCharging = false; finalChargeLimit = chargeLimit + MyPlayer.ModPlayer(player).chargeLimitAdd; // stop channeling if the player is out of ki if (MyPlayer.ModPlayer(player).IsKiDepleted()) { player.channel = false; } // keep alive routine. if (projectile.timeLeft < 4) { projectile.timeLeft = 10; } MyPlayer modPlayer = MyPlayer.ModPlayer(player); // charge the ball if the proper keys are held. // increment the charge timer if channeling and apply slowdown effect if (modPlayer.isMouseLeftHeld && !IsFired) { // shoot some dust into the ball to show it's charging, and to look cool. // Also generates light. if (!IsFired) { ProjectileHelper.DoChargeDust(GetChargeBallPosition(), dustType, chargeDustFrequency, false, chargeSize.ToVector2()); } // the player can hold the charge all they like once it's fully charged up. Currently this doesn't incur a movespeed debuff either. if (ChargeLevel < finalChargeLimit && modPlayer.HasKi(ChargeKiDrainRate())) { isCharging = true; // drain ki from the player when charging if (DBZMOD.IsTickRateElapsed(CHARGE_KI_DRAIN_WINDOW)) { MyPlayer.ModPlayer(player).AddKi(-ChargeKiDrainRate(), true, false); } // increase the charge ChargeLevel = Math.Min(finalChargeLimit, ChargeRate() + ChargeLevel); // slow down the player while charging. player.ApplyChannelingSlowdown(); } else { if (ChargeLevel == 0f) { projectile.Kill(); } } } // play the sound if the player just started charging and the audio is "off cooldown" if (!_wasCharging && isCharging && ChargeSoundCooldown == 0f) { if (!Main.dedServ) { chargeSoundSlotId = SoundHelper.PlayCustomSound(chargeSoundKey, projectile.Center, chargeSoundVolume); } ChargeSoundCooldown = chargeSoundDelay; } else { ChargeSoundCooldown = Math.Max(0f, ChargeSoundCooldown - 1); } // set the wasCharging flag for proper tracking _wasCharging = isCharging; }