From 5c619fea3e66f6e8cfa48ec28cf95f4200d1bfad Mon Sep 17 00:00:00 2001 From: milimoe Date: Sat, 2 Aug 2025 05:30:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=85=B1=E6=96=97=E3=80=81?= =?UTF-8?q?=E7=A4=BE=E5=9B=A2=EF=BC=8C=E4=B8=80=E4=BA=9B=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaModules/Models/FunGameConstant.cs | 3 + OshimaModules/Regions/Players.cs | 63 +- OshimaServers/AnonymousServer.cs | 1 + OshimaServers/Model/Cooperative.cs | 230 +++-- OshimaServers/Service/FunGameOrderList.cs | 22 +- OshimaServers/Service/FunGameService.cs | 55 +- OshimaServers/Service/OnlineService.cs | 12 + OshimaWebAPI/Controllers/FunGameController.cs | 915 +++++++++++++++--- OshimaWebAPI/Services/RainBOTService.cs | 706 +++++++------- 9 files changed, 1424 insertions(+), 583 deletions(-) diff --git a/OshimaModules/Models/FunGameConstant.cs b/OshimaModules/Models/FunGameConstant.cs index f255210..f0036e7 100644 --- a/OshimaModules/Models/FunGameConstant.cs +++ b/OshimaModules/Models/FunGameConstant.cs @@ -41,11 +41,14 @@ namespace Oshima.FunGame.OshimaModules.Models public static Dictionary UsersInRoom { get; set; } = []; public static ItemType[] ItemCanUsed => [ItemType.Consumable, ItemType.MagicCard, ItemType.SpecialItem, ItemType.GiftBox, ItemType.Others]; public static ItemType[] ItemCanNotDrawCard => [ItemType.Collectible, ItemType.QuestItem, ItemType.GiftBox, ItemType.Others]; + public static Dictionary UserForgingRanking { get; } = []; public static Dictionary UserHorseRacingRanking { get; } = []; + public static Dictionary UserCooperativeRanking { get; } = []; public static Dictionary UserCreditsRanking { get; } = []; public static Dictionary UserMaterialsRanking { get; } = []; public static Dictionary UserEXPRanking { get; } = []; public static Dictionary UserSkillRanking { get; } = []; + public static Dictionary ClubIdAndClub { get; } = []; public static DateTime RankingUpdateTime { get; set; } = DateTime.Now; public static char[] SplitChars => [',', ' ', ',', ';', ';']; diff --git a/OshimaModules/Regions/Players.cs b/OshimaModules/Regions/Players.cs index dabcc8d..af0bd31 100644 --- a/OshimaModules/Regions/Players.cs +++ b/OshimaModules/Regions/Players.cs @@ -40,6 +40,10 @@ namespace Oshima.FunGame.OshimaModules.Regions { template = CreateNewHorseRacingStore(); } + else if (storeName == "dokyo_cooperative") + { + template = CreateNewCooperativeStore(); + } else return null; } @@ -106,21 +110,24 @@ namespace Oshima.FunGame.OshimaModules.Regions { if (storeName == "dokyo_forge") { - double forgePoints = 0; if (pc.TryGetValue("forgepoints", out object? value) && double.TryParse(value.ToString(), out double points)) { - forgePoints = points; + return $"现有锻造积分:{points:0.##}"; } - return $"现有锻造积分:{forgePoints:0.##}"; } else if (storeName == "dokyo_horseracing") { - double horseRacingPoints = 0; - if (pc.TryGetValue("horseRacingPoints", out object? value) && double.TryParse(value.ToString(), out double points)) + if (pc.TryGetValue("horseRacingPoints", out object? value) && int.TryParse(value.ToString(), out int points)) { - horseRacingPoints = points; + return $"现有赛马积分:{points:0.##}"; + } + } + else if (storeName == "dokyo_cooperative") + { + if (pc.TryGetValue("cooperativePoints", out object? value) && int.TryParse(value.ToString(), out int points)) + { + return $"现有共斗积分:{points:0.##}"; } - return $"现有赛马积分:{horseRacingPoints:0.##}"; } return ""; } @@ -163,6 +170,19 @@ namespace Oshima.FunGame.OshimaModules.Regions store.CopyGoodsToNextRefreshGoods(newStore.Goods); } storeTemplate.Add("dokyo_horseracing", store); + + store = storeTemplate.Get("dokyo_cooperative"); + if (store is null) + { + store = CreateNewCooperativeStore(); + } + else + { + Store newStore = CreateNewCooperativeStore(); + store.NextRefreshGoods.Clear(); + store.CopyGoodsToNextRefreshGoods(newStore.Goods); + } + storeTemplate.Add("dokyo_cooperative", store); storeTemplate.SaveConfig(); } @@ -207,5 +227,34 @@ namespace Oshima.FunGame.OshimaModules.Regions store.Goods[1].Quota = 300; return store; } + + private static Store CreateNewCooperativeStore() + { + Store store = new("共斗积分商店") + { + GetNewerGoodsOnVisiting = true, + AutoRefresh = true, + RefreshInterval = 1, + NextRefreshDate = DateTime.Today.AddHours(4), + GlobalStock = true, + }; + Item item = new 奖券(); + store.AddItem(item, -1); + store.SetPrice(1, "共斗积分", 15); + store.Goods[1].Quota = 300; + item = new 十连奖券(); + store.AddItem(item, -1); + store.SetPrice(2, "共斗积分", 120); + store.Goods[2].Quota = 100; + Item[] items = [.. FunGameConstant.CharacterLevelBreakItems.Union(FunGameConstant.SkillLevelUpItems).OrderBy(o => Random.Shared.Next()).Take(5)]; + int i = 3; + foreach (Item cItem in items) + { + store.AddItem(cItem, -1); + store.SetPrice(i, "共斗积分", 4 * ((int)cItem.QualityType + 1)); + i++; + } + return store; + } } } diff --git a/OshimaServers/AnonymousServer.cs b/OshimaServers/AnonymousServer.cs index ab3d9d6..52a96ca 100644 --- a/OshimaServers/AnonymousServer.cs +++ b/OshimaServers/AnonymousServer.cs @@ -135,6 +135,7 @@ namespace Oshima.FunGame.OshimaServers TaskScheduler.Shared.AddRecurringTask("刷新存档缓存", TimeSpan.FromMinutes(1), () => { FunGameService.RefreshSavedCache(); + FunGameService.RefreshClubData(); Controller.WriteLine("读取 FunGame 存档缓存", LogLevel.Debug); OnlineService.RoomsAutoDisband(); Controller.WriteLine("清除空闲房间", LogLevel.Debug); diff --git a/OshimaServers/Model/Cooperative.cs b/OshimaServers/Model/Cooperative.cs index a31913f..3d0e274 100644 --- a/OshimaServers/Model/Cooperative.cs +++ b/OshimaServers/Model/Cooperative.cs @@ -1,6 +1,7 @@ using System.Text; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; +using Milimoe.FunGame.Core.Interface.Entity; using Milimoe.FunGame.Core.Library.Constant; using Oshima.FunGame.OshimaModules.Models; using Oshima.FunGame.OshimaModules.Regions; @@ -10,7 +11,6 @@ namespace Oshima.FunGame.OshimaServers.Model { public class Cooperative { - private const int MaxRounds = 9999; private static readonly Random _random = new(); public static async Task RunCooperativeGame(List msgs, Room room) @@ -33,7 +33,7 @@ namespace Oshima.FunGame.OshimaServers.Model { User userTemp = FunGameService.GetUser(pc); pcs[userTemp] = pc; - characters[user] = user.Inventory.MainCharacter; + characters[userTemp] = userTemp.Inventory.MainCharacter; } else { @@ -51,120 +51,162 @@ namespace Oshima.FunGame.OshimaServers.Model builder.AppendLine("☆--- 共斗模式玩家列表 ---☆"); builder.AppendLine($"房间号:{room.Roomid}"); + bool next = true; foreach (User user in characters.Keys) { - builder.AppendLine($"[ {user} ] 出战角色:{characters[user].ToStringWithLevelWithOutUser()}"); - } - - msgs.Add(builder.ToString().Trim()); - - // 生成敌人 - OshimaRegion region = FunGameConstant.Regions.OrderBy(o => _random.Next()).First(); - List enemys = []; - Character? enemy = null; - bool isUnit = Random.Shared.Next(2) != 0; - if (!isUnit) - { - enemy = region.Characters.OrderBy(o => Random.Shared.Next()).FirstOrDefault(); - if (enemy != null) + Character character = characters[user]; + double hpPercent = character.HP / character.MaxHP * 100; + ISkill[] skills = [character.NormalAttack, .. character.Skills]; + builder.AppendLine($"[ {user} ] 主战角色:{characters[user].ToStringWithLevelWithOutUser()},核心属性:{CharacterSet.GetPrimaryAttributeName(character.PrimaryAttribute)};" + + $"攻击力:{character.ATK:0.##};当前生命值;{hpPercent:0.##}%;拥有技能:{string.Join(",", skills.Select(s => $"{s.Name}({s.Level})"))}。"); + if (hpPercent < 10) { - enemy = enemy.Copy(); - enemy.ExHPPercentage += 0.2; - enemys.Add(enemy); + next = false; + builder.AppendLine($"[ {user} ] 的主战角色重伤未愈,当前生命值低于 10%,请先回复生命值或设置其他主战角色!推荐使用【生命之泉】指令快速治疗。"); } } - else + + msgs.Add(builder.ToString().Trim() + "\r\n"); + builder.Clear(); + + if (next) { - for (int i = 0; i < Math.Max(1, characters.Count); i++) + // 生成敌人 + OshimaRegion region = FunGameConstant.Regions.OrderBy(o => _random.Next()).First(); + List enemys = []; + Character? enemy = null; + bool isUnit = Random.Shared.Next(2) != 0; + if (!isUnit) { - enemy = region.Units.OrderBy(o => Random.Shared.Next()).FirstOrDefault(); + enemy = region.Characters.OrderBy(o => Random.Shared.Next()).FirstOrDefault(); if (enemy != null) { enemy = enemy.Copy(); - int dcount = enemys.Count(e => e.Name == enemy.Name); - if (dcount > 0 && FunGameConstant.GreekAlphabet.Length > dcount) enemy.Name += FunGameConstant.GreekAlphabet[dcount - 1]; enemys.Add(enemy); } } - } - if (enemys.Count == 0) - { - msgs.Add("没有可用的敌人,返回游戏房间。"); - } - else - { - Item[] weapons = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("11") && (int)i.QualityType == 5)]; - Item[] armors = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("12") && (int)i.QualityType == 5)]; - Item[] shoes = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("13") && (int)i.QualityType == 5)]; - Item[] accessory = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("14") && (int)i.QualityType == 5)]; - Item[] consumables = [.. FunGameConstant.AllItems.Where(i => i.ItemType == ItemType.Consumable && i.IsInGameItem)]; - // 敌人为动态难度,根据玩家的等级生成 - int cLevel = (int)characters.Values.Average(c => c.Level) + 5; - int sLevel = cLevel / 7; - int mLevel = cLevel / 9; - int naLevel = mLevel; - foreach (Character enemy_loop in enemys) + else { - FunGameService.EnhanceBoss(enemy_loop, weapons, armors, shoes, accessory, consumables, cLevel, sLevel, mLevel, naLevel, false, false, isUnit); + for (int i = 0; i < Math.Max(1, characters.Count); i++) + { + enemy = region.Units.OrderBy(o => Random.Shared.Next()).FirstOrDefault(); + if (enemy != null) + { + enemy = enemy.Copy(); + int dcount = enemys.Count(e => e.Name.StartsWith(enemy.Name)); + if (dcount > 0 && FunGameConstant.GreekAlphabet.Length > dcount) enemy.Name += FunGameConstant.GreekAlphabet[dcount - 1]; + enemys.Add(enemy); + } + } } - // 开始战斗 - Team team1 = new($"房间{room.Roomid}", characters.Values); - Team team2 = new($"{region.Name}", enemys); - FunGameActionQueue actionQueue = new(); - List gameMsgs = await actionQueue.StartTeamGame([team1, team2], showAllRound: true); - if (gameMsgs.Count > 15) + if (enemys.Count == 0) { - gameMsgs = gameMsgs[^15..]; - } - msgs.AddRange(gameMsgs); - - // 结算奖励 - Character? mvp = actionQueue.GamingQueue.CharacterStatistics.OrderByDescending(d => d.Value.Rating).Select(d => d.Key).FirstOrDefault(); - int multiplication = 1; - int award = multiplication * enemys.Count; - if (enemys.All(e => e.HP == 0)) - { - multiplication = 15; - award = multiplication * enemys.Count; - builder.Clear(); - builder.AppendLine($"☆--- 战斗胜利奖励 ---☆"); - builder.AppendLine($"击杀了全部敌人,所有玩家获得奖励:{award} {General.GameplayEquilibriumConstant.InGameMaterial}"); + msgs.Add("没有可用的敌人,返回游戏房间。"); } else { - builder.AppendLine($"☆--- 战斗失败奖励 ---☆"); - int count = enemys.Count(e => e.HP == 0); - award = multiplication * count; - builder.AppendLine($"击杀了 {count} 个敌人,所有玩家获得奖励:{award} {General.GameplayEquilibriumConstant.InGameMaterial}"); - } - foreach (User user in characters.Keys) - { - user.Inventory.Materials += award; - } - if (mvp != null) - { - builder.AppendLine($"MVP 玩家额外获得奖励:{award} {General.GameplayEquilibriumConstant.InGameMaterial}"); - if (characters.Keys.FirstOrDefault(u => u.Id == mvp.User.Id) is User mvpUser) + Item[] weapons = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("11") && (int)i.QualityType == 5)]; + Item[] armors = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("12") && (int)i.QualityType == 5)]; + Item[] shoes = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("13") && (int)i.QualityType == 5)]; + Item[] accessory = [.. FunGameConstant.Equipment.Where(i => i.Id.ToString().StartsWith("14") && (int)i.QualityType == 5)]; + Item[] consumables = [.. FunGameConstant.AllItems.Where(i => i.ItemType == ItemType.Consumable && i.IsInGameItem)]; + // 敌人为动态难度,根据玩家的等级生成 + int cLevel = (int)characters.Values.Average(c => c.Level) + 5; + int sLevel = cLevel / 7; + int mLevel = cLevel / 9; + int naLevel = mLevel; + foreach (Character enemy_loop in enemys) { - mvpUser.Inventory.Materials += award; + FunGameService.EnhanceBoss(enemy_loop, weapons, armors, shoes, accessory, consumables, cLevel, sLevel, mLevel, naLevel, false, false, isUnit); } + // 开始战斗 + Team team1 = new($"房间{room.Roomid}", characters.Values); + Team team2 = new($"{region.Name}", enemys); + FunGameActionQueue actionQueue = new(); + List gameMsgs = await actionQueue.StartTeamGame([team1, team2], showAllRound: true); + if (gameMsgs.Count > 15) + { + gameMsgs = gameMsgs[^15..]; + } + msgs.AddRange(gameMsgs); + + // 结算奖励 + Character? mvp = actionQueue.GamingQueue.CharacterStatistics.OrderByDescending(d => d.Value.Rating).Select(d => d.Key).FirstOrDefault(); + int award = cLevel; + if (enemys.All(e => e.HP == 0)) + { + builder.AppendLine($"☆--- 战斗胜利奖励 ---☆"); + builder.AppendLine($"击杀了全部敌人,所有玩家获得奖励:{award} {General.GameplayEquilibriumConstant.InGameMaterial} 和 {award} 点共斗积分。"); + builder.AppendLine($"所有角色获得【生命之泉】奖励!状态已经回复至满。"); + foreach (Character character in characters.Values) + { + character.Recovery(); + } + } + else + { + builder.AppendLine($"☆--- 战斗失败奖励 ---☆"); + int count = enemys.Count(e => e.HP == 0); + if (isUnit) + { + award = cLevel / enemys.Count * count; + } + else + { + award = 0; + } + if (count > 0) + { + builder.AppendLine($"击杀了 {count} 个敌人,所有玩家获得奖励:{award} {General.GameplayEquilibriumConstant.InGameMaterial} 和 {award} 点共斗积分。"); + } + else + { + builder.AppendLine($"未能击杀任何敌人,无法获得奖励。"); + } + builder.AppendLine($"角色进入重伤未愈状态,请所有玩家立即使用【生命之泉】指令回复状态!使用【酒馆】指令可以补满角色能量。"); + } + foreach (User user in characters.Keys) + { + user.Inventory.Materials += award; + PluginConfig pc = pcs[user]; + if (pc.TryGetValue("cooperativePoints", out object? value) && int.TryParse(value.ToString(), out int cooperativePoints)) + { + pc.Add("cooperativePoints", cooperativePoints + award); + } + else + { + pc.Add("cooperativePoints", award); + } + } + if (mvp != null && characters.ContainsKey(mvp.User)) + { + int mvpAward = cLevel / 5; + builder.AppendLine($"MVP 玩家 [ {mvp.User.Username} ] 额外获得奖励:{mvpAward} {General.GameplayEquilibriumConstant.InGameMaterial}。"); + mvp.User.Inventory.Materials += mvpAward; + } + builder.AppendLine($"共斗积分可以在【共斗商店】中兑换物品。"); + builder.AppendLine($"\r\n☆--- 战斗数据 ---☆"); + int index = 1; + foreach (Character character in actionQueue.GamingQueue.CharacterStatistics.Where(kv => characters.ContainsValue(kv.Key)). + OrderByDescending(kv => kv.Value.Rating).Select(kv => kv.Key)) + { + CharacterStatistics stats = actionQueue.GamingQueue.CharacterStatistics[character]; + builder.AppendLine($"{index + ". "}[ {character.ToStringWithLevel()} ]"); + builder.AppendLine($"技术得分:{stats.Rating:0.0#} / 击杀数:{stats.Kills} / 助攻数:{stats.Assists} / 死亡数:{stats.Deaths}"); + builder.AppendLine($"存活时长:{stats.LiveTime:0.##} / 存活回合数:{stats.LiveRound} / 行动回合数:{stats.ActionTurn}"); + builder.AppendLine($"控制时长:{stats.ControlTime:0.##} / 总计治疗:{stats.TotalHeal:0.##} / 护盾抵消:{stats.TotalShield:0.##}"); + builder.AppendLine($"总计伤害:{stats.TotalDamage:0.##} / 总计物理伤害:{stats.TotalPhysicalDamage:0.##} / 总计魔法伤害:{stats.TotalMagicDamage:0.##}"); + builder.AppendLine($"总承受伤害:{stats.TotalTakenDamage:0.##} / 总承受物理伤害:{stats.TotalTakenPhysicalDamage:0.##} / 总承受魔法伤害:{stats.TotalTakenMagicDamage:0.##}"); + if (stats.TotalTrueDamage > 0 || stats.TotalTakenTrueDamage > 0) builder.AppendLine($"总计真实伤害:{stats.TotalTrueDamage:0.##} / 总承受真实伤害:{stats.TotalTakenTrueDamage:0.##}"); + builder.AppendLine($"每秒伤害:{stats.DamagePerSecond:0.##} / 每回合伤害:{stats.DamagePerTurn:0.##}"); + index++; + } + msgs.Add(builder.ToString().Trim()); } - builder.AppendLine($"☆--- 战斗数据 ---☆"); - int index = 1; - foreach (Character character in actionQueue.GamingQueue.CharacterStatistics.Where(kv => characters.ContainsValue(kv.Key)).Select(kv => kv.Key)) - { - CharacterStatistics stats = actionQueue.GamingQueue.CharacterStatistics[character]; - builder.AppendLine($"{index + ". "}[ {character.ToStringWithLevel()} ]"); - builder.AppendLine($"技术得分:{stats.Rating:0.0#} / 击杀数:{stats.Kills} / 助攻数:{stats.Assists} / 死亡数:{stats.Deaths}"); - builder.AppendLine($"存活时长:{stats.LiveTime:0.##} / 存活回合数:{stats.LiveRound} / 行动回合数:{stats.ActionTurn}"); - builder.AppendLine($"控制时长:{stats.ControlTime:0.##} / 总计治疗:{stats.TotalHeal:0.##} / 护盾抵消:{stats.TotalShield:0.##}"); - builder.AppendLine($"总计伤害:{stats.TotalDamage:0.##} / 总计物理伤害:{stats.TotalPhysicalDamage:0.##} / 总计魔法伤害:{stats.TotalMagicDamage:0.##}"); - builder.AppendLine($"总承受伤害:{stats.TotalTakenDamage:0.##} / 总承受物理伤害:{stats.TotalTakenPhysicalDamage:0.##} / 总承受魔法伤害:{stats.TotalTakenMagicDamage:0.##}"); - if (stats.TotalTrueDamage > 0 || stats.TotalTakenTrueDamage > 0) builder.AppendLine($"总计真实伤害:{stats.TotalTrueDamage:0.##} / 总承受真实伤害:{stats.TotalTakenTrueDamage:0.##}"); - builder.AppendLine($"每秒伤害:{stats.DamagePerSecond:0.##} / 每回合伤害:{stats.DamagePerTurn:0.##}"); - index++; - } - msgs.Add(builder.ToString().Trim()); + } + else + { + msgs.Add("返回游戏房间。"); } // 存档 diff --git a/OshimaServers/Service/FunGameOrderList.cs b/OshimaServers/Service/FunGameOrderList.cs index 66406e4..c028ffa 100644 --- a/OshimaServers/Service/FunGameOrderList.cs +++ b/OshimaServers/Service/FunGameOrderList.cs @@ -19,6 +19,8 @@ {"我的状态", "查看主战角色状态"}, {"装备 <角色序号> <物品序号>", "装备指定物品给角色"}, {"取消装备 <角色序号> <装备槽序号>", "卸下角色装备(槽位1-6)"}, + {"加物/添加背包物品 <角色序号> <物品序号>", "添加指定消耗品到角色背包"}, + {"减物/移除背包物品 <角色序号> <背包物品序号>", "取回角色背包的消耗品"}, {"角色升级 [角色序号]", "提升角色等级(默认1)"}, {"角色突破 [角色序号]", "突破等级限制(默认1)"}, {"突破信息 [角色序号]", "查看突破需求(默认1)"}, @@ -79,6 +81,8 @@ {"金币排行榜", "查看全服金币数量排行榜"}, {"钻石排行榜", "查看全服钻石数量排行榜"}, {"赛马排行榜", "查看全服赛马积分排行榜"}, + {"共斗排行榜", "查看全服共斗积分排行榜"}, + {"锻造排行榜", "查看全服锻造积分排行榜"}, }; public static Dictionary PlayHelp { get; } = new() { @@ -90,6 +94,7 @@ {"主城", "查看主城信息"}, {"查地区 <地区序号>", "查看指定地区信息"}, {"探索 <地区序号> <{角色序号...}>", "探索指定地区(可多角色)"}, + {"小队探索 <地区序号>", "以小队探索指定地区"}, {"探索结算", "结算所有未完成的探索"}, {"挑战金币秘境 <难度>", "以小队挑战金币秘境,秘境难度1-5"}, {"挑战钻石秘境 <难度>", "以小队挑战钻石秘境,秘境难度1-5"}, @@ -105,8 +110,10 @@ {"创建房间 <类型>", "类型:mix/team/cooperative/horseracing对应混战/团队/共斗/赛马" }, {"加入房间 <房间号>", "加入多人游戏房间" }, {"退出房间", "退出多人游戏房间" }, - {"创建赛马", "快速创建赛马房间" }, {"开始游戏", "开始多人游戏" }, + {"房间列表", "查看本群聊的房间列表" }, + {"房间信息", "查看多人游戏房间信息" }, + {"创建赛马", "快速创建赛马房间" }, {"加入赛马", "快速加入赛马房间" }, {"创建共斗", "快速创建共斗房间" }, {"创建混战", "快速创建混战房间" }, @@ -114,20 +121,24 @@ }; public static Dictionary ClubHelp { get; } = new() { - {"我的社团", "查看社团信息"}, + {"社团列表", "查看公开可加入的社团列表"}, + {"查看社团", "查看指定社团信息"}, + {"我的社团", "查看我的社团信息"}, {"私信 <对方UID/昵称> <内容>", "发送私信给对方"}, - {"加入社团 <社团序号>", "申请加入社团"}, + {"加入社团 <社团序号>", "加入指定社团"}, + {"邀请加入 <对方UID>", "管理员可以邀请加入社团"}, {"退出社团", "退出当前社团"}, {"创建社团 <前缀>", "创建一个公开社团,若指令中包含私密一词,将创建私密社团\r\n社团前缀:3-4个字符,允许:英文字母和数字、部分特殊字符"}, {"查看社团成员", "查看社团成员列表"}, {"查看社团管理", "查看管理员列表"}, {"查看申请人列表", "查看申请加入的玩家列表"}, + {"查看受邀人列表", "查看待接受邀请的玩家列表"}, {"解散社团", "解散当前社团"}, {"社团批准 <对方UID>", "批准加入申请"}, {"社团拒绝 <对方UID>", "拒绝加入申请"}, {"社团踢出 <对方UID>", "踢出社团成员"}, {"社团转让 <对方UID>", "转让社团所有权"}, - {"社团设置 <设置项> <{参数...}>", "修改社团设置"}, + {"社团设置 <设置项> <{参数...}>", "修改社团设置,设置项有:名称/前缀/描述/批准/公开/管理/取消管理/新社长"}, {"社团捐献 <金币数>", "捐献金币到社团基金"}, {"社团任务列表", "查看社团任务列表"}, {"做社团任务 <任务序号>", "开始指定社团任务"}, @@ -160,7 +171,8 @@ {"商店3", "查看杂货铺商品"}, {"商店4", "查看慈善基金会商品"}, {"锻造商店/商店5", "查看锻造积分商店商品"}, - {"赛马商店/商店6", "查看锻造积分商店商品"}, + {"赛马商店/商店6", "查看赛马积分商店商品"}, + {"共斗商店/商店7", "查看共斗积分商店商品"}, {"商店查看 <商品序号>", "查看指定商品详情,访问任意商店后2分钟内可用"}, {"商店购买 <商品序号>", "购买指定商品,访问任意商店后2分钟内可用"}, {"商店出售 <物品序号>", "向商店出售具有回收价的指定物品"}, diff --git a/OshimaServers/Service/FunGameService.cs b/OshimaServers/Service/FunGameService.cs index 9ad8faa..3e0216f 100644 --- a/OshimaServers/Service/FunGameService.cs +++ b/OshimaServers/Service/FunGameService.cs @@ -656,6 +656,7 @@ namespace Oshima.FunGame.OshimaServers.Service int reduce; string reduceUnit; IEnumerable? items = null; + bool useItem = false; if (useCurrency) { if (is10) @@ -666,7 +667,8 @@ namespace Oshima.FunGame.OshimaServers.Service { items = user.Inventory.Items.Where(i => i is 奖券); } - if (items.Any()) + useItem = items.Any(); + if (useItem) { reduceUnit = items.First().Name; reduce = 1; @@ -730,7 +732,7 @@ namespace Oshima.FunGame.OshimaServers.Service } } - if (items != null && items.Any()) + if (items != null && useItem) { msgs.Insert(0, $"本次抽卡使用{reduceUnit}代替金币抽卡!你的库存剩余 {items.Count()} 张{reduceUnit}。"); } @@ -2180,6 +2182,19 @@ namespace Oshima.FunGame.OshimaServers.Service return $"你的{needy}不足 {reduce} 呢,无法购买【{goods.Name}】!"; } } + else if (needy == "共斗积分") + { + double reduce = Calculation.Round2Digits(goods.Prices[needy] * count); + if (pc.TryGetValue("cooperativePoints", out object? value) && double.TryParse(value.ToString(), out double points) && points >= reduce) + { + points -= reduce; + pc.Add("cooperativePoints", points); + } + else + { + return $"你的{needy}不足 {reduce} 呢,无法购买【{goods.Name}】!"; + } + } else { return $"不支持的货币类型:{needy},无法购买【{goods.Name}】!"; @@ -2632,7 +2647,7 @@ namespace Oshima.FunGame.OshimaServers.Service 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" : ""; + enemy.FirstName = enemys.Any(e => e.Name.StartsWith(enemy.Name)) ? "2" : ""; enemys.Add(enemy); break; case 5: @@ -2640,10 +2655,10 @@ namespace Oshima.FunGame.OshimaServers.Service 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) ? "α" : ""; + enemy.FirstName = enemys.Any(e => e.Name.StartsWith(enemy.Name)) ? "α" : ""; enemys.Add(enemy); enemy = region.Units.OrderBy(o => Random.Shared.Next()).First().Copy(); - enemy.FirstName = enemys.Any(e => e.Name == enemy.Name) ? "β" : ""; + enemy.FirstName = enemys.Any(e => e.Name.StartsWith(enemy.Name)) ? "β" : ""; enemys.Add(enemy); break; } @@ -3597,7 +3612,7 @@ namespace Oshima.FunGame.OshimaServers.Service if (enemy != null) { enemy = enemy.Copy(); - int dcount = enemys.Count(e => e.Name == enemy.Name); + int dcount = enemys.Count(e => e.Name.StartsWith(enemy.Name)); if (dcount > 0 && FunGameConstant.GreekAlphabet.Length > dcount) enemy.Name += FunGameConstant.GreekAlphabet[dcount - 1]; enemys.Add(enemy); } @@ -4579,6 +4594,14 @@ namespace Oshima.FunGame.OshimaServers.Service { FunGameConstant.UserHorseRacingRanking[user.Id] = horseRacingPoints; } + if (pc.TryGetValue("forgepoints", out value3) && double.TryParse(value3.ToString(), out double forgepoints)) + { + FunGameConstant.UserForgingRanking[user.Id] = forgepoints; + } + if (pc.TryGetValue("cooperativePoints", out value3) && int.TryParse(value3.ToString(), out int cooperativePoints)) + { + FunGameConstant.UserCooperativeRanking[user.Id] = cooperativePoints; + } } ReleaseUserSemaphoreSlim(fileName); } @@ -4586,6 +4609,26 @@ namespace Oshima.FunGame.OshimaServers.Service } } + public static void RefreshClubData() + { + string directoryPath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/clubs"; + if (Directory.Exists(directoryPath)) + { + string[] filePaths = Directory.GetFiles(directoryPath); + foreach (string filePath in filePaths) + { + string fileName = Path.GetFileNameWithoutExtension(filePath); + EntityModuleConfig clubs = new("clubs", fileName); + clubs.LoadConfig(); + Club? club = clubs.Get("club"); + if (club != null) + { + FunGameConstant.ClubIdAndClub[club.Id] = club; + } + } + } + } + public static void RefreshDailyQuest() { string directoryPath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/quests"; diff --git a/OshimaServers/Service/OnlineService.cs b/OshimaServers/Service/OnlineService.cs index 108d817..35f75c8 100644 --- a/OshimaServers/Service/OnlineService.cs +++ b/OshimaServers/Service/OnlineService.cs @@ -287,6 +287,18 @@ namespace Oshima.FunGame.OshimaServers.Service } return msg; } + + public static string RoomInfo(Room room) + { + string username = ""; + if (FunGameConstant.UserIdAndUsername.TryGetValue(room.RoomMaster.Id, out User? value) && value != null) + { + username = value.Username; + } + string msg = $"房间号:{room.Roomid}\r\n房间类型:{room.Name}\r\n创建时间:{room.CreateTime.ToString(General.GeneralDateTimeFormatChinese)}\r\n房主:{username}\r\n" + + $"人数:{room.UserAndIsReady.Count} / {room.MaxUsers}"; + return msg; + } public static void RoomsAutoDisband() { diff --git a/OshimaWebAPI/Controllers/FunGameController.cs b/OshimaWebAPI/Controllers/FunGameController.cs index 1f513d4..2cf86bd 100644 --- a/OshimaWebAPI/Controllers/FunGameController.cs +++ b/OshimaWebAPI/Controllers/FunGameController.cs @@ -583,7 +583,7 @@ namespace Oshima.FunGame.WebAPI.Controllers Club? club = emc.Get("club"); if (club != null) { - builder.AppendLine($"所属社团:{club.Name} [{club.Prefix}]"); + builder.AppendLine($"所属社团:{club}"); } else { @@ -2595,7 +2595,7 @@ namespace Oshima.FunGame.WebAPI.Controllers { if (character.EXP < need) { - msg += $"\r\n角色 [ {character} ] 仍需 {need - character.EXP} 点经验值才能继续升级。"; + msg += $"\r\n角色 [ {character} ] 仍需 {need - character.EXP:0.##} 点经验值才能继续升级。"; } else { @@ -2837,7 +2837,20 @@ namespace Oshima.FunGame.WebAPI.Controllers horseRacingPoints = itemCount; } pc2.Add("horseRacingPoints", horseRacingPoints); - msg = $"已为 [ {user2} ] 生成 {itemCount} 个锻造积分"; + msg = $"已为 [ {user2} ] 生成 {itemCount} 个赛马积分"; + } + else if (itemName == "共斗积分") + { + if (pc.TryGetValue("cooperativePoints", out object? value) && int.TryParse(value.ToString(), out int cooperativePoints)) + { + cooperativePoints += itemCount; + } + else + { + cooperativePoints = itemCount; + } + pc2.Add("cooperativePoints", cooperativePoints); + msg = $"已为 [ {user2} ] 生成 {itemCount} 个共斗积分"; } else if (itemName.Contains("魔法卡礼包")) { @@ -3045,7 +3058,7 @@ namespace Oshima.FunGame.WebAPI.Controllers user.Inventory.Materials += totalGained; } FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user); - return $"分解完毕!分解 {ids.Length} 件,库存允许分解 {dict.Count} 件,成功 {successCount} 件,得到了 {totalGained} {General.GameplayEquilibriumConstant.InGameMaterial}!"; + return $"分解完毕!分解 {ids.Length} 件,库存允许分解 {dict.Count} 件,成功 {successCount} 件,得到了 {totalGained:0.##} {General.GameplayEquilibriumConstant.InGameMaterial}!"; } else { @@ -3114,7 +3127,7 @@ namespace Oshima.FunGame.WebAPI.Controllers user.Inventory.Materials += totalGained; } FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user); - return $"分解完毕!分解 {useCount} 件物品,成功 {successCount} 件,得到了 {totalGained} {General.GameplayEquilibriumConstant.InGameMaterial}!"; + return $"分解完毕!分解 {useCount} 件物品,成功 {successCount} 件,得到了 {totalGained:0.##} {General.GameplayEquilibriumConstant.InGameMaterial}!"; } else { @@ -3188,7 +3201,7 @@ namespace Oshima.FunGame.WebAPI.Controllers user.Inventory.Materials += totalGained; } FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user); - return $"分解完毕!成功分解 {successCount} 件{qualityName}物品,得到了 {totalGained} {General.GameplayEquilibriumConstant.InGameMaterial}!"; + return $"分解完毕!成功分解 {successCount} 件{qualityName}物品,得到了 {totalGained:0.##} {General.GameplayEquilibriumConstant.InGameMaterial}!"; } else { @@ -3935,7 +3948,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.Bosses.Remove(bossIndex); double gained = boss.Level; user.Inventory.Materials += gained; - msgs.Add($"恭喜你击败了 Boss,获得 {gained} {General.GameplayEquilibriumConstant.InGameMaterial}奖励!"); + msgs.Add($"恭喜你击败了 Boss,获得 {gained:0.##} {General.GameplayEquilibriumConstant.InGameMaterial}奖励!"); } else { @@ -4205,7 +4218,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.Bosses.Remove(bossIndex); double gained = boss.Level; user.Inventory.Materials += gained; - msgs.Add($"恭喜你击败了 Boss,获得 {gained} {General.GameplayEquilibriumConstant.InGameMaterial}奖励!"); + msgs.Add($"恭喜你击败了 Boss,获得 {gained:0.##} {General.GameplayEquilibriumConstant.InGameMaterial}奖励!"); } else { @@ -4480,8 +4493,8 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpPost("joinclub")] - public string JoinClub([FromQuery] long? uid = null, [FromQuery] long? id = null) + [HttpPost("clubjoin")] + public string ClubJoin([FromQuery] long? uid = null, [FromQuery] long? id = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); long clubid = id ?? 0; @@ -4506,7 +4519,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return $"不存在编号为 {clubid} 的社团!"; } - if (!club.IsPublic) + if (!club.IsPublic && !club.Invitees.ContainsKey(user.Id)) { FunGameService.ReleaseUserSemaphoreSlim(userid); return $"社团 [ {club.Name} ] 未公开,只能通过邀请加入。"; @@ -4514,21 +4527,30 @@ namespace Oshima.FunGame.WebAPI.Controllers string msg = ""; - if (club.IsNeedApproval || club.Applicants.ContainsKey(userid)) + if (club.IsNeedApproval && !club.Invitees.ContainsKey(user.Id)) { club.ApplicationTime[userid] = DateTime.Now; club.Applicants[userid] = user; msg += $"已向社团 [ {club.Name} ] 提交加入申请!"; + foreach (long noticeUserId in club.Admins.Keys.Union([club.Master.Id])) + { + FunGameService.AddNotice(noticeUserId, $"【社团通知】[ {user.Username} ] 正在申请加入社团,请使用【查看申请人列表】指令查看列表!"); + } } else { club.MemberJoinTime[userid] = DateTime.Now; club.Members[userid] = user; + club.Invitees.Remove(userid); + club.InvitedTime.Remove(userid); + club.Applicants.Remove(userid); + club.ApplicationTime.Remove(userid); msg += $"加入社团 [ {club.Name} ] 成功!"; pc.Add("club", clubid); } emc.Add("club", club); emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user); return msg; @@ -4540,8 +4562,8 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpPost("quitclub")] - public string QuitClub([FromQuery] long? uid = null) + [HttpPost("clubquit")] + public string ClubQuit([FromQuery] long? uid = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); @@ -4571,7 +4593,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return $"不存在编号为 {clubid} 的社团!"; } - if (club.Master?.Id == userid) + if (club.Master.Id == userid) { FunGameService.ReleaseUserSemaphoreSlim(userid); return $"你是社团的社长,不能退出社团,请转让社长或【解散社团】!"; @@ -4586,6 +4608,7 @@ namespace Oshima.FunGame.WebAPI.Controllers club.MemberJoinTime.Remove(userid); emc.Add("club", club); emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; string msg = $"退出社团 [ {club.Name} ] 成功!"; pc.Add("club", 0); @@ -4599,8 +4622,8 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpPost("createclub")] - public string CreateClub([FromQuery] long? uid = null, [FromQuery] bool? @public = null, [FromQuery] string? prefix = null) + [HttpPost("clubcreate")] + public string ClubCreate([FromQuery] long? uid = null, [FromQuery] bool? @public = null, [FromQuery] string? prefix = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); bool isPublic = @public ?? false; @@ -4663,6 +4686,7 @@ namespace Oshima.FunGame.WebAPI.Controllers emc.LoadConfig(); emc.Add("club", club); emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; string msg = $"创建社团 [ {club.Name} ] (编号 {clubid})成功!"; pc.Add("club", clubid); @@ -4676,8 +4700,8 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpGet("showclubinfo")] - public string ShowClubInfo([FromQuery] long? uid = null) + [HttpGet("clubshowinfo")] + public string ClubShowInfo([FromQuery] long? uid = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); @@ -4700,25 +4724,25 @@ namespace Oshima.FunGame.WebAPI.Controllers if (club != null) { string master = "无"; - if (FunGameConstant.UserIdAndUsername.TryGetValue(club.Master?.Id ?? 0, out User? user2) && user2 != null) + if (FunGameConstant.UserIdAndUsername.TryGetValue(club.Master.Id, out User? user2) && user2 != null) { master = user2.Username; } StringBuilder builer = new(); builer.AppendLine($"☆--- {user.Username}的社团信息 ---☆"); - builer.AppendLine($"所属社团:{club.Name} [{club.Prefix}]"); + builer.AppendLine($"所属社团:{club}"); builer.AppendLine($"社团编号:{club.Id}"); builer.AppendLine($"社团社长:{master}"); builer.AppendLine($"是否公开:{(club.IsPublic ? "公开" : "私密")}"); if (club.IsPublic) builer.AppendLine($"加入规则:{(club.IsNeedApproval ? "需要批准" : "直接加入")}"); builer.AppendLine($"成员数量:{club.Members.Count}"); - if (club.Master?.Id == userid || club.Admins.ContainsKey(userid)) + if (club.Master.Id == userid || club.Admins.ContainsKey(userid)) { builer.AppendLine($"管理员数量:{club.Admins.Count}"); builer.AppendLine($"申请人数量:{club.Applicants.Count}"); builer.AppendLine($"社团基金:{club.ClubPoins}"); - if (club.Master?.Id == userid) + if (club.Master.Id == userid) { builer.AppendLine("你是此社团的社长"); } @@ -4743,8 +4767,57 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpGet("showclubmemberlist")] - public string ShowClubMemberList([FromQuery] long? uid = null, [FromQuery] int? type = null, [FromQuery] int? page = null) + [HttpGet("clubshowlist")] + public string ClubShowList([FromQuery] long? uid = null, [FromQuery] int page = 0) + { + long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + + PluginConfig pc = FunGameService.GetUserConfig(userid, out _); + FunGameService.ReleaseUserSemaphoreSlim(userid); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + StringBuilder builder = new(); + Club[] clubs = [.. FunGameConstant.ClubIdAndClub.Values.Where(c => c.IsPublic)]; + int maxPage = (int)Math.Ceiling((double)clubs.Length / FunGameConstant.ItemsPerPage2); + if (maxPage < 1) maxPage = 1; + if (page <= maxPage) + { + clubs = [.. FunGameService.GetPage(clubs, page, FunGameConstant.ItemsPerPage2)]; + builder.AppendLine($"☆--- 公开社团列表 ---☆"); + foreach (Club club in clubs) + { + string master = "无"; + if (FunGameConstant.UserIdAndUsername.TryGetValue(club.Master.Id, out User? user2) && user2 != null) + { + master = user2.Username; + } + builder.AppendLine($"== {club} =="); + builder.AppendLine($"社团编号:{club.Id}"); + builder.AppendLine($"社团社长:{master}"); + builder.AppendLine($"加入规则:{(club.IsNeedApproval ? "需要批准" : "直接加入")}"); + builder.AppendLine($"成员数量:{club.Members.Count}"); + builder.AppendLine($"社团描述:{club.Description}"); + } + builder.Append($"页数:{page} / {maxPage}"); + } + else + { + builder.Append($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {page} 页。"); + } + + return builder.ToString().Trim(); + } + else + { + return noSaved; + } + } + + [HttpGet("clubshowmemberlist")] + public string ClubShowMemberList([FromQuery] long? uid = null, [FromQuery] int? type = null, [FromQuery] int? page = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); int showType = type ?? 0; @@ -4777,7 +4850,7 @@ namespace Oshima.FunGame.WebAPI.Controllers builder.AppendLine($"☆--- 社团 [ {club.Name} ] 管理员列表 ---☆"); count = 1; List admins = []; - if (club.Master != null && club.Master.Id != 0) + if (club.Master.Id != 0) { admins.Add(club.Master.Id); } @@ -4807,7 +4880,7 @@ namespace Oshima.FunGame.WebAPI.Controllers } break; case 2: - if (club.Master?.Id == user.Id || club.Admins.ContainsKey(user.Id)) + if (club.Master.Id == user.Id || club.Admins.ContainsKey(user.Id)) { builder.AppendLine($"☆--- 社团 [ {club.Name} ] 申请人列表 ---☆"); count = 1; @@ -4839,6 +4912,39 @@ namespace Oshima.FunGame.WebAPI.Controllers builder.Append("你没有权限查看这个列表!"); } break; + case 3: + if (club.Master.Id == user.Id || club.Admins.ContainsKey(user.Id)) + { + builder.AppendLine($"☆--- 社团 [ {club.Name} ] 受邀人列表 ---☆"); + count = 1; + maxPage = (int)Math.Ceiling((double)club.Invitees.Count / FunGameConstant.ItemsPerPage2); + if (maxPage < 1) maxPage = 1; + if (showPage <= maxPage) + { + IEnumerable invitees = FunGameService.GetPage(club.Invitees.Keys, showPage, FunGameConstant.ItemsPerPage2); + foreach (long uid2 in invitees) + { + if (FunGameConstant.UserIdAndUsername.TryGetValue(uid2, out User? user2) && user2 != null) + { + builder.AppendLine($"{count}."); + builder.AppendLine($"UID:{user2.Id}"); + builder.AppendLine($"玩家昵称:{user2.Username}"); + builder.AppendLine($"邀请时间:{club.InvitedTime[user2.Id].ToString(General.GeneralDateTimeFormatChinese)}"); + } + count++; + } + builder.AppendLine($"页数:{showPage} / {maxPage}"); + } + else + { + builder.Append($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {showPage} 页。"); + } + } + else + { + builder.Append("你没有权限查看这个列表!"); + } + break; case 0: default: builder.AppendLine($"☆--- 社团 [ {club.Name} ] 成员列表 ---☆"); @@ -4856,7 +4962,7 @@ namespace Oshima.FunGame.WebAPI.Controllers builder.AppendLine($"UID:{user2.Id}"); builder.AppendLine($"玩家昵称:{user2.Username}"); string userType = "社员"; - if (club.Master?.Id == user2.Id) + if (club.Master.Id == user2.Id) { userType = "社长"; } @@ -4893,8 +4999,8 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpPost("disbandclub")] - public string DisbandClub([FromQuery] long? uid = null) + [HttpPost("clubdisband")] + public string ClubDisband([FromQuery] long? uid = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); @@ -4924,7 +5030,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return $"不存在编号为 {clubid} 的社团!"; } - if (club.Master?.Id != userid) + if (club.Master.Id != userid) { return $"你不是社团的社长,没有权限使用此指令!"; } @@ -4934,6 +5040,7 @@ namespace Oshima.FunGame.WebAPI.Controllers try { System.IO.File.Delete(path); + FunGameConstant.ClubIdAndClub.Remove(club.Id); msg = $"解散社团 [ {club.Name} ] 成功!"; pc.Add("club", 0); FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user); @@ -4950,6 +5057,7 @@ namespace Oshima.FunGame.WebAPI.Controllers User user2 = FunGameService.GetUser(pc2); pc2.Add("club", 0); FunGameService.SetUserConfig(fileName, pc2, user2); + FunGameService.AddNotice(user2.Id, $"【社团通知】社长 [ {user.Username} ] 已经解散了社团【{club}】。"); } else { @@ -4971,8 +5079,8 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpPost("approveclub")] - public string ApproveClub([FromQuery] long? uid = null, [FromQuery] long? id = null, [FromQuery] bool? approval = null) + [HttpPost("clubapprove")] + public string ClubApprove([FromQuery] long? uid = null, [FromQuery] long? id = null, [FromQuery] bool? approval = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); long applicant = id ?? 0; @@ -4996,7 +5104,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return $"你当前没有加入任何社团!"; } - if (club.Master?.Id == userid || club.Admins.ContainsKey(userid)) + if (club.Master.Id == userid || club.Admins.ContainsKey(userid)) { PluginConfig pc2 = FunGameService.GetUserConfig(applicant, out _); if (pc2.ContainsKey("user")) @@ -5016,6 +5124,7 @@ namespace Oshima.FunGame.WebAPI.Controllers { pc2.Add("club", userClub); FunGameService.SetUserConfigAndReleaseSemaphoreSlim(applicant, pc2, user2); + FunGameService.AddNotice(user2.Id, $"【社团通知】管理员 [ {user.Username} ] 已批准你加入社团【{club}】。"); } else { @@ -5025,10 +5134,12 @@ namespace Oshima.FunGame.WebAPI.Controllers else { msg += $"已拒绝 [ {user2.Username} ] 加入社团 [ {club.Name} ] !"; + FunGameService.AddNotice(user2.Id, $"【社团通知】管理员 [ {user.Username} ] 已拒绝你加入社团【{club}】。"); } emc.Add("club", club); emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; } else { @@ -5060,8 +5171,91 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpPost("kickclub")] - public string KickClub([FromQuery] long? uid = null, [FromQuery] long? id = null) + [HttpPost("clubinvite")] + public string ClubInvite([FromQuery] long? uid = null, [FromQuery] long? id = null, [FromQuery] bool cancel = false) + { + long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + long invitee = id ?? 0; + + PluginConfig pc = FunGameService.GetUserConfig(userid, out _); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user); + + string msg = ""; + if (pc.TryGetValue("club", out object? value) && long.TryParse(value.ToString(), out long userClub) && userClub != 0) + { + EntityModuleConfig emc = new("clubs", userClub.ToString()); + emc.LoadConfig(); + Club? club = emc.Get("club"); + if (club is null) + { + return $"你当前没有加入任何社团!"; + } + + if (club.Master.Id == userid || club.Admins.ContainsKey(userid)) + { + PluginConfig pc2 = FunGameService.GetUserConfig(invitee, out _); + if (pc2.ContainsKey("user")) + { + User user2 = FunGameService.GetUser(pc2); + + if (!club.Members.ContainsKey(user2.Id)) + { + if (!cancel) + { + club.InvitedTime[invitee] = DateTime.Now; + club.Invitees[invitee] = user2; + msg += $"已向 [ {user2.Username} ] 发出社团邀请!"; + FunGameService.AddNotice(user2.Id, $"【社团通知】社团【{club}】向你发出了邀请!请使用【加入社团{club.Id}】指令加入此社团。"); + } + else + { + club.InvitedTime.Remove(invitee); + club.Invitees.Remove(invitee); + msg += $"已取消对 [ {user2.Username} ] 的社团邀请!"; + FunGameService.AddNotice(user2.Id, $"【社团通知】社团【{club}】不再邀请你加入,接受指令已不可用。"); + } + + emc.Add("club", club); + emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; + FunGameService.ReleaseUserSemaphoreSlim(invitee); + } + else + { + FunGameService.ReleaseUserSemaphoreSlim(invitee); + return $"对方已经是社团成员!"; + } + } + else + { + FunGameService.ReleaseUserSemaphoreSlim(invitee); + return $"对方似乎还没创建存档呢!"; + } + } + else + { + return $"你没有邀请权限!"; + } + } + else + { + return $"你当前没有加入任何社团!"; + } + return msg; + } + else + { + FunGameService.ReleaseUserSemaphoreSlim(userid); + return noSaved; + } + } + + [HttpPost("clubkick")] + public string ClubKick([FromQuery] long? uid = null, [FromQuery] long? id = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); long kickid = id ?? 0; @@ -5084,9 +5278,9 @@ namespace Oshima.FunGame.WebAPI.Controllers return $"你当前没有加入任何社团!"; } - if (club.Master?.Id == userid || club.Admins.ContainsKey(userid)) + if (club.Master.Id == userid || club.Admins.ContainsKey(userid)) { - if (!club.Admins.ContainsKey(kickid) || (club.Master?.Id == userid && club.Admins.ContainsKey(kickid))) + if (!club.Admins.ContainsKey(kickid) || (club.Master.Id == userid && club.Admins.ContainsKey(kickid))) { PluginConfig pc2 = FunGameService.GetUserConfig(kickid, out _); if (pc2.ContainsKey("user")) @@ -5101,9 +5295,11 @@ namespace Oshima.FunGame.WebAPI.Controllers msg += $"操作成功,已将 [ {user2.Username} ] 踢出社团 [ {club.Name} ] !"; pc2.Add("club", 0); FunGameService.SetUserConfigAndReleaseSemaphoreSlim(kickid, pc2, user2); + FunGameService.AddNotice(user2.Id, $"【社团通知】管理员 [ {user.Username} ] 已将你移出社团【{club}】。"); emc.Add("club", club); emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; } else { @@ -5140,8 +5336,8 @@ namespace Oshima.FunGame.WebAPI.Controllers } } - [HttpPost("changeclub")] - public string ChangeClub([FromQuery] long? uid = null, [FromQuery] string? part = null, [FromBody] string[]? args = null) + [HttpPost("clubchange")] + public string ClubChange([FromQuery] long? uid = null, [FromQuery] string? part = null, [FromBody] string[]? args = null) { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); string name = part?.Trim().ToLower() ?? ""; @@ -5166,7 +5362,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return $"你当前没有加入任何社团!"; } - bool isMaster = club.Master?.Id == userid; + bool isMaster = club.Master.Id == userid; bool isAdmin = club.Admins.ContainsKey(userid); if (isMaster || isAdmin) @@ -5180,10 +5376,39 @@ namespace Oshima.FunGame.WebAPI.Controllers } if (values.Length > 0) { - if (values[0].Length >= 2 && values[0].Length <= 10) + string newName = string.Join(" ", values); + if (newName.Length >= 2 && newName.Length <= 15) { - club.Name = values[0]; - msg = "修改成功,新的社团名称是:" + club.Name; + if (FunGameConstant.ClubIdAndClub.Any(kv => kv.Value.Name == newName)) + { + return $"社团名称【{newName}】已被使用,请更换其他名称!"; + } + else + { + PluginConfig renameExamine = new("examines", "clubrename"); + renameExamine.LoadConfig(); + List strings = renameExamine.Get>(club.Id.ToString()) ?? []; + if (strings.Count > 0) + { + return $"该社团已经提交过改名申请,请使用【查询改名】指令查看进度,请耐心等待审核结果!"; + } + else + { + renameExamine.Add(club.Id.ToString(), new List { newName }); + renameExamine.SaveConfig(); + } + + TaskUtility.NewTask(() => + { + User[] operators = [.. FunGameConstant.UserIdAndUsername.Values.Where(u => u.IsAdmin || u.IsOperator)]; + foreach (User op in operators) + { + FunGameService.AddNotice(op.Id, $"有待处理的改名申请,请使用【改名审核】指令查看列表!"); + } + }); + + return $"提交社团改名申请成功!新的社团名称是【{newName}】,将在审核通过后更新。"; + } } else { @@ -5194,7 +5419,6 @@ namespace Oshima.FunGame.WebAPI.Controllers { return "请提供新的社团名称!"; } - break; case "prefix": if (!isMaster) { @@ -5309,6 +5533,7 @@ namespace Oshima.FunGame.WebAPI.Controllers emc.Add("club", club); emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; } else { @@ -5328,6 +5553,79 @@ namespace Oshima.FunGame.WebAPI.Controllers } } + [HttpPost("clubcontribution")] + public string ClubContribution([FromQuery] long uid = -1, [FromQuery] double credits = 0) + { + if (credits <= 0) + { + return $"{General.GameplayEquilibriumConstant.InGameCurrency}数量必须大于 0。"; + } + try + { + PluginConfig pc = FunGameService.GetUserConfig(uid, out bool isTimeout); + if (isTimeout) + { + return busy; + } + + long clubid = 0; + if (pc.TryGetValue("club", out object? value) && long.TryParse(value.ToString(), out long temp)) + { + clubid = temp; + } + + if (clubid == 0) + { + return $"你当前没有加入任何社团!"; + } + + EntityModuleConfig emc = new("clubs", clubid.ToString()); + emc.LoadConfig(); + Club? club = emc.Get("club"); + if (club is null) + { + return $"不存在编号为 {clubid} 的社团!"; + } + + string msg = ""; + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + if (user.Inventory.Credits >= credits) + { + user.Inventory.Credits -= credits; + club.ClubPoins += credits; + msg = $"你向社团【{club}】捐献了 {credits:0.##} {General.GameplayEquilibriumConstant.InGameCurrency},社团基金增加至 {club.ClubPoins:0.##}!"; + + emc.Add("club", club); + emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; + } + else + { + msg = $"你的 {General.GameplayEquilibriumConstant.InGameCurrency} 不足,无法捐献!"; + } + + FunGameService.SetUserConfigButNotRelease(uid, pc, user); + return msg; + } + else + { + return noSaved; + } + } + catch (Exception e) + { + Logger.LogError(e, "Error: {e}", e); + return busy; + } + finally + { + FunGameService.ReleaseUserSemaphoreSlim(uid); + } + } + [HttpPost("showdailystore")] public string ShowDailyStore([FromQuery] long? uid = null) { @@ -5616,7 +5914,7 @@ namespace Oshima.FunGame.WebAPI.Controllers } [HttpPost("exploreregion")] - public (string, string) ExploreRegion([FromQuery] long? uid = null, [FromQuery] long? id = null, [FromBody] long[]? cids = null) + public (string, string) ExploreRegion([FromQuery] long? uid = null, [FromQuery] long? id = null, [FromQuery] bool useSquad = false, [FromBody] long[]? cids = null) { string exploreId = ""; try @@ -5633,6 +5931,20 @@ namespace Oshima.FunGame.WebAPI.Controllers { User user = FunGameService.GetUser(pc); + if (useSquad) + { + if (user.Inventory.Squad.Count == 0) + { + FunGameService.ReleaseUserSemaphoreSlim(userid); + return ($"你尚未设置小队,请先设置1-4名角色!", exploreId); + } + else + { + characterIds = [.. user.Inventory.Squad]; + characterCount = characterIds.Length; + } + } + // 检查角色存在 List invalid = []; foreach (long cid in characterIds) @@ -6654,7 +6966,7 @@ namespace Oshima.FunGame.WebAPI.Controllers double gained = item.Price; totalGained += gained; successCount++; - msgs.Add($"物品 {itemIndex}. {item.Name} 出售成功,获得了 {gained} {General.GameplayEquilibriumConstant.InGameCurrency}。"); + msgs.Add($"物品 {itemIndex}. {item.Name} 出售成功,获得了 {gained:0.##} {General.GameplayEquilibriumConstant.InGameCurrency}。"); } } @@ -6696,13 +7008,34 @@ namespace Oshima.FunGame.WebAPI.Controllers PluginConfig renameExamine = new("examines", "rename"); renameExamine.LoadConfig(); - List strings = renameExamine.Get>(user.Id.ToString()) ?? []; - if (strings.Count > 0) + List strings1 = renameExamine.Get>(user.Id.ToString()) ?? []; + + long clubid = 0; + if (pc.TryGetValue("club", out object? value) && long.TryParse(value.ToString(), out long temp)) { - string name = strings[0]; + clubid = temp; + } + PluginConfig renameExamineClub = new("examines", "clubrename"); + renameExamineClub.LoadConfig(); + List strings2 = renameExamineClub.Get>(clubid.ToString()) ?? []; + + if (strings1.Count > 0) + { + string name = strings1[0]; msg = $"你提交的新昵称为【{name}】,正在审核中,请耐心等待。"; } - else + + if (strings2.Count > 0) + { + string name = strings2[0]; + if (FunGameConstant.ClubIdAndClub.TryGetValue(clubid, out Club? club) && (club.Master.Id == userid || club.Admins.ContainsKey(userid))) + { + if (msg != "") msg += "\r\n"; + msg += $"你所属社团【{club}】提交的新名称【{name}】,正在审核中,请耐心等待。"; + } + } + + if (msg == "") { msg = $"你目前没有已提交的改名申请。"; } @@ -6740,19 +7073,23 @@ namespace Oshima.FunGame.WebAPI.Controllers PluginConfig renameExamine = new("examines", "rename"); renameExamine.LoadConfig(); - if (renameExamine.Count > 0) + PluginConfig renameExamineClub = new("examines", "clubrename"); + renameExamineClub.LoadConfig(); + + string[] ids = [.. renameExamine.Keys, .. renameExamineClub.Keys.Select(s => $"club{s}")]; + if (ids.Length > 0) { StringBuilder builder = new(); builder.AppendLine($"☆--- 自定义改名申请列表 ---☆"); int count = 1; - int maxPage = (int)Math.Ceiling((double)renameExamine.Count / FunGameConstant.ItemsPerPage2); + int maxPage = (int)Math.Ceiling((double)ids.Length / FunGameConstant.ItemsPerPage2); if (maxPage < 1) maxPage = 1; if (showPage <= maxPage) { - string[] userIds = [.. FunGameService.GetPage(renameExamine.Keys, showPage, FunGameConstant.ItemsPerPage2)]; - foreach (string uidStr2 in userIds) + ids = [.. FunGameService.GetPage(ids, showPage, FunGameConstant.ItemsPerPage2)]; + foreach (string id in ids) { - if (long.TryParse(uidStr2, out long uid2)) + if (long.TryParse(id, out long uid2)) { List strings = renameExamine.Get>(uid2.ToString()) ?? []; if (strings.Count > 0 && FunGameConstant.UserIdAndUsername.TryGetValue(uid2, out User? user2) && user2 != null) @@ -6764,6 +7101,22 @@ namespace Oshima.FunGame.WebAPI.Controllers count++; } } + else if (id.StartsWith("club")) + { + string cid = id.Replace("club", "").Trim(); + if (long.TryParse(cid, out long clubid)) + { + List strings = renameExamineClub.Get>(clubid.ToString()) ?? []; + if (strings.Count > 0 && FunGameConstant.ClubIdAndClub.TryGetValue(clubid, out Club? club) && club != null) + { + builder.AppendLine($"{count}."); + builder.AppendLine($"社团编号:{club.Id}"); + builder.AppendLine($"社团名称:{club.Name}"); + builder.AppendLine($"新名称:{strings[0]}"); + count++; + } + } + } } builder.AppendLine($"页数:{showPage} / {maxPage}"); } @@ -6798,7 +7151,7 @@ namespace Oshima.FunGame.WebAPI.Controllers } [HttpPost("approverename")] - public string ApproveReName([FromQuery] long? uid = null, [FromQuery] long target = -1, [FromQuery] bool approve = true) + public string ApproveReName([FromQuery] long? uid = null, [FromQuery] long target = -1, [FromQuery] bool approve = true, [FromQuery] bool isClub = false, [FromQuery] string reason = "") { long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); @@ -6819,71 +7172,118 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(userid); } - if (user.IsAdmin) + if (user.IsAdmin || user.IsOperator) { - PluginConfig renameExamine = new("examines", "rename"); - renameExamine.LoadConfig(); - List strings = renameExamine.Get>(target.ToString()) ?? []; - if (strings.Count > 0) + if (isClub) { - PluginConfig pc2 = FunGameService.GetUserConfig(target, out _); - - if (pc2.Count > 0) + PluginConfig renameExamineClub = new("examines", "clubrename"); + renameExamineClub.LoadConfig(); + List strings = renameExamineClub.Get>(target.ToString()) ?? []; + if (strings.Count > 0) { - string name = strings[0]; - User user2 = FunGameService.GetUser(pc2); - // 移除改名卡 - Item? gmk = user2.Inventory.Items.FirstOrDefault(i => i.Guid.ToString() == strings[1]); - if (gmk != null) + EntityModuleConfig emc = new("clubs", target.ToString()); + emc.LoadConfig(); + Club? club = emc.Get("club"); + if (club != null) { + string name = strings[0]; if (approve) { - user2.Username = name; - user2.NickName = name; - if (user2.Inventory.Characters.FirstOrDefault(c => c.Id == FunGameConstant.CustomCharacterId) is Character character) + club.Name = name; + renameExamineClub.Remove(target.ToString()); + msg = $"已批准该社团的新名称【{name}】申请!"; + emc.Add("club", club); + emc.SaveConfig(); + FunGameConstant.ClubIdAndClub[club.Id] = club; + foreach (long noticeUserId in club.Admins.Keys.Union([club.Master.Id])) { - character.Name = user2.Username; - character.NickName = user2.NickName; + FunGameService.AddNotice(noticeUserId, $"【改名系统】你的社团新名称 [ {name} ] 审核通过,社团名称已更新!"); } - if (user2.Inventory.Name.EndsWith("的库存")) - { - user2.Inventory.Name = user2.Username + "的库存"; - } - user2.Inventory.Items.Remove(gmk); - FunGameConstant.UserIdAndUsername[user2.Id] = user2; - renameExamine.Remove(target.ToString()); - msg = $"该用户的新昵称【{name}】已审核通过!"; - FunGameService.AddNotice(user2.Id, $"改名系统通知:你先前提交的新昵称【{name}】审核通过,已更新你的昵称!已消耗 1 张改名卡。"); } else { - gmk.IsLock = false; - renameExamine.Remove(target.ToString()); - msg = $"已拒绝该用户的新昵称【{name}】申请!"; - FunGameService.AddNotice(user2.Id, $"改名系统通知:你先前提交的新昵称【{name}】审核不通过,请重新提交申请!"); + renameExamineClub.Remove(target.ToString()); + msg = $"已拒绝该社团的新名称【{name}】申请!"; + foreach (long noticeUserId in club.Admins.Keys.Union([club.Master.Id])) + { + FunGameService.AddNotice(noticeUserId, $"【改名系统】你的社团新名称 [ {name} ] 审核不通过,请重新提交申请!{(reason != "" ? $"原因:{reason}" : "")}"); + } + } + } + else + { + renameExamineClub.Remove(target.ToString()); + msg = $"该社团不存在。"; + } + } + renameExamineClub.SaveConfig(); + } + else + { + PluginConfig renameExamine = new("examines", "rename"); + renameExamine.LoadConfig(); + List strings = renameExamine.Get>(target.ToString()) ?? []; + if (strings.Count > 0) + { + PluginConfig pc2 = FunGameService.GetUserConfig(target, out _); + + if (pc2.Count > 0) + { + string name = strings[0]; + User user2 = FunGameService.GetUser(pc2); + // 移除改名卡 + Item? gmk = user2.Inventory.Items.FirstOrDefault(i => i.Guid.ToString() == strings[1]); + if (gmk != null) + { + if (approve) + { + user2.Username = name; + user2.NickName = name; + if (user2.Inventory.Characters.FirstOrDefault(c => c.Id == FunGameConstant.CustomCharacterId) is Character character) + { + character.Name = user2.Username; + character.NickName = user2.NickName; + } + if (user2.Inventory.Name.EndsWith("的库存")) + { + user2.Inventory.Name = user2.Username + "的库存"; + } + user2.Inventory.Items.Remove(gmk); + FunGameConstant.UserIdAndUsername[user2.Id] = user2; + renameExamine.Remove(target.ToString()); + msg = $"该用户的新昵称【{name}】已审核通过!"; + FunGameService.AddNotice(user2.Id, $"【改名系统】你先前提交的新昵称【{name}】审核通过,已更新你的昵称!已消耗 1 张改名卡。"); + } + else + { + gmk.IsLock = false; + renameExamine.Remove(target.ToString()); + msg = $"已拒绝该用户的新昵称【{name}】申请!"; + FunGameService.AddNotice(user2.Id, $"【改名系统】你先前提交的新昵称【{name}】审核不通过,请重新提交申请!{(reason != "" ? $"原因:{reason}" : "")}"); + } + FunGameService.SetUserConfigButNotRelease(target, pc2, user2); + } + else + { + renameExamine.Remove(target.ToString()); + msg = $"该用户用于申请自定义改名的改名卡已不存在,改名失败!"; + FunGameService.AddNotice(user2.Id, $"【改名系统】你先前提交的新昵称【{name}】因用于申请自定义改名的改名卡已不存在,改名失败!"); } - FunGameService.SetUserConfigButNotRelease(target, pc2, user2); } else { renameExamine.Remove(target.ToString()); - msg = $"该用户用于申请自定义改名的改名卡已不存在,改名失败!"; - FunGameService.AddNotice(user2.Id, $"改名系统通知:你先前提交的新昵称【{name}】因用于申请自定义改名的改名卡已不存在,改名失败!"); + msg = $"该用户不存在。"; } + FunGameService.ReleaseUserSemaphoreSlim(target); } else { renameExamine.Remove(target.ToString()); - msg = $"该用户不存在。"; + msg = $"该用户目前没有已提交的改名申请。"; } - FunGameService.ReleaseUserSemaphoreSlim(target); + renameExamine.SaveConfig(); } - else - { - renameExamine.Remove(target.ToString()); - msg = $"该用户目前没有已提交的改名申请。"; - } - renameExamine.SaveConfig(); } else { @@ -6939,9 +7339,9 @@ namespace Oshima.FunGame.WebAPI.Controllers List successItems = []; foreach (int itemIndex in itemIndexs) { - if (itemIndex > 0 && itemIndex <= user.Inventory.Items.Count) + if (itemIndex > 0 && itemIndex <= dict.Count) { - Item item = user.Inventory.Items.ToList()[itemIndex - 1]; + Item item = dict[itemIndex]; if (item.IsLock) { @@ -7015,7 +7415,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return busy; } } - + [HttpPost("marketshowlist")] public string MarketShowList([FromQuery] long userid = -1, [FromQuery] int page = 0) { @@ -7053,7 +7453,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return busy; } } - + [HttpPost("marketshowlistmysells")] public string MarketShowListMySells([FromQuery] long userid = -1, [FromQuery] int page = 0) { @@ -7105,7 +7505,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return busy; } } - + [HttpPost("marketiteminfo")] public string MarketItemInfo([FromQuery] long userid = -1, [FromQuery] long itemid = 0) { @@ -7151,7 +7551,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return busy; } } - + [HttpPost("marketbuyitem")] public string MarketBuyItem([FromQuery] long userid = -1, [FromQuery] long itemid = 0, [FromQuery] int count = 1) { @@ -7221,7 +7621,7 @@ namespace Oshima.FunGame.WebAPI.Controllers return busy; } } - + [HttpPost("marketdelistitem")] public string MarketDelistItem([FromQuery] long userid = -1, [FromQuery] long itemid = 0) { @@ -7554,7 +7954,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + [HttpPost("forgeitemmaster")] public string ForgeItem_Master([FromQuery] long uid = -1, [FromQuery] long rid = 0, [FromQuery] int q = 0) { @@ -7621,7 +8021,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + [HttpGet("forgeiteminfo")] public string ForgeItem_Info([FromQuery] long uid = -1) { @@ -7726,7 +8126,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + [HttpPost("forgeitemsimulate")] public string ForgeItem_Simulate([FromQuery] long uid = -1) { @@ -7774,7 +8174,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + [HttpPost("forgeitemcomplete")] public string ForgeItem_Complete([FromQuery] long uid = -1) { @@ -7924,7 +8324,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + [HttpPost("chatname")] public string Chat_Name([FromQuery] long uid = -1, [FromQuery] string name = "", [FromQuery] string msgTo = "") { @@ -7941,12 +8341,12 @@ namespace Oshima.FunGame.WebAPI.Controllers { return "未输入目标玩家的昵称。"; } - + if (msgTo == "") { return "发送了空信息。"; } - + if (msgTo.Length > 30) { return "超过 30 字符。"; @@ -7989,9 +8389,9 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - - [HttpPost("createroom")] - public string CreateRoom([FromQuery] long uid = -1, [FromQuery] string roomType = "", [FromQuery] string password = "", [FromQuery] string groupId = "") + + [HttpPost("roomcreate")] + public string RoomCreate([FromQuery] long uid = -1, [FromQuery] string roomType = "", [FromQuery] string password = "", [FromQuery] string groupId = "") { try { @@ -8033,9 +8433,9 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - - [HttpPost("intoroom")] - public string IntoRoom([FromQuery] long uid = -1, [FromQuery] string roomid = "", [FromQuery] string password = "") + + [HttpPost("roominto")] + public string RoomInto([FromQuery] long uid = -1, [FromQuery] string roomid = "", [FromQuery] string password = "") { try { @@ -8070,9 +8470,9 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - - [HttpPost("quitroom")] - public string QuitRoom([FromQuery] long uid = -1) + + [HttpPost("roomquit")] + public string RoomQuit([FromQuery] long uid = -1) { try { @@ -8107,7 +8507,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + [HttpPost("roominfo")] public string RoomInfo([FromQuery] long uid = -1) { @@ -8144,9 +8544,50 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - - [HttpPost("rungame")] - public async Task<(Room, List)> RunGame([FromQuery] long uid = -1) + + [HttpGet("roomshowlist")] + public string RoomShowList([FromQuery] long uid = -1, [FromQuery] string groupId = "") + { + try + { + PluginConfig pc = FunGameService.GetUserConfig(uid, out bool isTimeout); + if (isTimeout) + { + return busy; + } + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + StringBuilder builder = new(); + builder.AppendLine($"☆--- 本群在线房间列表 ---☆"); + foreach (Room room in FunGameConstant.Rooms.Values.Where(r => r.GameMap == groupId)) + { + builder.AppendLine(OnlineService.RoomInfo(room)); + } + + FunGameService.SetUserConfigButNotRelease(uid, pc, user); + return builder.ToString().Trim(); + } + else + { + return noSaved; + } + } + catch (Exception e) + { + Logger.LogError(e, "Error: {e}", e); + return busy; + } + finally + { + FunGameService.ReleaseUserSemaphoreSlim(uid); + } + } + + [HttpPost("roomrungame")] + public async Task<(Room, List)> RoomRunGame([FromQuery] long uid = -1) { Room room = General.HallInstance; try @@ -8161,7 +8602,7 @@ namespace Oshima.FunGame.WebAPI.Controllers if (pc.Count > 0) { User user = FunGameService.GetUser(pc); - FunGameService.SetUserConfigButNotRelease(uid, pc, user); + FunGameService.SetUserConfigAndReleaseSemaphoreSlim(uid, pc, user); (room, msgs) = await OnlineService.RunGameAsync(user); @@ -8182,7 +8623,7 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + [HttpGet("getranking")] public string GetRanking([FromQuery] long uid = -1, [FromQuery] int type = -1) { @@ -8255,7 +8696,7 @@ namespace Oshima.FunGame.WebAPI.Controllers score += value2; } return $"{index + 1}. UID:{kv.Key},昵称:{username},总得分:{score:0.##}"; - })) : "暂无任何数据。")}\r\n\r\n本榜单统计角色的经验值总额,并根据其普通和技能等级计算总得分。\r\n仅显示前 {showTop} 位{(currentTop > 0 ? $",你目前排在第 {currentTop} 位。" : "")}", + })) : "暂无任何数据。")}\r\n\r\n本榜单统计角色的经验值总额,并根据其普通攻击和技能的等级计算总得分。\r\n仅显示前 {showTop} 位{(currentTop > 0 ? $",你目前排在第 {currentTop} 位。" : "")}", 3 => $"【赛马积分排行榜】\r\n" + $"数据每分钟更新一次,上次更新:{FunGameConstant.RankingUpdateTime.ToString(General.GeneralDateTimeFormatChinese)}\r\n" + $"\r\n{(FunGameConstant.UserHorseRacingRanking.Count > 0 ? string.Join("\r\n", FunGameConstant.UserHorseRacingRanking. @@ -8272,6 +8713,38 @@ namespace Oshima.FunGame.WebAPI.Controllers } return $"{index + 1}. UID:{kv.Key},昵称:{username},赛马积分:{kv.Value}"; })) : "暂无任何数据。")}\r\n\r\n仅显示前 {showTop} 位{(currentTop > 0 ? $",你目前排在第 {currentTop} 位。" : "")}", + 4 => $"【共斗积分排行榜】\r\n" + + $"数据每分钟更新一次,上次更新:{FunGameConstant.RankingUpdateTime.ToString(General.GeneralDateTimeFormatChinese)}\r\n" + + $"\r\n{(FunGameConstant.UserCooperativeRanking.Count > 0 ? string.Join("\r\n", FunGameConstant.UserCooperativeRanking. + OrderByDescending(kv => kv.Value).Take(showTop).Select((kv, index) => + { + string username = "Unknown"; + if (FunGameConstant.UserIdAndUsername.TryGetValue(kv.Key, out User? value) && value != null) + { + username = value.Username; + } + if (kv.Key == user.Id) + { + currentTop = index + 1; + } + return $"{index + 1}. UID:{kv.Key},昵称:{username},共斗积分:{kv.Value}"; + })) : "暂无任何数据。")}\r\n\r\n仅显示前 {showTop} 位{(currentTop > 0 ? $",你目前排在第 {currentTop} 位。" : "")}", + 5 => $"【锻造积分排行榜】\r\n" + + $"数据每分钟更新一次,上次更新:{FunGameConstant.RankingUpdateTime.ToString(General.GeneralDateTimeFormatChinese)}\r\n" + + $"\r\n{(FunGameConstant.UserForgingRanking.Count > 0 ? string.Join("\r\n", FunGameConstant.UserForgingRanking. + OrderByDescending(kv => kv.Value).Take(showTop).Select((kv, index) => + { + string username = "Unknown"; + if (FunGameConstant.UserIdAndUsername.TryGetValue(kv.Key, out User? value) && value != null) + { + username = value.Username; + } + if (kv.Key == user.Id) + { + currentTop = index + 1; + } + return $"{index + 1}. UID:{kv.Key},昵称:{username},锻造积分:{kv.Value:0.##}"; + })) : "暂无任何数据。")}\r\n\r\n仅显示前 {showTop} 位{(currentTop > 0 ? $",你目前排在第 {currentTop} 位。" : "")}", _ => "不支持的查询。", }; FunGameService.SetUserConfigButNotRelease(uid, pc, user); @@ -8292,7 +8765,189 @@ namespace Oshima.FunGame.WebAPI.Controllers FunGameService.ReleaseUserSemaphoreSlim(uid); } } - + + [HttpPost("additemstocharacter")] + public string AddItemsToCharacter([FromQuery] long uid = -1, [FromQuery] int cid = -1, [FromBody] int[]? ids = null) + { + ids ??= []; + try + { + PluginConfig pc = FunGameService.GetUserConfig(uid, out bool isTimeout); + if (isTimeout) + { + return busy; + } + + string msg = ""; + if (pc.Count > 0) + { + using SQLHelper? sql = Factory.OpenFactory.GetSQLHelper(); + if (sql is null) + { + return busy; + } + User user = FunGameService.GetUser(pc); + + List msgs = []; + if (cid > 0 && cid <= user.Inventory.Characters.Count) + { + Character character = user.Inventory.Characters.ToList()[cid - 1]; + List itemTrading = []; + itemTrading = SQLService.GetUserItemGuids(sql, user.Id); + Dictionary dict = user.Inventory.Items.Select((item, index) => new { item, index }).ToDictionary(x => x.index + 1, x => x.item); + + List successItems = []; + foreach (int itemIndex in ids) + { + if (itemIndex > 0 && itemIndex <= dict.Count) + { + Item item = dict[itemIndex]; + + if (item.IsLock) + { + msgs.Add($"物品 {itemIndex}. {item.Name}:此物品已上锁。"); + } + + if (item.ItemType != ItemType.Consumable) + { + msgs.Add($"物品 {itemIndex}. {item.Name}:此物品不是消耗品类型。"); + } + + if (item.Character != null) + { + msgs.Add($"物品 {itemIndex}. {item.Name}:此物品已被 {item.Character} 装备中。"); + } + + if (itemTrading.Contains(item.Guid)) + { + msgs.Add($"物品 {itemIndex}. {item.Name}:此物品正在进行交易,请检查交易报价。"); + } + + if (msgs.Count == 0) + { + msgs.Add($"添加物品 {itemIndex}. {item.Name} 到角色 [ {character} ] 的背包中成功!"); + user.Inventory.Items.Remove(item); + character.Items.Add(item); + } + } + else + { + msgs.Add($"{itemIndex}. 没有找到与这个序号相对应的物品!"); + } + } + + if (successItems.Count == 0) + { + msgs.Add($"没有成功添加任何物品到角色背包中。请检查物品是否存在或是否满足条件。"); + } + } + else + { + msgs.Add("没有找到与这个序号相对应的角色!"); + } + + msg = string.Join("\r\n", msgs); + + FunGameService.SetUserConfigButNotRelease(uid, pc, user); + return msg; + } + else + { + return noSaved; + } + } + catch (Exception e) + { + Logger.LogError(e, "Error: {e}", e); + return busy; + } + finally + { + FunGameService.ReleaseUserSemaphoreSlim(uid); + } + } + + [HttpPost("removeitemsfromcharacter")] + public string RemoveItemsFromCharacter([FromQuery] long uid = -1, [FromQuery] int cid = -1, [FromBody] int[]? ids = null) + { + ids ??= []; + try + { + PluginConfig pc = FunGameService.GetUserConfig(uid, out bool isTimeout); + if (isTimeout) + { + return busy; + } + + string msg = ""; + if (pc.Count > 0) + { + using SQLHelper? sql = Factory.OpenFactory.GetSQLHelper(); + if (sql is null) + { + return busy; + } + User user = FunGameService.GetUser(pc); + + List msgs = []; + if (cid > 0 && cid <= user.Inventory.Characters.Count) + { + Character character = user.Inventory.Characters.ToList()[cid - 1]; + List itemTrading = []; + itemTrading = SQLService.GetUserItemGuids(sql, user.Id); + Dictionary dict = character.Items.Select((item, index) => new { item, index }).ToDictionary(x => x.index + 1, x => x.item); + + List successItems = []; + foreach (int itemIndex in ids) + { + if (itemIndex > 0 && itemIndex <= dict.Count) + { + Item item = dict[itemIndex]; + + if (msgs.Count == 0) + { + msgs.Add($"从角色 [ {character} ] 的背包中取回物品 {itemIndex}. {item.Name} 成功!"); + user.Inventory.Items.Add(item); + character.Items.Remove(item); + } + } + else + { + msgs.Add($"{itemIndex}. 没有找到与这个序号相对应的物品!"); + } + } + + if (successItems.Count == 0) + { + msgs.Add($"没有成功从角色背包中取回任何物品到库存。"); + } + } + else + { + msgs.Add("没有找到与这个序号相对应的角色!"); + } + + msg = string.Join("\r\n", msgs); + + FunGameService.SetUserConfigButNotRelease(uid, pc, user); + return msg; + } + else + { + return noSaved; + } + } + catch (Exception e) + { + Logger.LogError(e, "Error: {e}", e); + return busy; + } + finally + { + FunGameService.ReleaseUserSemaphoreSlim(uid); + } + } + [HttpPost("template")] public string Template([FromQuery] long uid = -1) { diff --git a/OshimaWebAPI/Services/RainBOTService.cs b/OshimaWebAPI/Services/RainBOTService.cs index c32deed..fdc1b4c 100644 --- a/OshimaWebAPI/Services/RainBOTService.cs +++ b/OshimaWebAPI/Services/RainBOTService.cs @@ -319,34 +319,7 @@ namespace Oshima.FunGame.WebAPI.Services { FunGameSimulation = true; List msgs = await Controller.GetTest(false, maxRespawnTimesMix: 0); - List real = []; - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count - 2; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 3) < perMergeLength) - { - remain = msgs.Count - i - 3; - } - else remain = perMergeLength; - } - } - if (msgs.Count > 2) - { - real.Add(msgs[^2]); - real.Add(msgs[^1]); - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -375,34 +348,7 @@ namespace Oshima.FunGame.WebAPI.Services { FunGameSimulation = true; List msgs = await Controller.GetTest(false, maxRespawnTimesMix: maxRespawnTimesMix); - List real = []; - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count - 2; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 3) < perMergeLength) - { - remain = msgs.Count - i - 3; - } - else remain = perMergeLength; - } - } - if (msgs.Count > 2) - { - real.Add(msgs[^2]); - real.Add(msgs[^1]); - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -432,38 +378,7 @@ namespace Oshima.FunGame.WebAPI.Services { FunGameSimulation = true; List msgs = await Controller.GetTest(false, true); - List real = []; - if (msgs.Count > 0) - { - real.Add(msgs[0]); - } - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 1; i < msgs.Count - 2; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 3) < perMergeLength) - { - remain = msgs.Count - i - 3; - } - else remain = perMergeLength; - } - } - if (msgs.Count > 2) - { - real.Add(msgs[^2]); - real.Add(msgs[^1]); - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -858,13 +773,22 @@ namespace Oshima.FunGame.WebAPI.Services { string detail = e.Detail.Replace("改名拒绝", "").Trim(); string msg = ""; - if (long.TryParse(detail, out long target)) + string[] strings = detail.Split(' ', StringSplitOptions.RemoveEmptyEntries); + if (strings.Length > 0) { - msg = Controller.ApproveReName(uid, target, false); - } - if (msg != "") - { - await SendAsync(e, "改名拒绝", msg); + string reason = ""; + if (strings.Length > 1) + { + reason = string.Join(" ", strings[1..]).Trim(); + } + if (long.TryParse(strings[0], out long target)) + { + msg = Controller.ApproveReName(uid, target, false, false, reason); + } + if (msg != "") + { + await SendAsync(e, "改名拒绝", msg); + } } return result; } @@ -884,6 +808,45 @@ namespace Oshima.FunGame.WebAPI.Services return result; } + if (e.Detail.StartsWith("社团改名拒绝")) + { + string detail = e.Detail.Replace("社团改名拒绝", "").Trim(); + string msg = ""; + string[] strings = detail.Split(' ', StringSplitOptions.RemoveEmptyEntries); + if (strings.Length > 0) + { + string reason = ""; + if (strings.Length > 1) + { + reason = string.Join(" ", strings[1..]).Trim(); + } + if (long.TryParse(strings[0], out long target)) + { + msg = Controller.ApproveReName(uid, target, false, true, reason); + } + if (msg != "") + { + await SendAsync(e, "社团改名拒绝", msg); + } + } + return result; + } + + if (e.Detail.StartsWith("社团改名批准")) + { + string detail = e.Detail.Replace("社团改名批准", "").Trim(); + string msg = ""; + if (long.TryParse(detail, out long target)) + { + msg = Controller.ApproveReName(uid, target, isClub: true); + } + if (msg != "") + { + await SendAsync(e, "社团改名批准", msg); + } + return result; + } + if (e.Detail.StartsWith("自定义改名")) { e.UseNotice = false; @@ -1691,45 +1654,7 @@ namespace Oshima.FunGame.WebAPI.Services { msgs = await Controller.FightCustom2(uid, detail.Trim(), true); } - List real = []; - if (msgs.Count > 2) - { - if (msgs.Count < 20) - { - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count - 1; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 2) < perMergeLength) - { - remain = msgs.Count - i - 2; - } - else remain = perMergeLength; - } - } - } - else - { - real.Add(string.Join("\r\n", msgs[^8..^2])); - } - real.Add(msgs[^2]); - real.Add(msgs[^1]); - } - else - { - real = msgs; - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -1751,37 +1676,7 @@ namespace Oshima.FunGame.WebAPI.Services { msgs = await Controller.FightCustom2(uid, detail.Trim(), false); } - List real = []; - if (msgs.Count > 2) - { - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count - 1; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 3) < perMergeLength) - { - remain = msgs.Count - i - 3; - } - else remain = perMergeLength; - } - } - real.Add(msgs[^1]); - } - else - { - real = msgs; - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -1803,45 +1698,7 @@ namespace Oshima.FunGame.WebAPI.Services { msgs = await Controller.FightCustomTeam2(uid, detail.Trim(), true); } - List real = []; - if (msgs.Count >= 3) - { - if (msgs.Count < 20) - { - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count - 1; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 3) < perMergeLength) - { - remain = msgs.Count - i - 3; - } - else remain = perMergeLength; - } - } - } - else - { - real.Add(msgs[^3]); - } - real.Add(msgs[^2]); - real.Add(msgs[^1]); - } - else - { - real = msgs; - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -1877,45 +1734,7 @@ namespace Oshima.FunGame.WebAPI.Services if (int.TryParse(detail.Trim(), out int index)) { msgs = await Controller.FightBossTeam(uid, index, true); - List real = []; - if (msgs.Count >= 3) - { - if (msgs.Count < 20) - { - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count - 1; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 3) < perMergeLength) - { - remain = msgs.Count - i - 3; - } - else remain = perMergeLength; - } - } - } - else - { - real.Add(msgs[^3]); - } - real.Add(msgs[^2]); - real.Add(msgs[^1]); - } - else - { - real = msgs; - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -1937,45 +1756,7 @@ namespace Oshima.FunGame.WebAPI.Services if (int.TryParse(detail.Trim(), out int index)) { msgs = await Controller.FightBoss(uid, index, true); - List real = []; - if (msgs.Count >= 3) - { - if (msgs.Count < 20) - { - int perMergeLength = msgs.Count > 7 ? 7 : msgs.Count - 1; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count - 1; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0) - { - real.Add(merge); - merge = ""; - if ((msgs.Count - i - 3) < perMergeLength) - { - remain = msgs.Count - i - 3; - } - else remain = perMergeLength; - } - } - } - else - { - real.Add(msgs[^3]); - } - real.Add(msgs[^2]); - real.Add(msgs[^1]); - } - else - { - real = msgs; - } - if (real.Count >= 3) - { - real = real[^3..]; - } + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -2043,7 +1824,35 @@ namespace Oshima.FunGame.WebAPI.Services string detail = e.Detail.Replace("加入社团", "").Trim(); if (int.TryParse(detail, out int c)) { - string msg = Controller.JoinClub(uid, c); + string msg = Controller.ClubJoin(uid, c); + if (msg != "") + { + await SendAsync(e, "社团", msg); + } + } + return result; + } + + if (e.Detail.StartsWith("邀请加入", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.Detail.Replace("邀请加入", "").Trim(); + if (int.TryParse(detail, out int id)) + { + string msg = Controller.ClubInvite(uid, id); + if (msg != "") + { + await SendAsync(e, "社团", msg); + } + } + return result; + } + + if (e.Detail.StartsWith("取消邀请加入", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.Detail.Replace("取消邀请加入", "").Trim(); + if (int.TryParse(detail, out int id)) + { + string msg = Controller.ClubInvite(uid, id, true); if (msg != "") { await SendAsync(e, "社团", msg); @@ -2061,7 +1870,7 @@ namespace Oshima.FunGame.WebAPI.Services isPublic = false; } detail = detail.Replace("私密", "").Trim(); - string msg = Controller.CreateClub(uid, isPublic, detail); + string msg = Controller.ClubCreate(uid, isPublic, detail); if (msg != "") { await SendAsync(e, "社团", msg); @@ -2071,7 +1880,7 @@ namespace Oshima.FunGame.WebAPI.Services if (e.Detail == "退出社团") { - string msg = Controller.QuitClub(uid); + string msg = Controller.ClubQuit(uid); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2081,7 +1890,7 @@ namespace Oshima.FunGame.WebAPI.Services if (e.Detail == "我的社团") { - string msg = Controller.ShowClubInfo(uid); + string msg = Controller.ClubShowInfo(uid); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2089,9 +1898,28 @@ namespace Oshima.FunGame.WebAPI.Services return result; } + if (e.Detail.StartsWith("社团列表")) + { + string detail = e.Detail.Replace("社团列表", "").Trim(); + string msg = ""; + if (int.TryParse(detail, out int page)) + { + msg = Controller.ClubShowList(uid, page); + } + else + { + msg = Controller.ClubShowList(uid, 1); + } + if (msg.Trim() != "") + { + await SendAsync(e, "社团", msg); + } + return result; + } + if (e.Detail == "解散社团") { - string msg = Controller.DisbandClub(uid); + string msg = Controller.ClubDisband(uid); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2104,7 +1932,7 @@ namespace Oshima.FunGame.WebAPI.Services string detail = e.Detail.Replace("查看社团成员", "").Trim(); if (int.TryParse(detail, out int page) && page > 0) { - string msg = Controller.ShowClubMemberList(uid, 0, page); + string msg = Controller.ClubShowMemberList(uid, 0, page); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2112,7 +1940,7 @@ namespace Oshima.FunGame.WebAPI.Services } else { - string msg = Controller.ShowClubMemberList(uid, 0, 1); + string msg = Controller.ClubShowMemberList(uid, 0, 1); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2126,7 +1954,7 @@ namespace Oshima.FunGame.WebAPI.Services string detail = e.Detail.Replace("查看社团管理", "").Trim(); if (int.TryParse(detail, out int page) && page > 0) { - string msg = Controller.ShowClubMemberList(uid, 1, page); + string msg = Controller.ClubShowMemberList(uid, 1, page); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2134,7 +1962,7 @@ namespace Oshima.FunGame.WebAPI.Services } else { - string msg = Controller.ShowClubMemberList(uid, 1, 1); + string msg = Controller.ClubShowMemberList(uid, 1, 1); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2148,7 +1976,7 @@ namespace Oshima.FunGame.WebAPI.Services string detail = e.Detail.Replace("查看申请人列表", "").Trim(); if (int.TryParse(detail, out int page) && page > 0) { - string msg = Controller.ShowClubMemberList(uid, 2, page); + string msg = Controller.ClubShowMemberList(uid, 2, page); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2156,7 +1984,29 @@ namespace Oshima.FunGame.WebAPI.Services } else { - string msg = Controller.ShowClubMemberList(uid, 2, 1); + string msg = Controller.ClubShowMemberList(uid, 2, 1); + if (msg != "") + { + await SendAsync(e, "社团", "\r\n" + msg); + } + } + return result; + } + + if (e.Detail.StartsWith("查看受邀人列表")) + { + string detail = e.Detail.Replace("查看受邀人列表", "").Trim(); + if (int.TryParse(detail, out int page) && page > 0) + { + string msg = Controller.ClubShowMemberList(uid, 3, page); + if (msg != "") + { + await SendAsync(e, "社团", "\r\n" + msg); + } + } + else + { + string msg = Controller.ClubShowMemberList(uid, 3, 1); if (msg != "") { await SendAsync(e, "社团", "\r\n" + msg); @@ -2170,7 +2020,7 @@ namespace Oshima.FunGame.WebAPI.Services string detail = e.Detail.Replace("社团批准", "").Replace("@", "").Trim(); if (long.TryParse(detail, out long id)) { - string msg = Controller.ApproveClub(uid, id, true); + string msg = Controller.ClubApprove(uid, id, true); if (msg != "") { await SendAsync(e, "社团", msg); @@ -2184,7 +2034,7 @@ namespace Oshima.FunGame.WebAPI.Services string detail = e.Detail.Replace("社团拒绝", "").Replace("@", "").Trim(); if (long.TryParse(detail, out long id)) { - string msg = Controller.ApproveClub(uid, id, false); + string msg = Controller.ClubApprove(uid, id, false); if (msg != "") { await SendAsync(e, "社团", msg); @@ -2198,7 +2048,7 @@ namespace Oshima.FunGame.WebAPI.Services string detail = e.Detail.Replace("社团踢出", "").Replace("@", "").Trim(); if (long.TryParse(detail, out long id)) { - string msg = Controller.KickClub(uid, id); + string msg = Controller.ClubKick(uid, id); if (msg != "") { await SendAsync(e, "社团", msg); @@ -2230,7 +2080,7 @@ namespace Oshima.FunGame.WebAPI.Services { args = [.. strings[1..]]; } - string msg = Controller.ChangeClub(uid, part, [.. args]); + string msg = Controller.ClubChange(uid, part, [.. args]); if (msg != "") { await SendAsync(e, "社团", msg); @@ -2243,7 +2093,7 @@ namespace Oshima.FunGame.WebAPI.Services { string detail = e.Detail.Replace("社团转让", "").Replace("@", "").Trim(); List args = [detail]; - string msg = Controller.ChangeClub(uid, "setmaster", [.. args]); + string msg = Controller.ClubChange(uid, "setmaster", [.. args]); if (msg != "") { await SendAsync(e, "社团", msg); @@ -2251,6 +2101,21 @@ namespace Oshima.FunGame.WebAPI.Services return result; } + if (e.Detail.StartsWith("社团捐献")) + { + string detail = e.Detail.Replace("社团捐献", "").Trim(); + string msg = ""; + if (double.TryParse(detail, out double credits)) + { + msg = Controller.ClubContribution(uid, credits); + } + if (msg.Trim() != "") + { + await SendAsync(e, "社团", msg); + } + return result; + } + if (e.Detail == "每日商店") { string msg = Controller.ShowDailyStore(uid); @@ -2403,7 +2268,7 @@ namespace Oshima.FunGame.WebAPI.Services } if (cindexs.Count > 1 && cindexs.Count <= 5) { - (msg, eid) = Controller.ExploreRegion(uid, cindexs[0], [.. cindexs.Skip(1).Select(id => (long)id)]); + (msg, eid) = Controller.ExploreRegion(uid, cindexs[0], false, [.. cindexs.Skip(1).Select(id => (long)id)]); if (msg.Trim() != "") { await SendAsync(e, "探索", msg); @@ -2428,6 +2293,44 @@ namespace Oshima.FunGame.WebAPI.Services } return result; } + + if (e.Detail.StartsWith("小队探索")) + { + string detail = e.Detail.Replace("小队探索", "").Trim(); + string msg = ""; + string eid = ""; + string[] strings = detail.Split(FunGameConstant.SplitChars, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + List cindexs = []; + foreach (string s in strings) + { + if (int.TryParse(s, out int c)) + { + cindexs.Add(c); + } + } + if (cindexs.Count > 0) + { + (msg, eid) = Controller.ExploreRegion(uid, cindexs[0], true); + if (msg.Trim() != "") + { + await SendAsync(e, "探索", msg); + } + _ = Task.Run(async () => + { + await Task.Delay(FunGameConstant.ExploreTime * 60 * 1000); + msg = Controller.SettleExplore(eid, uid); + if (msg.Trim() != "") + { + await SendAsync(e, "探索", msg, msgSeq: 2); + } + }); + } + else + { + await SendAsync(e, "探索", "探索指令格式错误,正确格式为:小队探索 <地区序号>"); + } + return result; + } if (e.Detail == "生命之泉") { @@ -2971,6 +2874,16 @@ namespace Oshima.FunGame.WebAPI.Services } return result; } + + if (e.Detail == "共斗商店") + { + string msg = Controller.ShowSystemStore(uid, "铎京城", "dokyo_cooperative"); + if (msg.Trim() != "") + { + await SendAsync(e, "商店", msg); + } + return result; + } if (e.Detail.StartsWith("商店")) { @@ -2998,6 +2911,9 @@ namespace Oshima.FunGame.WebAPI.Services case 6: msg = Controller.ShowSystemStore(uid, "铎京城", "dokyo_horseracing"); break; + case 7: + msg = Controller.ShowSystemStore(uid, "铎京城", "dokyo_cooperative"); + break; default: break; } @@ -3301,7 +3217,7 @@ namespace Oshima.FunGame.WebAPI.Services } if (groupId != "") { - string msg = Controller.CreateRoom(uid, "horseracing", "", groupId); + string msg = Controller.RoomCreate(uid, "horseracing", "", groupId); if (msg.Trim() != "") { await SendAsync(e, "赛马", msg); @@ -3327,7 +3243,7 @@ namespace Oshima.FunGame.WebAPI.Services } if (groupId != "") { - string msg = Controller.CreateRoom(uid, "cooperative", "", groupId); + string msg = Controller.RoomCreate(uid, "cooperative", "", groupId); if (msg.Trim() != "") { await SendAsync(e, "房间", msg); @@ -3353,7 +3269,7 @@ namespace Oshima.FunGame.WebAPI.Services } if (groupId != "") { - string msg = Controller.CreateRoom(uid, "mix", "", groupId); + string msg = Controller.RoomCreate(uid, "mix", "", groupId); if (msg.Trim() != "") { await SendAsync(e, "房间", msg); @@ -3379,7 +3295,7 @@ namespace Oshima.FunGame.WebAPI.Services } if (groupId != "") { - string msg = Controller.CreateRoom(uid, "team", "", groupId); + string msg = Controller.RoomCreate(uid, "team", "", groupId); if (msg.Trim() != "") { await SendAsync(e, "房间", msg); @@ -3407,7 +3323,7 @@ namespace Oshima.FunGame.WebAPI.Services { if (FunGameConstant.Rooms.Values.FirstOrDefault(r => r.GameMap == groupId) is Room room) { - string msg = Controller.IntoRoom(uid, room.Roomid, ""); + string msg = Controller.RoomInto(uid, room.Roomid, ""); if (msg.Trim() != "") { await SendAsync(e, "赛马", msg); @@ -3450,7 +3366,7 @@ namespace Oshima.FunGame.WebAPI.Services password = detail[(firstSpaceIndex + 1)..].Trim(); } } - string msg = Controller.CreateRoom(uid, roomType, password, groupId); + string msg = Controller.RoomCreate(uid, roomType, password, groupId); if (msg.Trim() != "") { await SendAsync(e, "房间", msg); @@ -3488,7 +3404,7 @@ namespace Oshima.FunGame.WebAPI.Services password = detail[(firstSpaceIndex + 1)..].Trim(); } } - string msg = Controller.IntoRoom(uid, roomid, password); + string msg = Controller.RoomInto(uid, roomid, password); if (msg.Trim() != "") { await SendAsync(e, "房间", msg); @@ -3519,41 +3435,8 @@ namespace Oshima.FunGame.WebAPI.Services await SendAsync(e, "房间", "你不在房间中或者所在的房间不是赛马房间,请使用【开始游戏】指令。注意:只有房主才可以开始游戏。"); return result; } - (Room room, List msgs) = await Controller.RunGame(uid); - List real = []; - if (msgs.Count > 1) - { - if (msgs.Count > 20) - { - msgs = [msgs[0], .. msgs[^20..]]; - } - int perMergeLength = msgs.Count > 5 ? 5 : msgs.Count; - int remain = perMergeLength; - string merge = ""; - for (int i = 0; i < msgs.Count; i++) - { - remain--; - merge += msgs[i] + "\r\n"; - if (remain == 0 || i == msgs.Count - 1) - { - real.Add(merge); - merge = ""; - if (msgs.Count < perMergeLength) - { - remain = msgs.Count; - } - else remain = perMergeLength; - } - } - } - else - { - real = msgs; - } - if (real.Count >= 3) - { - real = [real[0], .. real[^2..]]; - } + (Room room, List msgs) = await Controller.RoomRunGame(uid); + List real = MergeMessages(msgs); int count = 1; foreach (string msg in real) { @@ -3582,7 +3465,33 @@ namespace Oshima.FunGame.WebAPI.Services } if (groupId != "") { - string msg = Controller.QuitRoom(uid); + string msg = Controller.RoomQuit(uid); + if (msg.Trim() != "") + { + await SendAsync(e, "房间", msg); + } + } + else + { + await SendAsync(e, "房间", "请在群聊中进行多人游戏。"); + } + return result; + } + + if (e.Detail == "房间列表") + { + string groupId = ""; + if (e.IsGroup && e is GroupAtMessage groupAtMessage && groupAtMessage.GroupOpenId != "") + { + groupId = groupAtMessage.GroupOpenId; + } + else if (e.IsGroup && e is ThirdPartyMessage thirdPartyMessage && thirdPartyMessage.GroupOpenId != "") + { + groupId = thirdPartyMessage.GroupOpenId; + } + if (groupId != "") + { + string msg = Controller.RoomShowList(uid, groupId); if (msg.Trim() != "") { await SendAsync(e, "房间", msg); @@ -3644,6 +3553,82 @@ namespace Oshima.FunGame.WebAPI.Services } return result; } + + if (e.Detail == $"共斗排行榜") + { + string msg = Controller.GetRanking(uid, 4); + if (msg.Trim() != "") + { + await SendAsync(e, "排行榜", msg); + } + return result; + } + + if (e.Detail == $"锻造排行榜") + { + string msg = Controller.GetRanking(uid, 5); + if (msg.Trim() != "") + { + await SendAsync(e, "排行榜", msg); + } + return result; + } + + if (e.Detail.StartsWith("加物") || e.Detail.StartsWith("添加背包物品")) + { + string detail = e.Detail.Replace("加物", "").Replace("添加背包物品", "").Trim(); + string[] strings = detail.Split(FunGameConstant.SplitChars, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + if (strings.Length < 2) + { + await SendAsync(e, "加物", "格式不正确,请使用:加物 <角色> <{库存物品序号...}>。多个物品序号使用空格隔开。"); + return result; + } + List ids = []; + int cid = -999; + for (int i = 0; i < strings.Length; i++) + { + if (int.TryParse(strings[i], out int id)) + { + if (i != 0) ids.Add(id); + else cid = id; + } + } + string msg = Controller.AddItemsToCharacter(uid, cid, [.. ids]); + if (msg != "") + { + await SendAsync(e, "加物", msg); + } + + return result; + } + + if (e.Detail.StartsWith("减物") || e.Detail.StartsWith("移除背包物品")) + { + string detail = e.Detail.Replace("减物", "").Replace("移除背包物品", "").Trim(); + string[] strings = detail.Split(FunGameConstant.SplitChars, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + if (strings.Length < 2) + { + await SendAsync(e, "减物", "格式不正确,请使用:减物 <角色> <{库存物品序号...}>。多个物品序号使用空格隔开。"); + return result; + } + List ids = []; + int cid = -999; + for (int i = 0; i < strings.Length; i++) + { + if (int.TryParse(strings[i], out int id)) + { + if (i != 0) ids.Add(id); + else cid = id; + } + } + string msg = Controller.RemoveItemsFromCharacter(uid, cid, [.. ids]); + if (msg != "") + { + await SendAsync(e, "减物", msg); + } + + return result; + } if (uid == GeneralSettings.Master && e.Detail.StartsWith("重载FunGame", StringComparison.CurrentCultureIgnoreCase)) { @@ -3662,5 +3647,44 @@ namespace Oshima.FunGame.WebAPI.Services return false; } + + public List MergeMessages(List msgs) + { + List real = []; + if (msgs.Count > 1) + { + if (msgs.Count > 20) + { + msgs = [msgs[0], .. msgs[^20..]]; + } + int perMergeLength = msgs.Count > 5 ? 5 : msgs.Count; + int remain = perMergeLength; + string merge = ""; + for (int i = 0; i < msgs.Count; i++) + { + remain--; + merge += msgs[i] + "\r\n"; + if (remain == 0 || i == msgs.Count - 1) + { + real.Add(merge); + merge = ""; + if (msgs.Count < perMergeLength) + { + remain = msgs.Count; + } + else remain = perMergeLength; + } + } + } + else + { + real = msgs; + } + if (real.Count >= 3) + { + real = [real[0], .. real[^2..]]; + } + return real; + } } }