public StrongerCfd GetStrongerData(int stongerType, int starLv) { StrongerCfd data = null; Dictionary <int, StrongerCfd> tmpDic = null; if (_dictStrongerCfgData.TryGetValue(stongerType, out tmpDic)) { if (tmpDic.ContainsKey(starLv)) { data = tmpDic[starLv]; } } return(data); }
private void InitStrongerCfgData() { //开始解析xml文件 XmlDocument doc = new XmlDocument(); doc.Load(@"..\..\..\Configs\strong.xml"); XmlNodeList nodeList = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodeList.Count; i++) { XmlElement element = nodeList[i] as XmlElement; if (element.GetAttributeNode("ID") == null) { continue; } int id = Convert.ToInt32(element.GetAttributeNode("ID").InnerText); StrongerCfd strongerData = new StrongerCfd { ID = id, }; #region 遍历解析 foreach (XmlElement elem in nodeList[i].ChildNodes) { int value = int.Parse(elem.InnerText); switch (elem.Name) { case "pos": strongerData.stongerType = value; break; case "starlv": strongerData.starLv = value; break; case "addhp": strongerData.addHp = value; break; case "addhurt": strongerData.addHurt = value; break; case "adddef": strongerData.addDef = value; break; case "minlv": strongerData.minLv = value; break; case "coin": strongerData.coin = value; break; case "crystal": strongerData.crystal = value; break; } } #endregion Dictionary <int, StrongerCfd> tmpDic = null; if (_dictStrongerCfgData.TryGetValue(strongerData.stongerType, out tmpDic)) { tmpDic.Add(strongerData.starLv, strongerData); } else { tmpDic = new Dictionary <int, StrongerCfd>(); tmpDic.Add(strongerData.starLv, strongerData); _dictStrongerCfgData.Add(strongerData.stongerType, tmpDic); } } }
public void RequestStronger(MsgPack packMsg) { RequestStronger data = packMsg._msg.reqStronger; NetMsg netMsg = new NetMsg { cmd = (int)MsgCommand.Cmd_RspStronger, }; PlayerData playerData = cacheSvc.GetPlayerDataBySession(packMsg._session); int curStarLv = playerData.strongerArray[data.stongerType]; StrongerCfd nextCfg = ConfigSvc.Instance.GetStrongerData(data.stongerType, curStarLv + 1); //相关条件判断 if (playerData.lv < nextCfg.minLv) { netMsg.err = (int)ErroCode.Error_LevelLack; } else if (playerData.coin < nextCfg.coin) { netMsg.err = (int)ErroCode.Error_CoinLack; } else if (playerData.crystal < nextCfg.crystal) { netMsg.err = (int)ErroCode.Error_CrystalLack; } else { //强化任务 TaskRewardSys.Instance.CalcTaskProgress(playerData, 3); //资源扣除 playerData.coin -= nextCfg.coin; playerData.crystal -= nextCfg.crystal; playerData.strongerArray[data.stongerType] += 1; //增加属性值 playerData.hp += nextCfg.addHp; playerData.ad += nextCfg.addHurt; playerData.ap += nextCfg.addHurt; playerData.addef += nextCfg.addDef; playerData.apdef += nextCfg.addDef; } //更新数据库 if (!cacheSvc.UpdatePlayerData(playerData.id, playerData)) { netMsg.err = (int)ErroCode.Error_UpdateDB; } else { //发到客户端 netMsg.rspStronger = new ResponseStronger { coin = playerData.coin, crystal = playerData.crystal, hp = playerData.hp, ad = playerData.ad, ap = playerData.ap, addDef = playerData.addef, apDef = playerData.apdef, strongerArr = playerData.strongerArray }; packMsg._session.SendMsg(netMsg); } }