1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using Terraria ;
34using Terraria . ID ;
45using Terraria . ModLoader ;
@@ -8,8 +9,11 @@ namespace ChensGradiusMod.Projectiles.Melee
89{
910 public class ZalkYoyoProjectile : ModProjectile
1011 {
12+ private const int Cooldown = 30 ;
1113 private const float AngleSpeed = 10f ;
1214
15+ private int cooldownTick = Cooldown ;
16+
1317 public List < Projectile > alliedZalks = new List < Projectile > ( ) ;
1418 public float currentAngle = 0f ;
1519
@@ -38,23 +42,28 @@ public override void SetDefaults()
3842
3943 public override void AI ( )
4044 {
45+ ProcessCooldown ( ) ;
4146 UpdateReferenceAngle ( ) ;
4247 DestroyAlliesWhenReturning ( ) ;
4348 }
4449
4550 public override void OnHitNPC ( NPC target , int damage , float knockback , bool crit )
4651 {
47- float xSpawn ;
48- if ( Owner . direction == 1 ) xSpawn = Main . screenPosition . X - 28 ;
49- else xSpawn = Main . screenPosition . X + Main . screenWidth + 28 ;
50- int newAllyInd = Projectile . NewProjectile ( xSpawn , projectile . Center . Y , 0 , 0 , ModContent . ProjectileType < AlliedZalk > ( ) ,
51- projectile . damage , projectile . knockBack ,
52- projectile . owner , projectile . whoAmI ) ;
53- if ( newAllyInd >= 0 )
52+ if ( cooldownTick >= Cooldown )
5453 {
55- Projectile newProj = Main . projectile [ newAllyInd ] ;
56- newProj . spriteDirection = Owner . direction ;
57- alliedZalks . Add ( newProj ) ;
54+ float xSpawn ;
55+ if ( Owner . direction == 1 ) xSpawn = Main . screenPosition . X - 28 ;
56+ else xSpawn = Main . screenPosition . X + Main . screenWidth + 28 ;
57+ int newAllyInd = Projectile . NewProjectile ( xSpawn , projectile . Center . Y , 0 , 0 , ModContent . ProjectileType < AlliedZalk > ( ) ,
58+ projectile . damage , projectile . knockBack ,
59+ projectile . owner , projectile . whoAmI ) ;
60+ if ( newAllyInd >= 0 )
61+ {
62+ Projectile newProj = Main . projectile [ newAllyInd ] ;
63+ newProj . spriteDirection = Owner . direction ;
64+ alliedZalks . Add ( newProj ) ;
65+ cooldownTick = 0 ;
66+ }
5867 }
5968 }
6069
@@ -69,6 +78,14 @@ public float AngleDifference
6978
7079 private Player Owner => Main . player [ projectile . owner ] ;
7180
81+ private void ProcessCooldown ( )
82+ {
83+ if ( IsSameClientOwner ( projectile ) )
84+ {
85+ cooldownTick = Math . Min ( cooldownTick + 1 , Cooldown ) ;
86+ }
87+ }
88+
7289 private void UpdateReferenceAngle ( )
7390 {
7491 currentAngle += AngleSpeed * Owner . direction ;
0 commit comments