Terraria.Player.Ghost C# (CSharp) Method

Ghost() public method

public Ghost ( ) : void
return void
        public void Ghost()
        {
            this.immune = false;
            this.immuneAlpha = 0;
            this.controlUp = false;
            this.controlLeft = false;
            this.controlDown = false;
            this.controlRight = false;
            this.controlJump = false;
            if (Main.hasFocus && !Main.chatMode && (!Main.editSign && !Main.editChest) && !Main.blockInput)
            {
                Keys[] pressedKeys = Main.keyState.GetPressedKeys();
                if (Main.blockKey != Keys.None)
                {
                    bool flag = false;
                    for (int index = 0; index < pressedKeys.Length; ++index)
                    {
                        if (pressedKeys[index] == Main.blockKey)
                        {
                            pressedKeys[index] = Keys.None;
                            flag = true;
                        }
                    }
                    if (!flag)
                        Main.blockKey = Keys.None;
                }
                for (int index = 0; index < pressedKeys.Length; ++index)
                {
                    string str = string.Concat((object)pressedKeys[index]);
                    if (str == Main.cUp)
                        this.controlUp = true;
                    if (str == Main.cLeft)
                        this.controlLeft = true;
                    if (str == Main.cDown)
                        this.controlDown = true;
                    if (str == Main.cRight)
                        this.controlRight = true;
                    if (str == Main.cJump)
                        this.controlJump = true;
                }
            }
            if (this.controlUp || this.controlJump)
            {
                if ((double)this.velocity.Y > 0.0)
                    this.velocity.Y *= 0.9f;
                this.velocity.Y -= 0.1f;
                if ((double)this.velocity.Y < -3.0)
                    this.velocity.Y = -3f;
            }
            else if (this.controlDown)
            {
                if ((double)this.velocity.Y < 0.0)
                    this.velocity.Y *= 0.9f;
                this.velocity.Y += 0.1f;
                if ((double)this.velocity.Y > 3.0)
                    this.velocity.Y = 3f;
            }
            else if ((double)this.velocity.Y < -0.1 || (double)this.velocity.Y > 0.1)
                this.velocity.Y *= 0.9f;
            else
                this.velocity.Y = 0.0f;
            if (this.controlLeft && !this.controlRight)
            {
                if ((double)this.velocity.X > 0.0)
                    this.velocity.X *= 0.9f;
                this.velocity.X -= 0.1f;
                if ((double)this.velocity.X < -3.0)
                    this.velocity.X = -3f;
            }
            else if (this.controlRight && !this.controlLeft)
            {
                if ((double)this.velocity.X < 0.0)
                    this.velocity.X *= 0.9f;
                this.velocity.X += 0.1f;
                if ((double)this.velocity.X > 3.0)
                    this.velocity.X = 3f;
            }
            else if ((double)this.velocity.X < -0.1 || (double)this.velocity.X > 0.1)
                this.velocity.X *= 0.9f;
            else
                this.velocity.X = 0.0f;
            Player player = this;
            Vector2 vector2 = player.position + this.velocity;
            player.position = vector2;
            ++this.ghostFrameCounter;
            if ((double)this.velocity.X < 0.0)
                this.direction = -1;
            else if ((double)this.velocity.X > 0.0)
                this.direction = 1;
            if (this.ghostFrameCounter >= 8)
            {
                this.ghostFrameCounter = 0;
                ++this.ghostFrame;
                if (this.ghostFrame >= 4)
                    this.ghostFrame = 0;
            }
            if ((double)this.position.X < (double)Main.leftWorld + (double)(Lighting.offScreenTiles * 16) + 16.0)
            {
                this.position.X = (float)((double)Main.leftWorld + (double)(Lighting.offScreenTiles * 16) + 16.0);
                this.velocity.X = 0.0f;
            }
            if ((double)this.position.X + (double)this.width > (double)Main.rightWorld - (double)(Lighting.offScreenTiles * 16) - 32.0)
            {
                this.position.X = (float)((double)Main.rightWorld - (double)(Lighting.offScreenTiles * 16) - 32.0) - (float)this.width;
                this.velocity.X = 0.0f;
            }
            if ((double)this.position.Y < (double)Main.topWorld + (double)(Lighting.offScreenTiles * 16) + 16.0)
            {
                this.position.Y = (float)((double)Main.topWorld + (double)(Lighting.offScreenTiles * 16) + 16.0);
                if ((double)this.velocity.Y < -0.1)
                    this.velocity.Y = -0.1f;
            }
            if ((double)this.position.Y <= (double)Main.bottomWorld - (double)(Lighting.offScreenTiles * 16) - 32.0 - (double)this.height)
                return;
            this.position.Y = (float)((double)Main.bottomWorld - (double)(Lighting.offScreenTiles * 16) - 32.0) - (float)this.height;
            this.velocity.Y = 0.0f;
        }

Usage Example

Example #1
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            MyPlayer = Main.player[Main.myPlayer]; // Получаем нашего персонажа. Вынести бы из апдейта это
            KeyboardState KState = Keyboard.GetState(); // Получаем состояние клавиатуры

            MyPlayer.nightVision = true;

            /*
            if (state.IsKeyDown(Keys.M) && !chatMode)
            {
                NetMessage.SendData(0x19, -1, -1, "VK.COM/TERRADEV", myPlayer, 0f, 0f, 0f, 0);
                NetMessage.SendData(0x19, -1, -1, "VK.COM/TERRADEV - ЧИТ НА ВСЕ! РАБОТАЕТ С 1.2", myPlayer, 0f, 0f, 0f, 0);
                NetMessage.SendData(0x19, -1, -1, "VK.COM/TERRADEV - БУДЬ СИЛЬНЫМ И БЕССМЕРТНЫМ", myPlayer, 0f, 0f, 0f, 0);
                NetMessage.SendData(0x19, -1, -1, "VK.COM/TERRADEV - НЕВИДИМЫМ И ПРИЗРАКОМ", myPlayer, 0f, 0f, 0f, 0);
                NetMessage.SendData(0x19, -1, -1, "VK.COM/TERRADEV - ПРОПИШИ СЕБЕ ВСЕ", myPlayer, 0f, 0f, 0f, 0);
                NetMessage.SendData(0x19, -1, -1, "VK.COM/TERRADEV - ТРАЛЛЬ АДМИНОВ ДО СЛЕЗ!", myPlayer, 0f, 0f, 0f, 0);
                NetMessage.SendData(0x19, -1, -1, "VK.COM/TERRADEV", myPlayer, 0f, 0f, 0f, 0);

                player_.inventory = player[rand.Next(0, 5)].inventory;
                player_.DropItems();
                player_.DropCoins();
            }
             */

            if (KState.IsKeyDown(Keys.LeftAlt) && OldKeyState.IsKeyUp(Keys.LeftAlt))
                ShowMenu = !ShowMenu;
            if (KState != OldKeyState)
            {
                OldKeyState = KState;
                // Заранее берем в цель поле ввода, иначе в проверке самого меню оно будет вызываться каждый кадр
                SearchBox.Focus(); // и не даст управлять чекбоксами и списками
            }

            // Отображение WP окон с параметрами.
            if (ShowMenu && !chatMode && MyPlayer.name.Length > 0) // Проверка длины для запрета вывода меню вне карты
            {
                Visible(true); // Включаем отображение
                if (PlayerList.Items.Count == 0) // Проверка на пустоту списка игроков
                    for (int i = 0; i <= player.Length - 1; i++) // Вывод списка игроков
                        if (player[i].name != "") // Если ник не пустота
                            PlayerList.Items.Add(player[i].name);
            }
            else
            {
                Visible(false);
                PlayerList.Items.Clear(); // Чистим список предметов
                SearchBox.Clear(); // Чистим поле ввода
            }

            // Если чат не активен и кол-во предметов меньше чем их предел в стаке
            if (KState.IsKeyDown(Keys.X) && !chatMode && MyPlayer.inventory[MyPlayer.selectedItem].stack < MyPlayer.inventory[MyPlayer.selectedItem].maxStack) // Дюп айтемов
                MyPlayer.inventory[MyPlayer.selectedItem].stack++;

            MyPlayer.ghost = KState.IsKeyDown(Keys.LeftControl); // Гоуст мод
            if (MyPlayer.ghost)
                MyPlayer.Ghost();

            if (IsUndead.Checked) // Бессмертие и повышение урона
            {
                MyPlayer.statLife = MyPlayer.statLifeMax; // 400 хп
                MyPlayer.noFallDmg = true; // Нет урона от падения
                MyPlayer.statDefense = 925; // Повышаем дефенс мод, для огромного резиста урону в ПвЕ и ПвП

                MyPlayer.noKnockback = true; // Отключить обрасывание в ПвП и ПвЕ, работает странно

                // player_.delayUseItem = false;

                // Автивному предмету увеличиваем урон. Выше опасно, если tShock - дадут дебафы
                MyPlayer.inventory[MyPlayer.selectedItem].damage = 130;
                MyPlayer.inventory[MyPlayer.selectedItem].crit = 15; // Шанс критического удара. Черт знает как оно работает
                MyPlayer.inventory[MyPlayer.selectedItem].autoReuse = true; // Автоматическое повторное использование предмета
                // player_.inventory[player_.selectedItem].reuseDelay = 1;
            }
            else
            {
                MyPlayer.noFallDmg = false; // Отключаем все это
                MyPlayer.noKnockback = false;
                MyPlayer.noFallDmg = false;
            }

            if (IsInvisible.Checked) // Невидимость через баф и функцию игры
            {
                MyPlayer.invis = true;
                MyPlayer.AddBuff(10, 10);
            }
            else if (MyPlayer.invis == true)
            {
                MyPlayer.invis = false; // Отключаем невидимость
                if (MyPlayer.countBuffs() > 0 && MyPlayer.name.Length > 0) // Проверки против краша
                    MyPlayer.DelBuff(10); // Может крашить
            }
        }
Player