Finished porting npc loops

This commit is contained in:
BasicallyIAmFox committed 2024-05-08 17:34:00 +05:00
1 parent e2628cd096
commit 1a85f860e9
119 files changed
+424 -585

No files matched your search

@@ -627,14 +627,14 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
if (Main.getGoodWorld)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].active && Main.npc[i].aiStyle == NPCAIStyleID.PlanteraHook)
if (n.aiStyle == NPCAIStyleID.PlanteraHook)
{
for (int j = 0; j < totalTentacles / 2 - 1; j++)
{
int hookIndex = NPC.NewNPC(npc.GetSource_FromAI(), (int)npc.Center.X, (int)npc.Center.Y, NPCID.PlanterasTentacle, npc.whoAmI);
Main.npc[hookIndex].ai[3] = i + 1;
Main.npc[hookIndex].ai[3] = n.whoAmI + 1;
}
}
}
@@ -96,14 +96,14 @@ namespace CalamityMod.Projectiles.DraedonsArsenal
{
if (arcs < 10)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (!Main.npc[i].CanBeChasedBy(Projectile, false) || !Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (!n.CanBeChasedBy(Projectile, false) || !Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
continue;
if (Projectile.Center.ManhattanDistance(Main.npc[i].Center) < 600f)
if (Projectile.Center.ManhattanDistance(n.Center) < 600f)
{
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.SafeDirectionTo(Main.npc[i].Center) * 2f, Projectile.type, (int)(Projectile.damage * 0.6), Projectile.knockBack * 0.6f, Projectile.owner, 0f, -1f);
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.SafeDirectionTo(n.Center) * 2f, Projectile.type, (int)(Projectile.damage * 0.6), Projectile.knockBack * 0.6f, Projectile.owner, 0f, -1f);
Projectile.ai[1] = 60f;
+6 -6
View File
@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ModLoader;
@@ -57,14 +57,14 @@ namespace CalamityMod.Projectiles.Magic
if (Projectile.ai[0] > 30f)
{
Projectile.ai[0] = 30f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && !Main.npc[i].wet)
if (n.CanBeChasedBy(Projectile, false) && !n.wet)
{
float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float npcX = n.position.X + (float)(n.width / 2);
float npcY = n.position.Y + (float)(n.height / 2);
float npcDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcY);
if (npcDist < 800f && npcDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
if (npcDist < 800f && npcDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height))
{
homingRange = npcDist;
projX = npcX;
+5 -5
View File
@@ -93,15 +93,15 @@ namespace CalamityMod.Projectiles.Magic
float inertia = 25f;
float homingSpeed = 23f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (homingRange + extraDistance))
if (Vector2.Distance(n.Center, Projectile.Center) < (homingRange + extraDistance))
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+5 -5
View File
@@ -75,17 +75,17 @@ namespace CalamityMod.Projectiles.Magic
//Detect if any enemies are very close
int maxDistance = 10;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2);
float extraDistance = (n.width / 2) + (n.height / 2);
bool canHit = true;
if (extraDistance < maxDistance)
canHit = Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1);
canHit = Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1);
if (Projectile.WithinRange(Main.npc[i].Center, maxDistance + extraDistance) && canHit)
if (Projectile.WithinRange(n.Center, maxDistance + extraDistance) && canHit)
{
neartarget = true;
}
+5 -5
View File
@@ -169,17 +169,17 @@ namespace CalamityMod.Projectiles.Magic
int npcTrack = 0;
if (Projectile.ai[1] == 0f)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(this))
if (n.CanBeChasedBy(this))
{
Vector2 npcCenter = Main.npc[i].Center;
if (Projectile.Distance(npcCenter) < homingRange && Collision.CanHit(new Vector2(Projectile.position.X + Projectile.width / 2, Projectile.position.Y + Projectile.height / 2), 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
Vector2 npcCenter = n.Center;
if (Projectile.Distance(npcCenter) < homingRange && Collision.CanHit(new Vector2(Projectile.position.X + Projectile.width / 2, Projectile.position.Y + Projectile.height / 2), 1, 1, n.position, n.width, n.height))
{
homingRange = Projectile.Distance(npcCenter);
projCenter = npcCenter;
isHoming = true;
npcTrack = i;
npcTrack = n.whoAmI;
}
}
}
+4 -4
View File
@@ -68,12 +68,12 @@ namespace CalamityMod.Projectiles.Magic
float projY = Projectile.Center.Y;
float explodeRange = 250f;
bool canExplode = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float npcX = n.position.X + (float)(n.width / 2);
float npcY = n.position.Y + (float)(n.height / 2);
float npcDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcY);
if (npcDist < explodeRange)
{
+1 -3
View File
@@ -67,10 +67,8 @@ namespace CalamityMod.Projectiles.Magic
float bestScore = 0;
NPC bestTarget = null;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC potentialTarget in Main.ActiveNPCs)
{
NPC potentialTarget = Main.npc[i];
if (!potentialTarget.CanBeChasedBy(null, false))
continue;
+2 -4
View File
@@ -94,11 +94,9 @@ namespace CalamityMod.Projectiles.Magic
{
float collisionPoint = 0f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC struckNPC in Main.ActiveNPCs)
{
NPC struckNPC = Main.npc[i];
if (!struckNPC.active || struckNPC.townNPC || struckNPC.friendly)
if (struckNPC.townNPC || struckNPC.friendly)
continue;
float distance = struckNPC.Distance(Projectile.Center);
@@ -73,21 +73,19 @@ namespace CalamityMod.Projectiles.Melee
else
{
float homingRange = 1000f;
int inc;
for (int i = 0; i < Main.maxNPCs; i = inc + 1)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float npcX = n.position.X + (float)(n.width / 2);
float npcY = n.position.Y + (float)(n.height / 2);
float npcDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcY);
if (npcDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
if (npcDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height))
{
homingRange = npcDist;
Projectile.ai[0] = (float)i;
Projectile.ai[0] = (float)n.whoAmI;
}
}
inc = i;
}
}
+3 -4
View File
@@ -115,10 +115,9 @@ namespace CalamityMod.Projectiles.Melee
return;
Player owner = Main.player[Projectile.owner];
for (int i = 0; i < Main.npc.Length; ++i)
foreach (NPC target in Main.ActiveNPCs)
{
NPC target = Main.npc[i];
if (!target.active || target.dontTakeDamage || target.friendly)
if (target.dontTakeDamage || target.friendly)
continue;
// Shock any valid target within range. Check all four corners of their hitbox.
@@ -137,7 +136,7 @@ namespace CalamityMod.Projectiles.Melee
target.StrikeNPC(target.CalculateHitInfo(damage, 0, crit, 0));
if (Main.netMode != NetmodeID.SinglePlayer)
NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, i, damage, 0f, 0f, crit ? 1 : 0, 0, 0);
NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, target.whoAmI, damage, 0f, 0f, crit ? 1 : 0, 0, 0);
}
}
}
+4 -5
View File
@@ -165,21 +165,20 @@ namespace CalamityMod.Projectiles.Melee
//find a nearby NPC to track
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
bool hasHitNPC = false;
for (int j = 0; j < previousNPCs.Count; j++)
{
if (previousNPCs[j] == i)
if (previousNPCs[j] == npc.whoAmI)
{
hasHitNPC = true;
}
}
NPC npc = Main.npc[i];
if (npc == target)
{
previousNPCs.Add(i);
previousNPCs.Add(npc.whoAmI);
}
if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC)
{
@@ -187,7 +186,7 @@ namespace CalamityMod.Projectiles.Melee
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+4 -4
View File
@@ -46,12 +46,12 @@ namespace CalamityMod.Projectiles.Melee
float targetY = Projectile.Center.Y;
bool foundTarget = false;
float maxRange = MaxHomingRange;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
float iterCenterX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float iterCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float iterCenterX = n.position.X + (float)(n.width / 2);
float iterCenterY = n.position.Y + (float)(n.height / 2);
float dist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - iterCenterX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - iterCenterY);
if (dist < maxRange)
{
+2 -3
View File
@@ -191,13 +191,12 @@ namespace CalamityMod.Projectiles.Melee
Rectangle myRect = Projectile.Hitbox;
if (Projectile.owner == Main.myPlayer)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
bool voodooDolls = Projectile.owner < Main.maxPlayers && (npc.type == NPCID.Guide && player.killGuide || npc.type == NPCID.Clothier && player.killClothier);
bool friendlyProjs = Projectile.friendly && (!npc.friendly || voodooDolls);
bool hostileProjs = Projectile.hostile && npc.friendly && !npc.dontTakeDamageFromHostiles;
if (npc.active && !npc.dontTakeDamage && (friendlyProjs || hostileProjs) && (Projectile.owner < 0 || npc.immune[Projectile.owner] == 0 || Projectile.maxPenetrate == 1))
if (!npc.dontTakeDamage && (friendlyProjs || hostileProjs) && (Projectile.owner < 0 || npc.immune[Projectile.owner] == 0 || Projectile.maxPenetrate == 1))
{
if (npc.noTileCollide || !Projectile.ownerHitCheck || (ProjectileLoader.CanHitNPC(Projectile, npc) ?? false))
{
+1 -2
View File
@@ -88,9 +88,8 @@ namespace CalamityMod.Projectiles.Melee
{
float longestReach = MaxProjReach;
NPC target = null;
for (int i = 0; i < Main.maxNPCs; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC)
{
float distance = Vector2.Distance(hitFrom, npc.Center);
+2 -3
View File
@@ -79,16 +79,15 @@ namespace CalamityMod.Projectiles.Melee
{
int npcTracker = -1;
float homingRange = 60f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC in Main.ActiveNPCs)
{
NPC nPC = Main.npc[i];
if (nPC.CanBeChasedBy(Projectile, false))
{
float npcDistance = Projectile.Distance(nPC.Center);
if (npcDistance < homingRange && Collision.CanHitLine(Projectile.Center, 0, 0, nPC.Center, 0, 0))
{
homingRange = npcDistance;
npcTracker = i;
npcTracker = nPC.whoAmI;
}
}
}
+2 -3
View File
@@ -80,16 +80,15 @@ namespace CalamityMod.Projectiles.Melee
{
int npcTracker = -1;
float homingRange = 60f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC in Main.ActiveNPCs)
{
NPC nPC = Main.npc[i];
if (nPC.CanBeChasedBy(Projectile, false))
{
float npcDistance = Projectile.Distance(nPC.Center);
if (npcDistance < homingRange && Collision.CanHitLine(Projectile.Center, 0, 0, nPC.Center, 0, 0))
{
homingRange = npcDistance;
npcTracker = i;
npcTracker = nPC.whoAmI;
}
}
}
+2 -3
View File
@@ -79,16 +79,15 @@ namespace CalamityMod.Projectiles.Melee
{
int npcTracker = -1;
float homingRange = 60f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC in Main.ActiveNPCs)
{
NPC nPC = Main.npc[i];
if (nPC.CanBeChasedBy(Projectile, false))
{
float npcDistance = Projectile.Distance(nPC.Center);
if (npcDistance < homingRange && Collision.CanHitLine(Projectile.Center, 0, 0, nPC.Center, 0, 0))
{
homingRange = npcDistance;
npcTracker = i;
npcTracker = nPC.whoAmI;
}
}
}
@@ -132,9 +132,8 @@ namespace CalamityMod.Projectiles.Melee
{
float longestReach = MaxTangleReach;
NPC target = null;
for (int i = 0; i < Main.maxNPCs; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC)
{
float distance = Vector2.Distance(hitFrom, npc.Center);
+3 -4
View File
@@ -115,17 +115,16 @@ namespace CalamityMod.Projectiles.Melee
// Find the closest NPC targetable
float range = MaxHomingRange;
int targetNPC = -1;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC target in Main.ActiveNPCs)
{
NPC target = Main.npc[i];
if (!target.CanBeChasedBy(Projectile) || PreviousNPCs.Contains(i))
if (!target.CanBeChasedBy(Projectile) || PreviousNPCs.Contains(target.whoAmI))
continue;
float distance = Vector2.Distance(target.Center, Projectile.Center);
if (distance < range && Collision.CanHit(Projectile, target))
{
range = distance;
targetNPC = i;
targetNPC = target.whoAmI;
}
}
@@ -121,9 +121,8 @@ namespace CalamityMod.Projectiles.Melee
int whoAmI = -1;
Vector2 targetSpot = Projectile.Center;
float detectRange = 700f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float targetDist = Vector2.Distance(npc.Center, Projectile.Center);
@@ -131,7 +130,7 @@ namespace CalamityMod.Projectiles.Melee
{
detectRange = targetDist;
targetSpot = npc.Center;
whoAmI = i;
whoAmI = npc.whoAmI;
}
}
}
@@ -103,9 +103,8 @@ namespace CalamityMod.Projectiles.Melee
int whoAmI = -1;
Vector2 targetSpot = Projectile.Center;
float detectRange = 700f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float targetDist = Vector2.Distance(npc.Center, Projectile.Center);
@@ -113,7 +112,7 @@ namespace CalamityMod.Projectiles.Melee
{
detectRange = targetDist;
targetSpot = npc.Center;
whoAmI = i;
whoAmI = npc.whoAmI;
}
}
}
+1 -2
View File
@@ -82,9 +82,8 @@ namespace CalamityMod.Projectiles.Melee
}
float projX = Projectile.Center.X;
float projY = Projectile.Center.Y;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
{
float npcCenterX = npc.position.X + (float)(npc.width / 2);
@@ -142,9 +142,8 @@ namespace CalamityMod.Projectiles.Melee
{
float longestReach = MaxTangleReach;
NPC target = null;
for (int i = 0; i < Main.maxNPCs; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC)
{
float distance = Vector2.Distance(hitFrom, npc.Center);
+2 -3
View File
@@ -29,15 +29,14 @@ namespace CalamityMod.Projectiles.Melee
{
float maxRange = 100f;
int npcIndex = -1;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height))
{
float targetDist = (npc.Center - Projectile.Center).Length();
if (targetDist < maxRange)
{
npcIndex = i;
npcIndex = npc.whoAmI;
maxRange = targetDist;
}
}
+2 -6
View File
@@ -88,19 +88,15 @@ namespace CalamityMod.Projectiles.Melee
int targetIdx = -1;
float maxHomingRange = 400f;
bool hasHomingTarget = false;
for (int i = 0; i < Main.npc.Length; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc == null || !npc.active)
continue;
// Won't home in through walls and won't chase invulnerable targets.
if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < maxHomingRange)
{
targetIdx = i;
targetIdx = npc.whoAmI;
maxHomingRange = dist;
hasHomingTarget = true;
}
+1 -3
View File
@@ -132,10 +132,8 @@ namespace CalamityMod.Projectiles.Melee
float bestScore = 0;
NPC bestTarget = null;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC potentialTarget in Main.ActiveNPCs)
{
NPC potentialTarget = Main.npc[i];
if (!potentialTarget.CanBeChasedBy(null, false))
continue;
+3 -7
View File
@@ -65,19 +65,15 @@ namespace CalamityMod.Projectiles.Melee.Yoyos
{
List<int> targets = new List<int>();
float laserRange = 300f;
for (int i = 0; i < Main.npc.Length; ++i)
foreach (NPC n in Main.ActiveNPCs)
{
ref NPC n = ref Main.npc[i];
if (n is null || !n.active)
continue;
if (n.CanBeChasedBy(Projectile, false) && (n.Center - Projectile.Center).Length() <= laserRange && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
targets.Add(i);
targets.Add(n.whoAmI);
// Bosses are added 5 times instead of 1 so that they are preferentially but not exclusively targeted.
if (n.boss)
for (int j = 0; j < 4; ++j)
targets.Add(i);
targets.Add(n.whoAmI);
}
}
if (targets.Count == 0)
+3 -4
View File
@@ -221,10 +221,9 @@ namespace CalamityMod.Projectiles.Melee.Yoyos
return;
Player owner = Main.player[Projectile.owner];
for (int i = 0; i < Main.maxNPCs; ++i)
foreach (NPC target in Main.ActiveNPCs)
{
NPC target = Main.npc[i];
if (!target.active || target.dontTakeDamage || target.friendly)
if (target.dontTakeDamage || target.friendly)
continue;
// Shock any valid target within range. Check all four corners of their hitbox.
@@ -241,7 +240,7 @@ namespace CalamityMod.Projectiles.Melee.Yoyos
int finalDamage = (int)owner.GetTotalDamage<MeleeDamageClass>().ApplyTo(baseDamage);
if (Projectile.owner == Main.myPlayer)
{
Projectile p = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), target.Center, Vector2.Zero, ModContent.ProjectileType<DirectStrike>(), finalDamage, 0f, Projectile.owner, i);
Projectile p = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), target.Center, Vector2.Zero, ModContent.ProjectileType<DirectStrike>(), finalDamage, 0f, Projectile.owner, target.whoAmI);
if (p.whoAmI.WithinBounds(Main.maxProjectiles))
p.DamageType = DamageClass.MeleeNoSpeed;
}
+3 -5
View File
@@ -73,11 +73,9 @@ namespace CalamityMod.Projectiles.Ranged
int possibleTarget = -1;
float closestDistance = 700f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.active && npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly &&
if (npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly &&
!npc.immortal && Collision.CanHit(Projectile.Center, 0, 0, npc.Center, 0, 0))
{
float distance = Vector2.Distance(Projectile.Center, npc.Center);
@@ -85,7 +83,7 @@ namespace CalamityMod.Projectiles.Ranged
if (closestDistance > distance)
{
closestDistance = distance;
possibleTarget = i;
possibleTarget = npc.whoAmI;
}
}
}
+3 -3
View File
@@ -71,10 +71,10 @@ namespace CalamityMod.Projectiles.Ranged
Projectile.scale = MathHelper.Lerp(0.001f, 1f, Utils.GetLerpValue(0f, 25f, Time, true));
if (Projectile.localAI[0] == 0f)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile.GetSource_FromThis(), false))
NPCDestination = Main.npc[i].Center + Main.npc[i].velocity * 5f;
if (n.CanBeChasedBy(Projectile.GetSource_FromThis(), false))
NPCDestination = n.Center + n.velocity * 5f;
}
InitialCenter = Projectile.Center;
Projectile.localAI[0] = 1f;
+6 -6
View File
@@ -84,20 +84,20 @@ namespace CalamityMod.Projectiles.Ranged
int targetID = 0;
if (Projectile.ai[1] == 0f)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && (Projectile.ai[1] == 0f || Projectile.ai[1] == (float)(i + 1)))
if (n.CanBeChasedBy(Projectile, false) && (Projectile.ai[1] == 0f || Projectile.ai[1] == (float)(i + 1)))
{
float targetX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float targetY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float targetX = n.position.X + (float)(n.width / 2);
float targetY = n.position.Y + (float)(n.height / 2);
float targetDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - targetX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - targetY);
if (targetDist < constant && Collision.CanHit(new Vector2(Projectile.position.X + (float)(Projectile.width / 2), Projectile.position.Y + (float)(Projectile.height / 2)), 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
if (targetDist < constant && Collision.CanHit(new Vector2(Projectile.position.X + (float)(Projectile.width / 2), Projectile.position.Y + (float)(Projectile.height / 2)), 1, 1, n.position, n.width, n.height))
{
constant = targetDist;
projX = targetX;
projY = targetY;
canHit = true;
targetID = i;
targetID = n.whoAmI;
}
}
}
+4 -4
View File
@@ -36,11 +36,11 @@ namespace CalamityMod.Projectiles.Ranged
Vector2 targetCenter = Projectile.Center;
float minTargetDistance = 2500f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
float distanceFromTarget = Projectile.Center.ManhattanDistance(Main.npc[i].Center);
float distanceFromTarget = Projectile.Center.ManhattanDistance(n.Center);
if (distanceFromTarget < 200f)
{
if (Projectile.owner == Main.myPlayer)
@@ -58,7 +58,7 @@ namespace CalamityMod.Projectiles.Ranged
else if (distanceFromTarget < minTargetDistance)
{
minTargetDistance = distanceFromTarget;
targetCenter = Main.npc[i].Center;
targetCenter = n.Center;
homeIn = true;
}
}
@@ -87,9 +87,8 @@ namespace CalamityMod.Projectiles.Ranged
bool bossFound = false;
int life = 0;
Vector2 targetVec = Projectile.Center;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (bossFound && !npc.IsABoss())
continue;
if (npc.CanBeChasedBy(Projectile, false))
+1 -2
View File
@@ -84,9 +84,8 @@ namespace CalamityMod.Projectiles.Ranged
if (!homeIn)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float extraDistance = (npc.width / 2) + (npc.height / 2);
+5 -6
View File
@@ -72,16 +72,15 @@ namespace CalamityMod.Projectiles.Rogue
//Home in
float maxDistance = 800f;
int targetIndex = -1;
int i;
for (i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2);
float extraDistance = (n.width / 2) + (n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance))
{
targetIndex = i;
targetIndex = n.whoAmI;
break;
}
}
+2 -3
View File
@@ -57,16 +57,15 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = -1;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+5 -6
View File
@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
@@ -47,21 +47,20 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
bool hasHitNPC = false;
for (int j = 0; j < previousNPCs.Count; j++)
{
if (previousNPCs[j] == i)
if (previousNPCs[j] == npc.whoAmI)
{
hasHitNPC = true;
}
}
NPC npc = Main.npc[i];
if (npc == target)
{
previousNPCs.Add(i);
previousNPCs.Add(npc.whoAmI);
}
if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC)
{
@@ -69,7 +68,7 @@ namespace CalamityMod.Projectiles.Rogue
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+4 -5
View File
@@ -59,21 +59,20 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
bool hasHitNPC = false;
for (int j = 0; j < previousNPCs.Count; j++)
{
if (previousNPCs[j] == i)
if (previousNPCs[j] == npc.whoAmI)
{
hasHitNPC = true;
}
}
NPC npc = Main.npc[i];
if (npc == target)
{
previousNPCs.Add(i);
previousNPCs.Add(npc.whoAmI);
}
if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC)
{
@@ -81,7 +80,7 @@ namespace CalamityMod.Projectiles.Rogue
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+4 -4
View File
@@ -55,16 +55,16 @@ namespace CalamityMod.Projectiles.Rogue
{
int index = -1;
float otherConstant = 300f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
Vector2 npcCenter = Main.npc[i].Center;
Vector2 npcCenter = n.Center;
float targetDist = Vector2.Distance(npcCenter, Projectile.Center);
if (targetDist < otherConstant && index == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, npcCenter, 1, 1))
{
otherConstant = targetDist;
index = i;
index = n.whoAmI;
}
}
}
+1 -2
View File
@@ -116,9 +116,8 @@ namespace CalamityMod.Projectiles.Rogue
float maxDistance = 300f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float extraDistance = npc.width / 2 + npc.height / 2;
+2 -3
View File
@@ -73,16 +73,15 @@ namespace CalamityMod.Projectiles.Rogue
float minDist = 999f;
int index = 0;
// Get the closest enemy to the axe
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+3 -4
View File
@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
@@ -30,16 +30,15 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
@@ -168,18 +168,18 @@ namespace CalamityMod.Projectiles.Rogue
float closestNPCDistance = 10000f;
float targettingDistance = 400f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (i == target.whoAmI)
if (n.whoAmI == target.whoAmI)
continue;
if (Main.npc[i].CanBeChasedBy(Projectile))
if (n.CanBeChasedBy(Projectile))
{
float potentialNewDistance = (Projectile.Center - Main.npc[i].Center).Length();
float potentialNewDistance = (Projectile.Center - n.Center).Length();
if (potentialNewDistance < targettingDistance && potentialNewDistance < closestNPCDistance)
{
closestNPCDistance = potentialNewDistance;
newTarget = Main.npc[i];
newTarget = n;
}
}
}
+5 -6
View File
@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Terraria;
@@ -70,21 +70,20 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
bool hasHitNPC = false;
for (int j = 0; j < previousNPCs.Count; j++)
{
if (previousNPCs[j] == i)
if (previousNPCs[j] == npc.whoAmI)
{
hasHitNPC = true;
}
}
NPC npc = Main.npc[i];
if (npc == target)
{
previousNPCs.Add(i);
previousNPCs.Add(npc.whoAmI);
}
if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC)
{
@@ -92,7 +91,7 @@ namespace CalamityMod.Projectiles.Rogue
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+5 -6
View File
@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Terraria;
@@ -70,21 +70,20 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
bool hasHitNPC = false;
for (int j = 0; j < previousNPCs.Count; j++)
{
if (previousNPCs[j] == i)
if (previousNPCs[j] == npc.whoAmI)
{
hasHitNPC = true;
}
}
NPC npc = Main.npc[i];
if (npc == target)
{
previousNPCs.Add(i);
previousNPCs.Add(npc.whoAmI);
}
if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC)
{
@@ -92,7 +91,7 @@ namespace CalamityMod.Projectiles.Rogue
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+5 -5
View File
@@ -51,15 +51,15 @@ namespace CalamityMod.Projectiles.Rogue
float maxDistance = Projectile.Calamity().stealthStrike ? 800f : 400f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+2 -3
View File
@@ -64,10 +64,9 @@ namespace CalamityMod.Projectiles.Rogue
int buffType = ModContent.BuffType<GlacialState>();
float radius = 112f; // 7 blocks
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC in Main.ActiveNPCs)
{
NPC nPC = Main.npc[i];
if (nPC.active && !nPC.dontTakeDamage && !nPC.buffImmune[buffType] && Vector2.Distance(Projectile.Center, nPC.Center) <= radius)
if (!nPC.dontTakeDamage && !nPC.buffImmune[buffType] && Vector2.Distance(Projectile.Center, nPC.Center) <= radius)
{
if (nPC.FindBuffIndex(buffType) == -1)
nPC.AddBuff(buffType, 60, false);
+3 -4
View File
@@ -128,10 +128,9 @@ namespace CalamityMod.Projectiles.Rogue
bool bossFound = false;
int target = -1;
float minDist = HomingStartRange;
for (int i = 0; i < Main.maxNPCs; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (!npc.active || npc.type == NPCID.TargetDummy)
if (npc.type == NPCID.TargetDummy)
continue;
// If we've found a valid boss target, ignore ALL targets which aren't bosses.
@@ -149,7 +148,7 @@ namespace CalamityMod.Projectiles.Rogue
if (npc.boss)
bossFound = true;
minDist = distToNPC;
target = i;
target = npc.whoAmI;
}
}
}
+3 -4
View File
@@ -137,10 +137,9 @@ namespace CalamityMod.Projectiles.Rogue
bool bossFound = false;
int target = -1;
float minDist = HomingStartRange;
for (int i = 0; i < Main.maxNPCs; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (!npc.active || npc.type == NPCID.TargetDummy)
if (npc.type == NPCID.TargetDummy)
continue;
// If we've found a valid boss target, ignore ALL targets which aren't bosses.
@@ -158,7 +157,7 @@ namespace CalamityMod.Projectiles.Rogue
if (npc.boss)
bossFound = true;
minDist = distToNPC;
target = i;
target = npc.whoAmI;
}
}
}
+3 -4
View File
@@ -1,4 +1,4 @@
using CalamityMod.Buffs.DamageOverTime;
using Microsoft.Xna.Framework;
using Terraria;
@@ -65,16 +65,15 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+2 -3
View File
@@ -64,16 +64,15 @@ namespace CalamityMod.Projectiles.Rogue
// Follow Enemy
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+11 -11
View File
@@ -1,4 +1,4 @@
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.CalPlayer;
using CalamityMod.Dusts;
using Microsoft.Xna.Framework;
@@ -41,30 +41,30 @@ namespace CalamityMod.Projectiles.Rogue
float projY = Projectile.Center.Y;
float homeRange = Projectile.Calamity().stealthStrike ? 1800f : 600f;
float homingSpeed = 0.25f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
{
float npcCenterX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float npcCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float npcCenterX = n.position.X + (float)(n.width / 2);
float npcCenterY = n.position.Y + (float)(n.height / 2);
float targetDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcCenterX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcCenterY);
if (targetDist < homeRange)
{
if (Main.npc[i].position.X < projX)
if (n.position.X < projX)
{
Main.npc[i].velocity.X += homingSpeed;
n.velocity.X += homingSpeed;
}
else
{
Main.npc[i].velocity.X -= homingSpeed;
n.velocity.X -= homingSpeed;
}
if (Main.npc[i].position.Y < projY)
if (n.position.Y < projY)
{
Main.npc[i].velocity.Y += homingSpeed;
n.velocity.Y += homingSpeed;
}
else
{
Main.npc[i].velocity.Y -= homingSpeed;
n.velocity.Y -= homingSpeed;
}
}
}
+1 -2
View File
@@ -41,9 +41,8 @@ namespace CalamityMod.Projectiles.Rogue
float projY = Projectile.Center.Y;
float homeRange = Projectile.Calamity().stealthStrike ? 1800f : 600f;
float homingSpeed = 0.25f;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1) && !npc.boss)
{
float npcX = npc.position.X + (float)(npc.width / 2);
+6 -6
View File
@@ -53,16 +53,16 @@ namespace CalamityMod.Projectiles.Rogue
float maxDistance = 350f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && canHit)
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && canHit)
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+2 -3
View File
@@ -87,10 +87,9 @@ namespace CalamityMod.Projectiles.Rogue
Vector2 homingTarget = Projectile.Center;
bool foundTarget = false;
Vector2 targetVelocity = new Vector2(0f);
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC potentialTarget in Main.ActiveNPCs)
{
NPC potentialTarget = Main.npc[i];
if (potentialTarget.CanBeChasedBy(Projectile, false) && Projectile.WithinRange(Main.npc[i].Center, homingRange))
if (potentialTarget.CanBeChasedBy(Projectile, false) && Projectile.WithinRange(potentialTarget.Center, homingRange))
{
if (!foundTarget)
{
+5 -5
View File
@@ -54,15 +54,15 @@ namespace CalamityMod.Projectiles.Rogue
float maxDistance = 500f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+3 -3
View File
@@ -101,10 +101,10 @@ namespace CalamityMod.Projectiles.Rogue
}
if (InsideTiles)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile.GetSource_FromThis(), false))
NPCDestination = Main.npc[i].Center + Main.npc[i].velocity * 5f;
if (n.CanBeChasedBy(Projectile.GetSource_FromThis(), false))
NPCDestination = n.Center + n.velocity * 5f;
}
TimeUnderground++;
+10 -10
View File
@@ -90,30 +90,30 @@ namespace CalamityMod.Projectiles.Rogue
{
float projX = Projectile.Center.X;
float projY = Projectile.Center.Y;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
{
float npcCenterX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float npcCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float npcCenterX = n.position.X + (float)(n.width / 2);
float npcCenterY = n.position.Y + (float)(n.height / 2);
float targetDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcCenterX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcCenterY);
if (targetDist < 600f)
{
if (Main.npc[i].position.X < projX)
if (n.position.X < projX)
{
Main.npc[i].velocity.X += 0.25f;
n.velocity.X += 0.25f;
}
else
{
Main.npc[i].velocity.X -= 0.25f;
n.velocity.X -= 0.25f;
}
if (Main.npc[i].position.Y < projY)
if (n.position.Y < projY)
{
Main.npc[i].velocity.Y += 0.25f;
n.velocity.Y += 0.25f;
}
else
{
Main.npc[i].velocity.Y -= 0.25f;
n.velocity.Y -= 0.25f;
}
}
}
+10 -10
View File
@@ -112,30 +112,30 @@ namespace CalamityMod.Projectiles.Rogue
{
float projX = Projectile.Center.X;
float projY = Projectile.Center.Y;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses)
{
float npcCenterX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float npcCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float npcCenterX = n.position.X + (float)(n.width / 2);
float npcCenterY = n.position.Y + (float)(n.height / 2);
float targetDistance = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcCenterX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcCenterY);
if (targetDistance < 600f)
{
if (Main.npc[i].position.X < projX)
if (n.position.X < projX)
{
Main.npc[i].velocity.X += 0.25f;
n.velocity.X += 0.25f;
}
else
{
Main.npc[i].velocity.X -= 0.25f;
n.velocity.X -= 0.25f;
}
if (Main.npc[i].position.Y < projY)
if (n.position.Y < projY)
{
Main.npc[i].velocity.Y += 0.25f;
n.velocity.Y += 0.25f;
}
else
{
Main.npc[i].velocity.Y -= 0.25f;
n.velocity.Y -= 0.25f;
}
}
}
+2 -3
View File
@@ -54,16 +54,15 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
@@ -63,16 +63,16 @@ namespace CalamityMod.Projectiles.Rogue
float maxDistance = 200f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && canHit)
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && canHit)
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+6 -6
View File
@@ -1,4 +1,4 @@
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Dusts;
using Microsoft.Xna.Framework;
using System.IO;
@@ -69,15 +69,15 @@ namespace CalamityMod.Projectiles.Rogue
float maxDistance = 600f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance))
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+5 -5
View File
@@ -47,15 +47,15 @@ namespace CalamityMod.Projectiles.Rogue
float maxDistance = 500f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+1 -2
View File
@@ -143,9 +143,8 @@ namespace CalamityMod.Projectiles.Rogue
const float maxDistance = 300f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float extraDistance = npc.width / 2 + npc.height / 2;
+4 -6
View File
@@ -132,9 +132,8 @@ namespace CalamityMod.Projectiles.Rogue
int whoAmI = -1;
Vector2 targetSpot = Projectile.Center;
float detectRange = 1000f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float targetDist = Vector2.Distance(npc.Center, Projectile.Center);
@@ -142,7 +141,7 @@ namespace CalamityMod.Projectiles.Rogue
{
detectRange = targetDist;
targetSpot = npc.Center;
whoAmI = i;
whoAmI = npc.whoAmI;
}
}
}
@@ -304,10 +303,9 @@ namespace CalamityMod.Projectiles.Rogue
int buffType = ModContent.BuffType<TimeDistortion>();
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.active && !npc.dontTakeDamage && !npc.buffImmune[buffType] && Vector2.Distance(Projectile.Center, npc.Center) <= radius)
if (!npc.dontTakeDamage && !npc.buffImmune[buffType] && Vector2.Distance(Projectile.Center, npc.Center) <= radius)
{
if (npc.FindBuffIndex(buffType) == -1)
npc.AddBuff(buffType, 60, false);
+2 -3
View File
@@ -37,16 +37,15 @@ namespace CalamityMod.Projectiles.Rogue
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
index = npc.whoAmI;
}
}
}
+1 -2
View File
@@ -123,9 +123,8 @@ namespace CalamityMod.Projectiles.Summon
}
else
{
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
bool lineOfSight = Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height);
+1 -2
View File
@@ -100,9 +100,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!canAttack)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC2 in Main.ActiveNPCs)
{
NPC nPC2 = Main.npc[i];
if (nPC2.CanBeChasedBy(Projectile, false))
{
float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center);
@@ -117,9 +117,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!canAttack && !passive)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC2 in Main.ActiveNPCs)
{
NPC nPC2 = Main.npc[i];
if (nPC2.CanBeChasedBy(Projectile, false))
{
float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center);
@@ -143,16 +143,16 @@ namespace CalamityMod.Projectiles.Summon
int[] targetArray = new int[maxTargets];
int targetsAquired = 0;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (targetsAquired == maxTargets)
break;
if (Main.npc[i].CanBeChasedBy(Projectile))
if (n.CanBeChasedBy(Projectile))
{
if ((CnidarianPos - Main.npc[i].Center).Length() < targettingDistance)
if ((CnidarianPos - n.Center).Length() < targettingDistance)
{
targetArray[targetsAquired] = i;
targetArray[targetsAquired] = n.whoAmI;
targetsAquired++;
}
}
+2 -3
View File
@@ -76,9 +76,8 @@ namespace CalamityMod.Projectiles.Summon
}
else
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC2 in Main.ActiveNPCs)
{
NPC nPC2 = Main.npc[i];
if (nPC2.CanBeChasedBy(Projectile, false))
{
float maxTargetDist = Vector2.Distance(nPC2.Center, Projectile.Center);
@@ -87,7 +86,7 @@ namespace CalamityMod.Projectiles.Summon
targetDist = maxTargetDist;
projPos = nPC2.Center;
canAttack = true;
target = i;
target = nPC2.whoAmI;
}
}
}
@@ -86,15 +86,15 @@ namespace CalamityMod.Projectiles.Summon
}
if (!homeIn)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance))
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+5 -5
View File
@@ -140,17 +140,17 @@ namespace CalamityMod.Projectiles.Summon
}
if (!canAttack)
{
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float npcX = n.position.X + (float)(n.width / 2);
float npcY = n.position.Y + (float)(n.height / 2);
float npcDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcY);
if (npcDist < attackDistance)
{
attackDistance = npcDist;
center12 = Main.npc[i].Center;
center12 = n.Center;
canAttack = true;
}
}
+1 -2
View File
@@ -173,9 +173,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!gotoenemy)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC nPC2 in Main.ActiveNPCs)
{
NPC nPC2 = Main.npc[i];
if (nPC2.CanBeChasedBy(Projectile, false))
{
float disttoobjective = Vector2.Distance(nPC2.Center, Projectile.Center);
+1 -5
View File
@@ -80,12 +80,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!hasHomingTarget)
{
for (int i = 0; i < Main.npc.Length; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc == null || !npc.active)
continue;
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
+1 -2
View File
@@ -82,9 +82,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!homeIn)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float extraDistance = (npc.width / 2) + (npc.height / 2);
+2 -3
View File
@@ -117,16 +117,15 @@ namespace CalamityMod.Projectiles.Summon
float maxDistance = 1000f;
int possibleTarget = -1;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile))
{
float npcDistance = Projectile.Distance(npc.Center);
if (npcDistance < maxDistance)
{
maxDistance = npcDistance;
possibleTarget = i;
possibleTarget = npc.whoAmI;
}
}
}
+2 -6
View File
@@ -73,18 +73,14 @@ namespace CalamityMod.Projectiles.Summon
}
if (!hasHomingTarget)
{
for (int i = 0; i < Main.npc.Length; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc is null || !npc.active)
continue;
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < maxHomingRange && Collision.CanHit(Projectile.Center, Projectile.width, Projectile.height, npc.Center, npc.width, npc.height))
{
targetIdx = i;
targetIdx = npc.whoAmI;
maxHomingRange = dist;
hasHomingTarget = true;
}
+1 -2
View File
@@ -65,9 +65,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!homeIn)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if ((npc.CanBeChasedBy(Projectile, false) || (npc.type == NPCID.DukeFishron && (!npc.dontTakeDamage || npc.ai[0] > 9f))) && npc.active)
{
float extraDistance = (npc.width / 2) + (npc.height / 2);
+6 -6
View File
@@ -503,16 +503,16 @@ namespace CalamityMod.Projectiles.Summon
}
float distance = searchDistance * searchDistance;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy() && Main.npc[i].type != heartType)
if (n.CanBeChasedBy() && n.type != heartType)
{
float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2);
float extraDistance = (n.width / 2) + (n.height / 2);
if (Main.npc[i].WithinRange(Projectile.Center, distance + extraDistance))
if (n.WithinRange(Projectile.Center, distance + extraDistance))
{
distance = Main.npc[i].DistanceSQ(Projectile.Center);
closestTarget = Main.npc[i];
distance = n.DistanceSQ(Projectile.Center);
closestTarget = n;
}
}
}
+2 -5
View File
@@ -114,20 +114,17 @@ namespace CalamityMod.Projectiles.Summon
}
if (targetID < 0)
{
int targetIDCopy;
for (int i = 0; i < Main.maxNPCs; i = targetIDCopy + 1)
foreach (NPC target in Main.ActiveNPCs)
{
NPC target = Main.npc[i];
if (target.CanBeChasedBy(Projectile, false))
{
float targetDistance = Projectile.Distance(target.Center);
if (targetDistance < attackRange && Collision.CanHitLine(Projectile.Center, 0, 0, target.Center, 0, 0))
{
attackRange = targetDistance;
targetID = i;
targetID = target.whoAmI;
}
}
targetIDCopy = i;
}
}
if (targetID != -1)
+1 -2
View File
@@ -100,9 +100,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!foundTarget)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float npcDist = Vector2.Distance(Projectile.Center, npc.Center);
+1 -2
View File
@@ -100,9 +100,8 @@ namespace CalamityMod.Projectiles.Summon
}
if (!foundTarget)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float npcDist = Vector2.Distance(Projectile.Center, npc.Center);
+4 -4
View File
@@ -58,13 +58,13 @@ namespace CalamityMod.Projectiles.Summon
float maxDistance = 1000f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, Projectile.width, Projectile.height, Main.npc[i].Center, Main.npc[i].width, Main.npc[i].height))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, Projectile.width, Projectile.height, n.Center, n.width, n.height))
{
homeIn = true;
break;
+3 -5
View File
@@ -111,15 +111,14 @@ namespace CalamityMod.Projectiles.Summon
}
if (targetIndex < 0)
{
for (int i = 0; i < Main.maxNPCs; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
float num1 = (npc.Center - Projectile.Center).Length();
if (num1 < maxDistance)
{
targetIndex = i;
targetIndex = npc.whoAmI;
maxDistance = num1;
}
}
@@ -309,9 +308,8 @@ namespace CalamityMod.Projectiles.Summon
else
{
Rectangle rectangle = new Rectangle((int)(Projectile.position.X + Projectile.velocity.X * 0.5f - 4f), (int)(Projectile.position.Y + Projectile.velocity.Y * 0.5f - 4f), Projectile.width + 8, Projectile.height + 8);
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false) && npc.immune[Projectile.owner] <= 0)
{
Rectangle rect = npc.getRect();
+2 -6
View File
@@ -88,18 +88,14 @@ namespace CalamityMod.Projectiles.Summon.Umbrella
}
if (!hasHomingTarget)
{
for (int i = 0; i < Main.npc.Length; ++i)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc is null || !npc.active)
continue;
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < maxHomingRange)
{
targetIdx = i;
targetIdx = npc.whoAmI;
maxHomingRange = dist;
hasHomingTarget = true;
}
+4 -5
View File
@@ -255,16 +255,15 @@ namespace CalamityMod.Projectiles.Summon.Umbrella
return selectedTarget.whoAmI;
}
for (int i = 0; i < Main.maxNPCs; i++)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(this) && (npc.boss || !blackListedTargets.Contains(i)))
foreach (NPC npc in Main.ActiveNPCs)
{
if (npc.CanBeChasedBy(this) && (npc.boss || !blackListedTargets.Contains(npc.whoAmI)))
{
float npcDist = npc.Distance(center);
if (npcDist <= MagicHat.Range && (npcDist <= closestDist || closestDist == -1f))
{
closestDist = npcDist;
target = i;
target = npc.whoAmI;
}
}
}
+1 -2
View File
@@ -154,9 +154,8 @@ namespace CalamityMod.Projectiles.Summon
bool foundTarget = false;
float maxDist = 300f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile, false))
{
if (Vector2.Distance(Projectile.Center, npc.Center) < maxDist && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height))
@@ -166,14 +166,14 @@ namespace CalamityMod.Projectiles.Summon
}
Projectile.frameCounter++;
for (int i = 0; i < Main.npc.Length; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (!n.friendly && CalamityGlobalNPC.ShouldAffectNPC(n))
{
if (Main.npc[i].active && !Main.npc[i].friendly && CalamityGlobalNPC.ShouldAffectNPC(Main.npc[i]))
{
if (Vector2.Distance(Projectile.Center, Main.npc[i].Center) <= radius)
ApplySucc(Main.npc[i]);
}
if (Vector2.Distance(Projectile.Center, n.Center) <= radius)
ApplySucc(n);
}
}
if (Projectile.scale >= 2.5f) //it's boom o' clock
+5 -5
View File
@@ -125,14 +125,14 @@ namespace CalamityMod.Projectiles.Summon
}
if (!canAttack)
{
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float targetX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2);
float targetY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2);
float targetX = n.position.X + (float)(n.width / 2);
float targetY = n.position.Y + (float)(n.height / 2);
float targetDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - targetX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - targetY);
if (targetDist < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
if (targetDist < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height))
{
attackRange = targetDist;
projX = targetX;
+1 -3
View File
@@ -65,10 +65,8 @@ namespace CalamityMod.Projectiles.Summon
float bestScore = 0;
NPC bestTarget = null;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC potentialTarget in Main.ActiveNPCs)
{
NPC potentialTarget = Main.npc[i];
if (!potentialTarget.CanBeChasedBy(null, false))
continue;
+1 -3
View File
@@ -68,10 +68,8 @@ namespace CalamityMod.Projectiles.Summon
float bestScore = 0;
NPC bestTarget = null;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC potentialTarget in Main.ActiveNPCs)
{
NPC potentialTarget = Main.npc[i];
if (!potentialTarget.CanBeChasedBy(null, false))
continue;
+4 -4
View File
@@ -57,16 +57,16 @@ namespace CalamityMod.Projectiles.Typeless
{
int targetID = -1;
float hitDistance = 300f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
Vector2 targetCenter = Main.npc[i].Center;
Vector2 targetCenter = n.Center;
float targetDist = Vector2.Distance(targetCenter, Projectile.Center);
if (targetDist < hitDistance && targetID == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, targetCenter, 1, 1))
{
hitDistance = targetDist;
targetID = i;
targetID = n.whoAmI;
}
}
}
+4 -4
View File
@@ -58,16 +58,16 @@ namespace CalamityMod.Projectiles.Typeless
{
int targetID = -1;
float hitDistance = 300f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
Vector2 targetCenter = Main.npc[i].Center;
Vector2 targetCenter = n.Center;
float targetDist = Vector2.Distance(targetCenter, Projectile.Center);
if (targetDist < hitDistance && targetID == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, targetCenter, 1, 1))
{
hitDistance = targetDist;
targetID = i;
targetID = n.whoAmI;
}
}
}
+5 -5
View File
@@ -41,15 +41,15 @@ namespace CalamityMod.Projectiles.Typeless
float maxDistance = 500f;
bool homeIn = false;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
float extraDistance = (float)(n.width / 2) + (float)(n.height / 2);
if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))
{
center = Main.npc[i].Center;
center = n.Center;
homeIn = true;
break;
}
+4 -4
View File
@@ -46,16 +46,16 @@ namespace CalamityMod.Projectiles.Typeless
{
int targetID = -1;
float hitDistance = 150f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
Vector2 targetCenter = Main.npc[i].Center;
Vector2 targetCenter = n.Center;
float targetDist = Vector2.Distance(targetCenter, Projectile.Center);
if (targetDist < hitDistance && targetID == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, targetCenter, 1, 1))
{
hitDistance = targetDist;
targetID = i;
targetID = n.whoAmI;
}
}
}
+4 -4
View File
@@ -37,16 +37,16 @@ namespace CalamityMod.Projectiles.Typeless
{
int targetIdx = -1;
float npcRange = 150f;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC n in Main.ActiveNPCs)
{
if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false))
if (n.CanBeChasedBy(Projectile, false))
{
Vector2 npcPos = Main.npc[i].Center;
Vector2 npcPos = n.Center;
float npcDist = Vector2.Distance(npcPos, Projectile.Center);
if (npcDist < npcRange && targetIdx == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, npcPos, 1, 1))
{
npcRange = npcDist;
targetIdx = i;
targetIdx = n.whoAmI;
}
}
}
+2 -3
View File
@@ -95,16 +95,15 @@ namespace CalamityMod.Projectiles.Typeless
Projectile.ai[0] = 10 + Main.rand.Next(10);
float maxDistance = hentai ? 900f : 600f;
int target = -1;
for (int i = 0; i < Main.maxNPCs; i++)
foreach (NPC npc in Main.ActiveNPCs)
{
NPC npc = Main.npc[i];
if (npc.CanBeChasedBy(Projectile))
{
float npcDistance = Projectile.Distance(npc.Center);
if (npcDistance < maxDistance)
{
maxDistance = npcDistance;
target = i;
target = npc.whoAmI;
}
}
}
+1 -9
View File
@@ -101,15 +101,7 @@ namespace CalamityMod.Skies
if (CryogenIndex >= 0 && Main.npc[CryogenIndex].active && Main.npc[CryogenIndex].type == cryogenType)
return true;
CryogenIndex = -1;
for (int i = 0; i < Main.npc.Length; i++)
{
if (Main.npc[i].active && Main.npc[i].type == cryogenType)
{
CryogenIndex = i;
break;
}
}
CryogenIndex = NPC.FindFirstNPC(cryogenType);
return CryogenIndex != -1;
}
Loaded 100 of 119 files, more files were not shown because too many files have changed in this diff. Show more