Added the Cart of Gods

This commit is contained in:
Dominic authored and Cameron Ewell committed 2021-09-11 12:32:30 -04:00
1 parent 352004e989
commit cd372711e9
11 files changed
+287

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
using CalamityMod.Items.Mounts;
using CalamityMod.Items.Mounts.Minecarts;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Buffs.Mounts
{
public class DoGCartBuff : ModBuff
{
public override void SetDefaults()
{
DisplayName.SetDefault("Devourer Cart");
Description.SetDefault("Riding a cosmic terror");
Main.buffNoTimeDisplay[Type] = true;
Main.buffNoSave[Type] = true;
}
public override void Update(Player player, ref int buffIndex)
{
player.mount.SetMount(ModContent.MountType<DoGCartMount>(), player);
player.buffTime[buffIndex] = 10;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

+3
View File
@@ -13,6 +13,7 @@ using CalamityMod.Items.Armor;
using CalamityMod.Items.DifficultyItems;
using CalamityMod.Items.Dyes;
using CalamityMod.Items.Mounts;
using CalamityMod.Items.Mounts.Minecarts;
using CalamityMod.Items.Tools;
using CalamityMod.Items.TreasureBags;
using CalamityMod.Items.Weapons.Melee;
@@ -135,6 +136,8 @@ namespace CalamityMod.CalPlayer
public float blazingMouseAuraFade = 0f;
public float GeneralScreenShakePower = 0f;
public bool GivenBrimstoneLocus = false;
public DoGCartSegment[] DoGCartSegments = new DoGCartSegment[DoGCartMount.SegmentCount];
public float SmoothenedMinecartRotation;
#endregion
#region Tile Entity Trackers
+41
View File
@@ -5,6 +5,7 @@ using CalamityMod.Buffs.Potions;
using CalamityMod.Buffs.StatBuffs;
using CalamityMod.Buffs.StatDebuffs;
using CalamityMod.Buffs.Summon;
using CalamityMod.DataStructures;
using CalamityMod.Dusts;
using CalamityMod.Events;
using CalamityMod.Items;
@@ -13,6 +14,7 @@ using CalamityMod.Items.Armor;
using CalamityMod.Items.Fishing.AstralCatches;
using CalamityMod.Items.Fishing.BrimstoneCragCatches;
using CalamityMod.Items.Fishing.FishingRods;
using CalamityMod.Items.Mounts.Minecarts;
using CalamityMod.Items.Potions;
using CalamityMod.Items.Potions.Alcohol;
using CalamityMod.Items.Weapons.Melee;
@@ -498,6 +500,45 @@ namespace CalamityMod.CalPlayer
}
}
// Calculate/reset DoG cart rotations based on whether the DoG cart is in use.
if (player.mount.Active && player.mount.Type == ModContent.MountType<DoGCartMount>())
{
modPlayer.SmoothenedMinecartRotation = MathHelper.Lerp(modPlayer.SmoothenedMinecartRotation, DelegateMethods.Minecart.rotation, 0.05f);
// Initialize segments from null if necessary.
int direction = (player.velocity.SafeNormalize(Vector2.UnitX * player.direction).X > 0f).ToDirectionInt();
if (player.velocity.X == 0f)
direction = player.direction;
float idealRotation = DoGCartMount.CalculateIdealWormRotation(player);
float minecartRotation = DelegateMethods.Minecart.rotation;
if (Math.Abs(minecartRotation) < 0.5f)
minecartRotation = 0f;
Vector2 stickOffset = minecartRotation.ToRotationVector2() * player.velocity.Length() * direction * 1.25f;
for (int i = 0; i < modPlayer.DoGCartSegments.Length; i++)
{
if (modPlayer.DoGCartSegments[i] is null)
{
modPlayer.DoGCartSegments[i] = new DoGCartSegment
{
Center = player.Center - idealRotation.ToRotationVector2() * i * 20f
};
}
}
Vector2 startingStickPosition = player.Center + stickOffset + Vector2.UnitY * 12f;
modPlayer.DoGCartSegments[0].Update(player, startingStickPosition, idealRotation);
modPlayer.DoGCartSegments[0].Center = startingStickPosition;
for (int i = 1; i < modPlayer.DoGCartSegments.Length; i++)
{
Vector2 waveOffset = DoGCartMount.CalculateSegmentWaveOffset(i, player);
modPlayer.DoGCartSegments[i].Update(player, modPlayer.DoGCartSegments[i - 1].Center + waveOffset, modPlayer.DoGCartSegments[i - 1].Rotation);
}
}
else
modPlayer.DoGCartSegments = new DoGCartSegment[modPlayer.DoGCartSegments.Length];
// Dust on hand when holding the phosphorescent gauntlet.
if (player.ActiveItem().type == ModContent.ItemType<PhosphorescentGauntlet>())
PhosphorescentGauntletPunches.GenerateDustOnOwnerHand(player);
+29
View File
@@ -0,0 +1,29 @@
using Microsoft.Xna.Framework;
using Terraria;
namespace CalamityMod.DataStructures
{
public class DoGCartSegment
{
public Vector2 Center;
public float Rotation;
public int OldDirection;
public void Update(Player player, Vector2 aheadPosition, float idealRotation)
{
int direction = (player.velocity.SafeNormalize(Vector2.UnitX * player.direction).X > 0f).ToDirectionInt();
if (player.velocity.X == 0f)
direction = player.direction;
if (OldDirection != direction)
{
// Flip the segments if the player flips their direction.
if (OldDirection != 0)
Center = player.Center - Center + player.Center;
OldDirection = direction;
}
Rotation = (aheadPosition - Center).ToRotation();
Center = aheadPosition - (aheadPosition - Center).SafeNormalize(Vector2.Zero) * 24f;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 B

+42
View File
@@ -0,0 +1,42 @@
using CalamityMod.Items.Materials;
using CalamityMod.Tiles.Furniture.CraftingStations;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items.Mounts.Minecarts
{
public class DoGCart : ModItem
{
public override void SetStaticDefaults() => DisplayName.SetDefault("The Cart of Gods");
public override void SetDefaults()
{
item.width = 34;
item.height = 36;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = ItemUseStyleID.SwingThrow;
item.value = Item.sellPrice(gold: 30);
item.rare = ItemRarityID.Purple;
item.Calamity().customRarity = CalamityRarity.DarkBlue;
item.Calamity().donorItem = true;
item.UseSound = SoundID.Item68;
item.noMelee = true;
item.mountType = ModContent.MountType<DoGCartMount>();
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ModContent.ItemType<CosmiliteBar>(), 10);
recipe.AddIngredient(ModContent.ItemType<AscendantSpiritEssence>(), 10);
recipe.AddIngredient(ItemID.Wire, 60);
recipe.AddTile(ModContent.TileType<DraedonsForge>());
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

+148
View File
@@ -0,0 +1,148 @@
using CalamityMod.Buffs.Mounts;
using CalamityMod.DataStructures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items.Mounts.Minecarts
{
public class DoGCartMount : ModMountData
{
public const int SegmentCount = 18;
public override void SetDefaults()
{
mountData.Minecart = true;
mountData.MinecartDust = CreateSparkDust;
MountID.Sets.Cart[ModContent.MountType<DoGCartMount>()] = true;
mountData.spawnDust = 173;
mountData.buff = ModContent.BuffType<DoGCartBuff>();
// Movement fields.
mountData.flightTimeMax = 0;
mountData.fallDamage = 1f;
// Mechanical Cart in vanilla uses 20f and 0.1f respectively for these fields.
mountData.runSpeed = 22f;
mountData.acceleration = 0.16f;
mountData.jumpHeight = 16;
mountData.jumpSpeed = 5.2f;
mountData.blockExtraJumps = true;
mountData.heightBoost = 12;
// Drawing fields.
mountData.playerYOffsets = new int[] { 6, 6, 6 };
mountData.xOffset = 2;
mountData.yOffset = 12;
mountData.bodyFrame = 3;
// Animation fields.
mountData.totalFrames = 3;
mountData.standingFrameCount = 1;
mountData.standingFrameDelay = 12;
mountData.standingFrameStart = 0;
mountData.runningFrameCount = 3;
mountData.runningFrameDelay = 12;
mountData.runningFrameStart = 0;
mountData.flyingFrameCount = 0;
mountData.flyingFrameDelay = 0;
mountData.flyingFrameStart = 0;
mountData.inAirFrameCount = 0;
mountData.inAirFrameDelay = 0;
mountData.inAirFrameStart = 0;
mountData.idleFrameCount = 1;
mountData.idleFrameDelay = 10;
mountData.idleFrameStart = 0;
mountData.idleFrameLoop = false;
if (Main.netMode != NetmodeID.Server)
{
mountData.textureWidth = 74;
mountData.textureHeight = 114;
}
}
public void CreateSparkDust(Vector2 dustPosition)
{
Vector2 offsetDirection = DelegateMethods.Minecart.rotation.ToRotationVector2();
offsetDirection *= new Vector2(Main.rand.NextBool().ToDirectionInt(), 1f) * 13f;
dustPosition += offsetDirection;
Dust spark = Dust.NewDustPerfect(dustPosition, 234);
spark.velocity = Main.rand.NextVector2Circular(4f, 4f);
spark.velocity.X *= Main.rand.NextFloat(0.25f, 1f);
spark.velocity.Y -= Main.rand.NextFloat(1.25f, 3f);
spark.position.Y -= 4f;
spark.scale = Main.rand.NextFloat(0.9f, 1.4f);
spark.noGravity = true;
if (Main.rand.NextBool(8))
spark.scale *= 1.5f;
if (Main.rand.NextBool(8))
spark.scale *= 0.667f;
if (Main.rand.NextBool(3))
spark.scale *= 0.65f;
else
spark.noGravity = false;
}
public static float CalculateIdealWormRotation(Player player)
{
int direction = (player.velocity.SafeNormalize(Vector2.UnitX * player.direction).X > 0f).ToDirectionInt();
if (player.velocity.X == 0f)
direction = player.direction;
return (direction == 1 ? 0f : MathHelper.Pi) - DelegateMethods.Minecart.rotation * 0.1f;
}
public static Vector2 CalculateSegmentWaveOffset(int index, Player player)
{
Vector2 baseDirection = (CalculateIdealWormRotation(player) - MathHelper.PiOver2 + DelegateMethods.Minecart.rotation).ToRotationVector2();
Vector2 waveOffset = baseDirection * (float)Math.Sin(MathHelper.Pi * index / player.Calamity().DoGCartSegments.Length + Main.GameUpdateCount / 14f) * 5f;
waveOffset *= Utils.InverseLerp(10f, 4f, player.velocity.Length(), true);
return waveOffset;
}
public override bool Draw(List<DrawData> playerDrawData, int drawType, Player drawPlayer, ref Texture2D texture, ref Texture2D glowTexture, ref Vector2 drawPosition, ref Rectangle frame, ref Color drawColor, ref Color glowColor, ref float rotation, ref SpriteEffects spriteEffects, ref Vector2 drawOrigin, ref float drawScale, float shadow)
{
if (drawPlayer.Calamity().DoGCartSegments is null || drawPlayer.Calamity().DoGCartSegments[0] is null)
return true;
// Account for stupid rotational issues.
List<Vector2> rotationAdjustedPositions = new List<Vector2>()
{
drawPlayer.Calamity().DoGCartSegments[0].Center
};
for (int i = 1; i < drawPlayer.Calamity().DoGCartSegments.Length; i++)
{
rotationAdjustedPositions.Add(drawPlayer.Center - (drawPlayer.Center - drawPlayer.Calamity().DoGCartSegments[i].Center).RotatedBy(-drawPlayer.Calamity().SmoothenedMinecartRotation));
}
for (int i = 0; i < SegmentCount; i++)
{
DoGCartSegment segment = drawPlayer.Calamity().DoGCartSegments[i];
if (segment is null)
break;
Texture2D segmentTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/DoGCartBody");
if (i == SegmentCount - 1)
segmentTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/DoGCartTail");
Vector2 segmentDrawPosition = rotationAdjustedPositions[i] + CalculateSegmentWaveOffset(i, drawPlayer);
Color segmentColor = Lighting.GetColor((int)segmentDrawPosition.X / 16, (int)segmentDrawPosition.Y / 16);
Vector2 origin = segmentTexture.Size() * 0.5f;
float segmentRotation = segment.Rotation - DelegateMethods.Minecart.rotation;
playerDrawData.Add(new DrawData(segmentTexture, segmentDrawPosition - Main.screenPosition, null, segmentColor, segmentRotation, origin, Vector2.One, SpriteEffects.None, 0));
}
return true;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB