Пример #1
0
 public void Add(CountryUser cuser)
 {
     lock (lockObject)
     {
         _countryQueue.Enqueue(cuser);
     }
 }
Пример #2
0
        /// <summary>
        /// 国家战
        /// </summary>
        /// <param name="cuser1">发起人</param>
        /// <param name="cuser2"></param>
        /// <returns></returns>
        public static ISingleCombat TriggerTournament(CountryUser cuser1, CountryUser cuser2)
        {
            TrumpAbilityAttack.CombatTrumpLift(cuser1.UserId); //法宝每战斗M次就扣除N点寿命
            ICombatController controller =  new TjxCombatController();
            ISingleCombat plotCombater = controller.GetSingleCombat(CombatType.Country);

            plotCombater.SetAttack(new UserEmbattleQueue(cuser1.UserId, GetMagicId(cuser1.UserId), cuser1.InspirePercent, CombatType.Country));
            plotCombater.SetDefend(new UserEmbattleQueue(cuser2.UserId, GetMagicId(cuser2.UserId), cuser2.InspirePercent, CombatType.Country));
            return plotCombater;
        }
Пример #3
0
 private static void SetUserPrize(CountryUser cuser, int obtainNum, int gameCoin)
 {
     cuser.ObtainNum += obtainNum;
     cuser.GameCoin += gameCoin;
     GameUser user = new PersonalCacheStruct<GameUser>().FindKey(cuser.UserId);
     if (user != null)
     {
         user.ObtainNum = MathUtils.Addition(user.ObtainNum, obtainNum, int.MaxValue);
         user.GameCoin = MathUtils.Addition(user.GameCoin, gameCoin, int.MaxValue);
         //user.Update();
     }
     else
     {
         _log.SaveLog(new Exception("领土战" + cuser.UserId + "获得奖励异常"));
     }
 }
Пример #4
0
        //领土战赢杀人不留痕,败纸鸢线断,连胜1奖声10,金币7000,最高连胜杀人不留痕:1,失败方奖声1,金币500

        private static void ProcessPrize(CountryUser wincuser, CountryUser failcuser, CountryCombatProcess process)
        {
            string logStr = string.Format("领土战赢{0}[连{2}],败{1}[连{3}]", wincuser.UserName, failcuser.UserName, wincuser.CurrWinNum, failcuser.CurrWinNum);
            //胜方自动加入下次战斗
            int obtainNum = 0;
            int gameCoin = 0;
            wincuser.WinCount = wincuser.WinCount + 1;
            wincuser.CurrWinNum = wincuser.CurrWinNum + 1;
            //连胜奖励:声望=M*(X+1),金币=N+X*2000
            obtainNum = ObtainNum * wincuser.CurrWinNum;
            gameCoin = PrizeGameCoin + (wincuser.CurrWinNum - 1) * 2000;
            logStr += string.Format(",连胜{2}奖声{0},金币{1}", obtainNum, gameCoin, wincuser.CurrWinNum);

            if (failcuser.CurrWinNum > 0)
            {
                //击杀连胜额外:声望=M*X,金币=N+X*1000
                obtainNum += ObtainNum * failcuser.CurrWinNum;
                gameCoin += PrizeGameCoin + failcuser.CurrWinNum * 1000;
                logStr += string.Format(",击杀连胜后声{0},金币{1}", obtainNum, gameCoin);
                //Contribution(wincuser.UserId, obtainNum); //公会贡献
            }
            if (FistCountryUser != null && wincuser.UserId.Equals(FistCountryUser.UserId))
            {
                //最高连胜额外:N+X(最高连胜次数)*2000
                gameCoin += PrizeGameCoin + (wincuser.CurrWinNum - 1) * 2000;
                logStr += string.Format(",最高连胜后金币{0}", gameCoin);
            }
            if (wincuser.CurrWinNum > wincuser.MaxWinNum)
            {
                wincuser.MaxWinNum = wincuser.CurrWinNum;
            }
            //最高连胜
            if (FistCountryUser != null && wincuser.CurrWinNum > FistCountryUser.CurrWinNum)
            {
                lock (thisLock)
                {
                    FistCountryUser = new CountryUser();
                    FistCountryUser.CurrWinNum = wincuser.CurrWinNum;
                    FistCountryUser.MaxWinNum = wincuser.MaxWinNum;
                    FistCountryUser.WinCount = wincuser.WinCount;
                    FistCountryUser.UserId = wincuser.UserId;
                    FistCountryUser.UserName = wincuser.UserName;
                    FistCountryUser.UserVipLv = wincuser.UserVipLv;
                }

                logStr += string.Format(",最高连胜{0}:{1}", FistCountryUser.UserName, FistCountryUser.CurrWinNum);
                //Trace.WriteLine(string.Format("领土战最高连胜{0}:{1}", FistCountryUser.UserName, FistCountryUser.CurrWinNum));
            }
            SetUserPrize(wincuser, obtainNum, gameCoin);
            wincuser.Status = 1;
            process.WinUserId = wincuser.UserId;
            process.WinUserName = wincuser.UserName;
            process.KillNum = wincuser.CurrWinNum;
            process.WinObtainNum = obtainNum;
            process.WinGameCoin = gameCoin;
            process.FaildKillNum = failcuser.CurrWinNum;//打败几连杀
            //获胜方公会贡献
            Contribution(wincuser.UserId, obtainNum);

            obtainNum = (int)Math.Floor((double)ObtainNum / 5);
            gameCoin = (int)Math.Floor((double)PrizeGameCoin / 10);

            logStr += string.Format(",失败方[{2}连杀]奖声{0},金币{1}", obtainNum, gameCoin, process.FaildKillNum);
            failcuser.Status = 0;
            failcuser.CurrWinNum = 0;
            failcuser.FailCount = failcuser.FailCount + 1;
            SetUserPrize(failcuser, obtainNum, gameCoin);

            process.FailUserId = failcuser.UserId;
            process.FailUserName = failcuser.UserName;
            process.FailObtainNum = obtainNum;
            process.FailGameCoin = gameCoin;
            //战败方公会贡献
            Contribution(failcuser.UserId, obtainNum);
            _log.SaveDebugLog(logStr);
            CombatHelper.EmbattlePostion(failcuser.UserId);
        }
Пример #5
0
        private static void AsyncDoCombat(CountryUser cuser1, CountryUser cuser2, CountryCombatProcess process)
        {
            CountryLvGroup userLvGroup1;
            CountryLvGroup userLvGroup2;
            if (TryLvGroup(cuser1, out userLvGroup1) && TryLvGroup(cuser2, out userLvGroup2))
            {
                ISingleCombat combater = CombatFactory.TriggerTournament(cuser1, cuser2);
                bool isWin = combater.Doing();
                if (isWin)
                {
                    ProcessPrize(cuser1, cuser2, process);
                    cuser1.Refresh = DateTime.Now;
                    cuser1.Status = 1;
                    userLvGroup1.CombaQueue.Add(cuser1);
                    CountryGroup userGroup1;
                    if (TryGroup(cuser1.GroupType, out userGroup1)) userGroup1.Score++;
                    cuser2.Refresh = DateTime.Now;
                    cuser2.Status = 1;
                    userLvGroup2.CombaQueue.Add(cuser2);

                }
                else
                {
                    ProcessPrize(cuser2, cuser1, process);
                    cuser2.Refresh = DateTime.Now;
                    cuser2.Status = 1;
                    userLvGroup2.CombaQueue.Add(cuser2);
                    CountryGroup userGroup2;
                    if (TryGroup(cuser2.GroupType, out userGroup2)) userGroup2.Score++;
                    cuser1.Refresh = DateTime.Now;
                    cuser1.Status = 1;
                    userLvGroup1.CombaQueue.Add(cuser1);

                }

                process.ProcessContainer = (CombatProcessContainer)combater.GetProcessResult();

                lock (thisLock)
                {
                    if (_combatProcessList != null) _combatProcessList.Add(process);
                    //日志
                    UserCombatLog log = new UserCombatLog();
                    log.CombatLogID = Guid.NewGuid().ToString();
                    log.UserID = cuser1.UserId;
                    log.CityID = 0;
                    log.PlotID = 0;
                    log.NpcID = 0;
                    log.CombatType = CombatType.Country;
                    log.HostileUser = cuser2.UserId;
                    log.IsWin = isWin;
                    log.CombatProcess = JsonUtils.Serialize(process);
                    log.CreateDate = DateTime.Now;
                    var sender = DataSyncManager.GetDataSender();
                    sender.Send(log);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 获得战斗过程
        /// </summary>
        /// <param name="isSelf"></param>
        /// <returns></returns>
        public List<CountryCombatProcess> GetCombatProcess(bool isSelf)
        {
            List<CountryCombatProcess> list = new List<CountryCombatProcess>();
            CountryUser countryUser = new CountryUser();
            int version = 0;
            CountryLvGroup lvGroup;
            if (TryLvGroup(out lvGroup))
            {
                if (lvGroup.UserList.ContainsKey(_countryUser.UserId))
                {
                    countryUser = lvGroup.UserList[_countryUser.UserId];
                    version = countryUser.Version;
                }
                if (isSelf && _combatProcessList != null)
                {
                    list = _combatProcessList.FindAll(
                            m => (m.WinUserId == _countryUser.UserId || m.FailUserId == _countryUser.UserId) && m.Version > version);
                }
                else if (_combatProcessList != null)
                {
                    list = _combatProcessList.FindAll(m => m.Version > version);
                }

                foreach (var process in list)
                {
                    if (process.Version > countryUser.Version)
                    {
                        countryUser.Version = process.Version;
                        //lvGroup.Update(countryUser);
                    }
                }
            }
            return list;
        }
Пример #7
0
 /// <summary>
 /// 获取玩家战斗信息
 /// </summary>
 /// <returns></returns>
 public CountryUser GetCountryUser()
 {
     CountryUser countryUser = new CountryUser();
     CountryLvGroup lvGroup;
     if (TryLvGroup(out lvGroup) && lvGroup.UserList.ContainsKey(_countryUser.UserId))
     {
         countryUser = lvGroup.UserList[_countryUser.UserId];
     }
     return countryUser;
 }
Пример #8
0
 private static bool TryLvGroup(CountryUser cuser, out CountryLvGroup lvGroup)
 {
     lvGroup = null;
     CountryGroup group;
     if (cuser != null && TryGroup(cuser.GroupType, out group))
     {
         lvGroup = cuser.IsAdvanced ? group.AdvancedGroup : group.NomarlGroup;
         return true;
     }
     return false;
 }
Пример #9
0
 public CountryCombat(GameUser user)
 {
     _countryUser = new CountryUser()
     {
         UserId = user.UserID,
         UserName = user.NickName,
         UserLv = user.UserLv,
         UserVipLv = (short)user.VipLv,
         UserExpNum = user.ExpNum,
         Refresh = DateTime.Now,
         InspirePercent = 0,
         Status = 0,
         IsAdvanced = user.UserLv >= AdvLv
     };
     if (user.GroupType != CountryType.None)
     {
         _countryUser.GroupType = user.GroupType;
     }
 }
Пример #10
0
        /// <summary>
        /// 初始化
        /// </summary>
        internal static void Init(GameActive gameActive)
        {
            //Trace.WriteLine("领土战初化");
            _gameActive = gameActive;
            isOver = false;
            FistCountryUser = new CountryUser();
            _countryGroupDict = new Dictionary<CountryType, CountryGroup>(2);
            var mogemaGroup = new CountryGroup(CountryType.M);
            var hashideGroup = new CountryGroup(CountryType.H);
            _countryGroupDict.Add(mogemaGroup.CountryType, mogemaGroup);
            _countryGroupDict.Add(hashideGroup.CountryType, hashideGroup);
            CountryCombatProcess.RestVersion();
            _combatProcessList = new List<CountryCombatProcess>();

            _combatTimer = new Timer(DoCombat, gameActive, 60000, 17 * 1000);
            //_waitCombatTimer = new Timer(DoWaitCombat, gameActive, 60000, 1 * 1000);
        }
Пример #11
0
 internal void Update(CountryUser cuser)
 {
     if (UserList.ContainsKey(cuser.UserId))
     {
         UserList[cuser.UserId] = cuser;
     }
 }
Пример #12
0
        public override bool TakeAction()
        {
            if (ContextUser.CountryID == CountryType.None)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St5201_NoJoinCountry;
                return false;
            }
            CountryCombat countryCombat = new CountryCombat(ContextUser);
            if (countryCombat.GameActive == null ||
                countryCombat.GameActive.RefreshStatus() == CombatStatus.NoStart ||
                countryCombat.GameActive.RefreshStatus() == CombatStatus.Over)
            {
                if (ContextUser.UserStatus == UserStatus.CountryCombat)
                {
                    ContextUser.UserStatus = UserStatus.Normal;
                    //ContextUser.Update();
                }
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St5201_CombatNoStart;
                return false;
            }
            //wuzf 检查战斗状态
            if (ContextUser.UserStatus != UserStatus.CountryCombat || UserHelper.IsUserEmbattle(ContextUser.UserID, ContextUser.UseMagicID))
            {
                countryCombat.Exit();
                //ErrorCode = LanguageManager.GetLang().ErrorCode;
                //ErrorInfo = LanguageManager.GetLang().St5201_NoJoinCountry;
                //return false;
            }

            if (ops == 1)
            {
                processList = countryCombat.GetCombatProcess(true);
            }
            else if (ops == 2)
            {
                processList = countryCombat.GetCombatProcess(false);
            }
            coldTime = countryCombat.GameActive.ColdTime;
            countryUser = countryCombat.GetCountryUser();
            firstUser = CountryCombat.FistCountryUser ?? new CountryUser();
            CountryGroup mogemaGroup;
            CountryGroup hashideGroup;
            if (CountryCombat.TryGroup(CountryType.M, out mogemaGroup) && CountryCombat.TryGroup(CountryType.H, out hashideGroup))
            {
                _mscoreNum = mogemaGroup.Score;
                _hscoreNum = hashideGroup.Score;
            }
            if (coldTime == 0)
            {

            }
            return true;
        }