添加 Service,和局内模拟分开

This commit is contained in:
milimoe 2024-11-15 20:13:42 +08:00
parent b154062ef7
commit d3d4907955
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
9 changed files with 596 additions and 518 deletions

View File

@ -29,9 +29,9 @@ namespace Oshima.Core.Controllers
[HttpGet("stats")]
public string GetStats([FromQuery] int? id = null)
{
if (id != null && id > 0 && id <= FunGameSimulation.Characters.Count)
if (id != null && id > 0 && id <= FunGameService.Characters.Count)
{
Character character = FunGameSimulation.Characters[Convert.ToInt32(id) - 1];
Character character = FunGameService.Characters[Convert.ToInt32(id) - 1];
if (FunGameSimulation.CharacterStatistics.TryGetValue(character, out CharacterStatistics? stats) && stats != null)
{
StringBuilder builder = new();
@ -83,9 +83,9 @@ namespace Oshima.Core.Controllers
[HttpGet("teamstats")]
public string GetTeamStats([FromQuery] int? id = null)
{
if (id != null && id > 0 && id <= FunGameSimulation.Characters.Count)
if (id != null && id > 0 && id <= FunGameService.Characters.Count)
{
Character character = FunGameSimulation.Characters[Convert.ToInt32(id) - 1];
Character character = FunGameService.Characters[Convert.ToInt32(id) - 1];
if (FunGameSimulation.TeamCharacterStatistics.TryGetValue(character, out CharacterStatistics? stats) && stats != null)
{
StringBuilder builder = new();
@ -220,9 +220,9 @@ namespace Oshima.Core.Controllers
[HttpGet("cjs")]
public string GetCharacterIntroduce([FromQuery] int? id = null)
{
if (id != null && id > 0 && id <= FunGameSimulation.Characters.Count)
if (id != null && id > 0 && id <= FunGameService.Characters.Count)
{
Character c = FunGameSimulation.Characters[Convert.ToInt32(id) - 1].Copy();
Character c = FunGameService.Characters[Convert.ToInt32(id) - 1].Copy();
c.Level = General.GameplayEquilibriumConstant.MaxLevel;
c.NormalAttack.Level = General.GameplayEquilibriumConstant.MaxNormalAttackLevel;
@ -414,11 +414,11 @@ namespace Oshima.Core.Controllers
[HttpGet("cjn")]
public string GetSkillInfo([FromQuery] long? id = null)
{
IEnumerable<Skill> skills = FunGameSimulation.Skills.Union(FunGameSimulation.Magics);
if (id != null && FunGameSimulation.Characters.Count > 1)
IEnumerable<Skill> skills = FunGameService.Skills.Union(FunGameService.Magics);
if (id != null && FunGameService.Characters.Count > 1)
{
List<string> msg = [];
Character c = FunGameSimulation.Characters[1].Copy();
Character c = FunGameService.Characters[1].Copy();
Skill? s = skills.Where(s => s.Id == id).FirstOrDefault()?.Copy();
if (s != null)
{
@ -440,7 +440,7 @@ namespace Oshima.Core.Controllers
[HttpGet("cwp")]
public string GetItemInfo([FromQuery] long? id = null)
{
IEnumerable<Item> items = FunGameSimulation.Equipment;
IEnumerable<Item> items = FunGameService.Equipment;
if (id != null)
{
List<string> msg = [];
@ -459,14 +459,14 @@ namespace Oshima.Core.Controllers
[HttpGet("mfk")]
public string GenerateMagicCard()
{
Item i = FunGameSimulation.GenerateMagicCard();
Item i = FunGameService.GenerateMagicCard();
return NetworkUtility.JsonSerialize(i.ToString(false, true));
}
[HttpGet("mfkb")]
public string GenerateMagicCardPack()
{
Item? i = FunGameSimulation.GenerateMagicCardPack(3);
Item? i = FunGameService.GenerateMagicCardPack(3);
if (i != null)
{
return NetworkUtility.JsonSerialize(i.ToString(false, true));
@ -479,42 +479,41 @@ namespace Oshima.Core.Controllers
{
long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
string username = name ?? "Unknown";
string filepath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved/{userid}.json";
if (System.IO.File.Exists(filepath))
PluginConfig pc = new("saved", userid.ToString());
pc.LoadConfig();
if (pc.Count == 0)
{
User user = Factory.GetUser(userid, username, DateTime.Now, DateTime.Now, userid + "@qq.com", username);
user.Inventory.Credits = 100;
pc.Add("user", user);
pc.SaveConfig();
return NetworkUtility.JsonSerialize($"创建存档成功!你的用户名是【{username}】。");
}
else
{
return NetworkUtility.JsonSerialize("你已经创建过存档!");
}
User user = Factory.GetUser(userid, username, DateTime.Now, DateTime.Now, userid + "@qq.com", username);
user.Inventory.Credits = 100;
PluginConfig pc = new("saved", userid.ToString());
pc.LoadConfig();
pc.Add("user", user);
pc.SaveConfig();
return NetworkUtility.JsonSerialize($"创建存档成功!你的用户名是【{username}】。");
}
[HttpPost("ckkc")]
public string GetInventoryInfo([FromQuery] long? qq = null)
{
long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
string filepath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved/{userid}.json";
if (!System.IO.File.Exists(filepath))
{
return NetworkUtility.JsonSerialize("你还没有创建存档!请发送【创建存档】创建。");
}
PluginConfig pc = new("saved", userid.ToString());
pc.LoadConfig();
if (pc.Count > 0)
{
User user = FunGameSimulation.GetUser(pc);
User user = FunGameService.GetUser(pc);
return NetworkUtility.JsonSerialize(user.Inventory.ToString(false));
}
else
{
return NetworkUtility.JsonSerialize($"你好像一无所有……");
return NetworkUtility.JsonSerialize("你还没有创建存档!请发送【创建存档】创建。");
}
}
@ -522,82 +521,93 @@ namespace Oshima.Core.Controllers
public string DrawCards([FromQuery] long? qq = null)
{
long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
string filepath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved/{userid}.json";
if (!System.IO.File.Exists(filepath))
{
return NetworkUtility.JsonSerialize("你还没有创建存档!请发送【创建存档】创建。");
}
PluginConfig pc = new("saved", userid.ToString());
pc.LoadConfig();
User user = FunGameSimulation.GetUser(pc);
double dice = Random.Shared.NextDouble();
if (dice > 0.8)
if (pc.Count > 0)
{
string msg = "恭喜你抽到了:【";
int r = Random.Shared.Next(7);
switch (r)
User user = FunGameService.GetUser(pc);
double dice = Random.Shared.NextDouble();
if (dice > 0.8)
{
case 1:
Item[] = FunGameSimulation.Equipment.Where(i => i.Id.ToString().StartsWith("11")).ToArray();
Item a = [Random.Shared.Next(.Length)].Copy();
user.Inventory.Items.Add(a);
msg += a.Name;
break;
string msg = "恭喜你抽到了:";
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 + "】!";
break;
case 2:
Item[] = FunGameSimulation.Equipment.Where(i => i.Id.ToString().StartsWith("12")).ToArray();
Item b = [Random.Shared.Next(.Length)].Copy();
user.Inventory.Items.Add(b);
msg += b.Name;
break;
case 3:
Item[] = FunGameSimulation.Equipment.Where(i => i.Id.ToString().StartsWith("13")).ToArray();
Item c = [Random.Shared.Next(.Length)].Copy();
user.Inventory.Items.Add(c);
msg += c.Name;
break;
case 4:
Item[] = FunGameSimulation.Equipment.Where(i => i.Id.ToString().StartsWith("14")).ToArray();
Item d = [Random.Shared.Next(.Length)].Copy();
user.Inventory.Items.Add(d);
msg += d.Name;
break;
case 5:
Character character = FunGameSimulation.Characters[Random.Shared.Next(FunGameSimulation.Characters.Count)].Copy();
user.Inventory.Characters.Add(character);
msg += character.ToStringWithOutUser();
break;
case 6:
Item mfk = FunGameSimulation.GenerateMagicCard();
user.Inventory.Items.Add(mfk);
msg += mfk.Name;
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 + "】!";
break;
case 0:
default:
Item? mfkb = FunGameSimulation.GenerateMagicCardPack(3);
if (mfkb != null)
{
mfkb.IsTradable = false;
mfkb.NextTradableTime = DateTimeUtility.GetTradableTime();
user.Inventory.Items.Add(mfkb);
msg += mfkb.Name;
}
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 + "】!";
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 + "】!";
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() + "】但是你已经拥有此角色转换为【50】" + General.GameplayEquilibriumConstant.InGameMaterial + "";
}
else
{
user.Inventory.Characters.Add(character);
msg += "【" + character.ToStringWithOutUser() + "】!";
}
break;
case 6:
Item mfk = FunGameService.GenerateMagicCard();
user.Inventory.Items.Add(mfk);
msg += ItemSet.GetQualityTypeName(mfk.QualityType) + ItemSet.GetItemTypeName(mfk.ItemType) + "【" + mfk.Name + "】!";
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 + "】!";
}
break;
}
pc.Add("user", user);
pc.SaveConfig();
return NetworkUtility.JsonSerialize(msg);
}
else
{
return NetworkUtility.JsonSerialize("你什么也没抽中……");
}
pc.Add("user", user);
pc.SaveConfig();
return NetworkUtility.JsonSerialize(msg + "】!");
}
else
{
return NetworkUtility.JsonSerialize("你什么也没抽中……");
return NetworkUtility.JsonSerialize("你还没有创建存档!请发送【创建存档】创建。");
}
}
@ -606,7 +616,8 @@ namespace Oshima.Core.Controllers
{
if (master != null && master == GeneralSettings.Master)
{
FunGameSimulation.Reload();
FunGameService.Reload();
FunGameSimulation.InitFunGame();
return NetworkUtility.JsonSerialize("FunGame已重新加载。");
}
return NetworkUtility.JsonSerialize("提供的参数不正确。");

View File

@ -27,7 +27,7 @@
<ItemGroup>
<Reference Include="FunGame.Core">
<HintPath>..\..\FunGame.Core\bin\Release\net9.0\FunGame.Core.dll</HintPath>
<HintPath>..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll</HintPath>
</Reference>
</ItemGroup>

View File

@ -42,6 +42,7 @@ namespace Oshima.Core.WebAPI
Daily.InitDaily();
SayNo.InitSayNo();
Ignore.InitIgnore();
FunGameService.InitFunGame();
FunGameSimulation.InitFunGame();
Task taskTime = Task.Factory.StartNew(async () =>
{

View File

@ -0,0 +1,475 @@
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<Character> Characters { get; } = [];
public static List<Skill> Skills { get; } = [];
public static List<Skill> Magics { get; } = [];
public static List<Item> Equipment { get; } = [];
public static List<Item> 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<string, Item> exItems = Factory.GetGameModuleInstances<Item>(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<Item> GenerateMagicCards(int count, QualityType? qualityType = null)
{
List<Item> 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<Skill>(item.Id, item.Name, []);
GenerateAndAddEffectsToMagicCard(skill, str, agi, intelligence);
if (magic.Level > 1) item.Name += $" +{magic.Level - 1}";
skill.Level = 1;
List<string> 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<Effect>((long)EffectID.ExSTR, "", new()
{
{ "skill", skill },
{
"values", new Dictionary<string, object>()
{
{ "exstr", str }
}
}
}));
}
if (agi > 0)
{
skill.Effects.Add(Factory.OpenFactory.GetInstance<Effect>((long)EffectID.ExAGI, "", new()
{
{ "skill", skill },
{
"values", new Dictionary<string, object>()
{
{ "exagi", agi }
}
}
}));
}
if (intelligence > 0)
{
skill.Effects.Add(Factory.OpenFactory.GetInstance<Effect>((long)EffectID.ExINT, "", new()
{
{ "skill", skill },
{
"values", new Dictionary<string, object>()
{
{ "exint", intelligence }
}
}
}));
}
}
public static Item? ConflateMagicCardPack(IEnumerable<Item> magicCards)
{
if (magicCards.Any())
{
List<Skill> magics = [.. magicCards.Where(i => i.Skills.Active != null).Select(i => i.Skills.Active)];
List<Skill> 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<string> 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<Skill> 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<Item> 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>("user") ?? Factory.GetUser();
List<Character> characters = new(user.Inventory.Characters);
List<Item> 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<Character> 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;
}
}
}

View File

@ -13,11 +13,6 @@ namespace Oshima.Core.Utils
{
public class FunGameSimulation
{
public static List<Character> Characters { get; } = [];
public static List<Skill> Skills { get; } = [];
public static List<Skill> Magics { get; } = [];
public static List<Item> Equipment { get; } = [];
public static List<Item> Items { get; } = [];
public static Dictionary<Character, CharacterStatistics> CharacterStatistics { get; } = [];
public static Dictionary<Character, CharacterStatistics> TeamCharacterStatistics { get; } = [];
public static PluginConfig StatsConfig { get; } = new(nameof(FunGameSimulation), nameof(CharacterStatistics));
@ -30,20 +25,10 @@ namespace Oshima.Core.Utils
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());
CharacterStatistics.Clear();
TeamCharacterStatistics.Clear();
foreach (Character c in Characters)
foreach (Character c in FunGameService.Characters)
{
CharacterStatistics.Add(c, new());
}
@ -57,7 +42,7 @@ namespace Oshima.Core.Utils
}
}
foreach (Character c in Characters)
foreach (Character c in FunGameService.Characters)
{
TeamCharacterStatistics.Add(c, new());
}
@ -70,16 +55,6 @@ namespace Oshima.Core.Utils
TeamCharacterStatistics[character] = TeamStatsConfig.Get<CharacterStatistics>(character.ToStringWithOutUser()) ?? TeamCharacterStatistics[character];
}
}
Dictionary<string, Item> exItems = Factory.GetGameModuleInstances<Item>(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<string> StartGame(bool printout, bool isWeb = false, bool isTeam = false, bool deathMatchRoundDetail = false)
@ -105,7 +80,7 @@ namespace Oshima.Core.Utils
// M = 5, W = 0, P1 = 0, P3 = 2
// M = 5, W = 1, P1 = 0, P3 = 0
List<Character> list = new(Characters);
List<Character> list = new(FunGameService.Characters);
if (list.Count > 11)
{
@ -551,7 +526,7 @@ namespace Oshima.Core.Utils
roundMsg = Msg;
if (!deathMatchRoundDetail)
{
roundMsg = actionQueue.LastRound.ToString();
roundMsg = actionQueue.LastRound.ToString().Trim() + $"\r\n{(isTeam ? $"{string.Join(" / ", actionQueue.Teams.Values.Select(t => $"{t.Name}({t.Score})"))}{actionQueue.GetTeam(actionQueue.LastRound.Actor)}" : "")}\r\n";
}
Msg = "";
}
@ -792,10 +767,10 @@ namespace Oshima.Core.Utils
WriteLine($"社区送温暖了,现在随机发放空投!!");
foreach (Character character in queue.Queue)
{
Item[] = Equipment.Where(i => i.Id.ToString().StartsWith("11") && (int)i.QualityType == wQuality).ToArray();
Item[] = Equipment.Where(i => i.Id.ToString().StartsWith("12") && (int)i.QualityType == aQuality).ToArray();
Item[] = Equipment.Where(i => i.Id.ToString().StartsWith("13") && (int)i.QualityType == sQuality).ToArray();
Item[] = Equipment.Where(i => i.Id.ToString().StartsWith("14") && (int)i.QualityType == acQuality).ToArray();
Item[] = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("11") && (int)i.QualityType == wQuality).ToArray();
Item[] = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("12") && (int)i.QualityType == aQuality).ToArray();
Item[] = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("13") && (int)i.QualityType == sQuality).ToArray();
Item[] = FunGameService.Equipment.Where(i => i.Id.ToString().StartsWith("14") && (int)i.QualityType == acQuality).ToArray();
Item? a = null, b = null, c = null, d = null;
if (.Length > 0)
{
@ -818,7 +793,7 @@ namespace Oshima.Core.Utils
if (b != null) .Add(b);
if (c != null) .Add(c);
if (d != null) .Add(d);
Item? = GenerateMagicCardPack(3, (QualityType)mQuality);
Item? = FunGameService.GenerateMagicCardPack(3, (QualityType)mQuality);
if ( != null)
{
foreach (Skill magic in .Skills.Magics)
@ -838,302 +813,6 @@ namespace Oshima.Core.Utils
WriteLine("");
}
public static List<Item> GenerateMagicCards(int count, QualityType? qualityType = null)
{
List<Item> 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<Skill>(item.Id, item.Name, []);
GenerateAndAddEffectsToMagicCard(skill, str, agi, intelligence);
if (magic.Level > 1) item.Name += $" +{magic.Level - 1}";
skill.Level = 1;
List<string> 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<Effect>((long)EffectID.ExSTR, "", new()
{
{ "skill", skill },
{
"values", new Dictionary<string, object>()
{
{ "exstr", str }
}
}
}));
}
if (agi > 0)
{
skill.Effects.Add(Factory.OpenFactory.GetInstance<Effect>((long)EffectID.ExAGI, "", new()
{
{ "skill", skill },
{
"values", new Dictionary<string, object>()
{
{ "exagi", agi }
}
}
}));
}
if (intelligence > 0)
{
skill.Effects.Add(Factory.OpenFactory.GetInstance<Effect>((long)EffectID.ExINT, "", new()
{
{ "skill", skill },
{
"values", new Dictionary<string, object>()
{
{ "exint", intelligence }
}
}
}));
}
}
public static Item? ConflateMagicCardPack(IEnumerable<Item> magicCards)
{
if (magicCards.Any())
{
List<Skill> magics = [.. magicCards.Where(i => i.Skills.Active != null).Select(i => i.Skills.Active)];
List<Skill> 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<string> 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<Skill> 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<Item> magicCards = GenerateMagicCards(magicCardCount, qualityType);
Item? magicCardPack = ConflateMagicCardPack(magicCards);
return magicCardPack;
}
public static void Reload()
{
Characters.Clear();
CharacterStatistics.Clear();
TeamCharacterStatistics.Clear();
Equipment.Clear();
Skills.Clear();
Magics.Clear();
InitFunGame();
}
public static Dictionary<EffectID, Dictionary<string, object>> RoundRewards
{
get
@ -1344,93 +1023,5 @@ namespace Oshima.Core.Utils
// 确保评分在合理范围内
return Math.Max(0.01, rating);
}
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 User GetUser(PluginConfig pc)
{
User user = pc.Get<User>("user") ?? Factory.GetUser();
List<Character> characters = new(user.Inventory.Characters);
List<Item> 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<Character> 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;
}
}
}

View File

@ -24,7 +24,7 @@
<ItemGroup>
<Reference Include="FunGame.Core">
<HintPath>..\..\FunGame.Core\bin\Release\net9.0\FunGame.Core.dll</HintPath>
<HintPath>..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll</HintPath>
</Reference>
</ItemGroup>

View File

@ -27,7 +27,7 @@
<ItemGroup>
<Reference Include="FunGame.Core">
<HintPath>..\..\FunGame.Core\bin\Release\net9.0\FunGame.Core.dll</HintPath>
<HintPath>..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll</HintPath>
</Reference>
<Reference Include="FunGame.Desktop">
<HintPath>..\..\FunGame.Desktop\bin\Debug\net8.0-windows\FunGame.Desktop.dll</HintPath>

View File

@ -24,7 +24,7 @@
<ItemGroup>
<Reference Include="FunGame.Core">
<HintPath>..\..\FunGame.Core\bin\Release\net9.0\FunGame.Core.dll</HintPath>
<HintPath>..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll</HintPath>
</Reference>
</ItemGroup>

View File

@ -23,7 +23,7 @@
<ItemGroup>
<Reference Include="FunGame.Core">
<HintPath>..\..\FunGame.Core\bin\Release\net9.0\FunGame.Core.dll</HintPath>
<HintPath>..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll</HintPath>
</Reference>
</ItemGroup>