mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 20:19:34 +08:00
113 lines
4.5 KiB
C#
113 lines
4.5 KiB
C#
using System.Text;
|
||
using Milimoe.FunGame.Core.Interface.Entity;
|
||
using Milimoe.FunGame.Core.Library.Constant;
|
||
|
||
namespace Milimoe.FunGame.Core.Entity
|
||
{
|
||
public class User : BaseEntity
|
||
{
|
||
public static readonly User Empty = new();
|
||
public string Username { get; set; } = "";
|
||
public DateTime RegTime { get; set; }
|
||
public DateTime LastTime { get; set; }
|
||
public OnlineState OnlineState { get; set; } = OnlineState.Offline;
|
||
public string Email { get; set; } = "";
|
||
public string NickName { get; set; } = "";
|
||
public bool IsAdmin { get; set; } = false;
|
||
public bool IsOperator { get; set; } = false;
|
||
public bool IsEnable { get; set; } = true;
|
||
public double GameTime { get; set; } = 0;
|
||
public string AutoKey { get; set; } = "";
|
||
public UserProfile Profile { get; }
|
||
public UserStatistics Statistics { get; }
|
||
public Inventory Inventory { get; }
|
||
|
||
internal User()
|
||
{
|
||
Profile = new();
|
||
Statistics = new(this);
|
||
Inventory = new(this);
|
||
}
|
||
|
||
internal User(long Id = 0, string Username = "", DateTime? RegTime = null, DateTime? LastTime = null, string Email = "", string NickName = "", bool IsAdmin = false, bool IsOperator = false, bool IsEnable = true, double GameTime = 0, string AutoKey = "")
|
||
{
|
||
this.Id = Id;
|
||
this.Username = Username;
|
||
this.RegTime = RegTime ?? General.DefaultTime;
|
||
this.LastTime = LastTime ?? General.DefaultTime;
|
||
this.Email = Email;
|
||
this.NickName = NickName;
|
||
this.IsAdmin = IsAdmin;
|
||
this.IsOperator = IsOperator;
|
||
this.IsEnable = IsEnable;
|
||
this.GameTime = GameTime;
|
||
this.AutoKey = AutoKey;
|
||
Profile = new();
|
||
Statistics = new(this);
|
||
Inventory = new(this);
|
||
}
|
||
|
||
internal User(UserType usertype)
|
||
{
|
||
switch (usertype)
|
||
{
|
||
case UserType.General:
|
||
case UserType.Empty:
|
||
break;
|
||
case UserType.Guest:
|
||
Id = UserSet.GuestUserId;
|
||
Username = UserSet.GuestUserName;
|
||
break;
|
||
case UserType.LocalUser:
|
||
Id = UserSet.LocalUserId;
|
||
Username = UserSet.LocalUserName;
|
||
break;
|
||
}
|
||
Profile = new();
|
||
Statistics = new(this);
|
||
Inventory = new(this);
|
||
}
|
||
|
||
public override bool Equals(IBaseEntity? other)
|
||
{
|
||
return other is User u && u.Id == Id;
|
||
}
|
||
|
||
public override string ToString()
|
||
{
|
||
string str = Username;
|
||
if (NickName != "")
|
||
{
|
||
str += " ( " + NickName + " ) ";
|
||
}
|
||
return str;
|
||
}
|
||
|
||
public string GetUserInfo()
|
||
{
|
||
StringBuilder builder = new();
|
||
|
||
builder.AppendLine($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> {Username}<7D>Ĵ浵<C4B4><E6B5B5>Ϣ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
builder.AppendLine($"<22><><EFBFBD><EFBFBD> ID<49><44>{Id}");
|
||
builder.AppendLine($"{General.GameplayEquilibriumConstant.InGameCurrency}<7D><>{Inventory.Credits:0.00}");
|
||
builder.AppendLine($"{General.GameplayEquilibriumConstant.InGameMaterial}<7D><>{Inventory.Materials:0.00}");
|
||
builder.AppendLine($"<22><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{Inventory.Characters.Count}");
|
||
builder.AppendLine($"<22><>ս<EFBFBD><D5BD>ɫ<EFBFBD><C9AB>{Inventory.MainCharacter.ToStringWithLevelWithOutUser()}");
|
||
Character[] squad = [.. Inventory.Characters.Where(c => Inventory.Squad.Contains(c.Id))];
|
||
Dictionary<Character, int> characters = Inventory.Characters
|
||
.Select((character, index) => new { character, index })
|
||
.ToDictionary(x => x.character, x => x.index + 1);
|
||
builder.AppendLine($"С<>ӳ<EFBFBD>Ա<EFBFBD><D4B1>{(squad.Length > 0 ? string.Join(" / ", squad.Select(c => $"[#{characters[c]}]{c.NickName}({c.Level})")) : "<EFBFBD><EFBFBD>")}");
|
||
if (Inventory.Training.Count > 0)
|
||
{
|
||
builder.AppendLine($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{string.Join(" / ", Inventory.Characters.Where(c => Inventory.Training.ContainsKey(c.Id)).Select(c => c.ToStringWithLevelWithOutUser()))}");
|
||
}
|
||
builder.AppendLine($"<22><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{Inventory.Items.Count}");
|
||
builder.AppendLine($"ע<><D7A2>ʱ<EFBFBD>䣺{RegTime.ToString(General.GeneralDateTimeFormatChinese)}");
|
||
builder.AppendLine($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>{LastTime.ToString(General.GeneralDateTimeFormatChinese)}");
|
||
|
||
return builder.ToString();
|
||
}
|
||
}
|
||
}
|