Skip to content

Commit

Permalink
Fix #147: Change all readonly non-dynamic variables to const
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeeeeeeeeen committed Nov 10, 2019
1 parent c9d37b0 commit 0326327
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 133 deletions.
6 changes: 3 additions & 3 deletions Items/Accessories/Options/Miscellaneous/OptionSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ChensGradiusMod.Items.Accessories.Options.Miscellaneous
{
public class OptionSeed : ParentGradiusAccessory
{
private readonly string projectileName = "OptionSeedObject";
private const string ProjectileName = "OptionSeedObject";

public override void SetStaticDefaults()
{
Expand All @@ -35,10 +35,10 @@ public override void UpdateAccessory(Player player, bool hideVisual)

if (GradiusHelper.IsSameClientOwner(player))
{
if (player.ownedProjectileCounts[mod.ProjectileType(projectileName)] <= 0)
if (player.ownedProjectileCounts[mod.ProjectileType(ProjectileName)] <= 0)
{
int pInd = Projectile.NewProjectile(player.Center.X + OptionSeedObject.SeedDistance * player.direction,
player.Center.Y, 0f, 0f, mod.ProjectileType(projectileName), 0, 0f,
player.Center.Y, 0f, 0f, mod.ProjectileType(ProjectileName), 0, 0f,
player.whoAmI, 0f, 0f);
ModOwner(player).seedProjectile = Main.projectile[pInd];
}
Expand Down
32 changes: 16 additions & 16 deletions NPCs/BigCoreCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public class BigCoreCustom : GradiusEnemy
{
private const int FrameWidth = 192;
private const int FrameHeight = 130;
private const float RegularAssaultMaxSpeed = 30f;
private const float RegularAssaultAcceleration = 1f;
private const float RegularAssaultHorizontalGap = 600f;
private const int OpenCoreTime = 1200;
private const int MaxFrameIndex = 4;
private const int FireRate = 25;

private readonly int openCoreTime = 1200;
private readonly int maxFrameIndex = 4;
private readonly int fireRate = 25;
private bool openCore = false;
private States mode = States.RegularAssault;
private int fireTick = 0;
private int existenceTick = 0;
private int frameCounterX = 7;

private readonly float regularAssaultMaxSpeed = 30f;
private readonly float regularAssaultAcceleration = 1f;
private readonly float regularAssaultHorizontalGap = 600f;
private float regularAssaultXCurrentSpeed = 0f;
private float regularAssaultYCurrentSpeed = 0f;
private int regularAssaultDirection = 0;
Expand Down Expand Up @@ -202,13 +202,13 @@ private void RegularAssaultBehavior()

if (target.Center.Y > npc.Center.Y)
{
regularAssaultYCurrentSpeed += regularAssaultAcceleration;
regularAssaultYCurrentSpeed = Math.Min(regularAssaultYCurrentSpeed, regularAssaultMaxSpeed);
regularAssaultYCurrentSpeed += RegularAssaultAcceleration;
regularAssaultYCurrentSpeed = Math.Min(regularAssaultYCurrentSpeed, RegularAssaultMaxSpeed);
}
else if (target.Center.Y < npc.Center.Y)
{
regularAssaultYCurrentSpeed -= regularAssaultAcceleration;
regularAssaultYCurrentSpeed = Math.Max(regularAssaultYCurrentSpeed, -regularAssaultMaxSpeed);
regularAssaultYCurrentSpeed -= RegularAssaultAcceleration;
regularAssaultYCurrentSpeed = Math.Max(regularAssaultYCurrentSpeed, -RegularAssaultMaxSpeed);
}
npc.position.Y += regularAssaultYCurrentSpeed;
if (GradiusHelper.IsNotMultiplayerClient() &&
Expand All @@ -217,9 +217,9 @@ private void RegularAssaultBehavior()
npc.netUpdate = true;
}

float destinationX = target.Center.X + regularAssaultHorizontalGap * -regularAssaultDirection;
regularAssaultXCurrentSpeed += regularAssaultAcceleration;
regularAssaultXCurrentSpeed = Math.Min(regularAssaultXCurrentSpeed, regularAssaultMaxSpeed);
float destinationX = target.Center.X + RegularAssaultHorizontalGap * -regularAssaultDirection;
regularAssaultXCurrentSpeed += RegularAssaultAcceleration;
regularAssaultXCurrentSpeed = Math.Min(regularAssaultXCurrentSpeed, RegularAssaultMaxSpeed);
float newX = GradiusHelper.ApproachValue(npc.Center.X, destinationX, regularAssaultXCurrentSpeed);
if (newX == destinationX) regularAssaultXCurrentSpeed = 0f;
npc.Center = new Vector2(newX, npc.Center.Y);
Expand All @@ -229,7 +229,7 @@ private void PerformAttack()
{
if (GradiusHelper.IsNotMultiplayerClient() && mode != States.Exit)
{
if (++fireTick >= fireRate)
if (++fireTick >= FireRate)
{
fireTick = 0;

Expand Down Expand Up @@ -289,12 +289,12 @@ private void CoreManagement()
FrameCounter--;
}
}
else if (mode != States.Exit && !openCore && existenceTick >= openCoreTime)
else if (mode != States.Exit && !openCore && existenceTick >= OpenCoreTime)
{
if (++FrameTick >= FrameSpeed)
{
FrameTick = 0;
if (++FrameCounter >= maxFrameIndex) openCore = true;
if (++FrameCounter >= MaxFrameIndex) openCore = true;
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions NPCs/Ducker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ public class Ducker : GradiusEnemy
private const float CustomGravity = 8f;
private const int CancelThreshold = 500;
private const float AttackAngleDifference = 13f;

private readonly float runSpeed = 4f;
private readonly float fallSpeedYAccel = .5f;
private readonly float fallSpeedXAccel = .1f;
private readonly float targetDistance = 500f;
private readonly int syncRate = 30;
private const float RunSpeed = 4f;
private const float FallSpeedYAccel = .5f;
private const float FallSpeedXAccel = .1f;
private const float TargetDistance = 500f;
private const int SyncRate = 30;

private States mode = States.Run;
private States oldMode = States.Run;
Expand Down Expand Up @@ -199,11 +198,11 @@ public override void AI()
case States.Fall:
npc.velocity += new Vector2
{
X = fallSpeedXAccel * persistDirection,
Y = fallSpeedYAccel * yDirection
X = FallSpeedXAccel * persistDirection,
Y = FallSpeedYAccel * yDirection
};
if (persistDirection > 0) npc.velocity.X = Math.Min(npc.velocity.X, runSpeed);
else npc.velocity.X = Math.Max(npc.velocity.X, -runSpeed);
if (persistDirection > 0) npc.velocity.X = Math.Min(npc.velocity.X, RunSpeed);
else npc.velocity.X = Math.Max(npc.velocity.X, -RunSpeed);
if (yDirection > 0) npc.velocity.Y = Math.Min(npc.velocity.Y, CustomGravity);
else npc.velocity.Y = Math.Max(npc.velocity.Y, -CustomGravity);

Expand All @@ -229,7 +228,7 @@ public override void AI()
npc.velocity = new Vector2(0, 20f * -yDirection);
hasJumped = true;
}
else npc.velocity += new Vector2(fallSpeedXAccel * persistDirection, fallSpeedYAccel * yDirection);
else npc.velocity += new Vector2(FallSpeedXAccel * persistDirection, FallSpeedYAccel * yDirection);

if (hasJumped && ((yDirection > 0 && npc.velocity.Y >= 0) ||
(yDirection < 0 && npc.velocity.Y <= 0)))
Expand All @@ -254,7 +253,7 @@ public override void AI()
public override void PostAI()
{
base.PostAI();
if (!ConstantSync(ref syncTick, syncRate) && GradiusHelper.IsNotMultiplayerClient()
if (!ConstantSync(ref syncTick, SyncRate) && GradiusHelper.IsNotMultiplayerClient()
&& oldMode != mode)
{
npc.netUpdate = true;
Expand Down Expand Up @@ -287,7 +286,7 @@ public override void ReceiveExtraAI(BinaryReader reader)
yDirection = reader.ReadInt32();
hasJumped = reader.ReadBoolean();
targetLastSeen = reader.ReadVector2();
}
}

protected override int FrameSpeed { get; set; } = 5;

Expand Down Expand Up @@ -323,7 +322,7 @@ private void UsualMovement()
{
npc.velocity = new Vector2
{
X = runSpeed * persistDirection,
X = RunSpeed * persistDirection,
Y = CustomGravity * yDirection
};
}
Expand All @@ -332,7 +331,7 @@ private bool ConfirmTarget()
{
npc.TargetClosest(false);
targetLastSeen = Target.Center;
return Vector2.Distance(Target.Center, npc.Center) <= targetDistance
return Vector2.Distance(Target.Center, npc.Center) <= TargetDistance
&& ((yDirection > 0 && npc.Center.Y >= Target.Center.Y)
|| (yDirection < 0 && npc.Center.Y <= Target.Center.Y));
}
Expand Down
25 changes: 13 additions & 12 deletions NPCs/Garun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ namespace ChensGradiusMod.NPCs
{
public class Garun : GradiusEnemy
{
private readonly float waveFrequency = .05f;
private readonly float waveAmplitude = 150f;
private readonly float travelSpeed = 5f;
private readonly float attackDistance = 1200;
private readonly int fireRate = 20;
private readonly int syncRate = 120;
private const float WaveFrequency = .05f;
private const float WaveAmplitude = 150f;
private const float TravelSpeed = 5f;
private const float AttackDistance = 1200;
private const int FireRate = 20;
private const int SyncRate = 120;

private int timerTick = 0;
private bool targetDetermined = false;
private int persistDirection = 0;
Expand Down Expand Up @@ -66,13 +67,13 @@ public override void AI()

float xTo = (float)Math.Cos(GetDirection());
float yTo = (float)Math.Sin(GetDirection());
float wobble = waveAmplitude * (float)Math.Cos(waveFrequency * timerTick++) * waveFrequency;
npc.velocity.X += xTo * travelSpeed - yTo * wobble;
npc.velocity.Y += -yTo * travelSpeed + xTo * wobble;
float wobble = WaveAmplitude * (float)Math.Cos(WaveFrequency * timerTick++) * WaveFrequency;
npc.velocity.X += xTo * TravelSpeed - yTo * wobble;
npc.velocity.Y += -yTo * TravelSpeed + xTo * wobble;

PerformAttack();

ConstantSync(ref syncTick, syncRate);
ConstantSync(ref syncTick, SyncRate);
}

public override float SpawnChance(NPCSpawnInfo spawnInfo)
Expand Down Expand Up @@ -115,12 +116,12 @@ private double GetDirection()
private void PerformAttack()
{
if (GradiusHelper.IsNotMultiplayerClient() &&
Vector2.Distance(npc.Center, Main.player[npc.target].Center) <= attackDistance)
Vector2.Distance(npc.Center, Main.player[npc.target].Center) <= AttackDistance)
{
if ((npc.direction >= 0 && npc.Center.X <= Main.player[npc.target].Center.X) ||
(npc.direction <= 0 && npc.Center.X >= Main.player[npc.target].Center.X))
{
if (++fireTick >= fireRate)
if (++fireTick >= FireRate)
{
fireTick = 0;
Vector2 vel = GradiusHelper.MoveToward(npc.Center, Main.player[npc.target].Center, GradiusEnemyBullet.Spd);
Expand Down
12 changes: 6 additions & 6 deletions NPCs/Grazia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public class Grazia : GradiusEnemy
private const float DetectionRange = 800f;
private const int PersistDirection = -1;
private const float CustomGravity = 5f;
private const int FireRate = 50;
private const int CancelDeployThreshold = 500;
private const int SyncRate = 300;

private readonly int[] directLowerAngleAim = { 0, 21, 41, 61, 81, 100, 120, 140, 160 };
private readonly int[] directHigherAngleAim = { 20, 40, 60, 80, 99, 119, 139, 159, 180 };
private readonly int[] directFrameAngleAim = { 8, 7, 6, 5, 4, 3, 2, 1, 0 };
private readonly int[] inverseLowerAngleAim = { 180, 201, 221, 241, 261, 280, 300, 320, 340 };
private readonly int[] inverseHigherAngleAim = { 200, 220, 240, 260, 279, 299, 319, 339, 360 };
private readonly int[] inverseFrameAngleAim = { 17, 16, 15, 14, 13, 12, 11, 10, 9 };
private readonly int fireRate = 50;
private readonly int cancelDeployThreshold = 500;
private readonly int syncRate = 600;

private int yDirection = 0;
private int fireTick = 0;
Expand Down Expand Up @@ -66,7 +66,7 @@ public override void AI()

if (yDirection == 0)
{
yDirection = DecideYDeploy(npc.height * .5f, cancelDeployThreshold);
yDirection = DecideYDeploy(npc.height * .5f, CancelDeployThreshold);
if (yDirection == 0) return;
if (yDirection < 0) npc.frame.Y = 416;
}
Expand All @@ -82,7 +82,7 @@ public override void AI()
else fireTick = 0;
}

ConstantSync(ref syncTick, syncRate);
ConstantSync(ref syncTick, SyncRate);
}

public override void FindFrame(int frameHeight)
Expand Down Expand Up @@ -167,7 +167,7 @@ private int DetectTarget()

private void PerformAttack()
{
if (++fireTick >= fireRate)
if (++fireTick >= FireRate)
{
fireTick = 0;
Vector2 vel = GradiusHelper.MoveToward(npc.Center, Main.player[npc.target].Center, GradiusEnemyBullet.Spd);
Expand Down
13 changes: 6 additions & 7 deletions NPCs/Moai.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ namespace ChensGradiusMod.NPCs
public class Moai : GradiusEnemy
{
private const float DetectionRange = 1400f;

private readonly int attackTickDelay = 5;
private readonly int restingTime = 40;
private readonly int vulnerableTime = 10;
private const int AttackTickDelay = 5;
private const int RestingTime = 40;
private const int VulnerableTime = 20;

private int persistDirection = 0;
private int mode = (int)States.Dormant;
Expand Down Expand Up @@ -81,7 +80,7 @@ public override void AI()
}
break;
case (int)States.Aggressive:
if (++attackTick >= attackTickDelay)
if (++attackTick >= AttackTickDelay)
{
attackTick = 0;
PerformAttack();
Expand All @@ -93,14 +92,14 @@ public override void AI()
}
break;
case (int)States.Vulnerable:
if (++vulnerableTick >= vulnerableTime)
if (++vulnerableTick >= VulnerableTime)
{
vulnerableTick = 0;
mode = (int)States.Resting;
}
break;
case (int)States.Resting:
if (++restTick >= restingTime)
if (++restTick >= RestingTime)
{
restTick = 0;
mode = (int)States.Dormant;
Expand Down
Loading

0 comments on commit 0326327

Please sign in to comment.