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); } } }
//领土战赢杀人不留痕,败纸鸢线断,连胜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); }
/// <summary> /// 配对战斗 /// </summary> private static void TriggerPairCombat(List<CountryUser> mogemaUserList, List<CountryUser> hashideUserList) { int combatCount = 0; List<CountryUser> tempList = new List<CountryUser>(); if (mogemaUserList.Count > hashideUserList.Count) { combatCount = hashideUserList.Count; tempList = mogemaUserList; } else { combatCount = mogemaUserList.Count; tempList = hashideUserList; } //轮空的 for (int i = combatCount; i < tempList.Count; i++) { CountryUser cuser = tempList[i]; CountryLvGroup tempGroup; if (TryLvGroup(cuser, out tempGroup)) { tempGroup.PairCombatQueue.Add(cuser); } } for (int i = 0; i < combatCount; i++) { CountryCombatProcess process = new CountryCombatProcess(); CountryUser cuser1 = mogemaUserList[i]; int toIndex = i + 1; CountryUser cuser2 = toIndex < hashideUserList.Count ? hashideUserList[toIndex] : hashideUserList[0]; if (cuser1 == null || cuser2 == null) continue; if (cuser1.UserId.Equals(cuser2.UserId)) continue; //配对状态 _log.SaveDebugLog(string.Format("领土战[{0}]配对[{1}]战斗", cuser1.UserName, cuser2.UserName)); AsyncDoCombat(cuser1, cuser2, process); } }