/// <summary> /// 处理请求升级逻辑 /// </summary> /// <param name="pack"></param> public void ReqStrong(MsgPack pack) { ReqStrong data = pack.msg.reqStrong; GameMsg msg = new GameMsg { cmd = (int)CMD.RspStrong, }; PlayerData pd = cacheSvc.GetPlayerDataBySettion(pack.session); int curtStartLv = pd.strongArr[data.pos];//请求升级的武器 StrongCfg nextSd = cfgSvc.GetStrongCfg(data.pos, curtStartLv + 1); //数据校验(这是必须的,如果客户端均已校验,则此校验结果可以作为玩家是否作弊的依据) if (pd.lv < nextSd.minlv) { msg.err = (int)ErrorCode.LackLevel; } else if (pd.coin < nextSd.coin) { msg.err = (int)ErrorCode.LackCoin; } else if (pd.crystal < nextSd.crystal) { msg.err = (int)ErrorCode.LackCrystal; } else//校验通过 { //资产变化 pd.coin -= nextSd.coin; pd.crystal -= nextSd.crystal; pd.strongArr[data.pos] += 1; //属性变化 pd.hp += nextSd.addhp; pd.ad += nextSd.addhurt; pd.ap += nextSd.addhurt; pd.addef += nextSd.adddef; pd.apdef += nextSd.adddef; //任务进度更新 TaskSys.Instance.CalcTaskPrgs(pd, 3); //数据库更新 if (cacheSvc.UpdatePlayerData(pd.id, pd)) { msg.rspStrong = new RspStrong { coin = pd.coin, crystal = pd.crystal, hp = pd.hp, ad = pd.ad, ap = pd.ap, addef = pd.addef, apdef = pd.apdef, strongArr = pd.strongArr }; } else { msg.err = (int)ErrorCode.UpdateDbError; } } pack.session.SendMsg(msg); }
public int GetPropAddPreLv(int pos, int starLv, int type) { int val = 0; Dictionary <int, StrongCfg> dic = null; if (strongDict.TryGetValue(pos, out dic)) { for (int i = 1; i <= starLv; i++) { StrongCfg strongCfg = null; if (dic.TryGetValue(i, out strongCfg)) { switch (type) { case 1: //hp val += strongCfg.addhp; break; case 2: //attack val += strongCfg.addhurt; break; case 3: //def val += strongCfg.adddef; break; } } } } return(val); }
/// <summary> /// 查询装备强化加成信息属性 /// </summary> /// <param name="pos">装备部位</param> /// <param name="starLv">星级</param> /// <param name="type">属性</param> /// <returns></returns> public int GetPropAddValPreLv(int pos, int starLv, int type) { Dictionary <int, StrongCfg> posDic = null; int val = 0; if (strongCfg.TryGetValue(pos, out posDic)) { for (int i = 1; i <= starLv; i++) { StrongCfg sc = null; if (posDic.TryGetValue(i, out sc)) { switch (type) { case 1: //HP val += sc.addhp; break; case 2: val += sc.addhurt; //Hurt break; case 3: val += sc.adddef; //Defense break; } } } } return(val); }
public void ReqStrong(MsgPack pack) { ReqStrong data = pack.gameMsg.val as ReqStrong; GameMsg msg = new GameMsg() { cmd = (int)CMD.RspStrong }; PlayerData pd = cacheSvc.GetPlayerDataBySession(pack.session); int curtStarLv = pd.strongArr[data.pos]; StrongCfg nextSD = cfgSvc.GetStrongData(data.pos, curtStarLv + 1); if (pd.lv < nextSD.minlv) { msg.err = (int)ErrorCode.LackLevel; } else if (pd.coin < nextSD.coin) { msg.err = (int)ErrorCode.LackCoin; } else if (pd.crystal < nextSD.crystal) { msg.err = (int)ErrorCode.LackCrystal; } else { TaskSys.Instance.CalcTaskPrgs(pd, 3); pd.coin -= nextSD.coin; pd.crystal -= nextSD.crystal; pd.strongArr[data.pos] += 1; pd.hp += nextSD.addhp; pd.ad += nextSD.addhurt; pd.ap += nextSD.addhurt; pd.addef += nextSD.adddef; pd.apdef += nextSD.adddef; } if (cacheSvc.UpdatePlayerData(pd.id, pd)) { msg.val = new RspStrong() { coin = pd.coin, crystal = pd.crystal, hp = pd.hp, ad = pd.ad, ap = pd.ap, addef = pd.addef, apdef = pd.apdef, strong = pd.strongArr }; } else { msg.err = (int)ErrorCode.UpdateDBError; } pack.session.SendMsg(msg); }
public void RequestStrong(MsgPack msgPack) { RequestStrong data = msgPack.Msg.RequestStrong; NetMsg netMsg = new NetMsg { cmd = (int)Command.RspStrong }; PlayerData playerData = CacheSvc.GetPlayerDataBySession(msgPack.Session); int curtStartLevel = playerData.StrongArray[data.pos]; StrongCfg nextStrong = ResCfgSvc.Instance.GetStrongCfg(data.pos, curtStartLevel + 1); if (playerData.Level < nextStrong.MinLevel) { netMsg.err = (int)ErrorCode.LackLevel; } else if (playerData.Coin < nextStrong.Coin) { netMsg.err = (int)ErrorCode.LackCoin; } else if (playerData.Crystal < nextStrong.Crystal) { netMsg.err = (int)ErrorCode.LackCrystal; } else { TaskSys.Instance.CalcTaskPrangs(playerData, 3); playerData.Coin -= nextStrong.Coin; playerData.Crystal -= nextStrong.Crystal; playerData.StrongArray[data.pos] += 1; playerData.Hp += nextStrong.AddHp; playerData.Ad += nextStrong.AddHurt; playerData.AdDefense += nextStrong.AddDefense; playerData.ApDefense += nextStrong.AddDefense; } if (!CacheSvc.UpdatePlayerData(playerData.Id, playerData)) { netMsg.err = (int)ErrorCode.UpdateDbError; } else { netMsg.ResponseStrong = new ResponseStrong { Coin = playerData.Coin, Crystal = playerData.Crystal, Hp = playerData.Hp, Ad = playerData.Ad, Ap = playerData.Ap, AdDefense = playerData.AdDefense, ApDefense = playerData.ApDefense, StrongArray = playerData.StrongArray, }; } msgPack.Session.SendMsg(netMsg); }
public StrongCfg GetStrongData(int pos, int starlv) { StrongCfg sd = null; Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(pos, out dic)) { dic.TryGetValue(starlv, out sd); } return(sd); }
public StrongCfg GetStrongCfg(int pos, int starlv) { StrongCfg strongCfg = null; if (strongDictionary.TryGetValue(pos, out var dic)) { if (dic.ContainsKey(starlv)) { strongCfg = dic[starlv]; } } return(strongCfg); }
public StrongCfg GetStrongCfg(int id, int starlv) { StrongCfg CuttentStrong = null; Dictionary <int, StrongCfg> StrongDic = null; if (StrongCfgDic.TryGetValue(id, out StrongDic)) { if (StrongDic.ContainsKey(starlv)) { CuttentStrong = StrongDic[starlv]; } } return(CuttentStrong); }
public StrongCfg GetStrongData(int pos, int startlv) { StrongCfg sc = null; Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(pos, out dic)) { if (dic.TryGetValue(startlv, out sc)) { return(sc); } } return(null); }
public StrongCfg GetStrongCfg(int pos, int starlv) { StrongCfg sd = null; Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(pos, out dic)) { if (dic.ContainsKey(starlv)) { sd = dic[starlv]; } } return(sd); }
/// <summary> /// 查询装备强化加成信息 /// </summary> /// <param name="pos">装备部位</param> /// <param name="starLv">星级</param> /// <returns></returns> public StrongCfg GetStrongCfgData(int pos, int starLv) { Dictionary <int, StrongCfg> dic; if (strongCfg.TryGetValue(pos, out dic)) { //return data; StrongCfg data = null; if (dic.TryGetValue(starLv, out data)) { return(data); } } return(null); }
public StrongCfg GetStrongCfgData(int pos, int starLv) { StrongCfg res = null; if (strongCfgDic.ContainsKey(pos)) { Dictionary <int, StrongCfg> dic = strongCfgDic[pos]; if (dic.ContainsKey(starLv)) { return(dic[starLv]); } } if (res == null) { NETCommon.Log("StrongCfg获取失败", NETLogLevel.Error); } return(res); }
private void InitStrongCfg(string path) { TextAsset xml = Resources.Load <TextAsset>(path); if (!xml) { PECommon.Log("xml file:" + path + " not exist", LogType.Error); } else { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml.text); XmlNodeList nodLst = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodLst.Count; i++) { XmlElement ele = nodLst[i] as XmlElement; if (ele.GetAttributeNode("ID") == null) { continue; } int ID = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText); StrongCfg sd = new StrongCfg { ID = ID }; foreach (XmlElement e in nodLst[i].ChildNodes) { int val = int.Parse(e.InnerText); switch (e.Name) { case "pos": sd.pos = val; break; case "starlv": sd.startlv = val; break; case "addhp": sd.addhp = val; break; case "addhurt": sd.addhurt = val; break; case "adddef": sd.adddef = val; break; case "minlv": sd.minlv = val; break; case "coin": sd.coin = val; break; case "crystal": sd.crystal = val; break; } } Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(sd.pos, out dic)) { dic.Add(sd.startlv, sd); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(sd.startlv, sd); strongDic.Add(sd.pos, dic); } } } }
private void RefreshItem() { //金币 SetText(txtCoin, pd.coin); switch (currentIndex) { case 0: SetSprite(imgCurtPos, PathDefine.ItemToukui); break; case 1: SetSprite(imgCurtPos, PathDefine.ItemBody); break; case 2: SetSprite(imgCurtPos, PathDefine.ItemYaobu); break; case 3: SetSprite(imgCurtPos, PathDefine.ItemHand); break; case 4: SetSprite(imgCurtPos, PathDefine.ItemLeg); break; case 5: SetSprite(imgCurtPos, PathDefine.ItemFoot); break; default: break; } SetText(txtStartLv, pd.strongArr[currentIndex] + "星级"); int curtStarLv = pd.strongArr[currentIndex]; for (int i = 0; i < starTransGrp.childCount; i++) { Image img = starTransGrp.GetChild(i).GetComponent <Image>(); if (i < curtStarLv) { SetSprite(img, PathDefine.SpStar2); } else { SetSprite(img, PathDefine.SpStar1); } } int nextStarLv = curtStarLv + 1; int sumAddHp = resSvc.GetPropAddValPreLv(currentIndex, nextStarLv, 1); int sumAddHurt = resSvc.GetPropAddValPreLv(currentIndex, nextStarLv, 2); int sumAddDef = resSvc.GetPropAddValPreLv(currentIndex, nextStarLv, 3); SetText(propHP1, "生命 +" + sumAddHp); SetText(propHurt1, "伤害 +" + sumAddHurt); SetText(propDef1, "防御 +" + sumAddDef); nextSd = resSvc.GetStrongCfg(currentIndex, nextStarLv); if (nextSd != null) { IsShowUpgradePanel(true); SetText(propHp2, "强化后 +" + nextSd.addhp); SetText(propHurt2, "+" + nextSd.addhurt); SetText(propDef2, "+" + nextSd.adddef); SetText(txtNeedLv, "需要等级:" + nextSd.minlv); SetText(txtCostCoin, "需要消耗: " + nextSd.coin); SetText(txtCostCrystal, nextSd.crystal + "/" + pd.crystal); } else { IsShowUpgradePanel(false); } }
private void InitStrongCfg(string path) { XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNodeList nodLst = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodLst.Count; i++) { XmlElement ele = nodLst[i] as XmlElement; if (ele.GetAttributeNode("ID") == null) { continue; } int ID = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText); StrongCfg sc = new StrongCfg { ID = ID }; foreach (XmlElement e in nodLst[i].ChildNodes) { int val = int.Parse(e.InnerText);; switch (e.Name) { case "pos": sc.pos = val; break; case "starlv": sc.starlv = val; break; case "adddef": sc.adddef = val; break; case "addhp": sc.addhp = val; break; case "addhurt": sc.addhurt = val; break; case "minlv": sc.minlv = val; break; case "coin": sc.coin = val; break; case "crystal": sc.crystal = val; break; } } Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(sc.pos, out dic) == true) { dic.Add(sc.starlv, sc); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(sc.starlv, sc); strongDic.Add(sc.pos, dic); } } Common.Log("Strong Cfg Init Done."); }
public void InitStrongCfg(string path) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); XmlNode root = xmlDoc.SelectSingleNode("root"); XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode strongNode in nodeList) { int id = int.Parse(strongNode.Attributes["ID"].Value); StrongCfg strongCfg = new StrongCfg { ID = id }; XmlNodeList fieldNodeList = strongNode.ChildNodes; foreach (XmlNode fieldNode in fieldNodeList) { switch (fieldNode.Name) { case "pos": strongCfg.pos = int.Parse(fieldNode.InnerText); break; case "starlv": strongCfg.starlv = int.Parse(fieldNode.InnerText); break; case "addhp": strongCfg.addhp = int.Parse(fieldNode.InnerText); break; case "addhurt": strongCfg.addhurt = int.Parse(fieldNode.InnerText); break; case "adddef": strongCfg.adddef = int.Parse(fieldNode.InnerText); break; case "minlv": strongCfg.minlv = int.Parse(fieldNode.InnerText); break; case "coin": strongCfg.coin = int.Parse(fieldNode.InnerText); break; case "crystal": strongCfg.crystal = int.Parse(fieldNode.InnerText); break; } } Dictionary <int, StrongCfg> dic = null; //如果有对应的键pos,说明这类装备已经有部分升级配置信息被录入,直接加入 if (strongDict.TryGetValue(strongCfg.pos, out dic)) { dic.Add(strongCfg.starlv, strongCfg); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(strongCfg.starlv, strongCfg); strongDict.Add(strongCfg.pos, dic); } } }
private void InitStrongCfg(string path) { XmlNodeList nodList = null; if (TryGetRootNodeList(path, out nodList)) { for (int i = 0; i < nodList.Count; i++) { XmlElement ele = nodList[i] as XmlElement; if (ele.GetAttributeNode("ID") == null) { continue; } int ID = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText); StrongCfg sd = new StrongCfg() { ID = ID }; foreach (XmlElement e in nodList[i].ChildNodes) { int val = int.Parse(e.InnerText); switch (e.Name) { case "pos": sd.pos = val; break; case "starlv": sd.starlv = val; break; case "addhp": sd.addhp = val; break; case "addhurt": sd.addhurt = val; break; case "adddef": sd.adddef = val; break; case "minlv": sd.minlv = val; break; case "coin": sd.coin = val; break; case "crystal": sd.crystal = val; break; } } Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(sd.pos, out dic)) { dic.Add(sd.starlv, sd); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(sd.starlv, sd); strongDic.Add(sd.pos, dic); } } } }
public void ReqStrong(MsgPack pack) { ReqStrong data = (ReqStrong)pack.msg; RspStrong msg = new RspStrong(); PlayerData pd = cacheSvc.GetPlayerDataBySession(pack.session); int curtStartLv = pd.StrongArr[data.Pos]; StrongCfg nextSd = CfgSvc.Instance.GetStrongCfg(data.Pos, curtStartLv + 1); //条件判断 if (pd.Lv < nextSd.minlv) { msg.error = (int)ErrorCode.LackLevel; } else if (pd.Coin < nextSd.coin) { msg.error = (int)ErrorCode.LackCoin; } else if (pd.Crystal < nextSd.crystal) { msg.error = (int)ErrorCode.LackCrystal; } else { //任务进度数据更新 TaskSys.Instance.CalcTaskPrgs(pd, 3); //资源扣除 pd.Coin -= nextSd.coin; pd.Crystal -= nextSd.crystal; pd.StrongArr[data.Pos] += 1; //增加属性 pd.Hp += nextSd.addhp; pd.Ad += nextSd.addhurt; pd.Ap += nextSd.addhurt; pd.Addef += nextSd.adddef; pd.Apdef += nextSd.adddef; } //更新数据库 if (!cacheSvc.UpdatePlayerData(pd.Id, pd)) { msg.error = (int)ErrorCode.UpdateDBError; } else { msg = new RspStrong { Coin = pd.Coin, Crystal = pd.Crystal, Hp = pd.Hp, Ad = pd.Ad, Ap = pd.Ap, Addef = pd.Addef, Apdef = pd.Apdef, }; msg.StrongArr.SetRepeated <int>(pd.StrongArr); } pack.session.SendMsg(msg); }
private void InitStrongCfg() { string xml = DeSerializeXML(PathDefine.StrongCfg); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeList nodeList = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodeList.Count; i++) { XmlElement ele = nodeList[i] as XmlElement; if (ele.GetAttribute("ID") == null) { continue; } int ID = int.Parse(ele.GetAttributeNode("ID").InnerText); StrongCfg sc = new StrongCfg { ID = ID }; foreach (XmlElement e in nodeList[i].ChildNodes) { int val = int.Parse(e.InnerText); switch (e.Name) { case "pos": sc.pos = val; break; case "starlv": sc.starLv = val; break; case "addhp": sc.addHp = val; break; case "adddef": sc.addDef = val; break; case "minlv": sc.minLv = val; break; case "coin": sc.coin = val; break; case "crystal": sc.crystal = val; break; case "addhurt": sc.addHurt = val; break; } } Dictionary <int, StrongCfg> dic = null; if (strongCfgDic.TryGetValue(sc.pos, out dic)) { dic.Add(sc.starLv, sc); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(sc.starLv, sc); strongCfgDic.Add(sc.pos, dic); } } }
public void ReqStrong(MsgPack pack) { ReqStrong data = pack.msg.reqStrong; GameMsg msg = new GameMsg { cmd = (int)CMD.RspStrong, }; PlayerData pd = CacheSvc.Instance.GetPlayerDataBySession(pack.session); int curStarlv = pd.strongArr[data.pos]; StrongCfg nextsd = CfgSvc.Instance.GetStrongCfg(data.pos, curStarlv + 1); //判断资源是否足够 if (pd.lv < nextsd.minlv) { msg.err = (int)ErrorCode.LackLevel; } else if (pd.coin < nextsd.coin) { msg.err = (int)ErrorCode.LackCoin; } else if (pd.crystal < nextsd.crystal) { msg.err = (int)ErrorCode.LackCrystal; } else { //资源扣除 pd.coin -= nextsd.coin; pd.crystal -= nextsd.crystal; //增加属性 pd.strongArr[data.pos] += 1; pd.hp += nextsd.addhp; pd.ad += nextsd.addhurt; pd.ap += nextsd.addhurt; pd.addef += nextsd.adddef; pd.apdef += nextsd.adddef; //更新任务进度数据 TaskSys.Instance.CalcTaskPrgs(pd, 3); if (!CacheSvc.Instance.UpdatePlayerData(pd.id, pd, pack.session)) { msg.err = (int)ErrorCode.UpdateDBError; } else { msg.rspStrong = new RspStrong { coin = pd.coin, crystal = pd.crystal, hp = pd.hp, ad = pd.ad, ap = pd.ap, addef = pd.addef, apdef = pd.apdef, strongArr = pd.strongArr }; } } pack.session.SendMsg(msg); }
private void RefreshItem() { // 金币 SetText(txtCoin, playerData.coin); switch (currentIndex) { case 0: SetSprite(imgCurPos, PathDefine.ItemToukui); break; case 1: SetSprite(imgCurPos, PathDefine.ItemBody); break; case 2: SetSprite(imgCurPos, PathDefine.ItemYaobu); break; case 3: SetSprite(imgCurPos, PathDefine.ItemHand); break; case 4: SetSprite(imgCurPos, PathDefine.ItemLeg); break; case 5: SetSprite(imgCurPos, PathDefine.ItemFoot); break; } int curStarLv = playerData.strongArr[currentIndex]; SetText(txtStarLv, "- " + curStarLv + "星级"); for (int i = 0; i < starTransGrid.childCount; i++) { Image img = starTransGrid.GetChild(i).GetComponent <Image>(); if (i < curStarLv) { SetSprite(img, PathDefine.SpStar2); } else { SetSprite(img, PathDefine.SpStar1); } } int nextStarLv = curStarLv + 1; int sumAddHp = resSvc.GetPropAddValPreLv(currentIndex, nextStarLv, 1); int sumAddHurt = resSvc.GetPropAddValPreLv(currentIndex, nextStarLv, 2); int sumAddDef = resSvc.GetPropAddValPreLv(currentIndex, nextStarLv, 3); SetText(propHP1, "+" + sumAddHp); SetText(propHurt1, "+" + sumAddHurt); SetText(propDef1, "+" + sumAddDef); nextSc = resSvc.GetStrongCfg(currentIndex, nextStarLv); if (nextSc != null) { SetActive(propHP2, true); SetActive(propHurt2, true); SetActive(propDef2, true); SetActive(costTransRoot, true); SetActive(propArr1, true); SetActive(propArr2, true); SetActive(propArr3, true); SetText(propHP2, "强化后 +" + nextSc.addhp); SetText(propHurt2, "强化后 +" + nextSc.addhurt); SetText(propDef2, "强化后 +" + nextSc.adddef); SetText(txtNeedLv, "- 需要等级 :" + nextSc.minlv); SetText(txtCostCoin, nextSc.coin); SetText(txtCostCrystal, nextSc.crystal + "/" + playerData.crystal); } else { SetActive(propHP2, false); SetActive(propHurt2, false); SetActive(propDef2, false); SetActive(costTransRoot, false); SetActive(propArr1, false); SetActive(propArr2, false); SetActive(propArr3, false); } }
private void InitStrongCfg() { XmlDocument doc = new XmlDocument(); doc.Load(@"D:\UNITY\DarkGod\Assets\Resources\ResCfgs\strong.xml"); XmlNodeList nodLst = doc.SelectSingleNode("root")?.ChildNodes; for (int i = 0; i < nodLst?.Count; i++) { XmlElement ele = nodLst[i] as XmlElement; if (ele != null && ele.GetAttributeNode("ID") == null) { continue; } if (ele != null) { int id = Convert.ToInt32(ele.GetAttributeNode("ID")?.InnerText); StrongCfg strongCfg = new StrongCfg { Id = id }; foreach (XmlElement e in nodLst[i].ChildNodes) { int val = int.Parse(e.InnerText); switch (e.Name) { case "pos": strongCfg.Pos = val; break; case "starlv": strongCfg.StartLevel = val; break; case "addhp": strongCfg.AddHp = val; break; case "addhurt": strongCfg.AddHurt = val; break; case "adddef": strongCfg.AddDefense = val; break; case "minlv": strongCfg.MinLevel = val; break; case "coin": strongCfg.Coin = val; break; case "crystal": strongCfg.Crystal = val; break; } } if (strongDictionary.TryGetValue(strongCfg.Pos, out var dic)) { dic.Add(strongCfg.StartLevel, strongCfg); } else { dic = new Dictionary <int, StrongCfg> { { strongCfg.StartLevel, strongCfg } }; strongDictionary.Add(strongCfg.Pos, dic); } } } PeRoot.Log("StrongCfg Init Done.||强化数据配置."); }
public void InitStrongCfg() { XmlDocument doc = new XmlDocument(); doc.Load(@"G:\Unity Projects\ARPG\Assets\Resources\ResCfgs\strong.xml"); XmlNodeList nodeList = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodeList.Count; i++) { XmlElement ele = nodeList[i] as XmlElement; if (ele.GetAttributeNode("ID") == null) { continue; } int ID = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText); StrongCfg strongCfg = new StrongCfg { ID = ID, }; foreach (XmlElement item in ele.ChildNodes) { switch (item.Name) { case "pos": strongCfg.pos = int.Parse(item.InnerText); break; case "starlv": strongCfg.startlv = int.Parse(item.InnerText); break; case "addhp": strongCfg.addhp = int.Parse(item.InnerText); break; case "adddef": strongCfg.adddef = int.Parse(item.InnerText); break; case "addhurt": strongCfg.addhurt = int.Parse(item.InnerText); break; case "minlv": strongCfg.minlv = int.Parse(item.InnerText); break; case "coin": strongCfg.coin = int.Parse(item.InnerText); break; case "crystal": strongCfg.crystal = int.Parse(item.InnerText); break; } } Dictionary <int, StrongCfg> dic = null; if (strongCfgDic.TryGetValue(strongCfg.pos, out dic)) { dic.Add(strongCfg.startlv, strongCfg); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(strongCfg.startlv, strongCfg); strongCfgDic.Add(strongCfg.pos, dic); } } PECommon.Log("StrongCfg Init Done"); }
//刷新数据 private void RefreshItem() { //金币 SetText(txtCoin, m_pd.coin); switch (m_curtIndex) { case 0: SetSprite(imgCurtPos, PathDefine.ItemToukui); break; case 1: SetSprite(imgCurtPos, PathDefine.ItemBody); break; case 2: SetSprite(imgCurtPos, PathDefine.ItemYaobu); break; case 3: SetSprite(imgCurtPos, PathDefine.ItemHand); break; case 4: SetSprite(imgCurtPos, PathDefine.ItemLeg); break; case 5: SetSprite(imgCurtPos, PathDefine.ItemFoot); break; } SetText(txtStarLv, m_pd.strongArr[m_curtIndex] + "星级"); int curtStarLv = m_pd.strongArr[m_curtIndex]; //星级图片 for (int i = 0; i < starTransGrp.childCount; i++) { Image img = starTransGrp.GetChild(i).GetComponent <Image>(); if (i < curtStarLv) { SetSprite(img, PathDefine.SpStar2); } else { SetSprite(img, PathDefine.SpStar1); } } //查询 位置 星级 的属性 int sumAddHp = resSvc.GetPropAddValPreLv(m_curtIndex, curtStarLv, 1); int sumAddHurt = resSvc.GetPropAddValPreLv(m_curtIndex, curtStarLv, 2); int sumAddDef = resSvc.GetPropAddValPreLv(m_curtIndex, curtStarLv, 3); SetText(propHp1, "生命" + sumAddHp); SetText(propHurt1, "伤害" + sumAddHurt); SetText(propDef1, "防御" + sumAddDef); int nextStarLv = curtStarLv + 1; nextSc = resSvc.GetStrongCfgData(m_curtIndex, nextStarLv); if (nextSc != null) { //显示“强化后”加成内容 SetActive(costInfoTrans); SetActive(propArr1); SetActive(propArr2); SetActive(propArr3); SetActive(propHp2); SetActive(propHurt2); SetActive(propDef2); //强化后属性加成 SetText(propHp2, "强化后+" + nextSc.addhp); SetText(propHurt2, "强化后+" + nextSc.addhurt); SetText(propDef2, "强化后+" + nextSc.adddef); //强化条件提示 SetText(txtNeedLv, "需要等级" + nextSc.minlv); SetText(txtCostCoin, "需要消耗: " + nextSc.coin); SetText(txtCostCrystal, m_pd.crystal + "/" + nextSc.crystal); } else { //满级 //隐藏“强化后”加成内容 SetActive(costInfoTrans, false); SetActive(propArr1, false); SetActive(propArr2, false); SetActive(propArr3, false); SetActive(propHp2, false); SetActive(propHurt2, false); SetActive(propDef2, false); } }
private void InitStrongCfg() { XmlDocument doc = new XmlDocument(); doc.Load(@"D:\Unity Project Workspace\Dark God\Assets\Resources\ResCfgs\strong.xml"); XmlNodeList nodLst = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodLst.Count; i++) { XmlElement ele = nodLst[i] as XmlElement; if (ele.GetAttributeNode("ID") == null) { continue; } int ID = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText); StrongCfg sd = new StrongCfg { ID = ID }; foreach (XmlElement e in nodLst[i].ChildNodes) { int val = int.Parse(e.InnerText); switch (e.Name) { case "pos": sd.pos = val; break; case "starlv": sd.startlv = val; break; case "addhp": sd.addhp = val; break; case "addhurt": sd.addhurt = val; break; case "adddef": sd.adddef = val; break; case "minlv": sd.minlv = val; break; case "coin": sd.coin = val; break; case "crystal": sd.crystal = val; break; } } Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(sd.pos, out dic)) { dic.Add(sd.startlv, sd); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(sd.startlv, sd); strongDic.Add(sd.pos, dic); } } PECommon.Log("StrongCfg Init Done."); }
/// <summary> /// 更新UI /// </summary> public void RefreshItemUI() { playerData = GameRoot.Instance.PlayerData; //设置总金币数 SetText(txtOwnCoin, playerData.coin); //设置当前选中装备图片 switch (currentIndex) { case 0: SetImage(curPosImage, PathDefine.ImageHead); break; case 1: SetImage(curPosImage, PathDefine.ImageBody); break; case 2: SetImage(curPosImage, PathDefine.ImageWaist); break; case 3: SetImage(curPosImage, PathDefine.ImageHand); break; case 4: SetImage(curPosImage, PathDefine.ImageLeg); break; case 5: SetImage(curPosImage, PathDefine.ImageFoot); break; } int curStarLv = playerData.strongArr[currentIndex]; //设置星级 SetText(txtStar, curStarLv + "星级"); for (int i = 0; i < starGroupTrans.childCount; i++) { Image img = starGroupTrans.GetChild(i).GetComponent <Image>(); if (i < curStarLv) { SetImage(img, PathDefine.yellowStar); } else { SetImage(img, PathDefine.whiteStar); } } //获取当前等级装备的信息 StrongCfg curStrongCfg = resSvc.GetStrongCfg(currentIndex, curStarLv); //当前装备星级为0 if (curStrongCfg == null) { SetText(txtCurPlusHp, "生命 +0"); SetText(txtCurPlusAttk, "伤害 +0"); SetText(txtCurPlusDefence, "防御 +0"); } else { int addHp = resSvc.GetPropAddPreLv(currentIndex, curStarLv, 1); int addAttk = resSvc.GetPropAddPreLv(currentIndex, curStarLv, 2); int addDef = resSvc.GetPropAddPreLv(currentIndex, curStarLv, 3); SetText(txtCurPlusHp, "生命 +" + addHp); SetText(txtCurPlusAttk, "伤害 +" + addAttk); SetText(txtCurPlusDefence, "防御 +" + addDef); } //获取下个等级装备信息 int nextStarLv = curStarLv + 1; nextStrongCfg = resSvc.GetStrongCfg(currentIndex, nextStarLv); //为空 说明已经到了最大等级 if (nextStrongCfg == null) { //隐藏升级后的相关信息 SetActive(conditionTrans, false); SetActive(propHpArrow, false); SetActive(propAttkArrow, false); SetActive(propDefArrow, false); SetActive(txtAfterStrong, false); SetActive(txtStrongPlusHp, false); SetActive(txtStrongPlusAttk, false); SetActive(txtStrongPlusDefence, false); } else { SetActive(conditionTrans); SetActive(propHpArrow); SetActive(propAttkArrow); SetActive(propDefArrow); SetActive(txtAfterStrong); SetActive(txtStrongPlusHp); SetActive(txtStrongPlusAttk); SetActive(txtStrongPlusDefence); SetText(txtStrongPlusHp, "+" + resSvc.GetPropAddPreLv(currentIndex, nextStarLv, 1)); SetText(txtStrongPlusAttk, "+" + resSvc.GetPropAddPreLv(currentIndex, nextStarLv, 2)); SetText(txtStrongPlusDefence, "+" + resSvc.GetPropAddPreLv(currentIndex, nextStarLv, 3)); SetText(txtNeedCoin, nextStrongCfg.coin); SetText(txtNeedLv, "需要等级:" + nextStrongCfg.minlv); SetText(txtNeedMaterial, nextStrongCfg.crystal + "/" + playerData.crystal); } }
/// <summary> /// 回应强化请求 /// </summary> public void ReqStrong(PackMsg pack) { ReqStrong data = pack.msg.reqStrong; ServerSession session = pack.session; GameMsg msg = new GameMsg { cmd = (int)CMD.RspStrong, }; PlayerData playerData = cacheSvc.GetPlayerDataCache(session); if (playerData.strongArr[data.pos] == data.starlv) { int nextStarLv = data.starlv + 1; StrongCfg nextStrongCfg = cfgSvc.GetStrongCfg(data.pos, nextStarLv); if (playerData.lv < nextStrongCfg.minlv) { msg.err = (int)ErrorCode.LackLevel; } else if (playerData.coin < nextStrongCfg.coin) { msg.err = (int)ErrorCode.LackCoin; } else if (playerData.crystal < nextStrongCfg.crystal) { msg.err = (int)ErrorCode.LackCrystal; } else { //更新任务进度 PshTaskProgs pshTaskProgs = TaskSys.Instance.CalcTaskProgs(playerData, 3); playerData.hp += nextStrongCfg.addhp; playerData.ad += nextStrongCfg.addhurt; playerData.ap += nextStrongCfg.addhurt; playerData.addef += nextStrongCfg.adddef; playerData.apdef += nextStrongCfg.adddef; playerData.strongArr[data.pos] += 1; playerData.coin -= nextStrongCfg.coin; playerData.crystal -= nextStrongCfg.crystal; if (!cacheSvc.UpdatePlayerData(playerData.id, playerData)) { msg.err = (int)ErrorCode.UpdateDBError; } else { RspStrong rspStrong = new RspStrong { pos = nextStrongCfg.pos, starlv = nextStrongCfg.starlv, addhp = nextStrongCfg.addhp, addhurt = nextStrongCfg.addhurt, adddef = nextStrongCfg.adddef, minlv = nextStrongCfg.minlv, coin = nextStrongCfg.coin, crystal = nextStrongCfg.crystal, strongArr = playerData.strongArr }; msg.rspStrong = rspStrong; if (pshTaskProgs != null) { msg.pshTaskProgs = pshTaskProgs; } } } } else { msg.err = (int)ErrorCode.ServerDataError; } pack.session.SendMsg(msg); }
public void ReqStrong(MsgPack pack) { ReqStrong data = pack.msg.reqStrong; GameMsg msg = new GameMsg { //消息类型 cmd = (int)CMD.RspStrong, }; PlayerData pd = cacheSvc.GetPlayerDataBySession(pack.session); StrongCfg nextSc = cfgSvc.GetStrongCfgData(data.pos, pd.strongArr[data.pos] + 1); if (nextSc == null) { //错误码:满星 msg.err = (int)ErrorCode.MaxStar; } else if (pd.lv < nextSc.minlv) { //错误码:等级不够 msg.err = (int)ErrorCode.LackLevel; } else if (pd.coin < nextSc.coin) { //错误码:金币不够 msg.err = (int)ErrorCode.LackCoin; } else if (pd.crystal < nextSc.crystal) { //错误码:水晶不够 msg.err = (int)ErrorCode.LackCrystal; } else { //任务进度数据更新 TaskSys.Instance.CalcTaskPrgs(pd, 3); //满足条件 //消耗金币和水晶 pd.coin -= nextSc.coin; pd.crystal -= nextSc.crystal; //增加属性 pd.hp += nextSc.addhp; pd.ad += nextSc.addhurt; pd.ap += nextSc.addhurt; pd.addef += nextSc.adddef; pd.apdef += nextSc.adddef; pd.strongArr[data.pos] += 1; if (DBMgr.Instance.UpdatePlayerData(pd.id, pd)) { //发送协议更新客户端内容 msg.rspStrong = new RspStrong { coin = pd.coin, crystal = pd.crystal, hp = pd.hp, ad = pd.ad, ap = pd.ap, addef = pd.addef, apdef = pd.apdef, strongArr = pd.strongArr, }; } else { msg.err = (int)ErrorCode.UpdateDBError; } } pack.session.SendMsg(msg); }
public void ReqStrong(MsgPack pack) { ReqStrong data = pack.Msg.reqStrong; GameMsg msg = new GameMsg() { cmd = (int)CMD.RspStrong }; PlayerData pd = cacheSvc.GetPlayerDataBySession(pack.Session); int currentStarLv = pd.strongArr[data.pos]; StrongCfg nextStrongCfg = CfgSvc.Instance.GetStrongCfg(data.pos, currentStarLv + 1); //条件判断 if (pd.lv < nextStrongCfg.minLv) { msg.err = (int)ErrorCode.LackLevel; } else if (pd.coin < nextStrongCfg.coin) { msg.err = (int)ErrorCode.LackCoin; } else if (pd.crystal < nextStrongCfg.crystal) { msg.err = (int)ErrorCode.LackCrystal; } else { //任务进度数据更新 TaskSys.Instance.CalcTaskPrgs(pd, 3); //资源扣除 pd.coin -= nextStrongCfg.coin; pd.crystal -= nextStrongCfg.crystal; //星级+1 pd.strongArr[data.pos] += 1; //增加属性 pd.hp += nextStrongCfg.addhp; pd.ad += nextStrongCfg.addhurt; pd.ap += nextStrongCfg.addhurt; pd.addef += nextStrongCfg.adddef; pd.apdef += nextStrongCfg.adddef; } //更新数据库 if (!cacheSvc.UpdatePlayerData(pd.id, pd)) { msg.err = (int)ErrorCode.UpdateDBError; } else { msg.rspStrong = new RspStrong() { coin = pd.coin, crystal = pd.crystal, hp = pd.hp, ad = pd.ad, ap = pd.ap, addef = pd.addef, apdef = pd.apdef, strongArr = pd.strongArr }; } pack.Session.SendMsg(msg); }
private void InitStrongCfg() { XmlDocument doc = new XmlDocument(); doc.Load(@"D:\WENJIAN\Unity\Projects\DarkGod\Client\Assets\Resources\ResCfgs\strong.xml"); XmlNodeList nodLst = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodLst.Count; i++) { XmlElement ele = nodLst[i] as XmlElement; if (ele.GetAttributeNode("ID") == null) { continue; } int id = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText); StrongCfg sc = new StrongCfg { ID = id }; foreach (XmlElement e in nodLst[i].ChildNodes) { int inner = int.Parse(e.InnerText); switch (e.Name) { case "pos": sc.pos = inner; break; case "starlv": sc.starlv = inner; break; case "addhp": sc.addhp = inner; break; case "addhurt": sc.addhurt = inner; break; case "adddef": sc.adddef = inner; break; case "minlv": sc.minlv = inner; break; case "coin": sc.coin = inner; break; case "crystal": sc.crystal = inner; break; } } Dictionary <int, StrongCfg> dic = null; if (strongDic.TryGetValue(sc.pos, out dic)) { dic.Add(sc.starlv, sc); } else { dic = new Dictionary <int, StrongCfg>(); dic.Add(sc.starlv, sc); strongDic.Add(sc.pos, dic); } } }