Enchanted Blade Staff start.
This commit is contained in:
1 parent
f8edb48b77
commit
aa65b6d170
12 files changed
+385
No files matched your search
@@ -0,0 +1,34 @@
|
||||
using CalamityMod.CalPlayer;
|
||||
using CalamityMod.Projectiles.Summon;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Buffs.Summon
|
||||
{
|
||||
public class EnchantedBladeStaffBuff : ModBuff
|
||||
{
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
Main.buffNoTimeDisplay[Type] = true;
|
||||
Main.buffNoSave[Type] = true;
|
||||
}
|
||||
|
||||
public override void Update(Player player, ref int buffIndex)
|
||||
{
|
||||
CalamityPlayer modPlayer = player.Calamity();
|
||||
if (player.ownedProjectileCounts[ModContent.ProjectileType<EnchantedBladeSummon>()] > 0)
|
||||
{
|
||||
modPlayer.EnchantedBladeStaffBool = true;
|
||||
}
|
||||
if (!modPlayer.EnchantedBladeStaffBool)
|
||||
{
|
||||
player.DelBuff(buffIndex);
|
||||
buffIndex--;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.buffTime[buffIndex] = 18000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 603 B |
@@ -1119,6 +1119,7 @@ namespace CalamityMod.CalPlayer
|
||||
public bool KalandraMirror = false;
|
||||
public bool StellarTorus = false;
|
||||
public bool LiliesOfFinalityBool = false;
|
||||
public bool EnchantedBladeStaffBool = false;
|
||||
#endregion
|
||||
|
||||
#region Biome
|
||||
@@ -2205,6 +2206,7 @@ namespace CalamityMod.CalPlayer
|
||||
KalandraMirror = false;
|
||||
StellarTorus = false;
|
||||
LiliesOfFinalityBool = false;
|
||||
EnchantedBladeStaffBool = false;
|
||||
|
||||
/* Spawn blockers from back when they used to work by being favorited and not a toggleable item
|
||||
noStupidNaturalARSpawns = false
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using CalamityMod.Projectiles.Summon;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Items.Weapons.Summon
|
||||
{
|
||||
public class EnchantedBladeStaff : ModItem, ILocalizedModType
|
||||
{
|
||||
public static float SwingTime = 20f;
|
||||
public static float SwingWait = 10f;
|
||||
|
||||
public new string LocalizationCategory => "Items.Weapons.Summon";
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Item.damage = 10;
|
||||
Item.DamageType = DamageClass.Summon;
|
||||
Item.shoot = ModContent.ProjectileType<EnchantedBladeSummon>();
|
||||
Item.knockBack = 2f;
|
||||
|
||||
Item.useTime = Item.useAnimation = 15;
|
||||
Item.mana = 10;
|
||||
Item.noMelee = true;
|
||||
Item.autoReuse = true;
|
||||
Item.width = 50;
|
||||
Item.height = 50;
|
||||
Item.value = CalamityGlobalItem.RarityBlueBuyPrice;
|
||||
Item.rare = ItemRarityID.Blue;
|
||||
Item.useStyle = ItemUseStyleID.Shoot;
|
||||
Item.UseSound = SoundID.Item8;
|
||||
|
||||
Item.shootSpeed = 1f;
|
||||
}
|
||||
|
||||
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
|
||||
{
|
||||
var minion = Projectile.NewProjectileDirect(source, Main.MouseWorld, Vector2.Zero, type, damage, knockback, player.whoAmI);
|
||||
minion.velocity = minion.DirectionFrom(player.Center);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void AddRecipes()
|
||||
{
|
||||
base.AddRecipes();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 986 B |
@@ -1557,3 +1557,8 @@ Voidfrost: {
|
||||
DisplayName: Voidfrost
|
||||
Description: The emptiness of space devours all warmth and life
|
||||
}
|
||||
|
||||
EnchantedBladeStaffBuff: {
|
||||
DisplayName: Enchanted Blade Staff Buff
|
||||
Description: Mods.CalamityMod.Buffs.EnchantedBladeStaffBuff.Description
|
||||
}
|
||||
@@ -884,3 +884,8 @@ YharonsKindleStaff: {
|
||||
Requires 5 minion slots to use
|
||||
'''
|
||||
}
|
||||
|
||||
EnchantedBladeStaff: {
|
||||
DisplayName: Enchanted Blade Staff
|
||||
Tooltip: ""
|
||||
}
|
||||
@@ -330,3 +330,5 @@ WulfrumDroid.DisplayName: Wulfrum Droid
|
||||
WulfrumEnergyBurst.DisplayName: Wulfrum Bolt
|
||||
WulfrumFusionBolt.DisplayName: Fusion Bolt
|
||||
YharonMinionFireball.DisplayName: Dragon Fireball
|
||||
EnchantedBladeSummon.DisplayName: Enchanted Blade Summon
|
||||
EnchantedBladeStaffProjectile.DisplayName: Enchanted Blade Staff Projectile
|
||||
@@ -0,0 +1,46 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Projectiles.Summon
|
||||
{
|
||||
public class EnchantedBladeStaffProjectile : ModProjectile, ILocalizedModType
|
||||
{
|
||||
public new string LocalizationCategory => "Projectiles.Summon";
|
||||
|
||||
public override void SetStaticDefaults() => ProjectileID.Sets.MinionShot[Type] = true;
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Projectile.DamageType = DamageClass.Summon;
|
||||
Projectile.width = Projectile.height = 32;
|
||||
Projectile.usesLocalNPCImmunity = true;
|
||||
Projectile.localNPCHitCooldown = -1;
|
||||
Projectile.friendly = true;
|
||||
Projectile.penetrate = -1;
|
||||
Projectile.tileCollide = false;
|
||||
Projectile.timeLeft = 300;
|
||||
}
|
||||
|
||||
public override void OnSpawn(IEntitySource source) => Projectile.rotation = Projectile.velocity.ToRotation();
|
||||
|
||||
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => Projectile.timeLeft = 3;
|
||||
|
||||
public override bool PreDraw(ref Color lightColor)
|
||||
{
|
||||
Texture2D texture = TextureAssets.Projectile[Type].Value;
|
||||
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
|
||||
Color drawColor = Color.Cyan * 0.6f;
|
||||
float drawRotation = Projectile.rotation + MathHelper.PiOver2;
|
||||
Vector2 anchorPoint = texture.Size() * 0.5f;
|
||||
|
||||
Main.EntitySpriteDraw(texture, drawPosition, null, drawColor, drawRotation, anchorPoint, Projectile.scale, SpriteEffects.None);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 319 B |
@@ -0,0 +1,241 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using CalamityMod.Buffs.Summon;
|
||||
using CalamityMod.Projectiles.BaseProjectiles;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.ID;
|
||||
using static CalamityMod.Items.Weapons.Summon.EnchantedBladeStaff;
|
||||
using static Terraria.ModLoader.ModContent;
|
||||
|
||||
namespace CalamityMod.Projectiles.Summon
|
||||
{
|
||||
public class EnchantedBladeSummon : BaseMinionProjectile
|
||||
{
|
||||
public override int AssociatedProjectileTypeID => ProjectileType<EnchantedBladeSummon>();
|
||||
|
||||
public override int AssociatedBuffTypeID => BuffType<EnchantedBladeStaffBuff>();
|
||||
|
||||
public override ref bool AssociatedMinionBool => ref ModdedOwner.EnchantedBladeStaffBool;
|
||||
|
||||
public override bool PreHardmodeMinionTileVision => true;
|
||||
|
||||
private Action CurrentState
|
||||
{
|
||||
get => _currentState;
|
||||
set
|
||||
{
|
||||
OnStateChange(value);
|
||||
_currentState = value;
|
||||
NetUpdate();
|
||||
}
|
||||
}
|
||||
private Action _currentState;
|
||||
|
||||
private ref float SwingTimer => ref Projectile.ai[0];
|
||||
|
||||
private ref float SwingDirection => ref Projectile.ai[1];
|
||||
|
||||
private Vector2 IdlePosition => Owner.MountedCenter +
|
||||
new Vector2(50f * MathF.Ceiling(Projectile.minionPos / 2f) * (Projectile.minionPos % 2 == 0 ? -1 : 1), -60f + MathF.Ceiling(Projectile.minionPos / 2f) * 15f);
|
||||
|
||||
private Vector2 SwingCenter;
|
||||
|
||||
private float RandomRotationOffset;
|
||||
|
||||
private bool HasStartedSwinging;
|
||||
|
||||
private bool HasSpawned;
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
base.SetDefaults();
|
||||
Projectile.width = Projectile.height = 32;
|
||||
}
|
||||
|
||||
#region AI
|
||||
|
||||
public override void MinionAI()
|
||||
{
|
||||
if (!HasSpawned)
|
||||
{
|
||||
TrailCacheLength = 4;
|
||||
CurrentState = GoToOwnerState;
|
||||
HasSpawned = true;
|
||||
NetUpdate();
|
||||
}
|
||||
|
||||
CurrentState.Invoke();
|
||||
}
|
||||
|
||||
private void GoToOwnerState()
|
||||
{
|
||||
if (Target is not null)
|
||||
{
|
||||
CurrentState = AttackState;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Projectile.DistanceSQ(IdlePosition) < 80f * 80f)
|
||||
CurrentState = IdleState;
|
||||
|
||||
Projectile.velocity = Projectile.velocity.ToRotation().AngleTowards(Projectile.DirectionTo(IdlePosition).ToRotation(), 0.08f).ToRotationVector2() * 10f;
|
||||
Projectile.rotation = Projectile.velocity.ToRotation();
|
||||
}
|
||||
|
||||
private void IdleState()
|
||||
{
|
||||
if (Target is not null)
|
||||
{
|
||||
CurrentState = AttackState;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Projectile.DistanceSQ(IdlePosition) > 160f * 160f)
|
||||
CurrentState = GoToOwnerState;
|
||||
|
||||
float speed = Utils.Remap(Projectile.DistanceSQ(IdlePosition), 0f, 160f * 160f, 0.25f, 15f);
|
||||
Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.velocity.ToRotation().AngleTowards(Projectile.DirectionTo(IdlePosition).ToRotation(), 0.4f).ToRotationVector2() * speed, 0.2f);
|
||||
Projectile.rotation = MathHelper.Lerp(Projectile.rotation, MathHelper.ToRadians(RandomSineFunction(Main.GlobalTimeWrappedHourly + RandomRotationOffset) * 3f) - MathHelper.PiOver2, 0.1f);
|
||||
}
|
||||
|
||||
private void AttackState()
|
||||
{
|
||||
if (Target is null)
|
||||
{
|
||||
CurrentState = GoToOwnerState;
|
||||
return;
|
||||
}
|
||||
|
||||
var easing = new CalamityUtils.CurveSegment(CalamityUtils.PolyInOutEasing, 0f, 0f, 1f, 4);
|
||||
|
||||
float swingRotation = MathHelper.Lerp(-MathHelper.PiOver2, MathHelper.PiOver2, CalamityUtils.PiecewiseAnimation(Utils.GetLerpValue(SwingWait, SwingWait + SwingTime, SwingTimer, true), easing)) * MathF.Sign(Target.Center.X - SwingCenter.X);
|
||||
Projectile.Center = SwingCenter + (Projectile.DirectionTo(Target.Center).ToRotation() + swingRotation).ToRotationVector2() * 40f;
|
||||
Projectile.rotation = Projectile.DirectionFrom(SwingCenter).ToRotation();
|
||||
|
||||
if (SwingTimer == SwingWait + SwingTime * 0.5f && Main.myPlayer == Projectile.owner)
|
||||
{
|
||||
Vector2 predictiveDirection = CalamityUtils.CalculatePredictiveAimToTarget(SwingCenter, Target, 15f);
|
||||
Vector2 spawnPosition = SwingCenter + predictiveDirection.SafeNormalize(-Vector2.UnitY) * 40f;
|
||||
Projectile.NewProjectileDirect(
|
||||
Projectile.GetSource_FromThis(),
|
||||
spawnPosition,
|
||||
predictiveDirection,
|
||||
ProjectileType<EnchantedBladeStaffProjectile>(),
|
||||
Projectile.damage,
|
||||
Projectile.knockBack,
|
||||
Projectile.owner);
|
||||
}
|
||||
|
||||
SwingTimer += 1f * SwingDirection;
|
||||
if (SwingTimer == 0f || SwingTimer == SwingWait + SwingTime + SwingWait)
|
||||
{
|
||||
if (HasStartedSwinging)
|
||||
SwingDirection *= -1f;
|
||||
else
|
||||
HasStartedSwinging = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStateChange(Action newState)
|
||||
{
|
||||
if (newState == IdleState)
|
||||
RandomRotationOffset = Main.rand.NextFloat(MathHelper.TwoPi);
|
||||
|
||||
if (newState == AttackState)
|
||||
{
|
||||
float targetSize = Target.Size.Length();
|
||||
Vector2 previousCenter = Projectile.Center;
|
||||
Vector2 newCenter = Target.Center + Main.rand.NextVector2CircularEdge(targetSize * 0.5f + 160f, targetSize * 0.5f + 160f);
|
||||
|
||||
int maxAttempts = 10;
|
||||
int attempts = 0;
|
||||
while (Main.tile[newCenter.ToSafeTileCoordinates()].IsTileSolid() || attempts == maxAttempts)
|
||||
{
|
||||
newCenter = Target.Center + Main.rand.NextVector2CircularEdge(targetSize * 0.5f + 160f, targetSize * 0.5f + 160f);
|
||||
attempts++;
|
||||
}
|
||||
|
||||
Projectile.Center = newCenter;
|
||||
SwingCenter = Projectile.Center;
|
||||
|
||||
HasStartedSwinging = false;
|
||||
SwingDirection = Main.rand.NextBool().ToDirectionInt();
|
||||
int totalSwingTime = (int)(2f * SwingWait + SwingTime);
|
||||
SwingTimer = SwingDirection == 1 ? Main.rand.Next(-30, -2) : Main.rand.Next(totalSwingTime + 1, totalSwingTime + 30 + 1);
|
||||
|
||||
if (!Main.dedServ)
|
||||
{
|
||||
int dustAmount = Main.rand.Next(30, 40);
|
||||
for (int i = 0; i < dustAmount; i++)
|
||||
{
|
||||
float angle = MathHelper.TwoPi / dustAmount * i;
|
||||
Vector2 velocity = angle.ToRotationVector2() * Main.rand.NextFloat(5f);
|
||||
Dust tpDustStart = Dust.NewDustPerfect(previousCenter, 309, velocity);
|
||||
Dust tpDustEnd = Dust.NewDustPerfect(SwingCenter, 309, velocity);
|
||||
tpDustStart.noGravity = true;
|
||||
tpDustEnd.noGravity = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float RandomSineFunction(float x) => MathF.Sin(3f * x) + MathF.Cos(5f * x) + 2f * MathF.Sin(0.5f * x);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Drawing
|
||||
|
||||
public override bool PreDraw(ref Color lightColor)
|
||||
{
|
||||
Texture2D texture = TextureAssets.Projectile[Type].Value;
|
||||
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
|
||||
Color drawColor = Projectile.GetAlpha(lightColor);
|
||||
float drawRotation = Projectile.rotation + MathHelper.PiOver2;
|
||||
Vector2 anchorPoint = texture.Size() * 0.5f;
|
||||
|
||||
if (CurrentState == AttackState)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Vector2 afterimageDrawPosition = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition;
|
||||
Color afterimageDrawColor = Color.Cyan * ((4f - i) / 4f) * 0.8f;
|
||||
float afterimageDrawRotation = Projectile.oldRot[i] + MathHelper.PiOver2;
|
||||
Main.EntitySpriteDraw(texture, afterimageDrawPosition, null, afterimageDrawColor, afterimageDrawRotation, anchorPoint, Projectile.scale, SpriteEffects.None);
|
||||
}
|
||||
}
|
||||
|
||||
Main.EntitySpriteDraw(texture, drawPosition, null, drawColor, drawRotation, anchorPoint, Projectile.scale, SpriteEffects.None);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Syncing
|
||||
|
||||
private void NetUpdate()
|
||||
{
|
||||
Projectile.netUpdate = true;
|
||||
Projectile.netSpam = 0;
|
||||
}
|
||||
|
||||
public override void SendExtraAI(BinaryWriter writer)
|
||||
{
|
||||
writer.WritePackedVector2(SwingCenter);
|
||||
writer.Write(RandomRotationOffset);
|
||||
writer.Write(HasSpawned);
|
||||
}
|
||||
|
||||
public override void ReceiveExtraAI(BinaryReader reader)
|
||||
{
|
||||
SwingCenter = reader.ReadPackedVector2();
|
||||
RandomRotationOffset = reader.ReadSingle();
|
||||
HasSpawned = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 532 B |
Reference in new issue
Block a user