From ea4100e518171207450e1a385b320319692f2589 Mon Sep 17 00:00:00 2001 From: milimoe Date: Mon, 18 Nov 2024 22:10:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaCore/Controllers/FunGameController.cs | 588 +++++++++++-------- OshimaCore/OshimaWebAPI.cs | 2 + OshimaCore/Utils/FunGameService.cs | 340 +++++++++++ OshimaModules/Skills/MagicalGirl/缁濆棰嗗煙.cs | 1 + 4 files changed, 676 insertions(+), 255 deletions(-) diff --git a/OshimaCore/Controllers/FunGameController.cs b/OshimaCore/Controllers/FunGameController.cs index 085778b..f201735 100644 --- a/OshimaCore/Controllers/FunGameController.cs +++ b/OshimaCore/Controllers/FunGameController.cs @@ -7,7 +7,6 @@ using Milimoe.FunGame.Core.Library.Constant; using Oshima.Core.Configs; using Oshima.Core.Models; using Oshima.Core.Utils; -using Oshima.FunGame.OshimaModules.Skills; namespace Oshima.Core.Controllers { @@ -16,6 +15,8 @@ namespace Oshima.Core.Controllers public class FunGameController(ILogger logger) : ControllerBase { private readonly ILogger _logger = logger; + private const int drawCardReduce = 2000; + private const int drawCardReduce_Material = 10; private const string noSaved = "你还没有创建存档!请发送【创建存档】创建。"; [HttpGet("test")] @@ -219,193 +220,14 @@ namespace Oshima.Core.Controllers } [HttpGet("cjs")] - public string GetCharacterIntroduce([FromQuery] int? id = null) + public string GetCharacterInfo([FromQuery] int? id = null) { if (id != null && id > 0 && id <= FunGameService.Characters.Count) { Character c = FunGameService.Characters[Convert.ToInt32(id) - 1].Copy(); c.Level = General.GameplayEquilibriumConstant.MaxLevel; c.NormalAttack.Level = General.GameplayEquilibriumConstant.MaxNormalAttackLevel; - - if (id == 1) - { - Skill META马 = new META马(c) - { - Level = 1 - }; - c.Skills.Add(META马); - - Skill 力量爆发 = new 力量爆发(c) - { - Level = General.GameplayEquilibriumConstant.MaxMagicLevel - }; - c.Skills.Add(力量爆发); - } - - if (id == 2) - { - Skill 心灵之火 = new 心灵之火(c) - { - Level = 1 - }; - c.Skills.Add(心灵之火); - - Skill 天赐之力 = new 天赐之力(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(天赐之力); - } - - if (id == 3) - { - Skill 魔法震荡 = new 魔法震荡(c) - { - Level = 1 - }; - c.Skills.Add(魔法震荡); - - Skill 魔法涌流 = new 魔法涌流(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(魔法涌流); - } - - if (id == 4) - { - Skill 灵能反射 = new 灵能反射(c) - { - Level = 1 - }; - c.Skills.Add(灵能反射); - - Skill 三重叠加 = new 三重叠加(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(三重叠加); - } - - if (id == 5) - { - Skill 智慧与力量 = new 智慧与力量(c) - { - Level = 1 - }; - c.Skills.Add(智慧与力量); - - Skill 变幻之心 = new 变幻之心(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(变幻之心); - } - - if (id == 6) - { - Skill 致命打击 = new 致命打击(c) - { - Level = 1 - }; - c.Skills.Add(致命打击); - - Skill 精准打击 = new 精准打击(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(精准打击); - } - - if (id == 7) - { - Skill 毁灭之势 = new 毁灭之势(c) - { - Level = 1 - }; - c.Skills.Add(毁灭之势); - - Skill 绝对领域 = new 绝对领域(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(绝对领域); - } - - if (id == 8) - { - Skill 枯竭打击 = new 枯竭打击(c) - { - Level = 1 - }; - c.Skills.Add(枯竭打击); - - Skill 能量毁灭 = new 能量毁灭(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(能量毁灭); - } - - if (id == 9) - { - Skill 玻璃大炮 = new 玻璃大炮(c) - { - Level = 1 - }; - c.Skills.Add(玻璃大炮); - - Skill 迅捷之势 = new 迅捷之势(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(迅捷之势); - } - - if (id == 10) - { - Skill 累积之压 = new 累积之压(c) - { - Level = 1 - }; - c.Skills.Add(累积之压); - - Skill 嗜血本能 = new 嗜血本能(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(嗜血本能); - } - - if (id == 11) - { - Skill 敏捷之刃 = new 敏捷之刃(c) - { - Level = 1 - }; - c.Skills.Add(敏捷之刃); - - Skill 平衡强化 = new 平衡强化(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(平衡强化); - } - - if (id == 12) - { - Skill 弱者猎手 = new 弱者猎手(c) - { - Level = 1 - }; - c.Skills.Add(弱者猎手); - - Skill 血之狂欢 = new 血之狂欢(c) - { - Level = General.GameplayEquilibriumConstant.MaxSkillLevel - }; - c.Skills.Add(血之狂欢); - } + FunGameService.AddCharacterSkills(c, 1, General.GameplayEquilibriumConstant.MaxSkillLevel, General.GameplayEquilibriumConstant.MaxSuperSkillLevel); return NetworkUtility.JsonSerialize(c.GetInfo().Trim()); } @@ -487,7 +309,7 @@ namespace Oshima.Core.Controllers if (pc.Count == 0) { User user = Factory.GetUser(userid, username, DateTime.Now, DateTime.Now, userid + "@qq.com", username); - user.Inventory.Credits = 100; + user.Inventory.Credits = 5000; pc.Add("user", user); pc.SaveConfig(); return NetworkUtility.JsonSerialize($"创建存档成功!你的用户名是【{username}】。"); @@ -549,8 +371,7 @@ namespace Oshima.Core.Controllers int characterCount = 0; int itemCount = 0; - int characterSequence = characters.Take((showPage - 1) * 10).Count(); - int itemSequence = items.Take((showPage - 1) * 10).Count() - characterSequence; + int prevSequence = dict.Take((showPage - 1) * 10).Count(); foreach (int index in seq) { @@ -564,7 +385,7 @@ namespace Oshima.Core.Controllers showCharacter = false; list.Add("======= 角色 ======="); } - str = $"{characterSequence + characterCount}. {character.ToStringWithLevelWithOutUser()}"; + str = $"{prevSequence + characterCount}. {character.ToStringWithLevelWithOutUser()}"; } if (obj is Item item) { @@ -574,7 +395,7 @@ namespace Oshima.Core.Controllers showItem = false; list.Add("======= 物品 ======="); } - str = $"{itemSequence + itemCount}. [{ItemSet.GetQualityTypeName(item.QualityType)}|{ItemSet.GetItemTypeName(item.ItemType)}] {item.Name}\r\n"; + str = $"{index - (characterCount > 0 ? prevSequence + characterCount : characters.Count)}. [{ItemSet.GetQualityTypeName(item.QualityType)}|{ItemSet.GetItemTypeName(item.ItemType)}] {item.Name}\r\n"; str += $"{item.ToStringInventory(false).Trim()}"; } list.Add(str); @@ -593,9 +414,93 @@ namespace Oshima.Core.Controllers } return list; } + + [HttpPost("ckkc3")] + public List GetInventoryInfo3([FromQuery] long? qq = null, [FromQuery] int? page = null, [FromQuery] int? order = null, [FromQuery] int? orderqty = null) + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + int showPage = page ?? 1; + if (showPage <= 0) showPage = 1; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + List list = []; + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + list.Add($"☆★☆ {user.Inventory.Name} ☆★☆"); + list.Add($"{General.GameplayEquilibriumConstant.InGameCurrency}:{user.Inventory.Credits:0.00}"); + list.Add($"{General.GameplayEquilibriumConstant.InGameMaterial}:{user.Inventory.Materials:0.00}"); + List items = [.. user.Inventory.Items]; + + Dictionary> itemCategory = []; + foreach (Item item in items) + { + if (!itemCategory.TryAdd(item.GetIdName(), [item])) + { + itemCategory[item.GetIdName()].Add(item); + } + } + if (orderqty != 0) + { + IOrderedEnumerable>>? orderEnum = null; + if (order != 0) + { + orderEnum = order switch + { + 1 => itemCategory.OrderBy(kv => kv.Value.FirstOrDefault()?.QualityType ?? 0), + 2 => itemCategory.OrderByDescending(kv => kv.Value.FirstOrDefault()?.QualityType ?? 0), + 3 => itemCategory.OrderBy(kv => kv.Value.FirstOrDefault()?.ItemType ?? 0), + 4 => itemCategory.OrderByDescending(kv => kv.Value.FirstOrDefault()?.ItemType ?? 0), + _ => itemCategory.OrderBy(kv => 0) + }; + } + if (orderEnum != null) + { + if (orderqty == 1) + { + orderEnum = orderEnum.ThenBy(kv => kv.Value.Count); + } + else + { + orderEnum = orderEnum.ThenByDescending(kv => kv.Value.Count); + } + itemCategory = orderEnum.ToDictionary(); + } + } + + int maxPage = (int)Math.Ceiling((double)itemCategory.Count / 10); + if (showPage <= maxPage) + { + List keys = [.. FunGameService.GetPage(itemCategory.Keys, showPage, 10)]; + int itemCount = 0; + list.Add("======= 物品 ======="); + foreach (string key in keys) + { + itemCount++; + List objs = itemCategory[key]; + string str = $"{itemCount}. [{ItemSet.GetQualityTypeName(objs[0].QualityType)}|{ItemSet.GetItemTypeName(objs[0].ItemType)}] {objs[0].Name}\r\n"; + str += $"物品序号:{string.Join(",", objs.Select(i => items.IndexOf(i) + 1))}\r\n"; + str += $"拥有数量:{objs.Count}(可出售数量:{objs.Count(i => i.IsSellable)},可交易数量:{objs.Count(i => i.IsTradable)})"; + list.Add(str); + } + list.Add($"页数:{showPage} / {maxPage}"); + } + else + { + list.Add($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {showPage} 页。"); + } + } + else + { + list.Add(noSaved); + } + return list; + } [HttpPost("ck")] - public string DrawCards([FromQuery] long? qq = null) + public string DrawCard([FromQuery] long? qq = null) { long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); @@ -606,8 +511,8 @@ namespace Oshima.Core.Controllers { User user = FunGameService.GetUser(pc); - int reduce = 1; - if (user.Inventory.Credits > 0) + int reduce = drawCardReduce; + if (user.Inventory.Credits >= reduce) { user.Inventory.Credits -= reduce; } @@ -619,77 +524,13 @@ namespace Oshima.Core.Controllers double dice = Random.Shared.NextDouble(); if (dice > 0.8) { - string msg = $"消耗 {reduce} {General.GameplayEquilibriumConstant.InGameCurrency},恭喜你抽到了:"; - int r = Random.Shared.Next(7); - switch (r) - { - case 1: - Item[] 武器 = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("11")).ToArray(); - Item a = 武器[Random.Shared.Next(武器.Length)].Copy(); - user.Inventory.Items.Add(a); - msg += ItemSet.GetQualityTypeName(a.QualityType) + ItemSet.GetItemTypeName(a.ItemType) + "【" + a.Name + "】!\r\n" + a.Description; - break; - - case 2: - Item[] 防具 = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("12")).ToArray(); - Item b = 防具[Random.Shared.Next(防具.Length)].Copy(); - user.Inventory.Items.Add(b); - msg += ItemSet.GetQualityTypeName(b.QualityType) + ItemSet.GetItemTypeName(b.ItemType) + "【" + b.Name + "】!\r\n" + b.Description; - break; - - case 3: - Item[] 鞋子 = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("13")).ToArray(); - Item c = 鞋子[Random.Shared.Next(鞋子.Length)].Copy(); - user.Inventory.Items.Add(c); - msg += ItemSet.GetQualityTypeName(c.QualityType) + ItemSet.GetItemTypeName(c.ItemType) + "【" + c.Name + "】!\r\n" + c.Description; - break; - - case 4: - Item[] 饰品 = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("14")).ToArray(); - Item d = 饰品[Random.Shared.Next(饰品.Length)].Copy(); - user.Inventory.Items.Add(d); - msg += ItemSet.GetQualityTypeName(d.QualityType) + ItemSet.GetItemTypeName(d.ItemType) + "【" + d.Name + "】!\r\n" + d.Description; - break; - - case 5: - Character character = FunGameService.Characters[Random.Shared.Next(FunGameService.Characters.Count)].Copy(); - if (user.Inventory.Characters.Any(c => c.Id == character.Id)) - { - user.Inventory.Materials += 50; - msg += "【" + character.ToStringWithOutUser() + "】!\r\n但是你已经拥有此角色,转换为【50】" + General.GameplayEquilibriumConstant.InGameMaterial + "!"; - } - else - { - user.Inventory.Characters.Add(character); - msg += "【" + character.ToStringWithOutUser() + "】!\r\n输入【查角色" + character.Id + "】可以获取此角色完整信息。"; - } - break; - - case 6: - Item mfk = FunGameService.GenerateMagicCard(); - user.Inventory.Items.Add(mfk); - msg += ItemSet.GetQualityTypeName(mfk.QualityType) + ItemSet.GetItemTypeName(mfk.ItemType) + "【" + mfk.Name + "】!\r\n" + mfk.Description; - break; - - case 0: - default: - Item? mfkb = FunGameService.GenerateMagicCardPack(3); - if (mfkb != null) - { - mfkb.IsTradable = false; - mfkb.NextTradableTime = DateTimeUtility.GetTradableTime(); - user.Inventory.Items.Add(mfkb); - msg += ItemSet.GetQualityTypeName(mfkb.QualityType) + ItemSet.GetItemTypeName(mfkb.ItemType) + "【" + mfkb.Name + "】!\r\n" + mfkb.Description; - } - break; - } + string msg = FunGameService.GetDrawCardResult(reduce, user); pc.Add("user", user); pc.SaveConfig(); return NetworkUtility.JsonSerialize(msg); } else { - pc.Add("user", user); pc.SaveConfig(); return NetworkUtility.JsonSerialize($"消耗 {reduce} {General.GameplayEquilibriumConstant.InGameCurrency},你什么也没抽中……"); } @@ -699,6 +540,243 @@ namespace Oshima.Core.Controllers return NetworkUtility.JsonSerialize(noSaved); } } + + [HttpPost("ck10")] + public List DrawCards([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); + + int reduce = drawCardReduce * 10; + if (user.Inventory.Credits >= reduce) + { + user.Inventory.Credits -= reduce; + } + else + { + return [$"你的{General.GameplayEquilibriumConstant.InGameCurrency}不足 {reduce} 呢,无法十连抽卡!"]; + } + + List result = [$"消耗 {reduce} {General.GameplayEquilibriumConstant.InGameCurrency},恭喜你抽到了:"]; + int count = 0; + for (int i = 0; i < 10; i++) + { + double dice = Random.Shared.NextDouble(); + if (dice > 0.8) + { + count++; + result.Add(FunGameService.GetDrawCardResult(reduce, user, true, count)); + } + } + if (result.Count == 1) + { + result[0] = $"消耗 {reduce} {General.GameplayEquilibriumConstant.InGameCurrency},你什么也没抽中……"; + } + pc.Add("user", user); + pc.SaveConfig(); + return result; + } + else + { + return [noSaved]; + } + } + + [HttpPost("clck")] + public string DrawCard_Material([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); + + int reduce = drawCardReduce_Material; + if (user.Inventory.Materials >= reduce) + { + user.Inventory.Materials -= reduce; + } + else + { + return NetworkUtility.JsonSerialize($"你的{General.GameplayEquilibriumConstant.InGameMaterial}不足 {reduce} 呢,无法抽卡!"); + } + + double dice = Random.Shared.NextDouble(); + if (dice > 0.8) + { + string msg = FunGameService.GetDrawCardResult(reduce, user); + pc.Add("user", user); + pc.SaveConfig(); + return NetworkUtility.JsonSerialize(msg); + } + else + { + pc.SaveConfig(); + return NetworkUtility.JsonSerialize($"消耗 {reduce} {General.GameplayEquilibriumConstant.InGameMaterial},你什么也没抽中……"); + } + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + + [HttpPost("clck10")] + public List DrawCards_Material([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); + + int reduce = drawCardReduce_Material * 10; + if (user.Inventory.Materials >= reduce) + { + user.Inventory.Materials -= reduce; + } + else + { + return [$"你的{General.GameplayEquilibriumConstant.InGameMaterial}不足 {reduce} 呢,无法十连抽卡!"]; + } + + List result = [$"消耗 {reduce} {General.GameplayEquilibriumConstant.InGameMaterial},恭喜你抽到了:"]; + int count = 0; + for (int i = 0; i < 10; i++) + { + double dice = Random.Shared.NextDouble(); + if (dice > 0.8) + { + count++; + result.Add(FunGameService.GetDrawCardResult(reduce, user, true, count)); + } + } + if (result.Count == 1) + { + result[0] = $"消耗 {reduce} {General.GameplayEquilibriumConstant.InGameMaterial},你什么也没抽中……"; + } + pc.Add("user", user); + pc.SaveConfig(); + return result; + } + else + { + return [noSaved]; + } + } + + [HttpPost("dhjb")] + public string ExchangeCredits([FromQuery] long? qq = null, [FromQuery] double? materials = null) + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + double useMaterials = materials ?? 0; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + int reduce = useMaterials > 0 && useMaterials > 10 ? (int)useMaterials : 10; + + if (reduce % 10 != 0 && reduce > reduce % 10) + { + reduce -= reduce % 10; + } + else + { + return NetworkUtility.JsonSerialize($"你的{General.GameplayEquilibriumConstant.InGameMaterial}不足 {reduce},兑换失败!"); + } + if (user.Inventory.Materials >= reduce) + { + int reward = reduce / 10 * 2000; + user.Inventory.Credits += reward; + user.Inventory.Materials -= reduce; + pc.Add("user", user); + pc.SaveConfig(); + return NetworkUtility.JsonSerialize($"兑换成功!你消耗了 {reduce} {General.GameplayEquilibriumConstant.InGameMaterial},增加了 {reward} {General.GameplayEquilibriumConstant.InGameCurrency}!"); + } + else + { + return NetworkUtility.JsonSerialize($"你的{General.GameplayEquilibriumConstant.InGameMaterial}不足 {reduce},兑换失败!"); + } + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + + [HttpPost("cckjs")] + public string GetCharacterInfoFromInventory([FromQuery] long? qq = null, [FromQuery] int? index = null) + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + int itemIndex = index ?? 0; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + if (itemIndex > 0 && itemIndex <= user.Inventory.Characters.Count) + { + Character character = user.Inventory.Characters.ToList()[itemIndex - 1]; + return NetworkUtility.JsonSerialize($"这是你库存中序号为 {itemIndex} 的角色详细信息:\r\n{character.GetInfo().Trim()}"); + } + else + { + return NetworkUtility.JsonSerialize($"没有找到与这个序号相对应的角色!"); + } + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + + [HttpPost("cckwp")] + public string GetItemInfoFromInventory([FromQuery] long? qq = null, [FromQuery] int? index = null) + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + int itemIndex = index ?? 0; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + if (itemIndex > 0 && itemIndex <= user.Inventory.Items.Count) + { + Item item = user.Inventory.Items.ToList()[itemIndex - 1]; + return NetworkUtility.JsonSerialize($"这是你库存中序号为 {itemIndex} 的物品详细信息:\r\n{item.ToStringInventory(true).Trim()}"); + } + else + { + return NetworkUtility.JsonSerialize($"没有找到与这个序号相对应的物品!"); + } + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } [HttpGet("reload")] public string Relaod([FromQuery] long? master = null) diff --git a/OshimaCore/OshimaWebAPI.cs b/OshimaCore/OshimaWebAPI.cs index 5ba4dfd..8cbec41 100644 --- a/OshimaCore/OshimaWebAPI.cs +++ b/OshimaCore/OshimaWebAPI.cs @@ -82,6 +82,7 @@ namespace Oshima.Core.WebAPI check9 = false; Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("\r閲嶇疆鐗╁搧浜ゆ槗鍐峰嵈鏃堕棿銆"); + await FunGameService.AllowSellAndTrade(); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\r> "); } @@ -94,6 +95,7 @@ namespace Oshima.Core.WebAPI check15 = false; Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("\r閲嶇疆鐗╁搧浜ゆ槗鍐峰嵈鏃堕棿銆"); + await FunGameService.AllowSellAndTrade(); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\r> "); } diff --git a/OshimaCore/Utils/FunGameService.cs b/OshimaCore/Utils/FunGameService.cs index 035a262..c33cc9c 100644 --- a/OshimaCore/Utils/FunGameService.cs +++ b/OshimaCore/Utils/FunGameService.cs @@ -480,5 +480,345 @@ namespace Oshima.Core.Utils { return list.Skip((showPage - 1) * pageSize).Take(pageSize).ToList(); } + + public static string GetDrawCardResult(int reduce, User user, bool isMulti = false, int multiCount = 1) + { + string msg = ""; + if (!isMulti) + { + msg = $"娑堣 {reduce} {General.GameplayEquilibriumConstant.InGameCurrency}锛屾伃鍠滀綘鎶藉埌浜嗭細"; + } + int r = Random.Shared.Next(7); + double q = Random.Shared.NextDouble() * 100; + QualityType type = q switch + { + <= 37.21 => QualityType.White, + <= 37.21 + 27.94 => QualityType.Green, + <= 37.21 + 27.94 + 16.68 => QualityType.Blue, + <= 37.21 + 27.94 + 16.68 + 9.79 => QualityType.Purple, + <= 37.21 + 27.94 + 16.68 + 9.79 + 5.05 => QualityType.Orange, + <= 37.21 + 27.94 + 16.68 + 9.79 + 5.05 + 2.73 => QualityType.Red, + _ => QualityType.Gold + }; + 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: + Character character = Characters[Random.Shared.Next(Characters.Count)].Copy(); + AddCharacterSkills(character, 1, 0, 0); + if (user.Inventory.Characters.Any(c => c.Id == character.Id)) + { + user.Inventory.Materials += 50; + msg += "銆" + character.ToStringWithOutUser() + "銆戯紒\r\n浣嗘槸浣犲凡缁忔嫢鏈夋瑙掕壊锛岃浆鎹负銆50銆" + General.GameplayEquilibriumConstant.InGameMaterial + "锛"; + } + else + { + user.Inventory.Characters.Add(character); + msg += "銆" + character.ToStringWithOutUser() + "銆戯紒\r\n杈撳叆銆愭煡瑙掕壊" + character.Id + "銆戝彲浠ヨ幏鍙栨瑙掕壊瀹屾暣淇℃伅銆"; + } + break; + + case 6: + 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: + 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; + } + if (isMulti) msg = $"{multiCount}. \r\n{msg}"; + return msg; + } + + public static void SetSellAndTradeTime(Item item, bool sell = false, bool trade = true, DateTime? nextSell = null, DateTime? nextTrade = null) + { + if (sell) + { + item.IsSellable = false; + item.NextSellableTime = DateTimeUtility.GetTradableTime(nextSell); + } + if (trade) + { + item.IsTradable = false; + item.NextTradableTime = DateTimeUtility.GetTradableTime(nextTrade); + } + } + + public static async Task AllowSellAndTrade() + { + string msg; + string dpath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved"; + if (Directory.Exists(dpath)) + { + string[] jsonFiles = Directory.GetFiles(dpath, "*.json"); + + List tasks = []; + foreach (string file in jsonFiles) + { + tasks.Add(Task.Run(() => + { + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); + PluginConfig pc = new("saved", fileNameWithoutExtension); + pc.LoadConfig(); + if (pc.Count > 0) + { + User user = GetUser(pc); + foreach (Item item in user.Inventory.Items) + { + if (!item.IsSellable && item.NextSellableTime != DateTime.MinValue && DateTime.Now >= item.NextSellableTime) + { + item.NextSellableTime = DateTime.MinValue; + item.IsSellable = true; + } + if (!item.IsTradable && item.NextTradableTime != DateTime.MinValue && DateTime.Now >= item.NextTradableTime) + { + item.NextTradableTime = DateTime.MinValue; + item.IsTradable = true; + } + } + pc.Add("user", user); + pc.SaveConfig(); + } + })); + } + await Task.WhenAll(tasks); + msg = "宸叉竻鐞嗘墍鏈夌帺瀹剁殑鐗╁搧浜ゆ槗鏃堕棿銆"; + } + else + { + msg = "瀛樻。鐩綍涓嶅瓨鍦紝鏃犳硶娓呯悊浜ゆ槗鏃堕棿銆"; + } + return msg; + } + + public static void AddCharacterSkills(Character character, int passiveLevel, int skillLevel, int superLevel) + { + long id = character.Id; + Math.Sign(skillLevel); + if (id == 1) + { + Skill META椹 = new META椹(character) + { + Level = passiveLevel + }; + character.Skills.Add(META椹); + + Skill 鍔涢噺鐖嗗彂 = new 鍔涢噺鐖嗗彂(character) + { + Level = superLevel + }; + character.Skills.Add(鍔涢噺鐖嗗彂); + } + + if (id == 2) + { + Skill 蹇冪伒涔嬬伀 = new 蹇冪伒涔嬬伀(character) + { + Level = passiveLevel + }; + character.Skills.Add(蹇冪伒涔嬬伀); + + Skill 澶╄祼涔嬪姏 = new 澶╄祼涔嬪姏(character) + { + Level = superLevel + }; + character.Skills.Add(澶╄祼涔嬪姏); + } + + if (id == 3) + { + Skill 榄旀硶闇囪崱 = new 榄旀硶闇囪崱(character) + { + Level = passiveLevel + }; + character.Skills.Add(榄旀硶闇囪崱); + + Skill 榄旀硶娑屾祦 = new 榄旀硶娑屾祦(character) + { + Level = superLevel + }; + character.Skills.Add(榄旀硶娑屾祦); + } + + if (id == 4) + { + Skill 鐏佃兘鍙嶅皠 = new 鐏佃兘鍙嶅皠(character) + { + Level = passiveLevel + }; + character.Skills.Add(鐏佃兘鍙嶅皠); + + Skill 涓夐噸鍙犲姞 = new 涓夐噸鍙犲姞(character) + { + Level = superLevel + }; + character.Skills.Add(涓夐噸鍙犲姞); + } + + if (id == 5) + { + Skill 鏅烘収涓庡姏閲 = new 鏅烘収涓庡姏閲(character) + { + Level = passiveLevel + }; + character.Skills.Add(鏅烘収涓庡姏閲); + + Skill 鍙樺够涔嬪績 = new 鍙樺够涔嬪績(character) + { + Level = superLevel + }; + character.Skills.Add(鍙樺够涔嬪績); + } + + if (id == 6) + { + Skill 鑷村懡鎵撳嚮 = new 鑷村懡鎵撳嚮(character) + { + Level = passiveLevel + }; + character.Skills.Add(鑷村懡鎵撳嚮); + + Skill 绮惧噯鎵撳嚮 = new 绮惧噯鎵撳嚮(character) + { + Level = superLevel + }; + character.Skills.Add(绮惧噯鎵撳嚮); + } + + if (id == 7) + { + Skill 姣佺伃涔嬪娍 = new 姣佺伃涔嬪娍(character) + { + Level = passiveLevel + }; + character.Skills.Add(姣佺伃涔嬪娍); + + Skill 缁濆棰嗗煙 = new 缁濆棰嗗煙(character) + { + Level = superLevel + }; + character.Skills.Add(缁濆棰嗗煙); + } + + if (id == 8) + { + Skill 鏋鎵撳嚮 = new 鏋鎵撳嚮(character) + { + Level = passiveLevel + }; + character.Skills.Add(鏋鎵撳嚮); + + Skill 鑳介噺姣佺伃 = new 鑳介噺姣佺伃(character) + { + Level = superLevel + }; + character.Skills.Add(鑳介噺姣佺伃); + } + + if (id == 9) + { + Skill 鐜荤拑澶х偖 = new 鐜荤拑澶х偖(character) + { + Level = passiveLevel + }; + character.Skills.Add(鐜荤拑澶х偖); + + Skill 杩呮嵎涔嬪娍 = new 杩呮嵎涔嬪娍(character) + { + Level = superLevel + }; + character.Skills.Add(杩呮嵎涔嬪娍); + } + + if (id == 10) + { + Skill 绱Н涔嬪帇 = new 绱Н涔嬪帇(character) + { + Level = passiveLevel + }; + character.Skills.Add(绱Н涔嬪帇); + + Skill 鍡滆鏈兘 = new 鍡滆鏈兘(character) + { + Level = superLevel + }; + character.Skills.Add(鍡滆鏈兘); + } + + if (id == 11) + { + Skill 鏁忔嵎涔嬪垉 = new 鏁忔嵎涔嬪垉(character) + { + Level = passiveLevel + }; + character.Skills.Add(鏁忔嵎涔嬪垉); + + Skill 骞宠 寮哄寲 = new 骞宠 寮哄寲(character) + { + Level = superLevel + }; + character.Skills.Add(骞宠 寮哄寲); + } + + if (id == 12) + { + Skill 寮辫呯寧鎵 = new 寮辫呯寧鎵(character) + { + Level = passiveLevel + }; + character.Skills.Add(寮辫呯寧鎵); + + Skill 琛涔嬬媯娆 = new 琛涔嬬媯娆(character) + { + Level = superLevel + }; + character.Skills.Add(琛涔嬬媯娆); + } + } } } diff --git a/OshimaModules/Skills/MagicalGirl/缁濆棰嗗煙.cs b/OshimaModules/Skills/MagicalGirl/缁濆棰嗗煙.cs index dad660f..3800dd4 100644 --- a/OshimaModules/Skills/MagicalGirl/缁濆棰嗗煙.cs +++ b/OshimaModules/Skills/MagicalGirl/缁濆棰嗗煙.cs @@ -50,6 +50,7 @@ namespace Oshima.FunGame.OshimaModules.Skills if (enemy == Skill.Character && damageResult != DamageResult.Evaded) { WriteLine($"[ {enemy} ] 鍙戝姩浜嗙粷瀵归鍩燂紝宸у鐨勫寲瑙d簡姝や激瀹筹紒"); + isEvaded = true; return 0; } return 0;