Exemplo n.º 1
0
        /// <summary>
        /// Applies the painted buff to the provided npc, based on the paintColor and customPaint provided
        /// </summary>
        /// <param name="npc">The npc to apply the buff to</param>
        /// <param name="paintColor">The PaintID to use for painting the npc. Should be -1 when using a CustomPaint</param>
        /// <param name="customPaint">The CustomPaint to use for painting the npc. Should be null when using a vanilla paint</param>
        /// <param name="handledNpcs">Should not be provided</param>
        /// <param name="preventRecursion">Should not be provided</param>
        public static void applyPaintedToNPC(NPC npc, PaintData data, List <NPC> handledNpcs = null, bool preventRecursion = false)
        {
            switch (npc.type)
            {
            //cultist fight
            case NPCID.CultistDragonBody1:
            case NPCID.CultistDragonBody2:
            case NPCID.CultistDragonBody3:
            case NPCID.CultistDragonBody4:
            case NPCID.CultistDragonHead:
            case NPCID.CultistDragonTail:
            case NPCID.CultistBossClone:
            case NPCID.CultistBoss:
            case NPCID.AncientCultistSquidhead:
            //destroyer
            case NPCID.TheDestroyer:
            case NPCID.TheDestroyerBody:
            case NPCID.TheDestroyerTail:
            //pillars
            case NPCID.LunarTowerNebula:
            case NPCID.NebulaBeast:
            case NPCID.LunarTowerSolar:
            case NPCID.LunarTowerStardust:
            case NPCID.StardustWormTail:
            case NPCID.StardustWormBody:
            case NPCID.StardustWormHead:
            case NPCID.LunarTowerVortex:
            //martian saucer
            case NPCID.MartianSaucer:
            case NPCID.MartianSaucerCannon:
            case NPCID.MartianSaucerCore:
            case NPCID.MartianSaucerTurret:
            //misc bosses
            case NPCID.Pumpking:
            case NPCID.PumpkingBlade:
            //misc random mobs
            case NPCID.DungeonSpirit:
            case NPCID.Tumbleweed:
            case NPCID.DesertDjinn:
            case NPCID.Ghost:
            case NPCID.Poltergeist:
                return;
            }
            if (preventRecursion)
            {
                return;
            }

            npc.AddBuff(ModContent.BuffType <Painted>(), paintedBuffDuration);

            WoMDNPC globalNpc = npc.GetGlobalNPC <WoMDNPC>();

            if (data.CustomPaint != null)
            {
                data.CustomPaint.modifyPaintDataForNpc(ref data);
            }

            if (globalNpc.painted)
            {
                PaintData existingData = globalNpc.paintData;
                if (existingData.PaintColor == data.PaintColor &&
                    (existingData.CustomPaint == null) == (data.CustomPaint == null) &&                //either both or neither are null
                    existingData.CustomPaint.GetType().Equals(data.CustomPaint.GetType()) &&
                    existingData.sprayPaint == data.sprayPaint)
                {
                    return;                     //nothing needs to be updated
                }
            }

            globalNpc.setPaintData(npc, data);

            if (singlePlayer())
            {
                //TODO: do this whole section better
                if (handledNpcs == null)
                {
                    handledNpcs = new List <NPC>();
                }
                handledNpcs.Add(npc);
                switch (npc.type)
                {
                case NPCID.MoonLordHead:
                case NPCID.MoonLordHand:
                case NPCID.MoonLordCore:
                case NPCID.MoonLordLeechBlob:
                    for (int i = 0; i < Main.npc.Length; i++)
                    {
                        if (Main.npc[i].TypeName == "")
                        {
                            break;
                        }
                        switch (Main.npc[i].type)
                        {
                        case NPCID.MoonLordHead:
                        case NPCID.MoonLordHand:
                        case NPCID.MoonLordCore:
                            applyPaintedToNPC(Main.npc[i], data, null, true);
                            break;
                        }
                    }
                    break;

                case NPCID.EaterofWorldsBody:
                case NPCID.DevourerBody:
                case NPCID.WyvernBody:
                case NPCID.WyvernBody2:
                case NPCID.WyvernBody3:
                case NPCID.WyvernLegs:
                case NPCID.GiantWormBody:
                case NPCID.DiggerBody:
                case NPCID.SeekerBody:                         //world feeder
                case NPCID.TombCrawlerBody:
                case NPCID.DuneSplicerBody:
                case NPCID.SolarCrawltipedeBody:
                case NPCID.BoneSerpentBody:
                    if (npc.ai[0] == Math.Round(npc.ai[0]))
                    {
                        NPC prevSection = getNPC((int)npc.ai[0]);
                        if (prevSection != null && !handledNpcs.Contains(prevSection))
                        {
                            if (prevSection.ai[1] == Math.Round(prevSection.ai[1]))
                            {
                                NPC thisSection = getNPC((int)prevSection.ai[1]);
                                if (thisSection != null && thisSection.Equals(npc))
                                {
                                    applyPaintedToNPC(prevSection, data, handledNpcs);
                                }
                            }
                        }
                    }
                    goto case NPCID.EaterofWorldsTail;

                case NPCID.EaterofWorldsHead:
                case NPCID.DevourerHead:
                case NPCID.WyvernHead:
                case NPCID.GiantWormHead:
                case NPCID.DiggerHead:
                case NPCID.SeekerHead:                         //world feeder
                case NPCID.TombCrawlerHead:
                case NPCID.DuneSplicerHead:
                case NPCID.SolarCrawltipedeHead:
                case NPCID.BoneSerpentHead:
                    if (npc.ai[0] == Math.Round(npc.ai[0]))
                    {
                        NPC prevSection = getNPC((int)npc.ai[0]);
                        if (prevSection != null && !handledNpcs.Contains(prevSection))
                        {
                            if (prevSection.ai[1] == Math.Round(prevSection.ai[1]))
                            {
                                NPC thisSection = getNPC((int)prevSection.ai[1]);
                                if (thisSection != null && thisSection.Equals(npc))
                                {
                                    applyPaintedToNPC(prevSection, data, handledNpcs);
                                }
                            }
                        }
                    }
                    break;

                case NPCID.EaterofWorldsTail:
                case NPCID.DevourerTail:
                case NPCID.WyvernTail:
                case NPCID.GiantWormTail:
                case NPCID.DiggerTail:
                case NPCID.SeekerTail:                         //world feeder
                case NPCID.TombCrawlerTail:
                case NPCID.DuneSplicerTail:
                case NPCID.SolarCrawltipedeTail:
                case NPCID.BoneSerpentTail:
                    if (npc.ai[1] == Math.Round(npc.ai[1]))
                    {
                        NPC nextSection = getNPC((int)npc.ai[1]);
                        if (nextSection != null && !handledNpcs.Contains(nextSection))
                        {
                            if (nextSection.ai[0] == Math.Round(nextSection.ai[0]))
                            {
                                NPC thisSection = getNPC((int)nextSection.ai[0]);
                                if (thisSection != null && thisSection.Equals(npc))
                                {
                                    applyPaintedToNPC(nextSection, data, handledNpcs);
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }