This commit is contained in:
milimoe 2026-05-07 01:33:10 +08:00
parent 7eb16e2651
commit 851f839568
Signed by: milimoe
GPG Key ID: 9554D37E4B8991D0
4 changed files with 335 additions and 186 deletions

View File

@ -482,8 +482,9 @@ namespace Oshima.FunGame.OshimaServers.Models
/// <param name="visitedLabel">点击后显示的文本,为 null 则与 label 相同</param>
/// <param name="style">按钮样式0 = 灰色1 = 蓝色</param>
/// <param name="permissionType">权限类型0 = 指定用户1 = 管理者2 = 所有人</param>
/// <param name="specifyUserIds">当权限类型 = 0 时,需指定用户 OpenID</param>
/// <returns></returns>
public static Button CreateCmdButton(string label, string data, bool enter = true, bool reply = false, string? visitedLabel = null, int style = 1, int permissionType = 2)
public static Button CreateCmdButton(string label, string data, bool enter = true, bool reply = false, string? visitedLabel = null, int style = 1, int permissionType = 2, params List<string> specifyUserIds)
{
return new Button
{
@ -500,7 +501,7 @@ namespace Oshima.FunGame.OshimaServers.Models
Data = data,
Enter = enter,
Reply = reply,
Permission = new Permission { Type = permissionType }
Permission = new Permission { Type = permissionType, SpecifyUserIds = specifyUserIds }
}
};
}
@ -515,8 +516,9 @@ namespace Oshima.FunGame.OshimaServers.Models
/// <param name="visitedLabel">点击后显示的文本,为 null 则与 label 相同</param>
/// <param name="style">按钮样式0 = 灰色1 = 蓝色</param>
/// <param name="permissionType">权限类型0 = 指定用户1 = 管理者2 = 所有人</param>
/// <param name="specifyUserIds">当权限类型 = 0 时,需指定用户 OpenID</param>
/// <returns></returns>
public static Button CreateInteractionButton(string label, string data, string? visitedLabel = null, int style = 1, int permissionType = 2)
public static Button CreateInteractionButton(string label, string data, string? visitedLabel = null, int style = 1, int permissionType = 2, params List<string> specifyUserIds)
{
return new Button
{
@ -531,7 +533,7 @@ namespace Oshima.FunGame.OshimaServers.Models
{
Type = 1,
Data = data,
Permission = new Permission { Type = permissionType }
Permission = new Permission { Type = permissionType, SpecifyUserIds = specifyUserIds }
}
};
}
@ -595,6 +597,9 @@ namespace Oshima.FunGame.OshimaServers.Models
{
[JsonPropertyName("type")]
public int Type { get; set; }
[JsonPropertyName("specify_user_ids")]
public List<string> SpecifyUserIds { get; set; } = [];
}
public class InteractionEvent

View File

@ -3,7 +3,6 @@ using System.Text;
using Milimoe.FunGame.Core.Api.Transmittal;
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.Core.Constant;
using Oshima.FunGame.OshimaModules.Characters;
@ -21,6 +20,7 @@ namespace Oshima.FunGame.OshimaServers.Service
{
public class FunGameService
{
public static ConcurrentDictionary<long, string> UIDWithOpenID { get; } = [];
public static ConcurrentDictionary<long, List<string>> UserExploreCharacterCache { get; } = [];
public static ConcurrentDictionary<long, List<string>> UserExploreItemCache { get; } = [];
public static ConcurrentDictionary<long, List<string>> UserExploreEventCache { get; } = [];
@ -5458,6 +5458,10 @@ namespace Oshima.FunGame.OshimaServers.Service
{
OnUserConfigSaving(pc, user);
if (updateLastTime) user.LastTime = DateTime.Now;
if (UIDWithOpenID.TryGetValue(user.Id, out string? openid) && openid != null)
{
user.AutoKey = openid;
}
pc.Add("user", user);
pc.SaveConfig();
if (release && FunGameConstant.UserSemaphoreSlims.TryGetValue(key, out SemaphoreSlim? obj) && obj != null && obj.CurrentCount == 0)
@ -5513,5 +5517,14 @@ namespace Oshima.FunGame.OshimaServers.Service
FunGameConstant.MarketSemaphoreSlim.Release();
}
}
public static string MergeToMarkdown(string subtitle, params List<string> msgs)
{
if (msgs.Count > 30)
{
msgs = [.. msgs[..15], .. msgs[^15..]];
}
return $"{subtitle}\r\n```\r\n{string.Join("\r\n", msgs)}\r\n```";
}
}
}

View File

@ -1000,8 +1000,17 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
[HttpGet("inventoryinfo2")]
public List<string> GetInventoryInfo2([FromQuery] long? uid = null, [FromQuery] int? page = null)
public BotReply GetInventoryInfo2([FromQuery] long? uid = null, [FromQuery] int? page = null, [FromQuery] string command = "")
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
int showPage = page ?? 1;
if (showPage <= 0) showPage = 1;
@ -1062,22 +1071,41 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
list.Add($"页数:{showPage} / {maxPage}");
reply.Keyboard = new KeyboardMessage()
.AddPaginationRow(command, showPage, maxPage)
.AppendButtonsWithNewRow(1, Button.CreateCmdButton("库存搜索", $"库存搜索", false));
}
else
{
list.Add($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {showPage} 页。");
reply.Keyboard = new KeyboardMessage().AppendButtons(4, [
Button.CreateCmdButton("查看首页", $"{command}1"),
Button.CreateCmdButton("跳转至页码", $"{command}", false),
Button.CreateCmdButton("查看末页", $"{command}{maxPage}"),
Button.CreateCmdButton("库存搜索", $"库存搜索", false)
]);
}
}
else
{
list.Add(noSaved);
}
return list;
md.Content = string.Join("\r\n", list);
return reply;
}
[HttpGet("inventoryinfo3")]
public List<string> GetInventoryInfo3([FromQuery] long? uid = null, [FromQuery] int? page = null, [FromQuery] int? order = null, [FromQuery] int? orderqty = null)
public BotReply GetInventoryInfo3([FromQuery] long? uid = null, [FromQuery] int? page = null, [FromQuery] int? order = null, [FromQuery] int? orderqty = null, [FromQuery] string command = "")
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
int showPage = page ?? 1;
if (showPage <= 0) showPage = 1;
@ -1183,22 +1211,41 @@ namespace Oshima.FunGame.WebAPI.Controllers
list.Add(str);
}
list.Add($"页数:{showPage} / {maxPage}");
reply.Keyboard = new KeyboardMessage()
.AddPaginationRow(command, showPage, maxPage)
.AppendButtonsWithNewRow(1, Button.CreateCmdButton("库存搜索", $"库存搜索", false));
}
else
{
list.Add($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {showPage} 页。");
reply.Keyboard = new KeyboardMessage().AppendButtons(4, [
Button.CreateCmdButton("查看首页", $"{command}1"),
Button.CreateCmdButton("跳转至页码", $"{command}", false),
Button.CreateCmdButton("查看末页", $"{command}{maxPage}"),
Button.CreateCmdButton("库存搜索", $"库存搜索", false)
]);
}
}
else
{
list.Add(noSaved);
}
return list;
md.Content = string.Join("\r\n", list);
return reply;
}
[HttpGet("inventoryinfo4")]
public List<string> GetInventoryInfo4([FromQuery] long? uid = null, [FromQuery] int? page = null, [FromQuery] int? type = null)
public BotReply GetInventoryInfo4([FromQuery] long? uid = null, [FromQuery] int? page = null, [FromQuery] int? type = null, [FromQuery] string command = "")
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
int showPage = page ?? 1;
int itemtype = type ?? -1;
@ -1212,7 +1259,12 @@ namespace Oshima.FunGame.WebAPI.Controllers
{
if (type == -1)
{
return ["没有指定物品的类型,请使用通用查询方法!"];
md.Content = "没有指定物品的类型,请使用通用查询方法!";
reply.Keyboard = new KeyboardMessage().AppendButtons(2, [
Button.CreateCmdButton("我的库存", $"我的库存", false),
Button.CreateCmdButton("库存搜索", $"库存搜索", false)
]);
return reply;
}
User user = FunGameService.GetUser(pc);
@ -1295,22 +1347,41 @@ namespace Oshima.FunGame.WebAPI.Controllers
list.Add(str);
}
list.Add($"页数:{showPage} / {maxPage}");
reply.Keyboard = new KeyboardMessage()
.AddPaginationRow(command, showPage, maxPage)
.AppendButtonsWithNewRow(1, Button.CreateCmdButton("库存搜索", $"库存搜索", false));
}
else
{
list.Add($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {showPage} 页。");
reply.Keyboard = new KeyboardMessage().AppendButtons(4, [
Button.CreateCmdButton("查看首页", $"{command}1"),
Button.CreateCmdButton("跳转至页码", $"{command}", false),
Button.CreateCmdButton("查看末页", $"{command}{maxPage}"),
Button.CreateCmdButton("库存搜索", $"库存搜索", false)
]);
}
}
else
{
list.Add(noSaved);
}
return list;
md.Content = string.Join("\r\n", list);
return reply;
}
[HttpGet("inventoryinfo5")]
public List<string> GetInventoryInfo5([FromQuery] long? uid = null, [FromQuery] int? page = null)
public BotReply GetInventoryInfo5([FromQuery] long? uid = null, [FromQuery] int? page = null, [FromQuery] string command = "")
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
int showPage = page ?? 1;
if (showPage <= 0) showPage = 1;
@ -1357,22 +1428,41 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
list.Add($"页数:{showPage} / {maxPage}");
reply.Keyboard = new KeyboardMessage()
.AddPaginationRow(command, showPage, maxPage)
.AppendButtonsWithNewRow(1, Button.CreateCmdButton("库存搜索", $"库存搜索", false));
}
else
{
list.Add($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {showPage} 页。");
reply.Keyboard = new KeyboardMessage().AppendButtons(4, [
Button.CreateCmdButton("查看首页", $"{command}1"),
Button.CreateCmdButton("跳转至页码", $"{command}", false),
Button.CreateCmdButton("查看末页", $"{command}{maxPage}"),
Button.CreateCmdButton("库存搜索", $"库存搜索", false)
]);
}
}
else
{
list.Add(noSaved);
}
return list;
md.Content = string.Join("\r\n", list);
return reply;
}
[HttpGet("inventoryinfo6")]
public List<string> GetInventoryInfo6([FromQuery] long uid = 0, [FromQuery] int page = 1, [FromQuery] string name = "", [FromForm] bool containsDescription = false)
public BotReply GetInventoryInfo6([FromQuery] long uid = 0, [FromQuery] int page = 1, [FromQuery] string name = "", [FromQuery] bool containsDescription = false, [FromQuery] string command = "")
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
if (page <= 0) page = 1;
PluginConfig pc = FunGameService.GetUserConfig(uid, out _);
@ -1383,7 +1473,12 @@ namespace Oshima.FunGame.WebAPI.Controllers
{
if (name == "")
{
return ["搜索关键词为空!"];
md.Content = "搜索关键词为空!";
reply.Keyboard = new KeyboardMessage().AppendButtons(2, [
Button.CreateCmdButton("我的库存", $"我的库存", false),
Button.CreateCmdButton("库存搜索", $"库存搜索", false)
]);
return reply;
}
User user = FunGameService.GetUser(pc);
@ -1466,17 +1561,27 @@ namespace Oshima.FunGame.WebAPI.Controllers
list.Add(str);
}
list.Add($"页数:{page} / {maxPage}");
reply.Keyboard = new KeyboardMessage()
.AddPaginationRow(command, page, maxPage)
.AppendButtonsWithNewRow(1, Button.CreateCmdButton("库存搜索", $"库存搜索", false));
}
else
{
list.Add($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {page} 页。");
reply.Keyboard = new KeyboardMessage().AppendButtons(4, [
Button.CreateCmdButton("查看首页", $"{command}1"),
Button.CreateCmdButton("跳转至页码", $"{command}", false),
Button.CreateCmdButton("查看末页", $"{command}{maxPage}"),
Button.CreateCmdButton("库存搜索", $"库存搜索", false)
]);
}
}
else
{
list.Add(noSaved);
}
return list;
md.Content = string.Join("\r\n", list);
return reply;
}
[HttpPost("newcustomcharacter")]
@ -4162,8 +4267,16 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
[HttpPost("addsquad")]
public string AddSquad([FromQuery] long? uid = null, [FromQuery] int? c = null)
public BotReply AddSquad([FromQuery] long? uid = null, [FromQuery] int? c = null)
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
try
{
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
@ -4183,42 +4296,56 @@ namespace Oshima.FunGame.WebAPI.Controllers
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return $"没有找到与这个序号相对应的角色!";
md.Content = $"没有找到与这个序号相对应的角色!";
return reply;
}
if (user.Inventory.Squad.Count >= 4)
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return $"小队人数已满 4 人,无法继续添加角色!当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
md.Content = $"小队人数已满 4 人,无法继续添加角色!当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
return reply;
}
if (user.Inventory.Squad.Contains(character.Id))
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return $"此角色已经在小队中了!";
md.Content = $"此角色已经在小队中了!";
return reply;
}
user.Inventory.Squad.Add(character.Id);
FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user);
return $"添加小队角色成功:{character}\r\n当前小队角色如下\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
md.Content = $"添加小队角色成功:{character}\r\n当前小队角色如下\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
return reply;
}
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return noSaved;
md.Content = noSaved;
return reply;
}
}
catch (Exception e)
{
FunGameService.ReleaseUserSemaphoreSlim(uid.ToString() ?? "");
if (Logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) Logger.LogError(e, "Error: {e}", e);
return busy;
md.Content = busy;
return reply;
}
}
[HttpPost("removesquad")]
public string RemoveSquad([FromQuery] long? uid = null, [FromQuery] int? c = null)
public BotReply RemoveSquad([FromQuery] long? uid = null, [FromQuery] int? c = null)
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
try
{
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
@ -4238,36 +4365,49 @@ namespace Oshima.FunGame.WebAPI.Controllers
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return $"没有找到与这个序号相对应的角色!";
md.Content = $"没有找到与这个序号相对应的角色!";
return reply;
}
if (!user.Inventory.Squad.Contains(character.Id))
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return $"此角色不在小队中!";
md.Content = $"此角色不在小队中!";
return reply;
}
user.Inventory.Squad.Remove(character.Id);
FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user);
return $"移除小队角色成功:{character}\r\n当前小队角色如下\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
md.Content = $"移除小队角色成功:{character}\r\n当前小队角色如下\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
return reply;
}
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return noSaved;
md.Content = noSaved;
return reply;
}
}
catch (Exception e)
{
FunGameService.ReleaseUserSemaphoreSlim(uid.ToString() ?? "");
if (Logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) Logger.LogError(e, "Error: {e}", e);
return busy;
md.Content = busy;
return reply;
}
}
[HttpPost("setsquad")]
public string SetSquad([FromQuery] long? uid = null, [FromBody] int[]? c = null)
public BotReply SetSquad([FromQuery] long? uid = null, [FromBody] int[]? c = null)
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
try
{
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
@ -4290,25 +4430,29 @@ namespace Oshima.FunGame.WebAPI.Controllers
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return $"设置失败:没有找到与序号 {characterIndex} 相对应的角色!";
md.Content = $"设置失败:没有找到与序号 {characterIndex} 相对应的角色!";
return reply;
}
user.Inventory.Squad.Add(character.Id);
}
FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user);
return $"设置小队成员成功!当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
md.Content = $"设置小队成员成功!当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
return reply;
}
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return noSaved;
md.Content = noSaved;
return reply;
}
}
catch (Exception e)
{
FunGameService.ReleaseUserSemaphoreSlim(uid.ToString() ?? "");
if (Logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) Logger.LogError(e, "Error: {e}", e);
return busy;
md.Content = busy;
return reply;
}
}
@ -4345,8 +4489,17 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
[HttpGet("showsquad")]
public string ShowSquad([FromQuery] long? uid = null)
public BotReply ShowSquad([FromQuery] long? uid = null)
{
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
try
{
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
@ -4357,27 +4510,39 @@ namespace Oshima.FunGame.WebAPI.Controllers
if (pc.Count > 0)
{
User user = FunGameService.GetUser(pc);
return $"你的当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
md.Content = $"你的当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
return reply;
}
else
{
return noSaved;
md.Content = noSaved;
return reply;
}
}
catch (Exception e)
{
if (Logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) Logger.LogError(e, "Error: {e}", e);
return busy;
md.Content = busy;
return reply;
}
}
[HttpPost("fightbossteam")]
public async Task<List<string>> FightBossTeam([FromQuery] long? uid = null, [FromQuery] int? index = null, [FromQuery] bool? all = null)
public async Task<BotReply> FightBossTeam([FromQuery] long? uid = null, [FromQuery] int? index = null, [FromQuery] bool? all = null)
{
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
int bossIndex = index ?? 0;
bool showAllRound = all ?? false;
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
PluginConfig pc = FunGameService.GetUserConfig(userid, out _);
if (pc.Count > 0)
@ -4391,8 +4556,9 @@ namespace Oshima.FunGame.WebAPI.Controllers
if (squad.All(c => c.HP < c.MaxHP * 0.1))
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return [$"小队角色均重伤未愈,当前生命值低于 10%,请先等待生命值自动回复或重组小队!\r\n" +
$"当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}"];
md.Content = $"小队角色均重伤未愈,当前生命值低于 10%,请先等待生命值自动回复、使用{"".CreateCmdInput()}服务或重组小队!\r\n" +
$"当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
return reply;
}
Character boss2 = CharacterBuilder.Build(boss, false, true, null, FunGameConstant.AllItems, FunGameConstant.AllSkills, false);
@ -4416,18 +4582,22 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user);
return msgs;
md.Content = FunGameService.MergeToMarkdown("战斗结果如下:", msgs);
reply.Keyboard = new KeyboardMessage().AppendButtons(1, Button.CreateCmdButton("小队讨伐boss", $"小队讨伐boss"));
return reply;
}
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return [$"找不到指定编号的 Boss"];
md.Content = $"找不到指定编号的 Boss";
return reply;
}
}
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return [noSaved];
md.Content = noSaved;
return reply;
}
}
@ -6166,28 +6336,39 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
else
{
characterIds = [.. user.Inventory.Squad];
List<long> realCid = [];
List<Character> characters = [.. user.Inventory.Characters];
for (int i = 0; i < characters.Count; i++)
{
if ((i == 0 && user.Inventory.Squad.Contains(FunGameConstant.CustomCharacterId)) || user.Inventory.Squad.Contains(characters[i].Id))
{
realCid.Add(i + 1);
}
}
characterIds = [.. realCid];
characterCount = characterIds.Length;
}
}
// 检查角色存在
List<long> invalid = [];
foreach (long cid in characterIds)
else
{
if (cid > 0 && cid <= user.Inventory.Characters.Count)
// 检查角色存在
List<long> invalid = [];
foreach (long cid in characterIds)
{
// do nothing
if (cid > 0 && cid <= user.Inventory.Characters.Count)
{
// do nothing
}
else
{
invalid.Add(cid);
}
}
else
if (invalid.Count > 0)
{
invalid.Add(cid);
msg = $"没有找到与输入序号相对应的角色:{string.Join("", invalid)}。";
}
}
if (invalid.Count > 0)
{
msg = $"没有找到与输入序号相对应的角色:{string.Join("", invalid)}。";
}
// 检查探索许可
int exploreTimes = FunGameConstant.MaxExploreTimes;
@ -6436,7 +6617,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
md.Content = msg;
if (command != "")
{
reply.Keyboard = new KeyboardMessage().AppendButtons(1, Button.CreateCmdButton("再探再报", command, permissionType: 0));
reply.Keyboard = new KeyboardMessage().AppendButtons(1, Button.CreateCmdButton("再探再报", command, permissionType: 0, specifyUserIds: user.AutoKey));
}
return reply;
}
@ -8110,10 +8291,19 @@ namespace Oshima.FunGame.WebAPI.Controllers
}
[HttpPost("fightinstance")]
public async Task<string> FightInstance([FromQuery] long? uid = null, [FromQuery] int type = 0, [FromQuery] int difficulty = 1)
public async Task<BotReply> FightInstance([FromQuery] long? uid = null, [FromQuery] int type = 0, [FromQuery] int difficulty = 1)
{
long userid = uid ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
MarkdownMessage md = new()
{
Content = busy
};
BotReply reply = new()
{
Markdown = md
};
try
{
PluginConfig pc = FunGameService.GetUserConfig(userid, out _);
@ -8139,7 +8329,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
Character[] squad = [.. user.Inventory.Characters.Where(c => user.Inventory.Squad.Contains(c.Id))];
if (squad.All(c => c.HP < c.MaxHP * 0.1))
{
msg = $"小队角色均重伤未愈,当前生命值低于 10%,请先等待生命值自动回复或重组小队!\r\n" +
msg = $"小队角色均重伤未愈,当前生命值低于 10%,请先等待生命值自动回复、使用{"".CreateCmdInput()}服务或重组小队!\r\n" +
$"当前小队角色如下:\r\n{FunGameService.GetSquadInfo(user.Inventory.Characters, user.Inventory.Squad)}";
}
else
@ -8152,11 +8342,11 @@ namespace Oshima.FunGame.WebAPI.Controllers
if (exploreTimes <= 0)
{
exploreTimes = 0;
msg = $"今日的探索许可已用完,无法再继续挑战秘境。";
msg = $"今日的{"".CreateCmdInput("1")}已用完,无法再继续挑战秘境。";
}
else if (reduce > exploreTimes)
{
msg = $"本次秘境挑战需要消耗 {reduce} 个探索许可,超过了你的剩余探索许可数量({exploreTimes} 个),请减少小队的角色数量或更改难度系数。" +
msg = $"本次秘境挑战需要消耗 {reduce} 个{"".CreateCmdInput("1")},超过了你的剩余探索许可数量({exploreTimes} 个),请减少小队的角色数量或更改难度系数。" +
$"\r\n需要注意难度系数一比一兑换探索许可并且参与挑战的角色都需要消耗相同数量的探索许可。特殊地魔法卡秘境额外 3 倍探索许可消耗。";
}
}
@ -8172,11 +8362,11 @@ namespace Oshima.FunGame.WebAPI.Controllers
if (result)
{
exploreTimes -= reduce;
msg += $"本次秘境挑战消耗探索许可 {reduce} 个,你的剩余探索许可:{exploreTimes} 个。";
msg += $"本次秘境挑战消耗探索许可 {reduce} 个,你的剩余{"".CreateCmdInput("1")}{exploreTimes} 个。";
}
else
{
msg += $"本次秘境挑战失败,不消耗任何探索许可,请继续加油!你的剩余探索许可:{exploreTimes} 个。";
msg += $"本次秘境挑战失败,不消耗任何探索许可,请继续加油!你的剩余{"".CreateCmdInput("1")}{exploreTimes} 个。";
}
}
@ -8191,19 +8381,22 @@ namespace Oshima.FunGame.WebAPI.Controllers
FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user);
return msg;
md.Content = msg;
return reply;
}
else
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
return noSaved;
md.Content = noSaved;
return reply;
}
}
catch (Exception e)
{
FunGameService.ReleaseUserSemaphoreSlim(userid);
if (Logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) Logger.LogError(e, "Error: {e}", e);
return busy;
md.Content = busy;
return reply;
}
}

View File

@ -160,6 +160,7 @@ namespace Oshima.FunGame.WebAPI.Services
uid = user.Id;
e.FunGameUID = uid;
MemoryCache.Set(openid, uid, TimeSpan.FromMinutes(10));
FunGameService.UIDWithOpenID[uid] = openid;
}
}
}
@ -862,11 +863,7 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail == "我的小队")
{
e.UseNotice = false;
string msg = Controller.ShowSquad(uid);
if (msg != "")
{
await SendAsync(e, "我的小队", "\r\n" + msg);
}
await SendAsync(e, "我的小队", Controller.ShowSquad(uid));
return result;
}
@ -1157,10 +1154,10 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("查看库存") || e.Detail.StartsWith("我的库存") || e.Detail.StartsWith("我的背包"))
{
string detail = e.Detail.Replace("查看库存", "").Replace("我的库存", "").Replace("我的背包", "").Trim();
List<string> msgs = [];
BotReply reply;
if (int.TryParse(detail, out int page))
{
msgs = Controller.GetInventoryInfo2(uid, page);
reply = Controller.GetInventoryInfo2(uid, page, command: "我的库存");
}
else if (FunGameItemType.FirstOrDefault(detail.Contains) is string matchedType)
{
@ -1168,59 +1165,50 @@ namespace Oshima.FunGame.WebAPI.Services
string remain = detail.Replace(matchedType, "").Trim();
if (int.TryParse(remain, out page))
{
msgs = Controller.GetInventoryInfo4(uid, page, typeIndex);
reply = Controller.GetInventoryInfo4(uid, page, typeIndex, command: "我的库存");
}
else
{
msgs = Controller.GetInventoryInfo4(uid, 1, typeIndex);
reply = Controller.GetInventoryInfo4(uid, 1, typeIndex, command: "我的库存");
}
}
else
{
msgs = Controller.GetInventoryInfo2(uid, 1);
}
if (msgs.Count > 0)
{
await SendAsync(e, "查看库存", "\r\n" + string.Join("\r\n", msgs));
reply = Controller.GetInventoryInfo2(uid, 1, command: "我的库存");
}
await SendAsync(e, "查看库存", reply);
return result;
}
if (e.Detail.StartsWith("物品库存"))
{
string detail = e.Detail.Replace("物品库存", "").Trim();
List<string> msgs = [];
BotReply reply;
if (int.TryParse(detail, out int page))
{
msgs = Controller.GetInventoryInfo3(uid, page, 2, 2);
reply = Controller.GetInventoryInfo3(uid, page, 2, 2, command: "物品库存");
}
else
{
msgs = Controller.GetInventoryInfo3(uid, 1, 2, 2);
}
if (msgs.Count > 0)
{
await SendAsync(e, "查看分类库存", "\r\n" + string.Join("\r\n", msgs));
reply = Controller.GetInventoryInfo3(uid, 1, 2, 2, command: "物品库存");
}
await SendAsync(e, "查看分类库存", reply);
return result;
}
if (e.Detail.StartsWith("角色库存"))
{
string detail = e.Detail.Replace("角色库存", "").Trim();
List<string> msgs = [];
BotReply reply;
if (int.TryParse(detail, out int page))
{
msgs = Controller.GetInventoryInfo5(uid, page);
reply = Controller.GetInventoryInfo5(uid, page, command: "角色库存");
}
else
{
msgs = Controller.GetInventoryInfo5(uid, 1);
}
if (msgs.Count > 0)
{
await SendAsync(e, "查看角色库存", "\r\n" + string.Join("\r\n", msgs));
reply = Controller.GetInventoryInfo5(uid, 1, command: "角色库存");
}
await SendAsync(e, "查看角色库存", reply);
return result;
}
@ -1231,19 +1219,16 @@ namespace Oshima.FunGame.WebAPI.Services
int t = -1;
if (strings.Length > 0 && int.TryParse(strings[0].Trim(), out t))
{
List<string> msgs = [];
BotReply reply;
if (strings.Length > 1 && int.TryParse(strings[1].Trim(), out int page))
{
msgs = Controller.GetInventoryInfo4(uid, page, t);
reply = Controller.GetInventoryInfo4(uid, page, t, command: "分类库存");
}
else
{
msgs = Controller.GetInventoryInfo4(uid, 1, t);
}
if (msgs.Count > 0)
{
await SendAsync(e, "查看分类库存", "\r\n" + string.Join("\r\n", msgs));
reply = Controller.GetInventoryInfo4(uid, 1, t, command: "分类库存");
}
await SendAsync(e, "查看分类库存", reply);
}
return result;
}
@ -1258,11 +1243,8 @@ namespace Oshima.FunGame.WebAPI.Services
{
page = p;
}
List<string> msgs = Controller.GetInventoryInfo6(uid, page, search, false);
if (msgs.Count > 0)
{
await SendAsync(e, "搜索库存物品(带描述)", "\r\n" + string.Join("\r\n", msgs));
}
BotReply reply = Controller.GetInventoryInfo6(uid, page, search, false, command: "库存搜索2 ");
await SendAsync(e, "搜索库存物品(带描述)", reply);
return result;
}
@ -1276,11 +1258,8 @@ namespace Oshima.FunGame.WebAPI.Services
{
page = p;
}
List<string> msgs = Controller.GetInventoryInfo6(uid, page, search, true);
if (msgs.Count > 0)
{
await SendAsync(e, "搜索库存物品", "\r\n" + string.Join("\r\n", msgs));
}
BotReply reply = Controller.GetInventoryInfo6(uid, page, search, true, command: "库存搜索");
await SendAsync(e, "搜索库存物品", reply);
return result;
}
@ -1493,11 +1472,9 @@ namespace Oshima.FunGame.WebAPI.Services
string detail = e.Detail.Replace("兑换金币", "").Trim();
if (int.TryParse(detail, out int materials))
{
string msg = Controller.ExchangeCredits(uid, materials);
if (msg != "")
{
await SendAsync(e, "兑换金币", msg);
}
BotReply rpy = Controller.ExchangeCredits(uid, materials);
rpy.Keyboard = new KeyboardMessage().AppendButtons(1, Button.CreateCmdButton("继续兑换", "兑换金币", false));
await SendAsync(e, "兑换金币", rpy);
}
return result;
}
@ -1972,10 +1949,7 @@ namespace Oshima.FunGame.WebAPI.Services
List<string> msgs = [];
if (int.TryParse(detail.Trim(), out int index))
{
msgs = await Controller.FightBossTeam(uid, index, true);
BotReply rpy = MergeToMarkdown("战斗结果如下:", msgs);
rpy.Keyboard = new KeyboardMessage().AppendButtons(1, Button.CreateCmdButton("小队讨伐boss", $"小队讨伐boss"));
await SendAsync(e, "BOSS", rpy, msgSeq: 1);
await SendAsync(e, "BOSS", await Controller.FightBossTeam(uid, index, true), msgSeq: 1);
}
else
{
@ -2007,11 +1981,7 @@ namespace Oshima.FunGame.WebAPI.Services
string detail = e.Detail.Replace("小队添加", "").Trim();
if (int.TryParse(detail, out int c))
{
string msg = Controller.AddSquad(uid, c);
if (msg != "")
{
await SendAsync(e, "小队", msg);
}
await SendAsync(e, "小队", Controller.AddSquad(uid, c));
}
return result;
}
@ -2021,11 +1991,7 @@ namespace Oshima.FunGame.WebAPI.Services
string detail = e.Detail.Replace("小队移除", "").Trim();
if (int.TryParse(detail, out int c))
{
string msg = Controller.RemoveSquad(uid, c);
if (msg != "")
{
await SendAsync(e, "小队", msg);
}
await SendAsync(e, "小队", Controller.RemoveSquad(uid, c));
}
return result;
}
@ -2042,11 +2008,7 @@ namespace Oshima.FunGame.WebAPI.Services
cindexs.Add(c);
}
}
string msg = Controller.SetSquad(uid, [.. cindexs]);
if (msg != "")
{
await SendAsync(e, "小队", msg);
}
await SendAsync(e, "小队", Controller.SetSquad(uid, [.. cindexs]));
return result;
}
@ -2994,18 +2956,13 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("挑战金币秘境"))
{
string detail = e.Detail.Replace("挑战金币秘境", "").Trim();
string msg = "";
if (int.TryParse(detail, out int diff))
{
msg = await Controller.FightInstance(uid, (int)InstanceType.Currency, diff);
if (msg.Trim() != "")
{
await SendAsync(e, "挑战金币秘境", msg);
}
await SendAsync(e, "挑战金币秘境", await Controller.FightInstance(uid, (int)InstanceType.Currency, diff));
}
else
{
await SendAsync(e, "挑战秘境", "请在指令后面输入难度系数1-5");
await SendAsync(e, "挑战秘境", CreateMarkdownFromText("请在" + "指令".CreateCmdInput(e.Detail) + "后面输入难度系数1-5"));
}
return result;
}
@ -3013,18 +2970,13 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("挑战钻石秘境"))
{
string detail = e.Detail.Replace("挑战钻石秘境", "").Trim();
string msg = "";
if (int.TryParse(detail, out int diff))
{
msg = await Controller.FightInstance(uid, (int)InstanceType.Material, diff);
if (msg.Trim() != "")
{
await SendAsync(e, "挑战钻石秘境", msg);
}
await SendAsync(e, "挑战钻石秘境", await Controller.FightInstance(uid, (int)InstanceType.Material, diff));
}
else
{
await SendAsync(e, "挑战秘境", "请在指令后面输入难度系数1-5");
await SendAsync(e, "挑战秘境", CreateMarkdownFromText("请在" + "指令".CreateCmdInput(e.Detail) + "后面输入难度系数1-5"));
}
return result;
}
@ -3032,18 +2984,13 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("挑战经验秘境"))
{
string detail = e.Detail.Replace("挑战经验秘境", "").Trim();
string msg = "";
if (int.TryParse(detail, out int diff))
{
msg = await Controller.FightInstance(uid, (int)InstanceType.EXP, diff);
if (msg.Trim() != "")
{
await SendAsync(e, "挑战经验秘境", msg);
}
await SendAsync(e, "挑战经验秘境", await Controller.FightInstance(uid, (int)InstanceType.EXP, diff));
}
else
{
await SendAsync(e, "挑战秘境", "请在指令后面输入难度系数1-5");
await SendAsync(e, "挑战秘境", CreateMarkdownFromText("请在" + "指令".CreateCmdInput(e.Detail) + "后面输入难度系数1-5"));
}
return result;
}
@ -3051,18 +2998,13 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("挑战地区秘境"))
{
string detail = e.Detail.Replace("挑战地区秘境", "").Trim();
string msg = "";
if (int.TryParse(detail, out int diff))
{
msg = await Controller.FightInstance(uid, (int)InstanceType.RegionItem, diff);
if (msg.Trim() != "")
{
await SendAsync(e, "挑战地区秘境", msg);
}
await SendAsync(e, "挑战地区秘境", await Controller.FightInstance(uid, (int)InstanceType.RegionItem, diff));
}
else
{
await SendAsync(e, "挑战秘境", "请在指令后面输入难度系数1-5");
await SendAsync(e, "挑战秘境", CreateMarkdownFromText("请在" + "指令".CreateCmdInput(e.Detail) + "后面输入难度系数1-5"));
}
return result;
}
@ -3070,18 +3012,13 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("挑战突破秘境"))
{
string detail = e.Detail.Replace("挑战突破秘境", "").Trim();
string msg = "";
if (int.TryParse(detail, out int diff))
{
msg = await Controller.FightInstance(uid, (int)InstanceType.CharacterLevelBreak, diff);
if (msg.Trim() != "")
{
await SendAsync(e, "挑战突破秘境", msg);
}
await SendAsync(e, "挑战突破秘境", await Controller.FightInstance(uid, (int)InstanceType.CharacterLevelBreak, diff));
}
else
{
await SendAsync(e, "挑战秘境", "请在指令后面输入难度系数1-5");
await SendAsync(e, "挑战秘境", CreateMarkdownFromText("请在" + "指令".CreateCmdInput(e.Detail) + "后面输入难度系数1-5"));
}
return result;
}
@ -3089,18 +3026,13 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("挑战技能秘境"))
{
string detail = e.Detail.Replace("挑战技能秘境", "").Trim();
string msg = "";
if (int.TryParse(detail, out int diff))
{
msg = await Controller.FightInstance(uid, (int)InstanceType.SkillLevelUp, diff);
if (msg.Trim() != "")
{
await SendAsync(e, "挑战技能秘境", msg);
}
await SendAsync(e, "挑战技能秘境", await Controller.FightInstance(uid, (int)InstanceType.SkillLevelUp, diff));
}
else
{
await SendAsync(e, "挑战秘境", "请在指令后面输入难度系数1-5");
await SendAsync(e, "挑战秘境", CreateMarkdownFromText("请在" + "指令".CreateCmdInput(e.Detail) + "后面输入难度系数1-5"));
}
return result;
}
@ -3108,18 +3040,13 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("挑战魔法卡秘境"))
{
string detail = e.Detail.Replace("挑战魔法卡秘境", "").Trim();
string msg = "";
if (int.TryParse(detail, out int diff))
{
msg = await Controller.FightInstance(uid, (int)InstanceType.MagicCard, diff);
if (msg.Trim() != "")
{
await SendAsync(e, "挑战魔法卡秘境", msg);
}
await SendAsync(e, "挑战魔法卡秘境", await Controller.FightInstance(uid, (int)InstanceType.MagicCard, diff));
}
else
{
await SendAsync(e, "挑战秘境", "请在指令后面输入难度系数1-5");
await SendAsync(e, "挑战秘境", CreateMarkdownFromText("请在" + "指令".CreateCmdInput(e.Detail) + "后面输入难度系数1-5"));
}
return result;
}
@ -4034,5 +3961,16 @@ namespace Oshima.FunGame.WebAPI.Services
}
return real;
}
public BotReply CreateMarkdownFromText(string text)
{
return new()
{
Markdown = new()
{
Content = text
}
};
}
}
}