Beispiel #1
0
        public static void Handle_PlayTogether(ClientConnection Client, PacketReader packet, byte last)
        {
            Account User       = Client.CurrentAccount;
            int     unk        = packet.ReadLEInt32();
            int     roomid     = packet.ReadLEInt32();
            byte    roomkindid = packet.ReadByte();
            int     pwlen      = packet.ReadLEInt32();
            string  pw         = string.Empty;

            if (pwlen > 0)
            {
                pw = packet.ReadBig5StringSafe(pwlen);
            }
            bool isExist = Rooms.NormalRoomList.Exists(rm => rm.ID == roomid);

            if (!isExist)
            {
                Client.SendAsync(new GameRoom_EnterRoomError(User, 0x1, roomkindid, last));
            }
            else
            {
                NormalRoom room = Rooms.NormalRoomList.Find(rm => rm.ID == roomid);
                GameRoomEvent.EnterRoom(Client, room, pw, last);
            }
        }
Beispiel #2
0
        public static void Handle_EnterRoom(ClientConnection Client, PacketReader reader, byte last)
        {
            Account User   = Client.CurrentAccount;
            int     roomid = reader.ReadLEInt32();
            int     pwlen  = reader.ReadLEInt32();
            string  pw     = string.Empty;

            if (pwlen != 0)
            {
                pw = reader.ReadBig5StringSafe(pwlen);
            }
            if (User.CurrentRoomId != 0)
            {
                GameRoomEvent.DisconnectRoom(User);
            }
            bool isExist = Rooms.NormalRoomList.Exists(rm => rm.ID == roomid);

            if (isExist)
            {
                NormalRoom room = Rooms.NormalRoomList.Find(rm => rm.ID == roomid);
                GameRoomEvent.EnterRoom(Client, room, pw, last);
            }
            else
            {
                Client.SendAsync(new GameRoom_EnterRoomError(User, 0x1, 0x9B, last));
            }
        }
Beispiel #3
0
        public async static void Handle_GameEndInfo(ClientConnection Client, PacketReader reader, byte last)
        {
            Account User = Client.CurrentAccount;

            User.RaceDistance = reader.ReadLESingle();
            float MapDistance = reader.ReadLESingle();

            User.GameEndType = reader.ReadLEInt16();
            long CurrentTime = Utility.CurrentTimeMilliseconds();

            Log.Debug("Game End - Nickname: {0}, GameEndType: {1}, RaceDistance: {2}", User.NickName, User.GameEndType, User.RaceDistance);

            if (User.GameEndType > 1)
            {
                NormalRoom room = Rooms.NormalRoomList.Find(rm => rm.ID == User.CurrentRoomId);
                if (room.GameMode == 38) //小遊戲
                {
                    return;
                }
                //GameEndType 2 = alive
                //GameEndType 3 = timeover
                //GameEndType 4 = gameover
                if (User.GameEndType == 2)
                {
                    User.LapTime       = (int)(CurrentTime - room.StartTime);
                    User.ServerLapTime = User.LapTime;
                    User.Rank          = room.Rank++;
                    Task calctask = Task.Run(() => GameRoomEvent.Calc_DropItem(User, room, User.Rank, last));
                    long EndTime  = Utility.CurrentTimeMilliseconds() + 2000;
                    await Task.Run(() => GameRoomEvent.Execute_GameEnd(room, EndTime, last));
                }
                else if (User.GameEndType == 3)
                {
                    User.LapTime       = (int)(CurrentTime + 200000 - room.StartTime);
                    User.ServerLapTime = User.LapTime;
                }
                else if (User.GameEndType == 4)
                {
                    User.LapTime       = (int)(CurrentTime + 240000 - room.StartTime);
                    User.ServerLapTime = User.LapTime;
                    room.Survival     -= 1;
                    byte mypos = User.RoomPos;
                    foreach (Account RoomPlayer in room.Players)
                    {
                        RoomPlayer.Connection.SendAsync(new GameRoom_GameOver(RoomPlayer, mypos, last));
                        if (room.Survival == 1 && room.RuleType == 2) //生存mode
                        {
                            byte alivepos = room.Players.Find(f => f.GameEndType == 0 && f.Attribute != 3).RoomPos;
                            RoomPlayer.Connection.SendAsync(new GameRoom_alive(RoomPlayer, alivepos, last));
                        }
                    }

                    if (room.Survival == 0 && room.RuleType == 3) //Hardcore
                    {
                        long EndTime = Utility.CurrentTimeMilliseconds() + 2000;
                        await Task.Run(() => GameRoomEvent.Execute_GameEnd(room, EndTime, last));
                    }
                }
            }
        }
        public async static void Handle_GoalInData(ClientConnection Client, PacketReader reader, byte last)
        {
            Account    User = Client.CurrentAccount;
            NormalRoom room = Rooms.NormalRoomList.Find(rm => rm.ID == User.CurrentRoomId);

            if (room.GameMode == 38) //小遊戲
            {
                return;
            }
            //FF C0 02 FF 52 03
            User.LapTime       = reader.ReadLEInt32(); //11 31 02 00 goal time
            User.ServerLapTime = (int)(Utility.CurrentTimeMilliseconds() - room.StartTime);
            reader.ReadLEUInt32();                     //54 6A 02 00
            //User.RaceDistance = reader.ReadLESingle(); //6F C3 DE 47 RaceDistance float 114054.867188
            //00 00 00 00 flag?
            long EndTime = Utility.CurrentTimeMilliseconds() + 13000;

            User.Rank = room.Rank++;
            if (!room.isGoal)
            {
                MapHolder.MapInfos.TryGetValue(room.PlayingMapNum, out MapInfo mapinfo);
                if (mapinfo.GoalInLimitTime * 1000 < User.ServerLapTime)
                {
                    Console.WriteLine("GoalIn");
                    foreach (Account RoomPlayer in room.Players)
                    {
                        RoomPlayer.Connection.SendAsync(new GameRoom_GoalInData(User, User.LapTime, last));
                        RoomPlayer.Connection.SendAsync(new GameRoom_StartTimeOutCount(RoomPlayer, User.LapTime + 2000, last)); //FF 7C 03 E1 38 02 00 0A
                        room.isGoal = true;
                    }
                    //await Task.Run(() => GameRoomEvent.Execute_GameEnd(room, EndTime, last));
                    Task calctask = Task.Run(() => GameRoomEvent.Calc_DropItem(User, room, User.Rank, last));
                    await Task.Run(() => GameRoomEvent.Execute_GameEnd(room, EndTime, last));
                }
                else
                {
                    Console.WriteLine("GoalInError");
                    Client.SendAsync(new GameRoom_GoalInError(User, last));
                }
            }
            else
            {
                foreach (Account RoomPlayer in room.Players)
                {
                    RoomPlayer.Connection.SendAsync(new GameRoom_GoalInData(User, User.LapTime, last));
                }
                //GameRoomEvent.Calc_DropItem(User, room, User.Rank, last);
                Task calctask = Task.Run(() => GameRoomEvent.Calc_DropItem(User, room, User.Rank, last));
            }
        }
Beispiel #5
0
        public static void Handle_StartLoading(ClientConnection Client, PacketReader reader, byte last)
        {
            Account    User     = Client.CurrentAccount;
            NormalRoom room     = Rooms.GetRoom(User.CurrentRoomId);
            int        mapid    = reader.ReadLEInt32(); //mapid
            int        randseed = reader.ReadLEInt32(); //00 92 D1 00  randseed

            reader.ReadByte();                          //00

            //Log.Info("startLoading(randseed = {0})", randseed);
            if (MapHolder.MapInfos.TryGetValue(mapid, out MapInfo mapinfo))
            {
                room.RuleType = mapinfo.RuleType;
                if (!room.is8Player && !room.CheckReadyPlayerNum(out int err))
                {
                    if (err > 0)
                    {
                        Client.SendAsync(new GameRoom_StartError(err, last));
                    }
                    room.isPlaying = false;
                    return;
                }

                if (room.GameMode == 2)
                {
                    List <Account> notReadyPlayers = room.Players.FindAll(p => !p.IsReady && p.RoomPos != room.RoomMasterIndex);
                    foreach (Account notReadyPlayer in notReadyPlayers)
                    {
                        GameRoomEvent.KickPlayer(notReadyPlayer, room, last);
                    }
                }
                else if (room.GameMode == 3)
                {
                    List <Account> notReadyPlayers = room.Players.FindAll(p => !p.IsReady);
                    foreach (Account notReadyPlayer in notReadyPlayers)
                    {
                        GameRoomEvent.KickPlayer(notReadyPlayer, room, last);
                    }
                }
                room.PlayingMapNum = mapid;
                room.BroadcastToAll(new GameRoom_StartLoading(mapid, randseed, last));
                room.StartWaitAllSyncThread();
                room.SetRewardGroupList();
            }
        }
        public static void Handle_StartGame(ClientConnection Client, PacketReader reader, byte last)
        {
            Account    User = Client.CurrentAccount;
            NormalRoom room = Rooms.NormalRoomList.Find(rm => rm.ID == User.CurrentRoomId);

            bool isRoomMaster = User.RoomPos == room.RoomMasterIndex;

            bool isAllReady = room.is8Player ? room.Players.FindAll(player => player.RoomPos != room.RoomMasterIndex).All(player => player.IsReady) : true;//如果是八人房間的話,則檢查除房主以外的所有人是否有準備

            if (isRoomMaster && isAllReady)
            {
                bool justchange = DateTime.Compare(DateTime.Now, room.ChangeMapTime.AddSeconds(3)) < 0;
                if (justchange)
                {
                    User.Connection.SendAsync(new GameRoom_StartError(User, 9, last));
                    return;
                }
                if (room.isOrderBy == 1 && room.SendRank > room.Players.Count(p => p.Attribute != 3))
                {
                    User.Connection.SendAsync(new GameRoom_StartError(User, 8, last));//不符合商品登錄條件,遊戲無法開始。
                    return;
                }
                if (room.IsTeamPlay == 2)
                {
                    int redteamcount  = room.Players.FindAll(p => p.Team == 1).Count;
                    int blueteamcount = room.Players.FindAll(p => p.Team == 2).Count;
                    if (redteamcount != blueteamcount)
                    {
                        User.Connection.SendAsync(new GameRoom_Hex(User, "FF0C0303", last));
                        User.Connection.SendAsync(new GameRoom_StartError(User, 3, last));//團隊不適合
                        return;
                    }
                }
                Log.Info("Start game CountDown");
                room.MapNum = reader.ReadLEInt32(); //mapid
                foreach (Account RoomPlayer in room.Players)
                {
                    RoomPlayer.Connection.SendAsync(new GameRoom_Hex(RoomPlayer, "FF0703", last)); //307
                }
                Task.Run(() => GameRoomEvent.TimeoutLoading(room, room.MatchTime));
            }
        }
Beispiel #7
0
        public static void Handle_KickPlayer(ClientConnection Client, PacketReader reader, byte last)
        {
            Account    User        = Client.CurrentAccount;
            int        nicknamelen = reader.ReadLEInt32();
            string     nickname    = reader.ReadBig5StringSafe(nicknamelen);
            NormalRoom room        = Rooms.NormalRoomList.Find(rm => rm.ID == User.CurrentRoomId);
            bool       isExist     = room.Players.Exists(p => p.NickName == nickname);

            if (isExist)
            {
                Account KickedPlayer      = room.Players.Find(p => p.NickName == nickname);
                byte    KickedPlayerIndex = KickedPlayer.RoomPos;
                if (room.RoomMasterIndex == User.RoomPos && room.RoomKindID != 0x4A && KickedPlayer.Attribute == 0)//room.RoomKindID != 0x4A <-----防公園踢人外掛, KickedPlayer.Attribute == 0 <-----只能踢普通玩家
                {
                    GameRoomEvent.KickPlayer(KickedPlayer, room, last);
                }
                if (User.Attribute != 0)
                {
                    GameRoomEvent.KickPlayer(KickedPlayer, room, last);
                }
            }
        }
        private static byte[] GenResult_ForMiniGameMode(NormalRoom room, byte last)
        {
            PacketWriter ns = new PacketWriter();

            ns = PacketWriter.CreateInstance(16, true);
            ns.Write((byte)0xFF);
            ns.Write((short)0x381);
            ns.Write((byte)room.RoomKindID);
            ns.Fill(room.IsTeamPlay == 0 ? 0xB : 0xA);
            if (room.IsTeamPlay != 0)
            {
                int winteam  = room.Players.OrderBy(p => p.Rank).FirstOrDefault().Team;
                int loseteam = winteam == 1 ? 2 : 1;
                ns.Write((byte)0x1);
                ns.Write(2);
                ns.Write(winteam);
                ns.Write(loseteam);
                ns.Write(winteam);
            }
            int playercount = room.DropItem.Count;

            ns.Write((byte)playercount); //count?
            ns.Fill(0x6);
            foreach (var p in room.DropItem.OrderBy(o => o.Rank).ThenBy(o => o.Pos))
            {
                ns.Write(p.ServerLapTime);
                ns.Write(p.LapTime);
                ns.Write(p.Rank);
                ns.Write(p.Pos);
                ns.Write(p.EXP);
                ns.Write(p.MiniGameStarPoint);
                ns.Write(p.TR);
                ns.Write(0);
                ns.Write(0L);
                if (room.IsTeamPlay != 0)
                {
                    ns.Write((int)p.Team);
                }
                ns.Write(0);
                ns.Write(p.BounsEXP);
                ns.Write(p.BounsTR);
                int bounsweight = 0;
                if (p.BounsTR > 0)
                {
                    bounsweight += 4;
                }
                if (p.BounsEXP > 0)
                {
                    bounsweight += 8;
                }
                ns.Write(bounsweight); // 0C 00 00 00
                ns.Write(playercount); //02 00 00 00 player count?
                int count = p.CardID.Count;
                ns.Write(count);       //card count

                foreach (var card in p.CardID)
                {
                    ns.Write(card);
                }
                ns.WriteHex("00BA8B19000000000000000000000000000000000000000000C5B01B000000000000");
            }

            //minigame part
            //00 00 03 00 00 00 03 00 00 00 16 00 00 00
            //00 00 00 00 00 02 C2 01 00 00 02 00 00 00 01 00
            ns.Write((short)0);
            ns.Write(3);
            ns.Write(3);
            ns.Write(12 + playercount * 5);
            foreach (var p in room.DropItem.OrderBy(o => o.Pos))
            {
                ns.Write(p.Pos);
                ns.Write(p.MiniGamePoint);
            }
            ns.Write(playercount); //player count?
            ns.Write(1);
            ns.Write(4);
            //minigame part end

            bool hasgavegoods = GameRoomEvent.SendRegisterGoods(room, out byte[] getgoodsnickname, last);

            if (hasgavegoods)
            {
                Account roomMaster = room.Players.Find(p => p.RoomPos == room.RoomMasterIndex);
                roomMaster.Connection.SendAsync(new GameRoom_DeleteKeepItem(roomMaster, room, last));
            }

            ns.Write(0x3EA);
            ns.Write(!hasgavegoods ? 0x11 : 0x11 + getgoodsnickname.Length);
            ns.Write(room.ItemNum);

            if (!hasgavegoods)
            {
                ns.Write(-1L);
                ns.Write((byte)0);
                ns.Write(1);
            }
            else
            {
                ns.Write(0x3b1c32);                                     //32 1C 3B 00
                ns.Write(2);
                ns.Write(getgoodsnickname, 0, getgoodsnickname.Length); //B5 A3 B8 DC B6 5D A4 48
                ns.Write((byte)0);
                ns.Write(getgoodsnickname.Length + 1);
            }
            ns.Write(0x3F6);
            ns.Write(4);
            ns.Write(0);
            ns.Write(0xC);
            ns.Write(last);
            byte[] ret = ns.ToArray();
            PacketWriter.ReleaseInstance(ns);
            ns = null;
            //Console.WriteLine("Result packet: " + Utility.ByteArrayToString(ret));
            return(ret);
        }
        public static void GameMode_FootStep_GoalIn(ClientConnection Client, PacketReader reader, byte last)
        {
            //FF C0 02 FF 4E 03 BA 52 02 00 01 01
            Console.WriteLine("FootStep_GoalIn");
            Account User = Client.CurrentAccount;

            if (User.GameEndType == 0)
            {
                NormalRoom room    = Rooms.GetRoom(User.CurrentRoomId);
                int        laptime = reader.ReadLEInt32();
                byte       unk     = reader.ReadByte();//flag?
                User.LapTime       = laptime;
                User.ServerLapTime = room.GetCurrentTime();
                //User.Rank = room.Rank++;
                if (!room.isGoal)
                {
                    room.isGoal = true;
                    if (room.RuleType == 8)
                    {
                        foreach (Account RoomPlayer in room.Players)
                        {
                            RoomPlayer.Connection.SendAsync(new FootStep_GoalIn(User.RoomPos, 1, last));
                            RoomPlayer.Connection.SendAsync(new Amsan_LapTimeControl(room.GetCurrentTime(), 10000, 0, false, last));
                            RoomPlayer.LastLapTime    = User.ServerLapTime;
                            RoomPlayer.CurrentLapTime = 10000;
                        }
                        Client.SendAsync(new GameRoom_GoalInData(User.RoomPos, User.LapTime, 1, last));
                    }
                    else
                    {
                        foreach (Account RoomPlayer in room.Players)
                        {
                            RoomPlayer.Connection.SendAsync(new FootStep_GoalIn_CountDown(laptime, 10000, last));
                            RoomPlayer.Connection.SendAsync(new FootStep_GoalIn(User.RoomPos, 1, last));
                            RoomPlayer.Connection.SendAsync(new GameRoom_GoalInData(User.RoomPos, User.LapTime, 1, last));
                            RoomPlayer.Connection.SendAsync(new GameRoom_StartTimeOutCount(User.LapTime + 2000, last));
                        }
                    }
                    long EndTime = Utility.CurrentTimeMilliseconds() + 15000;
                    Task.Run(() => GameRoomEvent.Execute_GameEnd(room, EndTime, last));
                    //Task.Run(() => GameRoomEvent.Calc_DropItem(User, room, User.Rank, last));
                }
                else
                {
                    if (room.RuleType == 8)
                    {
                        foreach (Account RoomPlayer in room.Players)
                        {
                            RoomPlayer.Connection.SendAsync(new FootStep_GoalIn(User.RoomPos, 1, last));
                        }
                        Client.SendAsync(new GameRoom_GoalInData(User.RoomPos, User.LapTime, 1, last));
                    }
                    else
                    {
                        foreach (Account RoomPlayer in room.Players)
                        {
                            RoomPlayer.Connection.SendAsync(new FootStep_GoalIn(User.RoomPos, 1, last));
                            RoomPlayer.Connection.SendAsync(new GameRoom_GoalInData(User.RoomPos, User.LapTime, 1, last));
                        }
                    }
                    //Task.Run(() => GameRoomEvent.Calc_DropItem(User, room, User.Rank, last));
                }
            }
        }
Beispiel #10
0
        public static void Handle_RandomEnterRoom(ClientConnection Client, PacketReader reader, byte last)
        {
            Account User       = Client.CurrentAccount;
            byte    roomkindid = reader.ReadByte();

            //int empty = reader.ReadLEInt32();

            if (roomkindid == 0x4A)
            {
                bool isExist = Rooms.NormalRoomList.Any(rm => rm.RoomKindID == 0x4A && rm.Players.Count < rm.MaxPlayersCount);
                if (!isExist)
                {
                    NormalRoom room = new NormalRoom();
                    room.setID(Rooms.RoomID);
                    room.setName("Park");
                    room.setPassword("");
                    room.setItemType(1);
                    room.setIsStepOn(true);
                    room.setRoomKindID(0x4A);
                    room.setIsTeamPlay(0);

                    room.Players.Add(User);
                    room.setMaxPlayersCount(30);
                    room.setPosList(30);

                    User.RoomPos = room.PosList.First();
                    room.PosList.Remove(User.RoomPos);
                    room.setRoomMasterIndex(User.RoomPos);

                    User.CurrentRoomId = Rooms.RoomID;
                    User.InGame        = true;

                    Client.SendAsync(new GameRoom_SendRoomInfo(User, room, last));
                    Client.SendAsync(new GameRoom_SendPlayerInfo(User, last));
                    Client.SendAsync(new GameRoom_GetRoomMaster(User, room.RoomMasterIndex, last)); //場主位置

                    Client.SendAsync(new GameRoom_SendRoomMaster(User, room.MapNum, room.RoomMasterIndex, last));

                    Rooms.NormalRoomList.Add(room);
                    Rooms.RoomID += 1;
                }
                else
                {
                    NormalRoom room = Rooms.NormalRoomList.FirstOrDefault(rm => rm.RoomKindID == 0x4A && rm.Players.Count < rm.MaxPlayersCount);
                    User.CurrentRoomId = room.ID;
                    User.InGame        = true;

                    //取得當前第一個位置id
                    User.RoomPos = room.PosList.FirstOrDefault();
                    room.PosList.Remove(User.RoomPos);

                    Client.SendAsync(new GameRoom_Hex(User, "FF5805FFFFFFFF00000000000000000000000000", last));
                    Client.SendAsync(new GameRoom_SendRoomInfo(User, room, last, User.RoomPos));

                    //Send自己info俾其他roomuser
                    foreach (Account roomUser in room.Players)
                    {
                        roomUser.Connection.SendAsync(new GameRoom_SendPlayerInfo(User, last));
                    }

                    room.Players.Add(User);

                    //Send roomuser info俾自己
                    foreach (Account roomUser in room.Players)
                    {
                        Client.SendAsync(new GameRoom_SendPlayerInfo(roomUser, last));
                    }

                    byte roommasterpos = room.RoomMasterIndex; //room.Players.Find(player => player.IsRoomMaster).RoomPos;
                    Client.SendAsync(new GameRoom_GetRoomMaster(User, roommasterpos, last));
                }
            }
            else
            {
                bool isExist = Rooms.NormalRoomList.Any(rm => rm.RoomKindID == roomkindid && rm.Players.Count < rm.MaxPlayersCount && !rm.isPlaying && !rm.HasPassword && !rm.Players.Exists(p => p.Attribute == 3));
                if (!isExist)
                {
                    Client.SendAsync(new GameRoom_EnterRoomError(User, 0xB, roomkindid, last));
                }
                else
                {
                    int        count = Rooms.NormalRoomList.Count(rm => rm.RoomKindID == roomkindid && rm.Players.Count < rm.MaxPlayersCount && !rm.isPlaying && !rm.HasPassword && !rm.Players.Exists(p => p.Attribute == 3));
                    NormalRoom room  = Rooms.NormalRoomList.FindAll(rm => rm.RoomKindID == roomkindid && rm.Players.Count < rm.MaxPlayersCount && !rm.isPlaying && !rm.HasPassword && !rm.Players.Exists(p => p.Attribute == 3))[new Random().Next(count)];
                    GameRoomEvent.EnterRoom(Client, room, string.Empty, last);
                }
            }
        }