Esempio n. 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
            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;
                DataSender.SendPlayerDeath(TshockPlayer);

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

            DataSender.SendClientHealth(this, TPlayer.statLife);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates this players health, keeping it within the bounds of their max health
        /// </summary>
        /// <param name="health">The amount to set this players health to</param>
        public void SetActiveHealth(int health)
        {
            TPlayer.statLife = health;
            if (TPlayer.statLife > TPlayer.statLifeMax2)
            {
                TPlayer.statLife = TPlayer.statLifeMax2;
            }

            DataSender.SendClientHealth(this, TPlayer.statLife);
        }
Esempio n. 3
0
        /// <summary>
        /// Applies a player heal for the given amount, not going over the players max hp
        /// </summary>
        /// <param name="player">The player who is healing</param>
        /// <param name="healAmt">The amount they are healing for</param>
        public void Heal(int healAmt)
        {
            TPlayer.statLife += healAmt;
            if (TPlayer.statLife > TPlayer.statLifeMax2)
            {
                TPlayer.statLife = TPlayer.statLifeMax2;
            }

            DataSender.SendClientHealth(this, TPlayer.statLife);
        }