using System.Text; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Constant; using Oshima.FunGame.OshimaModules; using Oshima.FunGame.OshimaModules.Characters; using Oshima.FunGame.OshimaModules.Effects.OpenEffects; using Oshima.FunGame.OshimaModules.Items; using Oshima.FunGame.OshimaModules.Skills; namespace Oshima.Core.Utils { public class FunGameService { public static List Characters { get; } = []; public static List Skills { get; } = []; public static List Magics { get; } = []; public static List Equipment { get; } = []; public static List Items { get; } = []; public static void InitFunGame() { Characters.Add(new OshimaShiya()); Characters.Add(new XinYin()); Characters.Add(new Yang()); Characters.Add(new NanGanYu()); Characters.Add(new NiuNan()); Characters.Add(new DokyoMayor()); Characters.Add(new MagicalGirl()); Characters.Add(new QingXiang()); Characters.Add(new QWQAQW()); Characters.Add(new ColdBlue()); Characters.Add(new dddovo()); Characters.Add(new Quduoduo()); Dictionary exItems = Factory.GetGameModuleInstances(OshimaGameModuleConstant.General, OshimaGameModuleConstant.Item); Equipment.AddRange(exItems.Values.Where(i => (int)i.ItemType >= 0 && (int)i.ItemType < 5)); Equipment.AddRange([new 攻击之爪10(), new 攻击之爪30(), new 攻击之爪50()]); Items.AddRange(exItems.Values.Where(i => (int)i.ItemType > 4)); Skills.AddRange([new 疾风步()]); Magics.AddRange([new 冰霜攻击(), new 火之矢(), new 水之矢(), new 风之轮(), new 石之锤(), new 心灵之霞(), new 次元上升(), new 暗物质(), new 回复术(), new 治愈术()]); } public static List GenerateMagicCards(int count, QualityType? qualityType = null) { List items = []; for (int i = 0; i < count; i++) { items.Add(GenerateMagicCard(qualityType)); } return items; } public static Item GenerateMagicCard(QualityType? qualityType = null) { Item item = Factory.GetItem(); item.Id = Convert.ToInt64("16" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)); item.Name = GenerateRandomChineseName(); item.ItemType = ItemType.MagicCard; int total; if (qualityType != null) { total = qualityType switch { QualityType.Green => Random.Shared.Next(7, 13), QualityType.Blue => Random.Shared.Next(13, 19), QualityType.Purple => Random.Shared.Next(19, 25), QualityType.Orange => Random.Shared.Next(25, 31), _ => Random.Shared.Next(1, 7) }; item.QualityType = (QualityType)qualityType; } else { total = Random.Shared.Next(1, 31); if (total > 6 && total <= 12) { item.QualityType = QualityType.Green; } else if (total > 12 && total <= 18) { item.QualityType = QualityType.Blue; } else if (total > 18 && total <= 24) { item.QualityType = QualityType.Purple; } else if (total > 24 && total <= 30) { item.QualityType = QualityType.Orange; } } GenerateAndAddSkillToMagicCard(item, total); return item; } public static void GenerateAndAddSkillToMagicCard(Item item, int total) { Skill magic = Magics[Random.Shared.Next(Magics.Count)].Copy(); magic.Guid = item.Guid; magic.Level = (int)item.QualityType switch { 2 => 2, 4 => 3, 6 => 4, _ => 1 }; item.Skills.Active = magic; // 初始化属性值 int str = 0, agi = 0, intelligence = 0; // 随机决定将多少个属性赋给其中一个属性,确保至少一个不为零 int nonZeroAttributes = Random.Shared.Next(1, Math.Min(4, total + 1)); // 随机决定非零属性的数量,确保在 total = 1 时最多只有1个非零属性 // 根据非零属性数量分配属性点 if (nonZeroAttributes == 1) { // 只有一个属性不为零 int attribute = Random.Shared.Next(0, 3); if (attribute == 0) str = total; else if (attribute == 1) agi = total; else intelligence = total; } else if (nonZeroAttributes == 2 && total >= 2) { // 两个属性不为零 int first = Random.Shared.Next(1, total); // 第一个属性的值 int second = total - first; // 第二个属性的值 int attribute = Random.Shared.Next(0, 3); if (attribute == 0) { str = first; } else if (attribute == 1) { agi = first; } else { intelligence = first; } attribute = Random.Shared.Next(0, 3); while ((attribute == 0 && str > 0) || (attribute == 1 && agi > 0) || (attribute == 2 && intelligence > 0)) { attribute = Random.Shared.Next(0, 3); } if (attribute == 0) { str = second; } else if (attribute == 1) { agi = second; } else { intelligence = second; } } else if (total >= 3) { // 三个属性都不为零 str = Random.Shared.Next(1, total - 1); // 第一个属性的值 agi = Random.Shared.Next(1, total - str); // 第二个属性的值 intelligence = total - str - agi; // 剩下的值给第三个属性 } Skill skill = Factory.OpenFactory.GetInstance(item.Id, item.Name, []); GenerateAndAddEffectsToMagicCard(skill, str, agi, intelligence); if (magic.Level > 1) item.Name += $" +{magic.Level - 1}"; skill.Level = 1; List strings = []; if (str > 0) strings.Add($"{str:0.##} 点力量"); if (agi > 0) strings.Add($"{agi:0.##} 点敏捷"); if (intelligence > 0) strings.Add($"{intelligence:0.##} 点智力"); item.Description = $"包含魔法:{item.Skills.Active.Name}\r\n" + $"增加角色属性:{string.Join(",", strings)}"; item.Skills.Passives.Add(skill); } public static void GenerateAndAddEffectsToMagicCard(Skill skill, int str, int agi, int intelligence) { if (str > 0) { skill.Effects.Add(Factory.OpenFactory.GetInstance((long)EffectID.ExSTR, "", new() { { "skill", skill }, { "values", new Dictionary() { { "exstr", str } } } })); } if (agi > 0) { skill.Effects.Add(Factory.OpenFactory.GetInstance((long)EffectID.ExAGI, "", new() { { "skill", skill }, { "values", new Dictionary() { { "exagi", agi } } } })); } if (intelligence > 0) { skill.Effects.Add(Factory.OpenFactory.GetInstance((long)EffectID.ExINT, "", new() { { "skill", skill }, { "values", new Dictionary() { { "exint", intelligence } } } })); } } public static Item? ConflateMagicCardPack(IEnumerable magicCards) { if (magicCards.Any()) { List magics = [.. magicCards.Where(i => i.Skills.Active != null).Select(i => i.Skills.Active)]; List passives = [.. magicCards.SelectMany(i => i.Skills.Passives)]; Item item = Factory.GetItem(); item.Id = Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 8)); item.Name = GenerateRandomChineseName(); item.ItemType = ItemType.MagicCardPack; double str = 0, agi = 0, intelligence = 0; foreach (Skill skill in passives) { Skill newSkill = skill.Copy(); foreach (Effect effect in newSkill.Effects) { switch ((EffectID)effect.Id) { case EffectID.ExSTR: if (effect is ExSTR exstr) { str += exstr.Value; } break; case EffectID.ExAGI: if (effect is ExAGI exagi) { agi += exagi.Value; } break; case EffectID.ExINT: if (effect is ExINT exint) { intelligence += exint.Value; } break; } } newSkill.Level = skill.Level; item.Skills.Passives.Add(newSkill); } List strings = []; if (str > 0) strings.Add($"{str:0.##} 点力量"); if (agi > 0) strings.Add($"{agi:0.##} 点敏捷"); if (intelligence > 0) strings.Add($"{intelligence:0.##} 点智力"); foreach (Skill skill in magics) { IEnumerable has = item.Skills.Magics.Where(m => m.Id == skill.Id); if (has.Any() && has.First() is Skill s) { s.Level += skill.Level; if (s.Level > 1) s.Name = s.Name.Split(' ')[0] + $" +{s.Level - 1}"; } else { Skill magic = skill.Copy(); magic.Guid = item.Guid; magic.Level = skill.Level; item.Skills.Magics.Add(magic); } } item.Description = $"包含魔法:{string.Join(",", item.Skills.Magics.Select(m => m.Name + (m.Level > 1 ? $" +{m.Level - 1}" : "")))}\r\n" + $"增加角色属性:{string.Join(",", strings)}"; double total = str + agi + intelligence; if (total > 18 && total <= 36) { item.QualityType = QualityType.Green; } else if (total > 36 && total <= 54) { item.QualityType = QualityType.Blue; } else if (total > 54 && total <= 72) { item.QualityType = QualityType.Purple; } else if (total > 72 && total <= 90) { item.QualityType = QualityType.Orange; } return item; } return null; } public static Item? GenerateMagicCardPack(int magicCardCount, QualityType? qualityType = null) { List magicCards = GenerateMagicCards(magicCardCount, qualityType); Item? magicCardPack = ConflateMagicCardPack(magicCards); return magicCardPack; } public static void Reload() { Characters.Clear(); Equipment.Clear(); Skills.Clear(); Magics.Clear(); InitFunGame(); } public static string GenerateRandomChineseName() { // 定义一个包含常用汉字的字符串 string commonChineseCharacters = "云星宝灵梦龙花雨风叶山川月石羽水竹金" + "玉海火雷光天地凤虎虹珠华霞鹏雪银沙松桃兰青霜鸿康骏波泉河湖江泽洋林枫" + "梅桂樱桐晴韵凌若悠碧涛渊壁剑影霖玄承珍雅耀瑞鹤烟燕霏翼翔璃绮纱绫绣锦" + "瑜琼瑾璇璧琳琪瑶瑛芝杏茜荷莉莹菡莲诗瑰翠椒槐榆槿柱梧曜曙晶暖智煌熙霓" + "熠嘉琴曼菁蓉菲淑妙惠秋涵映巧慧茹荣菱曦容芬玲澜清湘澄泓润珺晨翠涟洁悠" + "霏淑绮润东南西北云山川风月溪雪雨雷天云海霜柏芳春秋夏冬温景寒和竹阳溪" + "溪飞风峰阳"; // 随机生成名字长度,2到5个字 int nameLength = Random.Shared.Next(2, 6); StringBuilder name = new(); for (int i = 0; i < nameLength; i++) { // 从常用汉字集中随机选择一个汉字 char chineseCharacter = commonChineseCharacters[Random.Shared.Next(commonChineseCharacters.Length)]; name.Append(chineseCharacter); } return name.ToString(); } public static string GenerateRandomChineseUserName() { string[] commonSurnames = [ "顾", "沈", "陆", "楚", "白", "苏", "叶", "萧", "莫", "司马", "欧阳", "上官", "慕容", "尉迟", "司徒", "轩辕", "端木", "南宫", "长孙", "百里", "东方", "西门", "独孤", "公孙", "令狐", "宇文", "夏侯", "赫连", "皇甫", "北堂", "安陵", "东篱", "花容", "夜", "柳", "云", "凌", "寒", "龙", "凤", "蓝", "冷", "华", "蓝夜", "叶南", "墨", "君", "月", "子车", "澹台", "钟离", "公羊", "闾丘", "仲孙", "司空", "羊舌", "亓官", "公冶", "濮阳", "独月", "南风", "凤栖", "南门", "姬", "闻人", "花怜", "若", "紫", "卿", "微", "清", "易", "月华", "霜", "兰", "岑", "语", "雪", "夜阑", "梦", "洛", "江", "黎", "夜北", "唐", "水", "韩", "庄", "夜雪", "夜凌", "君临", "青冥", "漠然", "林", "青", "岑", "容", "墨", "柏", "安", "晏", "尉", "南", "轩", "竹", "晨", "桓", "晖", "瑾", "溪", "汐", "沐", "玉", "汀", "归", "羽", "颜", "辰", "琦", "芷", "尹", "施", "原", "孟", "尧", "荀", "单", "简", "植", "傅", "司", "钟", "方", "谢" ]; // 定义一个包含常用汉字的字符串 string commonChineseCharacters = "云星宝灵梦龙花雨风叶山川月石羽水竹金" + "玉海火雷光天地凤虎虹珠华霞鹏雪银沙松桃兰青霜鸿康骏波泉河湖江泽洋林枫" + "梅桂樱桐晴韵凌若悠碧涛渊壁剑影霖玄承珍雅耀瑞鹤烟燕霏翼翔璃绮纱绫绣锦" + "瑜琼瑾璇璧琳琪瑶瑛芝杏茜荷莉莹菡莲诗瑰翠椒槐榆槿柱梧曜曙晶暖智煌熙霓" + "熠嘉琴曼菁蓉菲淑妙惠秋涵映巧慧茹荣菱曦容芬玲澜清湘澄泓润珺晨涟洁东南" + "西北溪飞峰阳龄一二三四五六七十"; StringBuilder name = new(); // 随机姓 string lastname = commonSurnames[Random.Shared.Next(commonSurnames.Length)]; name.Append(lastname); // 随机生成名字长度,2到5个字 int nameLength = Random.Shared.Next(1, 2); for (int i = 0; i < nameLength; i++) { // 从常用汉字集中随机选择一个汉字 char chineseCharacter = commonChineseCharacters[Random.Shared.Next(commonChineseCharacters.Length)]; name.Append(chineseCharacter); } return name.ToString(); } public static User GetUser(PluginConfig pc) { User user = pc.Get("user") ?? Factory.GetUser(); List characters = new(user.Inventory.Characters); List items = new(user.Inventory.Items); user.Inventory.Characters.Clear(); user.Inventory.Items.Clear(); foreach (Character inventoryCharacter in characters) { Character realCharacter = CharacterBuilder.Build(inventoryCharacter, false); realCharacter.User = user; user.Inventory.Characters.Add(realCharacter); } foreach (Item inventoryItem in items) { Item realItem = inventoryItem.Copy(true, true); 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; } } user.Inventory.Items.Add(realItem); } return user; } } }