예제 #1
0
        public void addAllPlayer(StringGroup pList)
        {
            uiPlayerList.Dispatcher.Invoke(() => {
                uiPlayerList.ItemsSource = null;

                var cache = pList.ToStringGroup();
                foreach (string item in cache) {
                    gm.gamePlayerList.Add(new Player { PlayerIPAddress = item });
                }

                uiPlayerList.ItemsSource = gm.gamePlayerList;

            });
        }
예제 #2
0
        public void inputPlayerData(StringGroup input)
        {
            var cache = input.ToStringGroup();

            foreach (Player item in gm.gamePlayerList) {
                if (item.PlayerName == cache[4]) {
                    item.NowLife = cache[1];
                    item.NowTime = cache[0];
                    item.NowUnit = cache[2];

                    //压入成就宣布队列
                    if (cache[4] != "") {
                        prizeLine.Enqueue(new PrizeStructure { PlayerName = cache[3], PrizeName = cache[4] });
                    }

                    return;
                }
            }

            //刷新
            this.FlushPlayerList();
        }
예제 #3
0
        public void allPlayerData(StringGroup data)
        {
            //split player
            var playerSplit = data.ToStringGroup();

            //先取出组信息
            var groupMsg = new StringGroup(playerSplit[0], "#").ToStringGroup();
            if (groupMsg[0] == gm.ms.TeamAName) {
                uiTeamAMark.Dispatcher.Invoke(() => { uiTeamAMark.Text = groupMsg[1]; });
                uiTeamBMark.Dispatcher.Invoke(() => { uiTeamBMark.Text = groupMsg[4]; });
                uiTeamAPP.Dispatcher.Invoke(() => { uiTeamAPP.Text = groupMsg[2]; });
                uiTeamBPP.Dispatcher.Invoke(() => { uiTeamBPP.Text = groupMsg[5]; });
            } else {
                uiTeamAMark.Dispatcher.Invoke(() => { uiTeamAMark.Text = groupMsg[4]; });
                uiTeamBMark.Dispatcher.Invoke(() => { uiTeamBMark.Text = groupMsg[1]; });
                uiTeamAPP.Dispatcher.Invoke(() => { uiTeamAPP.Text = groupMsg[5]; });
                uiTeamBPP.Dispatcher.Invoke(() => { uiTeamBPP.Text = groupMsg[2]; });
            }

            int index = 0;
            foreach (string item in playerSplit) {
                if (index == 0) { index++; continue; }

                //split data
                var dataSplit = new StringGroup(item, "#").ToStringGroup();

                //process untiData
                var cache1 = new StringGroup(dataSplit[0], "@").ToStringGroup();
                var unitData = new List<PlayerUnitData>();

                foreach (string item2 in cache1) {
                    var cache2 = new StringGroup(item2, "%").ToStringGroup();
                    unitData.Add(new PlayerUnitData { Unit = cache2[3], Mark = cache2[0], Life = cache2[1], PerfomancePoint = cache2[2] });
                }

                foreach (Player item3 in gm.gamePlayerList) {
                    if (item3.PlayerName == dataSplit[4]) {
                        item3.PlayerUnitPrize = unitData;
                        item3.FinallyMark = dataSplit[1];
                        item3.FinallyPP = dataSplit[2];
                        item3.FinallyPrize = dataSplit[3];
                    }
                }

                index++;
            }

            //input to list
            var teamAList = new List<Player>();
            var teamBList = new List<Player>();

            var result = from i in gm.gamePlayerList
                         where i.PlayerGroupName != ""
                         group i by i.PlayerGroupName;

            foreach (IGrouping<string, Player> item in result) {
                if (item.Key == gm.ms.TeamAName) {
                    foreach (Player item2 in item) {
                        teamAList.Add(item2);
                    }
                } else {
                    foreach (Player item2 in item) {
                        teamBList.Add(item2);
                    }
                }
            }

            //show
            uiTeamAList.Dispatcher.Invoke(() => { uiTeamAList.ItemsSource = teamAList;});
            uiTeamBList.Dispatcher.Invoke(() => { uiTeamBList.ItemsSource = teamBList; });

            uiNewPlay.Dispatcher.Invoke(() => { uiNewPlay.IsEnabled = true; });
            uiExit.Dispatcher.Invoke(() => { uiExit.IsEnabled = true;});
        }
        public void addPlayerInformation(StringGroup playerInfo)
        {
            var cache1 = playerInfo.ToStringGroup();

            List<string> cache2 = new StringGroup(cache1[5], "#").ToList();
            List<string> cache3 = new StringGroup(cache1[7], "#").ToList();

            //add to core
            foreach (Player item in gm.gamePlayerList) {
                if (item.PlayerIPAddress == cache1[10]) {
                    item.PlayerName = cache1[0];
                    item.ModList = cache3;
                    item.BackgroundName = cache1[8];
                    item.BGMName = cache1[9];
                    item.DutyUnit = cache2;
                    item.PlayerGroupName = cache1[6];
                }
            }

            if (gm.ms.MapName == "") {
                gm.ms.MapName = cache1[1];
                gm.ms.MapMD5 = cache1[2];
                gm.ms.GameMode = cache1[4];
                gm.ms.CountMode = cache1[3];
            }

            //add team
            if (gm.ms.TeamAName == "") {
                gm.ms.TeamAName = cache1[6];
                uiTeamAName.Dispatcher.Invoke(() => { uiTeamAName.Text = cache1[6]; });
            } else if (gm.ms.TeamBName == "") {
                gm.ms.TeamBName = cache1[6];
                uiTeamBName.Dispatcher.Invoke(() => { uiTeamBName.Text = cache1[6]; });
            } else { }

            //add to ui
            uiGameMapName.Dispatcher.Invoke(() =>
            {
                if (uiGameMapName.Text == "") {
                    uiGameMapName.Text = cache1[1];
                }
            });
            uiGameMode.Dispatcher.Invoke(() =>
            {
                if (uiGameMode.Text == "") {
                    switch (cache1[4]) {
                        case BallanceOnline.Const.GameMode.RankedRace:
                            uiGameMode.Text = "排位赛";
                            break;
                        case BallanceOnline.Const.GameMode.RelayRace:
                            uiGameMode.Text = "接力赛";
                            break;
                    }
                }
            });
            uiGameRule.Dispatcher.Invoke(() =>
            {
                if (uiGameRule.Text == "") {
                    switch (cache1[3]) {
                        case BallanceOnline.Const.CountMode.HighScore:
                            uiGameRule.Text = "HS";
                            break;
                        case BallanceOnline.Const.CountMode.SpeedRun:
                            uiGameRule.Text = "SR";
                            break;
                        case BallanceOnline.Const.CountMode.CrazyHighScore:
                            uiGameRule.Text = "疯狂HS";
                            break;
                        case BallanceOnline.Const.CountMode.CrazySpeedRun:
                            uiGameRule.Text = "疯狂SR";
                            break;

                    }
                }
            });

            //show player
            var playerSplit = from item in gm.gamePlayerList
                              where item.PlayerGroupName != ""
                              group item by item.PlayerGroupName;
            foreach (var item in playerSplit) {
                if (item.Key == gm.ms.TeamAName) {
                    uiTeamAList.Dispatcher.Invoke(() => { uiTeamAList.ItemsSource = item.ToList<Player>();});
                } else {
                    uiTeamBList.Dispatcher.Invoke(() => { uiTeamBList.ItemsSource = item.ToList<Player>();});
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 确认地图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiGSetMap_Click(object sender, RoutedEventArgs e)
        {
            if (nowStep != 0) { return; }

            if (uiMapPath.Text != "" && uiGroupAName.Text != "" && uiGroupBName.Text != "") {

                gm.ms.TeamAName = uiGroupAName.Text;
                gm.ms.TeamBName = uiGroupBName.Text;

                //set map name
                //todo:不知道为何要用双斜杠,不然出错
                //分开文件,文件夹
                var cache = new StringGroup(uiMapPath.Text, @"\\").ToStringGroup();
                //分开名字,扩展名
                var cache2 = cache[cache.Length - 1].Split('.');
                string cache3 = cache2[cache2.Length - 2];

                cache3 = cache3.Replace(",", "");
                cache3 = cache3.Replace("#", "");
                cache3 = cache3.Replace("@", "");
                cache3 = cache3.Replace("%", "");

                if (cache3.Length == 0) {
                    cache3 = "UnknowMap";
                }

                gm.ms.MapName = cache3;

                gm.ms.MapMD5 = uiMapMD5.Text;
                switch (uiGameMode.SelectedIndex) {
                    case 0:
                        gm.ms.GameMode = GameMode.RankedRace;
                        break;
                    case 1:
                        gm.ms.GameMode = GameMode.RelayRace;
                        break;
                }
                switch (uiCountMode.SelectedIndex) {
                    case 0:
                        gm.ms.CountMode = CountMode.HighScore;
                        break;
                    case 1:
                        gm.ms.CountMode = CountMode.SpeedRun;
                        break;
                    case 2:
                        gm.ms.CountMode = CountMode.CrazyHighScore;
                        break;
                    case 3:
                        gm.ms.CountMode = CountMode.CrazySpeedRun;
                        break;
                }

                //lock contorl
                uiGroupAName.IsReadOnly = true;
                uiGroupBName.IsReadOnly = true;

                uiMapPath.IsReadOnly = true;
                uiSelectMap.IsEnabled = false;

                uiSetMap.IsEnabled = false;
                uiGiveOutTask.IsEnabled = true;

                uiGameMode.IsEnabled = false;
                uiCountMode.IsEnabled = false;

                uiUnitCount.IsEnabled = false;

                //set unit selector
                for (int i = 0; i < uiUnitCount.Value; i++) {
                    var temp = new SetUnitToggleButton();

                    temp.Description = "第" + (i + 1).ToString() + "小节";
                    temp.IsChecked = false;
                    temp.Margin = new Thickness(15, 5, 15, 5);

                    //add to ui and core
                    uiUnitSelectorContainer.Children.Add(temp);
                    unitSelector.Add(temp);
                }

                nowStep++;
            } else {
                MessageBox.Show("某些信息您为填写完整");
            }
        }
예제 #6
0
        /// <summary>
        /// 主消息处理函数
        /// </summary>
        /// <param name="head"></param>
        /// <param name="data"></param>
        /// <param name="host"></param>
        public void MainMessageProcess(string head, byte[] data, Player host)
        {
            switch (head) {
                case ClientAndServerSign.Client + SocketSign.Ping:
                    host.PingCount--;
                    break;

                case ClientAndServerSign.Client + SocketSign.Message:
                    //转发,不交给界面处理
                    this.allPlayerBroadcast(CombineAndSplitSign.Combine(ClientAndServerSign.Server, SocketSign.Message, (host.PlayerName != "" ? host.PlayerName : host.PlayerIPAddress) + ":" + CombineAndSplitSign.ConvertToString(data)));
                    break;

                case ClientAndServerSign.Client + SocketSign.InformationTurnIn:
                    //set data
                    var cache = new StringGroup(CombineAndSplitSign.ConvertToString(data), ",").ToStringGroup();

                    host.ModList = new StringGroup(cache[0], "#").ToList();
                    host.BackgroundName = cache[1];
                    host.BGMName = cache[2];
                    host.PlayerName = cache[3];

                    var cache2 = new StringGroup(cache[4], "#").ToStringGroup();
                    host.HistoryWinCount = cache2[0];
                    host.HistoryFailCount = cache2[1];
                    host.HistoryRankedRaceCount = cache2[2];
                    host.HistoryRelayRaceCount = cache2[3];

                    //刷新
                    flushPlayerList();

                    break;

                case ClientAndServerSign.Client + SocketSign.PlayerIsReady:
                    //ready
                    host.playerIsReady();
                    this.allPlayerBroadcast(CombineAndSplitSign.Combine(ClientAndServerSign.Server, SocketSign.PlayerIsReady, host.PlayerName));

                    //刷新
                    flushPlayerList();

                    break;

                case ClientAndServerSign.Client + SocketSign.GameDataTurnIn:
                    var cache3 = new StringGroup(CombineAndSplitSign.ConvertToString(data), ",").ToStringGroup();
                    host.NowTime = cache3[0];
                    host.NowLife = cache3[1];
                    host.NowUnit = cache3[2];
                    host.NowState = "";

                    //判断游戏状态
                    if (host.NowState == PlayerState.Success || host.NowState==PlayerState.Died) {
                        //拒绝数据
                        break;
                    }

                    /* 判定方法
                     * 暂停:状态在正在游戏,数据保持不变<20次,且有命,时间数据不变。(放弃判断)
                     * 继续:状态为暂停,数据有变动,同时清空数据不变标识符。(放弃判断)
                     * 死亡:状态在正在游戏,数据不变>=20次,且命=0
                     * 成功:状态在正在游戏,时间减少,减少量>20点
                     * */

                    //***********************判断状态

                    //要传出的数据
                    List<string> outPrize = new List<string>();

                    if (host.dataCache.previousState == PlayerState.Playing && host.NowTime == host.dataCache.previousTime) {
                        //增加数据静止值
                        host.dataCache.dataCompareNotChangeCount++;
                    } else host.dataCache.dataCompareNotChangeCount = 0;

                    //先判断死亡
                    if (host.dataCache.previousState == PlayerState.Playing && host.dataCache.dataCompareNotChangeCount >= 20 && host.NowLife == "0" && host.NowTime == host.dataCache.previousTime) {

                        //###########################成就-沉默#######################
                        //不是一次性输出,可以多次输出
                        //信息压入玩家队列传出
                        outPrize.Add(GamePrize.Silence);
                        //###########################成就#######################
                        host.NowState = PlayerState.Died;
                        //增加完成任务数量人数
                        nowFinishPlayerCount++;

                        //判断一波组死亡
                        if (this.ms.GameMode == GameMode.RelayRace) {
                            foreach (string item in host.DutyUnit) {
                                if (int.Parse(item) >= int.Parse(host.NowUnit)) {
                                    //组死亡

                                    //组死亡肯定包含上面已经死的人,所以完成人数--防止重复计算
                                    nowFinishPlayerCount--;

                                    //循环死亡
                                    foreach (Player item2 in this.clientPlayerList) {
                                        if (item2.PlayerGroupName == host.PlayerGroupName) {
                                            item2.NowState = PlayerState.Died;
                                            //增加完成任务数量人数
                                            nowFinishPlayerCount++;

                                            //###########################成就-团灭#######################
                                            if (this.globalPrize.Ace == false) {
                                                //信息压入玩家队列传出
                                                outPrize.Add(GamePrize.Ace);
                                                this.globalPrize.Ace = true;
                                            }
                                            //###########################成就#######################

                                            //小节线最终写入
                                            item2.dataCache.AddUnitData(item2.NowTime, item2.NowLife);
                                            //停止计时器
                                            item2.gameTime.Stop();
                                        }
                                    }

                                    this.allPlayerBroadcast(CombineAndSplitSign.Combine(ClientAndServerSign.Server, SocketSign.TeamDied, host.PlayerGroupName));
                                }
                            }
                        }else {
                            //不是组死亡
                            //单独广播
                            this.allPlayerBroadcast(CombineAndSplitSign.Combine(ClientAndServerSign.Server, SocketSign.PlayerDied, host.PlayerName));
                        }
                    }

                    //成功
                    if (host.dataCache.previousState == PlayerState.Playing && (int.Parse(host.dataCache.previousTime) - int.Parse(host.NowTime)) > 20) {
                        this.allPlayerBroadcast(CombineAndSplitSign.Combine(ClientAndServerSign.Server, SocketSign.PlayerSuccess, host.PlayerName));
                        host.NowState = PlayerState.Success;
                        //增加完成任务数量人数
                        nowFinishPlayerCount++;

                        //小节线最终写入,用之前的数据写入,更加准确
                        host.dataCache.AddUnitData(host.dataCache.previousTime, host.dataCache.previousLife);
                        //停止计时器
                        host.gameTime.Stop();
                    }

                    //判断计时器
                    if (host.dataCache.previousTime == "") {
                        //第一次,启动计时器
                        host.gameTime.Start();
                    }

                    //判断小节线变动
                    if (host.dataCache.previousState == PlayerState.Playing) {
                        if (host.dataCache.previousTime == "") {
                            //刚开始,立即写入
                            host.dataCache.AddUnitData(host.NowTime, host.NowLife);

                        } else if (host.dataCache.previousUnit != host.NowUnit) {
                            //新小节
                            //###########################成就-通过#######################
                            //不是一次性成就
                            //信息压入玩家队列传出
                            outPrize.Add(GamePrize.Cross);
                            //###########################成就#######################
                            host.dataCache.AddUnitData(host.NowTime, host.NowLife);
                        }//否则不写入
                    }

                    //暂停
                    //if (host.previousState == PlayerState.Playing && host.dataCompareNotChangeCount <10 && host.NowLife != "0" && host.NowTime == host.previousTime) {
                    //    host.gameData.SendData(CombineAndSplitSign.Combine(ClientAndServerSign.Server, SocketSign.PlayerPaused, host.PlayerName));
                    //    host.NowState = PlayerState.Paused;
                    //}

                    //**********************************************************************todo:判断成就

                    //###########################成就-第一次死亡#######################
                    if (this.globalPrize.FirstBlood == false) {
                        //信息压入玩家队列传出
                        if (int.Parse(host.NowLife) < int.Parse(host.dataCache.previousLife)) {
                            outPrize.Add(GamePrize.FirstBlood);
                            this.globalPrize.FirstBlood = true;
                        }
                    }
                    //###########################成就#######################
                    //###########################成就-重生#######################
                    //非一次性成就
                    //信息压入玩家队列传出
                    if (int.Parse(host.NowLife) > int.Parse(host.dataCache.previousLife)) {
                        outPrize.Add(GamePrize.Reborn);
                    }
                    //###########################成就#######################
                    //###########################成就-时间#######################
                    //非一次性成就
                    //信息压入玩家队列传出
                    if (int.Parse(host.NowTime) > int.Parse(host.dataCache.previousTime)) {
                        outPrize.Add(GamePrize.Time);
                    }
                    //###########################成就#######################

                    //判断写入
                    host.dataCache.previousLife = host.NowLife;
                    host.dataCache.previousTime = host.NowTime;
                    host.dataCache.previousUnit = host.NowUnit;
                    if (host.NowState != "") host.dataCache.previousState = host.NowState;

                    //传出
                    this.allPlayerBroadcast(CombineAndSplitSign.Combine(
                        ClientAndServerSign.Server,
                        SocketSign.GameDataGiveOut,
                        new StringGroup(new List<string> {
                            host.dataCache.previousTime,
                            host.dataCache.previousLife,
                            host.dataCache.previousUnit,
                            outPrize.Count == 0 ? "" : new StringGroup(outPrize,"#").ToString(),
                            host.PlayerName
                        }, ",").ToString()));

                    //提醒服务器注意
                    if (nowFinishPlayerCount == clientPlayerList.Count) {
                        //可能都完成了
                        warnPlayerFinishGame();
                    }

                    //刷新
                    flushPlayerList();

                    break;

            }
        }
예제 #7
0
        /// <summary>
        /// 消息主处理函数
        /// </summary>
        /// <param name="head"></param>
        /// <param name="data"></param>
        public void dataProcess(string head, byte[] data)
        {
            switch (head) {

                case ClientAndServerSign.Server + SocketSign.Ping:
                    dataGiveIn.SendData(CombineAndSplitSign.Combine(ClientAndServerSign.Client, SocketSign.Ping, ""));
                    break;
                case ClientAndServerSign.Server + SocketSign.ReturnAllPlayer:

                    var cache = new StringGroup(CombineAndSplitSign.ConvertToString(data), ",");
                    WaitPlayer_addAllPlayer(cache);

                    break;
                case ClientAndServerSign.Server + SocketSign.NewPlayer:
                    WaitPlayer_addSinglePlayer(CombineAndSplitSign.ConvertToString(data));
                    break;

                case ClientAndServerSign.Server + SocketSign.DeletePlayer:
                    WaitPlayer_deletePlayer(CombineAndSplitSign.ConvertToString(data));
                    break;

                case ClientAndServerSign.Server + SocketSign.Message:
                    switch (nowPage) {
                        case 0:
                            WaitPlayer_newMessage(CombineAndSplitSign.ConvertToString(data));
                            break;
                        case 1:
                            //没有
                            break;
                        case 2:
                            PlayNow_newMessage(CombineAndSplitSign.ConvertToString(data));
                            break;
                        case 3:
                            //没有
                            break;
                    }

                    break;

                case ClientAndServerSign.Server + SocketSign.OrderTurnIn:
                    //返回数据
                    var cache2 = new ArrayList {
                        new StringGroup(gameSettings.ModList, "#").ToString(),
                        gameSettings.backgroundName,
                        gameSettings.BGMName,
                        gameSettings.playerName,
                        gameSettings.historyWinCount,
                        gameSettings.historyFailCount,
                        gameSettings.historyRankedCount,
                        gameSettings.historyRelayRaceCount
                    };
                    dataGiveIn.SendData(CombineAndSplitSign.Combine(ClientAndServerSign.Client, SocketSign.InformationTurnIn, new StringGroup(cache2, ",").ToString()));

                    nowPage += 1;

                    WaitPlayer_turnToNewWindow();

                    break;

                case ClientAndServerSign.Server + SocketSign.PlayerTask:
                    LoadResources_addPlayerInformation(new StringGroup(CombineAndSplitSign.ConvertToString(data), ","));
                    break;

                //********************************************
                case ClientAndServerSign.Server + SocketSign.StartDownloadingMap:
                    df.Start("");
                    break;
                case ClientAndServerSign.Server + SocketSign.DownloadingMapData:
                    df.Write(data);
                    break;
                case ClientAndServerSign.Server + SocketSign.EndDownloadingMap:
                    df.Stop();
                    //change file
                    System.IO.File.Delete(gameSettings.rootFolder + @"3D Entities\Level\Level_01.NMO");
                    System.IO.File.Copy(Environment.CurrentDirectory + @"\cacheMap.nmo", gameSettings.rootFolder + @"3D Entities\Level\Level_01.NMO");
                    //send message
                    dataGiveIn.SendData(CombineAndSplitSign.Combine(ClientAndServerSign.Client, SocketSign.PlayerIsReady, ""));
                    break;
                case ClientAndServerSign.Server + SocketSign.PlayerIsReady:
                    LoadResources_singlePlayerReady(CombineAndSplitSign.ConvertToString(data));
                    break;

                case ClientAndServerSign.Server + SocketSign.ReadyPlay:
                    LoadResources_turnToNewWindow();
                    nowPage += 1;
                    break;

                //********************************************
                case ClientAndServerSign.Server + SocketSign.GameDataGiveOut:
                    PlayNow_inputPlayerData(new StringGroup(CombineAndSplitSign.ConvertToString(data), ","));
                    break;

                case ClientAndServerSign.Server + SocketSign.PlayerDied:
                    PlayNow_playerDied(CombineAndSplitSign.ConvertToString(data));
                    break;

                case ClientAndServerSign.Server + SocketSign.PlayerSuccess:
                    PlayNow_playerSuccess(CombineAndSplitSign.ConvertToString(data));
                    break;

                case ClientAndServerSign.Server + SocketSign.TeamDied:
                    PlayNow_teamDied(CombineAndSplitSign.ConvertToString(data));
                    break;

                case ClientAndServerSign.Server + SocketSign.GameEnd:
                    PlayNow_turnToNewWindow();
                    nowPage += 1;
                    break;

                //********************************************

                case ClientAndServerSign.Server + SocketSign.AllPlayerGameData:
                    GameResult_allPlayerData(new StringGroup(CombineAndSplitSign.ConvertToString(data), ","));
                    //连接关闭
                    dataGiveIn.Dispose();
                    break;

            }
        }