Ported most/all player iterations

This commit is contained in:
BasicallyIAmFox committed 2024-05-02 23:04:09 +05:00
1 parent ae69405e71
commit bb5148e2cf
73 files changed
+280 -423

No files matched your search

+3 -4
View File
@@ -1405,16 +1405,15 @@ namespace CalamityMod.CalPlayer
float lowestHealthCheck = 0f;
int healTarget = Player.whoAmI;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player otherPlayer in Main.ActivePlayers)
{
Player otherPlayer = Main.player[i];
if (otherPlayer.active && !otherPlayer.dead && ((!Player.hostile && !otherPlayer.hostile) || Player.team == otherPlayer.team))
if (!otherPlayer.dead && ((!Player.hostile && !otherPlayer.hostile) || Player.team == otherPlayer.team))
{
float playerDist = Vector2.Distance(target.Center, otherPlayer.Center);
if (playerDist < 1200f && (otherPlayer.statLifeMax2 - otherPlayer.statLife) > lowestHealthCheck)
{
lowestHealthCheck = otherPlayer.statLifeMax2 - otherPlayer.statLife;
healTarget = i;
healTarget = otherPlayer.whoAmI;
}
}
}
+8 -25
View File
@@ -107,14 +107,8 @@ namespace CalamityMod.Events
{
get
{
int playerCount = 0;
for (int i = 0; i < Main.player.Length; i++)
{
if (Main.player[i].active)
{
playerCount++;
}
}
int playerCount = Main.CurrentFrameFlags.ActivePlayersCount;
if (DownedBossSystem.downedPolterghast)
return (int)(Math.Log(playerCount + Math.E - 1) * 170f);
else if (DownedBossSystem.downedAquaticScourge)
@@ -189,12 +183,7 @@ namespace CalamityMod.Events
if (AcidRainEventIsOngoing || (!NPC.downedBoss1 && !Main.hardMode && !DownedBossSystem.downedAquaticScourge) || BossRushEvent.BossRushActive)
return;
int playerCount = 0;
for (int i = 0; i < Main.player.Length; i++)
{
if (Main.player[i].active)
playerCount++;
}
int playerCount = Main.CurrentFrameFlags.ActivePlayersCount;
if (playerCount > 0)
{
@@ -243,12 +232,8 @@ namespace CalamityMod.Events
if (!HasStartedAcidicDownpour)
{
int sulphSeaWidth = SulphurousSea.BiomeWidth;
for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[playerIndex];
if (!player.active)
continue;
// An artificial biome can be made, and therefore, the event could be started by an artificial biome.
// While fighting the event in an artificial biome is not bad, having it be started by a patch of Sulphurous Sand
// would definitely be strange.
@@ -387,11 +372,9 @@ namespace CalamityMod.Events
if ((int)Main.time == (int)(Main.nightLength - 1f) && !Main.dayTime && Main.rand.NextBool(increasedEventChance ? 3 : 300))
{
bool shouldNotStartEvent = false;
for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++)
foreach (Player player in Main.ActivePlayers)
{
if (!Main.player[playerIndex].active)
continue;
if (Main.player[playerIndex].Calamity().noStupidNaturalARSpawns)
if (player.Calamity().noStupidNaturalARSpawns)
{
shouldNotStartEvent = true;
break;
@@ -407,9 +390,9 @@ namespace CalamityMod.Events
// Attempt to force an Acid Rain immediately after the EoC is dead when someone wanders to the sea.
if (NPC.downedBoss1 && !DownedBossSystem.downedEoCAcidRain && !HasBeenForceStartedByEoCDefeat)
{
for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[playerIndex].active && Main.player[playerIndex].Calamity().ZoneSulphur)
if (player.Calamity().ZoneSulphur)
{
HasBeenForceStartedByEoCDefeat = true;
TryStartEvent();
+20 -36
View File
@@ -318,14 +318,10 @@ namespace CalamityMod.Events
new Boss(ModContent.NPCType<CeaselessVoid>(), spawnContext: type =>
{
for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[playerIndex];
if (p is not null && p.active)
{
if (p.FindBuffIndex(ModContent.BuffType<IcarusFolly>()) > -1)
p.ClearBuff(ModContent.BuffType<IcarusFolly>());
}
if (p.FindBuffIndex(ModContent.BuffType<IcarusFolly>()) > -1)
p.ClearBuff(ModContent.BuffType<IcarusFolly>());
}
Player player = Main.player[ClosestPlayerToWorldCenter];
@@ -413,19 +409,15 @@ namespace CalamityMod.Events
BossRushDialogueSystem.StartDialogue(BossRushDialoguePhase.TierOneComplete);
// Teleport players to where they came from
for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[playerIndex];
if (p is not null && p.active)
if (p.Calamity().BossRushReturnPosition.HasValue)
{
if (p.Calamity().BossRushReturnPosition.HasValue)
{
CalamityPlayer.ModTeleport(p, p.Calamity().BossRushReturnPosition.Value, false, TeleportationStyleID.TeleportationPotion);
p.Calamity().BossRushReturnPosition = null;
}
CalamityPlayer.ModTeleport(p, p.Calamity().BossRushReturnPosition.Value, false, TeleportationStyleID.TeleportationPotion);
p.Calamity().BossRushReturnPosition = null;
SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center);
}
p.Calamity().BossRushReturnPosition = null;
SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center);
}
},
// Plantera: End of Tier 2
@@ -622,13 +614,9 @@ namespace CalamityMod.Events
public static void End()
{
// Reset BossRushReturnPosition
for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[playerIndex];
if (p is not null && p.active)
{
p.Calamity().BossRushReturnPosition = null;
}
p.Calamity().BossRushReturnPosition = null;
}
if (Main.netMode == NetmodeID.SinglePlayer)
@@ -729,18 +717,14 @@ namespace CalamityMod.Events
CalamityUtils.KillAllHostileProjectiles();
HostileProjectileKillCounter = 3;
for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[playerIndex];
if (p is not null && p.active)
{
p.Calamity().BossRushReturnPosition = p.Center;
Vector2? underworld = CalamityPlayer.GetUnderworldPosition(p);
if (!underworld.HasValue)
break;
CalamityPlayer.ModTeleport(p, underworld.Value, false, TeleportationStyleID.TeleportationPotion);
SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center);
}
p.Calamity().BossRushReturnPosition = p.Center;
Vector2? underworld = CalamityPlayer.GetUnderworldPosition(p);
if (!underworld.HasValue)
break;
CalamityPlayer.ModTeleport(p, underworld.Value, false, TeleportationStyleID.TeleportationPotion);
SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center);
}
}
@@ -788,12 +772,12 @@ namespace CalamityMod.Events
{
if (Main.netMode != NetmodeID.MultiplayerClient)
{
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player p in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (p.dead)
continue;
int animation = Projectile.NewProjectile(new EntitySource_WorldEvent(), Main.player[i].Center, Vector2.Zero, ModContent.ProjectileType<BossRushTierAnimation>(), 0, 0f, i);
int animation = Projectile.NewProjectile(new EntitySource_WorldEvent(), p.Center, Vector2.Zero, ModContent.ProjectileType<BossRushTierAnimation>(), 0, 0f, p.whoAmI);
if (Main.projectile.IndexInRange(animation))
Main.projectile[animation].ai[0] = tier;
}
+5 -6
View File
@@ -36,10 +36,9 @@ namespace CalamityMod.Items.Accessories
get
{
bool result = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -110,10 +109,9 @@ namespace CalamityMod.Items.Accessories
// Visibility is not net synced, for example.
bool alreadyDrawnShieldForPlayer = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -127,6 +125,7 @@ namespace CalamityMod.Items.Accessories
// Scale the shield is drawn at.
// The "i" parameter is to make different player's shields not be perfectly synced.
int i = player.whoAmI;
float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + i * 0.2f));
if (!alreadyDrawnShieldForPlayer)
+2 -3
View File
@@ -42,10 +42,9 @@ namespace CalamityMod.Items.Accessories
get
{
bool result = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
+5 -7
View File
@@ -36,10 +36,9 @@ namespace CalamityMod.Items.Accessories
get
{
bool result = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -104,10 +103,9 @@ namespace CalamityMod.Items.Accessories
// Visibility is not net synced, for example.
bool alreadyDrawnShieldForPlayer = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -119,7 +117,7 @@ namespace CalamityMod.Items.Accessories
continue;
// The shield very gently grows and shrinks
float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + i * 0.2f));
float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + player.whoAmI * 0.2f));
if (!alreadyDrawnShieldForPlayer)
{
+5 -6
View File
@@ -45,10 +45,9 @@ namespace CalamityMod.Items.Accessories
get
{
bool result = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -171,10 +170,9 @@ namespace CalamityMod.Items.Accessories
// Visibility is not net synced, for example.
bool alreadyDrawnShieldForPlayer = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -187,6 +185,7 @@ namespace CalamityMod.Items.Accessories
// Scale the shield is drawn at. The Sponge shield gently grows and shrinks; it should be largely imperceptible.
// The "i" parameter is to make different player's shields not be perfectly synced.
int i = player.whoAmI;
float baseScale = 0.155f;
float maxExtraScale = 0.025f;
float extraScalePulseInterpolant = MathF.Pow(4f, MathF.Sin(Main.GlobalTimeWrappedHourly * 0.791f + i) - 1);
+5 -6
View File
@@ -41,10 +41,9 @@ namespace CalamityMod.Items.Armor.LunicCorps
get
{
bool result = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -112,10 +111,9 @@ namespace CalamityMod.Items.Armor.LunicCorps
// Visibility is not net synced, for example.
bool alreadyDrawnShieldForPlayer = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active || player.outOfRange || player.dead)
if (player.outOfRange || player.dead)
continue;
CalamityPlayer modPlayer = player.Calamity();
@@ -126,6 +124,7 @@ namespace CalamityMod.Items.Armor.LunicCorps
// Scale the shield is drawn at. The Lunic Corps shield sticks very close to the body to mimic Halo and occasionally pulses.
// The "i" parameter is to make different player's shields not be perfectly synced.
int i = player.whoAmI;
float baseScale = 0.11f;
float maxExtraScale = 0.013f;
float extraScalePulseInterpolant = MathF.Pow(12f, MathF.Sin(Main.GlobalTimeWrappedHourly * 1.6f + i) - 1);
+2 -2
View File
@@ -44,9 +44,9 @@ namespace CalamityMod.Items.Materials
bool closePlayer = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
if ((Main.player[i].Center - Item.Center).Length() < 1200 && Main.player[i].GetModPlayer<WulfrumBatteryPlayer>().battery)
if ((player.Center - Item.Center).Length() < 1200 && player.GetModPlayer<WulfrumBatteryPlayer>().battery)
{
closePlayer = true;
break;
+1 -5
View File
@@ -85,12 +85,8 @@ namespace CalamityMod.Items.Mounts
public override void Dismount(Player player, ref bool skipDust)
{
bool anyPlayerOnFabMount = false;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player2 in Main.ActivePlayers)
{
Player player2 = Main.player[i];
if (!player2.active)
continue;
// The player that is dismounting is technically not on the mount anymore.
if (player2.Calamity().fab && player2.whoAmI != player.whoAmI)
{
+3 -4
View File
@@ -43,12 +43,11 @@ namespace CalamityMod.Items.Weapons.Rogue
if (spore.WithinBounds(Main.maxProjectiles))
Main.projectile[spore].ai[1] = 1f;
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player other in Main.ActivePlayers)
{
Player other = Main.player[i];
if (other is null || !other.active || other.dead)
if (other.dead)
continue;
if ((other.team == player.team && player.team != 0) || player.whoAmI == i)
if ((other.team == player.team && player.team != 0) || player.whoAmI == other.whoAmI)
{
if (player.Distance(other.Center) <= 800f)
other.AddBuff(ModContent.BuffType<Mushy>(), 900);
+6 -1
View File
@@ -158,8 +158,13 @@ namespace CalamityMod.NPCs.Abyss
NPC.height = (int)(NPC.height * 3f);
NPC.position -= NPC.Size * 0.5f; //hitbox expansion + adjustments
SoundEngine.PlaySound(SoundID.Item14, NPC.Center); //bomb sound
foreach (Player player in Main.player.Where(player => player.active && !player.dead && NPC.Hitbox.Intersects(player.Hitbox)))
foreach (Player player in Main.ActivePlayers)
{
if (player.dead || !NPC.Hitbox.Intersects(player.Hitbox))
continue;
player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), explosionDamage, NPC.direction);
}
for (int k = 0; k < 8; k++)
{
int dust = Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.MoonBoulder, 0f, -1f, 0, default, 1f);
+8 -2
View File
@@ -267,8 +267,14 @@ namespace CalamityMod.NPCs.Abyss
NPC.width = NPC.height;
NPC.position -= NPC.Size * 0.5f; //hitbox expansion + adjustments
SoundEngine.PlaySound(SoundID.Item14, NPC.Center); //bomb sound
foreach (Player player in Main.player.Where(player => player.active && !player.dead && NPC.Hitbox.Intersects(player.Hitbox)))
player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage * 3, NPC.direction); //Due to how slow the jelly is, this might catch you unaware, but then you'll never get hit by it again
foreach (Player player in Main.ActivePlayers)
{
if (player.dead || !NPC.Hitbox.Intersects(player.Hitbox))
continue;
//Due to how slow the jelly is, this might catch you unaware, but then you'll never get hit by it again
player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage * 3, NPC.direction);
}
for (int k = 0; k < 25; k++)
{
int dust = Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.MoonBoulder, 0f, -1f, 0, default, 2f);
+2 -3
View File
@@ -56,10 +56,9 @@ namespace CalamityMod.NPCs.AcidRain
NPC.velocity.X = xSpeed * NPC.ai[0];
NPC.spriteDirection = (int)NPC.ai[0];
bool flee = false;
for (int i = 0; i < Main.player.Length; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player.active && !player.dead && Vector2.Distance(player.Center, NPC.Center) <= 220f)
if (!player.dead && Vector2.Distance(player.Center, NPC.Center) <= 220f)
{
flee = true;
break;
+7 -7
View File
@@ -263,13 +263,13 @@ namespace CalamityMod.NPCs.Astral
centerY - height / 2,
width, height);
for (int i = 0; i < Main.player.Length; i++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[i].active && !Main.player[i].dead && Main.player[i].getRect().Intersects(hitbox))
if (!player.dead && player.getRect().Intersects(hitbox))
{
Vector2 before = Main.player[i].velocity;
Main.player[i].Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage, NPC.direction);
Vector2 after = Main.player[i].velocity;
Vector2 before = player.velocity;
player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage, NPC.direction);
Vector2 after = player.velocity;
Vector2 difference = after - before;
float horMult = 3.5f;
@@ -284,7 +284,7 @@ namespace CalamityMod.NPCs.Astral
swingYeet = true;
}
if (Main.player[i].noKnockback)
if (player.noKnockback)
{
horMult *= 0.5f;
verMult *= 0.5f;
@@ -292,7 +292,7 @@ namespace CalamityMod.NPCs.Astral
difference *= new Vector2(horMult, verMult);
Main.player[i].velocity = before + difference;
player.velocity = before + difference;
}
}
}
+4 -4
View File
@@ -209,12 +209,12 @@ namespace CalamityMod.NPCs.Astral
if (Main.netMode != NetmodeID.MultiplayerClient)
{
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[i].getRect().Intersects(myRect))
if (player.getRect().Intersects(myRect))
{
int direction = NPC.Center.X - Main.player[i].Center.X < 0 ? -1 : 1;
Main.player[i].Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage, direction);
int direction = NPC.Center.X - player.Center.X < 0 ? -1 : 1;
player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage, direction);
}
}
}
+12 -15
View File
@@ -3934,16 +3934,13 @@ namespace CalamityMod.NPCs
if (npc.position.Y > player.position.Y)
{
for (int m = 0; m < Main.maxPlayers; m++)
foreach (Player m in Main.ActivePlayers)
{
if (Main.player[m].active)
Rectangle rectangle2 = new Rectangle((int)m.position.X - noFlyZone, (int)m.position.Y - noFlyZone, noFlyZone * 2, height);
if (rectangle.Intersects(rectangle2))
{
Rectangle rectangle2 = new Rectangle((int)Main.player[m].position.X - noFlyZone, (int)Main.player[m].position.Y - noFlyZone, noFlyZone * 2, height);
if (rectangle.Intersects(rectangle2))
{
outsideNoFlyZone = false;
break;
}
outsideNoFlyZone = false;
break;
}
}
if (outsideNoFlyZone)
@@ -4522,20 +4519,20 @@ namespace CalamityMod.NPCs
}
float succPower = 0.125f + finalPhaseDustRatio * 0.125f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
float distance = Vector2.Distance(Main.player[i].Center, npc.Center);
if (distance < suckDistance && Main.player[i].grappling[0] == -1)
float distance = Vector2.Distance(plr.Center, npc.Center);
if (distance < suckDistance && plr.grappling[0] == -1)
{
if (Collision.CanHit(npc.Center, 1, 1, Main.player[i].Center, 1, 1))
if (Collision.CanHit(npc.Center, 1, 1, plr.Center, 1, 1))
{
float distanceRatio = distance / suckDistance;
float multiplier = 1f - distanceRatio;
if (Main.player[i].Center.X < npc.Center.X)
Main.player[i].velocity.X += succPower * multiplier;
if (plr.Center.X < npc.Center.X)
plr.velocity.X += succPower * multiplier;
else
Main.player[i].velocity.X -= succPower * multiplier;
plr.velocity.X -= succPower * multiplier;
}
}
}
+5 -5
View File
@@ -1161,11 +1161,11 @@ namespace CalamityMod.NPCs
int nailCount = Main.rand.Next(3, 6);
int[] players = new int[nailCount];
int i = 0;
for (int j = 0; j < Main.player.Length; j++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[j].active && !Main.player[j].dead && Collision.CanHitLine(npc.position, npc.width, npc.height, Main.player[j].position, Main.player[j].width, Main.player[j].height))
if (!plr.dead && Collision.CanHitLine(npc.position, npc.width, npc.height, plr.position, plr.width, plr.height))
{
players[i] = j;
players[i] = plr.whoAmI;
i++;
if (i == nailCount)
{
@@ -7637,9 +7637,9 @@ namespace CalamityMod.NPCs
bool spawnTwinkle = npc.ai[1] >= (CalamityWorld.death ? 60f : 120f);
if (!spawnTwinkle && npc.velocity.Y == 0f)
{
for (int j = 0; j < Main.maxPlayers; j++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[j].active && !Main.player[j].dead && Main.player[j].Distance(npc.Center) < 800f && Main.player[j].Center.Y < npc.Center.Y && Math.Abs(Main.player[j].Center.X - npc.Center.X) < 20f)
if (!plr.dead && plr.Distance(npc.Center) < 800f && plr.Center.Y < npc.Center.Y && Math.Abs(plr.Center.X - npc.Center.X) < 20f)
{
spawnTwinkle = true;
break;
+3 -11
View File
@@ -6230,9 +6230,9 @@ namespace CalamityMod.NPCs
#region Player Counts
public static bool AnyLivingPlayers()
{
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[i] != null && Main.player[i].active && !Main.player[i].dead && !Main.player[i].ghost)
if (!player.dead && !player.ghost)
{
return true;
}
@@ -6247,15 +6247,7 @@ namespace CalamityMod.NPCs
return 1;
}
int players = 0;
for (int i = 0; i < Main.maxPlayers; i++)
{
if (Main.player[i] != null && Main.player[i].active)
{
players++;
}
}
return players;
return Main.CurrentFrameFlags.ActivePlayersCount;
}
#endregion
+5 -8
View File
@@ -167,16 +167,13 @@ namespace CalamityMod.NPCs.DesertScourge
bool shouldDirectlyChase = true;
if (NPC.position.Y > Main.player[NPC.target].position.Y)
{
for (int m = 0; m < 255; m++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[m].active)
Rectangle rectangle2 = new Rectangle((int)plr.position.X - directChaseDistance, (int)plr.position.Y - directChaseDistance, directChaseDistance * 2, directChaseDistance * 2);
if (rectangle.Intersects(rectangle2))
{
Rectangle rectangle2 = new Rectangle((int)Main.player[m].position.X - directChaseDistance, (int)Main.player[m].position.Y - directChaseDistance, directChaseDistance * 2, directChaseDistance * 2);
if (rectangle.Intersects(rectangle2))
{
shouldDirectlyChase = false;
break;
}
shouldDirectlyChase = false;
break;
}
}
if (shouldDirectlyChase)
+7 -10
View File
@@ -354,18 +354,15 @@ namespace CalamityMod.NPCs.DesertScourge
{
int rectWidth = directChaseDistance * 2;
int rectHeight = directChaseDistance * 2;
for (int m = 0; m < 255; m++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[m].active)
int rectX = (int)plr.position.X - directChaseDistance;
int rectY = (int)plr.position.Y - directChaseDistance;
Rectangle directChaseRect = new Rectangle(rectX, rectY, rectWidth, rectHeight);
if (rectangle.Intersects(directChaseRect))
{
int rectX = (int)Main.player[m].position.X - directChaseDistance;
int rectY = (int)Main.player[m].position.Y - directChaseDistance;
Rectangle directChaseRect = new Rectangle(rectX, rectY, rectWidth, rectHeight);
if (rectangle.Intersects(directChaseRect))
{
shouldDirectlyChase = false;
break;
}
shouldDirectlyChase = false;
break;
}
}
if (shouldDirectlyChase)
+2 -7
View File
@@ -78,9 +78,8 @@ namespace CalamityMod.NPCs.DraedonLabThings
NPC.ai[2] *= -1;
}
// If she sees someone, start running
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (Collision.CanHit(NPC.position, NPC.width, NPC.height, player.position, player.width, player.height))
{
ChangeAI(1);
@@ -143,12 +142,8 @@ namespace CalamityMod.NPCs.DraedonLabThings
break;
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active)
continue;
if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck))
{
Main.BestiaryTracker.Kills.RegisterKill(NPC);
@@ -36,12 +36,8 @@ namespace CalamityMod.NPCs.DraedonLabThings
{
Lighting.AddLight(NPC.Center, 0.25f, 0.1f, 0f);
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active)
continue;
if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck))
{
NPC nPC = new NPC();
@@ -36,12 +36,8 @@ namespace CalamityMod.NPCs.DraedonLabThings
{
Lighting.AddLight(NPC.Center, 0.03f, 0.3f, 0.05f);
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active)
continue;
if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck))
{
NPC nPC = new NPC();
+1 -5
View File
@@ -36,12 +36,8 @@ namespace CalamityMod.NPCs.DraedonLabThings
{
Lighting.AddLight(NPC.Center, 0.3f, 0.03f, 0f);
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active)
continue;
if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck))
{
NPC nPC = new NPC();
+1 -5
View File
@@ -131,12 +131,8 @@ namespace CalamityMod.NPCs.DraedonLabThings
}
Time++;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active)
continue;
if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck))
{
Main.BestiaryTracker.Kills.RegisterKill(NPC);
+8 -8
View File
@@ -283,16 +283,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
whoAmIArray[numProjectiles] = i;
whoAmIArray[numProjectiles] = plr.whoAmI;
targetCenterArray[numProjectiles] = playerCenter;
int projectileLimit = numProjectiles + 1;
numProjectiles = projectileLimit;
@@ -347,16 +347,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
whoAmIArray[numProjectiles] = i;
whoAmIArray[numProjectiles] = plr.whoAmI;
targetCenterArray[numProjectiles] = playerCenter;
int projectileLimit = numProjectiles + 1;
numProjectiles = projectileLimit;
+7 -7
View File
@@ -281,12 +281,12 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
@@ -345,16 +345,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
whoAmIArray[numProjectiles] = i;
whoAmIArray[numProjectiles] = plr.whoAmI;
targetCenterArray[numProjectiles] = playerCenter;
int projectileLimit = numProjectiles + 1;
numProjectiles = projectileLimit;
+8 -8
View File
@@ -281,16 +281,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
whoAmIArray[numProjectiles] = i;
whoAmIArray[numProjectiles] = plr.whoAmI;
targetCenterArray[numProjectiles] = playerCenter;
int projectileLimit = numProjectiles + 1;
numProjectiles = projectileLimit;
@@ -345,16 +345,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
whoAmIArray[numProjectiles] = i;
whoAmIArray[numProjectiles] = plr.whoAmI;
targetCenterArray[numProjectiles] = playerCenter;
int projectileLimit = numProjectiles + 1;
numProjectiles = projectileLimit;
+1 -7
View File
@@ -489,13 +489,7 @@ namespace CalamityMod.NPCs.Leviathan
float restingPlayerDistance = (float)Math.Sqrt(restingPlayerXDist * restingPlayerXDist + restingPlayerYDist * restingPlayerYDist);
NPC.ai[1] += 1f;
int activePlayerAmt = 0;
for (int i = 0; i < 255; i++)
{
if (Main.player[i].active && !Main.player[i].dead && (vector - Main.player[i].Center).Length() < 1000f)
activePlayerAmt++;
}
NPC.ai[1] += activePlayerAmt / 2;
NPC.ai[1] += Main.CurrentFrameFlags.ActivePlayersCount / 2;
bool spawnedBubble = false;
float bubbleDelay = 20f;
+5 -8
View File
@@ -165,16 +165,13 @@ namespace CalamityMod.NPCs.NormalNPCs
bool outsideNoFlyZone = true;
if (NPC.position.Y > Main.player[NPC.target].position.Y)
{
for (int m = 0; m < 255; m++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[m].active)
Rectangle noFlyArea = new Rectangle((int)player.position.X - noFlyZone, (int)player.position.Y - noFlyZone, noFlyZone * 2, noFlyZone * 2);
if (rectangle.Intersects(noFlyArea))
{
Rectangle noFlyArea = new Rectangle((int)Main.player[m].position.X - noFlyZone, (int)Main.player[m].position.Y - noFlyZone, noFlyZone * 2, noFlyZone * 2);
if (rectangle.Intersects(noFlyArea))
{
outsideNoFlyZone = false;
break;
}
outsideNoFlyZone = false;
break;
}
}
if (outsideNoFlyZone)
+5 -8
View File
@@ -255,16 +255,13 @@ namespace CalamityMod.NPCs.Perforator
bool outsideFlyingRadius = true;
if (NPC.position.Y > player.position.Y)
{
for (int m = 0; m < 255; m++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[m].active)
Rectangle rectangle2 = new Rectangle((int)plr.position.X - stopFlyingRadius, (int)plr.position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2);
if (rectangle.Intersects(rectangle2))
{
Rectangle rectangle2 = new Rectangle((int)Main.player[m].position.X - stopFlyingRadius, (int)Main.player[m].position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2);
if (rectangle.Intersects(rectangle2))
{
outsideFlyingRadius = false;
break;
}
outsideFlyingRadius = false;
break;
}
}
if (outsideFlyingRadius)
+5 -8
View File
@@ -228,16 +228,13 @@ namespace CalamityMod.NPCs.Perforator
bool outsideFlyRadius = true;
if (NPC.position.Y > player.position.Y)
{
for (int m = 0; m < 255; m++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[m].active)
Rectangle rectangle2 = new Rectangle((int)plr.position.X - stopFlyingRadius, (int)plr.position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2);
if (rectangle.Intersects(rectangle2))
{
Rectangle rectangle2 = new Rectangle((int)Main.player[m].position.X - stopFlyingRadius, (int)Main.player[m].position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2);
if (rectangle.Intersects(rectangle2))
{
outsideFlyRadius = false;
break;
}
outsideFlyRadius = false;
break;
}
}
if (outsideFlyRadius)
+1 -8
View File
@@ -92,14 +92,7 @@ namespace CalamityMod.NPCs.PlagueEnemies
NPC.timeLeft = 750;
}
}
int playerAmt = 0;
for (int i = 0; i < 255; i++)
{
if (Main.player[i].active && !Main.player[i].dead && (NPC.Center - Main.player[i].Center).Length() < 1000f)
{
playerAmt++;
}
}
int playerAmt = Main.CurrentFrameFlags.ActivePlayersCount;
if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active)
{
NPC.TargetClosest();
@@ -140,10 +140,9 @@ namespace CalamityMod.NPCs.PlaguebringerGoliath
}
float distanceBeforeExploding = 42f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player.active && !player.dead && Vector2.Distance(player.Center, NPC.Center) <= distanceBeforeExploding)
if (!player.dead && Vector2.Distance(player.Center, NPC.Center) <= distanceBeforeExploding)
{
CheckDead();
NPC.life = 0;
@@ -202,12 +202,7 @@ namespace CalamityMod.NPCs.PlaguebringerGoliath
Vector2 vectorCenter = NPC.Center;
// Count nearby players
int activePlayers = 0;
for (int i = 0; i < Main.maxPlayers; i++)
{
if (Main.player[i].active && !Main.player[i].dead && (vectorCenter - Main.player[i].Center).Length() < 1000f)
activePlayers++;
}
int activePlayers = Main.CurrentFrameFlags.ActivePlayersCount;
// Get a target
if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active)
+8 -8
View File
@@ -601,16 +601,16 @@ namespace CalamityMod.NPCs.PrimordialWyrm
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
whoAmIArray[numProjectiles] = i;
whoAmIArray[numProjectiles] = plr.whoAmI;
targetCenterArray[numProjectiles] = playerCenter;
int projectileLimit = numProjectiles + 1;
numProjectiles = projectileLimit;
@@ -896,16 +896,16 @@ namespace CalamityMod.NPCs.PrimordialWyrm
int numProjectiles = 0;
float maxDistance = 2400f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (plr.dead)
continue;
Vector2 playerCenter = Main.player[i].Center;
Vector2 playerCenter = plr.Center;
float distance = Vector2.Distance(playerCenter, NPC.Center);
if (distance < maxDistance)
{
whoAmIArray[numProjectiles] = i;
whoAmIArray[numProjectiles] = plr.whoAmI;
targetCenterArray[numProjectiles] = playerCenter;
int projectileLimit = numProjectiles + 1;
numProjectiles = projectileLimit;
+3 -3
View File
@@ -1266,10 +1266,10 @@ namespace CalamityMod.NPCs.Providence
if (NPC.ai[3] % 60f == 0f && expertMode)
{
List<int> targets = new List<int>();
for (int p = 0; p < Main.maxPlayers; p++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[p].active && !Main.player[p].dead)
targets.Add(p);
if (!plr.dead)
targets.Add(plr.whoAmI);
if (targets.Count > 4)
break;
+3 -3
View File
@@ -431,10 +431,10 @@ namespace CalamityMod.NPCs.SlimeGod
if (enraged && expertMode)
{
List<int> targets = new List<int>();
for (int p = 0; p < Main.maxPlayers; p++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[p].active && !Main.player[p].dead)
targets.Add(p);
if (!plr.dead)
targets.Add(plr.whoAmI);
if (targets.Count > 1)
break;
+3 -3
View File
@@ -444,10 +444,10 @@ namespace CalamityMod.NPCs.SlimeGod
if (enraged && expertMode)
{
List<int> targets = new List<int>();
for (int p = 0; p < Main.maxPlayers; p++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[p].active && !Main.player[p].dead)
targets.Add(p);
if (!plr.dead)
targets.Add(plr.whoAmI);
if (targets.Count > 1)
break;
+3 -3
View File
@@ -413,10 +413,10 @@ namespace CalamityMod.NPCs.SlimeGod
if (enraged && expertMode)
{
List<int> targets = new List<int>();
for (int p = 0; p < Main.maxPlayers; p++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[p].active && !Main.player[p].dead)
targets.Add(p);
if (!plr.dead)
targets.Add(plr.whoAmI);
if (targets.Count > 1)
break;
+3 -3
View File
@@ -430,10 +430,10 @@ namespace CalamityMod.NPCs.SlimeGod
if (enraged && expertMode)
{
List<int> targets = new List<int>();
for (int p = 0; p < Main.maxPlayers; p++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[p].active && !Main.player[p].dead)
targets.Add(p);
if (!plr.dead)
targets.Add(plr.whoAmI);
if (targets.Count > 1)
break;
+1 -5
View File
@@ -96,12 +96,8 @@ namespace CalamityMod.NPCs.TownNPCs
break;
}
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
if (player is null || !player.active)
continue;
if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck))
{
Main.BestiaryTracker.Chats.RegisterChatStartWith(NPC);
+2 -3
View File
@@ -93,11 +93,10 @@ namespace CalamityMod.NPCs.TownNPCs
if (CalamityWorld.spawnedCirrus)
return true;
for (int k = 0; k < Main.maxPlayers; k++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[k];
bool hasVodka = player.InventoryHas(ModContent.ItemType<FabsolsVodka>()) || player.PortableStorageHas(ModContent.ItemType<FabsolsVodka>());
if (player.active && hasVodka)
if (hasVodka)
return Main.hardMode;
}
return false;
+2 -3
View File
@@ -82,11 +82,10 @@ namespace CalamityMod.NPCs.TownNPCs
if (CalamityWorld.spawnedBandit)
return true;
for (int k = 0; k < Main.maxPlayers; k++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[k];
bool rich = player.InventoryHas(ItemID.PlatinumCoin) || player.PortableStorageHas(ItemID.PlatinumCoin);
if (player.active && rich)
if (rich)
return NPC.downedBoss3;
}
return false;
@@ -539,22 +539,22 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
if (shadowHandTimer / shadowHandSpawnRate >= 3)
npc.localAI[2] = 0f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
if (npc.Boss_CanShootExtraAt(i, rotation % 3, 3, 1200f, alwaysSkipMainTarget: false))
if (npc.Boss_CanShootExtraAt(player.whoAmI, rotation % 3, 3, 1200f, alwaysSkipMainTarget: false))
{
// Normal shadow hand spawn behavior
// Modified to make the shadow hand spawns fair
RandomizeInsanityShadowFor(Main.player[i], isHostile: true, out var spawnPosition, out var spawnVelocity, out var ai, out var ai2);
RandomizeInsanityShadowFor(player, isHostile: true, out var spawnPosition, out var spawnVelocity, out var ai, out var ai2);
// Spawn hands to cut the player off and force them back towards Deerclops
// This only happens if the player is triggering Deerclops' increased DR
float minShadowHandSpawnDistanceFromPlayer = 450f;
float playerDistanceFromDeerclops = Vector2.Distance(npc.Center, Main.player[i].Center);
float playerDistanceFromDeerclops = Vector2.Distance(npc.Center, player.Center);
if (playerDistanceFromDeerclops >= 450f)
{
spawnPosition = (Main.player[i].Center - npc.Center).SafeNormalize(Vector2.UnitY) * (playerDistanceFromDeerclops + minShadowHandSpawnDistanceFromPlayer);
spawnVelocity = (Main.player[i].Center - spawnPosition).SafeNormalize(Vector2.UnitY) * spawnVelocity.Length();
spawnPosition = (player.Center - npc.Center).SafeNormalize(Vector2.UnitY) * (playerDistanceFromDeerclops + minShadowHandSpawnDistanceFromPlayer);
spawnVelocity = (player.Center - spawnPosition).SafeNormalize(Vector2.UnitY) * spawnVelocity.Length();
}
Projectile.NewProjectile(npc.GetSource_FromAI(), spawnPosition, spawnVelocity, shadowHand, shadowHandDamage, 0f, Main.myPlayer, ai, ai2);
@@ -342,16 +342,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
if (npc.position.Y > player.position.Y)
{
for (int m = 0; m < Main.maxPlayers; m++)
foreach (Player plr in Main.ActivePlayers)
{
if (Main.player[m].active)
Rectangle noFlyRectangle = new Rectangle((int)plr.position.X - noFlyZone, (int)plr.position.Y - noFlyZone, noFlyZone * 2, height);
if (rectangle.Intersects(noFlyRectangle))
{
Rectangle noFlyRectangle = new Rectangle((int)Main.player[m].position.X - noFlyZone, (int)Main.player[m].position.Y - noFlyZone, noFlyZone * 2, height);
if (rectangle.Intersects(noFlyRectangle))
{
outsideNoFlyZone = false;
break;
}
outsideNoFlyZone = false;
break;
}
}
if (outsideNoFlyZone)
@@ -281,16 +281,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
noFlyZone = 100;
bool freeMoveAnyway = true;
for (int k = 0; k < Main.maxPlayers; k++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[k].active)
Rectangle rectangle2 = new Rectangle((int)player.position.X - noFlyZone, (int)player.position.Y - noFlyZone, noFlyZone * 2, noFlyZone * 2);
if (rectangle.Intersects(rectangle2))
{
Rectangle rectangle2 = new Rectangle((int)Main.player[k].position.X - noFlyZone, (int)Main.player[k].position.Y - noFlyZone, noFlyZone * 2, noFlyZone * 2);
if (rectangle.Intersects(rectangle2))
{
freeMoveAnyway = false;
break;
}
freeMoveAnyway = false;
break;
}
}
if (freeMoveAnyway)
@@ -430,9 +427,9 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
if (shouldDespawn && !bossRush)
{
bool everyoneDead = true;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[i].active && !Main.player[i].dead)
if (!player.dead)
{
everyoneDead = false;
break;
@@ -502,12 +502,12 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
continue;
// Spawn extra Ethereal Lances per player.
for (int j = 0; j < Main.maxPlayers; j++)
foreach (Player player in Main.ActivePlayers)
{
if (!npc.Boss_CanShootExtraAt(j, lanceFrequency % 3, 3, 2400f))
if (!npc.Boss_CanShootExtraAt(player.whoAmI, lanceFrequency % 3, 3, 2400f))
continue;
Player extraPlayer = Main.player[j];
Player extraPlayer = player;
playerCenter = extraPlayer.Center;
if (Vector2.Dot(extraPlayer.velocity.SafeNormalize(Vector2.UnitY), lanceDirection) > 0f)
lanceDirection *= -1f;
@@ -988,12 +988,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
continue;
int multiplayerExtraStraightLances = (int)(npc.ai[1] / etherealLanceGateValue);
for (int l = 0; l < Main.maxPlayers; l++)
foreach (Player player in Main.ActivePlayers)
{
if (!npc.Boss_CanShootExtraAt(l, multiplayerExtraStraightLances % 3, 3, 2400f))
if (!npc.Boss_CanShootExtraAt(player.whoAmI, multiplayerExtraStraightLances % 3, 3, 2400f))
continue;
Player player = Main.player[l];
inverseTargetVel = -player.velocity;
inverseTargetVel.SafeNormalize(-Vector2.UnitY);
targetCenter = player.Center;
@@ -842,10 +842,9 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
if (attackTimer == 0f && Main.netMode != NetmodeID.MultiplayerClient)
{
Vector2 leechNPCCenter = npc.Center + leechCenterOffset;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player6 in Main.ActivePlayers)
{
Player player6 = Main.player[i];
if (player6.active && !player6.dead && Vector2.Distance(player6.Center, leechNPCCenter) <= 3000f)
if (!player6.dead && Vector2.Distance(player6.Center, leechNPCCenter) <= 3000f)
{
Vector2 targetLeechDist = Main.player[npc.target].Center - leechNPCCenter;
if (targetLeechDist != Vector2.Zero)
@@ -440,9 +440,9 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses
// Bee spawn timer
npc.ai[1] += 1f;
int beeSpawnTimer = 0;
for (int i = 0; i < 255; i++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[i].active && !Main.player[i].dead && (npc.Center - Main.player[i].Center).Length() < 1000f)
if (!player.dead && (npc.Center - player.Center).Length() < 1000f)
beeSpawnTimer++;
}
npc.ai[1] += beeSpawnTimer / 2;
+1 -3
View File
@@ -124,10 +124,8 @@ namespace CalamityMod.Projectiles.Boss
float distanceRequired = 800f * Projectile.scale;
float succPower = Main.zenithWorld ? 1f : 0.5f;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player player = Main.player[i];
float distance = Vector2.Distance(player.Center, Projectile.Center);
if (distance < distanceRequired && player.grappling[0] == -1)
{
@@ -107,9 +107,9 @@ namespace CalamityMod.Projectiles.Boss
Projectile.alpha = (int)MathHelper.Lerp(0f, 255f, (Projectile.ai[0] - 600f) / 120f);
bool canSpawnBoomer = false;
for (int i = 0; i < Main.player.Length; i++)
foreach (Player player in Main.ActivePlayers)
{
if (!Main.player[i].dead && Projectile.Distance(Main.player[i].Center) < 12000f)
if (!player.dead && Projectile.Distance(player.Center) < 12000f)
{
canSpawnBoomer = true;
break;
+2 -3
View File
@@ -3142,10 +3142,9 @@ namespace CalamityMod.Projectiles
float lowestHealthCheck = 0f;
int healTarget = projectile.owner;
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player otherPlayer in Main.ActivePlayers)
{
Player otherPlayer = Main.player[i];
if (otherPlayer.active && !otherPlayer.dead && ((!player.hostile && !otherPlayer.hostile) || player.team == otherPlayer.team))
if (!otherPlayer.dead && ((!player.hostile && !otherPlayer.hostile) || player.team == otherPlayer.team))
{
float playerDist = Vector2.Distance(projectile.Center, otherPlayer.Center);
if (playerDist < distanceRequired && (otherPlayer.statLifeMax2 - otherPlayer.statLife) > lowestHealthCheck)
+2 -2
View File
@@ -35,9 +35,9 @@ namespace CalamityMod.Projectiles.Enemy
Projectile.velocity.Y += 0.15f;
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
for (int i = 0; i < Main.player.Length; i++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[i].Distance(Projectile.Center) < 60f)
if (player.Distance(Projectile.Center) < 60f)
{
Projectile.Kill();
}
+1 -2
View File
@@ -78,9 +78,8 @@ namespace CalamityMod.Projectiles.Pets
npc.Calamity().ladHearts = CalamityUtils.SecondsToFrames(9f);
}
}
for (int k = 0; k < Main.maxPlayers; k++)
foreach (Player players in Main.ActivePlayers)
{
Player players = Main.player[k];
if (!players.dead && Vector2.Distance(Projectile.Center, players.Center) <= radius)
{
if (players.Calamity().ladHearts <= 0)
+1 -2
View File
@@ -93,10 +93,9 @@ namespace CalamityMod.Projectiles.Rogue
int buffType = ModContent.BuffType<GlacialState>();
float radius = 112f; // 7 blocks
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player player in Main.ActivePlayers)
{
Player owner = Main.player[Projectile.owner];
Player player = Main.player[i];
if ((owner.team != player.team || player.team == 0) && player.hostile && owner.hostile && !player.dead && !player.buffImmune[buffType] && Vector2.Distance(Projectile.Center, player.Center) <= radius)
{
if (player.FindBuffIndex(buffType) == -1)
+4 -4
View File
@@ -315,14 +315,14 @@ namespace CalamityMod.Projectiles.Summon
if (Main.netMode == NetmodeID.MultiplayerClient && mouseDistanceToOwner > 120f)
{
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player p in Main.ActivePlayers)
{
if (Main.player[i].active && !Main.player[i].dead && (Main.player[i].team == Owner.team || Main.player[i].team == 0))
if (!p.dead && (p.team == Owner.team || p.team == 0))
{
float mouseDistanceToPotentialTarget = (Main.player[i].MountedCenter - Owner.Calamity().mouseWorld).Length();
float mouseDistanceToPotentialTarget = (p.MountedCenter - Owner.Calamity().mouseWorld).Length();
if (mouseDistanceToPotentialTarget < 120f && mouseDistanceToOwner > mouseDistanceToPotentialTarget)
{
playerToBuff = Main.player[i];
playerToBuff = p;
mouseDistanceToOwner = mouseDistanceToPotentialTarget;
}
}
@@ -45,16 +45,13 @@ namespace CalamityMod.Projectiles.Typeless
public override void OnKill(int timeLeft)
{
BossRushEvent.End();
for (int i = Main.maxPlayers - 1; i >= 0; i--)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (p is null || !p.active)
continue;
int rock = Item.NewItem(p.GetSource_Misc("CalamityMod_BossRushRock"), (int)p.position.X, (int)p.position.Y, p.width, p.height, ModContent.ItemType<Rock>());
if (Main.netMode == NetmodeID.Server)
{
Main.timeItemSlotCannotBeReusedFor[rock] = 54000;
NetMessage.SendData(MessageID.InstancedItem, i, -1, null, rock);
NetMessage.SendData(MessageID.InstancedItem, p.whoAmI, -1, null, rock);
}
}
}
+3 -3
View File
@@ -43,13 +43,13 @@ namespace CalamityMod.Projectiles.Typeless
if (Main.netMode == NetmodeID.MultiplayerClient)
{
float closestPlayerDistance = (Main.LocalPlayer.Center - Projectile.Center).Length();
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player plr in Main.ActivePlayers)
{
float newDistance = (Main.player[i].Center - Projectile.Center).Length();
float newDistance = (plr.Center - Projectile.Center).Length();
if (newDistance < closestPlayerDistance)
{
closestPlayerDistance = newDistance;
player = Main.player[i];
player = plr;
}
}
}
+3 -3
View File
@@ -101,12 +101,12 @@ namespace CalamityMod.Systems
// Attempt to summon lab critters manually since they refuse to exist when using vanilla's spawn methods.
// This needs to check all players since the method only runs server-side.
for (int i = 0; i < Main.maxPlayers; i++)
foreach (Player p in Main.ActivePlayers)
{
if (!Main.player[i].active || Main.player[i].dead)
if (p.dead)
continue;
CalamityGlobalNPC.AttemptToSpawnLabCritters(Main.player[i]);
CalamityGlobalNPC.AttemptToSpawnLabCritters(p);
}
// Make the cultist countdown happen much more quickly.
+2 -3
View File
@@ -140,10 +140,9 @@ namespace CalamityMod.TileEntities
// If this charging station breaks, anyone's who's viewing it is no longer viewing it.
public override void OnKill()
{
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active)
if (p.dead)
continue;
// Use reflection to stop TML from spitting an error here.
+3 -4
View File
@@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities
Vector2 ret = InvalidTarget;
float distSQToBeat = MaxRange * MaxRange;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active || p.dead)
if (p.dead)
continue;
float distSQ = p.DistanceSQ(targetingCenter);
@@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities
{
distSQToBeat = distSQ;
ret = p.Center;
indexToSet = i;
indexToSet = p.whoAmI;
}
}
+3 -4
View File
@@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities
Vector2 ret = InvalidTarget;
float distSQToBeat = MaxRange * MaxRange;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active || p.dead)
if (p.dead)
continue;
float distSQ = p.DistanceSQ(targetingCenter);
@@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities
{
distSQToBeat = distSQ;
ret = p.Center;
indexToSet = i;
indexToSet = p.whoAmI;
}
}
+3 -4
View File
@@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities
Vector2 ret = InvalidTarget;
float distSQToBeat = MaxRange * MaxRange;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active || p.dead)
if (p.dead)
continue;
float distSQ = p.DistanceSQ(targetingCenter);
@@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities
{
distSQToBeat = distSQ;
ret = p.Center;
indexToSet = i;
indexToSet = p.whoAmI;
}
}
+3 -4
View File
@@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities
Vector2 ret = InvalidTarget;
float distSQToBeat = MaxRange * MaxRange;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active || p.dead)
if (p.dead)
continue;
float distSQ = p.DistanceSQ(targetingCenter);
@@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities
{
distSQToBeat = distSQ;
ret = p.Center;
indexToSet = i;
indexToSet = p.whoAmI;
}
}
+3 -4
View File
@@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities
Vector2 ret = InvalidTarget;
float distSQToBeat = MaxRange * MaxRange;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active || p.dead)
if (p.dead)
continue;
float distSQ = p.DistanceSQ(targetingCenter);
@@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities
{
distSQToBeat = distSQ;
ret = p.Center;
indexToSet = i;
indexToSet = p.whoAmI;
}
}
+3 -4
View File
@@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities
Vector2 ret = InvalidTarget;
float distSQToBeat = MaxRange * MaxRange;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active || p.dead)
if (p.dead)
continue;
float distSQ = p.DistanceSQ(targetingCenter);
@@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities
{
distSQToBeat = distSQ;
ret = p.Center;
indexToSet = i;
indexToSet = p.whoAmI;
}
}
+4 -4
View File
@@ -2,6 +2,7 @@
using CalamityMod.Tiles.DraedonStructures;
using Microsoft.Xna.Framework;
using System.IO;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
@@ -85,10 +86,9 @@ namespace CalamityMod.TileEntities
Vector2 ret = InvalidTarget;
float distSQToBeat = MaxRange * MaxRange;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active || p.dead)
if (p.dead)
continue;
float distSQ = p.DistanceSQ(targetingCenter);
@@ -96,7 +96,7 @@ namespace CalamityMod.TileEntities
{
distSQToBeat = distSQ;
ret = p.Center;
indexToSet = i;
indexToSet = p.whoAmI;
}
}
+4 -9
View File
@@ -35,11 +35,10 @@ namespace CalamityMod.TileEntities
// If one is, pop up.
Vector2 projectorCenterPos = Center;
float distSQ = PopupDistance * PopupDistance;
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active) // The lack of a dead check is intentional. Dead players keep hologram boxes on for amusement.
continue;
// The lack of a dead check is intentional. Dead players keep hologram boxes on for amusement.
if (p.DistanceSQ(projectorCenterPos) < distSQ)
{
PoppingUp = true;
@@ -72,12 +71,8 @@ namespace CalamityMod.TileEntities
// If this projector breaks, anyone who's viewing it is no longer viewing it.
public override void OnKill()
{
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active)
continue;
// Use reflection to stop TML from spitting an error here.
// Try-catching will not stop this error, TML will print it to console anyway. The error is harmless.
ModPlayer[] mpStorageArray = (ModPlayer[])typeof(Player).GetField("modPlayers", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(p);
+1 -5
View File
@@ -103,12 +103,8 @@ namespace CalamityMod.TileEntities
// If this factory breaks, anyone who's viewing it is no longer viewing it.
public override void OnKill()
{
for (int i = 0; i < Main.maxPlayers; ++i)
foreach (Player p in Main.ActivePlayers)
{
Player p = Main.player[i];
if (!p.active)
continue;
// Use reflection to stop TML from spitting an error here.
// Try-catching will not stop this error, TML will print it to console anyway. The error is harmless.
ModPlayer[] mpStorageArray = (ModPlayer[])typeof(Player).GetField("modPlayers", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(p);
+2 -3
View File
@@ -1154,9 +1154,8 @@ namespace CalamityMod
NPC npc = info.npc;
int idx = Item.NewItem(npc.GetSource_Loot(), npc.Center, itemId, stack, true, -1);
Main.timeItemSlotCannotBeReusedFor[idx] = protectionTime;
for (int i = 0; i < Main.maxPlayers; ++i)
if (Main.player[i].active)
NetMessage.SendData(MessageID.InstancedItem, i, -1, null, idx);
foreach (Player player in Main.ActivePlayers)
NetMessage.SendData(MessageID.InstancedItem, player.whoAmI, -1, null, idx);
Main.item[idx].active = false;
}
+6 -9
View File
@@ -83,13 +83,10 @@ namespace CalamityMod.World
// Clients in multiplayer don't drop meteors.
if (Main.netMode == NetmodeID.MultiplayerClient)
return;
for (int i = 0; i < 255; i++)
foreach (Player _ in Main.ActivePlayers)
{
if (Main.player[i].active)
{
meteorDropped = false;
break;
}
meteorDropped = false;
break;
}
// Check whether there is already too much ore.
@@ -257,11 +254,11 @@ namespace CalamityMod.World
}
int avoidRectangleSize = 35;
Rectangle rectangle = new Rectangle((i - avoidRectangleSize) * 16, (j - avoidRectangleSize) * 16, avoidRectangleSize * 2 * 16, avoidRectangleSize * 2 * 16);
for (int k = 0; k < Main.maxPlayers; k++)
foreach (Player player in Main.ActivePlayers)
{
if (Main.player[k].active)
if (player.active)
{
Rectangle value = new Rectangle((int)(Main.player[k].position.X + (float)(Main.player[k].width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.player[k].position.Y + (float)(Main.player[k].height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2);
Rectangle value = new Rectangle((int)(player.position.X + (float)(player.width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(player.position.Y + (float)(player.height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2);
if (rectangle.Intersects(value))
{
return false;