Ground movement & sfx

This commit is contained in:
IbanPlay authored and Cameron Ewell committed 2022-07-11 19:05:37 -04:00
1 parent c2beb378ec
commit 0d83f2c8cf
7 files changed
+237 -68

No files matched your search

+10 -1
View File
@@ -56,7 +56,12 @@ namespace CalamityMod.ILEditing
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += DrawCustomLava2;
IL.Terraria.Main.oldDrawWater += DrawCustomLava3;
On.Terraria.GameContent.Drawing.TileDrawing.Draw += ClearTilePings;
On.Terraria.Player.RemoveAllGrapplingHooks += RemoveCustomGrapples;
On.Terraria.Player.RemoveAllGrapplingHooks += RemoveCustomGrapples;
On.Terraria.Player.GrappleMovement += CustomGrappleMovementCheck;
On.Terraria.Player.UpdatePettingAnimal += CustomGrapplePreDefaultMovement;
On.Terraria.Player.PlayerFrame += CustomGrapplePostFrame;
On.Terraria.Player.SlopeDownMovement += CustomGrapplePreStepUp;
// TODO -- Revisit this. It's not an extremely important thing, but it'd be ideal to not just abandon it.
// IL.Terraria.WaterfallManager.DrawWaterfall += DrawCustomLavafalls;
@@ -159,6 +164,10 @@ namespace CalamityMod.ILEditing
IL.Terraria.Wiring.HitWireSingle -= AddTwinklersToStatue;
On.Terraria.GameContent.Drawing.TileDrawing.Draw -= ClearTilePings;
On.Terraria.Player.RemoveAllGrapplingHooks -= RemoveCustomGrapples;
On.Terraria.Player.GrappleMovement -= CustomGrappleMovementCheck;
On.Terraria.Player.UpdatePettingAnimal -= CustomGrapplePreDefaultMovement;
On.Terraria.Player.PlayerFrame -= CustomGrapplePostFrame;
On.Terraria.Player.SlopeDownMovement -= CustomGrapplePreStepUp;
// Damage and health balance
IL.Terraria.Main.DamageVar -= AdjustDamageVariance;
+71 -1
View File
@@ -14,6 +14,8 @@ using CalamityMod.Projectiles;
using CalamityMod.Systems;
using CalamityMod.Waters;
using CalamityMod.World;
using CalamityMod.Projectiles.Typeless;
using CalamityMod.Items.Accessories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Mono.Cecil.Cil;
@@ -948,16 +950,84 @@ namespace CalamityMod.ILEditing
#endregion
#region Custom Grappling hooks
/// <summary>
/// Custom grapples get removed when the vanilla function to remove all grapples get called, as the vanilla one relies solely on the ai stype = 7
/// </summary>
private static void RemoveCustomGrapples(On.Terraria.Player.orig_RemoveAllGrapplingHooks orig, Player self)
{
orig(self);
for (int i = 0; i < Main.maxProjectiles; i++)
{
if (Main.projectile[i].active && Main.projectile[i].owner == self.whoAmI && Main.projectile[i].type == ModContent.ProjectileType<Projectiles.Typeless.WulfrumHook>())
if (Main.projectile[i].active && Main.projectile[i].owner == self.whoAmI && Main.projectile[i].type == ModContent.ProjectileType<WulfrumHook>())
Main.projectile[i].Kill();
}
}
/// <summary>
/// Determines if the custom grapple movement should take place or not. Useful for hooks that only do movement tricks in some cases
/// </summary>
private static void CustomGrappleMovementCheck(On.Terraria.Player.orig_GrappleMovement orig, Player self)
{
WulfrumPackPlayer mp = self.GetModPlayer<WulfrumPackPlayer>();
if (mp.GrappleMovementDisabled)
return;
orig(self);
}
/// <summary>
/// This is called right before the game decides wether or not to update the players velocity based on "real" physics (aka not tongued or hooked or with a pulley)
/// </summary>
private static void CustomGrapplePreDefaultMovement(On.Terraria.Player.orig_UpdatePettingAnimal orig, Player self)
{
orig(self);
WulfrumPackPlayer mp = self.GetModPlayer<WulfrumPackPlayer>();
mp.hookCache = -1;
//if tongued, dnc.
if (self.tongued)
return;
//Cache the player's grapple and remove it temporarily (Gets re added in the modplayer's PostUpdateRunSpeeds)
if (self.grappling[0] >= 0 && mp.GrappleMovementDisabled && Main.projectile[self.grappling[0]].type == ModContent.ProjectileType<WulfrumHook>())
{
mp.hookCache = self.grappling[0];
self.grappling[0] = -1;
}
}
/// <summary>
/// Used before the player steps up a half tile. If we don't do that, players that are grappled but don't use hook movement won't be able to go over tiles.
/// The hook cache is reset in PreUpdateMovement
/// </summary>
private static void CustomGrapplePreStepUp(On.Terraria.Player.orig_SlopeDownMovement orig, Player self)
{
orig(self);
WulfrumPackPlayer mp = self.GetModPlayer<WulfrumPackPlayer>();
if (self.grappling[0] >= 0 && mp.GrappleMovementDisabled && Main.projectile[self.grappling[0]].type == ModContent.ProjectileType<WulfrumHook>())
{
mp.hookCache = self.grappling[0];
self.grappling[0] = -1;
}
}
/// <summary>
/// This is done to put the hook if it was cacehd during the frame instruction.
/// </summary>
private static void CustomGrapplePostFrame(On.Terraria.Player.orig_PlayerFrame orig, Player self)
{
orig(self);
WulfrumPackPlayer mp = self.GetModPlayer<WulfrumPackPlayer>();
if (mp.hookCache > -1)
self.grappling[0] = mp.hookCache;
mp.hookCache = -1;
}
#endregion
}
}
+108 -27
View File
@@ -11,12 +11,17 @@ using CalamityMod.DataStructures;
using System.Collections.Generic;
using System;
using System.Linq;
using CalamityMod.Items.Materials;
using Terraria.Audio;
namespace CalamityMod.Items.Accessories
{
[AutoloadEquip(EquipType.Back)]
public class WulfrumAcrobaticsPack : ModItem
{
public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Custom/WulfrumHookShoot") { Volume = 0.7f, MaxInstances = 1, SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest};
public static readonly SoundStyle GrabSound = new("CalamityMod/Sounds/Custom/WulfrumHookGrapple") { Volume = 0.7f, MaxInstances = 1, SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest };
public override void SetStaticDefaults()
{
SacrificeTotal = 1;
@@ -41,6 +46,16 @@ namespace CalamityMod.Items.Accessories
player.GetModPlayer<WulfrumPackPlayer>().WulfrumPackEquipped = true;
player.GetModPlayer<WulfrumPackPlayer>().PackItem = Item;
}
public override void AddRecipes()
{
CreateRecipe().
AddIngredient(ItemID.Chain, 2).
AddIngredient<WulfrumShard>(6).
AddIngredient<EnergyCore>(1).
AddTile(TileID.Anvils).
Register();
}
}
public class WulfrumPackProjectile : GlobalProjectile
@@ -78,8 +93,39 @@ namespace CalamityMod.Items.Accessories
public bool WulfrumPackEquipped = false;
public Item PackItem = null;
public bool AutoGrappleActivated => !Player.noFallDmg;
/// <summary>
/// The index of the grapple projectile currently grappled.
/// </summary>
public int Grapple = 0;
/// <summary>
/// The lenght of the current rope. Determined when the grapple lands.
/// </summary>
public float SwingLenght = 0f;
/// <summary>
/// Used when we need to store the hook between instructions.
/// </summary>
public int hookCache = -1;
/// <summary>
/// Is the player grappled?
/// </summary>
public bool Grappled => WulfrumPackEquipped && Main.projectile[Grapple].active && Main.projectile[Grapple].ModProjectile is WulfrumHook hook && hook.State == WulfrumHook.HookState.Grappling;
public bool GrappleMovementDisabled
{
get
{
if (!Grappled)
return false;
bool collisionTest = Collision.SolidCollision(Player.position + Vector2.UnitY * 2f, Player.width, Player.height, true);
if (!collisionTest)
return false;
if ((Player.Center - Main.projectile[Grapple].Center).Length() > SwingLenght)
return false;
return true;
}
}
public Vector2 CurrentPosition;
public Vector2 OldPosition;
@@ -90,13 +136,12 @@ namespace CalamityMod.Items.Accessories
public static float GrappleVelocity = 18f;
public static float ReturnVelocity = 5f;
public static float MaxHopVelocity = 4f; //The maximum velocity at which the player gets any amount of vertical boost from hopping out of the hook
public static float MaxHopHeight = 4f; //The max height of the vvertical hop that happens when jumping out of the hook at a low speed.
public override void ResetEffects()
{
WulfrumPackEquipped = false;
PackItem = null;
MaxHopHeight = 8.5f;
}
//Initialize the segments between the player and the hook's end point.
@@ -123,10 +168,23 @@ namespace CalamityMod.Items.Accessories
}
}
public override void PostUpdateRunSpeeds()
{
if (hookCache != -1)
Player.grappling[0] = hookCache;
hookCache = -1;
}
public override void PreUpdateMovement()
{
if (WulfrumPackEquipped && Main.projectile[Grapple].active && Main.projectile[Grapple].ModProjectile is WulfrumHook hook && hook.State == WulfrumHook.HookState.Grappling)
//If the hook cache was set from -1 in the part before the player stepped up,reset it.
//Should this be detoured before the PlayerLoaders PreUpdateMovement call? In case another mod uses hooks in this call and their modplayer gets called before this one?
if (hookCache > -1)
Player.grappling[0] = hookCache;
hookCache = -1;
if (Grappled)
SimulateMovement(Main.projectile[Grapple]);
}
@@ -145,33 +203,42 @@ namespace CalamityMod.Items.Accessories
//doost.noGravity = true;
}
CurrentPosition = Segments[SimulationResolution].position;
Player.velocity = CurrentPosition - Player.Center;
//let the player swing themselves around if they are under the hook.
if (Player.Center.Y - Segments[0].position.Y > 0)
if (!GrappleMovementDisabled)
{
float swing = 0;
CurrentPosition = Segments[SimulationResolution].position;
Player.velocity = CurrentPosition - Player.Center;
if (Math.Sign(Player.velocity.X) < 0)
//let the player swing themselves around if they are under the hook.
if (Player.Center.Y - Segments[0].position.Y > 0)
{
if (Player.controlLeft)
swing -= 0.1f;
float swing = 0;
else if (Player.controlRight)
swing += 0.1f;
if (Math.Sign(Player.velocity.X) < 0)
{
if (Player.controlLeft)
swing -= 0.1f;
else if (Player.controlRight)
swing += 0.1f;
}
else if (Math.Sign(Player.velocity.X) > 0)
{
if (Player.controlRight)
swing += 0.1f;
else if (Player.controlLeft)
swing -= 0.1f;
}
Player.velocity.X += swing;
}
}
else if (Math.Sign(Player.velocity.X) > 0)
{
if (Player.controlRight)
swing += 0.1f;
else if (Player.controlLeft)
swing -= 0.1f;
}
Player.velocity.X += swing;
for (int i = 1; i < Segments.Count; i++)
{
Lighting.AddLight(Segments[i].position, Color.Lerp(Color.DeepSkyBlue, Color.GreenYellow, i / 3f).ToVector3());
}
//Set the old position of the simulation's segments to be the players current center (before the velocity gets applied
@@ -182,7 +249,7 @@ namespace CalamityMod.Items.Accessories
public override void PostUpdate()
{
//After the player's movements are finished being calculated, set the current position of the hook chain to be at their new center.
if (WulfrumPackEquipped && Main.projectile[Grapple].active && Main.projectile[Grapple].ModProjectile is WulfrumHook hook && hook.State == WulfrumHook.HookState.Grappling)
if (Grappled)
Segments[SimulationResolution].position = Player.Center;
}
@@ -207,8 +274,12 @@ namespace CalamityMod.Items.Accessories
if (Main.projectile.Count(n => n.active && n.owner == Player.whoAmI && n.type == ProjectileType<WulfrumHook>()) <= 1)
{
Vector2 velocity = (Main.MouseWorld - Player.Center).SafeNormalize(Vector2.One) * GrappleVelocity;
Projectile.NewProjectile(Player.GetSource_ItemUse(PackItem), Player.Center, velocity, ProjectileType<WulfrumHook>(), 0, 0, Player.whoAmI);
SoundEngine.PlaySound(WulfrumAcrobaticsPack.ShootSound, Player.Center);
if (Player.whoAmI == Main.myPlayer)
{
Vector2 velocity = (Main.MouseWorld - Player.Center).SafeNormalize(Vector2.One) * GrappleVelocity;
Projectile.NewProjectile(Player.GetSource_ItemUse(PackItem), Player.Center, velocity, ProjectileType<WulfrumHook>(), 0, 0, Player.whoAmI);
}
}
}
@@ -235,7 +306,8 @@ namespace CalamityMod.Items.Accessories
}
//Additionally^2, if the player isnt moving very fast, make them do a straight up hop.
//Don't do the hop if the player isnt moving at all though because thats handled by vanilla.
if (Player.velocity.Length() < MaxHopVelocity && Player.velocity.Length() > 0.0001f)
bool disabledGrapple = Collision.SolidCollision(Player.position + Vector2.UnitY * 2f, Player.width, Player.height, true);
if (Player.velocity.Length() < MaxHopVelocity && (Player.velocity.Length() > 0.0001f || disabledGrapple))
{
velocityBoost -= Vector2.UnitY * Player.jumpSpeed * (1 - (float)Math.Pow(Player.velocity.Length() / MaxHopVelocity, 5f));
}
@@ -249,5 +321,14 @@ namespace CalamityMod.Items.Accessories
}
}
public override void FrameEffects()
{
if (Player.grappling[0] >= 0 && GrappleMovementDisabled && Main.projectile[Player.grappling[0]].type == ProjectileType<WulfrumHook>())
{
hookCache = Player.grappling[0];
Player.grappling[0] = -1;
}
}
}
}
-1
View File
@@ -109,7 +109,6 @@ namespace CalamityMod.Items.Tools
public override void AddRecipes()
{
//Intentionally craftable anywhere.
CreateRecipe().
AddIngredient<WulfrumShard>(6).
AddIngredient<EnergyCore>(1).
+48 -38
View File
@@ -41,7 +41,9 @@ namespace CalamityMod.Projectiles.Typeless
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Grappling Hook");
DisplayName.SetDefault("Wulfrum Slingshot");
//Expand the draw distance. Should never happen really , but just in case the player basically walks away from the hook.
ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 3000;
}
public override void SetDefaults()
@@ -53,6 +55,7 @@ namespace CalamityMod.Projectiles.Typeless
Projectile.timeLeft = 2;
Projectile.tileCollide = false;
Projectile.extraUpdates = WulfrumPackPlayer.HookUpdates;
Projectile.netImportant = true;
//Projectile.aiStyle = 7; Can i set its ai style to 7 wihle also making it not do anthing related to ai 7 whatsoever and use my own custom hook ai?
//That would bne great because fsr the onyl way to distinguish if a projectile is a hook or not is by checking its ai style.
}
@@ -64,7 +67,7 @@ namespace CalamityMod.Projectiles.Typeless
Lighting.AddLight(Projectile.Center, Color.DeepSkyBlue.ToVector3());
Vector2 BetweenOwner = Owner.Center - Projectile.Center;
if (Owner.dead || Owner.stoned || Owner.webbed || Owner.frozen || BetweenOwner.Length() > 2500)
if (Owner.dead || Owner.stoned || Owner.webbed || Owner.frozen || BetweenOwner.Length() > 1500)
{
Projectile.Kill();
return;
@@ -151,43 +154,8 @@ namespace CalamityMod.Projectiles.Typeless
if (Main.myPlayer != Owner.whoAmI)
continue;
WulfrumPackPlayer mp = Owner.GetModPlayer<WulfrumPackPlayer>();
//Clear previous grapple
if (Main.projectile[mp.Grapple].active && Main.projectile[mp.Grapple].ModProjectile is WulfrumHook hook && hook.State == WulfrumHook.HookState.Grappling)
Main.projectile[mp.Grapple].Kill();
//Hook onto the tile
Projectile.velocity = Vector2.Zero;
State = HookState.Grappling;
Projectile.Center = worldPos + Vector2.One * 8f;
//effects
WorldGen.KillTile(x, y, fail: true, effectOnly: true);
SoundEngine.PlaySound(SoundID.Dig, worldPos);
OnGrapple(worldPos, x, y);
if (Owner.grapCount < 10)
{
Owner.grappling[Owner.grapCount] = Projectile.whoAmI;
Owner.grapCount++;
//Owner.velocity = Vector2.Zero;
}
mp.SwingLenght = (Owner.Center - Projectile.Center).Length();
mp.OldPosition = Owner.Center - Owner.velocity;
mp.SetSegments(Projectile.Center);
mp.Grapple = Projectile.whoAmI;
Rectangle? tileVisualHitbox = WorldGen.GetTileVisualHitbox(x, y);
if (tileVisualHitbox.HasValue)
Projectile.Center = tileVisualHitbox.Value.Center.ToVector2();
Projectile.netUpdate = true;
NetMessage.SendData(MessageID.PlayerControls, -1, -1, null, Owner.whoAmI);
break;
}
@@ -196,8 +164,50 @@ namespace CalamityMod.Projectiles.Typeless
}
}
public void OnGrapple(Vector2 grapplePos, int x, int y)
{
WulfrumPackPlayer mp = Owner.GetModPlayer<WulfrumPackPlayer>();
//Clear previous grapple
if (Main.projectile[mp.Grapple].active && Main.projectile[mp.Grapple].ModProjectile is WulfrumHook hook && hook.State == WulfrumHook.HookState.Grappling)
Main.projectile[mp.Grapple].Kill();
//Hook onto the tile
Projectile.velocity = Vector2.Zero;
State = HookState.Grappling;
Projectile.Center = grapplePos + Vector2.One * 8f;
//effects
WorldGen.KillTile(x, y, fail: true, effectOnly: true);
SoundEngine.PlaySound(SoundID.Dig, grapplePos);
SoundEngine.PlaySound(WulfrumAcrobaticsPack.GrabSound, grapplePos);
if (Owner.grapCount < 10)
{
Owner.grappling[Owner.grapCount] = Projectile.whoAmI;
Owner.grapCount++;
//Owner.velocity = Vector2.Zero;
}
mp.SwingLenght = (Owner.Center - Projectile.Center).Length();
mp.OldPosition = Owner.Center - Owner.velocity;
mp.SetSegments(Projectile.Center);
mp.Grapple = Projectile.whoAmI;
Rectangle? tileVisualHitbox = WorldGen.GetTileVisualHitbox(x, y);
if (tileVisualHitbox.HasValue)
Projectile.Center = tileVisualHitbox.Value.Center.ToVector2();
Projectile.netUpdate = true;
NetMessage.SendData(MessageID.PlayerControls, -1, -1, null, Owner.whoAmI);
}
public override void Kill(int timeLeft)
{
if (Owner.grappling[0] == Projectile.whoAmI)
{
Owner.grappling[0] = -1;
Owner.grapCount--;
}
}
public float PrimWidthFunction(float completionRatio)
Binary file not shown.
Binary file not shown.