Example #1
0
        public override bool?CanHitNPC(Player player, NPC target)
        {
            if (recursionnt)
            {
                return(null);
            }
            if (!item.Hitbox.Intersects(target.Hitbox))
            {
                return(false);
            }
            recursionnt = true;
            bool cantBeHit = !target.CanBeHitBy(player, item, false);

            recursionnt = false;
            if (cantBeHit)
            {
                return(false);
            }

            int totalDamage = player.GetWeaponDamage(item);

            int critChance = player.rangedCrit;

            ItemLoader.GetWeaponCrit(item, player, ref critChance);
            PlayerHooks.GetWeaponCrit(player, item, ref critChance);
            bool crit = (critChance >= 100 || Main.rand.Next(1, 101) <= critChance);

            float knockBack = item.knockBack;

            ItemLoader.GetWeaponKnockback(item, player, ref knockBack);
            PlayerHooks.GetWeaponKnockback(player, item, ref knockBack);

            int bannerID = Item.NPCtoBanner(target.BannerID());

            if (bannerID >= 0 && player.NPCBannerBuff[bannerID])
            {
                totalDamage = ((!Main.expertMode) ? ((int)(totalDamage * ItemID.Sets.BannerStrength[Item.BannerToItem(bannerID)].NormalDamageDealt)) : ((int)(totalDamage * ItemID.Sets.BannerStrength[Item.BannerToItem(bannerID)].ExpertDamageDealt)));
            }

            int damage = Main.DamageVar(totalDamage);

            NPCLoader.ModifyHitByItem(target, player, item, ref damage, ref knockBack, ref crit);
            PlayerHooks.ModifyHitNPC(player, item, target, ref damage, ref knockBack, ref crit);
            player.OnHit(target.Center.X, target.Center.Y, target);
            if (player.armorPenetration > 0)
            {
                damage += target.checkArmorPenetration(player.armorPenetration);
            }

            Vector2 oldVel         = target.velocity;
            int     dmgDealt       = (int)target.StrikeNPC(damage, knockBack, player.direction, crit);
            Vector2 diff           = target.velocity - oldVel;
            float   totalKnockBack = diff.Length();

            diff = new Vector2(totalKnockBack * 0.6f * player.direction, totalKnockBack * -0.2f);
            if (totalKnockBack > 0 && diff.X > 0 == player.direction > 0)
            {
                float rot  = 0f;
                float mult = 1f;
                target.GetGlobalNPC <EpikGlobalNPC>().SetBounceTime(60);
                //Main.NewText(frame);
                switch (frame)
                {
                case 4:
                    rot  = target.collideY?-0.75f:1;
                    mult = 1.75f;
                    //target.GetGlobalNPC<EpikGlobalNPC>().OldCollideY = false;
                    break;

                case 2:
                    rot  = -0.7f;
                    mult = 1.5f;
                    break;
                }
                if (rot != 0)
                {
                    diff = diff.RotatedBy(rot * player.direction);
                }
                target.velocity = oldVel + (diff * mult);
            }

            if (bannerID >= 0)
            {
                player.lastCreatureHit = bannerID;
            }
            if (player.beetleOffense && !target.immortal)
            {
                player.beetleCounter  += dmgDealt;
                player.beetleCountdown = 0;
            }

            target.immune[player.whoAmI] = player.itemAnimation;

            ItemLoader.OnHitNPC(item, player, target, dmgDealt, knockBack, crit);
            NPCLoader.OnHitByItem(target, player, item, dmgDealt, knockBack, crit);
            PlayerHooks.OnHitNPC(player, item, target, dmgDealt, knockBack, crit);

            if (Main.netMode != NetmodeID.SinglePlayer)
            {
                if (crit)
                {
                    NetMessage.SendData(MessageID.StrikeNPC, -1, -1, null, target.whoAmI, damage, knockBack, player.direction, 1);
                }
                else
                {
                    NetMessage.SendData(MessageID.StrikeNPC, -1, -1, null, target.whoAmI, damage, knockBack, player.direction);
                }
            }

            if (player.accDreamCatcher)
            {
                player.addDPS(damage);
            }
            //target.immune[player.whoAmI] = player.itemAnimation;
            return(false);
        }