/// <summary> /// 升级 机器人 /// </summary> private void DoUpRobot() { BaseRobotInfo robotInfo = RobotInfo.Instance.MainRobotInfo; bool isEnoughMoney = RobotInfo.Instance.Coin >= robotInfo.cost; if (isEnoughMoney) { RobotInfo.Instance.Coin -= robotInfo.cost; RobotType robotType = robotInfo.robotType; int newLevel = robotInfo.robotLevel + 1; //更新数据库 DataManager.Instance.SaveRobotLevel(robotType, newLevel); //更新robot数据 RobotInfo.Instance.MainRobotInfo = RobotInfo.Instance.LoadBaseRobotData(robotType, newLevel); UpdateRobotUI(); } else { //TODO } }
/// <summary> /// 获取机器人的基础数据(默认为0级) /// </summary> public BaseRobotInfo LoadBaseRobotData(RobotType type, int robotLevel = 0) { BaseRobotInfo data = null; if (!LoadedData.ContainsKey(type)) { data = LoadBaseRobotDataUtil(type, robotLevel); //缓存 LoadedData.Add(type, new Dictionary <int, BaseRobotInfo>()); LoadedData[type].Add(robotLevel, data); } else if (!LoadedData[type].ContainsKey(robotLevel)) { data = LoadBaseRobotDataUtil(type, robotLevel); //缓存 LoadedData[type].Add(robotLevel, data); } return(LoadedData[type][robotLevel]); }
private BaseRobotInfo LoadBaseRobotDataUtil(RobotType type, int robotLevel = 0) { BaseRobotInfo data = null; string key = ((int)type).ToString(); string robotName = RobotJsonData[key]["name"].ToString(); string resName = RobotJsonData[key]["res"].ToString(); string robotInfo = RobotJsonData[key]["info"].ToString(); int maxLevel = RobotJsonData[key]["attribute"].Count; int speed = (int)RobotJsonData[key]["attribute"][robotLevel]["speed"]; int maxHP = (int)RobotJsonData[key]["attribute"][robotLevel]["maxHP"]; int weapon = (int)RobotJsonData[key]["attribute"][robotLevel]["weapon"]; int defense = (int)RobotJsonData[key]["attribute"][robotLevel]["defense"]; int move = (int)RobotJsonData[key]["attribute"][robotLevel]["move"]; int other = (int)RobotJsonData[key]["attribute"][robotLevel]["other"]; int cost = (int)RobotJsonData[key]["attribute"][robotLevel]["cost"]; data = new BaseRobotInfo(type, resName, robotName, robotInfo, robotLevel, maxLevel, speed, maxHP, weapon, defense, move, other, cost); return(data); }