Condemnation as a base holdout.
This commit is contained in:
1 parent
061b636a1c
commit
24e78d29b9
2 files changed
+71
-103
No files matched your search
@@ -44,10 +44,15 @@ namespace CalamityMod.Items.Weapons.Ranged
|
||||
|
||||
public override void HoldItem(Player player)
|
||||
{
|
||||
if (Main.myPlayer == player.whoAmI)
|
||||
player.Calamity().rightClickListener = true;
|
||||
var calPlayer = player.Calamity();
|
||||
|
||||
if (player.Calamity().mouseRight && player.ownedProjectileCounts[ModContent.ProjectileType<CondemnationHoldout>()] <= 0)
|
||||
if (Main.myPlayer == player.whoAmI)
|
||||
{
|
||||
calPlayer.rightClickListener = true;
|
||||
calPlayer.mouseRotationListener = true;
|
||||
}
|
||||
|
||||
if (calPlayer.mouseRight && player.ownedProjectileCounts[ModContent.ProjectileType<CondemnationHoldout>()] <= 0)
|
||||
{
|
||||
Item.noUseGraphic = false;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
using CalamityMod.Items.Weapons.Ranged;
|
||||
using CalamityMod.Sounds;
|
||||
using System.IO;
|
||||
using CalamityMod.Items.Weapons.Ranged;
|
||||
using CalamityMod.Projectiles.BaseProjectiles;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.Audio;
|
||||
using Terraria.ID;
|
||||
using Terraria.Localization;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Projectiles.Ranged
|
||||
{
|
||||
public class CondemnationHoldout : ModProjectile
|
||||
public class CondemnationHoldout : BaseGunHoldoutProjectile
|
||||
{
|
||||
public override LocalizedText DisplayName => CalamityUtils.GetItemName<Condemnation>();
|
||||
private Player Owner => Main.player[Projectile.owner];
|
||||
public override int AssociatedItemID => ModContent.ItemType<Condemnation>();
|
||||
public override float MaxOffsetLengthFromArm => 25f;
|
||||
public override float OffsetXUpwards => -5f;
|
||||
public override float BaseOffsetY => -5f;
|
||||
|
||||
private ref float CurrentChargingFrames => ref Projectile.ai[0];
|
||||
private ref float ArrowsLoaded => ref Projectile.ai[1];
|
||||
@@ -22,24 +24,8 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
public const float velocityMultiplier = 1.2f;
|
||||
public bool homing = false;
|
||||
|
||||
public override string Texture => "CalamityMod/Items/Weapons/Ranged/Condemnation";
|
||||
|
||||
public override void SetDefaults()
|
||||
public override void KillHoldoutLogic()
|
||||
{
|
||||
Projectile.width = 130;
|
||||
Projectile.height = 42;
|
||||
Projectile.friendly = true;
|
||||
Projectile.penetrate = -1;
|
||||
Projectile.tileCollide = false;
|
||||
Projectile.DamageType = DamageClass.Ranged;
|
||||
Projectile.ignoreWater = true;
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true);
|
||||
Vector2 tipPosition = armPosition + Projectile.velocity * Projectile.width * 0.5f;
|
||||
|
||||
// Fire arrows if the owner stops channeling or otherwise cannot use the weapon.
|
||||
if (Owner.CantUseHoldout())
|
||||
{
|
||||
@@ -51,65 +37,61 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
}
|
||||
|
||||
// Fire one charged arrow every frame until you're out of arrows.
|
||||
ShootProjectiles(tipPosition, homing);
|
||||
ShootProjectiles(homing);
|
||||
--ArrowsLoaded;
|
||||
if (ArrowsLoaded == 0 && homing == true)
|
||||
homing = false;
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
public override void HoldoutAI()
|
||||
{
|
||||
// Frame 1 effects: Record how fast the Condemnation item being used is, to determine how fast to load arrows.
|
||||
if (FramesToLoadNextArrow == 0f)
|
||||
{
|
||||
SoundEngine.PlaySound(SoundID.Item20, Projectile.Center);
|
||||
FramesToLoadNextArrow = HeldItem.useAnimation;
|
||||
}
|
||||
|
||||
// Frame 1 effects: Record how fast the Condemnation item being used is, to determine how fast to load arrows.
|
||||
if (FramesToLoadNextArrow == 0f)
|
||||
// If no arrows are loaded, spawn a bit of dust to indicate it's not ready yet.
|
||||
// Spawn the same dust if the max number of arrows have been loaded or the player ran out of ammos to load.
|
||||
if (ArrowsLoaded <= 0f || ArrowsLoaded >= Condemnation.MaxLoadedArrows || !Owner.HasAmmo(Owner.ActiveItem()))
|
||||
SpawnCannotLoadArrowsDust(GunTipPosition);
|
||||
|
||||
if (Owner.HasAmmo(HeldItem))
|
||||
{
|
||||
// Actually make progress towards loading more arrows.
|
||||
++CurrentChargingFrames;
|
||||
|
||||
// If it is time to load an arrow, produce a pulse of dust and add an arrow.
|
||||
// Also accelerate charging, because it's fucking awesome.
|
||||
// Take the ammo here as well
|
||||
if (CurrentChargingFrames >= FramesToLoadNextArrow && ArrowsLoaded < Condemnation.MaxLoadedArrows)
|
||||
{
|
||||
SoundEngine.PlaySound(SoundID.Item20, Projectile.Center);
|
||||
FramesToLoadNextArrow = Owner.ActiveItem().useAnimation;
|
||||
}
|
||||
// Save the stats here for later
|
||||
Owner.PickAmmo(HeldItem, out _, out float shootSpeed, out int damage, out float knockback, out _);
|
||||
Projectile.damage = damage;
|
||||
Projectile.knockBack = knockback;
|
||||
storedVelocity = shootSpeed * velocityMultiplier;
|
||||
|
||||
// If no arrows are loaded, spawn a bit of dust to indicate it's not ready yet.
|
||||
// Spawn the same dust if the max number of arrows have been loaded or the player ran out of ammos to load.
|
||||
if (ArrowsLoaded <= 0f || ArrowsLoaded >= Condemnation.MaxLoadedArrows || !Owner.HasAmmo(Owner.ActiveItem()))
|
||||
SpawnCannotLoadArrowsDust(tipPosition);
|
||||
SpawnArrowLoadedDust();
|
||||
CurrentChargingFrames = 0f;
|
||||
++ArrowsLoaded;
|
||||
--FramesToLoadNextArrow;
|
||||
|
||||
if (Owner.HasAmmo(Owner.ActiveItem()))
|
||||
{
|
||||
// Actually make progress towards loading more arrows.
|
||||
++CurrentChargingFrames;
|
||||
// Play a sound for additional notification that an arrow has been loaded.
|
||||
var loadSound = SoundEngine.PlaySound(SoundID.Item108 with { Volume = SoundID.Item108.Volume * 0.3f });
|
||||
|
||||
// If it is time to load an arrow, produce a pulse of dust and add an arrow.
|
||||
// Also accelerate charging, because it's fucking awesome.
|
||||
// Take the ammo here as well
|
||||
if (CurrentChargingFrames >= FramesToLoadNextArrow && ArrowsLoaded < Condemnation.MaxLoadedArrows)
|
||||
if (ArrowsLoaded >= Condemnation.MaxLoadedArrows)
|
||||
{
|
||||
// Save the stats here for later
|
||||
Item heldItem = Owner.ActiveItem();
|
||||
Owner.PickAmmo(heldItem, out _, out float shootSpeed, out int damage, out float knockback, out _);
|
||||
Projectile.damage = damage;
|
||||
Projectile.knockBack = knockback;
|
||||
storedVelocity = shootSpeed * velocityMultiplier;
|
||||
|
||||
SpawnArrowLoadedDust(tipPosition);
|
||||
CurrentChargingFrames = 0f;
|
||||
++ArrowsLoaded;
|
||||
--FramesToLoadNextArrow;
|
||||
|
||||
// Play a sound for additional notification that an arrow has been loaded.
|
||||
var loadSound = SoundEngine.PlaySound(SoundID.Item108 with { Volume = SoundID.Item108.Volume * 0.3f });
|
||||
|
||||
if (ArrowsLoaded >= Condemnation.MaxLoadedArrows)
|
||||
{
|
||||
SoundEngine.PlaySound(new("CalamityMod/Sounds/Custom/AbilitySounds/BrimflameRecharge"));
|
||||
homing = true;
|
||||
}
|
||||
SoundEngine.PlaySound(new("CalamityMod/Sounds/Custom/AbilitySounds/BrimflameRecharge"));
|
||||
homing = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UpdateProjectileHeldVariables(armPosition);
|
||||
ManipulatePlayerVariables();
|
||||
}
|
||||
|
||||
public void SpawnArrowLoadedDust(Vector2 tipPosition)
|
||||
public void SpawnArrowLoadedDust()
|
||||
{
|
||||
if (Main.dedServ)
|
||||
return;
|
||||
@@ -126,7 +108,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
Vector2 end = nextAngle.ToRotationVector2();
|
||||
for (int j = 0; j < 40; j++)
|
||||
{
|
||||
Dust starDust = Dust.NewDustPerfect(tipPosition, 267);
|
||||
Dust starDust = Dust.NewDustPerfect(GunTipPosition, 267);
|
||||
starDust.scale = 2.5f;
|
||||
starDust.velocity = Vector2.Lerp(start, end, j / 40f) * 16f;
|
||||
starDust.color = Color.Crimson;
|
||||
@@ -138,7 +120,7 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
|
||||
for (int i = 0; i < 36; i++)
|
||||
{
|
||||
Dust chargeMagic = Dust.NewDustPerfect(tipPosition, 267);
|
||||
Dust chargeMagic = Dust.NewDustPerfect(GunTipPosition, 267);
|
||||
chargeMagic.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 5f + Owner.velocity;
|
||||
chargeMagic.scale = Main.rand.NextFloat(1f, 1.5f);
|
||||
chargeMagic.color = Color.Violet;
|
||||
@@ -146,62 +128,43 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnCannotLoadArrowsDust(Vector2 tipPosition)
|
||||
public void SpawnCannotLoadArrowsDust(Vector2 GunTipPosition)
|
||||
{
|
||||
if (Main.dedServ)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Dust chargeMagic = Dust.NewDustPerfect(tipPosition + Main.rand.NextVector2Circular(20f, 20f), 267);
|
||||
chargeMagic.velocity = (tipPosition - chargeMagic.position) * 0.1f + Owner.velocity;
|
||||
Dust chargeMagic = Dust.NewDustPerfect(GunTipPosition + Main.rand.NextVector2Circular(20f, 20f), 267);
|
||||
chargeMagic.velocity = (GunTipPosition - chargeMagic.position) * 0.1f + Owner.velocity;
|
||||
chargeMagic.scale = Main.rand.NextFloat(1f, 1.5f);
|
||||
chargeMagic.color = Projectile.GetAlpha(Color.White);
|
||||
chargeMagic.noGravity = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShootProjectiles(Vector2 tipPosition, bool homing)
|
||||
public void ShootProjectiles(bool homing)
|
||||
{
|
||||
if (Main.myPlayer != Projectile.owner)
|
||||
return;
|
||||
|
||||
Vector2 shootVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * storedVelocity;
|
||||
int ArrowType = homing ? ModContent.ProjectileType<CondemnationArrowHoming>() : ModContent.ProjectileType<CondemnationArrow>();
|
||||
Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, shootVelocity, ArrowType, Projectile.damage, Projectile.knockBack, Projectile.owner);
|
||||
Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, shootVelocity, ArrowType, Projectile.damage, Projectile.knockBack, Projectile.owner);
|
||||
}
|
||||
|
||||
private void UpdateProjectileHeldVariables(Vector2 armPosition)
|
||||
public override void SendExtraAIHoldout(BinaryWriter writer)
|
||||
{
|
||||
if (Main.myPlayer == Projectile.owner)
|
||||
{
|
||||
float interpolant = Utils.GetLerpValue(5f, 25f, Projectile.Distance(Main.MouseWorld), true);
|
||||
Vector2 oldVelocity = Projectile.velocity;
|
||||
Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant);
|
||||
if (Projectile.velocity != oldVelocity)
|
||||
{
|
||||
Projectile.netSpam = 0;
|
||||
Projectile.netUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
Projectile.position = armPosition - Projectile.Size * 0.5f;
|
||||
Projectile.rotation = Projectile.velocity.ToRotation();
|
||||
if (Projectile.spriteDirection == -1)
|
||||
Projectile.rotation += MathHelper.Pi;
|
||||
Projectile.spriteDirection = Projectile.direction;
|
||||
Projectile.timeLeft = 2;
|
||||
writer.Write(FramesToLoadNextArrow);
|
||||
writer.Write(storedVelocity);
|
||||
writer.Write(homing);
|
||||
}
|
||||
|
||||
private void ManipulatePlayerVariables()
|
||||
public override void ReceiveExtraAIHoldout(BinaryReader reader)
|
||||
{
|
||||
Owner.ChangeDir(Projectile.direction);
|
||||
Owner.heldProj = Projectile.whoAmI;
|
||||
Owner.itemTime = 2;
|
||||
Owner.itemAnimation = 2;
|
||||
Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation();
|
||||
FramesToLoadNextArrow = reader.ReadSingle();
|
||||
storedVelocity = reader.ReadSingle();
|
||||
homing = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override bool? CanDamage() => false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user