mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-04-23 04:19:36 +08:00
添加角色状态显示
This commit is contained in:
parent
815a780a70
commit
b05f86ed69
@ -18,11 +18,12 @@ namespace Oshima.Core.Controllers
|
|||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class FunGameController(ILogger<FunGameController> logger) : ControllerBase
|
public class FunGameController(ILogger<FunGameController> logger) : ControllerBase
|
||||||
{
|
{
|
||||||
|
public static ItemType[] ItemCanUsed => [ItemType.Consumable, ItemType.MagicCard, ItemType.SpecialItem, ItemType.GiftBox, ItemType.Others];
|
||||||
|
|
||||||
private readonly ILogger<FunGameController> _logger = logger;
|
private readonly ILogger<FunGameController> _logger = logger;
|
||||||
private const int drawCardReduce = 2000;
|
private const int drawCardReduce = 2000;
|
||||||
private const int drawCardReduce_Material = 10;
|
private const int drawCardReduce_Material = 10;
|
||||||
private const string noSaved = "你还没有创建存档!请发送【创建存档】创建。";
|
private const string noSaved = "你还没有创建存档!请发送【创建存档】创建。";
|
||||||
private readonly ItemType[] itemCanUsed = [ItemType.Consumable, ItemType.MagicCard, ItemType.SpecialItem, ItemType.GiftBox, ItemType.Others];
|
|
||||||
|
|
||||||
[HttpGet("test")]
|
[HttpGet("test")]
|
||||||
public List<string> GetTest([FromQuery] bool? isweb = null, [FromQuery] bool? isteam = null, [FromQuery] bool? showall = null)
|
public List<string> GetTest([FromQuery] bool? isweb = null, [FromQuery] bool? isteam = null, [FromQuery] bool? showall = null)
|
||||||
@ -283,6 +284,25 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
return NetworkUtility.JsonSerialize("");
|
return NetworkUtility.JsonSerialize("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("iteminfoname")]
|
||||||
|
public string GetItemInfo_Name([FromQuery] string? name = null)
|
||||||
|
{
|
||||||
|
IEnumerable<Item> items = FunGameService.AllItems;
|
||||||
|
if (name != null)
|
||||||
|
{
|
||||||
|
List<string> msg = [];
|
||||||
|
Item? i = items.Where(i => i.Name == name).FirstOrDefault()?.Copy();
|
||||||
|
if (i != null)
|
||||||
|
{
|
||||||
|
i.SetLevel(1);
|
||||||
|
msg.Add(i.ToString(false, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NetworkUtility.JsonSerialize(string.Join("\r\n\r\n", msg));
|
||||||
|
}
|
||||||
|
return NetworkUtility.JsonSerialize("");
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("newmagiccard")]
|
[HttpGet("newmagiccard")]
|
||||||
public string GenerateMagicCard()
|
public string GenerateMagicCard()
|
||||||
@ -746,7 +766,7 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
str += $"物品序号:{itemsIndex}\r\n";
|
str += $"物品序号:{itemsIndex}\r\n";
|
||||||
str += $"拥有数量:{objs.Count}(" + (first.IsEquipment ? $"可装备数量:{objs.Count(i => i.Character is null)}," : "") +
|
str += $"拥有数量:{objs.Count}(" + (first.IsEquipment ? $"可装备数量:{objs.Count(i => i.Character is null)}," : "") +
|
||||||
(itemCanUsed.Contains(first.ItemType) ? $"可使用数量:{objs.Count(i => i.RemainUseTimes > 0)}," : "") +
|
(ItemCanUsed.Contains(first.ItemType) ? $"可使用数量:{objs.Count(i => i.RemainUseTimes > 0)}," : "") +
|
||||||
$"可出售数量:{objs.Count(i => i.IsSellable)},可交易数量:{objs.Count(i => i.IsTradable)})";
|
$"可出售数量:{objs.Count(i => i.IsSellable)},可交易数量:{objs.Count(i => i.IsTradable)})";
|
||||||
list.Add(str);
|
list.Add(str);
|
||||||
}
|
}
|
||||||
@ -831,7 +851,7 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
str += $"物品序号:{itemsIndex}\r\n";
|
str += $"物品序号:{itemsIndex}\r\n";
|
||||||
str += $"拥有数量:{objs.Count}(" + (first.IsEquipment ? $"可装备数量:{objs.Count(i => i.Character is null)}," : "") +
|
str += $"拥有数量:{objs.Count}(" + (first.IsEquipment ? $"可装备数量:{objs.Count(i => i.Character is null)}," : "") +
|
||||||
(itemCanUsed.Contains(first.ItemType) ? $"可使用数量:{objs.Count(i => i.RemainUseTimes > 0)}," : "") +
|
(ItemCanUsed.Contains(first.ItemType) ? $"可使用数量:{objs.Count(i => i.RemainUseTimes > 0)}," : "") +
|
||||||
$"可出售数量:{objs.Count(i => i.IsSellable)},可交易数量:{objs.Count(i => i.IsTradable)})";
|
$"可出售数量:{objs.Count(i => i.IsSellable)},可交易数量:{objs.Count(i => i.IsTradable)})";
|
||||||
list.Add(str);
|
list.Add(str);
|
||||||
}
|
}
|
||||||
@ -1639,7 +1659,7 @@ namespace Oshima.Core.Controllers
|
|||||||
if (itemIndex > 0 && itemIndex <= user.Inventory.Items.Count)
|
if (itemIndex > 0 && itemIndex <= user.Inventory.Items.Count)
|
||||||
{
|
{
|
||||||
item = user.Inventory.Items.ToList()[itemIndex - 1];
|
item = user.Inventory.Items.ToList()[itemIndex - 1];
|
||||||
if (itemCanUsed.Contains(item.ItemType))
|
if (ItemCanUsed.Contains(item.ItemType))
|
||||||
{
|
{
|
||||||
if (item.RemainUseTimes <= 0)
|
if (item.RemainUseTimes <= 0)
|
||||||
{
|
{
|
||||||
@ -1656,7 +1676,7 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FunGameService.UseItem(item, user, [.. targets], out string msg))
|
if (FunGameService.UseItem(item, user, targets, out string msg))
|
||||||
{
|
{
|
||||||
user.LastTime = DateTime.Now;
|
user.LastTime = DateTime.Now;
|
||||||
pc.Add("user", user);
|
pc.Add("user", user);
|
||||||
@ -1712,7 +1732,6 @@ namespace Oshima.Core.Controllers
|
|||||||
{
|
{
|
||||||
items = items.TakeLast(useCount);
|
items = items.TakeLast(useCount);
|
||||||
List<string> msgs = [];
|
List<string> msgs = [];
|
||||||
int successCount = 0;
|
|
||||||
|
|
||||||
List<Character> targets = [];
|
List<Character> targets = [];
|
||||||
Character? character = null;
|
Character? character = null;
|
||||||
@ -1729,33 +1748,14 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Item item in items)
|
// 一个失败全部失败
|
||||||
{
|
if (FunGameService.UseItems(items, user, targets, msgs))
|
||||||
if (itemCanUsed.Contains(item.ItemType))
|
|
||||||
{
|
|
||||||
if (item.RemainUseTimes <= 0)
|
|
||||||
{
|
|
||||||
msgs.Add("此物品剩余使用次数为0,无法使用!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FunGameService.UseItem(item, user, [.. targets], out string msg))
|
|
||||||
{
|
|
||||||
successCount++;
|
|
||||||
}
|
|
||||||
msgs.Add(msg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msgs.Add($"这个物品无法使用!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (successCount > 0)
|
|
||||||
{
|
{
|
||||||
user.LastTime = DateTime.Now;
|
user.LastTime = DateTime.Now;
|
||||||
pc.Add("user", user);
|
pc.Add("user", user);
|
||||||
pc.SaveConfig();
|
pc.SaveConfig();
|
||||||
}
|
}
|
||||||
return NetworkUtility.JsonSerialize($"使用完毕!使用 {useCount} 件物品,成功 {successCount} 件!\r\n" + string.Join("\r\n", msgs.Count > 30 ? msgs.Take(30) : msgs));
|
return NetworkUtility.JsonSerialize($"成功使用 {useCount} 件物品!\r\n" + string.Join("\r\n", msgs.Count > 30 ? msgs.Take(30) : msgs));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3507,6 +3507,72 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("settlequest")]
|
||||||
|
public string SettleQuest([FromQuery] long? qq = null)
|
||||||
|
{
|
||||||
|
long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
|
||||||
|
|
||||||
|
PluginConfig pc = new("saved", userid.ToString());
|
||||||
|
pc.LoadConfig();
|
||||||
|
|
||||||
|
if (pc.Count > 0)
|
||||||
|
{
|
||||||
|
User user = FunGameService.GetUser(pc);
|
||||||
|
|
||||||
|
EntityModuleConfig<Quest> quests = new("quests", userid.ToString());
|
||||||
|
quests.LoadConfig();
|
||||||
|
if (quests.Count > 0 && FunGameService.SettleQuest(user, quests))
|
||||||
|
{
|
||||||
|
quests.SaveConfig();
|
||||||
|
user.LastTime = DateTime.Now;
|
||||||
|
pc.Add("user", user);
|
||||||
|
pc.SaveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NetworkUtility.JsonSerialize("任务结算已完成,请查看你的任务列表!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NetworkUtility.JsonSerialize(noSaved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("showmaincharacterorsquadstatus")]
|
||||||
|
public string ShowMainCharacterOrSquadStatus([FromQuery] long? qq = null, [FromQuery] bool? squad = null)
|
||||||
|
{
|
||||||
|
long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
|
||||||
|
bool showSquad = squad ?? false;
|
||||||
|
|
||||||
|
PluginConfig pc = new("saved", userid.ToString());
|
||||||
|
pc.LoadConfig();
|
||||||
|
|
||||||
|
if (pc.Count > 0)
|
||||||
|
{
|
||||||
|
User user = FunGameService.GetUser(pc);
|
||||||
|
string msg = "";
|
||||||
|
|
||||||
|
if (showSquad)
|
||||||
|
{
|
||||||
|
Character[] characters = [.. user.Inventory.Characters.Where(c => user.Inventory.Squad.Contains(c.Id))];
|
||||||
|
foreach (Character character in characters)
|
||||||
|
{
|
||||||
|
if (msg != "") msg += "\r\n";
|
||||||
|
msg += character.GetSimpleInfo(true, false, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = user.Inventory.MainCharacter.GetSimpleInfo(true, false, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NetworkUtility.JsonSerialize(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NetworkUtility.JsonSerialize(noSaved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost("signin")]
|
[HttpPost("signin")]
|
||||||
public string SignIn([FromQuery] long? qq = null)
|
public string SignIn([FromQuery] long? qq = null)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ namespace Oshima.Core.WebAPI
|
|||||||
Controller.WriteLine("重置物品交易冷却时间");
|
Controller.WriteLine("重置物品交易冷却时间");
|
||||||
_ = FunGameService.AllowSellAndTrade();
|
_ = FunGameService.AllowSellAndTrade();
|
||||||
});
|
});
|
||||||
TaskScheduler.Shared.AddRecurringTask("刷新存档缓存", TimeSpan.FromSeconds(20), () =>
|
TaskScheduler.Shared.AddRecurringTask("刷新存档缓存", TimeSpan.FromMinutes(1), () =>
|
||||||
{
|
{
|
||||||
string directoryPath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved";
|
string directoryPath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved";
|
||||||
if (Directory.Exists(directoryPath))
|
if (Directory.Exists(directoryPath))
|
||||||
@ -77,7 +77,18 @@ namespace Oshima.Core.WebAPI
|
|||||||
if (pc.Count > 0)
|
if (pc.Count > 0)
|
||||||
{
|
{
|
||||||
User user = FunGameService.GetUser(pc);
|
User user = FunGameService.GetUser(pc);
|
||||||
|
// 将用户名存入缓存
|
||||||
FunGameService.UserIdAndUsername[user.Id] = user.Username;
|
FunGameService.UserIdAndUsername[user.Id] = user.Username;
|
||||||
|
// 任务结算
|
||||||
|
EntityModuleConfig<Quest> quests = new("quests", user.Id.ToString());
|
||||||
|
quests.LoadConfig();
|
||||||
|
if (quests.Count > 0 && FunGameService.SettleQuest(user, quests))
|
||||||
|
{
|
||||||
|
quests.SaveConfig();
|
||||||
|
user.LastTime = DateTime.Now;
|
||||||
|
pc.Add("user", user);
|
||||||
|
pc.SaveConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Controller.WriteLine("读取 FunGame 存档缓存");
|
Controller.WriteLine("读取 FunGame 存档缓存");
|
||||||
|
@ -2,6 +2,7 @@ using System.Text;
|
|||||||
using Milimoe.FunGame.Core.Api.Utility;
|
using Milimoe.FunGame.Core.Api.Utility;
|
||||||
using Milimoe.FunGame.Core.Entity;
|
using Milimoe.FunGame.Core.Entity;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
using Oshima.Core.Controllers;
|
||||||
using Oshima.FunGame.OshimaModules;
|
using Oshima.FunGame.OshimaModules;
|
||||||
using Oshima.FunGame.OshimaModules.Characters;
|
using Oshima.FunGame.OshimaModules.Characters;
|
||||||
using Oshima.FunGame.OshimaModules.Effects.OpenEffects;
|
using Oshima.FunGame.OshimaModules.Effects.OpenEffects;
|
||||||
@ -553,17 +554,6 @@ namespace Oshima.Core.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 任务结算
|
|
||||||
EntityModuleConfig<Quest> quests = new("quests", user.Id.ToString());
|
|
||||||
quests.LoadConfig();
|
|
||||||
if (quests.Count > 0 && SettleQuest(user, quests))
|
|
||||||
{
|
|
||||||
quests.SaveConfig();
|
|
||||||
user.LastTime = DateTime.Now;
|
|
||||||
pc.Add("user", user);
|
|
||||||
pc.SaveConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1005,12 +995,12 @@ namespace Oshima.Core.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool UseItem(Item item, User user, Character[] targets, out string msg)
|
public static bool UseItem(Item item, User user, IEnumerable<Character> targets, out string msg)
|
||||||
{
|
{
|
||||||
msg = "";
|
msg = "";
|
||||||
Dictionary<string, object> args = new()
|
Dictionary<string, object> args = new()
|
||||||
{
|
{
|
||||||
{ "targets", targets }
|
{ "targets", targets.ToArray() }
|
||||||
};
|
};
|
||||||
bool result = item.UseItem(args);
|
bool result = item.UseItem(args);
|
||||||
string key = args.Keys.FirstOrDefault(s => s.Equals("msg", StringComparison.CurrentCultureIgnoreCase)) ?? "";
|
string key = args.Keys.FirstOrDefault(s => s.Equals("msg", StringComparison.CurrentCultureIgnoreCase)) ?? "";
|
||||||
@ -1018,8 +1008,78 @@ namespace Oshima.Core.Utils
|
|||||||
{
|
{
|
||||||
msg = str;
|
msg = str;
|
||||||
}
|
}
|
||||||
|
if (msg.Trim() == "" && !result)
|
||||||
|
{
|
||||||
|
result = UseItemCustom(item, user, targets, out msg);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool UseItems(IEnumerable<Item> items, User user, IEnumerable<Character> targets, List<string> msgs)
|
||||||
|
{
|
||||||
|
Dictionary<string, object> args = new()
|
||||||
|
{
|
||||||
|
{ "targets", targets.ToArray() },
|
||||||
|
{ "useCount", items.Count() }
|
||||||
|
};
|
||||||
|
bool result = true;
|
||||||
|
foreach (Item item in items)
|
||||||
|
{
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (FunGameController.ItemCanUsed.Contains(item.ItemType))
|
||||||
|
{
|
||||||
|
if (item.RemainUseTimes <= 0)
|
||||||
|
{
|
||||||
|
msgs.Add($"{item.Name} 的剩余使用次数为 0,无法使用!");
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
bool tempResult = item.UseItem(args);
|
||||||
|
string tempStr = "";
|
||||||
|
string key = args.Keys.FirstOrDefault(s => s.Equals("msg", StringComparison.CurrentCultureIgnoreCase)) ?? "";
|
||||||
|
if (key != "" && args.TryGetValue(key, out object? value) && value is string str)
|
||||||
|
{
|
||||||
|
if (str != "") msgs.Add(str);
|
||||||
|
tempStr = str;
|
||||||
|
}
|
||||||
|
if (tempStr.Trim() == "" && !tempResult)
|
||||||
|
{
|
||||||
|
// 使用自定义使用方法
|
||||||
|
tempResult = UseItemCustom(item, user, targets, out tempStr);
|
||||||
|
}
|
||||||
|
if (!tempResult)
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
msgs.Add(tempStr);
|
||||||
|
// 这个参数会覆盖掉原消息
|
||||||
|
key = args.Keys.FirstOrDefault(s => s.Equals("truemsg", StringComparison.CurrentCultureIgnoreCase)) ?? "";
|
||||||
|
if (key != "" && args.TryGetValue(key, out value) && value is string truemsg)
|
||||||
|
{
|
||||||
|
msgs.Clear();
|
||||||
|
msgs.Add(truemsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msgs.Add($"这个物品无法使用!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool UseItemCustom(Item item, User user, IEnumerable<Character> targets, out string msg)
|
||||||
|
{
|
||||||
|
msg = "";
|
||||||
|
switch (item.Name)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetLevelBreakNeedy(int levelBreak)
|
public static string GetLevelBreakNeedy(int levelBreak)
|
||||||
{
|
{
|
||||||
|
@ -40,12 +40,14 @@ namespace Oshima.FunGame.OshimaModules.Items
|
|||||||
{
|
{
|
||||||
string msg = "";
|
string msg = "";
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
Character[] targets = [];
|
||||||
string key = args.Keys.FirstOrDefault(s => s.Equals("targets", StringComparison.CurrentCultureIgnoreCase)) ?? "";
|
string key = args.Keys.FirstOrDefault(s => s.Equals("targets", StringComparison.CurrentCultureIgnoreCase)) ?? "";
|
||||||
if (key != "" && args.TryGetValue(key, out object? value) && value is Character[] targets)
|
if (key != "" && args.TryGetValue(key, out object? value) && value is Character[] temp)
|
||||||
{
|
{
|
||||||
if (targets.Length > 0)
|
if (temp.Length > 0)
|
||||||
{
|
{
|
||||||
msg = UseItem(item, targets[0]);
|
targets = [temp[0]];
|
||||||
|
msg = UseItem(item, temp[0]);
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -53,7 +55,17 @@ namespace Oshima.FunGame.OshimaModules.Items
|
|||||||
msg = $"使用物品失败,没有作用目标!";
|
msg = $"使用物品失败,没有作用目标!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args.Add("msg", msg);
|
args["msg"] = msg;
|
||||||
|
key = args.Keys.FirstOrDefault(s => s.Equals("useCount", StringComparison.CurrentCultureIgnoreCase)) ?? "";
|
||||||
|
if (key != "" && args.TryGetValue(key, out value) && value is int count && targets.Length > 0)
|
||||||
|
{
|
||||||
|
string truemsg = $"对角色 [ {targets[0]} ] 使用 {count} 个 [ {item.Name} ] 成功!";
|
||||||
|
if (item is EXPBook expBook)
|
||||||
|
{
|
||||||
|
truemsg += $"获得了 {expBook.EXP * count} 点经验值!";
|
||||||
|
}
|
||||||
|
args["truemsg"] = truemsg;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user