Files
CalamityModPublic/Utilities/PlayerUtils.cs
T
Ozzatron 72bb69852a 1 - There is now a Utility function to give players immunity frames. Immunity frames should not be given to players any other way.
2 - Gael's Greatsword right click parry removed.
3 - Removed Determination Breaker.
4 - Shield slam iframes normalized. Ornate Shield and Plaguebringer set give 4. Asgard's Valor line gives 6.
5 - Shield of Cthulhu gives 6 iframes and 6 no-collide frames instead of 10 no-collide frames.
6 - Shield of Cthulhu can't cause you to get double-hit anymore.
7 - Calamity-granted iframes will never cause the player to get double-hit.
8 - Solar Flare Armor set bonus now has a base damage of 400. Its spawned explosion now has the same damage and scales with melee stats.
9 - Solar Flare Armor set bonus now gives 12 iframes.
10 - Solar Flare Armor set bonus can't cause you to get double-hit anymore.
11 - Exo Gladius on-hit gives 3 iframes.
12 - Lucrecia (and its projectiles) on-hit give 5 iframes.
13 - Phosphorescent Gauntlet on-hit gives 15 iframes.
14 - Cosmic Plushie explicitly removes all your iframes immediately upon stabbing you.
2021-11-11 18:50:12 -05:00

214 lines
8.6 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Buffs.StatDebuffs;
using CalamityMod.CalPlayer;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
namespace CalamityMod
{
public static partial class CalamityUtils
{
// These functions factor in TML 0.11 allDamage to get the player's total damage boost which affects the specified class.
public static float MeleeDamage(this Player player) => player.allDamage + player.meleeDamage - 1f;
public static float RangedDamage(this Player player) => player.allDamage + player.rangedDamage - 1f;
public static float MagicDamage(this Player player) => player.allDamage + player.magicDamage - 1f;
public static float MinionDamage(this Player player) => player.allDamage + player.minionDamage - 1f;
public static float ThrownDamage(this Player player) => player.allDamage + player.thrownDamage - 1f;
public static float RogueDamage(this Player player) => player.allDamage + player.thrownDamage + player.Calamity().throwingDamage - 2f;
public static float AverageDamage(this Player player) => player.allDamage + (player.meleeDamage + player.rangedDamage + player.magicDamage + player.minionDamage + player.Calamity().throwingDamage - 5f) / 5f;
public static bool IsUnderwater(this Player player) => Collision.DrownCollision(player.position, player.width, player.height, player.gravDir);
public static bool StandingStill(this Player player, float velocity = 0.05f) => player.velocity.Length() < velocity;
public static bool InSpace(this Player player)
{
float x = Main.maxTilesX / 4200f;
x *= x;
float spaceGravityMult = (float)((player.position.Y / 16f - (60f + 10f * x)) / (Main.worldSurface / 6.0));
return spaceGravityMult < 1f;
}
public static bool PillarZone(this Player player) => player.ZoneTowerStardust || player.ZoneTowerSolar || player.ZoneTowerVortex || player.ZoneTowerNebula;
public static bool InCalamity(this Player player) => player.Calamity().ZoneCalamity;
public static bool InSunkenSea(this Player player) => player.Calamity().ZoneSunkenSea;
public static bool InSulphur(this Player player) => player.Calamity().ZoneSulphur;
public static bool InAstral(this Player player, int biome = 0) //1 is above ground, 2 is underground, 3 is desert
{
switch (biome)
{
case 1:
return player.Calamity().ZoneAstral && (player.ZoneOverworldHeight || player.ZoneSkyHeight);
case 2:
return player.Calamity().ZoneAstral && (player.ZoneDirtLayerHeight || player.ZoneRockLayerHeight || player.ZoneUnderworldHeight);
case 3:
return player.Calamity().ZoneAstral && player.ZoneDesert;
default:
return player.Calamity().ZoneAstral;
}
}
public static bool InAbyss(this Player player, int layer = 0)
{
switch (layer)
{
case 1:
return player.Calamity().ZoneAbyssLayer1;
case 2:
return player.Calamity().ZoneAbyssLayer2;
case 3:
return player.Calamity().ZoneAbyssLayer3;
case 4:
return player.Calamity().ZoneAbyssLayer4;
default:
return player.Calamity().ZoneAbyss;
}
}
public static bool InventoryHas(this Player player, params int[] items)
{
return player.inventory.Any(item => items.Contains(item.type));
}
public static bool PortableStorageHas(this Player player, params int[] items)
{
bool hasItem = false;
if (player.bank.item.Any(item => items.Contains(item.type)))
hasItem = true;
if (player.bank2.item.Any(item => items.Contains(item.type)))
hasItem = true;
if (player.bank3.item.Any(item => items.Contains(item.type)))
hasItem = true;
return hasItem;
}
/// <summary>
/// Gives the player the specified number of immunity frames (or "iframes" for short).<br />If the player already has more iframes than you want to give them, this function does nothing.
/// </summary>
/// <param name="player">The player who should be given immunity frames.</param>
/// <param name="frames">The number of immunity frames to give.</param>
/// <param name="blink">Whether or not the player should be blinking during this time.</param>
/// <returns>Whether or not any immunity frames were given.</returns>
public static bool GiveIFrames(this Player player, int frames, bool blink = false)
{
// Check to see if there is any way for the player to get iframes from this operation.
bool anyIFramesWouldBeGiven = false;
for (int i = 0; i < player.hurtCooldowns.Length; ++i)
if (player.hurtCooldowns[i] < frames)
anyIFramesWouldBeGiven = true;
// If they would get nothing, don't do it.
if (!anyIFramesWouldBeGiven)
return false;
// Apply iframes thoroughly.
player.immune = true;
player.immuneNoBlink = !blink;
player.immuneTime = frames;
for (int i = 0; i < player.hurtCooldowns.Length; ++i)
if (player.hurtCooldowns[i] < frames)
player.hurtCooldowns[i] = frames;
return true;
}
public static void RemoveAllIFrames(this Player player)
{
player.immune = false;
player.immuneNoBlink = false;
player.immuneTime = 0;
for (int i = 0; i < player.hurtCooldowns.Length; ++i)
player.hurtCooldowns[i] = 0;
}
/// <summary>
/// Returns the damage multiplier Adrenaline Mode provides for the given player.
/// </summary>
/// <param name="mp">The player whose Adrenaline damage should be calculated.</param>
/// <returns>Adrenaline damage multiplier. 1.0 would be no change.</returns>
public static double GetAdrenalineDamage(this CalamityPlayer mp)
{
double adrenalineBoost = CalamityPlayer.AdrenalineDamageBoost;
if (mp.adrenalineBoostOne)
adrenalineBoost += CalamityPlayer.AdrenalineDamagePerBooster;
if (mp.adrenalineBoostTwo)
adrenalineBoost += CalamityPlayer.AdrenalineDamagePerBooster;
if (mp.adrenalineBoostThree)
adrenalineBoost += CalamityPlayer.AdrenalineDamagePerBooster;
return adrenalineBoost;
}
/// <summary>
/// Applies Rage and Adrenaline to the given damage multiplier. The values controlling the so-called "Rippers" can be found in CalamityPlayer.
/// </summary>
/// <param name="mp">The CalamityPlayer who may or may not be using Rage or Adrenaline.</param>
/// <param name="damageMult">A reference to the current in-use damage multiplier. This will be increased in-place.</param>
public static void ApplyRippersToDamage(CalamityPlayer mp, ref double damageMult)
{
// Rage and Adrenaline now stack additively with no special cases.
if (mp.rageModeActive)
damageMult += mp.RageDamageBoost;
if (mp.adrenalineModeActive)
damageMult += mp.GetAdrenalineDamage();
}
public static void Inflict246DebuffsPvp(Player target, int buff, float timeBase = 2f)
{
if (Main.rand.NextBool(4))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false);
}
else if (Main.rand.NextBool(2))
{
target.AddBuff(buff, SecondsToFrames(timeBase * 2f), false);
}
else
{
target.AddBuff(buff, SecondsToFrames(timeBase), false);
}
}
/// <summary>
/// Inflict typical exo weapon debuffs in pvp.
/// </summary>
/// <param name="target">The Player attacked.</param>
/// <param name="multiplier">Debuff time multiplier if needed.</param>
/// <returns>Inflicts debuffs if the target isn't immune.</returns>
public static void ExoDebuffs(this Player target, float multiplier = 1f)
{
target.AddBuff(BuffType<ExoFreeze>(), (int)(30 * multiplier));
target.AddBuff(BuffType<BrimstoneFlames>(), (int)(120 * multiplier));
target.AddBuff(BuffType<Plague>(), (int)(120 * multiplier));
target.AddBuff(BuffType<HolyFlames>(), (int)(120 * multiplier));
target.AddBuff(BuffID.CursedInferno, (int)(120 * multiplier));
target.AddBuff(BuffID.Frostburn, (int)(120 * multiplier));
target.AddBuff(BuffID.OnFire, (int)(120 * multiplier));
target.AddBuff(BuffID.Ichor, (int)(120 * multiplier));
}
/// <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 />
/// If server is true, the packet is sent to all clients except the player it pertains to.
/// </summary>
/// <param name="player">The player to whom the packet's data pertains.</param>
/// <param name="packet">The packet to send with certain parameters.</param>
/// <param name="server">True if a dedicated server is broadcasting information to all players.</param>
public static void SendPacket(this Player player, ModPacket packet, bool server)
{
// Client: Send the packet only to the host.
if (!server)
packet.Send();
// Server: Send the packet to every OTHER client.
else
packet.Send(-1, player.whoAmI);
}
}
}