public CfgStrong GetStrongCfg(int pos, int starLv) { CfgStrong cfg = null; Dictionary <int, CfgStrong> cfgDic = null; if (strongDic.TryGetValue(pos, out cfgDic)) { if (cfgDic != null && cfgDic.TryGetValue(starLv, out cfg)) { return(cfg); } } return(null); }
public void UpdateData(PlayerData data) { if (data == null) { data = mGameRoot.GetPlayerData(); } string iconPath = ""; int curStar = data.Strong[curToggleIndex]; CfgStrong cfg = mCfgSvc.GetCfgStrong(curToggleIndex, curStar); if (cfg == null) { Debug.LogError("获取强化数据配置错误"); return; } int addHp = mCfgSvc.GetStrongProTotalAddition(curToggleIndex, curStar, (int)PropertyType.Hp); int addHurt = mCfgSvc.GetStrongProTotalAddition(curToggleIndex, curStar, (int)PropertyType.Hurt); int addDef = mCfgSvc.GetStrongProTotalAddition(curToggleIndex, curStar, (int)PropertyType.Def); //下一个星级配置数据 nextStrongCfg = mCfgSvc.GetCfgStrong(curToggleIndex, curStar + 1); int addHpAfter = 0; int addHurtAfter = 0; int addDefAfter = 0; int needLv = 0; int consumeCoin = 0; int consumeCrystal = 0; if (nextStrongCfg == null) { fullToHideTr.gameObject.SetActive(false); } else { fullToHideTr.gameObject.SetActive(true); addHpAfter = nextStrongCfg.addHp; addHurtAfter = nextStrongCfg.addHurt; addDefAfter = nextStrongCfg.addDef; needLv = nextStrongCfg.minLv; consumeCoin = nextStrongCfg.coin; consumeCrystal = nextStrongCfg.crystal; } int totalCoin = data.Coin; switch (curToggleIndex) { case 0: //头部 iconPath = PathDefine.TouKuiIcon; break; case 1: //身体 iconPath = PathDefine.BodyIcon; break; case 2: //腰部 iconPath = PathDefine.YaoBuIcon; break; case 3: //手臂 iconPath = PathDefine.HandIcon; break; case 4: //腿部 iconPath = PathDefine.LegIcon; break; case 5: //脚部 iconPath = PathDefine.FootIcon; break; } SetSprite(imgIcon, iconPath); SetText(txtCurStar, string.Format(Language.GetString(94), curStar)); for (int i = 0; i < starTrs.Length; i++) { if (i <= curStar - 1) { starTrs[i].gameObject.SetActive(true); } else { starTrs[i].gameObject.SetActive(false); } } SetText(txtHpPreDes, string.Format(Language.GetString(95), addHp)); SetText(txtHurtPreDes, string.Format(Language.GetString(96), addHurt)); SetText(txtDefPreDes, string.Format(Language.GetString(97), addDef)); SetText(txtHpAfterDes, string.Format(Language.GetString(98), addHpAfter)); SetText(txtHurtAfterDes, string.Format(Language.GetString(98), addHurtAfter)); SetText(txtDefAfterDes, string.Format(Language.GetString(98), addDefAfter)); SetText(txtNeedLv, string.Format(Language.GetString(89), needLv)); SetText(txtConsumeCoin, consumeCoin); SetText(txtConsumeCrystal, string.Format(Language.GetString(9), consumeCrystal, data.Crystal)); SetText(txtTotalCoin, totalCoin); }
private void InitStrongCfg() { XmlDocument xmlDoc = new XmlDocument(); string inHaoXinStr = @"G:\Homework\DarkGod\Assets\Resources\Configs\strong.xml"; string inHomeStr = @"E:\UnityPorjects\DarkGod\Assets\Resources\Configs\strong.xml"; xmlDoc.Load(inHaoXinStr); XmlNodeList nodeList = xmlDoc.SelectSingleNode("root").ChildNodes; Dictionary <int, CfgStrong> cfgDic = null; for (int i = 0; i < nodeList.Count; i++) { XmlElement ele = nodeList[i] as XmlElement; if (ele.GetAttribute("ID") == null) { continue; } int ID = Convert.ToInt32(ele.GetAttribute("ID")); CfgStrong cfg = new CfgStrong { ID = ID, }; foreach (XmlElement subEle in nodeList[i].ChildNodes) { string str = subEle.Name; switch (str) { case "pos": cfg.pos = int.Parse(subEle.InnerText); break; case "starlv": cfg.starLv = int.Parse(subEle.InnerText); break; case "addhp": cfg.addHp = int.Parse(subEle.InnerText); break; case "addhurt": cfg.addHurt = int.Parse(subEle.InnerText); break; case "adddef": cfg.addDef = int.Parse(subEle.InnerText); break; case "minlv": cfg.minLv = int.Parse(subEle.InnerText); break; case "coin": cfg.coin = int.Parse(subEle.InnerText); break; case "crystal": cfg.crystal = int.Parse(subEle.InnerText); break; } } if (strongDic.ContainsKey(cfg.pos)) { cfgDic.Add(cfg.starLv, cfg); } else { cfgDic = new Dictionary <int, CfgStrong>(); cfgDic.Add(cfg.starLv, cfg); strongDic.Add(cfg.pos, cfgDic); } } }
public void HandleReqStrong(MsgPack pack) { ReqStrong reqData = pack.msg.ReqStrong; NetMsg newMsg = new NetMsg { cmd = (int)MsgType.RspStrong, }; int pos = reqData.pos; PlayerData pd = CacheSvc.Instance.GetPlayerDataBySession(pack.session); int curStarLv = pd.Strong[pos]; CfgStrong nextCfg = CfgSvc.Instance.GetStrongCfg(pos, curStarLv + 1); if (nextCfg != null) { if (pd.Coin < nextCfg.coin) { newMsg.err = (int)ErrorCode.LackCoin; } else if (pd.Level < nextCfg.minLv) { newMsg.err = (int)ErrorCode.LackLevel; } else if (pd.Crystal < nextCfg.crystal) { newMsg.err = (int)ErrorCode.LackCrystal; } else { //修改缓存,更新数据库 pd.Strong[pos] += 1; pd.Hp += nextCfg.addHp; pd.Ad += nextCfg.addHurt; pd.Ap += nextCfg.addHurt; pd.Addef += nextCfg.addDef; pd.Apdef += nextCfg.addDef; pd.Coin -= nextCfg.coin; pd.Crystal -= nextCfg.crystal; if (CacheSvc.Instance.UpdatePlayerDataToDB(pd.ID, pd)) { newMsg.RspStrong = new RspStrong { data = pd, }; } else { newMsg.err = (int)ErrorCode.UpdateDBFailed; } } } else { //这里防止客户端在已经升满级的情况下发起强化请求 PECommonTool.Log("获取强化配置错误", LogType.Error); return; } pack.session.SendMsg(newMsg); }