Merge of Ares Exoskeleton summon weapon

This commit is contained in:
Cameron Ewell authored and GitHub committed 2022-07-26 17:06:18 -04:00
commit 8334975ac1
64 files changed
+2085 -25

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
using CalamityMod.CalPlayer;
using CalamityMod.Items.Weapons.Summon;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Buffs.Summon
{
public class ExoskeletonCannons : ModBuff
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Ares' Cannons");
Description.SetDefault("Pulse cannon not included");
Main.buffNoTimeDisplay[Type] = true;
Main.buffNoSave[Type] = true;
}
public override void Update(Player player, ref int buffIndex)
{
CalamityPlayer modPlayer = player.Calamity();
if (AresExoskeleton.ArmExists(player))
modPlayer.AresCannons = true;
if (modPlayer.AresCannons)
player.buffTime[buffIndex] = 18000;
else
{
player.DelBuff(buffIndex);
buffIndex--;
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 604 B

+6
View File
@@ -36,6 +36,7 @@ using CalamityMod.Items.VanillaArmorChanges;
using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Items.Weapons.Ranged;
using CalamityMod.Items.Weapons.Rogue;
using CalamityMod.Items.Weapons.Summon;
using CalamityMod.NPCs;
using CalamityMod.NPCs.Abyss;
using CalamityMod.NPCs.ExoMechs.Apollo;
@@ -987,6 +988,7 @@ namespace CalamityMod.CalPlayer
public bool eyeOfNight = false;
public bool soulSeeker = false;
public bool perditionBeacon = false;
public bool AresCannons = false;
public List<DeadMinionProperties> PendingProjectilesToRespawn = new List<DeadMinionProperties>();
@@ -2057,6 +2059,7 @@ namespace CalamityMod.CalPlayer
eyeOfNight = false;
soulSeeker = false;
perditionBeacon = false;
AresCannons = false;
disableVoodooSpawns = false;
disablePerfCystSpawns = false;
@@ -5601,6 +5604,9 @@ namespace CalamityMod.CalPlayer
Player.head = EquipLoader.GetEquipSlot(Mod, snowmanNoseless ? "PopoNoseless" : "Popo", EquipType.Head);
Player.face = -1;
}
else if (AresExoskeleton.ArmExists(Player))
Player.body = EquipLoader.GetEquipSlot(Mod, "AresExoskeleton", EquipType.Body);
else if ((abyssalDivingSuitPower || abyssalDivingSuitForce) && !abyssalDivingSuitHide)
{
Player.legs = EquipLoader.GetEquipSlot(Mod, "AbyssalDivingSuit", EquipType.Legs);
+17
View File
@@ -0,0 +1,17 @@
using Microsoft.Xna.Framework.Graphics;
namespace CalamityMod.DataStructures
{
// Restarting the sprite batch for each different projectile is analogously equivalent to creating an entire new factory just to build a single car.
// It is inefficient and leads to performance problems as many projectiles do it.
// To mitigate this problem, a special interface exists for the purpose of deferring drawing of certain entities to a time in which they all may be
// subject to the same additive draw state before all of the spritebatch's contents are flushed.
// Manual drawing hooks should not be utilized when using this interface, such as ModNPC.PreDraw.
// The implementation of this is almost identical to that of SLR but they're both so simple that it really shouldn't matter.
public interface IAdditiveDrawer
{
void AdditiveDraw(SpriteBatch spriteBatch);
}
}
+2
View File
@@ -49,6 +49,7 @@ namespace CalamityMod.ILEditing
IL.Terraria.Player.QuickHeal += ConditionallyReplaceManaSickness;
IL.Terraria.Player.QuickMana += ConditionallyReplaceManaSickness;
IL.Terraria.Player.ItemCheck_Inner += ConditionallyReplaceManaSickness;
IL.Terraria.Main.DoDraw += AdditiveDrawing;
On.Terraria.Main.SortDrawCacheWorms += DrawFusableParticles;
On.Terraria.Main.DrawInfernoRings += DrawForegroundParticles;
On.Terraria.Main.SetDisplayMode += ResetRenderTargetSizes;
@@ -161,6 +162,7 @@ namespace CalamityMod.ILEditing
IL.Terraria.Player.QuickHeal -= ConditionallyReplaceManaSickness;
IL.Terraria.Player.QuickMana -= ConditionallyReplaceManaSickness;
IL.Terraria.Player.ItemCheck_Inner -= ConditionallyReplaceManaSickness;
IL.Terraria.Main.DoDraw -= AdditiveDrawing;
On.Terraria.Main.SortDrawCacheWorms -= DrawFusableParticles;
On.Terraria.Main.DrawInfernoRings -= DrawForegroundParticles;
On.Terraria.Main.SetDisplayMode -= ResetRenderTargetSizes;
+38 -1
View File
@@ -38,6 +38,8 @@ using Terraria.ModLoader;
using Terraria.UI.Gamepad;
using Terraria.Utilities;
using Terraria.Graphics.Light;
using Terraria.GameContent.Events;
using CalamityMod.DataStructures;
using CalamityMod.Particles.Metaballs;
namespace CalamityMod.ILEditing
@@ -637,10 +639,45 @@ namespace CalamityMod.ILEditing
}
#endregion Fire Cursor Effect for the Calamity Accessory
#region Custom Draw Layers
private static void AdditiveDrawing(ILContext il)
{
ILCursor cursor = new(il);
if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCall<MoonlordDeathDrama>("DrawWhite")))
return;
cursor.EmitDelegate<Action>(() =>
{
Main.spriteBatch.SetBlendState(BlendState.Additive);
// Draw Projectiles.
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (!Main.projectile[i].active)
continue;
if (Main.projectile[i].ModProjectile is IAdditiveDrawer d)
d.AdditiveDraw(Main.spriteBatch);
}
// Draw NPCs.
for (int i = 0; i < Main.maxNPCs; i++)
{
if (!Main.npc[i].active)
continue;
if (Main.npc[i].ModNPC is IAdditiveDrawer d)
d.AdditiveDraw(Main.spriteBatch);
}
Main.spriteBatch.SetBlendState(BlendState.AlphaBlend);
});
}
#endregion Custom Draw Layers
#region General Particle Rendering
private static void DrawFusableParticles(On.Terraria.Main.orig_SortDrawCacheWorms orig, Main self)
{
DeathAshParticle.DrawAll();
FusableParticleManager.RenderAllFusableParticles();
+19 -6
View File
@@ -174,7 +174,7 @@ namespace CalamityMod.ILEditing
{
cache.Add(new OrderedProjectileEntry()
{
Proj = Main.projectile[i] ?? new Projectile(),
Proj = Main.projectile[i] ?? new(),
OriginalIndex = i
});
}
@@ -182,12 +182,18 @@ namespace CalamityMod.ILEditing
});
cursor.Emit(OpCodes.Stsfld, typeof(ILChanges).GetField("OrderedProjectiles", BindingFlags.Static | BindingFlags.Public));
// Find the update loop update local index.
int updateLoopLocalIndex = -1;
cursor.GotoNext(i => i.MatchStloc(out updateLoopLocalIndex));
// Go before the declaration of the projectile loop index and declare the ordered projectile.
if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchStsfld<Main>("ProjectileUpdateLoopIndex")))
cursor.Goto(0);
if (!cursor.TryGotoNext(MoveType.After, i => i.MatchStsfld<Main>("ProjectileUpdateLoopIndex")))
{
LogFailure("Projectile Update Priority fix", "Could not locate the ProjectileUpdateLoopIndex field.");
return;
}
int updateIndexPosition = cursor.Index;
// Replace the projectile reference on the Projectile.Update call.
if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdelemRef()))
@@ -199,14 +205,21 @@ namespace CalamityMod.ILEditing
// Pop the Main.projectile[i] reference and replace it with OrderedProjectiles[i].Proj.
cursor.Emit(OpCodes.Pop);
cursor.Emit(OpCodes.Ldsfld, typeof(ILChanges).GetField("OrderedProjectiles", BindingFlags.Static | BindingFlags.Public));
cursor.Emit(OpCodes.Ldloc, 29);
cursor.Emit(OpCodes.Ldloc, updateLoopLocalIndex);
cursor.Emit(OpCodes.Callvirt, typeof(List<OrderedProjectileEntry>).GetMethod("get_Item"));
cursor.Emit(OpCodes.Ldfld, typeof(OrderedProjectileEntry).GetField("Proj"));
// Remove the direct i reference in the Update call and replace it with the original index in the cache, to prevent update ID
// Pop the direct i reference in the Update call and replace it with the original index in the cache, to prevent update ID
// mismatches.
cursor.Remove();
cursor.Emit(OpCodes.Ldloc, 29);
cursor.Goto(updateIndexPosition);
if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCall<Projectile>("Call")))
{
LogFailure("Projectile Update Priority fix", "Could not locate the projectile Update call.");
return;
}
cursor.Emit(OpCodes.Pop);
cursor.Emit(OpCodes.Ldloc, updateLoopLocalIndex);
cursor.EmitDelegate<Func<int, int>>(i => OrderedProjectiles[i].OriginalIndex);
}
#endregion Fix Projectile Update Priority Problems
@@ -0,0 +1,55 @@
using Microsoft.Xna.Framework;
using System;
using Terraria;
namespace CalamityMod.InverseKinematics
{
public class CyclicCoordinateDescentUpdateRule : IInverseKinematicsUpdateRule
{
public float AngularOffsetAcceleration;
public float AngularDeviationLenience;
public CyclicCoordinateDescentUpdateRule(float angularOffsetAcceleration, float angularDeviationLenience)
{
AngularOffsetAcceleration = angularOffsetAcceleration;
AngularDeviationLenience = angularDeviationLenience;
}
public void Update(LimbCollection limbs, Vector2 destination)
{
float distanceFromStart = Vector2.Distance(destination, limbs.ConnectPoint);
float distanceFromEnd = Vector2.Distance(destination, limbs.EndPoint);
float slowdownInterpolant = Utils.GetLerpValue(8f, 40f, distanceFromEnd, true);
slowdownInterpolant *= Utils.GetLerpValue(8f, 40f, distanceFromStart, true);
Vector2 originalEndPoint = limbs.EndPoint;
for (int i = limbs.Limbs.Length - 1; i >= 0; i--)
{
// Move based on angular offsets. Movement is dampened the closer a limb is to being the first limb.
Vector2 currentToEndOffset = originalEndPoint - limbs.Limbs[i].ConnectPoint;
Vector2 currentToDestinationOffset = destination - limbs.Limbs[i].ConnectPoint;
Vector2 perpendicularDirection = currentToDestinationOffset.RotatedBy(MathHelper.PiOver2);
float angularOffset = currentToEndOffset.AngleBetween(currentToDestinationOffset) * (float)Math.Sqrt((i + 1f) / limbs.Limbs.Length);
// Determine direction by choosing the angle which approaches the destination faster.
float leftAngularOffset = currentToEndOffset.AngleBetween(currentToDestinationOffset - perpendicularDirection);
float rightAngularOffset = currentToEndOffset.AngleBetween(currentToDestinationOffset + perpendicularDirection);
if (leftAngularOffset > rightAngularOffset)
angularOffset *= -1f;
// Perform safety checks on the result of the underlying arccosines.
if (float.IsNaN(angularOffset))
break;
// Update rotation.
limbs.Limbs[i].Rotation += angularOffset * slowdownInterpolant * AngularOffsetAcceleration;
// And limit it so that it doesn't look weird.
if (i > 0)
{
float behindRotation = (float)limbs.Limbs[i - 1].Rotation;
limbs.Limbs[i].Rotation = MathHelper.Clamp((float)limbs.Limbs[i].Rotation, behindRotation - AngularDeviationLenience, behindRotation + AngularDeviationLenience);
}
}
}
}
}
@@ -0,0 +1,9 @@
using Microsoft.Xna.Framework;
namespace CalamityMod.InverseKinematics
{
public interface IInverseKinematicsUpdateRule
{
void Update(LimbCollection limbs, Vector2 destination);
}
}
+21
View File
@@ -0,0 +1,21 @@
using Microsoft.Xna.Framework;
using Terraria;
namespace CalamityMod.InverseKinematics
{
public class Limb
{
// Doubles are used instead of floats as a means of providing sufficient precision to not cause erroneous results when
// doing approximations of derivative limits with small divisors.
public double Rotation;
public double Length;
public Vector2 ConnectPoint;
public Vector2 EndPoint => ConnectPoint + ((float)Rotation).ToRotationVector2() * (float)Length;
public Limb(float rotation, float length)
{
Rotation = rotation;
Length = length;
}
}
}
+55
View File
@@ -0,0 +1,55 @@
using Microsoft.Xna.Framework;
using System.Linq;
namespace CalamityMod.InverseKinematics
{
public class LimbCollection
{
public Limb[] Limbs;
public IInverseKinematicsUpdateRule UpdateRule;
public Vector2 ConnectPoint => Limbs.First().ConnectPoint;
public Vector2 EndPoint => Limbs.Last().EndPoint;
public double TotalLength => Limbs.Sum(l => l.Length);
public LimbCollection(IInverseKinematicsUpdateRule updateRule, int limbCount, float limbLength)
{
UpdateRule = updateRule;
Limbs = new Limb[limbCount];
for (int i = 0; i < limbCount; i++)
Limbs[i] = new Limb(0f, limbLength);
}
public LimbCollection(IInverseKinematicsUpdateRule updateRule, params float[] limbLengths)
{
UpdateRule = updateRule;
int limbCount = limbLengths.Length;
Limbs = new Limb[limbCount];
for (int i = 0; i < limbCount; i++)
Limbs[i] = new Limb(0f, limbLengths[i]);
}
public void UpdateConnectPoints(Vector2? connectPoint = null)
{
if (connectPoint.HasValue)
Limbs[0].ConnectPoint = connectPoint.Value;
for (int i = 1; i < Limbs.Length; i++)
Limbs[i].ConnectPoint = Limbs[i - 1].EndPoint;
}
public Limb this[int index]
{
get => Limbs[index];
set => Limbs[index] = value;
}
public void Update(Vector2 connectPoint, Vector2 destination)
{
UpdateRule.Update(this, destination);
Limbs[0].ConnectPoint = connectPoint;
UpdateConnectPoints(connectPoint);
}
}
}
@@ -406,7 +406,7 @@ namespace CalamityMod.Items.Armor.DesertProwler
public override void OnSpawn(Projectile projectile, IEntitySource source)
{
if (projectile.damage > 0)
if (projectile.damage > 0 && !Main.gameMenu)
{
if (projectile.owner >= 0 && DesertProwlerHat.ShroudedInSmoke(Main.player[projectile.owner], out var cd) && projectile.DamageType.CountsAsClass(DamageClass.Ranged))
{
+8 -8
View File
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using CalamityMod.Cooldowns;
using CalamityMod.Items.Accessories.Vanity;
using CalamityMod.Items.Materials;
using CalamityMod.Items.Materials;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.DataStructures;
using CalamityMod.Items.Accessories.Vanity;
using CalamityMod.Cooldowns;
using Terraria.Audio;
using System;
using System.Collections.Generic;
using static Microsoft.Xna.Framework.Input.Keys;
using static Terraria.ModLoader.ModContent;
+2
View File
@@ -5,6 +5,7 @@ using CalamityMod.Items.Mounts;
using CalamityMod.Items.Weapons.Melee;
using CalamityMod.Items.Weapons.Ranged;
using CalamityMod.Items.Weapons.Rogue;
using CalamityMod.Items.Weapons.Summon;
using CalamityMod.NPCs.ExoMechs.Ares;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -60,6 +61,7 @@ namespace CalamityMod.Items.TreasureBags
{
DropHelper.DropItem(s, player, ModContent.ItemType<PhotonRipper>());
DropHelper.DropItem(s, player, ModContent.ItemType<TheJailor>());
DropHelper.DropItem(s, player, ModContent.ItemType<AresExoskeleton>());
}
if (DownedBossSystem.downedThanatos)
{
+146
View File
@@ -0,0 +1,146 @@
using Terraria.DataStructures;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using CalamityMod.Projectiles.Summon.SmallAresArms;
using Microsoft.Xna.Framework.Graphics;
using CalamityMod.Particles;
namespace CalamityMod.Items.Weapons.Summon
{
public class AresExoskeleton : ModItem
{
public int FrameCounter = 0;
public int Frame = 0;
public const int BoxParticleLifetime = 95;
public const int PlasmaCannonShootRate = 30;
public const int TeslaCannonShootRate = 48;
public const int LaserCannonNormalShootRate = 30;
public const int GaussNukeShootRate = 210;
public const float TargetingDistance = 1020f;
public const float MinionSlotsPerCannon = 2f;
// Multiple orbs can arc together when there are 2+ tesla cannons, resulting in a LOT of hits.
// The local i-frames are also quite high to combat this problem.
public const float TeslaOrbDamageFactor = 0.625f;
public const float NukeDamageFactor = 1.5f;
public const float MaxNukeExplosionRadius = 720f;
public const float TeslaOrbDetatchDistance = 1500f;
public static bool ArmExists(Player player)
{
if (player.ownedProjectileCounts[ModContent.ProjectileType<ExoskeletonPlasmaCannon>()] >= 1)
return true;
if (player.ownedProjectileCounts[ModContent.ProjectileType<ExoskeletonTeslaCannon>()] >= 1)
return true;
if (player.ownedProjectileCounts[ModContent.ProjectileType<ExoskeletonLaserCannon>()] >= 1)
return true;
if (player.ownedProjectileCounts[ModContent.ProjectileType<ExoskeletonGaussNukeCannon>()] >= 1)
return true;
return false;
}
public override void Load()
{
// Add the body equip texture.
if (Main.netMode != NetmodeID.Server)
EquipLoader.AddEquipTexture(Mod, $"{Texture}_{EquipType.Body}", EquipType.Body, this);
}
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Ares' Exoskeleton");
Tooltip.SetDefault("Creates a panel with four slots and four choices above it: Plasma, Tesla, Laser, and Gauss\n" +
"Clicking one of the choices and then clicking one of the slots allows you to summon a cannon that stays close to you and attacks nearby enemies\n" +
"Clicking on a slot that's already occupied destroys its associated cannon and clears the slot\n" +
$"Cannons take {MinionSlotsPerCannon} minion slots each");
SacrificeTotal = 1;
}
public override void SetDefaults()
{
Item.mana = 80;
Item.damage = 672;
Item.useStyle = ItemUseStyleID.HoldUp;
Item.noUseGraphic = true;
Item.width = Item.height = 36;
Item.useTime = Item.useAnimation = 9;
Item.noMelee = true;
Item.knockBack = 1f;
Item.value = CalamityGlobalItem.RarityVioletBuyPrice;
Item.Calamity().customRarity = CalamityRarity.Violet;
Item.UseSound = SoundID.Item117;
Item.shoot = ModContent.ProjectileType<ExoskeletonPlasmaCannon>();
Item.shootSpeed = 10f;
Item.DamageType = DamageClass.Summon;
}
public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frameI, Color drawColor, Color itemColor, Vector2 origin, float scale)
{
Texture2D texture = ModContent.Request<Texture2D>("CalamityMod/Items/Weapons/Summon/AresExoskeleton").Value;
if (ArmExists(Main.LocalPlayer))
{
texture = ModContent.Request<Texture2D>("CalamityMod/Items/Weapons/Summon/AresExoskeletonRemote").Value;
position.X += scale * 6f;
}
spriteBatch.Draw(texture, position, new(0, 0, texture.Width, texture.Height), Color.White, 0f, origin, scale, 0, 0);
return false;
}
public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
{
Texture2D texture = ModContent.Request<Texture2D>("CalamityMod/Items/Weapons/Summon/AresExoskeleton").Value;
spriteBatch.Draw(texture, Item.position - Main.screenPosition, Item.GetCurrentFrame(ref Frame, ref FrameCounter, 1, 1), lightColor, 0f, Vector2.Zero, 1f, 0, 0);
return false;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
int panelID = ModContent.ProjectileType<ExoskeletonPanel>();
// If the player owns a panel, make it fade away.
if (player.ownedProjectileCounts[panelID] >= 1)
{
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (Main.projectile[i].type != panelID || Main.projectile[i].owner != player.whoAmI || !Main.projectile[i].active)
continue;
Main.projectile[i].ai[0] = 1f;
Main.projectile[i].netUpdate = true;
}
}
// Otherwise, create one. While it doesn't do damage on its own, it does store it for reference by the cannons that might be spawned.
else
{
int panel = Projectile.NewProjectile(source, position, Vector2.Zero, panelID, damage, 0f, player.whoAmI);
if (Main.projectile.IndexInRange(panel))
Main.projectile[panel].originalDamage = Item.damage;
// Also throw a cool mechanical box particle out.
Vector2 boxVelocity = -Vector2.UnitY.RotatedByRandom(0.7f) * 6f + Vector2.UnitX * player.direction * 4f;
Particle box = new AresSummonCrateParticle(player, boxVelocity, BoxParticleLifetime);
GeneralParticleHandler.SpawnParticle(box);
}
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

+4 -2
View File
@@ -30,6 +30,7 @@ using Terraria.ModLoader;
using Terraria.Audio;
using Terraria.GameContent.ItemDropRules;
using CalamityMod.Sounds;
using CalamityMod.Items.Weapons.Summon;
namespace CalamityMod.NPCs.ExoMechs.Ares
{
@@ -185,8 +186,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
//We'll probably want a custom background for Exos like ML has.
//BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Exo,
// Will move to localization whenever that is cleaned up.
new FlavorTextBestiaryInfoElement("While it is the most flamboyant of Draedon’s machines, it appears to be lacking some finish, though this trait does not compromise its killing potential whatsoever.")
// Will move to localization whenever that is cleaned up.
new FlavorTextBestiaryInfoElement("While it is the most flamboyant of Draedon’s machines, it appears to be lacking some finish, though this trait does not compromise its killing potential whatsoever.")
});
}
@@ -1370,6 +1371,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
// Ares weapons
normalOnly.Add(ItemDropRule.ByCondition(DropHelper.If(AresLoot), ModContent.ItemType<PhotonRipper>()));
normalOnly.Add(ItemDropRule.ByCondition(DropHelper.If(AresLoot), ModContent.ItemType<TheJailor>()));
normalOnly.Add(ItemDropRule.ByCondition(DropHelper.If(AresLoot), ModContent.ItemType<AresExoskeleton>()));
// Twins weapons
normalOnly.Add(ItemDropRule.ByCondition(DropHelper.If(ApolloLoot), ModContent.ItemType<TheAtomSplitter>()));
Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

+52
View File
@@ -0,0 +1,52 @@
using Microsoft.Xna.Framework;
using Terraria;
using System;
using Microsoft.Xna.Framework.Graphics;
namespace CalamityMod.Particles
{
public class AresSummonCrateParticle : Particle
{
public override bool SetLifetime => true;
public override string Texture => "CalamityMod/Particles/AresSummonCrate";
public override bool UseCustomDraw => true;
public AresSummonCrateParticle(Player owner, Vector2 velocity, int lifetime)
{
Position = owner.Center - Vector2.UnitY * 4f;
Scale = 1f;
Color = Color.White;
Velocity = velocity;
Rotation = 0f;
Lifetime = lifetime;
}
public override void Update()
{
Rotation += Math.Sign(Velocity.X) * 0.05f;
Velocity.X *= 0.95f;
Velocity.Y += 0.24f;
if (Collision.SolidCollision(Position - Vector2.One * Scale * 19f, (int)(Scale * 38f), (int)(Scale * 38f), true))
{
Velocity.X *= 0.8f;
Rotation = 0f;
Velocity.Y = 0f;
}
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
Texture2D texture = GeneralParticleHandler.GetTexture(Type);
Color lightColor = Lighting.GetColor(Position.ToTileCoordinates());
int frameY = (int)Math.Round(MathHelper.Lerp(0f, 2f, (float)Math.Pow(LifetimeCompletion, 0.16f)));
Rectangle frame = texture.Frame(1, 3, 0, frameY);
float opacity = MathHelper.Clamp(1f - (float)Math.Pow(LifetimeCompletion, 7f), 0f, 1f);
spriteBatch.Draw(texture, Position - Main.screenPosition, frame, lightColor * opacity, Rotation, frame.Size() * 0.5f, Scale, 0, 0);
}
}
}
+2 -3
View File
@@ -1,6 +1,5 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using System;
using Microsoft.Xna.Framework.Graphics;
@@ -12,11 +11,11 @@ namespace CalamityMod.Particles
public override string Texture => "CalamityMod/Particles/WulfrumHat";
public override bool UseCustomDraw => true;
public int Direction ;
public int Direction;
public WulfrumHatParticle(Player owner, Vector2 velocity, int lifetime)
{
Position = owner.Center - Vector2.UnitY * 20f;;
Position = owner.Center - Vector2.UnitY * 20f;
Direction = owner.direction;
Scale = 1f;
Color = Color.White;
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1019 B

After

Width:  |  Height:  |  Size: 383 B

-4
View File
@@ -94,7 +94,6 @@ namespace CalamityMod.Projectiles.Boss
Dust dust = Main.dust[num54];
dust.velocity *= 3f;
dust = Main.dust[num54];
num54 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 100, default, 0.8f);
Main.dust[num54].position = Projectile.Center + Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * (float)Main.rand.NextDouble() * Projectile.width / 2f;
@@ -105,8 +104,6 @@ namespace CalamityMod.Projectiles.Boss
Main.dust[num54].noGravity = true;
Main.dust[num54].fadeIn = 1f;
Main.dust[num54].color = Color.Green * 0.5f;
dust = Main.dust[num54];
}
for (int num55 = 0; num55 < 20; num55++)
{
@@ -122,7 +119,6 @@ namespace CalamityMod.Projectiles.Boss
Dust dust = Main.dust[num56];
dust.velocity *= 0.5f;
dust = Main.dust[num56];
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

@@ -0,0 +1,158 @@
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class CannonLaserbeam : BaseLaserbeamProjectile
{
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public Player Owner => Main.player[Projectile.owner];
public Projectile OwnerProjectile => CalamityUtils.FindProjectileByIdentity((int)Projectile.ai[1], Projectile.owner);
public const int LifetimeConst = 75;
public override float MaxScale => 0.5f + (float)Math.Cos(Main.GlobalTimeWrappedHourly * 10f) * 0.07f;
public override float MaxLaserLength => 1560f;
public override float Lifetime => LifetimeConst;
public override Color LaserOverlayColor => Color.White;
public override Color LightCastColor => LaserOverlayColor;
public override Texture2D LaserBeginTexture => ModContent.Request<Texture2D>("CalamityMod/Projectiles/Boss/ThanatosBeamStart", AssetRequestMode.ImmediateLoad).Value;
public override Texture2D LaserMiddleTexture => ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Lasers/ThanatosBeamMiddle", AssetRequestMode.ImmediateLoad).Value;
public override Texture2D LaserEndTexture => ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Lasers/ThanatosBeamEnd", AssetRequestMode.ImmediateLoad).Value;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Exothermal Deathray");
Main.projFrames[Projectile.type] = 5;
ProjectileID.Sets.MinionShot[Projectile.type] = true;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 38;
Projectile.friendly = true;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.penetrate = -1;
Projectile.alpha = 255;
Projectile.localNPCHitCooldown = 14;
Projectile.scale = 0.5f;
Projectile.usesLocalNPCImmunity = true;
Projectile.hide = true;
Projectile.Calamity().UpdatePriority = 1f;
}
public override float DetermineLaserLength()
{
float[] samples = new float[4];
Collision.LaserScan(Projectile.Center, Projectile.velocity, Projectile.width * Projectile.scale, MaxLaserLength, samples);
return samples.Average();
}
public override void UpdateLaserMotion()
{
if (OwnerProjectile is null)
{
Projectile.Kill();
return;
}
Projectile.rotation = Projectile.velocity.ToRotation() - MathHelper.PiOver2;
}
public override void AttachToSomething()
{
Projectile ownerProjectile = OwnerProjectile;
if (ownerProjectile is null)
{
Projectile.Kill();
return;
}
float attachmentOffset = ownerProjectile.width * ownerProjectile.scale * 0.75f;
Projectile.Center = ownerProjectile.Center + ownerProjectile.rotation.ToRotationVector2() * attachmentOffset - Owner.velocity;
Projectile.rotation = ownerProjectile.rotation;
Projectile.velocity = Projectile.rotation.ToRotationVector2();
// Update frames.
Projectile.frame = Projectile.frameCounter++ / 5 % Main.projFrames[Type];
}
public override bool ShouldUpdatePosition() => false;
public override void DrawBehind(int index, List<int> behindNPCsAndTiles, List<int> behindNPCs, List<int> behindProjectiles, List<int> overPlayers, List<int> overWiresUI)
{
overPlayers.Add(index);
}
public override bool PreDraw(ref Color lightColor)
{
// This should never happen, but just in case.
if (Projectile.velocity == Vector2.Zero || Projectile.localAI[0] < 2f)
return false;
Color beamColor = LaserOverlayColor;
Rectangle startFrameArea = LaserBeginTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
Rectangle middleFrameArea = LaserMiddleTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
Rectangle endFrameArea = LaserEndTexture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
// Start texture drawing.
Main.EntitySpriteDraw(LaserBeginTexture,
Projectile.Center - Main.screenPosition,
startFrameArea,
beamColor,
Projectile.rotation,
startFrameArea.Size() * new Vector2(0.5f, 1f),
Projectile.scale,
SpriteEffects.None,
0);
// Prepare things for body drawing.
float laserBodyLength = LaserLength + middleFrameArea.Height;
Vector2 centerOnLaser = Projectile.Center;
// Body drawing.
if (laserBodyLength > 0f)
{
float laserOffset = middleFrameArea.Height * Projectile.scale;
float incrementalBodyLength = 0f;
while (incrementalBodyLength + 1f < laserBodyLength)
{
Main.EntitySpriteDraw(LaserMiddleTexture,
centerOnLaser - Main.screenPosition,
middleFrameArea,
beamColor,
Projectile.rotation,
middleFrameArea.Size() * 0.5f,
Projectile.scale,
SpriteEffects.None,
0);
incrementalBodyLength += laserOffset;
centerOnLaser += Projectile.velocity * laserOffset;
middleFrameArea.Y += LaserMiddleTexture.Height / Main.projFrames[Projectile.type];
if (middleFrameArea.Y + middleFrameArea.Height > LaserMiddleTexture.Height)
middleFrameArea.Y = 0;
}
}
Vector2 laserEndCenter = centerOnLaser - Main.screenPosition;
Main.EntitySpriteDraw(LaserEndTexture,
laserEndCenter,
endFrameArea,
beamColor,
Projectile.rotation,
endFrameArea.Size() * 0.5f,
Projectile.scale,
SpriteEffects.None,
0);
return false;
}
}
}
@@ -0,0 +1,218 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using CalamityMod.Items.Weapons.Summon;
using CalamityMod.InverseKinematics;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using CalamityMod.Buffs.Summon;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public abstract class ExoskeletonCannon : ModProjectile
{
public int ShootTimer;
public int HoverOffsetIndex => (int)Projectile.ai[0];
public bool TargetingSomething => Projectile.ai[1] == 1f;
public Player Owner => Main.player[Projectile.owner];
public LimbCollection Limbs = new(new CyclicCoordinateDescentUpdateRule(0.27f, MathHelper.PiOver2), 70f, 82f);
public static readonly Vector2[] HoverOffsetTable = new Vector2[]
{
new(300f, 96f),
new(-300f, 96f),
new(190f, -102f),
new(-190f, -102f)
};
public static readonly float[] RotationalClampTable = new float[]
{
0.23f,
MathHelper.Pi - 0.23f,
0.2f,
MathHelper.Pi - 0.2f
};
public virtual bool UsesSuperpredictiveness => false;
public virtual Vector2 DrawOffset => new((OwnerRestingOffset.X > 0f).ToDirectionInt() * 6f, -6f);
public virtual Vector2 ConnectOffset => HoverOffsetIndex >= 2 ? new((OwnerRestingOffset.X > 0f).ToDirectionInt() * 14f, -30f) : Vector2.Zero;
public abstract int ShootRate { get; }
public abstract float ShootSpeed { get; }
public abstract Vector2 OwnerRestingOffset { get; }
public abstract void ClampFirstLimbRotation(ref double limbRotation);
public abstract void ShootAtTarget(NPC target, Vector2 shootDirection);
public override void SetDefaults()
{
ShootTimer = Main.rand?.Next(ShootRate) ?? 0;
Projectile.width = 94;
Projectile.height = 40;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.netImportant = true;
Projectile.minion = true;
Projectile.minionSlots = AresExoskeleton.MinionSlotsPerCannon;
Projectile.penetrate = -1;
Projectile.timeLeft = 900000;
Projectile.scale = 1f;
Projectile.DamageType = DamageClass.Summon;
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(Projectile.rotation);
writer.Write(Limbs?.Limbs?.Length ?? 0);
for (int i = 0; i < Limbs.Limbs.Length; i++)
writer.Write(Limbs[i].Rotation);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
Projectile.rotation = reader.ReadSingle();
int limbCount = Limbs.Limbs.Length;
for (int i = 0; i < limbCount; i++)
{
Limbs[i].Rotation = reader.ReadDouble();
if (i >= 1)
Limbs[i].ConnectPoint = Limbs[i - 1].EndPoint;
}
}
public override void AI()
{
// Update limbs.
if (Main.myPlayer == Projectile.owner)
{
Vector2 connectPosition = Main.LocalPlayer.Center + ConnectOffset;
connectPosition.X += (OwnerRestingOffset.X > 0f).ToDirectionInt() * Projectile.scale * 20f;
Vector2 endPosition = Owner.Center + OwnerRestingOffset;
endPosition += (Main.MouseWorld - endPosition) * 0.075f;
ClampFirstLimbRotation(ref Limbs[0].Rotation);
Limbs.Update(connectPosition, endPosition);
Projectile.netSpam = 0;
Projectile.netUpdate = true;
}
Projectile.ai[1] = 0f;
Projectile.velocity = Vector2.Zero;
Projectile.Center = Limbs.EndPoint;
// Handle buffs.
Owner.AddBuff(ModContent.BuffType<ExoskeletonCannons>(), 3600);
if (Owner.dead)
Owner.Calamity().AresCannons = false;
if (Owner.Calamity().AresCannons)
Projectile.timeLeft = 2;
// Look at the mouse if not targetting anything.
// If something is being targeted, look at them instead.
float idealRotation = Main.myPlayer != Projectile.owner ? Projectile.rotation : Projectile.AngleTo(Main.MouseWorld);
NPC potentialTarget = Projectile.Center.ClosestNPCAt(AresExoskeleton.TargetingDistance);
if (potentialTarget != null)
{
Projectile.ai[1] = 1f;
idealRotation = Projectile.AngleTo(potentialTarget.Center);
if (UsesSuperpredictiveness)
idealRotation = CalamityUtils.CalculatePredictiveAimToTarget(Projectile.Center, potentialTarget, ShootSpeed).ToRotation();
ShootTimer++;
if (ShootTimer >= ShootRate)
{
ShootAtTarget(potentialTarget, idealRotation.ToRotationVector2());
ShootTimer = 0;
}
}
Projectile.rotation = Projectile.rotation.AngleLerp(idealRotation, 0.15f);
Projectile.spriteDirection = (Math.Cos(Projectile.rotation) > 0f).ToDirectionInt();
}
public void DefaultDrawCannon(Texture2D glowmask)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
Rectangle frame = texture.Frame(2, Main.projFrames[Type], TargetingSomething.ToInt(), Projectile.frame);
Vector2 origin = frame.Size() * 0.5f;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
float rotation = Projectile.rotation;
if (Projectile.spriteDirection == -1)
rotation += MathHelper.Pi;
DrawLimbs();
Color lightColor = Lighting.GetColor(Projectile.Center.ToTileCoordinates());
Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), rotation, origin, Projectile.scale, direction, 0);
Main.EntitySpriteDraw(glowmask, drawPosition, frame, Projectile.GetAlpha(Color.White), rotation, origin, Projectile.scale, direction, 0);
}
public void DrawLimbs()
{
// Draw the arms. Third and onward arms use the otherwise unused old Ares arm segment texture.
int frame = (int)(Main.GlobalTimeWrappedHourly * 8.1f) % 9;
for (int i = 0; i < Limbs.Limbs.Length; i++)
{
float scale = Projectile.scale;
float rotation = (float)Limbs[i].Rotation;
Vector2 segmentOriginFactor = new(0f, 0.5f);
SpriteEffects segmentDirection = SpriteEffects.FlipHorizontally;
Texture2D segmentTexture = ModContent.Request<Texture2D>("CalamityMod/NPCs/ExoMechs/Ares/AresArmSegment").Value;
Texture2D glowmaskTexture = null;
Rectangle segmentFrame = segmentTexture.Frame(1, 24, 0, (int)(Main.GlobalTimeWrappedHourly * 13f + i) % 24);
if (i == 0)
{
segmentTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ArmPart1").Value;
glowmaskTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ArmPart1Glowmask").Value;
}
if (i == 1)
{
segmentTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ArmPart2").Value;
glowmaskTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ArmPart2Glowmask").Value;
}
if (i <= 1)
{
segmentFrame = segmentTexture.Frame(1, 9, 0, frame);
segmentDirection = OwnerRestingOffset.X < 0f ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
if (OwnerRestingOffset.X < 0f)
{
segmentOriginFactor.X = 1f;
rotation += MathHelper.Pi;
}
}
else
scale *= 0.67f;
Color segmentColor = Lighting.GetColor(Limbs[i].ConnectPoint.ToTileCoordinates());
Vector2 segmentDrawPosition = Limbs[i].ConnectPoint - Main.screenPosition;
Main.spriteBatch.DrawLineBetter(Limbs[i].ConnectPoint, Limbs[i].EndPoint, Color.Cyan, 3f);
Main.EntitySpriteDraw(segmentTexture, segmentDrawPosition, segmentFrame, Projectile.GetAlpha(segmentColor), rotation, segmentFrame.Size() * segmentOriginFactor, scale, segmentDirection, 0);
if (glowmaskTexture != null)
Main.EntitySpriteDraw(glowmaskTexture, segmentDrawPosition, segmentFrame, Projectile.GetAlpha(Color.White), rotation, segmentFrame.Size() * segmentOriginFactor, scale, segmentDirection, 0);
}
// Draw the shoulders on top of everything else.
Vector2 shoulderPosition = Limbs.ConnectPoint + DrawOffset * Projectile.scale;
Color shoulderColor = Lighting.GetColor(Limbs.ConnectPoint.ToTileCoordinates());
Texture2D shoulderTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ArmTopShoulder").Value;
SpriteEffects shoulderDirection = OwnerRestingOffset.X < 0f ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Rectangle shoulderFrame = shoulderTexture.Frame(1, 9, 0, frame);
Main.EntitySpriteDraw(shoulderTexture, shoulderPosition - Main.screenPosition, shoulderFrame, Projectile.GetAlpha(shoulderColor), 0f, shoulderFrame.Size() * 0.5f, Projectile.scale, shoulderDirection, 0);
}
}
}
@@ -0,0 +1,142 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.Audio;
using Microsoft.Xna.Framework.Graphics;
using CalamityMod.Sounds;
using CalamityMod.Items.Weapons.Summon;
using System;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class ExoskeletonGaussNukeCannon : ExoskeletonCannon
{
public int NukeRebuildTime => ShootRate - 45;
public ref float RebuildTimer => ref Projectile.localAI[0];
public override int ShootRate => AresExoskeleton.GaussNukeShootRate;
public override float ShootSpeed => 16f;
public override Vector2 OwnerRestingOffset => HoverOffsetTable[HoverOffsetIndex];
public override void ClampFirstLimbRotation(ref double limbRotation) => limbRotation = RotationalClampTable[HoverOffsetIndex];
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Gauss Nuke");
Main.projFrames[Type] = 12;
}
public override void ShootAtTarget(NPC target, Vector2 shootDirection)
{
// Play the large gun fire sound.
SoundEngine.PlaySound(CommonCalamitySounds.LargeWeaponFireSound with { Volume = 0.4f }, Projectile.Center);
// Start the rebuild timer.
RebuildTimer = 1f;
// Shoot the fireball. This only happens for the owner client.
if (Main.myPlayer != Projectile.owner)
return;
int nukeID = ModContent.ProjectileType<MinionGaussNuke>();
Vector2 laserVelocity = shootDirection * ShootSpeed;
int laser = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, laserVelocity, nukeID, (int)(Projectile.damage * AresExoskeleton.NukeDamageFactor), 0f, Projectile.owner);
if (Main.projectile.IndexInRange(laser))
Main.projectile[laser].originalDamage = (int)(Projectile.originalDamage * AresExoskeleton.NukeDamageFactor);
}
public override void PostAI()
{
Projectile.frameCounter++;
Projectile.frame = Projectile.frameCounter / 5 % 6;
if (RebuildTimer >= 1f)
{
RebuildTimer++;
Projectile.frame += 6;
}
if (RebuildTimer >= NukeRebuildTime)
{
RebuildTimer = 0f;
Projectile.frameCounter = 0;
Projectile.frame = 0;
}
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
Texture2D glowmask = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCannonGlowmask").Value;
// The two stabilizers have two different shades of lighting, thus necessitating two different textures.
Texture2D stabilizer = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizer").Value;
Texture2D stabilizer2 = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeStabilizerBottom").Value;
Texture2D crystal = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCrystal").Value;
Texture2D core = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonGaussNukeCore").Value;
Rectangle frame = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame);
float stabilizerRotationInterpolant = (float)Math.Pow(Utils.GetLerpValue(NukeRebuildTime * 0.75f, NukeRebuildTime * 0.92f, RebuildTimer, true), 1.7);
Vector2 origin = frame.Size() * 0.5f;
Vector2 crystalOrigin = crystal.Size() * new Vector2(Projectile.spriteDirection == 1 ? 1f : 0f, 0.5f);
Vector2 stabilizerOrigin = stabilizer.Size() * new Vector2(0.5f, 1f);
Vector2 coreOrigin = core.Size() * new Vector2(Projectile.spriteDirection == 1 ? 0f : 1f, 0.5f);
Vector2 perpendicularStabilizerOffset = (Projectile.rotation + MathHelper.PiOver2).ToRotationVector2() * Projectile.scale * MathHelper.Lerp(18f, 10f, stabilizerRotationInterpolant);
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
float rotation = Projectile.rotation;
if (Projectile.spriteDirection == -1)
rotation += MathHelper.Pi;
DrawLimbs();
// Draw the nuke pieces when rebuilding. This is done before the cannon itself is drawn, to make it look like they're attached to it.
if (RebuildTimer >= 1f)
{
float componentDirection = rotation + MathHelper.Pi;
float stabilizerDirection = componentDirection;
if (Projectile.spriteDirection == -1)
stabilizerDirection += MathHelper.Pi;
Vector2 aimDirection = Projectile.rotation.ToRotationVector2();
// Draw the crystal.
float crystalOffsetInterpolant = Utils.GetLerpValue(0f, NukeRebuildTime * 0.5f, RebuildTimer, true);
Vector2 crystalOffset = aimDirection * crystalOffsetInterpolant * Projectile.scale * (crystal.Width - 15f);
Main.EntitySpriteDraw(crystal, drawPosition + crystalOffset, null, Projectile.GetAlpha(lightColor), rotation, crystalOrigin, Projectile.scale, direction, 0);
// Draw the stabilizers.
float stabilizerOffsetInterpolant = Utils.GetLerpValue(NukeRebuildTime * 0.5f, NukeRebuildTime * 0.75f, RebuildTimer, true);
float stabilizerOffsetMagnitude = MathHelper.Lerp(-stabilizer.Width * 0.32f, stabilizer.Width * 0.4f - 8f, stabilizerOffsetInterpolant) * Projectile.scale;
float leftStabilizerRotation = stabilizerDirection + MathHelper.Pi - (1f - stabilizerRotationInterpolant) * 0.42f;
float rightStabilizerRotation = stabilizerDirection + (1f - stabilizerRotationInterpolant) * 0.42f;
Vector2 stabilizerOffset = aimDirection * stabilizerOffsetMagnitude;
Color stabilizerColor = Projectile.GetAlpha(lightColor) * (float)Math.Pow(stabilizerOffsetInterpolant, 1.61);
Vector2 leftStabilizerPosition = drawPosition + stabilizerOffset - perpendicularStabilizerOffset * 0.9f;
Vector2 rightStabilizerPosition = drawPosition + stabilizerOffset + perpendicularStabilizerOffset;
SpriteEffects leftStabilizerDirection = direction;
SpriteEffects rightStabilizerDirection = direction ^ SpriteEffects.FlipHorizontally;
if (Projectile.spriteDirection == -1)
{
leftStabilizerDirection ^= SpriteEffects.FlipHorizontally;
rightStabilizerDirection ^= SpriteEffects.FlipHorizontally;
Utils.Swap(ref stabilizer, ref stabilizer2);
}
Main.EntitySpriteDraw(stabilizer, leftStabilizerPosition, null, stabilizerColor, leftStabilizerRotation, stabilizerOrigin, Projectile.scale, leftStabilizerDirection, 0);
Main.EntitySpriteDraw(stabilizer2, rightStabilizerPosition, null, stabilizerColor, rightStabilizerRotation, stabilizerOrigin, Projectile.scale, rightStabilizerDirection, 0);
// Draw the core.
Vector2 coreDrawPosition = drawPosition + aimDirection * Projectile.scale * -12f;
Main.EntitySpriteDraw(core, coreDrawPosition, null, Projectile.GetAlpha(lightColor) * stabilizerRotationInterpolant, rotation, coreOrigin, Projectile.scale, direction, 0);
}
Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), rotation, origin, Projectile.scale, direction, 0);
Main.EntitySpriteDraw(glowmask, drawPosition, frame, Projectile.GetAlpha(Color.White), rotation, origin, Projectile.scale, direction, 0);
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 395 B

@@ -0,0 +1,105 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.Audio;
using Microsoft.Xna.Framework.Graphics;
using CalamityMod.Sounds;
using CalamityMod.Items.Weapons.Summon;
using System.IO;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class ExoskeletonLaserCannon : ExoskeletonCannon
{
public ref float ShootCounter => ref Projectile.localAI[0];
// This is how many small, regular lasers will happen before the laser will charge up and prepare a laserbeam.
public const int NormalLasersBeforeBeam = 6;
public override int ShootRate => ShootCounter % NormalLasersBeforeBeam == 0f ? 150 : AresExoskeleton.LaserCannonNormalShootRate;
public override float ShootSpeed => 13.5f;
public override Vector2 OwnerRestingOffset => HoverOffsetTable[HoverOffsetIndex];
public override void ClampFirstLimbRotation(ref double limbRotation) => limbRotation = RotationalClampTable[HoverOffsetIndex];
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Laser Cannon");
Main.projFrames[Type] = 6;
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(ShootCounter);
base.SendExtraAI(writer);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
ShootCounter = reader.ReadSingle();
base.ReceiveExtraAI(reader);
}
public override void ShootAtTarget(NPC target, Vector2 shootDirection)
{
// Play the laser cannon fire sound.
SoundEngine.PlaySound(CommonCalamitySounds.LaserCannonSound with { Volume = 0.4f }, Projectile.Center);
// Create a burst of dust.
for (int i = 0; i < 24; i++)
{
Dust laserEnergy = Dust.NewDustPerfect(Projectile.Center + shootDirection * Projectile.width * Projectile.scale * 0.45f, 182);
laserEnergy.velocity = (MathHelper.TwoPi * i / 24f).ToRotationVector2() * 4f;
laserEnergy.scale = 1.1f;
laserEnergy.fadeIn = 0.4f;
laserEnergy.noGravity = true;
}
// Shoot the laser. This only happens for the owner client.
if (Main.myPlayer != Projectile.owner)
return;
int laserID = ModContent.ProjectileType<MinionLaserBurst>();
bool fireLaser = ShootCounter % NormalLasersBeforeBeam == NormalLasersBeforeBeam - 1f;
if (fireLaser)
laserID = ModContent.ProjectileType<CannonLaserbeam>();
Vector2 laserVelocity = shootDirection * ShootSpeed;
int laser = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, laserVelocity, laserID, Projectile.damage, 0f, Projectile.owner);
if (Main.projectile.IndexInRange(laser))
{
Main.projectile[laser].originalDamage = Projectile.originalDamage;
if (fireLaser)
Main.projectile[laser].ai[1] = Projectile.identity;
}
// Increment the shoot counter. This decides if the cannon fires a simple laser or a beam.
ShootCounter++;
Projectile.netUpdate = true;
}
// Create some charge dust before firing a laserbeam.
public override void PostAI()
{
Projectile.frameCounter++;
Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Type];
if (ShootCounter % NormalLasersBeforeBeam != NormalLasersBeforeBeam - 1f || !TargetingSomething)
return;
Vector2 aimDirection = Projectile.rotation.ToRotationVector2();
Dust laserEnergy = Dust.NewDustPerfect(Projectile.Center + aimDirection * Projectile.width * Projectile.scale * 0.51f, 182);
laserEnergy.velocity = aimDirection.RotatedByRandom(0.48f) * Main.rand.NextFloat(3f);
laserEnergy.scale = 1.1f;
laserEnergy.fadeIn = 0.4f;
laserEnergy.noGravity = true;
}
public override bool PreDraw(ref Color lightColor)
{
DefaultDrawCannon(ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonLaserCannonGlowmask").Value);
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

@@ -0,0 +1,369 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using CalamityMod.Items.Weapons.Summon;
using Terraria.GameContent;
using Terraria.Audio;
using System.Linq;
using System;
using System.Collections.Generic;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class ExoskeletonPanel : ModProjectile
{
public enum IconType
{
Inactive,
Plasma,
Tesla,
Laser,
Gauss
}
public class IconState
{
public int PanelFlashTimer;
public int MousePressFrameCountdown;
public bool BeingHoveredOver;
public bool PlacedInPanel;
public IconType CurrentState;
public Texture2D IconTexture
{
get
{
Texture2D plasmaTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonPanelPlasma").Value;
Texture2D teslaTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonPanelTesla").Value;
Texture2D laserTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonPanelLaser").Value;
Texture2D gaussTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonPanelGauss").Value;
return CurrentState switch
{
IconType.Plasma => plasmaTexture,
IconType.Tesla => teslaTexture,
IconType.Laser => laserTexture,
IconType.Gauss => gaussTexture,
_ => null,
};
}
}
public Rectangle Frame
{
get
{
int frame = 0;
if (BeingHoveredOver)
frame = PlacedInPanel ? 3 : 1;
if (MousePressFrameCountdown >= 1)
frame = 2;
if (PanelFlashTimer >= 1)
frame = (int)Math.Round(MathHelper.Lerp(4f, 6f, PanelFlashTimer / 16f));
return IconTexture?.Frame(1, 7, 0, frame) ?? default;
}
}
public IconState(bool hover, bool panel, IconType state)
{
BeingHoveredOver = hover;
PlacedInPanel = panel;
CurrentState = state;
}
public void Update()
{
if (PanelFlashTimer >= 1)
PanelFlashTimer++;
if (PanelFlashTimer >= 16)
PanelFlashTimer = 0;
if (MousePressFrameCountdown > 0)
MousePressFrameCountdown--;
}
}
public IconType ClickedIcon = IconType.Inactive;
public IconState[] SelectionIcons = new IconState[]
{
new(false, false, IconType.Plasma),
new(false, false, IconType.Tesla),
new(false, false, IconType.Laser),
new(false, false, IconType.Gauss),
};
public IconState[] PanelIcons = new IconState[]
{
new(false, true, IconType.Inactive),
new(false, true, IconType.Inactive),
new(false, true, IconType.Inactive),
new(false, true, IconType.Inactive),
};
public bool ShouldDeleteArmIndex = false;
public int ArmIDToSpawn = -1;
public int ArmIndex = -1;
public bool FadeOut => Projectile.ai[0] == 1f;
public Vector2 PlayerOffset;
public ref float Time => ref Projectile.ai[1];
public static Rectangle MouseRectangle => new((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 2, 2);
public override void SetStaticDefaults()
{
DisplayName.SetDefault("UI");
ProjectileID.Sets.DrawScreenCheckFluff[Type] = 9999999;
}
public override void SetDefaults()
{
Projectile.width = 40;
Projectile.height = 40;
Projectile.penetrate = -1;
Projectile.ignoreWater = true;
Projectile.timeLeft = 36000;
Projectile.Opacity = 0f;
Projectile.tileCollide = false;
Projectile.hide = true;
}
public override void AI()
{
int plasmaCannonID = ModContent.ProjectileType<ExoskeletonPlasmaCannon>();
int teslaCannonID = ModContent.ProjectileType<ExoskeletonTeslaCannon>();
int laserCannonID = ModContent.ProjectileType<ExoskeletonLaserCannon>();
int gaussNukeID = ModContent.ProjectileType<ExoskeletonGaussNukeCannon>();
int[] arms = new int[]
{
plasmaCannonID,
teslaCannonID,
laserCannonID,
gaussNukeID,
};
// Initialize things.
if (PlayerOffset == Vector2.Zero)
PlayerOffset = Main.MouseWorld - Main.LocalPlayer.Center;
// Dynamically update panel icons.
for (int i = 0; i < 4; i++)
PanelIcons[i].CurrentState = IconType.Inactive;
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (!arms.Contains(Main.projectile[i].type) || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].active)
continue;
IconType stateFromID = IconType.Inactive;
if (Main.projectile[i].type == plasmaCannonID)
stateFromID = IconType.Plasma;
if (Main.projectile[i].type == teslaCannonID)
stateFromID = IconType.Tesla;
if (Main.projectile[i].type == laserCannonID)
stateFromID = IconType.Laser;
if (Main.projectile[i].type == gaussNukeID)
stateFromID = IconType.Gauss;
PanelIcons[(int)Main.projectile[i].ai[0]].CurrentState = stateFromID;
}
// Handle fade effects.
if (Time >= AresExoskeleton.BoxParticleLifetime)
Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity - FadeOut.ToDirectionInt() * 0.0225f, 0f, 1f);
if (FadeOut && Projectile.Opacity <= 0f)
Projectile.Kill();
if (Main.player[Projectile.owner].dead || !Main.player[Projectile.owner].active)
Projectile.Kill();
Time++;
// Create and destroy arms as necessary.
if (Main.myPlayer != Projectile.owner)
return;
if (ArmIDToSpawn >= 0)
{
bool armAlreadyExists = false;
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (!arms.Contains(Main.projectile[i].type) || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].active || Main.projectile[i].ai[0] != ArmIndex)
continue;
armAlreadyExists = true;
break;
}
if (!armAlreadyExists)
{
SoundEngine.PlaySound(SoundID.Zombie66, Projectile.Center);
int cannon = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, Vector2.Zero, ArmIDToSpawn, Projectile.damage, 0f, Projectile.owner, ArmIndex);
if (Main.projectile.IndexInRange(cannon))
Main.projectile[cannon].originalDamage = Projectile.originalDamage;
}
}
if (ShouldDeleteArmIndex)
{
SoundEngine.PlaySound(SoundID.Item74, Projectile.Center);
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (!arms.Contains(Main.projectile[i].type) || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].active || Main.projectile[i].ai[0] != ArmIndex)
continue;
Main.projectile[i].Kill();
}
}
ShouldDeleteArmIndex = false;
ArmIDToSpawn = -1;
ArmIndex = -1;
}
public override bool PreDraw(ref Color lightColor)
{
// This UI only renders for the player that created it.
if (Main.myPlayer != Projectile.owner)
return false;
Texture2D panelTexture = ModContent.Request<Texture2D>(Texture).Value;
Texture2D plasmaTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonPanelPlasma").Value;
Texture2D arrowTexture = ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/Arrow").Value;
Vector2 area = plasmaTexture.Frame(1, 7, 0, 0).Size();
Vector2 drawPosition = (Main.LocalPlayer.Center + PlayerOffset - Main.screenPosition).Floor();
Rectangle[] selectionIconAreas = new Rectangle[4]
{
Utils.CenteredRectangle(drawPosition + new Vector2(-62f, -70f) * Projectile.scale, area * Projectile.scale),
Utils.CenteredRectangle(drawPosition + new Vector2(-22f, -70f) * Projectile.scale, area * Projectile.scale),
Utils.CenteredRectangle(drawPosition + new Vector2(22f, -70f) * Projectile.scale, area * Projectile.scale),
Utils.CenteredRectangle(drawPosition + new Vector2(62f, -70f) * Projectile.scale, area * Projectile.scale)
};
bool hoveringOverAnySlot = false;
bool clickedAnIconOnPanel = false;
bool sufficientSlots = Main.LocalPlayer.maxMinions > AresExoskeleton.MinionSlotsPerCannon;
// Draw icon and handle hover behaviors.
// If an arm needs to be destroyed or spawned, it will happen on the next frame in the AI update loop.
for (int i = 0; i < 4; i++)
{
Texture2D selectionIconTexture = SelectionIcons[i].IconTexture;
// Handle selection icon click stuff.
SelectionIcons[i].BeingHoveredOver = false;
PanelIcons[i].BeingHoveredOver = false;
if (selectionIconAreas[i].Intersects(MouseRectangle))
{
hoveringOverAnySlot = true;
SelectionIcons[i].BeingHoveredOver = true;
if (Main.mouseLeft && Main.mouseLeftRelease && Projectile.Opacity >= 1f)
{
ClickedIcon = SelectionIcons[i].CurrentState;
SelectionIcons[i].MousePressFrameCountdown = 15;
}
}
// Handle panel icon click stuff.
Rectangle panelArea = selectionIconAreas[i];
panelArea.Y += (int)(Projectile.scale * 78f);
if (panelArea.Intersects(MouseRectangle))
{
hoveringOverAnySlot = true;
PanelIcons[i].BeingHoveredOver = true;
if (Main.mouseLeft && Main.mouseLeftRelease && Projectile.Opacity >= 1f && sufficientSlots)
{
clickedAnIconOnPanel = true;
PanelIcons[i].CurrentState = ClickedIcon;
PanelIcons[i].PanelFlashTimer = 1;
switch (ClickedIcon)
{
case IconType.Plasma:
ArmIDToSpawn = ModContent.ProjectileType<ExoskeletonPlasmaCannon>();
break;
case IconType.Tesla:
ArmIDToSpawn = ModContent.ProjectileType<ExoskeletonTeslaCannon>();
break;
case IconType.Laser:
ArmIDToSpawn = ModContent.ProjectileType<ExoskeletonLaserCannon>();
break;
case IconType.Gauss:
ArmIDToSpawn = ModContent.ProjectileType<ExoskeletonGaussNukeCannon>();
break;
case IconType.Inactive:
ShouldDeleteArmIndex = true;
PanelIcons[i].PanelFlashTimer = 0;
break;
}
ArmIndex = i;
}
}
Main.EntitySpriteDraw(selectionIconTexture, selectionIconAreas[i].Center.ToVector2(), SelectionIcons[i].Frame, Projectile.GetAlpha(Color.White), 0f, area * 0.5f, Projectile.scale, 0, 0);
}
Main.EntitySpriteDraw(panelTexture, drawPosition, null, Projectile.GetAlpha(Color.White), 0f, panelTexture.Size() * 0.5f, Projectile.scale, 0, 0);
// Draw panel icons.
for (int i = 0; i < 4; i++)
{
Rectangle panelArea = selectionIconAreas[i];
panelArea.Y += (int)(Projectile.scale * 78f);
Texture2D panelIconTexture = PanelIcons[i].IconTexture;
if (panelIconTexture is not null)
Main.EntitySpriteDraw(panelIconTexture, panelArea.Center.ToVector2(), PanelIcons[i].Frame, Projectile.GetAlpha(Color.White), 0f, area * 0.5f, Projectile.scale, 0, 0);
SelectionIcons[i].Update();
PanelIcons[i].Update();
}
// Draw an arrow at the mouse from the selected icon if one has been selected.
if (ClickedIcon != IconType.Inactive)
{
Vector2 arrowDrawPosition = selectionIconAreas[(int)ClickedIcon - 1].Center.ToVector2();
Vector2 arrowDirection = (Main.MouseScreen - arrowDrawPosition).SafeNormalize(Vector2.UnitY);
arrowDrawPosition += arrowDirection * Projectile.scale * 24f;
Main.EntitySpriteDraw(arrowTexture, arrowDrawPosition, null, Projectile.GetAlpha(Color.White), arrowDirection.ToRotation(), arrowTexture.Size() * 0.5f, Projectile.scale, 0, 0);
}
// Tell the player if they don't have enough summon slots.
if (hoveringOverAnySlot && !sufficientSlots)
Utils.DrawBorderStringFourWay(Main.spriteBatch, FontAssets.MouseText.Value, "Insufficient minion slots!", Main.MouseScreen.X + 20f, Main.MouseScreen.Y + 12f, Color.Cyan, Color.Black, new Vector2(0f, 0.5f));
// Reset the clicked icon if a click is made but not to a specific icon.
if (!hoveringOverAnySlot && Main.mouseLeft && Main.mouseLeftRelease)
ClickedIcon = IconType.Inactive;
if (hoveringOverAnySlot)
{
Main.blockMouse = true;
Main.LocalPlayer.mouseInterface = true;
}
// Reset the clicked icon and handle the arm creation/deletion if an icon was clicked on the panel.
if (clickedAnIconOnPanel)
ClickedIcon = IconType.Inactive;
return false;
}
public override void DrawBehind(int index, List<int> behindNPCsAndTiles, List<int> behindNPCs, List<int> behindProjectiles, List<int> overPlayers, List<int> overWiresUI)
{
overWiresUI.Add(index);
}
// This is a UI. It should not do damage.
public override bool? CanDamage() => false;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

@@ -0,0 +1,93 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.Audio;
using Microsoft.Xna.Framework.Graphics;
using CalamityMod.Items.Weapons.DraedonsArsenal;
using CalamityMod.Items.Weapons.Summon;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class ExoskeletonPlasmaCannon : ExoskeletonCannon
{
public override int ShootRate => AresExoskeleton.PlasmaCannonShootRate;
public override float ShootSpeed => 13.5f;
public override Vector2 OwnerRestingOffset => HoverOffsetTable[HoverOffsetIndex];
public override void ClampFirstLimbRotation(ref double limbRotation) => limbRotation = RotationalClampTable[HoverOffsetIndex];
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Plasma Cannon");
Main.projFrames[Type] = 6;
}
public override void PostAI()
{
Projectile.frameCounter++;
Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Type];
}
public override void ShootAtTarget(NPC target, Vector2 shootDirection)
{
// Play the plasma caster fire sound.
SoundEngine.PlaySound(PlasmaCaster.FireSound with { Volume = 0.4f }, Projectile.Center);
// Create a burst of dust.
for (int i = 0; i < 40; i++)
{
float dustSpeed = Main.rand.NextFloat(1.8f, 3f);
Vector2 dustVel = shootDirection * dustSpeed;
dustVel = dustVel.RotatedBy(-0.35f);
dustVel = dustVel.RotatedByRandom(2.0f * 0.35f);
int randomDustType = Main.rand.NextBool(2) ? 107 : 110;
Dust plasma = Dust.NewDustDirect(Projectile.TopLeft, Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 200, default, 1.7f);
plasma.position = Projectile.Center + Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * (float)Main.rand.NextDouble() * Projectile.width / 4f;
plasma.position += shootDirection * 60f;
plasma.noGravity = true;
plasma.velocity *= Projectile.scale * 1.6f;
plasma = Dust.NewDustDirect(Projectile.TopLeft, Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 100, default, 0.8f);
plasma.position = Projectile.Center + Vector2.UnitY.RotatedByRandom(MathHelper.Pi) * (float)Main.rand.NextDouble() * Projectile.width / 4f;
plasma.position += shootDirection * 60f;
plasma.velocity *= Projectile.scale * 0.9f;
plasma.noGravity = true;
plasma.fadeIn = 1f;
plasma.color = Color.Green * 0.5f;
}
for (int i = 0; i < 20; i++)
{
float dustSpeed = Main.rand.NextFloat(1.8f, 3f);
Vector2 dustVel = shootDirection * dustSpeed;
dustVel = dustVel.RotatedBy(-0.35f);
dustVel = dustVel.RotatedByRandom(2.0f * 0.35f);
int randomDustType = Main.rand.NextBool(2) ? 107 : 110;
Dust plasma = Dust.NewDustDirect(Projectile.TopLeft, Projectile.width, Projectile.height, randomDustType, dustVel.X, dustVel.Y, 0, default, 2f);
plasma.position = Projectile.Center + Vector2.UnitX.RotatedByRandom(MathHelper.Pi).RotatedBy(shootDirection.ToRotation()) * Projectile.width / 5f;
plasma.position += shootDirection * 60f;
plasma.noGravity = true;
plasma.velocity *= Projectile.scale * 0.27f;
}
// Shoot the fireball. This only happens for the owner client.
if (Main.myPlayer != Projectile.owner)
return;
Vector2 fireballVelocity = shootDirection * ShootSpeed;
int fireball = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, fireballVelocity, ModContent.ProjectileType<MinionPlasmaBlast>(), Projectile.damage, 0f, Projectile.owner);
if (Main.projectile.IndexInRange(fireball))
Main.projectile[fireball].originalDamage = Projectile.originalDamage;
}
public override bool PreDraw(ref Color lightColor)
{
DefaultDrawCannon(ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonPlasmaCannonGlowmask").Value);
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@@ -0,0 +1,67 @@
using CalamityMod.Sounds;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.Audio;
using Microsoft.Xna.Framework.Graphics;
using CalamityMod.Items.Weapons.Summon;
using System.IO;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class ExoskeletonTeslaCannon : ExoskeletonCannon
{
public ref float TeslaOrbIndex => ref Projectile.localAI[0];
public override int ShootRate => AresExoskeleton.TeslaCannonShootRate;
public override float ShootSpeed => 12f;
public override bool UsesSuperpredictiveness => true;
public override Vector2 OwnerRestingOffset => HoverOffsetTable[HoverOffsetIndex];
public override void ClampFirstLimbRotation(ref double limbRotation) => limbRotation = RotationalClampTable[HoverOffsetIndex];
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Tesla Cannon");
Main.projFrames[Type] = 6;
}
public override void SendExtraAI(BinaryWriter writer) => writer.Write(TeslaOrbIndex);
public override void ReceiveExtraAI(BinaryReader reader) => TeslaOrbIndex = reader.ReadSingle();
public override void PostAI()
{
Projectile.frameCounter++;
Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Type];
}
public override void ShootAtTarget(NPC target, Vector2 shootDirection)
{
// Play the plasma bolt fire sound.
SoundEngine.PlaySound(CommonCalamitySounds.PlasmaBoltSound with { Volume = 0.4f }, Projectile.Center);
// Shoot the tesla orb. This only happens for the owner client.
if (Main.myPlayer != Projectile.owner)
return;
int damage = (int)(Projectile.damage * AresExoskeleton.TeslaOrbDamageFactor);
Vector2 teslaOrbVelocity = shootDirection * ShootSpeed;
int teslaOrb = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, teslaOrbVelocity, ModContent.ProjectileType<MinionTeslaOrb>(), damage, 0f, Projectile.owner);
if (Main.projectile.IndexInRange(teslaOrb))
{
Main.projectile[teslaOrb].originalDamage = (int)(Projectile.originalDamage * AresExoskeleton.TeslaOrbDamageFactor);
Main.projectile[teslaOrb].ai[0] = TeslaOrbIndex++ % 6;
}
}
public override bool PreDraw(ref Color lightColor)
{
DefaultDrawCannon(ModContent.Request<Texture2D>("CalamityMod/Projectiles/Summon/SmallAresArms/ExoskeletonTeslaCannonGlowmask").Value);
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@@ -0,0 +1,34 @@
using CalamityMod.Projectiles.BaseProjectiles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class MinionGaussBoom : BaseMassiveExplosionProjectile
{
public override int Lifetime => 60;
// No screenshake is used for the sake of gameplay convenience.
public override bool UsesScreenshake => false;
public override float GetScreenshakePower(float pulseCompletionRatio) => 0f;
public override Color GetCurrentExplosionColor(float pulseCompletionRatio) => Color.Lerp(Color.Yellow * 1.6f, Color.White, MathHelper.Clamp(pulseCompletionRatio * 2.2f, 0f, 1f));
public override void SetStaticDefaults() => DisplayName.SetDefault("Gauss Hyperexplosion");
public override void SetDefaults()
{
Projectile.width = Projectile.height = 2;
Projectile.friendly = true;
Projectile.tileCollide = false;
Projectile.penetrate = -1;
Projectile.timeLeft = Lifetime;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.DamageType = DamageClass.Summon;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 12;
}
public override void PostAI() => Lighting.AddLight(Projectile.Center, 0.2f, 0.1f, 0f);
}
}
@@ -0,0 +1,59 @@
using CalamityMod.Items.Weapons.DraedonsArsenal;
using CalamityMod.Items.Weapons.Summon;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class MinionGaussNuke : ModProjectile
{
public override void SetStaticDefaults() => DisplayName.SetDefault("Gauss Nuke");
public override void SetDefaults()
{
Projectile.width = Projectile.height = 76;
Projectile.penetrate = -1;
Projectile.tileCollide = true;
Projectile.timeLeft = 180;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.DamageType = DamageClass.Summon;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 12;
}
public override void AI()
{
// Handle rotation.
Projectile.rotation = Projectile.velocity.ToRotation();
// Home towards targets.
NPC potentialTarget = Projectile.Center.ClosestNPCAt(960f, false);
if (potentialTarget != null)
Projectile.velocity = Projectile.SuperhomeTowardsTarget(potentialTarget, 23f, 10f);
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
Projectile.Kill();
}
public override void Kill(int timeLeft)
{
SoundEngine.PlaySound(TeslaCannon.FireSound, Projectile.Center);
if (Main.myPlayer == Projectile.owner)
{
int boom = Projectile.NewProjectile(Projectile.GetSource_Death(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType<MinionGaussBoom>(), Projectile.damage, Projectile.knockBack, Projectile.owner);
if (Main.projectile.IndexInRange(boom))
{
Main.projectile[boom].ai[1] = AresExoskeleton.MaxNukeExplosionRadius;
Main.projectile[boom].originalDamage = Projectile.originalDamage;
}
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

@@ -0,0 +1,61 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class MinionLaserBurst : ModProjectile
{
public override string Texture => "CalamityMod/Projectiles/Boss/ThanatosLaser";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Exothermal Laser");
Main.projFrames[Type] = 4;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 32;
Projectile.height = 32;
Projectile.friendly = true;
Projectile.penetrate = -1;
Projectile.tileCollide = true;
Projectile.netImportant = true;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.timeLeft = 420;
Projectile.Opacity = 0f;
Projectile.DamageType = DamageClass.Summon;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 12;
}
public override void AI()
{
// Accelerate.
if (Projectile.velocity.Length() < 27f)
Projectile.velocity *= 1.024f;
// Fade in.
Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity + 0.12f, 0f, 1f);
// Handle frames and rotation.
Projectile.frameCounter++;
Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type];
Projectile.rotation = Projectile.velocity.ToRotation();
}
public override bool PreDraw(ref Color lightColor)
{
lightColor.R = (byte)(255 * Projectile.Opacity);
lightColor.G = (byte)(255 * Projectile.Opacity);
lightColor.B = (byte)(255 * Projectile.Opacity);
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1);
return false;
}
}
}
@@ -0,0 +1,83 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.Audio;
using Terraria.ID;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class MinionPlasmaBlast : ModProjectile
{
public override string Texture => "CalamityMod/Projectiles/Boss/AresPlasmaFireball";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Volatile Plasma Blast");
Main.projFrames[Type] = 6;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 36;
Projectile.height = 36;
Projectile.friendly = true;
Projectile.penetrate = 1;
Projectile.tileCollide = true;
Projectile.netImportant = true;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.timeLeft = 420;
Projectile.Opacity = 0f;
Projectile.DamageType = DamageClass.Summon;
}
public override void AI()
{
// Accelerate.
if (Projectile.velocity.Length() < 23f)
Projectile.velocity *= 1.0175f;
// Fade in.
Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity + 0.06667f, 0f, 1f);
// Handle frames and rotation.
Projectile.frameCounter++;
Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type];
Projectile.rotation = Projectile.velocity.ToRotation() - MathHelper.PiOver2;
// Home towards targets.
NPC potentialTarget = Projectile.Center.ClosestNPCAt(900f, false);
if (potentialTarget != null)
Projectile.velocity = Projectile.SuperhomeTowardsTarget(potentialTarget, 23f, 10f);
}
public override void Kill(int timeLeft)
{
SoundEngine.PlaySound(SoundID.Item93, Projectile.Center);
// Release a spread of plasma gas.
if (Main.netMode != NetmodeID.MultiplayerClient && Projectile.ai[1] != -1f)
{
int type = ModContent.ProjectileType<MinionPlasmaGas>();
for (int i = 0; i < 15; i++)
{
Vector2 plasmaVelocity = Main.rand.NextVector2Circular(5f, 5f);
int gas = Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center, plasmaVelocity, type, Projectile.damage, 0f, Main.myPlayer);
if (Main.projectile.IndexInRange(gas))
Main.projectile[gas].originalDamage = Projectile.originalDamage;
}
}
}
public override bool PreDraw(ref Color lightColor)
{
lightColor.R = (byte)(255 * Projectile.Opacity);
lightColor.G = (byte)(255 * Projectile.Opacity);
lightColor.B = (byte)(255 * Projectile.Opacity);
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1);
return false;
}
}
}
@@ -0,0 +1,67 @@
using CalamityMod.DataStructures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.GameContent;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class MinionPlasmaGas : ModProjectile, IAdditiveDrawer
{
public ref float LightPower => ref Projectile.ai[0];
public ref float Time => ref Projectile.ai[1];
public override void SetStaticDefaults() => DisplayName.SetDefault("Superheated Plasma Cloud");
public override void SetDefaults()
{
Projectile.width = Projectile.height = 50;
Projectile.penetrate = -1;
Projectile.tileCollide = false;
Projectile.timeLeft = 150;
Projectile.scale = 1.5f;
Projectile.hide = true;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.DamageType = DamageClass.Summon;
Projectile.usesIDStaticNPCImmunity = true;
Projectile.idStaticNPCHitCooldown = 12;
}
public override void AI()
{
// Decide scale and initial rotation on the first frame this projectile exists.
if (Projectile.localAI[0] == 0f)
{
Projectile.scale = Main.rand.NextFloat(1f, 1.7f);
Projectile.rotation = Main.rand.NextFloat(MathHelper.TwoPi);
Projectile.localAI[0] = 1f;
}
// Calculate light power. This checks below the position of the fog to check if this fog is underground.
// Without this, it may render over the fullblack that the game renders for obscured tiles.
float lightPowerBelow = Lighting.GetColor((int)Projectile.Center.X / 16, (int)Projectile.Center.Y / 16 + 6).ToVector3().Length() / (float)Math.Sqrt(3D);
LightPower = MathHelper.Lerp(LightPower, lightPowerBelow, 0.15f);
Projectile.Opacity = Utils.GetLerpValue(0f, 15f, Time, true) * Utils.GetLerpValue(0f, 60f, Projectile.timeLeft, true);
Projectile.rotation += Projectile.velocity.X * 0.004f;
Projectile.velocity *= 0.97f;
Time++;
}
public void AdditiveDraw(SpriteBatch spriteBatch)
{
Texture2D texture = TextureAssets.Projectile[Projectile.type].Value;
Vector2 origin = texture.Size() * 0.5f;
Vector2 drawPosition = Projectile.Center - Main.screenPosition;
float opacity = Utils.GetLerpValue(0f, 0.08f, LightPower, true) * Projectile.Opacity * 0.6f;
Color drawColor = new Color(141, 255, 105) * opacity;
Vector2 scale = Projectile.Size / texture.Size() * Projectile.scale * 1.35f;
spriteBatch.Draw(texture, drawPosition, null, drawColor, Projectile.rotation, origin, scale, SpriteEffects.None, 0f);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

@@ -0,0 +1,151 @@
using CalamityMod.Items.Weapons.Summon;
using CalamityMod.Projectiles.Boss;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Summon.SmallAresArms
{
public class MinionTeslaOrb : ModProjectile
{
public ref float Identity => ref Projectile.ai[0];
public ref float Time => ref Projectile.ai[1];
public PrimitiveTrail LightningDrawer;
public PrimitiveTrail LightningBackgroundDrawer;
public override string Texture => "CalamityMod/Projectiles/Boss/AresTeslaOrb";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Tesla Sphere");
Main.projFrames[Projectile.type] = 4;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 10000;
}
public override void SetDefaults()
{
Projectile.width = 32;
Projectile.height = 32;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.tileCollide = false;
Projectile.penetrate = -1;
Projectile.minion = true;
Projectile.minionSlots = 0f;
Projectile.timeLeft = 420;
Projectile.Opacity = 0f;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 35;
Projectile.DamageType = DamageClass.Summon;
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(Projectile.localAI[0]);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
Projectile.localAI[0] = reader.ReadSingle();
}
public override void AI()
{
// Accelerate.
if (Projectile.velocity.Length() < 21f)
Projectile.velocity *= 1.012f;
// Handle fade effects.
Projectile.Opacity = Utils.GetLerpValue(0f, 4f, Time, true) * Utils.GetLerpValue(0f, 15f, Projectile.timeLeft, true);
// Emit electric light.
Lighting.AddLight(Projectile.Center, 0.1f * Projectile.Opacity, 0.25f * Projectile.Opacity, 0.25f * Projectile.Opacity);
// Handle frames.
Projectile.frameCounter++;
Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Projectile.type];
Time++;
}
public Projectile GetOrbToAttachTo()
{
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (Main.projectile[i].type != Projectile.type || Main.projectile[i].ai[0] != Identity + 1f || !Main.projectile[i].active)
continue;
if (!Main.projectile[i].WithinRange(Projectile.Center, AresExoskeleton.TeslaOrbDetatchDistance))
continue;
return Main.projectile[i];
}
return null;
}
internal float WidthFunction(float completionRatio)
{
return MathHelper.Lerp(0.75f, 1.85f, (float)Math.Sin(MathHelper.Pi * completionRatio)) * Projectile.scale;
}
internal Color ColorFunction(float completionRatio)
{
float fadeToWhite = MathHelper.Lerp(0f, 0.65f, (float)Math.Sin(MathHelper.TwoPi * completionRatio + Main.GlobalTimeWrappedHourly * 4f) * 0.5f + 0.5f);
Color baseColor = Color.Lerp(Color.Cyan, Color.White, fadeToWhite);
return Color.Lerp(baseColor, Color.LightBlue, ((float)Math.Sin(MathHelper.Pi * completionRatio + Main.GlobalTimeWrappedHourly * 4f) * 0.5f + 0.5f) * 0.8f) * Projectile.Opacity;
}
internal float BackgroundWidthFunction(float completionRatio) => WidthFunction(completionRatio) * 4f;
internal Color BackgroundColorFunction(float completionRatio)
{
Color color = Color.CornflowerBlue * Projectile.Opacity * 0.4f;
return color;
}
public override bool PreDraw(ref Color lightColor)
{
if (LightningDrawer is null)
LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
if (LightningBackgroundDrawer is null)
LightningBackgroundDrawer = new PrimitiveTrail(BackgroundWidthFunction, BackgroundColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
Projectile orbToAttachTo = GetOrbToAttachTo();
if (orbToAttachTo != null)
{
List<Vector2> arcPoints = AresTeslaOrb.DetermineElectricArcPoints(Projectile.Center, orbToAttachTo.Center, 117);
LightningBackgroundDrawer.Draw(arcPoints, -Main.screenPosition, 90);
LightningDrawer.Draw(arcPoints, -Main.screenPosition, 90);
}
lightColor.R = (byte)(255 * Projectile.Opacity);
lightColor.G = (byte)(255 * Projectile.Opacity);
lightColor.B = (byte)(255 * Projectile.Opacity);
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1);
return false;
}
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
{
if (projHitbox.Intersects(targetHitbox))
return true;
float _ = 0f;
Projectile orbToAttachTo = GetOrbToAttachTo();
if (orbToAttachTo != null && Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Projectile.Center, orbToAttachTo.Center, 8f, ref _))
return true;
return false;
}
}
}
+8
View File
@@ -199,6 +199,14 @@ namespace CalamityMod
return dividend - (float)Math.Floor(dividend / divisor) * divisor;
}
/// <summary>
/// Clamps the magnitude of a vector via safe normalization.
/// </summary>
/// <param name="v">The vector.</param>
/// <param name="min">The minimum magnitude.</param>
/// <param name="max">The maximum magnitude.</param>
public static Vector2 ClampMagnitude(this Vector2 v, float min, float max) => v.SafeNormalize(Vector2.UnitY) * MathHelper.Clamp(v.Length(), min, max);
#region Easings
/// <summary>
/// Gets a value from 0 to 1 and returns an eased value.