コード例 #1
0
        internal static void CalculateLoot(NPC npc, Player player)
        {
            ModItem itembag = null;

            player.active = true;

            if (npc.type == NPCID.KingSlime)
            {
                NPC.downedSlimeKing = false;
            }
            if (npc.type == NPCID.EyeofCthulhu)
            {
                NPC.downedBoss1 = false;
            }
            if (npc.type == NPCID.EaterofWorldsHead)
            {
                NPC.downedBoss2 = false;
            }
            if (npc.type == NPCID.BrainofCthulhu)
            {
                NPC.downedBoss2 = false;
            }
            if (npc.type == NPCID.QueenBee)
            {
                NPC.downedQueenBee = false;
            }
            if (npc.type == NPCID.SkeletronHead)
            {
                NPC.downedBoss3 = false;
            }
            if (npc.type == NPCID.WallofFlesh)
            {
                Main.hardMode = false;
            }
            if (npc.type == NPCID.TheDestroyer)
            {
                NPC.downedMechBoss1 = false;
            }
            if (npc.type == NPCID.Retinazer)
            {
                NPC.downedMechBoss2 = false;
            }
            if (npc.type == NPCID.Spazmatism)
            {
                NPC.downedMechBoss2 = false;
            }
            if (npc.type == NPCID.SkeletronPrime)
            {
                NPC.downedMechBoss3 = false;
            }
            if (npc.type == NPCID.Plantera)
            {
                NPC.downedPlantBoss = false;
            }
            if (npc.type == NPCID.Golem)
            {
                NPC.downedGolemBoss = false;
            }
            if (npc.type == NPCID.DukeFishron)
            {
                NPC.downedFishron = false;
            }
            if (npc.type == NPCID.CultistBoss)
            {
                NPC.downedAncientCultist = false;
            }
            if (npc.type == NPCID.MoonLordCore)
            {
                NPC.downedMoonlord = false;
            }

            if (npc.type == 564 || npc.type == 565 || npc.type == 576 || npc.type == 577)
            {
                DD2Event.Ongoing = true;
            }

            if (npc.type == 345 || npc.type == 346 || npc.type == 344)
            {
                Main.dayTime = false; Main.snowMoon = true;
            }

            if (npc.type == 54 || npc.type == 55 || npc.type == 56 || npc.type == 325 || npc.type == 326 || npc.type == 327 || npc.type == 315 || (npc.type >= 305 && npc.type <= 314))
            {
                Main.dayTime = false; Main.pumpkinMoon = true;
            }

            if (npc.type == 489 || npc.type == 490 || npc.type == 109)
            {
                Main.dayTime = false; Main.bloodMoon = true;
            }

            if (ModLoader.GetMod("CalamityMod") != null)
            {
                if (npc.type == ModLoader.GetMod("CalamityMod").NPCType("Yharon"))
                {
                    npc.modNPC.npc.ai[0]    = 25f;
                    npc.modNPC.npc.ai[2]    = 190;
                    npc.modNPC.npc.timeLeft = 6;
                }
            }

            npc.Center = new Microsoft.Xna.Framework.Vector2(1000, 1000);
            int iterationsWithNoChange = 0;

            var realRandom = Main.rand;
            var fakeRandom = new LootUnifiedRandom();

            for (int i = 0; i < 500; i++)
            {
                if (npc.type == NPCID.KingSlime)
                {
                    player.OpenBossBag(3318);
                }
                if (npc.type == NPCID.EyeofCthulhu)
                {
                    player.OpenBossBag(3319);
                }
                if (npc.type == NPCID.EaterofWorldsHead)
                {
                    player.OpenBossBag(3320);
                }
                if (npc.type == NPCID.BrainofCthulhu)
                {
                    player.OpenBossBag(3321);
                }
                if (npc.type == NPCID.QueenBee)
                {
                    player.OpenBossBag(3322);
                }
                if (npc.type == NPCID.SkeletronHead)
                {
                    player.OpenBossBag(3323);
                }
                if (npc.type == NPCID.WallofFlesh)
                {
                    player.OpenBossBag(3324);
                }
                if (npc.type == NPCID.TheDestroyer)
                {
                    player.OpenBossBag(3325);
                }
                if (npc.type == NPCID.Retinazer)
                {
                    player.OpenBossBag(3326);
                }
                if (npc.type == NPCID.Spazmatism)
                {
                    player.OpenBossBag(3326);
                }
                if (npc.type == NPCID.SkeletronPrime)
                {
                    player.OpenBossBag(3327);
                }
                if (npc.type == NPCID.Plantera)
                {
                    player.OpenBossBag(3328);
                }
                if (npc.type == NPCID.Golem)
                {
                    player.OpenBossBag(3329);
                }
                if (npc.type == NPCID.DukeFishron)
                {
                    player.OpenBossBag(3330);
                }
                if (npc.type == NPCID.CultistBoss)
                {
                    player.OpenBossBag(3331);
                }
                if (npc.type == NPCID.MoonLordCore)
                {
                    player.OpenBossBag(3332);
                }
                if (npc.type == NPCID.DD2Betsy)
                {
                    player.OpenBossBag(3860);
                }
                foreach (var item in Main.item)
                {
                    if (item.active)
                    {
                        //if (ignoreItemIDS.Contains(item.type))  // npc.value = 0;
                        //	continue;
                        loots.Add(item.type);                         // hmm, Item.NewItem reverseLookup?
                        item.active = false;
                        //if (iterationsWithNoChange > 150)
                        //	Debug.WriteLine($"{i}: {iterationsWithNoChange} {item.Name}");
                    }
                    else
                    {
                        break;
                    }
                }
            }

            for (int i = 0; i < MaxNumberLootExperiments; i++)
            {
                if (i == 0)
                {
                    Main.rand = fakeRandom;
                }
                if (i == 50)
                {
                    Main.rand = realRandom;
                }

                if (i == 0 && npc.type == 22)
                {
                    npc.GivenName = "Andrew";
                }
                if (i == 1 && npc.type == 22)
                {
                    npc.GivenName = "Cerberus";
                }

                try
                {
                    LootUnifiedRandom.loop = i;
                    npc.NPCLoot();
                }
                catch
                {
                }
                npc.active = false;
                bool anyNew = false;
                //if(Main.item[400].active || Main.item[399].active)
                //{
                //	Console.WriteLine();
                //}

                foreach (var item in Main.item)
                {
                    if (item.active)
                    {
                        //if (ignoreItemIDS.Contains(item.type))  // npc.value = 0;
                        //	continue;
                        ModItem item2 = ItemLoader.GetItem(item.type);
                        if (item2 != null && item2.CanRightClick())
                        {
                            itembag = item2;
                        }
                        loots.Add(item.type);                         // hmm, Item.NewItem reverseLookup?
                        item.active = false;
                        anyNew      = true;
                        //if (iterationsWithNoChange > 150)
                        //	Debug.WriteLine($"{i}: {iterationsWithNoChange} {item.Name}");
                    }
                    else
                    {
                        break;
                    }
                }

                if (anyNew)
                {
                    iterationsWithNoChange = 0;
                }
                else
                {
                    iterationsWithNoChange++;
                }

                if (iterationsWithNoChange > 250)
                {
                    break;
                }
            }


            Main.snowMoon    = false;
            Main.pumpkinMoon = false;
            Main.bloodMoon   = false;
            DD2Event.Ongoing = false;

            if (npc.type == NPCID.KingSlime)
            {
                NPC.downedSlimeKing = true;
            }
            if (npc.type == NPCID.EyeofCthulhu)
            {
                NPC.downedBoss1 = true;
            }
            if (npc.type == NPCID.EaterofWorldsHead)
            {
                NPC.downedBoss2 = true;
            }
            if (npc.type == NPCID.BrainofCthulhu)
            {
                NPC.downedBoss2 = true;
            }
            if (npc.type == NPCID.QueenBee)
            {
                NPC.downedQueenBee = true;
            }
            if (npc.type == NPCID.SkeletronHead)
            {
                NPC.downedBoss3 = true;
            }
            if (npc.type == NPCID.WallofFlesh)
            {
                Main.hardMode = true;
            }
            if (npc.type == NPCID.TheDestroyer)
            {
                NPC.downedMechBoss1 = true;
            }
            if (npc.type == NPCID.Retinazer)
            {
                NPC.downedMechBoss2 = true;
            }
            if (npc.type == NPCID.Spazmatism)
            {
                NPC.downedMechBoss2 = true;
            }
            if (npc.type == NPCID.SkeletronPrime)
            {
                NPC.downedMechBoss3 = true;
            }
            if (npc.type == NPCID.Plantera)
            {
                NPC.downedPlantBoss = true;
            }
            if (npc.type == NPCID.Golem)
            {
                NPC.downedGolemBoss = true;
            }
            if (npc.type == NPCID.DukeFishron)
            {
                NPC.downedFishron = true;
            }
            if (npc.type == NPCID.CultistBoss)
            {
                NPC.downedAncientCultist = true;
            }
            if (npc.type == NPCID.MoonLordCore)
            {
                NPC.downedMoonlord = true;
            }

            for (int i = 0; i < 500; i++)
            {
                if (itembag != null && itembag.BossBagNPC > 0)
                {
                    itembag.OpenBossBag(player);
                    itembag.RightClick(player);
                }
                foreach (var item in Main.item)
                {
                    if (item.active)
                    {
                        //if (ignoreItemIDS.Contains(item.type))  // npc.value = 0;
                        //	continue;
                        loots.Add(item.type);                                 // hmm, Item.NewItem reverseLookup?
                        item.active = false;
                        //if (iterationsWithNoChange > 150)
                        //	Debug.WriteLine($"{i}: {iterationsWithNoChange} {item.Name}");
                    }
                    else
                    {
                        break;
                    }
                }
            }
            //}
        }