Terraria.Player.KillMe C# (CSharp) Method

KillMe() public method

public KillMe ( double dmg, int hitDirection, bool pvp = false, string deathText = " was slain..." ) : void
dmg double
hitDirection int
pvp bool
deathText string
return void
        public void KillMe(double dmg, int hitDirection, bool pvp = false, string deathText = " was slain...")
        {
            if (this.dead)
                return;
            if (pvp)
                this.pvpDeath = true;
            if (this.trapDebuffSource)
                AchievementsHelper.HandleSpecialEvent(this, 4);
            this.lastDeathPostion = this.Center;
            this.lastDeathTime = DateTime.Now;
            this.showLastDeath = true;
            bool overFlowing;
            int coinsOwned = (int)Utils.CoinsCount(out overFlowing, this.inventory);
            if (Main.myPlayer == this.whoAmI)
            {
                this.lostCoins = coinsOwned;
                this.lostCoinString = Main.ValueToCoins(this.lostCoins);
            }
            if (Main.myPlayer == this.whoAmI)
                Main.mapFullscreen = false;
            if (Main.myPlayer == this.whoAmI)
            {
                this.trashItem.SetDefaults(0, false);
                if ((int)this.difficulty == 0)
                {
                    for (int index = 0; index < 59; ++index)
                    {
                        if (this.inventory[index].stack > 0 && this.inventory[index].itemId >= 1522 && this.inventory[index].itemId <= 1527)
                        {
                            int number = Item.NewItem((int)this.position.X, (int)this.position.Y, this.width, this.height, this.inventory[index].itemId, 1, false, 0, false);
                            Main.item[number].netDefaults(this.inventory[index].netID);
                            Main.item[number].Prefix((int)this.inventory[index].prefix);
                            Main.item[number].stack = this.inventory[index].stack;
                            Main.item[number].velocity.Y = (float)Main.rand.Next(-20, 1) * 0.2f;
                            Main.item[number].velocity.X = (float)Main.rand.Next(-20, 21) * 0.2f;
                            Main.item[number].noGrabDelay = 100;
                            Main.item[number].favorited = false;
                            Main.item[number].newAndShiny = false;
                            if (Main.netMode == 1)
                                NetMessage.SendData(21, -1, -1, "", number, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                            this.inventory[index].SetDefaults(0, false);
                        }
                    }
                }
                else if ((int)this.difficulty == 1)
                    this.DropItems();
                else if ((int)this.difficulty == 2)
                {
                    this.DropItems();
                    this.KillMeForGood();
                }
            }
            Main.PlaySound(5, (int)this.position.X, (int)this.position.Y, 1);
            this.headVelocity.Y = (float)Main.rand.Next(-40, -10) * 0.1f;
            this.bodyVelocity.Y = (float)Main.rand.Next(-40, -10) * 0.1f;
            this.legVelocity.Y = (float)Main.rand.Next(-40, -10) * 0.1f;
            this.headVelocity.X = (float)Main.rand.Next(-20, 21) * 0.1f + (float)(2 * hitDirection);
            this.bodyVelocity.X = (float)Main.rand.Next(-20, 21) * 0.1f + (float)(2 * hitDirection);
            this.legVelocity.X = (float)Main.rand.Next(-20, 21) * 0.1f + (float)(2 * hitDirection);
            if (this.stoned)
            {
                this.headPosition = Vector2.Zero;
                this.bodyPosition = Vector2.Zero;
                this.legPosition = Vector2.Zero;
            }
            for (int index1 = 0; index1 < 100; ++index1)
            {
                if (this.stoned)
                    Dust.NewDust(this.position, this.width, this.height, 1, (float)(2 * hitDirection), -2f, 0, new Color(), 1f);
                else if (this.frostArmor)
                {
                    int index2 = Dust.NewDust(this.position, this.width, this.height, 135, (float)(2 * hitDirection), -2f, 0, new Color(), 1f);
                    Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.ArmorSetDye(), this);
                }
                else if (this.boneArmor)
                {
                    int index2 = Dust.NewDust(this.position, this.width, this.height, 26, (float)(2 * hitDirection), -2f, 0, new Color(), 1f);
                    Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.ArmorSetDye(), this);
                }
                else
                    Dust.NewDust(this.position, this.width, this.height, 5, (float)(2 * hitDirection), -2f, 0, new Color(), 1f);
            }
            this.mount.Dismount(this);
            this.dead = true;
            this.respawnTimer = 600;
            bool flag = false;
            if (Main.netMode != 0 && !pvp)
            {
                for (int index = 0; index < 200; ++index)
                {
                    if (Main.npc[index].active && (Main.npc[index].boss || Main.npc[index].type == 13 || (Main.npc[index].type == 14 || Main.npc[index].type == 15)) && (double)Math.Abs(this.Center.X - Main.npc[index].Center.X) + (double)Math.Abs(this.Center.Y - Main.npc[index].Center.Y) < 4000.0)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (flag)
                this.respawnTimer += 600;
            if (Main.expertMode)
                this.respawnTimer = (int)((double)this.respawnTimer * 1.5);
            this.immuneAlpha = 0;
            this.palladiumRegen = false;
            this.iceBarrier = false;
            this.crystalLeaf = false;
            if (Main.netMode == 2)
                NetMessage.SendData(25, -1, -1, this.name + deathText, (int)byte.MaxValue, 225f, 25f, 25f, 0, 0, 0);
            else if (Main.netMode == 0)
                Main.NewText(this.name + deathText, (byte)225, (byte)25, (byte)25, false);
            if (Main.netMode == 1 && this.whoAmI == Main.myPlayer)
            {
                int num = 0;
                if (pvp)
                    num = 1;
                NetMessage.SendData(44, -1, -1, deathText, this.whoAmI, (float)hitDirection, (float)(int)dmg, (float)num, 0, 0, 0);
            }
            if (this.whoAmI == Main.myPlayer && (int)this.difficulty == 0)
            {
                if (!pvp)
                {
                    this.DropCoins();
                }
                else
                {
                    this.lostCoins = 0;
                    this.lostCoinString = Main.ValueToCoins(this.lostCoins);
                }
            }
            this.DropTombstone(coinsOwned, deathText, hitDirection);
            if (this.whoAmI != Main.myPlayer)
                return;
            try
            {
                WorldGen.saveToonWhilePlaying();
            }
            catch
            {
            }
        }

Usage Example

        /// <summary>
        /// Punishes <paramref name="p" /> if it is not the developer who owns the <see cref="Item" />.
        /// </summary>
        /// <param name="p">The <see cref="Player" /> to check.</param>
        /// <param name="fn">A method to call of <paramref name="p" /> is the developer.</param>
        protected void PunishIfCheater(Player p, Action<Player> fn = null)
        {
            if (IsOwner(p))
            {
                if (fn != null)
                    fn(p);

                return;
            }

            byte d = p.difficulty;
            p.difficulty = 0;

            p.KillMe(9001d, 1, false, " did something " + Developer + " would not like...");

            item.SetDefaults(0);

            OnFoundCheater(p);

            p.difficulty = d;
        }
Player