public bool ShouldHandleWeaponChangesAndContinue(Player player) { if (player.HeldItem == null) { projectile.Kill(); return(false); } if (weaponBinding == -1) { weaponBinding = player.HeldItem.type; } else { if (player.HeldItem.type != weaponBinding) { // do a buttload of decay dust for (var i = 0; i < DisperseDustQuantity; i++) { ProjectileUtil.DoChargeDust(GetChargeBallPosition(), DustType, DisperseDustFrequency, true, ChargeSize.ToVector2()); } projectile.Kill(); return(false); } } // weapon's correct, keep doing what you're doing. return(true); }
public void ProcessKillRoutine(Player player) { projectile.timeLeft = 2; MyPlayer modPlayer = player.GetModPlayer <MyPlayer>(); if (!modPlayer.IsMouseLeftHeld) { ProjectileUtil.StartKillRoutine(projectile); } if (IsDetached && FiringTime == 0) { DetachmentTimer++; TailDistance += BeamSpeed; Distance -= BeamSpeed; } if (FiringTime > 0) { FiringTime--; } if (player.dead || DetachmentTimer >= BeamFadeOutTime || (DetachmentTimer > 0 && Distance <= 0)) { projectile.Kill(); } }
private void Update() { if (!_flying) { _velocityDisplay.text = string.Format("Velocity: {0:f1}", _initialVelocity); _elevationDisplay.text = string.Format("Angle: {0:f1}", _elevation); var positions = ProjectileUtil.MakeTrajectory(_elevation, _initialVelocity, Physics.gravity.y); _trajectoryRenderer.positionCount = positions.Length; _trajectoryRenderer.SetPositions(positions); } }
public void KillBeam() { // set the cooldown CurrentFireTime = -InitialBeamCooldown; if (MyProjectile != null) { ProjectileUtil.StartKillRoutine(MyProjectile); MyProjectile = null; } }
public override bool PreAI() { // pre AI of the charge ball is responsible for telling us if the weapon has changed or the projectile should otherwise die bool isPassingPreAI = base.PreAI(); if (!isPassingPreAI && MyProjectile != null) { ProjectileUtil.StartKillRoutine(MyProjectile); } return(isPassingPreAI); }
public override bool AltFunctionUse(Player player) { player.channel = true; if (Main.netMode != NetmodeID.MultiplayerClient || Main.myPlayer == player.whoAmI) { if (!ProjectileUtil.RecapturePlayerChargeBall(player, item.shoot)) { int weaponDamage = item.damage; GetWeaponDamage(player, ref weaponDamage); var proj = Projectile.NewProjectileDirect(player.position, player.position, item.shoot, weaponDamage, item.knockBack, player.whoAmI); player.heldProj = proj.whoAmI; } } return(base.AltFunctionUse(player)); }
private void Update() { _velocityDisplay.text = string.Format("Velocity: {0:f1}", _initialVelocity); _elevationDisplay.text = string.Format("Angle: {0:f1}", _elevation); if (!_flying) { if (ProjectileUtil.CalculateElevation(ref _elevation, _initialVelocity, _target)) { var positions = ProjectileUtil.MakeTrajectoryToTarget(_elevation, _initialVelocity, _target.position, Physics.gravity.y); _trajectoryRenderer.positionCount = positions.Length; _trajectoryRenderer.SetPositions(positions); } else { _trajectoryRenderer.positionCount = 0; } } }
public override void BeginToUse(Actor actorUsing, OnUsed <Actor> onUseBegin, OnUsed <Actor> onDynamicItemUsed) { //Casting projectile here this.actorUsing = actorUsing; onUseOver = onDynamicItemUsed; actorFacingWhenFired = actorUsing.Facing; gameObjectInstanceId = actorUsing.gameObject.GetInstanceID(); ownerId = actorUsing.ownerId; GameObject gToSpawn = Resources.Load(actorUsing.projectileThrownType.ToString()) as GameObject; if (gToSpawn == null) { Debug.LogError("gToSpawn is null"); return; } liveProjectile = GridManager.InstantiateGameObject(gToSpawn).GetComponent <ProjectileUtil>(); liveProjectile.transform.position = actorUsing.actorTransform.position; finalPos = actorUsing.actorTransform.position + (liveProjectile.projectileTileTravelDistance * GridManager.instance.GetFacingDirectionOffsetVector3(actorUsing.Facing)); liveProjectile.Initialise(this); }
public override void PostAI() { projectile.netUpdate = true; player = Main.player[projectile.owner]; FinalChargeLimit = ChargeLimit + MyPlayer.ModPlayer(player).ChargeLimitAdd; if (!ChargeBall) { projectile.scale = projectile.scale + ChargeLevel; } if (BeamTrail && projectile.scale > 0 && SizeTimer > 0) { SizeTimer = 120; SizeTimer--; projectile.scale = (projectile.scale * SizeTimer / 120f); } if (ChargeBall) { if (MyPlayer.ModPlayer(player).IsKiDepleted()) { player.channel = false; } projectile.hide = true; if (projectile.timeLeft < 4) { projectile.timeLeft = 10; } projectile.position.X = player.Center.X + (player.direction * 20 + xoffset) - 5; projectile.position.Y = player.Center.Y - 3 + yoffset; projectile.netUpdate2 = true; if (!player.channel && ChargeLevel < 1) { projectile.Kill(); } // if the player is channeling, increment the timer and apply some slowdown if (player.channel && projectile.active) { ChargeTimer++; ProjectileUtil.ApplyChannelingSlowdown(player); } //ChargeTimerMax -= MyPlayer.ModPlayer(player).chargeTimerMaxAdd; if (ChargeTimer > ChargeTimerMax && ChargeLevel < FinalChargeLimit) { ChargeLevel += 1; CombatText.NewText(new Rectangle((int)player.position.X, (int)player.position.Y, player.width, player.height), new Color(51, 204, 255), ChargeLevel, false, false); ChargeTimer = 0; } if (DBZMOD.IsTickRateElapsed(2) && !MyPlayer.ModPlayer(player).IsKiDepleted()) { MyPlayer.ModPlayer(player).AddKi(-KiDrainRate, true, false); } for (int d = 0; d < 4; d++) { 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 * (10 + 2.0f * projectile.scale)), projectile.width, projectile.height, DustType, 0f, 0f, 213, default(Color), ballscale); tDust.velocity = Vector2.Normalize((projectile.position + (projectile.Size / 2)) - tDust.position) * 2; tDust.noGravity = true; } } }
public override void AI() { Player player = Main.player[projectile.owner]; if (!isInitialized) { HeldTime = 1; isInitialized = true; } // cancel channeling if the projectile is maxed if (player.channel && projectile.scale > 2.5) { player.channel = false; } if (player.channel && HeldTime > 0) { projectile.scale = BASE_SCALE + SCALE_INCREASE * HeldTime; Vector2 projectileOffset = new Vector2(-projectile.width * 0.5f, -projectile.height * 0.5f); projectileOffset += new Vector2(0, -(80 + projectile.scale * 115f)); projectile.position = player.Center + projectileOffset; HeldTime++; projectile.netUpdate = true; //Rock effect projectile.ai[1]++; if (projectile.ai[1] % 7 == 0) { Projectile.NewProjectile(projectile.Center.X + Main.rand.NextFloat(-500, 600), projectile.Center.Y + 1000, 0, -10, mod.ProjectileType("StoneBlockDestruction"), projectile.damage, 0f, projectile.owner); } Projectile.NewProjectile(projectile.Center.X + Main.rand.NextFloat(-500, 600), projectile.Center.Y + 1000, 0, -10, mod.ProjectileType("DirtBlockDestruction"), projectile.damage, 0f, projectile.owner); if (projectile.timeLeft < 399) { projectile.timeLeft = 400; } projectile.netUpdate2 = true; MyPlayer.ModPlayer(player).AddKi(-2, true, false); ProjectileUtil.ApplyChannelingSlowdown(player); // depleted check, release the ball if (MyPlayer.ModPlayer(player).IsKiDepleted()) { player.channel = false; } int soundtimer = 0; soundtimer++; if (soundtimer > 120) { SoundUtil.PlayCustomSound("Sounds/SuperNovaCharge", player, 0.6f); 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) * 6; projectile.tileCollide = false; projectile.damage *= (int)Math.Ceiling(projectile.scale * 3f); SoundUtil.PlayCustomSound("Sounds/SuperNovaThrow", player, 0.6f); } }
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; }
// The AI of the projectile public override void AI() { Player player = Main.player[projectile.owner]; ProcessKillRoutine(player); // stationary beams are instantaneously "detached", they behave weirdly. if (IsStationaryBeam && !IsDetached) { DetachmentTimer = 1; } // capture the current mouse vector, we're going to normalize movement prior to updating the charge ball location. if (projectile.owner == Main.myPlayer) { Vector2 mouseVector = Main.MouseWorld; if (OriginalMouseVector == Vector2.Zero) { OriginalMouseVector = mouseVector; } if (IsStationaryBeam && OriginalMouseVector != Vector2.Zero) { mouseVector = OriginalMouseVector; } Vector2 screenPosition = Main.screenPosition; if (OriginalScreenPosition == Vector2.Zero) { OriginalScreenPosition = screenPosition; } if (IsStationaryBeam && OriginalScreenPosition != Vector2.Zero) { screenPosition = OriginalScreenPosition; } if (OldMouseVector != Vector2.Zero && !IsStationaryBeam) { Vector2 mouseMovementVector = (mouseVector - OldMouseVector) / RotationSlowness; Vector2 screenChange = screenPosition - OldScreenPosition; mouseVector = OldMouseVector + mouseMovementVector + screenChange; } UpdateBeamTailLocationAndDirection(player, mouseVector); OldMouseVector = mouseVector; OldScreenPosition = screenPosition; } UpdateBeamPlayerItemUse(player); // handle whether the beam should be visible, and how visible. HandleBeamVisibility(); // handle the distance routine // the difference between distance and tracked distance is that distance is the actual travel. // tracked distance is with collision, and resets distance if it's too high. Distance += BeamSpeed; float TrackedDistance; for (TrackedDistance = 0f; TrackedDistance <= MaxBeamDistance; TrackedDistance += BEAM_TILE_DISTANCE_GRADIENT) { Vector2 origin = TailPositionStart() + projectile.velocity * (TrackedDistance + HeadSize.Y - StepLength()); if (!ProjectileUtil.CanHitLine(TailPositionStart(), origin)) { // changed to a while loop at a much finer gradient to smooth out beam transitions. Experimental. TrackedDistance -= BEAM_TILE_DISTANCE_GRADIENT; if (TrackedDistance <= 0) { TrackedDistance = 0; } break; } } // handle animation frames on animated beams if (IsBeamSegmentAnimated) { BeamSegmentAnimation += 8; if (BeamSegmentAnimation >= StepLength()) { BeamSegmentAnimation = 0; } } // if distance is about to be throttled, we're hitting something. Spawn some dust. if (Distance >= TrackedDistance) { var dustVector = TailPositionStart() + (TrackedDistance + HeadSize.Y - StepLength()) * projectile.velocity; ProjectileUtil.DoBeamCollisionDust(DustType, CollisionDustFrequency, projectile.velocity, dustVector); } // throttle distance by collision Distance = Math.Min(TrackedDistance, Distance); // shoot sweet sweet particles for (var i = 0; i < FireParticleDensity; i++) { ProjectileUtil.DoBeamDust(projectile.position, projectile.velocity, DustType, DustFrequency, Distance, TailHeldDistance, TailSize.ToVector2(), BeamSpeed); } // Handle the audio playing, note this positionally tracks at the head position end for effect. if (JustFired) { BeamSoundSlotId = SoundUtil.PlayCustomSound(BeamSoundKey, HeadPositionEnd()); } JustFired = false; // Update tracked audio SoundUtil.UpdateTrackedSound(BeamSoundSlotId, HeadPositionEnd()); //Add lights DelegateMethods.v3_1 = new Vector3(0.8f, 0.8f, 1f); Utils.PlotTileLine(projectile.Center, projectile.Center + projectile.velocity * (Distance - TailHeldDistance), BeamSize.Y, DelegateMethods.CastLight); }
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 override void AI() { Player player = Main.player[projectile.owner]; if (!isInitialized) { HeldTime = 1; isInitialized = true; } // cancel channeling if the projectile is maxed if (player.channel && projectile.scale > 3.0) { player.channel = false; } if (player.channel && HeldTime > 0) { projectile.scale = BASE_SCALE + SCALE_INCREASE * HeldTime; Vector2 projectileOffset = new Vector2(-projectile.width * 0.5f, -projectile.height * 0.5f); projectileOffset += new Vector2(0, -(80 + projectile.scale * 115f)); Vector2 projectileOuter = new Vector2(projectile.scale * projectile.width, projectile.scale * projectile.height) / 2f; projectile.position = player.Center + projectileOffset; HeldTime++; for (int d = 0; d < 25; d++) { float angle = Main.rand.NextFloat(360); float angleRad = MathHelper.ToRadians(angle); Vector2 dustPosition = new Vector2((float)Math.Cos(angleRad), (float)Math.Sin(angleRad)); Dust tDust = Dust.NewDustDirect(projectile.Center + (dustPosition * projectileOuter) + projectileOffset, projectile.width, projectile.height, 15, 0f, 0f, 213, default(Color), 2.0f); tDust.velocity = Vector2.Normalize((projectile.Center + projectile.Size / 2f) - tDust.position) * 2; tDust.noGravity = true; } //Rock effect projectile.ai[1]++; if (projectile.ai[1] % 7 == 0) { Projectile.NewProjectile(projectile.Center.X + Main.rand.NextFloat(-500, 600), projectile.Center.Y + 1000, 0, -10, mod.ProjectileType("StoneBlockDestruction"), projectile.damage, 0f, projectile.owner); } Projectile.NewProjectile(projectile.Center.X + Main.rand.NextFloat(-500, 600), projectile.Center.Y + 1000, 0, -10, mod.ProjectileType("DirtBlockDestruction"), projectile.damage, 0f, projectile.owner); projectile.netUpdate = true; if (projectile.timeLeft < 399) { projectile.timeLeft = 400; } MyPlayer.ModPlayer(player).AddKi(-2, true, false); ProjectileUtil.ApplyChannelingSlowdown(player); projectile.netUpdate2 = true; // depleted check, release the ball if (MyPlayer.ModPlayer(player).IsKiDepleted()) { player.channel = false; } } else if (HeldTime > 0) { HeldTime = 0; projectile.timeLeft = (int)Math.Ceiling(projectile.scale * 15) + 600; projectile.velocity = Vector2.Normalize(Main.MouseWorld - player.Center) * 6; projectile.tileCollide = false; projectile.damage *= (int)Math.Ceiling(projectile.scale * 4f); } }