private static void UpdateTime() { Time += 1.0; if (!dayTime) { if (WorldModify.spawnEye && Time > 4860.0) { foreach (Player player in players) { if (player.Active && !player.dead && (double)player.Position.Y < worldSurface * 16.0) { NPC.SpawnOnPlayer(player.whoAmi, 4); WorldModify.spawnEye = false; break; } } } if (Time > 32400.0) { checkXmas(); if (invasionDelay > 0) { invasionDelay--; } WorldModify.spawnNPC = 0; checkForSpawns = 0; Time = 0.0; bloodMoon = false; dayTime = true; moonPhase++; if (moonPhase >= 8) { moonPhase = 0; } NetMessage.SendData(7); WorldIO.SaveWorldThreaded(); if (WorldModify.shadowOrbSmashed) { var startInvasion = !NPC.downedGoblins ? rand.Next(3) == 0 : rand.Next(15) == 0; if (startInvasion) { StartInvasion(); } } } if (Time > 16200.0 && WorldModify.spawnMeteor) { WorldModify.spawnMeteor = false; WorldModify.dropMeteor(null, null); return; } } else { bloodMoon = false; if (Time > 54000.0) { WorldModify.spawnNPC = 0; checkForSpawns = 0; if (rand.Next(50) == 0 && WorldModify.shadowOrbSmashed) { WorldModify.spawnMeteor = true; } if (!NPC.downedBoss1) { bool flag = false; foreach (Player player in players) { if (player.Active && player.statLifeMax >= 200 && player.statDefense > 10) { flag = true; break; } } if (flag && rand.Next(3) == 0) { int num = 0; for (int i = 0; i < NPC.MAX_NPCS; i++) { if (npcs[i].Active && npcs[i].townNPC) { num++; } } if (num >= 4) { WorldModify.spawnEye = true; NetMessage.SendData(25, -1, -1, "You feel an evil presence watching you...", 255, 50f, 255f, 130f); } } } if (!WorldModify.spawnEye && moonPhase != 4 && rand.Next(9) == 0) { for (int i = 0; i < 255; i++) { if (players[i].Active && players[i].statLifeMax > 100) { bloodMoon = true; break; } } if (bloodMoon) { NetMessage.SendData(25, -1, -1, "The Blood Moon is rising...", 255, 50f, 255f, 130f); } } Time = 0.0; dayTime = false; NetMessage.SendData(7); } //checkForSpawns++; if (++checkForSpawns >= 7200) { int num2 = 0; for (int i = 0; i < 255; i++) { if (players[i].Active) { num2++; } } checkForSpawns = 0; WorldModify.spawnNPC = 0; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; int num7 = 0; int num8 = 0; int num9 = 0; int num10 = 0; int num11 = 0; int goblin = 0, wizard = 0, mechanic = 0, santa = 0; for (int i = 0; i < NPC.MAX_NPCS; i++) { if (npcs[i].Active && npcs[i].townNPC) { if (npcs[i].type != NPCType.N37_OLD_MAN && !npcs[i].homeless) { WorldModify.QuickFindHome(null, i); } switch (npcs[i].type) { case NPCType.N37_OLD_MAN: num8++; break; case NPCType.N17_MERCHANT: num3++; break; case NPCType.N18_NURSE: num4++; break; case NPCType.N19_ARMS_DEALER: num6++; break; case NPCType.N20_DRYAD: num5++; break; case NPCType.N22_GUIDE: num7++; break; case NPCType.N38_DEMOLITIONIST: num9++; break; case NPCType.N54_CLOTHIER: num10++; break; case NPCType.N107_GOBLIN_TINKERER: goblin++; break; case NPCType.N108_WIZARD: wizard++; break; case NPCType.N124_MECHANIC: mechanic++; break; case NPCType.N142_SANTA_CLAUS: santa++; break; } num11++; } } if (WorldModify.spawnNPC == 0) { int num12 = 0; bool flag2 = false; int num13 = 0; bool flag3 = false; bool flag4 = false; for (int i = 0; i < 255; i++) { if (players[i].Active) { for (int j = 0; j < 44; j++) { if (players[i].inventory[j] != null & players[i].inventory[j].Stack > 0) { if (players[i].inventory[j].Type == 71) { num12 += players[i].inventory[j].Stack; } if (players[i].inventory[j].Type == 72) { num12 += players[i].inventory[j].Stack * 100; } if (players[i].inventory[j].Type == 73) { num12 += players[i].inventory[j].Stack * 10000; } if (players[i].inventory[j].Type == 74) { num12 += players[i].inventory[j].Stack * 1000000; } if (players[i].inventory[j].Ammo == ProjectileType.N14_BULLET || players[i].inventory[j].UseAmmo == ProjectileType.N14_BULLET) { flag3 = true; } if (players[i].inventory[j].Type == 166 || players[i].inventory[j].Type == 167 || players[i].inventory[j].Type == 168 || players[i].inventory[j].Type == 235) { flag4 = true; } } } int num14 = players[i].statLifeMax / 20; if (num14 > 5) { flag2 = true; } num13 += num14; } } if (!NPC.downedBoss3 && num8 == 0) { int num15 = NPC.NewNPC(dungeonX * 16 + 8, dungeonY * 16, 37, 0); npcs[num15].homeless = false; npcs[num15].homeTileX = dungeonX; npcs[num15].homeTileY = dungeonY; } if (WorldModify.spawnNPC == 0 && num7 < 1) { WorldModify.spawnNPC = 22; } if (WorldModify.spawnNPC == 0 && (double)num12 > 5000.0 && num3 < 1) { WorldModify.spawnNPC = 17; } if (WorldModify.spawnNPC == 0 && flag2 && num4 < 1) { WorldModify.spawnNPC = 18; } if (WorldModify.spawnNPC == 0 && flag3 && num6 < 1) { WorldModify.spawnNPC = 19; } if (WorldModify.spawnNPC == 0 && (NPC.downedBoss1 || NPC.downedBoss2 || NPC.downedBoss3) && num5 < 1) { WorldModify.spawnNPC = 20; } if (WorldModify.spawnNPC == 0 && flag4 && num3 > 0 && num9 < 1) { WorldModify.spawnNPC = 38; } if (WorldModify.spawnNPC == 0 && NPC.downedBoss3 && num10 < 1) { WorldModify.spawnNPC = 54; } if (WorldModify.spawnNPC == 0 && NPC.savedGoblin && goblin < 1) { WorldModify.spawnNPC = 107; } if (WorldModify.spawnNPC == 0 && NPC.savedWizard && wizard < 1) { WorldModify.spawnNPC = 108; } if (WorldModify.spawnNPC == 0 && NPC.savedMech && mechanic < 1) { WorldModify.spawnNPC = 124; } if (WorldModify.spawnNPC == 0 && NPC.downedFrost && santa < 1 && Xmas) { WorldModify.spawnNPC = 142; } } } } }
//static TimeChangedEvent timeEvent = new TimeChangedEvent(); private static void UpdateTime() { Main.time += 1.0; //Server.PluginManager.processHook(Hooks.TIME_CHANGED, timeEvent); if (!Main.dayTime) { if (WorldModify.spawnEye) { if (Main.time > 4860.0) { int count = 0; foreach (Player player in Main.players) { if (player.Active && !player.dead && (double)player.Position.Y < Main.worldSurface * 16.0) { NPC.SpawnOnPlayer(player, count, 4); WorldModify.spawnEye = false; break; } count++; } } } if (Main.time > 32400.0) { if (Main.invasionDelay > 0) { Main.invasionDelay--; } WorldModify.spawnNPC = 0; Main.checkForSpawns = 0; Main.time = 0.0; Main.bloodMoon = false; Main.dayTime = true; Main.moonPhase++; if (Main.moonPhase >= 8) { Main.moonPhase = 0; } NetMessage.SendData(7); WorldIO.SaveWorldThreaded(); if (Main.rand.Next(15) == 0) { Main.StartInvasion(); } } if (Main.time > 16200.0 && WorldModify.spawnMeteor) { WorldModify.spawnMeteor = false; WorldModify.dropMeteor(); } } else { if (Main.time > 54000.0) { WorldModify.spawnNPC = 0; Main.checkForSpawns = 0; if (Main.rand.Next(50) == 0 && WorldModify.shadowOrbSmashed) { WorldModify.spawnMeteor = true; } if (!NPC.downedBoss1) { bool flag = false; foreach (Player player in Main.players) { if (player.Active && player.statLifeMax >= 200) { flag = true; break; } } if (flag && Main.rand.Next(3) == 0) { int num = 0; for (int i = 0; i < NPC.MAX_NPCS; i++) { if (Main.npcs[i].Active) { if (Main.npcs[i].townNPC) { num++; } } } if (num >= 4) { WorldModify.spawnEye = true; NetMessage.SendData(25, -1, -1, "You feel an evil presence watching you...", 255, 50f, 255f, 130f); } } } if (!WorldModify.spawnEye && Main.moonPhase != 4 && Main.rand.Next(7) == 0) { for (int i = 0; i < 255; i++) { if (Main.players[i].Active && Main.players[i].statLifeMax > 100) { Main.bloodMoon = true; break; } } if (Main.bloodMoon) { NetMessage.SendData(25, -1, -1, "The Blood Moon is rising...", 255, 50f, 255f, 130f); } } Main.time = 0.0; Main.dayTime = false; NetMessage.SendData(7); } Main.checkForSpawns++; if (Main.checkForSpawns >= 7200) { int num2 = 0; for (int i = 0; i < 255; i++) { if (Main.players[i].Active) { num2++; } } Main.checkForSpawns = 0; WorldModify.spawnNPC = 0; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; int num7 = 0; int num8 = 0; int num9 = 0; int num10 = 0; int num11 = 0; for (int i = 0; i < NPC.MAX_NPCS; i++) { if (Main.npcs[i].Active && Main.npcs[i].townNPC) { if (Main.npcs[i].type != NPCType.N37_OLD_MAN && !Main.npcs[i].homeless) { WorldModify.QuickFindHome(i); } else { num8++; } switch (Main.npcs[i].type) { case NPCType.N17_MERCHANT: num3++; break; case NPCType.N18_NURSE: num4++; break; case NPCType.N19_ARMS_DEALER: num6++; break; case NPCType.N20_DRYAD: num5++; break; case NPCType.N22_GUIDE: num7++; break; case NPCType.N38_DEMOLITIONIST: num9++; break; case NPCType.N54_CLOTHIER: num10++; break; } num11++; } } if (WorldModify.spawnNPC == 0) { int num12 = 0; bool flag2 = false; int num13 = 0; bool flag3 = false; bool flag4 = false; for (int i = 0; i < 255; i++) { if (Main.players[i].Active) { for (int j = 0; j < 44; j++) { if (Main.players[i].inventory[j] != null & Main.players[i].inventory[j].Stack > 0) { if (Main.players[i].inventory[j].Type == 71) { num12 += Main.players[i].inventory[j].Stack; } if (Main.players[i].inventory[j].Type == 72) { num12 += Main.players[i].inventory[j].Stack * 100; } if (Main.players[i].inventory[j].Type == 73) { num12 += Main.players[i].inventory[j].Stack * 10000; } if (Main.players[i].inventory[j].Type == 74) { num12 += Main.players[i].inventory[j].Stack * 1000000; } if (Main.players[i].inventory[j].Ammo == ProjectileType.N14_BULLET || Main.players[i].inventory[j].UseAmmo == ProjectileType.N14_BULLET) { flag3 = true; } if (Main.players[i].inventory[j].Type == 166 || Main.players[i].inventory[j].Type == 167 || Main.players[i].inventory[j].Type == 168 || Main.players[i].inventory[j].Type == 235) { flag4 = true; } } } int num14 = Main.players[i].statLifeMax / 20; if (num14 > 5) { flag2 = true; } num13 += num14; } } if (num7 < 1) { WorldModify.spawnNPC = 22; } if ((double)num12 > 5000.0 && num3 < 1) { WorldModify.spawnNPC = 17; } if (flag2 && num4 < 1) { WorldModify.spawnNPC = 18; } if (flag3 && num6 < 1) { WorldModify.spawnNPC = 19; } if ((NPC.downedBoss1 || NPC.downedBoss2 || NPC.downedBoss3) && num5 < 1) { WorldModify.spawnNPC = 20; } if (flag4 && num3 > 0 && num9 < 1) { WorldModify.spawnNPC = 38; } if (NPC.downedBoss3 && num10 < 1) { WorldModify.spawnNPC = 54; } if (num12 > 100000 && num3 < 2 && num2 > 2) { WorldModify.spawnNPC = 17; } if (num13 >= 20 && num4 < 2 && num2 > 2) { WorldModify.spawnNPC = 18; } if (num12 > 5000000 && num3 < 3 && num2 > 4) { WorldModify.spawnNPC = 17; } if (!NPC.downedBoss3 && num8 == 0) { int num15 = NPC.NewNPC(Main.dungeonX * 16 + 8, Main.dungeonY * 16, 37, 0); Main.npcs[num15].homeless = false; Main.npcs[num15].homeTileX = Main.dungeonX; Main.npcs[num15].homeTileY = Main.dungeonY; } } } } }