using System; using UnityEngine; using FairyGUI; namespace GFGGame { public class RoleDataManager { public static long roleId; public static string roleName; public static int rechargeTotal; public static int rechargeTotalMon; public static int powerTime { get; private set; } private static int _powerBuyTimes = 0; public static int powerBuyTimes { get { return _powerBuyTimes; } set { _powerBuyTimes = value; } } private static int _power = GameConst.MAX_POWER_AUTO_REGAIN; public static int power { get { return _power; } set { int dValue = value - _power; _power = value; if (dValue != 0) { powerTime = ServerDataManager.currentTimeSecs; GameController.PrepareUpdateTreasure(); EventAgent.DispatchEvent(ConstMessage.ROLE_POWER_CHANGED, dValue); } } } private static int _goldBuyTimes = 0; public static int goldBuyTimes { get { return _goldBuyTimes; } set { _goldBuyTimes = value; } } private static int _gold = 0; public static int gold { get { return _gold; } set { int dValue = value - _gold; _gold = value; if (dValue != 0) { GameController.PrepareUpdateTreasure(); EventAgent.DispatchEvent(ConstMessage.ROLE_GOLD_CHANGED, dValue); } } } private static int _exp = 0; public static int exp { get { return _exp; } set { int oldValue = _exp; RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(lvl); if (roleLevelCfg.exp > 0) { _exp = value; while (exp >= roleLevelCfg.exp) { lvl++; FunctionOpenDataManager.Instance.CheckHasLvFunOpen(lvl);//等级变化要加测是否有功能开启 exp -= roleLevelCfg.exp; roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(lvl); } } else { _exp = 0; } int dValue = _exp - oldValue; if (dValue != 0) { GameController.PrepareUpdateTreasure(); EventAgent.DispatchEvent(ConstMessage.ROLE_EXP_CHANGED, dValue); } } } private static int _lvl = 1; public static int lvl { get { return _lvl; } set { int dValue = value - _lvl; _lvl = value; if (dValue != 0) { GameController.PrepareUpdateTreasure(); EventAgent.DispatchEvent(ConstMessage.ROLE_LEVEL_CHANGED, dValue); } } } private static int _diaP = 0; public static int diaP { get { return _diaP; } set { int dValue = value - _diaP; _diaP = value; if (dValue != 0) { GameController.PrepareUpdateTreasure(); EventAgent.DispatchEvent(ConstMessage.ROLE_DIAMOND_PURPLE_CHANGED, dValue); } } } private static int _diaR = 0; public static int diaR { get { return _diaR; } set { int dValue = value - _diaR; _diaR = value; if (dValue != 0) { GameController.PrepareUpdateTreasure(); EventAgent.DispatchEvent(ConstMessage.ROLE_DIAMOND_RED_CHANGED, dValue); } } } private static string _lastRandomName = null; public static string RandomRoleName() { string randomName = null; while (_lastRandomName == randomName || randomName == null) { int len = GameConst.ROLE_NAME_LIST.Length; System.Random random = new System.Random(); int i = random.Next(len); randomName = GameConst.ROLE_NAME_LIST[i]; } _lastRandomName = randomName; return randomName; } public static bool CheckPowerFull() { return RoleDataManager.power >= GameConst.MAX_POWER_AUTO_REGAIN; } public static void InitServerData(RoleInfo roleInfo) { if (roleInfo != null) { roleId = roleInfo.id; roleName = roleInfo.name; rechargeTotal = roleInfo.rechargeTotal; rechargeTotalMon = roleInfo.rechargeTotalMon; _power = roleInfo.power; _gold = roleInfo.gold; _exp = roleInfo.exp; _lvl = roleInfo.lvl; _diaP = roleInfo.diaP; _diaR = roleInfo.diaR; powerTime = roleInfo.powerTime; //处理体力 while (!CheckPowerFull()) { int passTime = ServerDataManager.currentTimeSecs - powerTime; if (passTime >= GameConst.INTERVAL_TIME_SECONDS_POWER) { _power++; powerTime += GameConst.INTERVAL_TIME_SECONDS_POWER; } else { break; } } } else { _power = GameConst.MAX_POWER_AUTO_REGAIN; _gold = 0; _exp = 0; _lvl = 1; _diaP = 0; _diaR = 0; powerTime = 0; } } } }