player.CheckSolidGround util

This commit is contained in:
IbanPlay committed 2022-01-26 17:17:59 +01:00
1 parent b66283f976
commit ecc2f2dd84
3 files changed
+36 -13

No files matched your search

+2 -6
View File
@@ -259,11 +259,8 @@ namespace CalamityMod.Items.Weapons.Melee
if (Main.projectile.Any(n => n.active && n.type == ProjectileType<BrokenBiomeBladeHoldout>() && n.owner == player.whoAmI))
return;
int x = (int)player.Center.X / 16;
int y = (int)(player.position.Y + (float)player.height - 1f) / 16;
Tile tileStandingOn = Main.tile[x, y + 1];
bool mayAttune = player.StandingStill() && !player.mount.Active && tileStandingOn.IsTileSolidGround();
bool mayAttune = player.StandingStill() && !player.mount.Active && player.CheckSolidGround(1, 3);
Vector2 displace = new Vector2(18f, 0f);
Projectile.NewProjectile(player.Top + displace, Vector2.Zero, ProjectileType<BrokenBiomeBladeHoldout>(), 0, 0, player.whoAmI, mayAttune ? 0f : 1f);
}
@@ -326,9 +323,8 @@ namespace CalamityMod.Items.Weapons.Melee
{
private Player Owner => Main.player[projectile.owner];
public bool OwnerOnGround => Main.tile[(int)Owner.Center.X / 16, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround() && Main.tile[(int)Owner.Center.X / 16 + Owner.direction, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround();
public bool OwnerCanUseItem => Owner.HeldItem == associatedItem ? (Owner.HeldItem.modItem as BiomeBlade).CanUseItem(Owner) : false;
public bool OwnerMayChannel => OwnerCanUseItem && Owner.Calamity().mouseRight && Owner.active && !Owner.dead && Owner.StandingStill() && !Owner.mount.Active && OwnerOnGround;
public bool OwnerMayChannel => OwnerCanUseItem && Owner.Calamity().mouseRight && Owner.active && !Owner.dead && Owner.StandingStill() && !Owner.mount.Active && Owner.CheckSolidGround(1, 3);
public ref float ChanneledState => ref projectile.ai[0];
public ref float ChannelTimer => ref projectile.ai[1];
public ref float Initialized => ref projectile.localAI[0];
+2 -7
View File
@@ -281,11 +281,7 @@ namespace CalamityMod.Items.Weapons.Melee
if (Main.projectile.Any(n => n.active && n.type == ProjectileType<BiomeBladeHoldout>() && n.owner == player.whoAmI))
return;
int x = (int)player.Center.X / 16;
int y = (int)(player.position.Y + (float)player.height - 1f) / 16;
Tile tileStandingOn = Main.tile[x, y + 1];
bool mayAttune = player.StandingStill() && !player.mount.Active && tileStandingOn.IsTileSolidGround();
bool mayAttune = player.StandingStill() && !player.mount.Active && player.CheckSolidGround(1, 3);
Vector2 displace = new Vector2(18f, 0f);
Projectile.NewProjectile(player.Top + displace, Vector2.Zero, ProjectileType<BiomeBladeHoldout>(), 0, 0, player.whoAmI, mayAttune ? 0f : 1f);
}
@@ -381,9 +377,8 @@ namespace CalamityMod.Items.Weapons.Melee
public class BiomeBladeHoldout : ModProjectile //Visuals
{
private Player Owner => Main.player[projectile.owner];
public bool OwnerOnGround => Main.tile[(int)Owner.Center.X / 16, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround() && Main.tile[(int)Owner.Center.X / 16 + Owner.direction, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround();
public bool OwnerCanUseItem => Owner.HeldItem == associatedItem ? (Owner.HeldItem.modItem as TrueBiomeBlade).CanUseItem(Owner) : false;
public bool OwnerMayChannel => OwnerCanUseItem && Owner.Calamity().mouseRight && Owner.active && !Owner.dead && Owner.StandingStill() && !Owner.mount.Active && OwnerOnGround;
public bool OwnerMayChannel => OwnerCanUseItem && Owner.Calamity().mouseRight && Owner.active && !Owner.dead && Owner.StandingStill() && !Owner.mount.Active && Owner.CheckSolidGround(1, 3);
public ref float ChanneledState => ref projectile.ai[0];
public ref float ChannelTimer => ref projectile.ai[1];
public ref float Initialized => ref projectile.localAI[0];
+32
View File
@@ -187,6 +187,38 @@ namespace CalamityMod
target.AddBuff(BuffID.OnFire, (int)(180 * multiplier));
}
/// <summary>
/// Checks if the player is ontop of solid ground. May also check for solid ground for X tiles in front of them
/// </summary>
/// <param name="player">The Player whose position is being checked</param>
/// <param name="solidGroundAhead">How many tiles in front of the player to check</param>
/// <param name="airExposureNeeded">How many tiles above every checked tile are checked for non-solid ground</param>
public static bool CheckSolidGround(this Player player, int solidGroundAhead = 0, int airExposureNeeded = 0)
{
if (player.velocity.Y != 0) //Player gotta be standing still in any case
return false;
Tile checkedTile;
bool ConditionMet = true;
for (int i = 0; i <= solidGroundAhead; i++) //Check i tiles in front of the player
{
ConditionMet = Main.tile[(int)player.Center.X / 16 + player.direction * i, (int)(player.position.Y + (float)player.height - 1f) / 16 + 1].IsTileSolidGround();
if (!ConditionMet)
return ConditionMet;
for (int j = 1; j <= airExposureNeeded; j++) //Check j tiles ontop of each checked tiles for non-solid ground
{
checkedTile = Main.tile[(int)player.Center.X / 16 + player.direction * i, (int)(player.position.Y + (float)player.height - 1f) / 16 + 1 - j];
ConditionMet = !(checkedTile != null && checkedTile.nactive() && Main.tileSolid[checkedTile.type]); //IsTileSolidGround minus the ground part, to avoid platforms and other half solid tiles messing it up
if (!ConditionMet)
return ConditionMet;
}
}
return ConditionMet;
}
/// <summary>
/// Makes the given player send the given packet to all appropriate receivers.<br />
/// If server is false, the packet is sent only to the multiplayer host.<br />