Example #1
0
        internal static void CalculateLoot(NPC npc)
        {
            if (npc.type == NPCID.WallofFlesh)
            {
                Main.hardMode = true;                                           //return;
            }
            // Hmmmmmm, start hardmode code might overwrite world....
            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 < MaxNumberLootExperiments; i++)
            {
                if (i == 0)
                {
                    Main.rand = fakeRandom;
                }
                if (i == 50)
                {
                    Main.rand = realRandom;
                }
                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;
                        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.hardMode = false;
        }
Example #2
0
        internal static bool CalculateLoot(NPC npc)
        {
            bool cancelled = false;

            if (npc.type == NPCID.WallofFlesh)
            {
                Main.hardMode = true;                                           //return;
            }
            // Hmmmmmm, start hardmode code might overwrite world....
            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 < MaxNumberLootExperiments; i++)
            {
                if (Main.keyState.PressingShift())
                {
                    RecipeBrowser.instance.Logger.Error($"LootCache calculation cancelled. NPCID {npc.type}/{NPCLoader.NPCCount}, Source Mod: {npc.modNPC?.mod.Name ?? "Terraria"}, Name: {Lang.GetNPCNameValue(npc.type)}, Step: {i}/{MaxNumberLootExperiments}");
                    cancelled = true;
                    break;
                }
                if (i == 0)
                {
                    Main.rand = fakeRandom;
                }
                if (i == 50)
                {
                    Main.rand = realRandom;
                }
                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;
                        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.hardMode = false;
            return(cancelled);
        }