////

        private bool CustomLoad(int npcType, int bossHeadIndex, string bossNpcUid, string displayName)
        {
            if (npcType == 0 || npcType == -1)                  // -1 for legacy support
            {
                return(false);
            }

            var npc = new NPC();

            npc.SetDefaults(npcType);

            if (NPCID.GetUniqueKey(npc) != bossNpcUid)
            {
                npcType = NPCID.TypeFromUniqueKey(bossNpcUid);
                if (npcType > 0)
                {
                    npc.SetDefaults(npcType);
                    return(this.CustomLoad(npcType, npc.GetBossHeadTextureIndex(), bossNpcUid, npc.GivenName));
                }

                this.mod.Logger.Info("Could not find boss head of custom boss mask for npc " + bossNpcUid);
                return(false);
            }

            this.BossNpcType     = npcType;
            this.BossHeadIndex   = bossHeadIndex;
            this.BossUid         = bossNpcUid;
            this.BossDisplayName = displayName;

            return(true);
        }
        ////////////////

        public bool SetBoss(int npcType)
        {
            NPC npc = new NPC();

            npc.SetDefaults(npcType);

            int idx = npc.GetBossHeadTextureIndex();

            if (idx < 0 || idx >= Main.npcHeadBossTexture.Length || Main.npcHeadBossTexture[idx] == null)
            {
                return(false);
            }

            if (this.CustomLoad(npcType, idx, NPCID.GetUniqueKey(npc), npc.GivenName))
            {
                this.item.SetNameOverride(npc.GivenName + " Mask");
            }


            /*if( Main.netMode != 2 ) {
             *      var tex = Main.npcHeadBossTexture[info.BossHeadIndex];
             *      //var old_tex = Main.armorHeadTexture[this.item.headSlot];
             *      if( tex == null ) { return; }
             *      //if( old_tex == null ) { return; }
             *
             *      Main.itemTexture[this.item.type] = tex;
             *
             *      try {
             *              var graDev = Main.graphics.GraphicsDevice;
             *              var newTex = new RenderTarget2D( graDev, oldTex.Width, oldTex.Height, false, graDev.PresentationParameters.BackBufferFormat, DepthFormat.Depth24 );
             *              var old_ren_tar = graDev.GetRenderTargets();
             *
             *              graDev.SetRenderTarget( newTex );
             *              graDev.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
             *
             *              graDev.Clear( Color.Transparent );
             *              var sb = new SpriteBatch( graDev );
             *              sb.Begin( SpriteSortMode.Deferred, BlendState.AlphaBlend );
             *              for( int i = 0; i <= 20; i++ ) {
             *                      var rect = new Rectangle( 0, 4 + (i * oldTex.Height), oldTex.Width, oldTex.Height / 20 );
             *                      sb.Draw( tex, rect, Color.White );
             *              }
             *              sb.End();
             *
             *              graDev.SetRenderTargets( old_ren_tar );
             *
             *              Main.armorHeadTexture[this.item.headSlot] = newTex;
             *      } catch( Exception e ) {
             *              ErrorLogger.Log( e.ToString() );
             *      }
             * }*/

            return(true);
        }
        ////

        public static void ModifyHitIf(NPC npc, ref int damage, ref float knockback)
        {
            var    mymod = EnragedMod.Instance;
            string uid   = NPCID.GetUniqueKey(npc.type);

            if (mymod.EnragedNpcHooks.ContainsKey(uid))
            {
                (bool _, bool isDamageResist)? behavior = mymod.EnragedNpcHooks[uid].Invoke(npc.whoAmI);
                if (behavior.HasValue && !behavior.Value.isDamageResist)
                {
                    return;
                }
            }

            //

            damage    = Math.Max((damage / 2) - 10, 1);
            knockback = 0;
        }
        public static void ApplyExternalEffectsIf(NPC npc)
        {
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                return;
            }

            //

            var    mymod = EnragedMod.Instance;
            string uid   = NPCID.GetUniqueKey(npc.type);

            if (mymod.EnragedNpcHooks.ContainsKey(uid))
            {
                (bool isBramble, bool _)? behavior = mymod.EnragedNpcHooks[uid].Invoke(npc.whoAmI);
                if (behavior.HasValue && !behavior.Value.isBramble)
                {
                    return;
                }
            }

            //

            var   config    = EnragedConfig.Instance;
            int   thickness = config.Get <int>(nameof(EnragedConfig.EnragedBrambleTrailThickness));
            float density   = config.Get <float>(nameof(EnragedConfig.EnragedBrambleTrailDensity));

            if (thickness > 0 && density > 0f)
            {
                int created = CursedBrambleTile.CreateBramblePatchAt(
                    tileX: (int)npc.Center.X / 16,
                    tileY: (int)npc.Center.Y / 16,
                    radius: thickness,
                    densityPercent: density,
                    sync: true
                    );
            }
        }
Example #5
0
        public IconData(Type type, int id)
        {
            this.type = type;
            this.id   = id;

            switch (type)
            {
            case Type.Item:
                uniqueKey = ItemID.GetUniqueKey(id);
                animation = Main.itemAnimations[id] as DrawAnimationVertical ?? new DrawAnimationVertical(0, 1);
                break;

            case Type.NPC:
                uniqueKey = NPCID.GetUniqueKey(id);
                animation = new DrawAnimationVertical(5, Main.npcFrameCount[id]);
                break;

            case Type.Projectile:
                uniqueKey = ProjectileID.GetUniqueKey(id);
                animation = new DrawAnimationVertical(5, Main.projFrames[id]);
                break;
            }
        }
Example #6
0
 public NPCDefinition(int type) : base(NPCID.GetUniqueKey(type))
 {
 }
Example #7
0
        public override void NPCLoot(NPC npc)
        {
            if (npc == null)
            {
                return;
            }

            var mymod = (TheLunaticMod)this.mod;

            if (!mymod.Config.Enabled)
            {
                return;
            }

            if (!npc.boss && npc.type != 551 && npc.type != 398)
            {
                return;
            }                                                                                   // Betsy isn't a boss?
            var myworld = ModContent.GetInstance <TheLunaticWorld>();

            if (!myworld.GameLogic.HaveWeHopeToWin())
            {
                return;
            }

            Item item     = null;
            int  maskType = MaskLogic.GetMaskTypeOfNpc(npc.type);

            if (maskType == -1)
            {
                return;
            }

            // Already given this mask?
            bool isVanilla = MaskLogic.AllVanillaMasks.Contains(maskType);

            if (!myworld.MaskLogic.GivenVanillaMasksByType.Contains(maskType))
            {
                if (!isVanilla && myworld.MaskLogic.GivenCustomMasksByBossUid.Contains(NPCID.GetUniqueKey(npc)))
                {
                    return;
                }
            }

            // No modded masks allowed?
            if (!isVanilla && mymod.Config.OnlyVanillaBossesDropMasks)
            {
                return;
            }

            int which = ItemHelpers.CreateItem(npc.position, maskType, 1, 15, 15);

            item = Main.item[which];

            if (item != null && !item.IsAir)
            {
                if (maskType == ModContent.ItemType <CustomBossMaskItem>())
                {
                    var moditem = (CustomBossMaskItem)item.modItem;
                    if (!moditem.SetBoss(npc.type))
                    {
                        ItemHelpers.DestroyWorldItem(which);
                    }
                }
                else
                {
                    /*if( !modworld.MaskLogic.GivenVanillaMasks.Contains( mask_type ) ) {
                     *      // Does this mask already exist in the world?
                     *      for( int i = 0; i < Main.item.Length; i++ ) {
                     *              if( Main.item[i] != null && Main.item[i].active && Main.item[i].type == mask_type ) {
                     *                      item = Main.item[i];
                     *                      break;
                     *              }
                     *      }
                     * }*/
                }
            }
            else
            {
                LogHelpers.Log("Could not spawn a mask of type " + maskType);
            }
        }
Example #8
0
 public static EnrangedBehaviorHook GetEnragedNpcBehaviorHook(int npcType)
 {
     EnragedMod.Instance.EnragedNpcHooks.TryGetValue(NPCID.GetUniqueKey(npcType), out EnrangedBehaviorHook callback);
     return(callback);
 }
Example #9
0
 public static void SetEnragedNpcBehaviorHook(int npcType, EnrangedBehaviorHook callback)
 {
     EnragedMod.Instance.EnragedNpcHooks[NPCID.GetUniqueKey(npcType)] = callback;
 }
Example #10
0
        ////////////////

        public void RegisterReceiptOfMask(Player givingPlayer, int maskType, int bossNpcType)
        {
            var mymod = TheLunaticMod.Instance;

            if (maskType == ModContent.ItemType <CustomBossMaskItem>() && bossNpcType != 0 && bossNpcType != -1)                // -1 for legacy support
            {
                NPC npc = new NPC();
                npc.SetDefaults(bossNpcType);

                this.GivenCustomMasksByBossUid.Add(NPCID.GetUniqueKey(npc));
            }
            else
            {
                this.GivenVanillaMasksByType.Add(maskType);
            }

            if (mymod.Config.DebugModeInfo)
            {
                LogHelpers.Log("DEBUG Registering mask. " + givingPlayer.name + ", " + maskType);
            }

            // Buy time before the end comes
            if (this.GivenVanillaMasksByType.Count < (MaskLogic.AvailableMaskCount))
            {
                var modworld  = ModContent.GetInstance <TheLunaticWorld>();
                int recovered = mymod.Config.HalfDaysRecoveredPerMask;

                switch (maskType)
                {
                case ItemID.FleshMask:
                    recovered = (int)((float)recovered * mymod.Config.WallOfFleshMultiplier);
                    break;

                case ItemID.DestroyerMask:
                case ItemID.TwinMask:
                case ItemID.SkeletronPrimeMask:
                case ItemID.PlanteraMask:
                case ItemID.GolemMask:
                case ItemID.DukeFishronMask:
                case ItemID.BossMaskBetsy:
                case ItemID.BossMaskCultist:
                case ItemID.BossMaskMoonlord:
                    if (maskType == ItemID.BossMaskMoonlord && mymod.Config.MoonLordMaskWins)
                    {
                        this.GiveAllVanillaMasks();
                    }
                    recovered = (int)((float)recovered * mymod.Config.HardModeMultiplier);
                    break;
                }

                if (WorldStateHelpers.GetDayOrNightPercentDone() > 0.5f)
                {
                    recovered += 1;
                }

                modworld.GameLogic.SetTime(modworld.GameLogic.HalfDaysElapsed - recovered);
            }

            // Sky flash for all
            if (!Main.dedServ && Main.netMode != 2)                 // Not server
            {
                Player currentPlayer = Main.player[Main.myPlayer];
                var    modplayer     = currentPlayer.GetModPlayer <TheLunaticPlayer>();
                modplayer.FlashMe();
            }
        }
Example #11
0
        public override void SetDefaults(NPC npc)
        {
            if (npc.townNPC && npc.type < NPCID.Count && npc.type != NPCID.OldMan)
            {
                Main.npcCatchable[npc.type] = true;
                npc.catchItem = npc.type == NPCID.DD2Bartender ? (short)mod.ItemType("Tavernkeep") : (short)mod.ItemType(NPCID.GetUniqueKey(npc.type).Replace("Terraria ", string.Empty));
            }

            if (npc.type == NPCID.SkeletonMerchant)
            {
                Main.npcCatchable[npc.type] = true;
                npc.catchItem = (short)mod.ItemType("SkeletonMerchant");
            }
        }