Example #1
0
        public void RemovePlayer(GamePlayer player)
        {
            _processor.OnRemovingPlayer(this, player);
            lock (Data._syncStop)
            {
                if (_userList[player.CurrentGameIndex] == player)
                {
                    _userList[player.CurrentGameIndex] = null;
                    _count--;

                    int        offer = DeductOffer(player);
                    GSPacketIn pkg   = player.Out.SendGamePlayerLeave(player, offer, this);
                    SendToPlayerExceptSelf(pkg, player);

                    if (player == _player)
                    {
                        if (Count > 0)
                        {
                            for (byte i = 0; i < _userList.Length; i++)
                            {
                                if (_userList[i] != null)
                                {
                                    Player = _userList[i];
                                    GSPacketIn msgHost = player.Out.SendRoomHost(_player);
                                    SendToRoomPlayer(msgHost);
                                    break;
                                }
                            }
                        }
                    }


                    if (GameState == eGameState.PAIRUP)
                    {
                        SendPairUpCancel();
                        PairUpMgr.RemovefromPairUpMgr(this);
                        GSPacketIn msg = _player.Out.SendMessage(eMessageType.ChatERROR, LanguageMgr.GetTranslation("Game.Server.SceneGames.PairUp.Failed"));
                        SendToPlayerExceptSelf(msg, _player);
                    }

                    OperateGameClass();
                    SendRoomInfo();
                    _processor.OnRemovedPlayer(this, player);


                    player.CurrentGame = null;
                }
            }

            //if (_isChangeStyle)
            //{
            //    player.UpdateStyle();
            //}
        }
Example #2
0
        public override void OnShowArk(BaseSceneGame game, GamePlayer player)
        {
            game.Data._fallItemID.Clear();

            game.GameState = eGameState.FREE;
            game.BeginTimer(TIMEOUT * 5);

            if (game.RoomType == eRoomType.PAIRUP)
            {
                PairUpMgr.PairUpGameLeave(game);
            }
        }
Example #3
0
        public override void OnRemovedPlayer(BaseSceneGame game, GamePlayer player)
        {
            base.OnRemovedPlayer(game, player);

            TankData data = game.Data;

            if (data == null)
            {
                if (game.GameState == eGameState.FREE || game.GameState == eGameState.PAIRUP || game.GameState == eGameState.OVER)
                {
                    if (game.Count == 0)
                    {
                        game.StopTimer();

                        if (game.RoomType == eRoomType.PAIRUP)
                        {
                            PairUpMgr.RemovefromPairUpMgr(game);
                        }
                        else
                        {
                            game.GameState = eGameState.FREE;
                        }
                    }
                }

                return;
            }

            if (!data.Players.ContainsKey(player))
            {
                return;
            }

            //if (game.GameState == eGameState.PLAY || game.GameState == eGameState.LOAD)
            //{
            //    int disLevel = (data.TotalLevel - data.persons[player.CurrentTeamIndex].TotalLevel) / (data.TotalPerson - game.Data.persons[player.CurrentTeamIndex].TeamPerson) - data.persons[player.CurrentTeamIndex].AveLevel;
            //    int GP = (int)(20 * (1 - data.Players[player].TotalKill * 0.1 - disLevel * 0.1) * 0.8);

            //    if (GP > 1 && player.PlayerCharacter.Grade > 10)
            //        player.SetGP(-GP);
            //}

            //data.Players[player].State = TankGameState.LOSE;
            data.Players[player].Lose();

            if (game.GameState == eGameState.LOAD && player.CurrentGameState != ePlayerGameState.FINISH)
            {
                CanStartGame(game);
            }

            if (game.GameState == eGameState.OVER)
            {
                byte index = data.GetCards();
                if (data.Players[player].IsTakeOut)
                {
                    GSPacketIn pkg = new GSPacketIn((int)ePackageType.GAME_TAKE_OUT, player.PlayerCharacter.ID);
                    pkg.WriteByte(index);
                    ThreadSafeRandom rand = new ThreadSafeRandom();
                    int gold = data.GetRandomGold(game.RoomType);
                    player.SetGold(gold, Game.Server.Statics.GoldAddType.Cards);
                    pkg.WriteByte(1);
                    pkg.WriteInt(gold);
                    player.Out.SendTCP(pkg);
                }
            }

            if (!CanStopGame(game, data) && game.GameState == eGameState.PLAY)
            {
                if (game.RoomType == eRoomType.PAIRUP)
                {
                    player.PlayerCharacter.Escape++;
                    player.PlayerCharacter.Total++;
                }

                if (player == data.CurrentIndex && game.Data.Count > 0)
                {
                    SendPlayFinish(game, player);
                }
                //else if (game.Data.Count > 0)
                //{
                //    int Count = game.Data.GetPlayFinishCount();
                //    if (Count == game.Data.Count)
                //        SendPlayFinish(game, player);
                //}
            }


            if (game.GameState == eGameState.FREE || game.GameState == eGameState.PAIRUP || game.GameState == eGameState.OVER)
            {
                data.Players.Remove(player);
            }

            if (game.GameState == eGameState.OVER && 8 - game.Data.ArkCount == game.Data.Count)
            {
                OnShowArk(game, player);
            }

            if (game.Data.Count == 0)
            {
                game.StopTimer();
                game.GameState = eGameState.FREE;
                game.Data.Players.Clear();

                if (game.RoomType == eRoomType.PAIRUP)
                {
                    PairUpMgr.RemovefromPairUpMgr(game);
                    if (game.MatchGame != null)
                    {
                        game.MatchGame.StopTimer();
                        game.MatchGame.GameState = eGameState.FREE;
                        PairUpMgr.RemovefromPairUpMgr(game.MatchGame);
                    }

                    PairUpMgr.PairUpGameLeave(game);
                }
                //else
                //{
                //    //game.Data = null;
                //}
            }
        }
Example #4
0
        public override void OnTick(BaseSceneGame game)
        {
            base.OnTick(game);

            try
            {
                if (game.GameState == eGameState.LOAD)
                {
                    GamePlayer[] keys = game.Data.Players.Keys.ToArray();
                    foreach (GamePlayer p in keys)
                    {
                        if (p.CurrentGameState == ePlayerGameState.FINISH || game.GameState != eGameState.LOAD)
                        {
                            continue;
                        }

                        game.RemovePlayer(p);
                        if (game.MatchGame != null)
                        {
                            game.MatchGame.RemovePlayer(p);
                        }
                        //p.CurrentGame.RemovePlayer(p);
                        p.Out.SendMessage(eMessageType.ALERT, LanguageMgr.GetTranslation("Game.Server.SceneGames.KickMsg1"));
                    }
                }
                else if (game.GameState == eGameState.PLAY)
                {
                    GamePlayer player = game.Data.CurrentIndex;
                    game.RemovePlayer(player);
                    if (game.MatchGame != null)
                    {
                        game.MatchGame.RemovePlayer(player);
                    }
                    player.Out.SendMessage(eMessageType.ALERT, LanguageMgr.GetTranslation("Game.Server.SceneGames.KickMsg2"));
                }
                else if (game.GameState == eGameState.OVER)
                {
                    if (game.MatchGame != null)
                    {
                        OnShowArk(game.MatchGame, null);
                    }
                    OnShowArk(game, null);
                }
                else if (game.GameState == eGameState.FREE)
                {
                    GamePlayer player = game.Player;
                    if (player != null && player.CurrentGame != null && player.CurrentGame.ID == game.ID)
                    {
                        game.RemovePlayer(player);
                        if (game.MatchGame != null)
                        {
                            game.MatchGame.RemovePlayer(player);
                        }
                        //player.Out.SendMessage(eMessageType.ALERT, LanguageMgr.GetTranslation("Game.Server.SceneGames.KickMsg3"));
                    }
                }
                else if (game.GameState == eGameState.PAIRUP)
                {
                    PairUpMgr.RemovefromPairUpMgr(game);

                    game.SendPairUpFailed();
                    GSPacketIn msg = game.Player.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Game.Server.SceneGames.PairUpTimeOut"));
                    game.SendToPlayerExceptSelf(msg, game.Player);
                }
            }
            catch (Exception e)
            {
                log.Error(string.Format("GameNumber:" + game.ID + ", OnTick is Error: {0}", e.ToString()));
            }
        }