public override bool CanStopGame(BaseSceneGame game, TankData data)
        {
            //if (game.GameState != eGameState.LOAD && game.GameState != eGameState.PLAY)
            //    return false;

            //List<int> leave = new List<int>();

            //foreach (KeyValuePair<GamePlayer, Player> p in data.Players)
            //{
            //    if (p.Value.Blood > 0)
            //    {
            //        if (p.Key.CurrentTeamIndex == 0)
            //            leave.Add(p.Key.CurrentTeamIndex);
            //        else if (!leave.Contains(p.Key.CurrentTeamIndex))
            //        {
            //            if (game.GameMode == eGameMode.FLAG && game.GameState != eGameState.LOAD)
            //            {
            //                if (p.Value.IsCaptain)
            //                    leave.Add(p.Key.CurrentTeamIndex);
            //            }
            //            else
            //            {
            //                leave.Add(p.Key.CurrentTeamIndex);
            //            }
            //        }
            //    }

            //    if (leave.Count > 1)
            //        return false;

            //}

            //if (leave.Count < 2)
            //{
            //    game.Stop();
            //    return true;
            //}
            return false;
        }
Beispiel #2
0
        public static void InitPairUpGame(BaseSceneGame game)
        {
            TankData baseData = new TankData();

            GamePlayer[] firstPlayers = game.GetAllPlayers();

            foreach (GamePlayer p in firstPlayers)
            {
                p.CurrentTeamIndex = 1;
                baseData.Players.Add(p, new Player(p));
            }

            GamePlayer[] secondPlayers = game.MatchGame.GetAllPlayers();

            foreach (GamePlayer p in secondPlayers)
            {
                p.CurrentTeamIndex = 2;
                baseData.Players.Add(p, new Player(p));
            }

            if(game.GameClass == eGameClass.CONSORTIA)
            {
                baseData.ConsortiaID1 = game.ConsortiaID;
                baseData.ConsortiaID2 = game.MatchGame.ConsortiaID;
            }

            baseData.StartedGameClass = (int)game.GameClass;

            game.Data = baseData;

            game.MatchGame.Data = baseData;
        }
Beispiel #3
0
 public virtual bool CanStopGame(BaseSceneGame game, TankData data)
 {
     return(false);
 }
Beispiel #4
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;
                //}
            }
        }
Beispiel #5
0
        public override void OnStopping(BaseSceneGame game, Game.Base.Packets.GSPacketIn pkg)
        {
            base.OnStopping(game, pkg);
            game.BeginTimer(TIMEOUT / 2);

            TankData data = game.Data;

            pkg.WriteByte((byte)data.Players.Count);

            int winTeam  = -1;
            int lastTeam = -1;

            data.killFlag = false;

            foreach (KeyValuePair <GamePlayer, Player> p in data.Players)
            {
                //if(p.Value.TotalHurt > 0)
                //{
                //    data.killFlag = true;
                //}

                if (winTeam == -1 && p.Value.Blood > 0)
                {
                    if (game.GameMode == eGameMode.FLAG)
                    {
                        if (p.Value.IsCaptain)
                        {
                            winTeam = p.Key.CurrentTeamIndex;
                            break;
                        }
                        else
                        {
                            lastTeam = p.Key.CurrentTeamIndex;
                        }
                    }
                    else
                    {
                        winTeam = p.Key.CurrentTeamIndex;
                        break;
                    }
                }
            }

            //if (!data.killFlag)
            //{
            //    game.BeginTimer(3000);
            //}

            if (winTeam == -1 && game.Data.CurrentIndex == null)
            {
                winTeam = lastTeam;
            }

            if (winTeam == -1)
            {
                if (game.Data.CurrentFire != null)
                {
                    winTeam = game.Data.CurrentFire.CurrentTeamIndex;
                }
                else
                {
                    winTeam = data.LastDead;
                }
            }

            int GP;

            //E等级差=(对方平均等级+5)-玩家等级;取值区间(1~9);
            //            P赢=4*[(对方平均等级+5)-玩家等级]+伤害的血量*0.2%+击杀数*2+(命中次数/玩家总的回合次数)*8;
            //P输=1*[(对方平均等级+5)-玩家等级]+伤害的血量*0.2%+击杀数*2+(命中次数/玩家总的回合次数)*8


            //            P赢=[2+伤害的血量*0.1%+击杀数*0.5+(命中次数/玩家总的回合次数)*2]*[(对方平均等级+10)-玩家等级]
            //P输=[伤害的血量*0.1%+击杀数*0.5+(命中次数/玩家总的回合次数)*2]*[(对方平均等级+10)-玩家等级];

//            P赢=[2+伤害的血量*0.1%+击杀数*0.5+(命中次数/玩家总的回合次数)*2]*对方平均等级*[1+(总击杀数-1)*33%]
//P输=[伤害的血量*0.1%+击杀数*0.5+(命中次数/玩家总的回合次数)*2]*对方平均等级*[1+(总击杀数-1)*33%]

            //P赢=[2+伤害的血量*0.1%+击杀数*0.5+(命中次数/玩家总的回合次数)*2]*对方平均等级*[0.9+(游戏开始时对方玩家人数-1)*30%]
            //P输=[伤害的血量*0.1%+击杀数*0.5+(命中次数/玩家总的回合次数)*2]*对方平均等级*[0.9+(游戏开始时对方玩家人数-1)*30%]


            //bool flag = data.GameStart.AddMinutes(1).CompareTo(DateTime.Now) > 0;
            string     winStr     = LanguageMgr.GetTranslation("Game.Server.SceneGames.OnStopping.Msg5");
            GamePlayer winPlayer  = null;
            string     loseStr    = LanguageMgr.GetTranslation("Game.Server.SceneGames.OnStopping.Msg5");
            GamePlayer losePlayer = null;

            foreach (KeyValuePair <GamePlayer, Player> p in data.Players)
            {
                if (game.RoomType == 0)
                {
                    p.Key.PlayerCharacter.CheckCount++;
                }
                else
                {
                    p.Key.PlayerCharacter.CheckCount += 2;
                }
                p.Key.Out.SendCheckCode();

                if (p.Value.TotalHurt > 0)
                {
                    data.killFlag = true;
                }

                if (game.GameClass == eGameClass.CONSORTIA)
                {
                    if (p.Key.CurrentTeamIndex == winTeam)
                    {
                        winStr   += " [" + p.Key.PlayerCharacter.NickName + "] ";
                        winPlayer = p.Key;
                    }
                    else
                    {
                        loseStr   += " [" + p.Key.PlayerCharacter.NickName + "] ";
                        losePlayer = p.Key;
                    }
                }
            }

            int riches = 0;

            if (game.GameClass == eGameClass.CONSORTIA)
            {
                winStr  += LanguageMgr.GetTranslation("Game.Server.SceneGames.OnStopping.Msg1") + losePlayer.PlayerCharacter.ConsortiaName + LanguageMgr.GetTranslation("Game.Server.SceneGames.OnStopping.Msg2");
                loseStr += LanguageMgr.GetTranslation("Game.Server.SceneGames.OnStopping.Msg3") + winPlayer.PlayerCharacter.ConsortiaName + LanguageMgr.GetTranslation("Game.Server.SceneGames.OnStopping.Msg4");
                riches   = ConsortiaMgr.ConsortiaFight(winPlayer.CurrentTeamIndex == 1 ? data.ConsortiaID1 : data.ConsortiaID2,
                                                       winPlayer.CurrentTeamIndex == 1 ? data.ConsortiaID2 : data.ConsortiaID1, game.Data.Players, game.RoomType, game.GameClass, data.persons[winPlayer.CurrentTeamIndex].TotalKillHealth);
                GameServer.Instance.LoginServer.SendConsortiaFight(winPlayer.PlayerCharacter.ConsortiaID, riches, winStr);
                //GameServer.Instance.LoginServer.SendConsortiaFight(losePlayer.PlayerCharacter.ConsortiaID, -riches, loseStr);
            }

            foreach (KeyValuePair <GamePlayer, Player> p in data.Players)
            {
                GP = 1;
                if (p.Value.State != TankGameState.LOSE)
                {
                    if (game.RoomType == eRoomType.PAIRUP)
                    {
                        p.Key.PlayerCharacter.Total++;
                    }

                    double level    = (data.TotalLevel - data.persons[p.Key.CurrentTeamIndex].TotalLevel) / (data.TotalPerson - data.persons[p.Key.CurrentTeamIndex].TeamPerson);
                    double disLevel = level + 10 - p.Key.PlayerCharacter.Grade;

                    if (p.Key.CurrentTeamIndex == winTeam)
                    {
                        if (game.RoomType == eRoomType.PAIRUP)
                        {
                            p.Key.PlayerCharacter.Win++;
                        }

                        //GP = (int)Math.Ceiling((((data.killFlag ? 2 : 0) + (double)p.Value.TotalHurt * 0.001 + p.Value.TotalKill * 0.5 + (p.Value.HitNum / (p.Value.BoutNum == 0 ? 1 : p.Value.BoutNum)) * 2) * level * (1 + (data.persons[p.Key.CurrentTeamIndex].TatolKill - 1) * 0.33)));
                        GP = (int)Math.Ceiling((((data.killFlag ? 2 : 0) + (double)p.Value.TotalHurt * 0.001 + p.Value.TotalKill * 0.5 + (p.Value.HitNum / (p.Value.BoutNum == 0 ? 1 : p.Value.BoutNum)) * 2) * level * (0.9 + (data.persons[p.Key.CurrentTeamIndex].TeamPerson - 1) * 0.3)));
                    }
                    else
                    {
                        GP = (int)Math.Ceiling(((double)p.Value.TotalHurt * 0.001 + p.Value.TotalKill * 0.5 + (p.Value.HitNum / (p.Value.BoutNum == 0 ? 1 : p.Value.BoutNum)) * 2) * level * (0.9 + (data.persons[p.Key.CurrentTeamIndex].TeamPerson - 1) * 0.3));
                    }

                    bool isMarried = false;
                    if (p.Key.PlayerCharacter.IsMarried)
                    {
                        foreach (GamePlayer q in data.Players.Keys)
                        {
                            if (q.PlayerCharacter.ID != p.Key.PlayerCharacter.ID)
                            {
                                if (q.CurrentTeamIndex == p.Key.CurrentTeamIndex && p.Key.PlayerCharacter.SpouseID == q.PlayerCharacter.ID)
                                {
                                    GP        = (int)(GP * 1.2);
                                    isMarried = true;
                                }
                            }
                        }
                    }

                    p.Key.QuestInventory.CheckWin(data.MapIndex, (int)game.GameMode, game.ScanTime, p.Value.IsCaptain,
                                                  data.persons[p.Key.CurrentTeamIndex].TeamPerson, data.TotalPerson - data.persons[p.Key.CurrentTeamIndex].TeamPerson, p.Key.CurrentTeamIndex == winTeam, game.GameClass == eGameClass.CONSORTIA, (int)game.RoomType, isMarried);


                    double AAS = AntiAddictionMgr.GetAntiAddictionCoefficient(p.Key.PlayerCharacter.AntiAddiction);
                    GP = (int)(GP * AAS);

                    GP  = (int)(GP * RateMgr.GetRate(eRateType.Experience_Rate));
                    GP *= p.Key.BuffInventory.GPMultiple();

                    if (game.RoomType != eRoomType.PAIRUP && (disLevel <= 0 || disLevel >= 20))
                    {
                        GP = 1;
                    }

                    if (AAS < 10E-6)
                    {
                        GP = 0;
                    }
                    else
                    {
                        if (GP < 1)
                        {
                            GP = 1;
                        }
                    }

                    p.Key.SetGP(GP);

                    Dictionary <int, int> requestItems = p.Key.QuestInventory.GetRequestItems();
                    List <MapGoodsInfo>   questItems   = Managers.MapMgr.GetQuestGoodsAll(data.MapIndex);
                    foreach (MapGoodsInfo questID in questItems)
                    {
                        if (requestItems.ContainsKey(questID.GoodsID) && requestItems[questID.GoodsID] > 0)
                        {
                            int total = random.Next(questID.Value + 1);
                            if (p.Key.CurrentTeamIndex != winTeam)
                            {
                                total = total / 2;
                            }
                            else if (total < 1)
                            {
                                total = 1;
                            }
                            if (total < 1)
                            {
                                continue;
                            }

                            int count             = requestItems[questID.GoodsID] > total ? total : requestItems[questID.GoodsID];
                            ItemTemplateInfo temp = Bussiness.Managers.ItemMgr.GetSingleGoods(questID.GoodsID);
                            p.Key.TempInventory.AddItemTemplate(temp, questID, count);
                            requestItems[questID.GoodsID] -= count;
                        }
                    }
                }

                //p.Value.IsTakeOut = true;
                pkg.WriteInt(p.Key.PlayerCharacter.ID);
                pkg.WriteBoolean(winTeam == p.Key.CurrentTeamIndex);
                pkg.WriteInt(p.Key.PlayerCharacter.Grade);
                pkg.WriteInt(p.Key.PlayerCharacter.GP);
                pkg.WriteInt((int)p.Value.TotalKill);
                pkg.WriteInt(p.Value.TotalHurt);
                pkg.WriteInt(GP);
                pkg.WriteInt((int)p.Value.HitNum);
                pkg.WriteInt((int)p.Value.BoutNum);
                pkg.WriteInt(p.Value.Offer);

                if (data.persons[p.Key.CurrentTeamIndex].TotalKillHealth > 0)
                {
                    p.Value.IsTakeOut = true;
                    if (p.Key.CurrentGame != null)
                    {
                        p.Key.CurrentGame.IsTakeOut = true;
                    }
                }
                pkg.WriteBoolean(p.Value.IsTakeOut);
            }

            pkg.WriteInt(riches);
            //pkg.WriteBoolean(data.killFlag);
            pkg.WriteInt(data.TotalPerson / 2);

            data.InsertGameInfo(game, winTeam);

            GamePlayer[] list = data.Players.Keys.ToArray();
            foreach (GamePlayer p in list)
            {
                if (data.Players[p].State == TankGameState.LOSE)
                {
                    data.Players.Remove(p);
                }
                else
                {
                    //data.Players[p].Reset();
                    //p.PropInventory.Clear();
                    //if (!killFlag)
                    //{
                    //    if (p.CurrentGame.GameState != eGameState.FREE)
                    //    {
                    //        p.CurrentGame.ShowArk(p.CurrentGame, p);
                    //    }
                    //}
                }
            }
        }
 public virtual bool CanStopGame(BaseSceneGame game, TankData data)
 {
     return false;
 }