using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using UnityEngine; using NetData; /// /// 玩家数据结构 /// public class Player { #region 基础字段 /// /// 游戏ID /// public string uid { get; set; } /// /// 分区ID /// public int zoneid { get; set; } /// /// 分区名称 /// public string zonename { get; set; } /// /// http通讯中采用的token /// public string TK=""; //======================================== /// /// 类型数值 含义 ///-1 未实名 ///0 0 到 7 岁 ///8 8 到 15 岁 ///16 16 到 17 岁 ///18 成年玩家 /// public int ageRange = -1; #endregion //-----------------分割线---------------------------- #region 集合型字段 private Info_UserBase _baseInfo; private int _baseInfoHash = 0; /// /// 基础信息 /// public Info_UserBase baseInfo { get { if (_baseInfo == null || _baseInfoHash != _userGameVer) { _baseInfo = _userGame?["baseInfo"].ToObject() ?? null; _baseInfoHash = _userGameVer; } return _baseInfo; } set { _baseInfo = value; } } /// /// 玩家圈养的 英雄数据列表 /// public GameCollectHero collectHero; /// /// 物品数据 /// public GameCollectItem collectItem; /// /// 装备 /// public GameCollectEquips collectEquip; /// /// 言灵 /// public GameCollectYanling collectYanling; public GameCollectTaskCard collectTaskCard; /// /// 触发条件得到的限时随机礼包 /// public List triggerLimitTsGift = new List(); /// /// 玩家的配置的战队信息 /// public Info_HeroTeamConfig heroTeamConfig; private Info_NewMap _newMap; private int _newMap_ver; /// /// 地图解锁信息 /// public Info_NewMap newMap { get { if (null == _newMap || _newMap_ver != _userGameVer) { _newMap = _userGame.TryGetValue("newMap", out var jo)?jo.ToObject() : new Info_NewMap(); _newMap_ver = _userGameVer; } return _newMap; } set { _newMap = value; } } private Info_PrivateState _privateState; private int _privateStateVer = 0; /// /// 私有数据 /// public Info_PrivateState PrivateState { get { if (null == _privateState || _privateStateVer != _userGameVer) { if (null != _userGame && null != _userGame["privateState"]) { _privateState = _userGame["privateState"].ToObject(); _privateStateVer = _userGameVer; } } return _privateState; } set { _privateState = value; } } private Info_NewbieGuide _newbieGuide; private int _newbieGuideVer = 0; /// /// 新手引导 /// public Info_NewbieGuide NewbieGuideInfo { get { if (null == _newbieGuide || _newbieGuideVer != _userGameVer) { _newbieGuide = _userGame.TryGetValue("NewbieGuide",out var jo)?jo.ToObject() : new Info_NewbieGuide(); _newbieGuideVer = _userGameVer; } return _newbieGuide; } set { _newbieGuide = value; } } private Info_UserTask _task; private int _task_ver; /// /// 任务数据 2020年7月8日19:07:57 /// public Info_UserTask task { get { if (null == _task || _task_ver != _userGameVer) { _task = _userGame.TryGetValue("task", out var jo) ? jo.ToObject() : new Info_UserTask(); _task_ver = _userGameVer; } return _task; } set { _task = value; } } /// /// 商城数据 /// public Info_UserShop shopdata = new Info_UserShop(); private Info_UserPVP _pvpInfo; private int _pvpInfo_ver; /// /// PVP的数据记录(2020年5月11日 更新) /// public Info_UserPVP pvpRecord { get { if (null == _pvpInfo || _pvpInfo_ver != _userGameVer) { _pvpInfo = _userGame.TryGetValue("pvp", out var jo) ? jo.ToObject() : new Info_UserPVP(); _pvpInfo_ver = _userGameVer; } return _pvpInfo; } set { _pvpInfo = value; } } private Info_TaskCard_Shop _taskCard_Shop; private int _taskCard_shop_ver = 0; /// /// 玩家任务卡商店数据 /// public Info_TaskCard_Shop taskCardShop { get { if (null == _taskCard_Shop || _taskCard_shop_ver != _userGameVer) { _taskCard_Shop = _userGame.TryGetValue("taskCardShop", out var jo) ? jo.ToObject() : new Info_TaskCard_Shop(); _taskCard_shop_ver = _userGameVer; } return _taskCard_Shop; } set { _taskCard_Shop = value; } } /// /// 圣哲学院 /// public CollegeInfo collegeInfo = new CollegeInfo(); /// /// 神庙 /// public ShenmiaoInfo shenmiaoInfo = new ShenmiaoInfo(); public Info_Gem gemInfo = new Info_Gem(); public Info_Pay payInfo = new Info_Pay(); /// /// 武器商店每日的武器信息 /// public Dictionary>> weaponPool = new Dictionary>>(); /// /// 购买武器记录 ---因为有重置所以这里做记录 /// public Dictionary>> weaponReward = new Dictionary>>(); /// /// /// public Dictionary storage = new Dictionary(); public StoreNewFeild StoreNewFeild; #endregion #region 不需要同步字段 #endregion #region ' 暂时废弃不用的字段 ' //================好友=============== /// /// 冒险类型 观其的数据记录 /// [Obsolete("关卡地图")] public ArenasRecord areansRecord; #endregion private JObject _userGame; private int _userGameVer = 0; /// /// 初始化玩家的数据 /// public void Initlize(JObject game) { LogHelper.Log("玩家数据反序列化 1"); areansRecord = new ArenasRecord(); collectHero = new GameCollectHero(); collectItem = new GameCollectItem(); collectEquip = new GameCollectEquips(); collectYanling = new GameCollectYanling(); collectTaskCard = new GameCollectTaskCard(); StoreNewFeild = new StoreNewFeild(); zonename = PlayerPrefs.GetString("ZoneName"); if (game != null) { TK = game["TK"].ToString(); _userGame = game; _userGameVer = _userGame.GetHashCode(); InitFromStore((JObject)game["store"]); areansRecord.InitArenasGateData((JObject)game["gates"]); collectHero.InitData((JObject)game["heros"], this); shopdata = game.TryGetValue("shopdata", out var jo) ? jo.ToObject() : new Info_UserShop(); heroTeamConfig = game.TryGetValue("heroTeamConfig", out var htj) ? htj.ToObject() : new Info_HeroTeamConfig(); // 队伍配置信息 collegeInfo.Initlize(game["college"]); shenmiaoInfo.Initlize(game["shenmiao"]); gemInfo.Initlize(game["Gem"]); payInfo.Initlize(game["pay"]); } LogHelper.Log("玩家数据反序列化 完"); } public void InitFromStore(JObject store) { collectItem.InitItemData(store); // 普通道具 collectEquip.InitItemData(store); // 装备从item中独立出来 collectYanling.InitItemData(store); // 言灵 collectTaskCard.InitData(store); // 任务卡 StoreNewFeild.InitItemData(store); this.initWeaponShopInfo(store); //商店武器信息 } public void initWeaponShopInfo(JObject store) { this.weaponPool.Clear(); this.weaponReward.Clear(); JObject jweaponPoolDic = JObject.Parse(store["weaponPool"].ToString()); //Dictionary>> weaponPool = new Dictionary>>(); foreach (KeyValuePair kv in jweaponPoolDic) { JObject jDic = JObject.Parse(kv.Value.ToString()); Dictionary> dic = new Dictionary>(); foreach (KeyValuePair kt in jDic) { JArray arr = JArray.Parse(kt.Value.ToString()); List list = new List(); foreach (JToken item in arr) { list.Add(int.Parse(item.ToString())); } dic[int.Parse(kt.Key)] = list; } this.weaponPool[int.Parse(kv.Key)] = dic; } JObject jweaponRewardDic = JObject.Parse(store["weaponReward"].ToString()); //Dictionary>> weaponReward = new Dictionary>>(); foreach (KeyValuePair kv in jweaponRewardDic) { JObject jDic = JObject.Parse(kv.Value.ToString()); Dictionary> dic = new Dictionary>(); foreach (KeyValuePair kt in jDic) { JArray arr = JArray.Parse(kt.Value.ToString()); List list = new List(); foreach (JToken item in arr) { list.Add(int.Parse(item.ToString())); } dic[int.Parse(kt.Key)] = list; } this.weaponReward[int.Parse(kv.Key)] = dic; } initStorageInfo(store["storage"]); } public void initStorageInfo(JToken Jstorage) { this.storage.Clear(); Dictionary tempdic = new Dictionary(); JObject jstorageDic = JObject.Parse(Jstorage.ToString()); foreach (KeyValuePair kv in jstorageDic) { JObject jitem = JObject.Parse(kv.Value.ToString()); JObject itemDic = JObject.Parse(jitem["itemDic"].ToString()); Dictionary idic = new Dictionary(); foreach (KeyValuePair ki in itemDic) { ItemVo vo = new ItemVo(); vo.typeId = ki.Key; vo.count = int.Parse(ki.Value.ToString()); idic[ki.Key] = vo; } tempdic[int.Parse(kv.Key)] = new StorageVo(); tempdic[int.Parse(kv.Key)].itemDic = idic; Dictionary equipments = jitem["equipment"].ToObject>(); foreach (var ke in equipments) { ke.Value.uid = ke.Key.ToString(); } tempdic[int.Parse(kv.Key)].equipment = equipments; Dictionary yanling = jitem["yanling"].ToObject>(); foreach (var ky in yanling) { ky.Value.uid = ky.Key.ToString(); } tempdic[int.Parse(kv.Key)].yanling = yanling; } this.storage = tempdic; } /// /// 检查玩家账户余额是否充足 /// /// 消费类型 /// 消费钻石数 /// 消费金币数 /// 消费晶石数 /// true = 有足够的账户余额 false = 不足 public bool CheckHasEngoughMoney(AccountType type, int cashPara = 0, int goldPara = 0, int sparPara = 0, int friendPara = 0) { if (type == AccountType.none) { return false; } else if (type == AccountType.gold) { return baseInfo.gold >= goldPara; } else if (type == AccountType.cash) { return baseInfo.cash >= cashPara; } else if (type == AccountType.spar) { return baseInfo.spar >= sparPara; } else { return false; } } /// /// //声明一个委托,其实就是个“命令” /// public delegate void UserAccountChangedEventHandler(); /// /// 玩家账号的金钱信息发生变化事件 /// public UserAccountChangedEventHandler myAccountChangedDelegate; /// /// 玩家的邮件系统发生变化 /// public EventHandler RefreshEmailChangedEvent; /// /// 玩家账号信息发生变化 /// /// 消费账号类型 /// 变化数值 public void ChangeUserAccount(AccountType type, int para) { if (type == AccountType.none) return; if (type == AccountType.gold) { baseInfo.gold += para; } else if (type == AccountType.cash) { baseInfo.cash += para; } else if (type == AccountType.spar) { baseInfo.spar += para; } else if (type == AccountType.exp) { //判断是否升级啦,以及升到哪一级啦 int temp = baseInfo.level; ////根据李宁提供的玩家经验表,和李宁沟通后,采用新的函数.20170406 getNewXp(para); } else { } if (myAccountChangedDelegate != null) { myAccountChangedDelegate.Invoke(); } } #region 玩家获得经验 /// /// 通过等级获取当前升级需要的经验数据 /// /// /// public sm_playerlevel getUserLvById(int lvl) => sm_playerlevel.getUserLvById(lvl); /// /// 新玩家获得经验----根据李宁提供的玩家经验表,和李宁沟通后,采用新的函数.20170406 /// /// private void getNewXp(int num) => baseInfo.getNewXp(num); #endregion /// /// 获取关卡战斗中,玩家上阵的英雄队伍配置 /// /// public Ins_TeamInfo CurrentBattleteam { get { Ins_TeamInfo _arenasBattleteam = heroTeamConfig.CurTeam; for (int i = 0; i < _arenasBattleteam.heros.Count; i++) { string uid = _arenasBattleteam.heros[i]; GameHeroVo vo = collectHero.GetHeroGameInfoByHeroUId(uid); if (vo == null) { _arenasBattleteam.heros[i] = ""; } } return _arenasBattleteam; } } #region 背包/道具相关操作 /// /// 发放奖励字符串 /// /// id,num;id,num;... internal void putItemToStore(string rewardstr) { Dictionary mRewardDic = new Dictionary(); int totalGold = 0; // 金币 int totalCash = 0; // 钻石 int totalTi = 0; // 体力 if (!string.IsNullOrEmpty(rewardstr)) { string[] arr = rewardstr.Split(';'); foreach (string s in arr) { string[] rewards = s.Split(','); string itemid = rewards[0]; int itemnum = Convert.ToInt32(rewards[1]); if (mRewardDic.ContainsKey(itemid)) { mRewardDic[itemid] += itemnum; } else { mRewardDic.Add(itemid, itemnum); } } foreach (var kv in mRewardDic) { var itemMo = sm_item_base.GetMoById(int.Parse(kv.Key)); if (null != itemMo) { var subType = (EItemSubType)itemMo.subType; switch (subType) { case EItemSubType.EXP: // 0: 指挥官经验 break; case EItemSubType.Gold: // 1: 金币 totalGold += kv.Value; break; case EItemSubType.Gem: // 2: 钻石 totalCash += kv.Value; break; case EItemSubType.PVPCoin: // 5: PVP币 break; case EItemSubType.Weapon: // 101: 武器 case EItemSubType.YanLing: // 401: 言灵 LogHelper.LogError("言灵和武器不可以在客户直接加,需要服务端生成uid,然后同步给客户端."); break; case EItemSubType.Segment: // 201: 碎片 case EItemSubType.YanlingBookSegement: // 202: 言灵碎片 case EItemSubType.StrengthStone: // 312: 进阶材料 case EItemSubType.YanlingBook: // 313: 言灵召唤书 case EItemSubType.AdvancedStone: // 321: 进阶材料 case EItemSubType.AdvancedFineStone: // 322: 进阶材料 case EItemSubType.ForgingMaterial: // 323: 锻造材料 case EItemSubType.Gene: // 311: 基因,经验丹 collectItem.AddItems(kv.Key, kv.Value); break; case EItemSubType.BattleItem_HP: // 341: 战场掉落补血丹 不进包裹 case EItemSubType.BattleItem_MP: // 342: 战场掉落补魔丹 不进包裹 case EItemSubType.BattleItem_Box: // 343: 战场掉落宝箱 不进包裹 LogHelper.LogError("战场掉落道具不进入包裹!"); break; default: LogHelper.LogError("落入包裹时,出现非法物品!"); break; } } } } UserProxy.Instance.player.ChangeUserAccount(AccountType.cash, totalCash); UserProxy.Instance.player.ChangeUserAccount(AccountType.gold, totalGold); } #endregion } /// /// 账号数据类型 /// public enum AccountType { none, gold, spar, cash, exp, friend }