Exemple #1
0
        /// <summary>
        /// Applies an amount of damage to this player, updating their client and the server version of their health
        /// </summary>
        /// <param name="killer"></param>
        /// <param name="victim"></param>
        /// <param name="killersWeapon"></param>
        /// <param name="dir"></param>
        /// <param name="damage"></param>
        /// <param name="realDamage"></param>
        public void ApplyPlayerDamage(PlayerKiller killer, Item killersWeapon, int dir, int damage, int realDamage)
        {
            // Send the damage using the special method to avoid invincibility frames issue
            Controller.DataSender.SendPlayerDamage(TshockPlayer, dir, damage);
            Controller.RaisePlayerDamageEvent(this, new PlayerDamageEventArgs(killer.Player, TshockPlayer, killersWeapon, realDamage));
            TPlayer.statLife -= realDamage;

            // Hurt the player to prevent instant regen activating
            var savedHealth = TPlayer.statLife;

            TPlayer.Hurt(new PlayerDeathReason(), damage, 0, true, false, false, 3);
            TPlayer.statLife = savedHealth;

            if (TPlayer.statLife <= 0)
            {
                TshockPlayer.Dead = true;
                IsDead            = true;
                Controller.DataSender.SendPlayerDeath(TshockPlayer);

                if (TPlayer.hostile && killer != null)
                {
                    PlayerKillEventArgs killArgs = new PlayerKillEventArgs(killer.Player, TshockPlayer, killer.Weapon);
                    Controller.RaisePlayerKillEvent(this, killArgs);
                }
                return;
            }

            Controller.DataSender.SendClientHealth(this, TPlayer.statLife);
        }
Exemple #2
0
 /// <summary>
 /// Raises a player kill event if there are any listeners
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 internal void RaisePlayerKillEvent(object sender, PlayerKillEventArgs args)
 {
     OnPlayerKill?.Invoke(sender, args);
 }