From cd372711e91dbd9accb375df02c02e5ce7f35461 Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 30 Aug 2021 14:37:45 -0500 Subject: [PATCH] Added the Cart of Gods --- Buffs/Mounts/DoGCartBuff.cs | 24 +++ Buffs/Mounts/DoGCartBuff.png | Bin 0 -> 753 bytes CalPlayer/CalamityPlayer.cs | 3 + CalPlayer/CalamityPlayerMiscEffects.cs | 41 +++++ DataStructures/DoGCartSegment.cs | 29 ++++ ExtraTextures/DoGCartBody.png | Bin 0 -> 559 bytes ExtraTextures/DoGCartTail.png | Bin 0 -> 574 bytes Items/Mounts/Minecarts/DoGCart.cs | 42 +++++ Items/Mounts/Minecarts/DoGCart.png | Bin 0 -> 432 bytes Items/Mounts/Minecarts/DoGCartMount.cs | 148 ++++++++++++++++++ Items/Mounts/Minecarts/DoGCartMount_Front.png | Bin 0 -> 2302 bytes 11 files changed, 287 insertions(+) create mode 100644 Buffs/Mounts/DoGCartBuff.cs create mode 100644 Buffs/Mounts/DoGCartBuff.png create mode 100644 DataStructures/DoGCartSegment.cs create mode 100644 ExtraTextures/DoGCartBody.png create mode 100644 ExtraTextures/DoGCartTail.png create mode 100644 Items/Mounts/Minecarts/DoGCart.cs create mode 100644 Items/Mounts/Minecarts/DoGCart.png create mode 100644 Items/Mounts/Minecarts/DoGCartMount.cs create mode 100644 Items/Mounts/Minecarts/DoGCartMount_Front.png diff --git a/Buffs/Mounts/DoGCartBuff.cs b/Buffs/Mounts/DoGCartBuff.cs new file mode 100644 index 0000000000..0b96dfaa7e --- /dev/null +++ b/Buffs/Mounts/DoGCartBuff.cs @@ -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(), player); + player.buffTime[buffIndex] = 10; + } + } +} diff --git a/Buffs/Mounts/DoGCartBuff.png b/Buffs/Mounts/DoGCartBuff.png new file mode 100644 index 0000000000000000000000000000000000000000..95ffd9b47ea3effdd3d4a34e44e5768ac0afe4dd GIT binary patch literal 753 zcmVPx%t4TybR9J=0mrY1iQ5462Ge`*`skCVFqZ+eMZM3o?O>D~PLrtTCEP@O~OM@(; zMYRip@}o~ef@;&MTsYXmAqMG-N~IzR3Y;u4TSOKjlti|;-Y4hHJU4>#{+oOM_nvd^ zd;fdxx$imLE-wI~!QdFv2)E1Y0B}y{qLJVL#sI2{UjPv2o+%8H=4Ame@b!)0RxsOX zt}z_?13+`zdcXz>#ORLs&A)YZs+LYUZsJxj+s$2*6LB5;D4?PD$c(o?{epYqcM9J9 z>4xB|7uH0KYhMN0ADshWgZu2H4#y6k0N`PJ8vvn!k79mt#%2Jzdz2zE2`MUW;>w8e z?4!UsZz%weTdIKYJ=A#B*9*Xr`UWw6x<=aP?yeR5dGNgIgk-#^D_~T@%;m)Z{2l6_ z)Ism5x1ta(5?K( z>%wTY%8{~K)%ufEE)?y(3qbu<#iOo3*j-?LbF1-=R@G`Hingj#)YMQ1fb)V<)IZ)@ zA?gYkIpE1VDkf^m_6V*k;LBjE7}vR>?Nfa70q75W7JeUwMugv!d&iak)SiFpFcjE$ z;4%P95@rDt=U1cdWD_uP3u?rTEEPO?Zld|DA>!7(=g+dRt7ehPdK-T`1nnmp&D zy{eX(Z#kV4<~wALw?goP+3I^BwQv()BL%|hfQGr!1satC=G@RYll~fjeV#4=G9Ofm z`KI7_M}9^`UjZWrmbp9t`0`Y(4m>?14E4AbItFhEUf`;n3 jP3zxrdUByX{*M0xTuQ({p?s|T00000NkvXXu0mjfD(PJ8 literal 0 HcmV?d00001 diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 2374460f2b..4da6de7b1d 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -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 diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 05dfa7166f..58e9db4549 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -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()) + { + 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()) PhosphorescentGauntletPunches.GenerateDustOnOwnerHand(player); diff --git a/DataStructures/DoGCartSegment.cs b/DataStructures/DoGCartSegment.cs new file mode 100644 index 0000000000..3662671bfd --- /dev/null +++ b/DataStructures/DoGCartSegment.cs @@ -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; + } + } +} diff --git a/ExtraTextures/DoGCartBody.png b/ExtraTextures/DoGCartBody.png new file mode 100644 index 0000000000000000000000000000000000000000..c80146560300f1a4d4a7e08b30216d1317030c5d GIT binary patch literal 559 zcmV+~0?_@5P)Px$=}AOER7i>C*Ud{*Q5XjB-z_1E45?JI53<6tlr~ZeOZp&!v|PAu)gpwpE$WYG z)222p+e=zzP;I1a6Ot)Lilican4=aWrA~{P({!h4SB^~2=JLMxIfwJy=bZPvH>y9_ zB7>A)P+GPng89TWSo-oQP5PdU@dC=L>m!&+B*3e|&U`d$@@D@bN^%oNPql)+#~m>x z>o$}{urQkhjcr$A;{v~GYk36A)yKi|!WPG<-M!6mag#jOjhrsCMn^=C&_8QQ9 zwk4LodFKXLoEZn3OY0)|JU@U!Dy*p72{x9jPmx{ut}`dWyGKvJi?I=8m6z|Y1xI%8 zjZOTlGwt>B;p@mMU3rDI+YW=RRR=&K`8BpXbG-_R1A_9dhv{<{yl$vykMV-il~;JI zp$$w=zD+?*-RT%1tT^ntKjFgUOVD-c7Fg=OotL-rl_n_5Q#ruCrY6vM{!r}w_+TOy zcQ>WSug%0undhd8$_VB@yvJ&&rMb#3w_gPV6Zb*yz1LuLU<{mSZ3GvuHG{ex=fH!W zyP&@_Jzrmc4+?Y+|B8oCJ9=aBw~=&Qa1V?B9R3HjwD|ACqVH*btEB;<()=VYFJ}7E xsT7oFzC`de@IzlZk(@S->P)Px$_(?=TR9J=W*S||uaTv$(*D(vEjHtA-kgO;)r6nqmq=E?2a%gUH2%)v1{(zRC zrG_GDtfdCgN(`(;%9fB!QBo|Gs4y>D7@FRO>p{-#+%Rmo$^9(nJm2rba}IAl-yct4 znJV9QAbd^6%@>tb1u&6FfH%FZv32s6`y>BK`O7U3tS$h_*=bOH?qX!VtD`vyC7X)^ zm@hjD=6_6rzK`9=A|k<36RRrfV#n9yrAo}qCzG&i`(99cDw==e?sf2UVgzg~tPJ4m zR1f|qA|Z*j1?#}~>2I;CBP0>3XkR%vv~zc4{6%ZZOE3GcV3ADr5lQzzNMLJm2^f4o z5bJ@`lgDEVKe*EbzV!Ejp|JsQu(&aj7m~>yA|Z*w4V%DJVm#u3OsnA4@F3`Xc=L}R zI6L+lJZiWF=Gtz@=4B0$d<$p9RAL+)K2eX~-5wI?>SzXgYHC13)741cNN*w%x7DO} z+Eokj+`@Bx@s 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(); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ItemID.Wire, 60); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Mounts/Minecarts/DoGCart.png b/Items/Mounts/Minecarts/DoGCart.png new file mode 100644 index 0000000000000000000000000000000000000000..2823eccb57327b09c294db2d69c91160e916c7e6 GIT binary patch literal 432 zcmeAS@N?(olHy`uVBq!ia0vp^IzTMJ!3-p~ZG7JWq!^2X+?^QKos)S9+XVQ8xN1u3>uUMPS% z-#_(9OaC9gk?62>iQT{Lm+t<_Jq0x2qKl3ekP;~g@(cct2^jqSp9=!zISV`@iy0XB z4ude`@%$AjK*777E{-7<{!1s_-gHQThk=yl+ewO7MwG7 z=h7%R6qq()] = true; + + mountData.spawnDust = 173; + mountData.buff = ModContent.BuffType(); + + // 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 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 rotationAdjustedPositions = new List() + { + 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; + } + } +} diff --git a/Items/Mounts/Minecarts/DoGCartMount_Front.png b/Items/Mounts/Minecarts/DoGCartMount_Front.png new file mode 100644 index 0000000000000000000000000000000000000000..98ea6a750909adbe3023c0cd163a60f7a9b394b1 GIT binary patch literal 2302 zcma)8`#;l<8vksXY2UAF=9`F0MJ94ti3quEl)H^Ehvrg87=~}n7E<|2H$|>}hcKGC zMddQNMWRBvjJYkDZLYbGvvbZLaLy0U<@I`=*YkSb&+YZxbG&3D2|EA-06-FDYw0YK zXb}-4#6^5%!=^$cKoQP17683Rc@_X9>QI*Et})sC?2s@xMzMpObw{8hnIp3RUN_AChbdCFS6 zS_W2N2@*RIg1!)OL1J(0yEwzOPQJ(KGc!pa9GABnSvZ<5#g*wD0i*t$ZX{pU(FuYs4ke9%JZ27 zrLAZ~#w{*qMUh4j56+GjPuj7?eI0(imN0VW*k_O3+BS7FBdui=g5}`%uhYrZEOHSOm%U5{Z3)v}F+`TCdoD2!1OkgrJyJSP# zThGegJ%N^RQ~>5X(m2gbU9@`xk97?&9J#3pW)KFZZcPbF#uTEdRE_g`c~eC@5avp} zh4gq(!dVq>Oa-A4EP<65SeVSX!z=W{8>x5fBr+^%|lO?tctaA@kp&0|$2P3Ic zlnC`qkm1{F=~1NaG!|3IR_pQp$e;WsfU(h`1NywdfdOL(o!6Tj(<&%MP^kz6# zG+~7D6o!LSr=o|7*%orYevHHjA!10e)yq zj`eM!Ry;S;svQ>k*|2V%e`DBUv^vkQ@_1Fn_X_bRYJ}CdA5^DgIOi>)0o%rw>T*xK z`$YRP)Lz?YQyB=E(3hnw7UtEq8?#qJrF|n^!xR2aCKNQOa4?T?=1WI+ovyie&{VZ5 zhd=gQjv-}vB-is??xLCd1Y8{#v7bKsakun{M+)ddM zn87)=P1HT)XXM6^>Zt9ZV*%=<9}oCuTF~yBeW@o4rL($zL`c7amSxuVwLWgYDE^|L zyx#~HI}$lQY4q%n8+1eU& zc%JlWKq=o_vkc@D<5#%hpBEcnYoflTov%SAq0^99h<<5<;llP0;qi2}O@wa9P;w|( zxA5X|Y@hpY0oXcjJ#jcbg*A&cw)6< zBQ%WOT((5hu-Sw^^~9)xf;NOzfYu zkX@+8mj3j(n&JNb?*>_O4IxD)6x&|NwQSqo+jXH&whM~zF+h$tQNS&)D5WaTVq6I; zIG?c<7>VD0aI!Fy^sO$ar+=7r)#NN0zwGbdO$(o1IP4o1=zWPh5Wo^dYvK1g<22Ew z3jp`s)v|D5kNNZR^Z>oT3Ji=}7W4-%A8<=k+j}E>d#5n%OYj%mJ~d~(PoaT*@4m2K zGQ+oX9TnGTD@TB@Pb$mia!Bp7Yd%FoGbMMHVQnrLhLWhP{czr0(OHdx7>l;e(z`je zn5yiAVW|BtQyG1H!pggu3sdn);=vSjipu=rdCUR$Ig2+}FpTkN=!2#Kjr>2S%0W?( z2m9rSklrQxZdvJ>q?%|?G567+VHD39vml}N4@?+&i}dC5>)upI#oGbow^)(CjP_Dk zGGZMOhgtA{0A`Heng=n;S4oEy)TTROoWfZ5^B5`Z5rCN!+V45j*5^?fWyRW|Vx6)d z79;A&rd-&i6gwhhYm|9Mtvy(Mt4M^aG~(hnHZJ)7kvG|{kbd~h+k{TKFWJgPGiM(x z<>Pc@!jO&Rk1_;WA5EX9-J65;pc;n7g7|SA2Qc2v7>Nr+ND;>}&-H3$RD%u|C4&jW z%?vTa`{CQ<Ap6uPN~I+L0M5txGkWf z`nYWSL+|E$RFPuwp6(l~qh6ZKmgKRaCXGbA#Xj1NiCQzB9sO}j31VICy~x$sMCK31 zA?=C#