mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-04-23 04:19:36 +08:00
完善任务系统和添加签到
This commit is contained in:
parent
a98c7b457c
commit
0f48d2ea73
@ -3412,6 +3412,43 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("checkworkingquest")]
|
||||||
|
public string CheckWorkingQuest([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();
|
||||||
|
string msg = "";
|
||||||
|
IEnumerable<Quest> working = quests.Values.Where(q => q.Status == QuestState.InProgress);
|
||||||
|
if (working.Any())
|
||||||
|
{
|
||||||
|
msg = "你正在进行中的任务详情如下:\r\n" + string.Join("\r\n", working);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = "你当前没有正在进行中的任务!";
|
||||||
|
}
|
||||||
|
|
||||||
|
user.LastTime = DateTime.Now;
|
||||||
|
pc.Add("user", user);
|
||||||
|
pc.SaveConfig();
|
||||||
|
|
||||||
|
return NetworkUtility.JsonSerialize(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NetworkUtility.JsonSerialize(noSaved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost("acceptquest")]
|
[HttpPost("acceptquest")]
|
||||||
public string AcceptQuest([FromQuery] long? qq = null, [FromQuery] int? id = null)
|
public string AcceptQuest([FromQuery] long? qq = null, [FromQuery] int? id = null)
|
||||||
{
|
{
|
||||||
@ -3430,7 +3467,7 @@ namespace Oshima.Core.Controllers
|
|||||||
quests.LoadConfig();
|
quests.LoadConfig();
|
||||||
if (quests.Count > 0)
|
if (quests.Count > 0)
|
||||||
{
|
{
|
||||||
if (quests.Values.FirstOrDefault(q => q.Status == 1) is Quest quest)
|
if (quests.Values.FirstOrDefault(q => q.Status == QuestState.InProgress) is Quest quest)
|
||||||
{
|
{
|
||||||
msg = $"你正在进行任务【{quest.Name}】,无法开始新任务!\r\n{quest}";
|
msg = $"你正在进行任务【{quest.Name}】,无法开始新任务!\r\n{quest}";
|
||||||
}
|
}
|
||||||
@ -3443,9 +3480,9 @@ namespace Oshima.Core.Controllers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
quest2.StartTime = DateTime.Now;
|
quest2.StartTime = DateTime.Now;
|
||||||
quest2.Status = 1;
|
quest2.Status = QuestState.InProgress;
|
||||||
quests.SaveConfig();
|
quests.SaveConfig();
|
||||||
msg = $"开始任务【{quest2.Name}】成功!\r\n任务信息如下:{quest2}\r\n预计完成时间:{DateTime.Now.AddMinutes(quest2.EstimatedMinutes).ToString(General.GeneralDateTimeFormatChinese)}";
|
msg = $"开始任务【{quest2.Name}】成功!任务信息如下:\r\n{quest2}\r\n预计完成时间:{DateTime.Now.AddMinutes(quest2.EstimatedMinutes).ToString(General.GeneralDateTimeFormatChinese)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -3470,6 +3507,37 @@ namespace Oshima.Core.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("signin")]
|
||||||
|
public string SignIn([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);
|
||||||
|
bool sign = pc.Get<bool>("signed");
|
||||||
|
|
||||||
|
if (sign)
|
||||||
|
{
|
||||||
|
return NetworkUtility.JsonSerialize("你今天已经签过到了哦!");
|
||||||
|
}
|
||||||
|
|
||||||
|
string msg = FunGameService.GetSignInResult(user);
|
||||||
|
user.LastTime = DateTime.Now;
|
||||||
|
pc.Add("user", user);
|
||||||
|
pc.Add("signed", true);
|
||||||
|
pc.SaveConfig();
|
||||||
|
return NetworkUtility.JsonSerialize(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NetworkUtility.JsonSerialize(noSaved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("reload")]
|
[HttpGet("reload")]
|
||||||
public string Relaod([FromQuery] long? master = null)
|
public string Relaod([FromQuery] long? master = null)
|
||||||
{
|
{
|
||||||
|
@ -99,6 +99,21 @@ namespace Oshima.Core.WebAPI
|
|||||||
}
|
}
|
||||||
Controller.WriteLine("刷新每日任务");
|
Controller.WriteLine("刷新每日任务");
|
||||||
}
|
}
|
||||||
|
// 刷新签到
|
||||||
|
directoryPath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved";
|
||||||
|
if (Directory.Exists(directoryPath))
|
||||||
|
{
|
||||||
|
string[] filePaths = Directory.GetFiles(directoryPath);
|
||||||
|
foreach (string filePath in filePaths)
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileNameWithoutExtension(filePath);
|
||||||
|
PluginConfig pc = new("saved", fileName);
|
||||||
|
pc.LoadConfig();
|
||||||
|
pc.Add("signed", false);
|
||||||
|
pc.SaveConfig();
|
||||||
|
}
|
||||||
|
Controller.WriteLine("刷新签到");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
TaskScheduler.Shared.AddRecurringTask("刷新boss", TimeSpan.FromHours(1), () =>
|
TaskScheduler.Shared.AddRecurringTask("刷新boss", TimeSpan.FromHours(1), () =>
|
||||||
{
|
{
|
||||||
|
@ -556,41 +556,12 @@ namespace Oshima.Core.Utils
|
|||||||
// 任务结算
|
// 任务结算
|
||||||
EntityModuleConfig<Quest> quests = new("quests", user.Id.ToString());
|
EntityModuleConfig<Quest> quests = new("quests", user.Id.ToString());
|
||||||
quests.LoadConfig();
|
quests.LoadConfig();
|
||||||
if (quests.Count > 0)
|
if (quests.Count > 0 && SettleQuest(user, quests))
|
||||||
{
|
{
|
||||||
IEnumerable<Quest> workingQuests = quests.Values.Where(q => q.Status == 1);
|
|
||||||
foreach (Quest quest in workingQuests)
|
|
||||||
{
|
|
||||||
if (quest.StartTime.HasValue && quest.StartTime.Value.AddMinutes(quest.EstimatedMinutes) <= DateTime.Now)
|
|
||||||
{
|
|
||||||
quest.Status = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IEnumerable<Quest> finishQuests = quests.Values.Where(q => q.Status == 2);
|
|
||||||
foreach (Quest quest in finishQuests)
|
|
||||||
{
|
|
||||||
quest.Status = 3;
|
|
||||||
quest.SettleTime = DateTime.Now;
|
|
||||||
foreach (string name in quest.Awards.Keys)
|
|
||||||
{
|
|
||||||
if (name == General.GameplayEquilibriumConstant.InGameCurrency)
|
|
||||||
{
|
|
||||||
user.Inventory.Credits += quest.Awards[name];
|
|
||||||
}
|
|
||||||
else if (name == General.GameplayEquilibriumConstant.InGameMaterial)
|
|
||||||
{
|
|
||||||
user.Inventory.Materials += quest.Awards[name];
|
|
||||||
}
|
|
||||||
else if (AllItems.FirstOrDefault(i => i.Name == name) is Item item)
|
|
||||||
{
|
|
||||||
Item newItem = item.Copy();
|
|
||||||
newItem.User = user;
|
|
||||||
SetSellAndTradeTime(newItem);
|
|
||||||
user.Inventory.Items.Add(newItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
quests.SaveConfig();
|
quests.SaveConfig();
|
||||||
|
user.LastTime = DateTime.Now;
|
||||||
|
pc.Add("user", user);
|
||||||
|
pc.SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
@ -705,6 +676,89 @@ namespace Oshima.Core.Utils
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetSignInResult(User user)
|
||||||
|
{
|
||||||
|
string msg = "签到成功!本次签到获得:";
|
||||||
|
int currency = Random.Shared.Next(1000, 3000);
|
||||||
|
msg += $"{currency} 金币和";
|
||||||
|
int material = Random.Shared.Next(1000, 3000);
|
||||||
|
msg += $"{material} 材料!额外获得:";
|
||||||
|
user.Inventory.Credits += currency;
|
||||||
|
user.Inventory.Materials += material;
|
||||||
|
int r = Random.Shared.Next(6);
|
||||||
|
double q = Random.Shared.NextDouble() * 100;
|
||||||
|
QualityType type = q switch
|
||||||
|
{
|
||||||
|
<= 69.53 => QualityType.White,
|
||||||
|
> 69.53 and <= 69.53 + 15.35 => QualityType.Green,
|
||||||
|
> 69.53 + 15.35 and <= 69.53 + 15.35 + 9.48 => QualityType.Blue,
|
||||||
|
> 69.53 + 15.35 + 9.48 and <= 69.53 + 15.35 + 9.48 + 4.25 => QualityType.Purple,
|
||||||
|
> 69.53 + 15.35 + 9.48 + 4.25 and <= 69.53 + 15.35 + 9.48 + 4.25 + 1.33 => QualityType.Orange,
|
||||||
|
> 69.53 + 15.35 + 9.48 + 4.25 + 1.33 and <= 69.53 + 15.35 + 9.48 + 4.25 + 1.33 + 0.06 => QualityType.Red,
|
||||||
|
_ => QualityType.White
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (r)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
if ((int)type > (int)QualityType.Orange) type = QualityType.Orange;
|
||||||
|
Item[] 武器 = Equipment.Where(i => i.Id.ToString().StartsWith("11") && i.QualityType == type).ToArray();
|
||||||
|
Item a = 武器[Random.Shared.Next(武器.Length)].Copy();
|
||||||
|
SetSellAndTradeTime(a);
|
||||||
|
user.Inventory.Items.Add(a);
|
||||||
|
msg += ItemSet.GetQualityTypeName(a.QualityType) + ItemSet.GetItemTypeName(a.ItemType) + "【" + a.Name + "】!\r\n" + a.Description;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if ((int)type > (int)QualityType.Green) type = QualityType.Green;
|
||||||
|
Item[] 防具 = Equipment.Where(i => i.Id.ToString().StartsWith("12") && i.QualityType == type).ToArray();
|
||||||
|
Item b = 防具[Random.Shared.Next(防具.Length)].Copy();
|
||||||
|
SetSellAndTradeTime(b);
|
||||||
|
user.Inventory.Items.Add(b);
|
||||||
|
msg += ItemSet.GetQualityTypeName(b.QualityType) + ItemSet.GetItemTypeName(b.ItemType) + "【" + b.Name + "】!\r\n" + b.Description;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
if ((int)type > (int)QualityType.Green) type = QualityType.Green;
|
||||||
|
Item[] 鞋子 = Equipment.Where(i => i.Id.ToString().StartsWith("13") && i.QualityType == type).ToArray();
|
||||||
|
Item c = 鞋子[Random.Shared.Next(鞋子.Length)].Copy();
|
||||||
|
SetSellAndTradeTime(c);
|
||||||
|
user.Inventory.Items.Add(c);
|
||||||
|
msg += ItemSet.GetQualityTypeName(c.QualityType) + ItemSet.GetItemTypeName(c.ItemType) + "【" + c.Name + "】!\r\n" + c.Description;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
if ((int)type > (int)QualityType.Purple) type = QualityType.Purple;
|
||||||
|
Item[] 饰品 = Equipment.Where(i => i.Id.ToString().StartsWith("14") && i.QualityType == type).ToArray();
|
||||||
|
Item d = 饰品[Random.Shared.Next(饰品.Length)].Copy();
|
||||||
|
SetSellAndTradeTime(d);
|
||||||
|
user.Inventory.Items.Add(d);
|
||||||
|
msg += ItemSet.GetQualityTypeName(d.QualityType) + ItemSet.GetItemTypeName(d.ItemType) + "【" + d.Name + "】!\r\n" + d.Description;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
if ((int)type > (int)QualityType.Orange) type = QualityType.Orange;
|
||||||
|
Item mfk = GenerateMagicCard(type);
|
||||||
|
SetSellAndTradeTime(mfk);
|
||||||
|
user.Inventory.Items.Add(mfk);
|
||||||
|
msg += ItemSet.GetQualityTypeName(mfk.QualityType) + ItemSet.GetItemTypeName(mfk.ItemType) + "【" + mfk.Name + "】!\r\n" + mfk.Description;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
if ((int)type > (int)QualityType.Orange) type = QualityType.Orange;
|
||||||
|
Item? mfkb = GenerateMagicCardPack(3, type);
|
||||||
|
if (mfkb != null)
|
||||||
|
{
|
||||||
|
SetSellAndTradeTime(mfkb);
|
||||||
|
user.Inventory.Items.Add(mfkb);
|
||||||
|
msg += ItemSet.GetQualityTypeName(mfkb.QualityType) + ItemSet.GetItemTypeName(mfkb.ItemType) + "【" + mfkb.Name + "】!\r\n" + mfkb.Description;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
public static void SetSellAndTradeTime(Item item, bool sell = false, bool trade = true, DateTime? nextSell = null, DateTime? nextTrade = null)
|
public static void SetSellAndTradeTime(Item item, bool sell = false, bool trade = true, DateTime? nextSell = null, DateTime? nextTrade = null)
|
||||||
{
|
{
|
||||||
if (sell)
|
if (sell)
|
||||||
@ -1790,8 +1844,8 @@ namespace Oshima.Core.Utils
|
|||||||
{
|
{
|
||||||
int minutes = Random.Shared.Next(10, 41);
|
int minutes = Random.Shared.Next(10, 41);
|
||||||
Dictionary<string, int> items = [];
|
Dictionary<string, int> items = [];
|
||||||
items[General.GameplayEquilibriumConstant.InGameCurrency] = minutes * 50;
|
items[General.GameplayEquilibriumConstant.InGameCurrency] = minutes * 20;
|
||||||
items[General.GameplayEquilibriumConstant.InGameMaterial] = minutes / 10 * 2;
|
items[General.GameplayEquilibriumConstant.InGameMaterial] = minutes / 8 * 1;
|
||||||
int index = Random.Shared.Next(AllItems.Count);
|
int index = Random.Shared.Next(AllItems.Count);
|
||||||
Item item = AllItems[index];
|
Item item = AllItems[index];
|
||||||
items.Add(item.Name, 1);
|
items.Add(item.Name, 1);
|
||||||
@ -1816,13 +1870,13 @@ namespace Oshima.Core.Utils
|
|||||||
};
|
};
|
||||||
quests.Add(quest.GetIdName(), quest);
|
quests.Add(quest.GetIdName(), quest);
|
||||||
}
|
}
|
||||||
return string.Join("\r\n", quests);
|
return "☆--- 今日任务列表 ---☆\r\n" + string.Join("\r\n", quests.Values.Select(q => q.ToString())) + "\r\n温馨提示:请务必在次日 4:00 前完成任务结算,未结算的任务都会被取消!";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (quests.Count > 0)
|
if (quests.Count > 0)
|
||||||
{
|
{
|
||||||
return string.Join("\r\n", quests);
|
return "☆--- 今日任务列表 ---☆\r\n" + string.Join("\r\n", quests.Values.Select(q => q.ToString())) + "\r\n温馨提示:请务必在次日 4:00 前完成任务结算,未结算的任务都会被取消!";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1830,5 +1884,45 @@ namespace Oshima.Core.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool SettleQuest(User user, EntityModuleConfig<Quest> quests)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
IEnumerable<Quest> workingQuests = quests.Values.Where(q => q.Status == QuestState.InProgress);
|
||||||
|
foreach (Quest quest in workingQuests)
|
||||||
|
{
|
||||||
|
if (quest.StartTime.HasValue && quest.StartTime.Value.AddMinutes(quest.EstimatedMinutes) <= DateTime.Now)
|
||||||
|
{
|
||||||
|
quest.Status = QuestState.Completed;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IEnumerable<Quest> finishQuests = quests.Values.Where(q => q.Status == QuestState.Completed);
|
||||||
|
foreach (Quest quest in finishQuests)
|
||||||
|
{
|
||||||
|
quest.Status = QuestState.Settled;
|
||||||
|
quest.SettleTime = DateTime.Now;
|
||||||
|
foreach (string name in quest.Awards.Keys)
|
||||||
|
{
|
||||||
|
if (name == General.GameplayEquilibriumConstant.InGameCurrency)
|
||||||
|
{
|
||||||
|
user.Inventory.Credits += quest.Awards[name];
|
||||||
|
}
|
||||||
|
else if (name == General.GameplayEquilibriumConstant.InGameMaterial)
|
||||||
|
{
|
||||||
|
user.Inventory.Materials += quest.Awards[name];
|
||||||
|
}
|
||||||
|
else if (AllItems.FirstOrDefault(i => i.Name == name) is Item item)
|
||||||
|
{
|
||||||
|
Item newItem = item.Copy();
|
||||||
|
newItem.User = user;
|
||||||
|
SetSellAndTradeTime(newItem);
|
||||||
|
user.Inventory.Items.Add(newItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user