diff --git a/OshimaModules/Skills/MagicalGirl/绝对领域.cs b/OshimaModules/Skills/MagicalGirl/绝对领域.cs index a8d52df..c3f1269 100644 --- a/OshimaModules/Skills/MagicalGirl/绝对领域.cs +++ b/OshimaModules/Skills/MagicalGirl/绝对领域.cs @@ -58,6 +58,16 @@ namespace Oshima.FunGame.OshimaModules.Skills return 0; } + public override bool BeforeApplyTrueDamage(Character character, Character enemy, double damage, bool isNormalAttack, DamageResult damageResult) + { + if (enemy == Skill.Character && (damageResult == DamageResult.Normal || damageResult == DamageResult.Critical)) + { + WriteLine($"[ {enemy} ] 发动了绝对领域,巧妙的化解了此伤害!"); + return true; + } + return false; + } + public override void OnSkillCasting(Character caster, List targets) { 释放时的能量值 = caster.EP; diff --git a/OshimaServers/Service/FunGameConstant.cs b/OshimaServers/Service/FunGameConstant.cs index 4720a8d..3a56b5e 100644 --- a/OshimaServers/Service/FunGameConstant.cs +++ b/OshimaServers/Service/FunGameConstant.cs @@ -302,10 +302,10 @@ namespace Oshima.FunGame.OshimaServers.Service public static Dictionary ExploreResultProbabilities { get; } = new() { - { ExploreResult.General, 0.4 }, + { ExploreResult.General, 0.45 }, { ExploreResult.Nothing, 0.2 }, - { ExploreResult.Fight, 0.2 }, - { ExploreResult.Earned, 0.2 }, + { ExploreResult.Fight, 0.25 }, + { ExploreResult.Earned, 0.1 }, { ExploreResult.Event, 0 } }; diff --git a/OshimaServers/Service/FunGameService.cs b/OshimaServers/Service/FunGameService.cs index 4eb22a6..df1ec47 100644 --- a/OshimaServers/Service/FunGameService.cs +++ b/OshimaServers/Service/FunGameService.cs @@ -1416,7 +1416,7 @@ namespace Oshima.FunGame.OshimaServers.Service } private static void EnhanceBoss(Character boss, Item[] weapons, Item[] armors, Item[] shoes, Item[] accessory, Item[] consumables, - int cLevel, int sLevel, int mLevel, int naLevel, bool enhanceHPMP = true, bool enhanceCRCRD = true) + int cLevel, int sLevel, int mLevel, int naLevel, bool enhanceHPMP = true, bool enhanceCRCRD = true, bool isUnit = false) { boss.Level = cLevel; boss.NormalAttack.Level = naLevel; @@ -1477,8 +1477,9 @@ namespace Oshima.FunGame.OshimaServers.Service double exMP2 = 0.8; if (!enhanceHPMP) { - exHP2 = 0; - exMP2 = 0; + if (isUnit) exHP2 = -0.1; + else exHP2 = 0.5; + exMP2 = 0.2; } double exCR = 0.35; double exCRD = 0.9; @@ -1494,16 +1495,16 @@ namespace Oshima.FunGame.OshimaServers.Service "values", new Dictionary() { - { "exatk", 3.4 * cLevel }, - { "exdef", 3.4 * cLevel }, + { "exatk", isUnit ? 1.4 * cLevel : 3.4 * cLevel }, + { "exdef", isUnit ? 1.4 * cLevel : 3.4 * cLevel }, { "exhp2", exHP2 }, { "exmp2", exMP2 }, { "exhr", 0.15 * cLevel }, { "exmr", 0.1 * cLevel }, { "excr", exCR }, { "excrd", exCRD }, - { "excdr", 0.25 }, - { "exacc", 0.25 } + { "excdr", isUnit ? 0.2 : 0.25 }, + { "exacc", isUnit ? 0.15 : 0.25 } } } }); @@ -1570,7 +1571,7 @@ namespace Oshima.FunGame.OshimaServers.Service return roundRewards; } - public static double CalculateRating(CharacterStatistics stats, Team? team = null) + public static double CalculateRating(CharacterStatistics stats, Team? team = null, CharacterStatistics[]? teammateStats = null) { // 基础得分 double baseScore = (stats.Kills + stats.Assists) / (stats.Kills + stats.Assists + stats.Deaths + 0.01); @@ -1586,6 +1587,17 @@ namespace Oshima.FunGame.OshimaServers.Service // 伤害贡献 double logDamageContribution = Math.Log(1 + (stats.TotalDamage / (stats.TotalTakenDamage + 1.75))); + if (team != null && teammateStats != null) + { + // 考虑团队伤害排名,优先高伤害的 + int damageRank = teammateStats.OrderByDescending(s => s.TotalDamage).ToList().IndexOf(stats) + 1; + if (damageRank > 1) + { + double d = 1 - (0.1 * (damageRank - 1)); + if (d < 0.1) d = 0.1; + logDamageContribution *= d; + } + } // 存活时间贡献 double liveTimeContribution = Math.Log(1 + (stats.LiveTime / (stats.TotalTakenDamage + 0.01) * 100)); @@ -1594,6 +1606,7 @@ namespace Oshima.FunGame.OshimaServers.Service double teamContribution = 0; if (team != null) { + if (stats.Assists > team.Score) stats.Assists = team.Score; teamContribution = (stats.Kills + stats.Assists) / (team.Score + 0.01); if (team.IsWinner) { @@ -1618,11 +1631,16 @@ namespace Oshima.FunGame.OshimaServers.Service foreach (Character character in statistics.Keys) { Team? team = null; + CharacterStatistics[]? teammateStats = null; if (isTeam) { team = teams.Where(t => t.IsOnThisTeam(character)).FirstOrDefault(); + if (team != null) + { + teammateStats = [.. statistics.Where(kv => team.Members.Contains(kv.Key)).Select(kv => kv.Value)]; + } } - statistics[character].Rating = CalculateRating(statistics[character], team); + statistics[character].Rating = CalculateRating(statistics[character], team, teammateStats); } } @@ -1848,9 +1866,11 @@ namespace Oshima.FunGame.OshimaServers.Service (min, max) = (range.Min, range.Max); } double price = Random.Shared.Next(min, max); + int stock = Random.Shared.Next(1, 3); if (item.ItemType == ItemType.MagicCard) { price *= 0.7; + stock = 1; } else if (item.ItemType == ItemType.Consumable) { @@ -1859,13 +1879,14 @@ namespace Oshima.FunGame.OshimaServers.Service min = 300 * (1 + (prev * prev - prev)); max = 300 * (1 + (current * current - current)); price = Random.Shared.Next(min, max); + stock += 3; } if (price == 0) { price = (Random.Shared.NextDouble() + 0.1) * Random.Shared.Next(1000, 5000) * Random.Shared.Next((int)item.QualityType + 2, 6 + ((int)item.QualityType)); } item.Price = (int)price; - daily.AddItem(item, Random.Shared.Next(1, 3)); + daily.AddItem(item, stock); } store.Add("daily", daily); return daily.ToString() + "\r\n温馨提示:使用【商店查看+序号】查看物品详细信息,使用【商店购买+序号】购买物品!每天 4:00 刷新每日商店。"; @@ -2100,9 +2121,8 @@ namespace Oshima.FunGame.OshimaServers.Service public static string GetEvents(ActivityState status = ActivityState.InProgress) { - EntityModuleConfig activities = new("activities", "activities"); - activities.LoadConfig(); - IEnumerable filteredActivities = activities.Values.Where(a => a.Status == status); + GetEventCenter(); + IEnumerable filteredActivities = Activities.Where(a => a.Status == status); if (!filteredActivities.Any()) { return $"当前没有任何{CommonSet.GetActivityStatus(status)}的活动,敬请期待。"; @@ -2114,9 +2134,8 @@ namespace Oshima.FunGame.OshimaServers.Service public static string GetEvent(long id) { - EntityModuleConfig activities = new("activities", "activities"); - activities.LoadConfig(); - if (activities.Values.FirstOrDefault(a => a.Id == id) is Activity activity) + GetEventCenter(); + if (Activities.FirstOrDefault(a => a.Id == id) is Activity activity) { return $"{activity}"; } @@ -2189,27 +2208,25 @@ namespace Oshima.FunGame.OshimaServers.Service switch (diff) { case 2: - probabilities[ExploreResult.General] -= 0.05; - probabilities[ExploreResult.Earned] -= 0.05; + probabilities[ExploreResult.General] -= 0.1; probabilities[ExploreResult.Fight] += 0.1; break; case 3: - probabilities[ExploreResult.General] -= 0.1; + probabilities[ExploreResult.General] -= 0.15; probabilities[ExploreResult.Earned] -= 0.05; - probabilities[ExploreResult.Nothing] -= 0.05; - probabilities[ExploreResult.Fight] += 0.2; + probabilities[ExploreResult.Nothing] += 0.05; + probabilities[ExploreResult.Fight] += 0.15; break; case 4: - probabilities[ExploreResult.General] -= 0.2; - probabilities[ExploreResult.Earned] -= 0.1; - probabilities[ExploreResult.Nothing] -= 0.05; + probabilities[ExploreResult.General] -= 0.3; + probabilities[ExploreResult.Earned] -= 0.05; probabilities[ExploreResult.Fight] += 0.35; break; case 5: - probabilities[ExploreResult.General] -= 0.3; - probabilities[ExploreResult.Earned] -= 0.15; + probabilities[ExploreResult.General] -= 0.35; + probabilities[ExploreResult.Earned] -= 0.05; probabilities[ExploreResult.Nothing] -= 0.05; - probabilities[ExploreResult.Fight] += 0.5; + probabilities[ExploreResult.Fight] += 0.45; break; default: break; @@ -2247,10 +2264,10 @@ namespace Oshima.FunGame.OshimaServers.Service // 筛选敌人 List enemys = []; Character enemy; + bool isUnit = Random.Shared.Next(2) != 0; if (region.Characters.Count > 0 && region.Units.Count > 0) { - random = Random.Shared.Next(2); - if (random == 0) + if (!isUnit) { enemy = region.Characters.OrderBy(o => Random.Shared.Next()).First().Copy(); enemy.ExHPPercentage += 0.5; @@ -2262,34 +2279,77 @@ namespace Oshima.FunGame.OshimaServers.Service { case 1: case 2: - enemy = region.Units.OrderBy(o => Random.Shared.Next()).First(); - enemys.Add(enemy.Copy()); + enemy = region.Units.OrderBy(o => Random.Shared.Next()).First().Copy(); + enemys.Add(enemy); break; case 3: case 4: - enemy = region.Units.OrderBy(o => Random.Shared.Next()).First(); - enemys.Add(enemy.Copy()); - enemy = region.Units.OrderBy(o => Random.Shared.Next()).First(); - enemys.Add(enemy.Copy()); + enemy = region.Units.OrderBy(o => Random.Shared.Next()).First().Copy(); + enemys.Add(enemy); + enemy = region.Units.OrderBy(o => Random.Shared.Next()).First().Copy(); + enemy.FirstName = enemys.Any(e => e.Name == enemy.Name) ? "2" : ""; + enemys.Add(enemy); break; case 5: default: - enemy = region.Units.OrderBy(o => Random.Shared.Next()).First(); - enemys.Add(enemy.Copy()); - enemy = region.Units.OrderBy(o => Random.Shared.Next()).First(); - enemys.Add(enemy.Copy()); - enemy = region.Units.OrderBy(o => Random.Shared.Next()).First(); - enemys.Add(enemy.Copy()); + enemy = region.Units.OrderBy(o => Random.Shared.Next()).First().Copy(); + enemys.Add(enemy); + enemy = region.Units.OrderBy(o => Random.Shared.Next()).First().Copy(); + enemy.FirstName = enemys.Any(e => e.Name == enemy.Name) ? "α" : ""; + enemys.Add(enemy); + enemy = region.Units.OrderBy(o => Random.Shared.Next()).First().Copy(); + enemy.FirstName = enemys.Any(e => e.Name == enemy.Name) ? "β" : ""; + enemys.Add(enemy); break; } } } else { - enemy = new RegionCharacter(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); - enemys.Add(enemy); + if (!isUnit) + { + enemy = new RegionCharacter(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); + enemys.Add(enemy); + } + else + { + switch (diff) + { + case 1: + case 2: + enemy = new RegionUnit(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); + enemys.Add(enemy); + break; + case 3: + case 4: + enemy = new RegionUnit(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); + enemys.Add(enemy); + enemy = new RegionUnit(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); + enemys.Add(enemy); + break; + case 5: + default: + enemy = new RegionUnit(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); + enemys.Add(enemy); + enemy = new RegionUnit(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); + enemys.Add(enemy); + enemy = new RegionUnit(long.Parse(Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)), GenerateRandomChineseUserName()); + enemys.Add(enemy); + break; + } + } } + // 初始化掉落装备的概率 + Dictionary pE = new() + { + { QualityType.Blue, 0.4 }, + { QualityType.Purple, 0.27 + (0.01 * (characterCount - 1)) }, + { QualityType.Orange, 0.2 + (0.01 * (characterCount - 1)) }, + { QualityType.Red, 0.1 + (0.0075 * (characterCount - 1)) }, + { QualityType.Gold, 0.03 + (0.0075 * (characterCount - 1)) } + }; + // 生成奖励 string award = ""; switch (model.Result) @@ -2338,7 +2398,7 @@ namespace Oshima.FunGame.OshimaServers.Service break; case ExploreResult.Fight: // 小队信息 - Character[] squad = [.. user.Inventory.Characters.Where((c, index) => characterIds.Contains(index + 1)).Select(c => CharacterBuilder.Build(c, false, true, user.Inventory, FunGameConstant.AllItems, FunGameConstant.AllSkills, false))]; + Character[] squad = [.. user.Inventory.Characters.Where((c, index) => characterIds.Contains(index + 1)).Select(c => CharacterBuilder.Build(c, true, true, user.Inventory, FunGameConstant.AllItems, FunGameConstant.AllSkills, false))]; if (squad.All(c => c.HP <= 0)) { model.Result = ExploreResult.Nothing; @@ -2365,7 +2425,7 @@ namespace Oshima.FunGame.OshimaServers.Service int naLevel = mLevel; foreach (Character enemy_loop in enemys) { - EnhanceBoss(enemy_loop, weapons, armors, shoes, accessory, consumables, cLevel, sLevel, mLevel, naLevel, false, false); + EnhanceBoss(enemy_loop, weapons, armors, shoes, accessory, consumables, cLevel, sLevel, mLevel, naLevel, false, false, isUnit); } // 开始战斗 Team team1 = new($"{user.Username}的探索小队", squad); @@ -2407,7 +2467,16 @@ namespace Oshima.FunGame.OshimaServers.Service $"{materials} {General.GameplayEquilibriumConstant.InGameMaterial}," + $"以及 {count} 个{item.Name}"; if (Random.Shared.NextDouble() > 0.6) { - Item? itemDrop = region.Items.OrderBy(o => Random.Shared.Next()).FirstOrDefault(); + QualityType qualityType = QualityType.Blue; + foreach (QualityType type in pE.Keys.OrderByDescending(q => (int)q)) + { + if (Random.Shared.NextDouble() <= pE[type]) + { + qualityType = type; + break; + } + } + Item? itemDrop = region.Items.Where(i => qualityType == QualityType.Blue ? (int)i.QualityType <= (int)qualityType : (int)i.QualityType == (int)qualityType).FirstOrDefault(); if (itemDrop != null) { string itemquality = ItemSet.GetQualityTypeName(itemDrop.QualityType); @@ -2420,16 +2489,34 @@ namespace Oshima.FunGame.OshimaServers.Service } else { - Item item = FunGameConstant.ExploreItems[region][Random.Shared.Next(FunGameConstant.ExploreItems[region].Count)]; - model.Awards[item.Name] = characterCount; - award = $"{characterCount} 个{item.Name}"; - exploreString = $"{exploreString}\r\n{string.Join("\r\n", msgs)}\r\n探索小队未能战胜{enemy.Name},但是获得了补偿:{award}!"; + exploreString = $"{exploreString}\r\n{string.Join("\r\n", msgs)}\r\n探索小队未能战胜{enemy.Name},"; + IEnumerable deadEnemys = enemys.Where(c => c.HP <= 0); + if (!deadEnemys.Any()) + { + exploreString += "探索宣告失败!(什么也没有获得)"; + } + else + { + Item item = FunGameConstant.ExploreItems[region][Random.Shared.Next(FunGameConstant.ExploreItems[region].Count)]; + model.Awards[item.Name] = deadEnemys.Count(); + award = $"{deadEnemys.Count()} 个{item.Name}"; + exploreString += $"但是获得了补偿:{award}!"; + } } model.AfterFightHPs = [.. squad.Select(c => c.HP)]; } break; case ExploreResult.Earned: - Item? itemEarned = region.Items.OrderBy(o => Random.Shared.Next()).FirstOrDefault(); + QualityType quality = QualityType.Blue; + foreach (QualityType type in pE.Keys.OrderByDescending(q => (int)q)) + { + if (Random.Shared.NextDouble() <= pE[type]) + { + quality = type; + break; + } + } + Item? itemEarned = region.Items.OrderBy(i => quality == QualityType.Blue ? (int)i.QualityType <= (int)quality : (int)i.QualityType == (int)quality).FirstOrDefault(); if (itemEarned is null) { model.Result = ExploreResult.Nothing; @@ -2520,13 +2607,13 @@ namespace Oshima.FunGame.OshimaServers.Service return result; } - public static bool SettleExploreAll(List list, User user) + public static bool SettleExploreAll(List list, User user, bool skip = false) { bool settle = false; List remove = []; foreach (ExploreModel model in list) { - if (model.StartTime.HasValue && (DateTime.Now - model.StartTime.Value).TotalMinutes > FunGameConstant.ExploreTime + 2) + if (skip || (model.StartTime.HasValue && (DateTime.Now - model.StartTime.Value).TotalMinutes > FunGameConstant.ExploreTime + 2)) { if (SettleExplore(model.Guid, list, user, out string msg)) { diff --git a/OshimaWebAPI/Controllers/FunGameController.cs b/OshimaWebAPI/Controllers/FunGameController.cs index ad39f28..f1faa30 100644 --- a/OshimaWebAPI/Controllers/FunGameController.cs +++ b/OshimaWebAPI/Controllers/FunGameController.cs @@ -25,6 +25,7 @@ namespace Oshima.FunGame.WebAPI.Controllers { private ILogger Logger { get; set; } = logger; + private readonly SemaphoreSlim _semaphore = new(1, 1); private const int drawCardReduce = 1000; private const int drawCardReduce_Material = 5; private const string noSaved = "你还没有创建存档!请发送【创建存档】创建。"; @@ -5249,140 +5250,150 @@ namespace Oshima.FunGame.WebAPI.Controllers public async Task<(string, Guid)> ExploreRegion([FromQuery] long? uid = null, [FromQuery] long? id = null, [FromBody] long[]? cids = null) { Guid exploreId = Guid.Empty; - long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); - long regionid = id ?? 0; - long[] characterIds = cids ?? []; - int characterCount = characterIds.Length; - - PluginConfig pc = new("saved", userid.ToString()); - pc.LoadConfig(); - - string msg = ""; - if (pc.Count > 0) + await _semaphore.WaitAsync(); + try { - User user = FunGameService.GetUser(pc); + long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + long regionid = id ?? 0; + long[] characterIds = cids ?? []; + int characterCount = characterIds.Length; - // 检查角色存在 - List invalid = []; - foreach (long cid in characterIds) - { - if (cid > 0 && cid <= user.Inventory.Characters.Count) - { - // do nothing - } - else - { - invalid.Add(cid); - } - } - if (invalid.Count > 0) - { - msg = $"没有找到与输入序号相对应的角色:{string.Join(",", invalid)}。"; - } + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); - // 检查探索许可 - int exploreTimes = 0; - int reduce = 1; - if (regionid > 0 && regionid <= FunGameConstant.Regions.Count && FunGameConstant.Regions.FirstOrDefault(r => r.Id == regionid) is OshimaRegion region) + string msg = ""; + if (pc.Count > 0) { - int diff = region.Difficulty switch + User user = FunGameService.GetUser(pc); + + // 检查角色存在 + List invalid = []; + foreach (long cid in characterIds) { - RarityType.OneStar => 1, - RarityType.TwoStar => 2, - RarityType.ThreeStar => 3, - RarityType.FourStar => 4, - _ => 5 - }; - reduce = characterCount * diff; - if (pc.TryGetValue("exploreTimes", out object? value) && int.TryParse(value.ToString(), out exploreTimes)) - { - if (exploreTimes <= 0) + if (cid > 0 && cid <= user.Inventory.Characters.Count) { - exploreTimes = 0; - msg = $"今日的探索许可已用完,无法再继续探索。"; + // do nothing } - else if (reduce > exploreTimes) + else { - msg = $"本次探索需要消耗 {reduce} 个探索许可,超过了你的剩余探索许可数量({exploreTimes} 个),请减少选择的角色数量或更换探索地区。" + - $"\r\n需要注意:探索难度星级一比一兑换探索许可,并且参与探索的角色,都需要消耗相同数量的探索许可。"; + invalid.Add(cid); + } + } + if (invalid.Count > 0) + { + msg = $"没有找到与输入序号相对应的角色:{string.Join(",", invalid)}。"; + } + + // 检查探索许可 + int exploreTimes = 0; + int reduce = 1; + if (regionid > 0 && regionid <= FunGameConstant.Regions.Count && FunGameConstant.Regions.FirstOrDefault(r => r.Id == regionid) is OshimaRegion region) + { + int diff = region.Difficulty switch + { + RarityType.OneStar => 1, + RarityType.TwoStar => 2, + RarityType.ThreeStar => 3, + RarityType.FourStar => 4, + _ => 5 + }; + reduce = characterCount * diff; + if (pc.TryGetValue("exploreTimes", out object? value) && int.TryParse(value.ToString(), out exploreTimes)) + { + if (exploreTimes <= 0) + { + exploreTimes = 0; + msg = $"今日的探索许可已用完,无法再继续探索。"; + } + else if (reduce > exploreTimes) + { + msg = $"本次探索需要消耗 {reduce} 个探索许可,超过了你的剩余探索许可数量({exploreTimes} 个),请减少选择的角色数量或更换探索地区。" + + $"\r\n需要注意:探索难度星级一比一兑换探索许可,并且参与探索的角色,都需要消耗相同数量的探索许可。"; + } + } + else + { + exploreTimes = FunGameConstant.MaxExploreTimes; } } else { - exploreTimes = FunGameConstant.MaxExploreTimes; + return ($"没有找到与这个序号相对应的地区!", exploreId); } + + // 检查角色是否正在探索 + List list = pc.Get>("exploring") ?? []; + if (list.Count > 0) + { + string msg2 = ""; + List remove = []; + foreach (ExploreModel model in list) + { + // 可能要结算先前的超时探索 + if (model.StartTime.HasValue && (DateTime.Now - model.StartTime.Value).TotalMinutes > FunGameConstant.ExploreTime + 2) + { + if (FunGameService.SettleExplore(model.Guid, list, user, out string notice)) + { + if (notice != "") + { + if (msg2 != "") msg2 += "\r\n"; + msg2 += $"你上次未完成的探索已被自动结算:{notice}"; + } + remove.Add(model.Guid); + } + } + + IEnumerable exploring = model.CharacterIds.Intersect(characterIds); + if (exploring.Any()) + { + if (msg2 != "") msg2 += "\r\n"; + msg2 += $"你暂时无法使用以下角色进行探索:[ {FunGameService.GetCharacterGroupInfoByInventorySequence(user.Inventory.Characters, exploring, " ] / [ ")} ]," + + $"因为这些角色已经参与了另一场探索:\r\n{model.GetExploreInfo(user.Inventory.Characters, FunGameConstant.Regions)}"; + } + } + foreach (Guid guid in remove) + { + list.RemoveAll(m => m.Guid == guid); + } + if (msg2 != "") + { + if (msg != "") msg += "\r\n"; + msg += msg2; + } + } + + if (msg == "") + { + exploreTimes -= reduce; + + msg = $"开始探索【{region.Name}】,探索时间预计 {FunGameConstant.ExploreTime} 分钟(系统会自动结算,届时会有提示)。" + + $"探索成员:[ {FunGameService.GetCharacterGroupInfoByInventorySequence(user.Inventory.Characters, characterIds, " ] / [ ")} ]"; + ExploreModel model = await FunGameService.GenerateExploreModel(region, characterIds, user); + exploreId = model.Guid; + list.Add(model); + + if (msg != "") msg += "\r\n"; + msg += $"本次消耗探索许可 {reduce} 个,你的剩余探索许可:{exploreTimes} 个。需要注意:探索难度星级一比一兑换探索许可,并且参与探索的角色,都需要消耗相同数量的探索许可。"; + } + + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.Add("exploreTimes", exploreTimes); + pc.Add("exploring", list); + pc.SaveConfig(); + + return (msg, exploreId); } else { - return ($"没有找到与这个序号相对应的地区!", exploreId); + return (noSaved, exploreId); } - - // 检查角色是否正在探索 - List list = pc.Get>("exploring") ?? []; - if (list.Count > 0) - { - string msg2 = ""; - List remove = []; - foreach (ExploreModel model in list) - { - // 可能要结算先前的超时探索 - if (model.StartTime.HasValue && (DateTime.Now - model.StartTime.Value).TotalMinutes > FunGameConstant.ExploreTime + 2) - { - if (FunGameService.SettleExplore(model.Guid, list, user, out string notice)) - { - if (notice != "") - { - if (msg2 != "") msg2 += "\r\n"; - msg2 += $"你上次未完成的探索已被自动结算:{notice}"; - } - remove.Add(model.Guid); - } - } - - IEnumerable exploring = model.CharacterIds.Intersect(characterIds); - if (exploring.Any()) - { - if (msg2 != "") msg2 += "\r\n"; - msg2 += $"你暂时无法使用以下角色进行探索:[ {FunGameService.GetCharacterGroupInfoByInventorySequence(user.Inventory.Characters, exploring, " ] / [ ")} ]," + - $"因为这些角色已经参与了另一场探索:\r\n{model.GetExploreInfo(user.Inventory.Characters, FunGameConstant.Regions)}"; - } - } - foreach (Guid guid in remove) - { - list.RemoveAll(m => m.Guid == guid); - } - if (msg2 != "") - { - if (msg != "") msg += "\r\n"; - msg += msg2; - } - } - - if (msg == "") - { - exploreTimes -= reduce; - - msg = $"开始探索【{region.Name}】,探索时间预计 {FunGameConstant.ExploreTime} 分钟(系统会自动结算,届时会有提示)。" + - $"探索成员:[ {FunGameService.GetCharacterGroupInfoByInventorySequence(user.Inventory.Characters, characterIds, " ] / [ ")} ]"; - ExploreModel model = await FunGameService.GenerateExploreModel(region, characterIds, user); - exploreId = model.Guid; - list.Add(model); - - if (msg != "") msg += "\r\n"; - msg += $"本次消耗探索许可 {reduce} 个,你的剩余探索许可:{exploreTimes} 个。需要注意:探索难度星级一比一兑换探索许可,并且参与探索的角色,都需要消耗相同数量的探索许可。"; - } - - user.LastTime = DateTime.Now; - pc.Add("user", user); - pc.Add("exploreTimes", exploreTimes); - pc.Add("exploring", list); - pc.SaveConfig(); - - return (msg, exploreId); } - else + catch (Exception e) { - return (noSaved, exploreId); + _semaphore.Release(); + Logger.LogError(e, "Error: "); + return (busy, exploreId); } } @@ -5449,7 +5460,7 @@ namespace Oshima.FunGame.WebAPI.Controllers } [HttpPost("exploresettleall")] - public string SettleExploreAll([FromQuery] long? uid = null) + public string SettleExploreAll([FromQuery] long? uid = null, [FromQuery] bool? skip = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); @@ -5464,7 +5475,7 @@ namespace Oshima.FunGame.WebAPI.Controllers List list = pc.Get>("exploring") ?? []; if (list.Count > 0) { - if (FunGameService.SettleExploreAll(list, user)) + if (FunGameService.SettleExploreAll(list, user, skip ?? false)) { pc.Add("exploring", list); msg = $"已完成探索结算。";