69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace XGame
|
|
{
|
|
public enum PlayerRoleType
|
|
{
|
|
Adventurer = 0,
|
|
Warrior = 1,
|
|
Mage = 2,
|
|
Archer = 3
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class PlayerProfileData
|
|
{
|
|
public string Nickname = "Player";
|
|
public string Uid = "0";
|
|
public int AvatarId;
|
|
public PlayerRoleType RoleType = PlayerRoleType.Adventurer;
|
|
public int Gold;
|
|
public int Diamond;
|
|
public int Lv = 1;
|
|
public int Exp;
|
|
public int Hp = 100;
|
|
public int HpMax = 100;
|
|
public int Mp = 50;
|
|
public int MpMax = 50;
|
|
public int Ad = 10;
|
|
public int Ap = 5;
|
|
public float AtkSpeed = 1f;
|
|
public float MoveSpeed = 4f;
|
|
|
|
public int RequiredExp => Mathf.Max(100, Lv * 100);
|
|
public float Experience01 => Mathf.Clamp01((float)Mathf.Max(0, Exp) / RequiredExp);
|
|
|
|
public static PlayerProfileData CreateDefault()
|
|
{
|
|
PlayerProfileData data = new PlayerProfileData();
|
|
data.Normalize();
|
|
return data;
|
|
}
|
|
|
|
public PlayerProfileData Clone()
|
|
{
|
|
return (PlayerProfileData)MemberwiseClone();
|
|
}
|
|
|
|
public void Normalize()
|
|
{
|
|
Nickname = string.IsNullOrWhiteSpace(Nickname) ? "Player" : Nickname.Trim();
|
|
Uid = string.IsNullOrWhiteSpace(Uid) ? "0" : Uid.Trim();
|
|
AvatarId = Mathf.Max(0, AvatarId);
|
|
Gold = Mathf.Max(0, Gold);
|
|
Diamond = Mathf.Max(0, Diamond);
|
|
Lv = Mathf.Max(1, Lv);
|
|
Exp = Mathf.Max(0, Exp);
|
|
HpMax = Mathf.Max(1, HpMax);
|
|
MpMax = Mathf.Max(1, MpMax);
|
|
Hp = Mathf.Clamp(Hp, 0, HpMax);
|
|
Mp = Mathf.Clamp(Mp, 0, MpMax);
|
|
Ad = Mathf.Max(0, Ad);
|
|
Ap = Mathf.Max(0, Ap);
|
|
AtkSpeed = Mathf.Max(0.01f, AtkSpeed);
|
|
MoveSpeed = Mathf.Max(0.01f, MoveSpeed);
|
|
}
|
|
}
|
|
}
|