From 908817764721a76d5bcb5398d6e7017b5bafee7c Mon Sep 17 00:00:00 2001 From: milimoe Date: Sun, 22 Dec 2024 22:25:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E8=A7=A3=E7=89=A9?= =?UTF-8?q?=E5=93=81=E3=80=81=E4=BD=BF=E7=94=A8=E9=AD=94=E6=B3=95=E5=8D=A1?= =?UTF-8?q?=E3=80=81=E5=90=88=E6=88=90=E9=AD=94=E6=B3=95=E5=8D=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaCore/Controllers/FunGameController.cs | 426 +++++++++++++++++++- OshimaCore/Utils/FunGameService.cs | 119 +++--- 2 files changed, 489 insertions(+), 56 deletions(-) diff --git a/OshimaCore/Controllers/FunGameController.cs b/OshimaCore/Controllers/FunGameController.cs index de59154..84273f0 100644 --- a/OshimaCore/Controllers/FunGameController.cs +++ b/OshimaCore/Controllers/FunGameController.cs @@ -1429,7 +1429,7 @@ namespace Oshima.Core.Controllers targets.Add(character); } } - + if (FunGameService.UseItem(item, user, [.. targets], out string msg)) { user.LastTime = DateTime.Now; @@ -1476,10 +1476,10 @@ namespace Oshima.Core.Controllers { User user = FunGameService.GetUser(pc); - IEnumerable items = user.Inventory.Items.Where(i => i.Name == name); + IEnumerable items = user.Inventory.Items.Where(i => i.Name == name && i.Character is null && i.ItemType != ItemType.MagicCard); if (!items.Any()) { - return NetworkUtility.JsonSerialize($"库存中不存在名称为【{name}】的物品!"); + return NetworkUtility.JsonSerialize($"库存中不存在名称为【{name}】的物品!如果是魔法卡,请用【使用魔法卡】指令。"); } if (items.Count() >= useCount) @@ -1547,6 +1547,109 @@ namespace Oshima.Core.Controllers } } + [HttpPost("useitem3")] + public string UseItem3([FromQuery] long? qq = null, [FromQuery] int? id = null, [FromQuery] int? id2 = null, [FromQuery] bool? c = null) + { + try + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + int itemIndex = id ?? 0; + int itemToIndex = id2 ?? 0; + bool isCharacter = c ?? false; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + Item? item = null; + if (itemIndex > 0 && itemIndex <= user.Inventory.Items.Count) + { + item = user.Inventory.Items.ToList()[itemIndex - 1]; + if (item.ItemType == ItemType.MagicCard) + { + if (item.RemainUseTimes <= 0) + { + return NetworkUtility.JsonSerialize("此物品剩余使用次数为0,无法使用!"); + } + + string msg = ""; + Item? itemTo = null; + if (isCharacter) + { + if (itemToIndex > 0 && itemToIndex <= user.Inventory.Characters.Count) + { + Character character = user.Inventory.Characters.ToList()[itemToIndex - 1]; + if (character.EquipSlot.MagicCardPack != null) + { + itemTo = user.Inventory.Items.FirstOrDefault(i => i.Guid == character.EquipSlot.MagicCardPack.Guid); + if (itemTo != null) + { + msg = FunGameService.UseMagicCard(user, item, itemTo); + } + else + { + return NetworkUtility.JsonSerialize($"库存中没有找到此角色对应的魔法卡包!"); + } + } + else + { + return NetworkUtility.JsonSerialize($"这个角色没有装备魔法卡包,无法对其使用魔法卡!"); + } + } + else + { + return NetworkUtility.JsonSerialize($"没有找到与这个序号相对应的角色!"); + } + } + else + { + if (itemToIndex > 0 && itemToIndex <= user.Inventory.Items.Count) + { + itemTo = user.Inventory.Items.ToList()[itemToIndex - 1]; + if (itemTo != null && itemTo.ItemType == ItemType.MagicCardPack) + { + msg = FunGameService.UseMagicCard(user, item, itemTo); + } + else + { + return NetworkUtility.JsonSerialize($"与目标序号相对应的物品不是魔法卡包!"); + } + } + else + { + return NetworkUtility.JsonSerialize($"没有找到与目标序号相对应的物品!"); + } + } + + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); + return NetworkUtility.JsonSerialize(msg); + } + else + { + return NetworkUtility.JsonSerialize($"这个物品不是魔法卡!"); + } + } + else + { + return NetworkUtility.JsonSerialize($"没有找到与目标序号相对应的物品!"); + } + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + catch (Exception e) + { + return NetworkUtility.JsonSerialize(e.ToString()); + } + } + [HttpPost("characterlevelup")] public string CharacterLevelUp([FromQuery] long? qq = null, [FromQuery] int? c = null, [FromQuery] int? count = null) { @@ -1784,6 +1887,45 @@ namespace Oshima.Core.Controllers user2.Inventory.Materials += itemCount; msg = $"已为 [ {user2} ] 生成 {itemCount} {General.GameplayEquilibriumConstant.InGameMaterial}"; } + else if (itemName.Contains("魔法卡包")) + { + foreach (string type in ItemSet.QualityTypeNameArray) + { + if (itemName == $"{type}魔法卡包") + { + int success = 0; + for (int i = 0; i < itemCount; i++) + { + Item? item = FunGameService.GenerateMagicCardPack(3, ItemSet.GetQualityTypeFromName(type)); + if (item != null) + { + item.User = user2; + user2.Inventory.Items.Add(item); + success++; + } + } + msg = $"已为 [ {user2} ] 成功生成 {success} 个{type}魔法卡包"; + break; + } + } + } + else if (itemName.Contains("魔法卡")) + { + foreach (string type in ItemSet.QualityTypeNameArray) + { + if (itemName == $"{type}魔法卡") + { + for (int i = 0; i < itemCount; i++) + { + Item item = FunGameService.GenerateMagicCard(ItemSet.GetQualityTypeFromName(type)); + item.User = user2; + user2.Inventory.Items.Add(item); + } + msg = $"已为 [ {user2} ] 生成 {itemCount} 张{type}魔法卡"; + break; + } + } + } else if (FunGameService.AllItems.FirstOrDefault(i => i.Name == itemName) is Item item) { for (int i = 0; i < itemCount; i++) @@ -1819,6 +1961,284 @@ namespace Oshima.Core.Controllers } } + [HttpPost("decomposeitem")] + public string DecomposeItem([FromQuery] long? qq = null, [FromBody] int[]? items = null) + { + try + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + int[] ids = items ?? []; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + List msgs = []; + int successCount = 0; + double totalGained = 0; + Dictionary dict = user.Inventory.Items.Select((item, index) => new { item, index }) + .Where(x => ids.Contains(x.index) && x.item.Character is null) + .ToDictionary(x => x.index, x => x.item); + + foreach (int id in dict.Keys) + { + Item item = dict[id]; + + if (user.Inventory.Items.Remove(item)) + { + double gained = item.QualityType switch + { + QualityType.Gold => 80, + QualityType.Red => 55, + QualityType.Orange => 35, + QualityType.Purple => 20, + QualityType.Blue => 10, + QualityType.Green => 4, + _ => 1 + }; + totalGained += gained; + successCount++; + } + } + + if (successCount > 0) + { + user.Inventory.Materials += totalGained; + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); + } + return NetworkUtility.JsonSerialize($"分解完毕!分解 {ids.Length} 件,成功 {successCount} 件,得到了 {totalGained} {General.GameplayEquilibriumConstant.InGameMaterial}!"); + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + catch (Exception e) + { + return NetworkUtility.JsonSerialize(e.ToString()); + } + } + + [HttpPost("decomposeitem2")] + public string DecomposeItem2([FromQuery] long? qq = null, [FromQuery] string? name = null, [FromQuery] int? count = null) + { + try + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + string itemName = name ?? ""; + int useCount = count ?? 0; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + IEnumerable items = user.Inventory.Items.Where(i => i.Name == name && i.Character is null); + if (!items.Any()) + { + return NetworkUtility.JsonSerialize($"库存中不存在名称为【{name}】的物品!"); + } + + if (items.Count() >= useCount) + { + items = items.TakeLast(useCount); + List msgs = []; + int successCount = 0; + double totalGained = 0; + + foreach (Item item in items) + { + if (user.Inventory.Items.Remove(item)) + { + double gained = item.QualityType switch + { + QualityType.Gold => 80, + QualityType.Red => 55, + QualityType.Orange => 35, + QualityType.Purple => 20, + QualityType.Blue => 10, + QualityType.Green => 4, + _ => 1 + }; + totalGained += gained; + successCount++; + } + } + if (successCount > 0) + { + user.Inventory.Materials += totalGained; + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); + } + return NetworkUtility.JsonSerialize($"分解完毕!分解 {useCount} 件物品,成功 {successCount} 件,得到了 {totalGained} {General.GameplayEquilibriumConstant.InGameMaterial}!"); + } + else + { + return NetworkUtility.JsonSerialize("此物品的可分解数量小于你想要分解的数量!"); + } + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + catch (Exception e) + { + return NetworkUtility.JsonSerialize(e.ToString()); + } + } + + [HttpPost("decomposeitem3")] + public string DecomposeItem3([FromQuery] long? qq = null, [FromQuery] int? q = null) + { + try + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + int qType = q ?? 0; + + if (qType < 0 || qType > (int)QualityType.Gold) + { + return NetworkUtility.JsonSerialize($"品质序号输入错误!"); + } + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + string qualityName = ItemSet.GetQualityTypeName((QualityType)qType); + IEnumerable items = user.Inventory.Items.Where(i => (int)i.QualityType == qType && i.Character is null); + if (!items.Any()) + { + return NetworkUtility.JsonSerialize($"库存中{qualityName}物品数量为零!"); + } + + List msgs = []; + int successCount = 0; + double gained = items.First().QualityType switch + { + QualityType.Gold => 80, + QualityType.Red => 55, + QualityType.Orange => 35, + QualityType.Purple => 20, + QualityType.Blue => 10, + QualityType.Green => 4, + _ => 1 + }; + + foreach (Item item in items) + { + if (user.Inventory.Items.Remove(item)) + { + successCount++; + } + } + + double totalGained = 0; + if (successCount > 0) + { + totalGained = successCount * gained; + user.Inventory.Materials += totalGained; + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); + } + return NetworkUtility.JsonSerialize($"分解完毕!成功分解 {successCount} 件{qualityName}物品,得到了 {totalGained} {General.GameplayEquilibriumConstant.InGameMaterial}!"); + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + catch (Exception e) + { + return NetworkUtility.JsonSerialize(e.ToString()); + } + } + + [HttpPost("conflatemagiccardpack")] + public string ConflateMagicCardPack([FromQuery] long? qq = null, [FromBody] int[]? items = null) + { + try + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + List itemsIndex = items?.ToList() ?? []; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + Item? item = null; + List mfks = []; + foreach (int itemIndex in itemsIndex) + { + if (itemIndex > 0 && itemIndex <= user.Inventory.Items.Count) + { + item = user.Inventory.Items.ToList()[itemIndex - 1]; + if (item.ItemType == ItemType.MagicCard && item.RemainUseTimes > 0) + { + mfks.Add(item); + } + else + { + return NetworkUtility.JsonSerialize($"此物品不是魔法卡或者使用次数为0:{itemIndex}. {item.Name}"); + } + } + else + { + return NetworkUtility.JsonSerialize($"没有找到与这个序号相对应的物品:{itemIndex}"); + } + } + if (mfks.Count >= 3) + { + item = FunGameService.ConflateMagicCardPack([mfks[0], mfks[1], mfks[2]]); + if (item != null) + { + item.User = user; + FunGameService.SetSellAndTradeTime(item); + user.Inventory.Items.Add(item); + user.Inventory.Items.Remove(mfks[0]); + user.Inventory.Items.Remove(mfks[1]); + user.Inventory.Items.Remove(mfks[2]); + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); + return NetworkUtility.JsonSerialize($"合成魔法卡包成功!获得魔法卡包:\r\n{item.ToStringInventory(true)}"); + } + else + { + return NetworkUtility.JsonSerialize($"合成魔法卡包失败!"); + } + } + else + { + return NetworkUtility.JsonSerialize($"选用的魔法卡不足 3 张,请重新选择!"); + } + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + catch (Exception e) + { + return NetworkUtility.JsonSerialize(e.ToString()); + } + } + [HttpGet("reload")] public string Relaod([FromQuery] long? master = null) { diff --git a/OshimaCore/Utils/FunGameService.cs b/OshimaCore/Utils/FunGameService.cs index f853127..579618e 100644 --- a/OshimaCore/Utils/FunGameService.cs +++ b/OshimaCore/Utils/FunGameService.cs @@ -506,58 +506,20 @@ namespace Oshima.Core.Utils user.Inventory.Characters.Clear(); user.Inventory.Items.Clear(); - foreach (Character inventoryCharacter in characters) - { - Character realCharacter = CharacterBuilder.Build(inventoryCharacter, false, AllItems, AllSkills); - realCharacter.User = user; - user.Inventory.Characters.Add(realCharacter); - } - foreach (Item inventoryItem in items) { Item realItem = inventoryItem.Copy(true, true, true, AllItems, AllSkills); - if (realItem.IsEquipment) - { - IEnumerable has = user.Inventory.Characters.Where(character => - { - if (realItem.ItemType == ItemType.MagicCardPack && character.EquipSlot.MagicCardPack != null && realItem.Guid == character.EquipSlot.MagicCardPack.Guid) - { - return true; - } - if (realItem.ItemType == ItemType.Weapon && character.EquipSlot.Weapon != null && realItem.Guid == character.EquipSlot.Weapon.Guid) - { - return true; - } - if (realItem.ItemType == ItemType.Armor && character.EquipSlot.Armor != null && realItem.Guid == character.EquipSlot.Armor.Guid) - { - return true; - } - if (realItem.ItemType == ItemType.Shoes && character.EquipSlot.Shoes != null && realItem.Guid == character.EquipSlot.Shoes.Guid) - { - return true; - } - if (realItem.ItemType == ItemType.Accessory) - { - if (character.EquipSlot.Accessory1 != null && realItem.Guid == character.EquipSlot.Accessory1.Guid) - { - return true; - } - else if (character.EquipSlot.Accessory2 != null && realItem.Guid == character.EquipSlot.Accessory2.Guid) - { - return true; - } - } - return false; - }); - if (has.Any() && has.First() is Character character) - { - realItem.Character = character; - } - } realItem.User = user; user.Inventory.Items.Add(realItem); } + foreach (Character inventoryCharacter in characters) + { + Character realCharacter = CharacterBuilder.Build(inventoryCharacter, false, true, user.Inventory, AllItems, AllSkills); + realCharacter.User = user; + user.Inventory.Characters.Add(realCharacter); + } + return user; } @@ -573,18 +535,19 @@ namespace Oshima.Core.Utils { msg = $"娑堣 {reduce} {General.GameplayEquilibriumConstant.InGameCurrency}锛屾伃鍠滀綘鎶藉埌浜嗭細"; } - int r = Random.Shared.Next(7); + int r = Random.Shared.Next(8); 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 + <= 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: @@ -939,5 +902,55 @@ namespace Oshima.Core.Utils } return ""; } + + public static string UseMagicCard(User user, Item magicCard, Item magicCardPack) + { + if (magicCard.QualityType != magicCardPack.QualityType) + { + return $"鍙兘瀵圭浉鍚屽搧璐ㄧ殑榄旀硶鍗″寘浣跨敤榄旀硶鍗★紒"; + } + if (magicCard.Skills.Active != null) + { + string msg = ""; + Skill magic = magicCard.Skills.Active; + if (magicCardPack.Skills.Magics.FirstOrDefault(m => m.GetIdName() == magic.GetIdName()) is Skill has && has.Level < 8) + { + int original = has.Level; + // 娣诲姞鎶鑳界瓑绾 + has.Level += magic.Level; + // 琛ュ伩鏉愭枡锛1绾10鏉愭枡 + int diff = magic.Level - (has.Level - original); + if (diff != 0) + { + user.Inventory.Materials += diff * 10; + msg = $"鐢变簬榄旀硶鍗$殑鎶鑳界瓑绾ф暟灏氭湭鐢ㄥ畬锛屾妧鑳戒究宸茬粡鍗囪嚦婊$骇锛岀壒姝よˉ鍋 {diff * 10} {General.GameplayEquilibriumConstant.InGameMaterial}锛乗r\n"; + } + } + else + { + if (magicCardPack.Skills.Magics.Count < 3) + { + // 娣诲姞鎶鑳 + magicCardPack.Skills.Magics.Add(magic); + magic.Guid = magicCard.Guid; + msg = $"姝ら瓟娉曞崱鐨勬妧鑳藉凡缁忔坊鍔犲埌鏈弧涓変釜榄旀硶鐨勫崱鍖呬笂銆俓r\n"; + } + return $"榄旀硶銆恵magic.Name}銆戝湪姝ら瓟娉曞崱鍖呬腑涓嶅瓨鍦ㄦ垨鏄凡缁忓崌鑷虫弧绾э紒"; + } + string containMagics = magicCardPack.Description.Split("澧炲姞瑙掕壊灞炴")[0]; + magicCardPack.Description = $"鍖呭惈榄旀硶锛歿string.Join("锛", magicCardPack.Skills.Magics.Select(m => m.Name + (m.Level > 1 ? $" +{m.Level - 1}" : "")))}\r\n" + magicCardPack.Description.Replace(containMagics, ""); + magicCard.RemainUseTimes--; + if (magicCard.RemainUseTimes < 0) magicCard.RemainUseTimes = 0; + if (magicCard.RemainUseTimes == 0) + { + user.Inventory.Items.Remove(magicCard); + } + return $"鐩爣榄旀硶鍗″寘鐨勫姏閲忓凡缁忚姝ら瓟娉曞崱鏄捐憲鍦版彁鍗囦簡锛侊紒锛乗r\n{msg}{magicCardPack.ToStringInventory(true)}"; + } + else + { + return "姝ら瓟娉曞崱涓嶅瓨鍦ㄤ换浣曢瓟娉曪紒"; + } + } } }