添加自建角色

This commit is contained in:
milimoe 2024-12-08 13:49:33 +08:00
parent d928656036
commit 0cc5647fa4
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
2 changed files with 84 additions and 1 deletions

View File

@ -7,6 +7,7 @@ using Milimoe.FunGame.Core.Library.Constant;
using Oshima.Core.Configs; using Oshima.Core.Configs;
using Oshima.Core.Models; using Oshima.Core.Models;
using Oshima.Core.Utils; using Oshima.Core.Utils;
using Oshima.FunGame.OshimaModules.Characters;
namespace Oshima.Core.Controllers namespace Oshima.Core.Controllers
{ {
@ -302,7 +303,7 @@ namespace Oshima.Core.Controllers
public string CreateSaved([FromQuery] long? qq = null, [FromQuery] string? name = null) public string CreateSaved([FromQuery] long? qq = null, [FromQuery] string? name = null)
{ {
long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11));
string username = name ?? "Unknown"; string username = name ?? FunGameService.GenerateRandomChineseUserName();
PluginConfig pc = new("saved", userid.ToString()); PluginConfig pc = new("saved", userid.ToString());
pc.LoadConfig(); pc.LoadConfig();
@ -311,6 +312,7 @@ namespace Oshima.Core.Controllers
{ {
User user = Factory.GetUser(userid, username, DateTime.Now, DateTime.Now, userid + "@qq.com", username); User user = Factory.GetUser(userid, username, DateTime.Now, DateTime.Now, userid + "@qq.com", username);
user.Inventory.Credits = 5000000; user.Inventory.Credits = 5000000;
user.Inventory.Characters.Add(new CustomCharacter(userid, username));
pc.Add("user", user); pc.Add("user", user);
pc.SaveConfig(); pc.SaveConfig();
return NetworkUtility.JsonSerialize($"创建存档成功!你的用户名是【{username}】。"); return NetworkUtility.JsonSerialize($"创建存档成功!你的用户名是【{username}】。");
@ -674,6 +676,36 @@ namespace Oshima.Core.Controllers
return list; return list;
} }
[HttpPost("newcustomcharacter")]
public string NewCustomCharacter([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);
if (user.Inventory.Characters.Any(c => c.Id == user.Id))
{
return NetworkUtility.JsonSerialize($"你已经拥有一个自建角色【{user.Username}】,无法再创建!");
}
else
{
user.Inventory.Characters.Add(new CustomCharacter(userid, user.Username));
user.LastTime = DateTime.Now;
pc.Add("user", user);
pc.SaveConfig();
return NetworkUtility.JsonSerialize($"恭喜你成功创建了一个自建角色【{user.Username}】,请查看你的角色库存!");
}
}
else
{
return NetworkUtility.JsonSerialize(noSaved);
}
}
[HttpPost("drawcard")] [HttpPost("drawcard")]
public string DrawCard([FromQuery] long? qq = null) public string DrawCard([FromQuery] long? qq = null)
{ {

View File

@ -0,0 +1,51 @@
using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Entity;
using Milimoe.FunGame.Core.Library.Constant;
namespace Oshima.FunGame.OshimaModules.Characters
{
public class CustomCharacter : Character
{
public CustomCharacter(long user_id, string name, string firstname = "", string nickname = "") : base()
{
Id = user_id;
Name = name;
FirstName = firstname;
NickName = nickname;
PrimaryAttribute = (PrimaryAttribute)Random.Shared.Next(4);
InitialATK = Random.Shared.Next(15, 26);
InitialHP = Random.Shared.Next(40, 86);
InitialMP = Random.Shared.Next(20, 56);
int value = 31;
int valueGrowth = 31;
for (int i = 0; i < 3; i++)
{
if (value == 0) break;
int attribute = i < 2 ? Random.Shared.Next(value) : (value - 1);
int growth = i < 2 ? Random.Shared.Next(0, valueGrowth) : (valueGrowth - 1);
switch (i)
{
case 1:
InitialAGI = attribute;
AGIGrowth = Calculation.Round(Convert.ToDouble(growth) / 10, 2);
break;
case 2:
InitialINT = attribute;
INTGrowth = Calculation.Round(Convert.ToDouble(growth) / 10, 2);
break;
case 0:
default:
InitialSTR = attribute;
STRGrowth = Calculation.Round(Convert.ToDouble(growth) / 10, 2);
break;
}
value -= attribute;
valueGrowth -= growth;
}
InitialSPD = Random.Shared.Next(220, 291);
InitialHR = Random.Shared.Next(1, 6);
InitialMR = Random.Shared.Next(1, 6);
}
}
}