86 lines
3.3 KiB
C#
86 lines
3.3 KiB
C#
using Siva.Projectiles;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
|
|
|
|
namespace Siva.Buffs
|
|
{
|
|
public class Parasitism : ModBuff
|
|
{
|
|
public static readonly int BuffType = ModContent.BuffType<Parasitism>();
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.debuff[Type] = true; // Indicates this is a negative effect.
|
|
Main.buffNoSave[Type] = true; // Indicates that the buff won't save when exiting the game.
|
|
Main.buffNoTimeDisplay[Type] = false; // Shows the duration on the buff icon.
|
|
}
|
|
|
|
// What happens while the debuff is a applied
|
|
public override void Update(NPC npc, ref int buffIndex)
|
|
{
|
|
// Do I make them glow red or anything?
|
|
}
|
|
|
|
public static int AttachedNaniteCount(NPC npc)
|
|
{
|
|
int attachedNanites = 0;
|
|
foreach (var p in Main.ActiveProjectiles)
|
|
{
|
|
if (p.type == SIVANanite.ProjectileType && p.ai[0] == 1f && p.ai[1] == npc.whoAmI) {
|
|
attachedNanites++;
|
|
// Main.NewText($"{attachedNanites}"); // Debug text
|
|
}
|
|
}
|
|
return attachedNanites;
|
|
}
|
|
|
|
public static float GetParasitismScaleFactor(int attachedNanites)
|
|
{
|
|
if(attachedNanites <= 5)
|
|
{
|
|
return attachedNanites*0.3f;
|
|
}
|
|
else if(attachedNanites > 5 && attachedNanites < 100)
|
|
{
|
|
return (attachedNanites-5)*0.021f+1.5f;
|
|
}
|
|
else if(attachedNanites >= 100)
|
|
{
|
|
return 3.5f;
|
|
}
|
|
else
|
|
{
|
|
return 0f;
|
|
}
|
|
}
|
|
|
|
public class ParasitismScaling : GlobalNPC
|
|
{
|
|
public override bool InstancePerEntity => true;
|
|
|
|
public override void ModifyHitByProjectile(NPC npc, Projectile projectile, ref NPC.HitModifiers modifiers)
|
|
{
|
|
if(LogicPerfected.ParasitismOnTarget(npc) && projectile.owner == Main.myPlayer) // Check to make sure the projectile is the local players rather than any other projectils from any other gun. Trying to prevent hypothetical exploits.
|
|
{
|
|
if(LogicPerfected.NormBullet(projectile))
|
|
{
|
|
float scaleFactor = GetParasitismScaleFactor(AttachedNaniteCount(npc));
|
|
AddableFloat addableScaleFactor = AddableFloat.Zero + scaleFactor;
|
|
modifiers.ScalingBonusDamage = addableScaleFactor;
|
|
Main.NewText($"norm {scaleFactor}"); // debug text
|
|
}
|
|
else if(LogicPerfected.MasterBulletOrNanite(projectile))
|
|
{
|
|
float scaleFactor = GetParasitismScaleFactor(AttachedNaniteCount(npc));
|
|
AddableFloat addableScaleFactor = AddableFloat.Zero + scaleFactor;
|
|
modifiers.ScalingBonusDamage = addableScaleFactor;
|
|
Main.NewText($"master {scaleFactor}"); // debug text
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|