Пример #1
0
 private static void ProcessRequestTeleport(ref BinaryReader reader, int playerNumber)
 {
     if (Network.Players[playerNumber].Group.HasPermission("Teleport"))
     {
         Vector2 destination = reader.ReadVector2();
         Main.player[playerNumber].Teleport(destination, 1, 0);
         RemoteClient.CheckSection(playerNumber, destination, 1);
         NetMessage.SendData(65, -1, -1, null, 0, playerNumber, destination.X, destination.Y, 1, 0, 0);
         //int num169 = -1;
         //float num170 = 9999f;
         //for (int num171 = 0; num171 < 255; num171++)
         //{
         //	if (Main.player[num171].active && num171 != this.whoAmI)
         //	{
         //		Vector2 vector2 = Main.player[num171].position - Main.player[this.whoAmI].position;
         //		if (vector2.Length() < num170)
         //		{
         //			num170 = vector2.Length();
         //			num169 = num171;
         //		}
         //	}
         //}
         //if (num169 >= 0)
         //{
         //	NetMessage.SendData(25, -1, -1, Main.player[this.whoAmI].name + " has teleported to " + Main.player[num169].name, 255, 250f, 250f, 0f, 0, 0, 0);
         //}
     }
 }
Пример #2
0
        public override ActionResponse Handle()
        {
            var player = Player;
            var others = Utils.GetTargets(player, _other);

            if (others.Length > 0)
            {
                others = others.Where(player1 => player1.whoAmI != player.whoAmI).ToArray();
                if (others.Length > 0)
                {
                    var other = others[Main.rand.Next(others.Length)];

                    MyModServer.Log.Debug($"Switching location of {player.name} and {other.name}");
                    var pos1 = player.position;
                    var pos2 = other.position;

                    player.Teleport(pos2, _style);
                    RemoteClient.CheckSection(player.whoAmI, pos2);
                    NetMessage.TrySendData(65, -1, -1, null, 0, player.whoAmI, pos2.X, pos2.Y, _style);

                    other.Teleport(pos1);
                    RemoteClient.CheckSection(other.whoAmI, pos1);
                    NetMessage.TrySendData(65, -1, -1, null, 0, other.whoAmI, pos1.X, pos1.Y, _style);

                    return(ActionResponse.Done);
                }
            }

            MyModServer.Log.Debug("Retrying switch location");
            TryLater(TimeSpan.FromSeconds(20));
            return(ActionResponse.Retry);
        }
        /// <summary>
        /// Teleports a player to a given position.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="pos"></param>
        /// <param name="style">"Style" of teleportation (visual, sound, etc.).</param>
        public static void Teleport(Player player, Vector2 pos, int style = -1)
        {
            player.grappling[0] = -1;
            player.grapCount    = 0;

            bool isImmune   = player.immune;
            int  immuneTime = player.immuneTime;

            player.Spawn();
            player.immune     = isImmune;
            player.immuneTime = immuneTime;

            if (Main.netMode <= 1)
            {
                player.Teleport(pos, style);
            }
            else
            {
                if (Main.netMode == 2)
                {
                    RemoteClient.CheckSection(player.whoAmI, pos);
                }

                style = style == -1 ? 1 : style;
                NetMessage.SendData(MessageID.Teleport, -1, -1, null, 0, (float)player.whoAmI, pos.X, pos.Y, style, 0, 0);
            }
        }
Пример #4
0
        //public static void SendTextToPlayer(string msg, int playerIndex, Color color = new Color())
        //{
        //	NetMessage.SendData(25, playerIndex, -1, msg, 255, color.R, color.G, color.B, 0);
        //}

        //public static void SendTextToAllPlayers(string msg, Color color = new Color())
        //{
        //	NetMessage.SendData(25, -1, -1, msg, 255, color.R, color.G, color.B, 0);
        //}

        //public override void ChatInput(string text)
        //{
        //	worldInstance.ChatInput(text);
        //}

        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            MessageType msgType = (MessageType)reader.ReadByte();

            //	DebugText($"Ded: {Main.dedServ} whoAmI:{whoAmI} Main.myPlayer{Main.myPlayer} msgType: {msgType}");
            switch (msgType)
            {
            case MessageType.RequestSwapTeleport:
                int     x           = reader.ReadInt32();
                int     y           = reader.ReadInt32();
                Vector2 destination = new Vector2(x * 16, y * 16);
                Main.player[whoAmI].Teleport(destination, 1, 0);
                RemoteClient.CheckSection(whoAmI, destination, 1);
                NetMessage.SendData(65, -1, -1, null, 0, whoAmI, destination.X, destination.Y, 1, 0, 0);
                break;

            //case MessageType.DimensionsData: // Server has sent Dimension data
            //	worldInstance.ReceiveDimensionData(reader);
            //	break;
            //case MessageType.RequestDimensionData: // Client wants data
            //	world.PlayerJoined(whoAmI);
            //	break;
            default:
                DebugText("Unknown Message type: " + msgType);
                break;
            }
            //DebugText($"Complete " + msgType);
        }
Пример #5
0
        public override bool UseItem(Player player)
        {
            bool canSpawn = false;
            bool tele     = false;

            while (tele == false)
            {
                int     teleportStartX = (int)(Main.player[Main.myPlayer].position.X / 16) - 75;
                int     teleportRangeX = 150;
                int     teleportStartY = (int)(Main.player[Main.myPlayer].position.Y / 16) - 75;
                int     teleportRangeY = 150;
                Vector2 vector2        = this.TestTeleport(ref canSpawn, teleportStartX, teleportRangeX, teleportStartY, teleportRangeY);
                if (canSpawn)
                {
                    Vector2 newPos = vector2;
                    Main.player[Main.myPlayer].Teleport(newPos, 2, 0);
                    Main.player[Main.myPlayer].velocity = Vector2.Zero;
                    if (Main.netMode == 2)
                    {
                        RemoteClient.CheckSection(Main.myPlayer, Main.player[Main.myPlayer].position, 1);
                        NetMessage.SendData(65, -1, -1, null, 0, (float)Main.myPlayer, newPos.X, newPos.Y, 3, 0, 0);
                    }
                    tele = true;
                }
            }
            return(true);
        }
Пример #6
0
        //public void RequestTeleport(int toWho, int fromWho, Vector2 mapPosition)
        //{
        //    ModPacket packet = GetPacket(REQUEST_TELEPORT_MESSAGE, fromWho);
        //    packet.WriteVector2(mapPosition);
        //    packet.Send();
        //}

        public void ProcessRequestTeleport(BinaryReader reader, int fromWho)
        {
            Vector2 destination = reader.ReadVector2();

            Main.player[fromWho].Teleport(destination, 1, 0);
            RemoteClient.CheckSection(fromWho, destination, 1);
            NetMessage.SendData(65, -1, -1, null, 0, fromWho, destination.X, destination.Y, 1, 0, 0);
        }
Пример #7
0
 public static void SyncPortalSections(Vector2 portalPosition, int fluff)
 {
     for (int playerIndex = 0; playerIndex < (int) byte.MaxValue; ++playerIndex)
       {
     if (Main.player[playerIndex].active)
       RemoteClient.CheckSection(playerIndex, portalPosition, fluff);
       }
 }
Пример #8
0
 /// <summary>
 /// for world section fix
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="whoAmI"></param>
 public override void HandlePacket(BinaryReader reader, int whoAmI)
 {
     switch (reader.ReadByte())
     {
     case 0:
         RemoteClient.CheckSection(whoAmI, reader.ReadVector2());
         break;
     }
 }
Пример #9
0
 public static void SyncPortalSections(Vector2 portalPosition, int fluff)
 {
     for (int i = 0; i < 255; i++)
     {
         if (Main.player[i].active)
         {
             RemoteClient.CheckSection(i, portalPosition, fluff);
         }
     }
 }
Пример #10
0
        ////////////////

        public override void ReceiveOnServer(int fromWho)
        {
            var wldPos = new Vector2(
                this.TileSectionX * 200 * 16,
                this.TileSectionY * 150 * 16
                );

            RemoteClient.CheckSection(fromWho, wldPos, 1);
            //NetMessage.SendSection( fromWho, this.TileSectionX, this.TileSectionY );
        }
Пример #11
0
        private static void TeleportSulphurousShell(Player player)
        {
            Vector2 specialPos = Vector2.Zero;
            int     abyssSide  = -CalamityWorld.abyssSide.ToDirectionInt();
            int     startX     = CalamityWorld.abyssSide
                ? 200
                : Main.maxTilesX - 200;
            bool specialTeleport = true;

            if (!RequestSulphurousTeleportPosition(player, -abyssSide, startX, out Point landingPoint))
            {
                specialTeleport = false;
                startX          = !CalamityWorld.abyssSide ? 50 : Main.maxTilesX - 50;

                if (RequestSulphurousTeleportPosition(player, abyssSide, startX, out landingPoint))
                {
                    specialTeleport = true;
                }
            }

            if (specialTeleport)
            {
                specialPos = landingPoint.ToWorldCoordinates(8f,
                                                             16f) - new Vector2(player.width / 2f, player.height);
            }

            if (specialTeleport)
            {
                player.Teleport(specialPos, 5);
                player.velocity = Vector2.Zero;

                if (Main.netMode != NetmodeID.Server)
                {
                    return;
                }

                RemoteClient.CheckSection(player.whoAmI, player.position);
                NetMessage.SendData(MessageID.Teleport, -1, -1, null, 0, player.whoAmI, specialPos.X, specialPos.Y, 5);
            }
            else
            {
                Vector2 position = player.position;
                player.Teleport(position, 5);
                player.velocity = Vector2.Zero;

                if (Main.netMode != NetmodeID.Server)
                {
                    return;
                }

                RemoteClient.CheckSection(player.whoAmI, player.position);
                NetMessage.SendData(MessageID.Teleport, -1, -1, null, 0, player.whoAmI, position.X, position.Y, 5, 1);
            }
        }
Пример #12
0
 private static void HandleRandomTeleport(Player player, bool syncData = false)
 {
     player.TeleportationPotion();             // RND
     LeaveDust(player);
     if (Main.netMode != 2)
     {
         return;
     }
     if (syncData)
     {
         RemoteClient.CheckSection(player.whoAmI, player.position);
         NetMessage.SendData(65, -1, -1, null, 0, player.whoAmI, player.position.X, player.position.Y, 3);
     }
 }
Пример #13
0
        public void SafeTeleport(Vector2 position)
        {
            if (RealPlayer && ConnectionAlive)
            {
                var p = PrototypePlayer;


                p.AddBuff(ServerSideCharacter2.Instance.BuffType <Protection>(), 300, false);
                NetMessage.SendData(MessageID.AddPlayerBuff, playerID, -1,
                                    NetworkText.Empty, playerID,
                                    ServerSideCharacter2.Instance.BuffType <Protection>(), 300, 0f, 0, 0, 0);
                RemoteClient.CheckSection(playerID, position);

                MessageSender.SendSafeTeleport(p.whoAmI, position);
            }
        }
Пример #14
0
        private void Teleport(Point16 from, Point16 to, bool auto)
        {
            Rectangle fromRect = new Rectangle(from.X * 16 - 16, from.Y * 16 - 48, 48, 48);
            Rectangle toRect   = new Rectangle(to.X * 16 - 16, to.Y * 16 - 48, 48, 48);
            Vector2   delta    = new Vector2(toRect.X - fromRect.X, toRect.Y - fromRect.Y);

            if (!Wiring.blockPlayerTeleportationForOneIteration)
            {
                for (int i = 0; i < Main.player.Length; i++)
                {
                    if (Main.player[i].active && !Main.player[i].dead && !Main.player[i].teleporting && fromRect.Intersects(Main.player[i].getRect()))
                    {
                        if (!CanAuto(i) && auto)
                        {
                            continue;
                        }

                        Vector2 newPos = Main.player[i].position + delta;
                        if (Main.netMode == 2)
                        {
                            RemoteClient.CheckSection(i, newPos, 1);
                        }
                        Main.player[i].Teleport(newPos, 0, 0);
                        if (Main.netMode == 2)
                        {
                            NetMessage.SendData(65, -1, -1, null, 0, (float)i, newPos.X, newPos.Y, 0, 0, 0);
                        }
                    }
                }
            }

            if (!auto)
            {
                for (int i = 0; i < Main.npc.Length; i++)
                {
                    if (Main.npc[i].active && !Main.npc[i].teleporting && Main.npc[i].lifeMax > 5 && !Main.npc[i].boss && !Main.npc[i].noTileCollide)
                    {
                        int type = Main.npc[i].type;
                        if (!NPCID.Sets.TeleportationImmune[type] && fromRect.Intersects(Main.npc[i].getRect()))
                        {
                            Main.npc[i].Teleport(Main.npc[i].position + delta, 0, 0);
                        }
                    }
                }
            }
        }
Пример #15
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            var msgType = (MessageType)reader.ReadByte();

            switch (msgType)
            {
            case MessageType.AddLink:

                var transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                var receiver    = new Point16(reader.ReadInt16(), reader.ReadInt16());
                if (!WirelessUtils.AlreadyExists(transmitter, receiver))
                {
                    WirelessSystem.Links[transmitter] = receiver;
                    if (Main.netMode == NetmodeID.Server)                            //Server-side
                    {
                        SyncAddLink(transmitter, receiver, whoAmI);                  //Broadcast the change to other clients
                    }
                }
                break;

            case MessageType.RemoveLink:
                transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                WirelessSystem.Links.Remove(transmitter);

                if (Main.netMode == NetmodeID.Server)
                {
                    SyncRemoveLink(transmitter, whoAmI);
                }
                break;

            case MessageType.TripWire:
                receiver = new Point16(reader.ReadInt16(), reader.ReadInt16());
                ActivateReceiver(receiver);

                if (Main.netMode == NetmodeID.Server)
                {
                    RemoteClient.CheckSection(whoAmI, receiver.ToWorldCoordinates());
                }
                break;
            }
        }
Пример #16
0
        private static void RunTeleport(Player player, Vector2 pos, bool syncData = false, bool convertFromTiles = false)
        {
            bool postImmune      = player.immune;
            int  postImmunteTime = player.immuneTime;

            if (convertFromTiles)
            {
                pos = new Vector2(pos.X * 16 + 8 - player.width / 2, pos.Y * 16 - player.height);
            }

            LeaveDust(player);

            //Kill hooks
            player.grappling[0] = -1;
            player.grapCount    = 0;
            for (int index = 0; index < 1000; ++index)
            {
                if (Main.projectile[index].active && Main.projectile[index].owner == player.whoAmI && Main.projectile[index].aiStyle == 7)
                {
                    Main.projectile[index].Kill();
                }
            }

            player.Teleport(pos, 2, 0);
            player.velocity   = Vector2.Zero;
            player.immune     = postImmune;
            player.immuneTime = postImmunteTime;

            LeaveDust(player);

            if (Main.netMode != 2)
            {
                return;
            }

            if (syncData)
            {
                RemoteClient.CheckSection(player.whoAmI, player.position, 1);
                NetMessage.SendData(65, -1, -1, null, 0, (float)player.whoAmI, pos.X, pos.Y, 3, 0, 0);
            }
        }
Пример #17
0
        public void HandleTeleportRequest(TeleportPylonInfo info, int playerIndex)
        {
            Player player = Main.player[playerIndex];
            string key    = (string)null;
            bool   flag1  = true;

            if (flag1)
            {
                flag1 &= TeleportPylonsSystem.IsPlayerNearAPylon(player);
                if (!flag1)
                {
                    key = "Net.CannotTeleportToPylonBecausePlayerIsNotNearAPylon";
                }
            }
            if (flag1)
            {
                int necessaryNPCCount = this.HowManyNPCsDoesPylonNeed(info, player);
                flag1 &= this.DoesPylonHaveEnoughNPCsAroundIt(info, necessaryNPCCount);
                if (!flag1)
                {
                    key = "Net.CannotTeleportToPylonBecauseNotEnoughNPCs";
                }
            }
            if (flag1)
            {
                flag1 &= !NPC.AnyDanger(false);
                if (!flag1)
                {
                    key = "Net.CannotTeleportToPylonBecauseThereIsDanger";
                }
            }
            if (flag1)
            {
                if (!NPC.downedPlantBoss && (double)info.PositionInTiles.Y > Main.worldSurface && Framing.GetTileSafely((int)info.PositionInTiles.X, (int)info.PositionInTiles.Y).wall == (ushort)87)
                {
                    flag1 = false;
                }
                if (!flag1)
                {
                    key = "Net.CannotTeleportToPylonBecauseAccessingLihzahrdTempleEarly";
                }
            }
            SceneMetricsScanSettings metricsScanSettings;

            if (flag1)
            {
                SceneMetrics sceneMetrics = this._sceneMetrics;
                metricsScanSettings = new SceneMetricsScanSettings();
                metricsScanSettings.VisualScanArea = new Rectangle?();
                metricsScanSettings.BiomeScanCenterPositionInWorld = new Vector2?(info.PositionInTiles.ToWorldCoordinates(8f, 8f));
                metricsScanSettings.ScanOreFinderData = false;
                SceneMetricsScanSettings settings = metricsScanSettings;
                sceneMetrics.ScanAndExportToMain(settings);
                flag1 = this.DoesPylonAcceptTeleportation(info, player);
                if (!flag1)
                {
                    key = "Net.CannotTeleportToPylonBecauseNotMeetingBiomeRequirements";
                }
            }
            if (flag1)
            {
                bool flag2 = false;
                int  num   = 0;
                for (int index = 0; index < this._pylons.Count; ++index)
                {
                    TeleportPylonInfo pylon = this._pylons[index];
                    if (player.InInteractionRange((int)pylon.PositionInTiles.X, (int)pylon.PositionInTiles.Y))
                    {
                        if (num < 1)
                        {
                            num = 1;
                        }
                        int necessaryNPCCount = this.HowManyNPCsDoesPylonNeed(pylon, player);
                        if (this.DoesPylonHaveEnoughNPCsAroundIt(pylon, necessaryNPCCount))
                        {
                            if (num < 2)
                            {
                                num = 2;
                            }
                            SceneMetrics sceneMetrics = this._sceneMetrics;
                            metricsScanSettings = new SceneMetricsScanSettings();
                            metricsScanSettings.VisualScanArea = new Rectangle?();
                            metricsScanSettings.BiomeScanCenterPositionInWorld = new Vector2?(pylon.PositionInTiles.ToWorldCoordinates(8f, 8f));
                            metricsScanSettings.ScanOreFinderData = false;
                            SceneMetricsScanSettings settings = metricsScanSettings;
                            sceneMetrics.ScanAndExportToMain(settings);
                            if (this.DoesPylonAcceptTeleportation(pylon, player))
                            {
                                flag2 = true;
                                break;
                            }
                        }
                    }
                }
                if (!flag2)
                {
                    flag1 = false;
                    switch (num)
                    {
                    case 1:
                        key = "Net.CannotTeleportToPylonBecauseNotEnoughNPCsAtCurrentPylon";
                        break;

                    case 2:
                        key = "Net.CannotTeleportToPylonBecauseNotMeetingBiomeRequirements";
                        break;

                    default:
                        key = "Net.CannotTeleportToPylonBecausePlayerIsNotNearAPylon";
                        break;
                    }
                }
            }
            if (flag1)
            {
                Vector2 newPos      = info.PositionInTiles.ToWorldCoordinates(8f, 8f) - new Vector2(0.0f, (float)player.HeightOffsetBoost);
                int     num         = 9;
                int     typeOfPylon = (int)info.TypeOfPylon;
                int     number6     = 0;
                player.Teleport(newPos, num, typeOfPylon);
                player.velocity = Vector2.Zero;
                if (Main.netMode != 2)
                {
                    return;
                }
                RemoteClient.CheckSection(player.whoAmI, player.position, 1);
                NetMessage.SendData(65, -1, -1, (NetworkText)null, 0, (float)player.whoAmI, newPos.X, newPos.Y, num, number6, typeOfPylon);
            }
            else
            {
                ChatHelper.SendChatMessageToClient(NetworkText.FromKey(key), new Color((int)byte.MaxValue, 240, 20), playerIndex);
            }
        }
Пример #18
0
        private void OnGetData(GetDataEventArgs args)
        {
            // TshockではGhostへのタイル送信が行われないため、プレイヤーが移動するPlayerUpdateパケットで送信する
            if (!args.Handled &&
                args.MsgID == PacketTypes.PlayerUpdate)
            {
                if (Main.player[args.Msg.whoAmI].ghost)
                {
                    BinaryReader reader      = new BinaryReader(new MemoryStream(args.Msg.readBuffer, args.Index, args.Length));
                    int          playerIndex = reader.ReadByte();
                    if (playerIndex != Main.myPlayer ||
                        Main.ServerSideCharacter)
                    {
                        // Update Player
                        Player player = Main.player[playerIndex];

                        BitsByte bitsByte10 = reader.ReadByte();
                        BitsByte bitsByte11 = reader.ReadByte();
                        BitsByte bitsByte12 = reader.ReadByte();
                        BitsByte bitsByte13 = reader.ReadByte();
                        player.controlUp      = bitsByte10[0];
                        player.controlDown    = bitsByte10[1];
                        player.controlLeft    = bitsByte10[2];
                        player.controlRight   = bitsByte10[3];
                        player.controlJump    = bitsByte10[4];
                        player.controlUseItem = bitsByte10[5];
                        player.direction      = (bitsByte10[6] ? 1 : (-1));
                        if (bitsByte11[0])
                        {
                            player.pulley    = true;
                            player.pulleyDir = (byte)((!bitsByte11[1]) ? 1 : 2);
                        }
                        else
                        {
                            player.pulley = false;
                        }
                        player.vortexStealthActive = bitsByte11[3];
                        player.gravDir             = (bitsByte11[4] ? 1 : (-1));
                        player.TryTogglingShield(bitsByte11[5]);
                        player.ghost        = bitsByte11[6];
                        player.selectedItem = reader.ReadByte();
                        player.position     = reader.ReadVector2();
                        if (bitsByte11[2])
                        {
                            player.velocity = reader.ReadVector2();
                        }
                        else
                        {
                            player.velocity = Vector2.Zero;
                        }
                        if (bitsByte12[6])
                        {
                            player.PotionOfReturnOriginalUsePosition = reader.ReadVector2();
                            player.PotionOfReturnHomePosition        = reader.ReadVector2();
                        }
                        else
                        {
                            player.PotionOfReturnOriginalUsePosition = null;
                            player.PotionOfReturnHomePosition        = null;
                        }
                        player.tryKeepingHoveringUp        = bitsByte12[0];
                        player.IsVoidVaultEnabled          = bitsByte12[1];
                        player.sitting.isSitting           = bitsByte12[2];
                        player.downedDD2EventAnyDifficulty = bitsByte12[3];
                        player.isPettingAnimal             = bitsByte12[4];
                        player.isTheAnimalBeingPetSmall    = bitsByte12[5];
                        player.tryKeepingHoveringDown      = bitsByte12[7];
                        player.sleeping.SetIsSleepingAndAdjustPlayerRotation(player, bitsByte13[0]);

                        RemoteClient.CheckSection(playerIndex, player.position);
                    }
                }

                // ひとまずGhostと同じ処理
                if (!Main.player[args.Msg.whoAmI].active)
                {
                    BinaryReader reader      = new BinaryReader(new MemoryStream(args.Msg.readBuffer, args.Index, args.Length));
                    int          playerIndex = reader.ReadByte();
                    if (playerIndex != Main.myPlayer ||
                        Main.ServerSideCharacter)
                    {
                        // Update Player
                        Player player = Main.player[playerIndex];

                        BitsByte bitsByte10 = reader.ReadByte();
                        BitsByte bitsByte11 = reader.ReadByte();
                        BitsByte bitsByte12 = reader.ReadByte();
                        BitsByte bitsByte13 = reader.ReadByte();
                        player.controlUp      = bitsByte10[0];
                        player.controlDown    = bitsByte10[1];
                        player.controlLeft    = bitsByte10[2];
                        player.controlRight   = bitsByte10[3];
                        player.controlJump    = bitsByte10[4];
                        player.controlUseItem = bitsByte10[5];
                        player.direction      = (bitsByte10[6] ? 1 : (-1));
                        if (bitsByte11[0])
                        {
                            player.pulley    = true;
                            player.pulleyDir = (byte)((!bitsByte11[1]) ? 1 : 2);
                        }
                        else
                        {
                            player.pulley = false;
                        }
                        player.vortexStealthActive = bitsByte11[3];
                        player.gravDir             = (bitsByte11[4] ? 1 : (-1));
                        player.TryTogglingShield(bitsByte11[5]);
                        player.ghost        = bitsByte11[6];
                        player.selectedItem = reader.ReadByte();
                        player.position     = reader.ReadVector2();
                        if (bitsByte11[2])
                        {
                            player.velocity = reader.ReadVector2();
                        }
                        else
                        {
                            player.velocity = Vector2.Zero;
                        }
                        if (bitsByte12[6])
                        {
                            player.PotionOfReturnOriginalUsePosition = reader.ReadVector2();
                            player.PotionOfReturnHomePosition        = reader.ReadVector2();
                        }
                        else
                        {
                            player.PotionOfReturnOriginalUsePosition = null;
                            player.PotionOfReturnHomePosition        = null;
                        }
                        player.tryKeepingHoveringUp        = bitsByte12[0];
                        player.IsVoidVaultEnabled          = bitsByte12[1];
                        player.sitting.isSitting           = bitsByte12[2];
                        player.downedDD2EventAnyDifficulty = bitsByte12[3];
                        player.isPettingAnimal             = bitsByte12[4];
                        player.isTheAnimalBeingPetSmall    = bitsByte12[5];
                        player.tryKeepingHoveringDown      = bitsByte12[7];
                        player.sleeping.SetIsSleepingAndAdjustPlayerRotation(player, bitsByte13[0]);

                        RemoteClient.CheckSection(playerIndex, player.position);
                    }
                }
            }
        }
Пример #19
0
        public void HandleTeleportRequest(TeleportPylonInfo info, int playerIndex)
        {
            Player player = Main.player[playerIndex];
            string key    = null;
            bool   flag   = true;

            if (flag)
            {
                flag &= IsPlayerNearAPylon(player);
                if (!flag)
                {
                    key = "Net.CannotTeleportToPylonBecausePlayerIsNotNearAPylon";
                }
            }
            if (flag)
            {
                int necessaryNPCCount = HowManyNPCsDoesPylonNeed(info, player);
                flag &= DoesPylonHaveEnoughNPCsAroundIt(info, necessaryNPCCount);
                if (!flag)
                {
                    key = "Net.CannotTeleportToPylonBecauseNotEnoughNPCs";
                }
            }
            if (flag)
            {
                flag &= !NPC.AnyDanger();
                if (!flag)
                {
                    key = "Net.CannotTeleportToPylonBecauseThereIsDanger";
                }
            }
            if (flag)
            {
                if (!NPC.downedPlantBoss && (double)info.PositionInTiles.Y > Main.worldSurface && Framing.GetTileSafely(info.PositionInTiles.X, info.PositionInTiles.Y).wall == 87)
                {
                    flag = false;
                }
                if (!flag)
                {
                    key = "Net.CannotTeleportToPylonBecauseAccessingLihzahrdTempleEarly";
                }
            }
            SceneMetricsScanSettings settings;

            if (flag)
            {
                SceneMetrics sceneMetrics = _sceneMetrics;
                settings = new SceneMetricsScanSettings
                {
                    VisualScanArea = null,
                    BiomeScanCenterPositionInWorld = info.PositionInTiles.ToWorldCoordinates(),
                    ScanOreFinderData = false
                };
                sceneMetrics.ScanAndExportToMain(settings);
                flag = DoesPylonAcceptTeleportation(info, player);
                if (!flag)
                {
                    key = "Net.CannotTeleportToPylonBecauseNotMeetingBiomeRequirements";
                }
            }
            if (flag)
            {
                bool flag2 = false;
                int  num   = 0;
                for (int i = 0; i < _pylons.Count; i++)
                {
                    TeleportPylonInfo info2 = _pylons[i];
                    if (!player.InInteractionRange(info2.PositionInTiles.X, info2.PositionInTiles.Y))
                    {
                        continue;
                    }
                    if (num < 1)
                    {
                        num = 1;
                    }
                    int necessaryNPCCount2 = HowManyNPCsDoesPylonNeed(info2, player);
                    if (DoesPylonHaveEnoughNPCsAroundIt(info2, necessaryNPCCount2))
                    {
                        if (num < 2)
                        {
                            num = 2;
                        }
                        SceneMetrics sceneMetrics2 = _sceneMetrics;
                        settings = new SceneMetricsScanSettings
                        {
                            VisualScanArea = null,
                            BiomeScanCenterPositionInWorld = info2.PositionInTiles.ToWorldCoordinates(),
                            ScanOreFinderData = false
                        };
                        sceneMetrics2.ScanAndExportToMain(settings);
                        if (DoesPylonAcceptTeleportation(info2, player))
                        {
                            flag2 = true;
                            break;
                        }
                    }
                }
                if (!flag2)
                {
                    flag = false;
                    switch (num)
                    {
                    default:
                        key = "Net.CannotTeleportToPylonBecausePlayerIsNotNearAPylon";
                        break;

                    case 1:
                        key = "Net.CannotTeleportToPylonBecauseNotEnoughNPCsAtCurrentPylon";
                        break;

                    case 2:
                        key = "Net.CannotTeleportToPylonBecauseNotMeetingBiomeRequirements";
                        break;
                    }
                }
            }
            if (flag)
            {
                Vector2 newPos      = info.PositionInTiles.ToWorldCoordinates() - new Vector2(0f, player.HeightOffsetBoost);
                int     num2        = 9;
                int     typeOfPylon = (int)info.TypeOfPylon;
                int     number      = 0;
                player.Teleport(newPos, num2, typeOfPylon);
                player.velocity = Vector2.Zero;
                if (Main.netMode == 2)
                {
                    RemoteClient.CheckSection(player.whoAmI, player.position);
                    NetMessage.SendData(65, -1, -1, null, 0, player.whoAmI, newPos.X, newPos.Y, num2, number, typeOfPylon);
                }
            }
            else
            {
                ChatHelper.SendChatMessageToClient(NetworkText.FromKey(key), new Color(255, 240, 20), playerIndex);
            }
        }