コード例 #1
0
ファイル: ParamManager.cs プロジェクト: TheRekman/Pvp-Arena
        public void OnPlayerUpdate(object sender, GetDataHandlers.PlayerUpdateEventArgs args)
        {
            var player = TShock.Players[args.PlayerId];
            var arena  = ArenaManager.InArea(player);

            if (arena == null || player.HasPermission(Permissions.Ignore))
            {
                return;
            }


            if (ParamContains(arena, "autopvp"))
            {
                if (!player.TPlayer.hostile)
                {
                    ChangePvpStatus(player);
                }
                return;
            }
            if (ParamContains(arena, "autoinvise"))
            {
                if (!player.TPlayer.hostile)
                {
                    BuffInvise(player);
                }
                return;
            }
            if (ParamContains(arena, "autotp"))
            {
                if (!player.TPlayer.hostile)
                {
                    player.Teleport(Terraria.Main.spawnTileX * 16, Terraria.Main.spawnTileY * 16);
                }
                return;
            }
        }
コード例 #2
0
        private void OnGetData(GetDataEventArgs args)
        {
            switch (args.MsgID)
            {
                #region OnTileChange
            case PacketTypes.Tile:
                var playerInfo = TShock.Players[args.Msg.whoAmI].GetPlayerInfo();
                if (playerInfo.State == State.None)
                {
                    return;
                }
                using (var reader = new BinaryReader(new MemoryStream(args.Msg.readBuffer, args.Index, args.Length)))
                {
                    reader.ReadByte();
                    short x = reader.ReadInt16();
                    short y = reader.ReadInt16();
                    if ((x >= 0 && y >= 0) && (x < Main.maxTilesX && y < Main.maxTilesY))
                    {
                        SetPoints(new Point(x, y), playerInfo, TShock.Players[args.Msg.whoAmI]);
                    }
                }
                args.Handled = true;
                break;
                #endregion

                #region OnMassWire
            case PacketTypes.MassWireOperation:
                playerInfo = TShock.Players[args.Msg.whoAmI].GetPlayerInfo();
                if (playerInfo.State == State.None)
                {
                    return;
                }
                using (var reader = new BinaryReader(new MemoryStream(args.Msg.readBuffer, args.Index, args.Length)))
                {
                    short x1 = reader.ReadInt16();
                    short y1 = reader.ReadInt16();
                    short x2 = reader.ReadInt16();
                    short y2 = reader.ReadInt16();
                    if (x1 > 0 && y1 > 0 && x2 > 0 && y2 > 0 &&
                        x1 < Main.maxTilesX && y1 < Main.maxTilesY &&
                        x2 < Main.maxTilesX && y2 < Main.maxTilesY)
                    {
                        if ((x1 != x2 || y1 != y2) && (playerInfo.State == State.MapSave || playerInfo.State == State.ArenaSet))
                        {
                            SetPoints(new Point(x2, y2), playerInfo, TShock.Players[args.Msg.whoAmI]);
                        }
                        SetPoints(new Point(x1, y1), playerInfo, TShock.Players[args.Msg.whoAmI]);
                    }
                }
                args.Handled = true;
                break;
                #endregion

                #region OnDeath
            case PacketTypes.PlayerDeathV2:
                var arena = ArenaManager.InArea(TShock.Players[args.Msg.whoAmI]);
                if (arena == null)
                {
                    return;
                }
                if (TShock.Players[args.Msg.whoAmI].TPlayer.hostile)
                {
                    playerInfo = TShock.Players[args.Msg.whoAmI].GetPlayerInfo();
                    Random rnd        = new Random();
                    Point  spawnPoint = arena.Map.Spawns[new Random().Next() % arena.Map.Spawns.Count()];
                    playerInfo.SpawnPoint = new Point((spawnPoint.X + arena.MapPoint.X) * 16,
                                                      (spawnPoint.Y + arena.MapPoint.Y) * 16);
                }
                break;
                #endregion

                #region OnSpawn
            case PacketTypes.PlayerSpawn:
                playerInfo = TShock.Players[args.Msg.whoAmI].GetPlayerInfo();
                if (playerInfo.SpawnPoint.X < 1)
                {
                    return;
                }
                TShock.Players[args.Msg.whoAmI].Teleport(playerInfo.SpawnPoint.X, playerInfo.SpawnPoint.Y);
                playerInfo.SpawnPoint.X = -1;
                TShock.Players[args.Msg.whoAmI].SendInfoMessage("You automatically teleported to the arena.");
                break;
                #endregion
            }
        }