public bool IsCombat(int plotId) { var plot = new ConfigCacheSet <PlotInfo>().FindKey(plotId); if (plot != null) { //todo var userPlot = UserPlotHelper.GetUserPlotInfo(_userId, plot.PrePlotID); //new GameDataCacheSet<UserPlot>().FindKey(_userId, plot.PrePlotID);) if (userPlot != null && userPlot.PlotStatus == PlotStatus.Completed) { //string key = _userId + plotId; //int timesNum = _userTimesList != null && _userTimesList.ContainsKey(key) ? _userTimesList[key] : 0; //return timesNum < MaxCombatNum; int timesNum = CombatHelper.GetDailyMorePlotNum(_userId, plotId); return(timesNum < MaxCombatNum); } } return(false); }
private static void SendMessage(CountryLvGroup lvGroup) { List <KeyValuePair <string, CountryUser> > cuserList = lvGroup.UserList.ToList(); var chatService = new TjxChatService(); foreach (KeyValuePair <string, CountryUser> keyPair in cuserList) { CountryUser cuser = keyPair.Value; GameUser gameUser = new PersonalCacheStruct <GameUser>().FindKey(cuser.UserId); if (gameUser != null) { gameUser.UserStatus = UserStatus.Normal; gameUser.GroupType = CountryType.None; //领土战礼包 UserItemHelper.AddUserItem(gameUser.UserID, 5013, 1); CombatHelper.EmbattlePostion(gameUser.UserID); } string content = string.Format(LanguageManager.GetLang().St5204_CombatTransfusion, cuser.WinCount, cuser.FailCount, cuser.GameCoin, cuser.ObtainNum); chatService.SystemSendWhisper(cuser.UserId, cuser.UserName, cuser.UserVipLv, content); } }
/// <summary> /// 触发战斗 /// </summary> /// <param name="user"></param> /// <param name="bossCombatProcess"></param> /// <returns></returns> public bool Combat(GameUser user, BossCombatProcess bossCombatProcess) { CombatGeneral bossGeneral = Boss; bossGeneral.LossLifeNum = 0; bool isWin = false; BossUser bossUser = GetCombatUser(user.UserID); ICombatController controller = CombatControllerFactory.Create(); ISingleCombat plotCombater = controller.GetSingleCombat(CombatType.BossPlot); double inspirePercent = bossUser.InspirePercent + bossUser.ReliveInspirePercent; plotCombater.SetAttack(new UserEmbattleQueue(user.UserID, user.UseMagicID, inspirePercent, CombatType.BossPlot)); plotCombater.SetDefend(new MonsterQueue(bossGeneral)); isWin = plotCombater.Doing(); bossCombatProcess.ProcessContainer = (CombatProcessContainer)plotCombater.GetProcessResult(); bossUser.CombatNum += 1; bossUser.DamageNum = MathUtils.Addition(bossUser.DamageNum, bossGeneral.LossLifeNum, int.MaxValue); bossCombatProcess.LiveNum = bossGeneral.LifeNum; bossCombatProcess.DamageNum = bossGeneral.LossLifeNum; bossCombatProcess.IsWin = isWin; bossCombatProcess.UserId = user.UserID; DoDamagePrize(user, bossGeneral.LossLifeNum, bossCombatProcess); if (isWin && bossGeneral.IsOver) { //GameActive active = GameActive; UserGuild guild = UserGuild; short bossprizeLv = 0; int killbossrate = 0; if (guild.BossPrize != null) { bossprizeLv = (short)guild.BossPrize.KillBossLv; killbossrate = guild.BossPrize.KillBossRate; //击杀奖 BossActivePrize bossPrize = UserGuild.BossPrize; string prizeItemMsg = string.Empty; DoTopThreePrize(0, user, bossPrize.KillReward, bossPrize.Items, out prizeItemMsg); } short lv = MathUtils.Subtraction(bossGeneral.Lv, bossprizeLv, (short)1); int killCoin = lv * killbossrate; user.GameCoin = MathUtils.Addition(user.GameCoin, killCoin, int.MaxValue); // new CacheChat().SystemSend(ChatType.World, string.Format("{0}玩家获得公会Boss战击杀奖,奖励{1}金币", user.NickName, killCoin)); new TjxChatService(user).SystemGuildSend(ChatType.Guild, string.Format(LanguageManager.GetLang().St6105_CombatKillReward, user.NickName, killCoin)); bossCombatProcess.KillGameCoin = killCoin; DoKillPrize(); int tempMinute = gameActive.Minutes - ConfigEnvSet.GetInt("BossCombat.KillTime"); int subSeconds = (int)new TimeSpan(0, tempMinute, 0).TotalSeconds; if (subSeconds - guild.ColdTime < 0) { //Boss自动升级 guild.GuildBossInfo.UpdateNotify(obj => { guild.GuildBossInfo.BossLv = MathUtils.Addition(guild.GuildBossInfo.BossLv, (short)1, short.MaxValue); return(true); }); //guild.Update(); } guild.CombatStatus = CombatStatus.Killed; CombatHelper.UpdateGuildBossKill(guild.GuildID); //公会boss已被杀 } else { bossUser.IsRelive = true; bossUser.ReliveBeginDate = DateTime.Now; } //日志 var log = new UserCombatLog { CombatLogID = Guid.NewGuid().ToString(), UserID = user.UserID, CityID = user.CityID, PlotID = gameActive == null ? 0 : gameActive.BossPlotID, NpcID = bossGeneral.GeneralID, CombatType = CombatType.BossPlot, HostileUser = string.Empty, IsWin = isWin, CombatProcess = JsonUtils.Serialize(bossCombatProcess), CreateDate = DateTime.Now }; var sender = DataSyncManager.GetDataSender(); sender.Send(log); //user.Update(); return(isWin); }
private void DoCombat(MorePlotTeam team) { //初始阵形 var plotNpcTeam = new ShareCacheStruct <PlotNPCInfo>().FindAll(m => m.PlotID == team.MorePlot.PlotID); List <MonsterQueue> monsterQueueList = new List <MonsterQueue>(plotNpcTeam.Count); var userEmbattleList = new List <UserEmbattleQueue>(team.UserList.Count); foreach (var npcInfo in plotNpcTeam) { monsterQueueList.Add(new MonsterQueue(npcInfo.PlotNpcID)); } foreach (var user in team.UserList) { var gameUser = new PersonalCacheStruct <GameUser>().FindKey(user.UserId); userEmbattleList.Add(new UserEmbattleQueue(user.UserId, gameUser.UseMagicID, 0, CombatType.MultiPlot)); } bool isLoop = true; int maxCount = 0; while (isLoop) { if (maxCount > 500) { break; } int overNum = 0; for (int i = 0; i < userEmbattleList.Count; i++) { maxCount++; int position; var userEmbattle = userEmbattleList[i]; if (userEmbattle.IsOver) { overNum++; continue; } var monster = GetMonster(monsterQueueList, i, out position); if (monster == null || monster.IsOver) { team.CombatResult = true; isLoop = false; break; } ICombatController controller = new TjxCombatController(); ISingleCombat plotCombater = controller.GetSingleCombat(CombatType.MultiPlot); plotCombater.SetAttack(userEmbattle); plotCombater.SetDefend(monster); bool IsWin = plotCombater.Doing(); var processLost = new TeamCombatProcess { TeamID = team.TeamID, PlotID = team.MorePlot.PlotID, Position = position, ProcessContainer = (CombatProcessContainer)plotCombater.GetProcessResult(), UserId = team.UserList[i].UserId, PlotNpcID = plotNpcTeam[position].PlotNpcID, IsWin = IsWin }; //new BaseLog().SaveDebuLog(string.Format("多人副本>>{4}组队{0}打{1}位置{2}结果{3}", processLost.UserId, processLost.PlotNpcID, position + 1, IsWin, team.TeamID)); AppendLog(team.TeamID, processLost); } if (overNum == userEmbattleList.Count) { team.CombatResult = false; isLoop = false; } } //奖励 if (team.CombatResult) { //new BaseLog().SaveDebuLog(string.Format("多人副本>>组队{0}结果{1}", team.TeamID, team.CombatResult)); SetCombatResult(team.TeamID, team.CombatResult); var chatService = new TjxChatService(); foreach (var user in team.UserList) { GameUser gameUser = new PersonalCacheStruct <GameUser>().FindKey(user.UserId); gameUser.ExpNum = MathUtils.Addition(gameUser.ExpNum, team.MorePlot.ExpNum, int.MaxValue); //gameUser.Update(); UserItemHelper.AddUserItem(user.UserId, team.MorePlot.ItemId, team.MorePlot.ItemNum); new BaseLog("参加多人副本获得奖励:" + team.MorePlot.ItemName); SetWinNum(user.UserId, team.MorePlot.PlotID); CombatHelper.DailyMorePlotRestrainNum(gameUser.UserID, team.MorePlot.PlotID); // 多人副本获胜加一次 chatService.SystemSendWhisper(gameUser, string.Format(LanguageManager.GetLang().St4211_MorePlotReward, team.MorePlot.ExpNum, team.MorePlot.ItemName, team.MorePlot.ItemNum)); } } }
//领土战赢杀人不留痕,败纸鸢线断,连胜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> /// <param name="user"></param> /// <param name="bossCombatProcess"></param> /// <returns></returns> public bool Combat(GameUser user, BossCombatProcess bossCombatProcess) { CombatGeneral bossGeneral = Boss; bossGeneral.LossLifeNum = 0; BossUser bossUser = GetCombatUser(user.UserID); ICombatController controller = CombatControllerFactory.Create(); ISingleCombat plotCombater = controller.GetSingleCombat(CombatType.BossPlot); double inspirePercent = bossUser.InspirePercent + bossUser.ReliveInspirePercent; plotCombater.SetAttack(new UserEmbattleQueue(user.UserID, user.UseMagicID, inspirePercent, CombatType.BossPlot)); plotCombater.SetDefend(new MonsterQueue(Boss)); bool isWin = plotCombater.Doing(); bossCombatProcess.ProcessContainer = (CombatProcessContainer)plotCombater.GetProcessResult(); bossUser.CombatNum += 1; bossUser.DamageNum = MathUtils.Addition(bossUser.DamageNum, bossGeneral.LossLifeNum, int.MaxValue); bossCombatProcess.LiveNum = bossGeneral.LifeNum; bossCombatProcess.DamageNum = bossGeneral.LossLifeNum; bossCombatProcess.IsWin = isWin; bossCombatProcess.UserId = user.UserID; DoDamagePrize(user, bossGeneral.LossLifeNum, bossCombatProcess); if (isWin && bossGeneral.IsOver) { GameActive active = GameActive; short lv = MathUtils.Subtraction(bossGeneral.Lv, (short)active.BossPrize.KillBossLv, (short)1); int killCoin = lv * active.BossPrize.KillBossRate; user.GameCoin = MathUtils.Addition(user.GameCoin, killCoin, int.MaxValue); new TjxChatService().SystemSend(ChatType.World, string.Format(LanguageManager.GetLang().St5405_CombatKillReward, user.NickName, killCoin)); TraceLog.ReleaseWriteDebug(string.Format(LanguageManager.GetLang().St5405_CombatKillReward, user.NickName, killCoin)); bossCombatProcess.KillGameCoin = killCoin; ServerEnvSet.Set(ServerEnvKey.KillBossUserID, user.UserID); DoKillPrize(user); int tempMinute = active.Minutes - ConfigEnvSet.GetInt("BossCombat.KillTime"); if (new TimeSpan(0, tempMinute, 0).TotalSeconds - active.ColdTime < 0) { //Boss自动升级 active.BossLv = MathUtils.Addition(active.BossLv, (short)1); //active.Update(); } active.CombatStatus = CombatStatus.Killed; CombatHelper.BossKillDate(); //增加boss被杀时间 } else { bossUser.IsRelive = true; bossUser.ReliveBeginDate = DateTime.Now; } //日志 var log = new UserCombatLog { CombatLogID = Guid.NewGuid().ToString(), UserID = user.UserID, CityID = user.CityID, PlotID = GameActive == null ? 0 : GameActive.BossPlotID, NpcID = bossGeneral.GeneralID, CombatType = CombatType.BossPlot, HostileUser = string.Empty, IsWin = isWin, CombatProcess = JsonUtils.Serialize(bossCombatProcess), CreateDate = DateTime.Now }; var sender = DataSyncManager.GetDataSender(); sender.Send(log); //user.Update(); return(isWin); }