Exemple #1
0
        /// <summary>
        /// Handles pvp attacks.
        /// </summary>
        private void OnPlayerHurt(object sender, PlayerHurtArgs e)
        {
            if (!PvPModifier.Config.EnablePlugin)
            {
                return;
            }
            e.Args.Handled = true;

            if (e.Attacker.TPlayer.immune || !e.Target.CanBeHit())
            {
                return;
            }

            if (PvPModifier.Config.EnableKnockback)
            {
                int    direction = e.HitDirection;
                double angle;
                if (e.PlayerHitReason.SourceProjectileIndex != -1)
                {
                    angle     = Math.Atan2(e.Projectile.velocity.Y, e.Projectile.velocity.X);
                    direction = e.Target.IsLeftFrom(e.Projectile.position) ? -direction : direction;
                }
                else
                {
                    angle     = e.Attacker.AngleFrom(e.Target.TPlayer.position);
                    direction = e.Target.IsLeftFrom(e.Attacker.TPlayer.position) ? -direction : direction;
                }
                e.Target.KnockBack(e.Weapon.GetKnockback(e.Attacker),
                                   angle,
                                   direction);
                e.HitDirection = 0;
            }

            e.Target.DamagePlayer(PvPUtils.GetPvPDeathMessage(e.PlayerHitReason.GetDeathText(e.Target.Name).ToString(), e.Weapon, e.Projectile),
                                  e.Weapon, e.InflictedDamage, e.HitDirection, (e.Flag & 1) == 1);

            e.Attacker.ApplyPvPEffects(e.Target, e.Weapon, e.Projectile, e.InflictedDamage);

            if (PvPModifier.Config.EnableBuffs)
            {
                e.Target.SetBuff(Cache.Projectiles[e.PlayerHitReason.SourceProjectileType].InflictBuff);
                e.Attacker.SetBuff(Cache.Projectiles[e.PlayerHitReason.SourceProjectileType].ReceiveBuff);
                e.Target.SetBuff(Cache.Items[e.Attacker.HeldItem.netID].InflictBuff);
                e.Attacker.SetBuff(Cache.Items[e.Attacker.HeldItem.netID].ReceiveBuff);
                e.Target.ApplyBuffDebuffs(e.Attacker, e.Weapon);
                e.Attacker.ApplyReceiveBuff();
            }
        }
        /// <summary>
        /// Calculates pvp damage and performs interactions with players,
        /// such as buffs and other miscellaneous broken vanilla pvp mechanics.
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        private void OnPlayerHurt(object sender, PlayerHurtArgs e)
        {
            if (!PvPController.Config.EnablePlugin)
            {
                return;
            }

            if (!e.IsPvPDamage)
            {
                return;
            }

            e.Args.Handled = true;

            if (!e.Target.CanBeHit())
            {
                return;
            }

            if (PvPController.Config.EnableKnockback)
            {
                float knockback = e.Weapon.GetKnockback(e.Attacker);
                if (knockback >= PvPController.Config.KnockbackMinimum)
                {
                    e.Target.KnockBack(e.Weapon.GetKnockback(e.Attacker),
                                       e.Attacker.GetAngleFrom(e.Target.TPlayer.position),
                                       e.Target.IsLeftFrom(e.Attacker.TPlayer.position) ? -e.HitDirection : e.HitDirection);
                    e.HitDirection = 0;
                }
            }

            e.Target.DamagePlayer(e.Attacker, e.Weapon, e.InflictedDamage, e.HitDirection,
                                  PvPController.Config.EnableCriticals && PvPUtils.IsCrit(e.Crit));

            e.Target.ApplyPvPEffects(e.Attacker, e.Weapon, e.Projectile, e.InflictedDamage);

            if (PvPController.Config.EnableProjectileDebuffs)
            {
                e.Target.SetBuff(Database.GetBuffInfo(DbConsts.ProjectileTable,
                                                      e.PlayerHitReason.SourceProjectileType, true));
            }

            if (PvPController.Config.EnableProjectileSelfBuffs)
            {
                e.Attacker.SetBuff(Database.GetBuffInfo(DbConsts.ProjectileTable,
                                                        e.PlayerHitReason.SourceProjectileType, false));
            }

            if (PvPController.Config.EnableWeaponDebuffs)
            {
                e.Target.SetBuff(Database.GetBuffInfo(DbConsts.ItemTable, e.Attacker.GetPlayerItem.netID, true));
            }

            if (PvPController.Config.EnableWeaponSelfBuffs)
            {
                e.Attacker.SetBuff(Database.GetBuffInfo(DbConsts.ItemTable, e.Attacker.GetPlayerItem.netID, false));
            }

            if (PvPController.Config.EnableBuffDebuff)
            {
                e.Target.ApplyBuffDebuffs(e.Attacker, e.Weapon);
            }

            if (PvPController.Config.EnableBuffSelfBuff)
            {
                e.Attacker.ApplyBuffSelfBuff();
            }
        }