123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using NetData;
- /// <summary>
- /// 玩家数据结构
- /// </summary>
- public class Player
- {
- #region 基础字段
- /// <summary>
- /// 游戏ID
- /// </summary>
- public string uid { get; set; }
- /// <summary>
- /// 分区ID
- /// </summary>
- public int zoneid { get; set; }
- /// <summary>
- /// 分区名称
- /// </summary>
- public string zonename { get; set; }
- /// <summary>
- /// http通讯中采用的token
- /// </summary>
- public string TK="";
- //========================================
- /// <summary>
- /// 类型数值 含义
- ///-1 未实名
- ///0 0 到 7 岁
- ///8 8 到 15 岁
- ///16 16 到 17 岁
- ///18 成年玩家
- /// </summary>
- public int ageRange = -1;
- #endregion
- //-----------------分割线----------------------------
- #region 集合型字段
- private Info_UserBase _baseInfo;
- private int _baseInfoHash = 0;
- /// <summary>
- /// 基础信息
- /// </summary>
- public Info_UserBase baseInfo
- {
- get
- {
- if (_baseInfo == null || _baseInfoHash != _userGameVer)
- {
- _baseInfo = _userGame?["baseInfo"].ToObject<Info_UserBase>() ?? null;
- _baseInfoHash = _userGameVer;
- }
- return _baseInfo;
- }
- set
- {
- _baseInfo = value;
- }
- }
- /// <summary>
- /// 玩家圈养的 英雄数据列表
- /// </summary>
- public GameCollectHero collectHero;
- /// <summary>
- /// 物品数据
- /// </summary>
- public GameCollectItem collectItem;
- /// <summary>
- /// 装备
- /// </summary>
- public GameCollectEquips collectEquip;
- /// <summary>
- /// 言灵
- /// </summary>
- public GameCollectYanling collectYanling;
- public GameCollectTaskCard collectTaskCard;
- /// <summary>
- /// 触发条件得到的限时随机礼包
- /// </summary>
- public List<Ins_Gift> triggerLimitTsGift = new List<Ins_Gift>();
- /// <summary>
- /// 玩家的配置的战队信息
- /// </summary>
- public Info_HeroTeamConfig heroTeamConfig;
- private Info_NewMap _newMap;
- private int _newMap_ver;
- /// <summary>
- /// 地图解锁信息
- /// </summary>
- public Info_NewMap newMap
- {
- get
- {
- if (null == _newMap || _newMap_ver != _userGameVer)
- {
- _newMap = _userGame.TryGetValue("newMap", out var jo)?jo.ToObject<Info_NewMap>() : new Info_NewMap();
- _newMap_ver = _userGameVer;
- }
- return _newMap;
- }
- set
- {
- _newMap = value;
- }
- }
- private Info_PrivateState _privateState;
- private int _privateStateVer = 0;
- /// <summary>
- /// 私有数据
- /// </summary>
- public Info_PrivateState PrivateState
- {
- get
- {
- if (null == _privateState || _privateStateVer != _userGameVer)
- {
- if (null != _userGame && null != _userGame["privateState"])
- {
- _privateState = _userGame["privateState"].ToObject<Info_PrivateState>();
- _privateStateVer = _userGameVer;
- }
- }
- return _privateState;
- }
- set
- {
- _privateState = value;
- }
- }
- private Info_NewbieGuide _newbieGuide;
- private int _newbieGuideVer = 0;
- /// <summary>
- /// 新手引导
- /// </summary>
- public Info_NewbieGuide NewbieGuideInfo
- {
- get
- {
- if (null == _newbieGuide || _newbieGuideVer != _userGameVer)
- {
- _newbieGuide = _userGame.TryGetValue("NewbieGuide",out var jo)?jo.ToObject<Info_NewbieGuide>() : new Info_NewbieGuide();
- _newbieGuideVer = _userGameVer;
- }
- return _newbieGuide;
- }
- set
- {
- _newbieGuide = value;
- }
- }
- private Info_UserTask _task;
- private int _task_ver;
- /// <summary>
- /// 任务数据 2020年7月8日19:07:57
- /// </summary>
- public Info_UserTask task
- {
- get
- {
- if (null == _task || _task_ver != _userGameVer)
- {
- _task = _userGame.TryGetValue("task", out var jo) ? jo.ToObject<Info_UserTask>() : new Info_UserTask();
- _task_ver = _userGameVer;
- }
- return _task;
- }
- set
- {
- _task = value;
- }
- }
- /// <summary>
- /// 商城数据
- /// </summary>
- public Info_UserShop shopdata = new Info_UserShop();
- private Info_UserPVP _pvpInfo;
- private int _pvpInfo_ver;
- /// <summary>
- /// PVP的数据记录(2020年5月11日 更新)
- /// </summary>
- public Info_UserPVP pvpRecord
- {
- get
- {
- if (null == _pvpInfo || _pvpInfo_ver != _userGameVer)
- {
- _pvpInfo = _userGame.TryGetValue("pvp", out var jo) ? jo.ToObject<Info_UserPVP>() : new Info_UserPVP();
- _pvpInfo_ver = _userGameVer;
- }
- return _pvpInfo;
- }
- set
- {
- _pvpInfo = value;
- }
- }
- private Info_TaskCard_Shop _taskCard_Shop;
- private int _taskCard_shop_ver = 0;
- /// <summary>
- /// 玩家任务卡商店数据
- /// </summary>
- public Info_TaskCard_Shop taskCardShop
- {
- get
- {
- if (null == _taskCard_Shop || _taskCard_shop_ver != _userGameVer)
- {
- _taskCard_Shop = _userGame.TryGetValue("taskCardShop", out var jo) ? jo.ToObject<Info_TaskCard_Shop>() : new Info_TaskCard_Shop();
- _taskCard_shop_ver = _userGameVer;
- }
- return _taskCard_Shop;
- }
- set
- {
- _taskCard_Shop = value;
- }
- }
- /// <summary>
- /// 圣哲学院
- /// </summary>
- public CollegeInfo collegeInfo = new CollegeInfo();
- /// <summary>
- /// 神庙
- /// </summary>
- public ShenmiaoInfo shenmiaoInfo = new ShenmiaoInfo();
- public Info_Gem gemInfo = new Info_Gem();
- public Info_Pay payInfo = new Info_Pay();
- /// <summary>
- /// 武器商店每日的武器信息
- /// </summary>
- public Dictionary<int, Dictionary<int, List<int>>> weaponPool = new Dictionary<int, Dictionary<int, List<int>>>();
- /// <summary>
- /// 购买武器记录 ---因为有重置所以这里做记录
- /// </summary>
- public Dictionary<int, Dictionary<int, List<int>>> weaponReward = new Dictionary<int, Dictionary<int, List<int>>>();
- /// <summary>
- ///
- /// </summary>
- public Dictionary<int, StorageVo> storage = new Dictionary<int, StorageVo>();
- public StoreNewFeild StoreNewFeild;
- #endregion
- #region 不需要同步字段
- #endregion
- #region ' 暂时废弃不用的字段 '
- //================好友===============
- /// <summary>
- /// 冒险类型 观其的数据记录
- /// </summary>
- [Obsolete("关卡地图")]
- public ArenasRecord areansRecord;
- #endregion
- private JObject _userGame;
- private int _userGameVer = 0;
- /// <summary>
- /// 初始化玩家的数据
- /// </summary>
- 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<Info_UserShop>() : new Info_UserShop();
- heroTeamConfig = game.TryGetValue("heroTeamConfig", out var htj) ? htj.ToObject<Info_HeroTeamConfig>() : 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<int, Dictionary<int, List<int>>> weaponPool = new Dictionary<int, Dictionary<int, List<int>>>();
- foreach (KeyValuePair<string, JToken> kv in jweaponPoolDic)
- {
- JObject jDic = JObject.Parse(kv.Value.ToString());
- Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
- foreach (KeyValuePair<string, JToken> kt in jDic)
- {
- JArray arr = JArray.Parse(kt.Value.ToString());
- List<int> list = new List<int>();
- 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<int, Dictionary<int, List<int>>> weaponReward = new Dictionary<int, Dictionary<int, List<int>>>();
- foreach (KeyValuePair<string, JToken> kv in jweaponRewardDic)
- {
- JObject jDic = JObject.Parse(kv.Value.ToString());
- Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
- foreach (KeyValuePair<string, JToken> kt in jDic)
- {
- JArray arr = JArray.Parse(kt.Value.ToString());
- List<int> list = new List<int>();
- 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<int, StorageVo> tempdic = new Dictionary<int, StorageVo>();
- JObject jstorageDic = JObject.Parse(Jstorage.ToString());
- foreach (KeyValuePair<string, JToken> kv in jstorageDic)
- {
- JObject jitem = JObject.Parse(kv.Value.ToString());
- JObject itemDic = JObject.Parse(jitem["itemDic"].ToString());
- Dictionary<string, ItemVo> idic = new Dictionary<string, ItemVo>();
- foreach (KeyValuePair<string, JToken> 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<int, UserEquipmentVo> equipments = jitem["equipment"].ToObject<Dictionary<int, UserEquipmentVo>>();
- foreach (var ke in equipments)
- {
- ke.Value.uid = ke.Key.ToString();
- }
- tempdic[int.Parse(kv.Key)].equipment = equipments;
- Dictionary<int, UserYanlingVo> yanling = jitem["yanling"].ToObject<Dictionary<int, UserYanlingVo>>();
- foreach (var ky in yanling)
- {
- ky.Value.uid = ky.Key.ToString();
- }
- tempdic[int.Parse(kv.Key)].yanling = yanling;
- }
- this.storage = tempdic;
- }
- /// <summary>
- /// 检查玩家账户余额是否充足
- /// </summary>
- /// <param name="type">消费类型</param>
- /// <param name="cashPara">消费钻石数</param>
- /// <param name="goldPara">消费金币数</param>
- /// <param name="sparPara">消费晶石数</param>
- /// <returns>true = 有足够的账户余额 false = 不足</returns>
- 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;
- }
- }
- /// <summary>
- /// //声明一个委托,其实就是个“命令”
- /// </summary>
- public delegate void UserAccountChangedEventHandler();
- /// <summary>
- /// 玩家账号的金钱信息发生变化事件
- /// </summary>
- public UserAccountChangedEventHandler myAccountChangedDelegate;
- /// <summary>
- /// 玩家的邮件系统发生变化
- /// </summary>
- public EventHandler RefreshEmailChangedEvent;
- /// <summary>
- /// 玩家账号信息发生变化
- /// </summary>
- /// <param name="type">消费账号类型</param>
- /// <param name="para">变化数值</param>
- 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 玩家获得经验
- /// <summary>
- /// 通过等级获取当前升级需要的经验数据
- /// </summary>
- /// <param name="lvl"></param>
- /// <returns></returns>
- public sm_playerlevel getUserLvById(int lvl) => sm_playerlevel.getUserLvById(lvl);
- /// <summary>
- /// 新玩家获得经验----根据李宁提供的玩家经验表,和李宁沟通后,采用新的函数.20170406
- /// </summary>
- /// <param name="num"></param>
- private void getNewXp(int num) => baseInfo.getNewXp(num);
- #endregion
- /// <summary>
- /// 获取关卡战斗中,玩家上阵的英雄队伍配置
- /// </summary>
- /// <returns></returns>
- 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 背包/道具相关操作
- /// <summary>
- /// 发放奖励字符串
- /// </summary>
- /// <param name="rewardStr">id,num;id,num;...</param>
- internal void putItemToStore(string rewardstr)
- {
- Dictionary<string, int> mRewardDic = new Dictionary<string, int>();
- 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
- }
- /// <summary>
- /// 账号数据类型
- /// </summary>
- public enum AccountType
- {
- none,
- gold,
- spar,
- cash,
- exp,
- friend
- }
|