private void OnEnterMainCity() { NETCommon.Log("Enter MainCity..."); // 打开主城场景UI mainCityWindow.SetWindowState(); // 播放主城背景音乐 audioSev.PlayBGM(Constans.MainCityBGM); GameObject map = GameObject.FindGameObjectWithTag("MapRoot"); MainCityMap cityMap = map.GetComponent <MainCityMap>(); npcPosTrans = cityMap.NPCPosTrans; MapCfg mapData = resSev.GetMapCfgData(Constans.MainCityID); // 加载游戏主角 LoadPlayer(mapData); // 设置角色展示相机 if (charShowCamTrans != null) { charShowCamTrans.gameObject.SetActive(false); } }
public static T DeSerizlizeToObject_GZip <T>(byte[] buffer) { try { byte[] deCompressBuffer = null; using (MemoryStream inputMS = new MemoryStream(buffer)) { using (MemoryStream outputMS = new MemoryStream()) { using (GZipStream gzs = new GZipStream(inputMS, CompressionMode.Decompress, true)) { byte[] bytes = new byte[1024]; int len = 0; while ((len = gzs.Read(bytes, 0, bytes.Length)) > 0) { outputMS.Write(bytes, 0, len); } gzs.Close(); deCompressBuffer = outputMS.ToArray(); } } } using (MemoryStream ms = new MemoryStream(deCompressBuffer)) { BinaryFormatter bf = new BinaryFormatter(); return((T)bf.Deserialize(ms)); } } catch (Exception e) { NETCommon.Log("反序列失败: " + e, NETLogLevel.Error); return(default(T)); } }
public bool QueryNameData(string name) { bool exit = false; MySqlDataReader reader = null; try { MySqlCommand cmd = new MySqlCommand("select * from account where name=@name", conn); cmd.Parameters.AddWithValue("name", name); reader = cmd.ExecuteReader(); if (reader.Read()) { exit = true; } } catch (Exception e) { NETCommon.Log("Query Name Data Error: " + e, NETLogLevel.Error); } finally { if (reader != null) { reader.Close(); } } return(exit); }
private string DeSerializeXML(string path) { if (string.IsNullOrEmpty(path)) { return(null); } TextAsset textAsset = Resources.Load <TextAsset>(path); if (textAsset == null) { NETCommon.Log("未加载到配置文件,Path: " + path); return(null); } byte[] bytes = textAsset.bytes; using (MemoryStream rms = new MemoryStream(bytes)) { using (MemoryStream ms = new MemoryStream()) { using (GZipStream gzs = new GZipStream(rms, CompressionMode.Decompress, true)) { byte[] buffer = new byte[1024]; int len = 0; while ((len = gzs.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, len); } return(Encoding.UTF8.GetString(ms.ToArray())); } } } }
public void Init() { conn = new MySqlConnection("server=localhost;userid=root;password=;database=arpg;charset=utf8"); conn.Open(); NETCommon.Log(conn.Database); NETCommon.Log("DBMgr Init Done"); }
public void Init() { InitAutoGuidCfg(); InitStrongCfg(); InitFilterWordCfg(); InitTaskCfg(); InitMapCfg(); NETCommon.Log("CfgSev Init Done"); }
public TaskRewardCfg GetTaskRewardCfg(int id) { TaskRewardCfg cfg = null; if (taskRewardCfgDic.TryGetValue(id, out cfg)) { return(cfg); } NETCommon.Log("获取 TaskRewardCfg 失败,ID:" + id); return(null); }
public MonsterCfg GetMonsterCfg(int id) { MonsterCfg cfg = null; if (monsterCfgDic.TryGetValue(id, out cfg)) { return(cfg); } NETCommon.Log("获取 MonsterCfg 失败,ID:" + id); return(null); }
public SkillActionCfg GetSkillActionCfg(int id) { SkillActionCfg cfg = null; if (skillActionCfgDic.TryGetValue(id, out cfg)) { return(cfg); } NETCommon.Log("获取 SkillActionCfg 失败,ID:" + id); return(null); }
public MapCfg GetMapCfgData(int id) { if (mapCfgDic.ContainsKey(id)) { return(mapCfgDic[id]); } else { NETCommon.Log("MapCfg获取失败", NETLogLevel.Error); return(null); } }
public void ReqLogin(MsgPack pack) { ReqLogin data = pack.msg.reqLogin; // 判断当前账号是否已经上线 GameMsg msg = new GameMsg { cmd = (int)CMD.RspLogin, rspLogin = new RspLogin() }; // 已上线:返回错误信息 if (cacheSev.IsAccountOnline(data.account)) { msg.err = (int)ErrorCode.AccountIsOnline; } else // 未上线: { // 账号是否存在并检测密码 PlayerData pd = cacheSev.GetPlayerData(data.account, data.pass); if (pd == null) { msg.err = (int)ErrorCode.WrongPass; } else { int power = pd.power; long milliseconds = timeSev.GetNowTime() - pd.time; int addPower = (int)(milliseconds / (1000 * 60 * NETCommon.PowerAddSpace)) * NETCommon.PowerAddCount; if (addPower > 0) { int powerMax = NETCommon.GetPowerLimit(pd.lv); int targetPower = pd.power + addPower; pd.power = pd.power < powerMax ? (targetPower > powerMax ? powerMax : targetPower) : powerMax; } if (power != pd.power) { cacheSev.UpdatePlayerData(pd); } msg.rspLogin = new RspLogin { playerData = pd }; // 缓存账号数据 cacheSev.CacheAccountOnline(data.account, pack.session, pd); } } // 回应客户端 pack.session.SendMsg(msg); }
public bool AcctOffLine(ServerSession session) { bool suc = true; string act = onlineAccountReversDic[session]; suc = suc ? onlineAccountDic.Remove(act) : false; suc = suc ? onlineAccountReversDic.Remove(session) : false; suc = suc ? onlineSessionDic.Remove(session) : false; if (!suc) { NETCommon.Log("Clear Cahce Error", NETLogLevel.Error); } return(suc); }
public override void InitSys() { base.InitSys(); NETCommon.Log("Init MainCitySys"); mainCityWindow = GetWindow <MainCityWindow>("MainCityWindow"); infoWindow = GetWindow <InfoWindow>("InfoWindow"); guidWindow = GetWindow <GuidWindow>("GuidWindow"); strongWindow = GetWindow <StrongWindow>("StrongWindow"); chatWindow = GetWindow <ChatWindow>("ChatWindow"); buyWindow = GetWindow <BuyWindow>("BuyWindow"); taskWindow = GetWindow <TaskWindow>("TaskWindow"); }
public AutoGuideCfg GetAutoGuidCfg(int id) { AutoGuideCfg cfg = null; if (autoGuidDic.TryGetValue(id, out cfg)) { return(cfg); } else { NETCommon.Log("AutoGuideCfg 获取失败", NETLogLevel.Error); return(null); } }
public void ClearCache(ServerSession session) { PlayerData pd = cacheSev.GetPlayerDataBySession(session); if (pd != null) { pd.time = timeSev.GetNowTime(); if (!cacheSev.UpdatePlayerData(pd)) { NETCommon.Log("Update Offline time Error", NETLogLevel.Error); } } cacheSev.AcctOffLine(session); }
public void ReqGuide(MsgPack pack) { ReqGuide data = pack.msg.reqGuide; GameMsg msg = new GameMsg { cmd = (int)CMD.RspGuided }; // 更新任务 ID PlayerData pd = cacheSev.GetPlayerDataBySession(pack.session); if (pd.guidid == data.guidID) { switch (pd.guidid) { case 1001: msg.pshTaskPrgs = TaskSystem.Instance.CalcTaskPrg(pd, 1); break; } pd.guidid += 1; // 更新玩家数据 AutoGuideCfg guidCfg = cfgSev.GetAutoGuidCfg(data.guidID); pd.coin += guidCfg.coin; NETCommon.CalcExp(pd, guidCfg.exp); if (!cacheSev.UpdatePlayerData(pd)) { msg.err = (int)ErrorCode.UpdateDBError; } else { msg.rspGuide = new RspGuide { guideid = pd.guidid, coin = pd.coin, lv = pd.lv, exp = pd.exp, addExp = guidCfg.exp }; } } else { msg.err = (int)ErrorCode.ServerDataError; } pack.session.SendMsg(msg); }
public static string XmlByteToStr(byte[] buffer) { string str = ""; try { str = Encoding.UTF8.GetString(buffer); } catch (Exception e) { NETCommon.Log("反序列失败: " + e, NETLogLevel.Error); } return(str); }
public int GetPRD_C(int p) { if (p > 100) { p = 100; } int c = -1; if (PRDDic.TryGetValue(p, out c)) { return(c); } NETCommon.Log("获取 PRD_C 失败,P:" + p); return(c); }
public static void XmlByteToXmlFile(string targetPath, byte[] buffer) { try { using (FileStream fs = new FileStream(targetPath, FileMode.Create)) { fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); } } catch (Exception e) { NETCommon.Log("反序列失败: " + e, NETLogLevel.Error); } }
public void RspStrong(GameMsg msg) { audioSev.PlayUIAudio(Constans.FBItem); int fight = NETCommon.GetFightByProps(GameRoot.Instance.PlayerData); GameRoot.Instance.SetPlayerDataByStrong(msg.rspStrong); int curFight = NETCommon.GetFightByProps(GameRoot.Instance.PlayerData); strongWindow.RefreshUI(); mainCityWindow.RefreshUI(); GameRoot.AddTips(Constans.ColorStr("战力提升:" + (curFight - fight), TxtColor.Blue)); if (msg.pshTaskPrgs != null) { PshTaskPrgs(msg); } }
public void RefreshUI() { PlayerData pd = GameRoot.Instance.PlayerData; SetText(txtFight, NETCommon.GetFightByProps(pd)); int powerLimit = NETCommon.GetPowerLimit(pd.lv); SetText(txtPower, "体力:" + pd.power + "/" + powerLimit); imgPowerPrg.fillAmount = pd.power * 1.0f / powerLimit; SetText(txtLevel, pd.lv); SetText(txtName, pd.name); #region ExpPrg int expPrgVal = (int)(pd.exp * 1.0f / NETCommon.GetExpUpValByLv(pd.lv) * 100); SetText(txtExpPrg, expPrgVal + "%"); int index = expPrgVal / 10; float globalRate = 1f * Constans.ScreenStandardHeight / Screen.height; float screenWidth = globalRate * Screen.width; float itemWidht = (screenWidth - 181f) / 10f; expGridGroup.cellSize = new Vector2(itemWidht, 7f); for (int i = 0; i < expItems.Length; i++) { Image item = expItems[i]; if (i < index) { item.fillAmount = 1f; } else if (i == index) { item.fillAmount = (float)(expPrgVal % 10) / 10; } else { item.fillAmount = 0f; } } #endregion // 设置自动任务图标 curTaskData = resSev.GetAutoGuidCfg(pd.guidid); if (curTaskData != null) { SetGuideBtnIcon(curTaskData.npcID); } }
public static T XmlByteToObject <T>(byte[] buffer) { T data = default(T); try { using (MemoryStream ms = new MemoryStream(buffer)) { XmlSerializer xs = new XmlSerializer(typeof(T)); data = (T)xs.Deserialize(ms); } } catch (Exception e) { NETCommon.Log("反序列失败: " + e, NETLogLevel.Error); } return(data); }
public static byte[] SerializeToObjectByte <T>(T data) { byte[] buffer = null; try { using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms, data); buffer = ms.ToArray(); } } catch (Exception e) { NETCommon.Log("序列化失败: " + e, NETLogLevel.Error); } return(buffer); }
public static byte[] SerializeToXmlByte <T>(T data) { byte[] buffer = null; try { XmlSerializer xs = new XmlSerializer(typeof(T)); using (MemoryStream ms = new MemoryStream()) { xs.Serialize(ms, data); buffer = ms.ToArray(); } } catch (Exception e) { NETCommon.Log("序列化失败: " + e, NETLogLevel.Error); } return(buffer); }
public static T DeSerializeToObject <T>(byte[] buffer) { T data = default(T); using (MemoryStream rs = new MemoryStream(buffer)) { BinaryFormatter bf = new BinaryFormatter(); try { data = (T)bf.Deserialize(rs); } catch (Exception e) { NETCommon.Log("反序列化失败: " + e, NETLogLevel.Error); } } return(data); }
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 CalcPowerAdd(int id) { GameMsg msg = new GameMsg { cmd = (int)CMD.PshPower, pshPower = new PshPower() }; // 向所有在线玩家推送 Dictionary <ServerSession, PlayerData> onlineDic = cacheSev.GetOnlinePlayers(); foreach (var pair in onlineDic) { PlayerData pd = pair.Value; ServerSession session = pair.Key; int powerMax = NETCommon.GetPowerLimit(pd.lv); if (pd.power >= powerMax) { continue; } pd.power += NETCommon.PowerAddCount; if (pd.power > powerMax) { pd.power = powerMax; } pd.time = timeSev.GetNowTime(); if (!cacheSev.UpdatePlayerData(pd)) { msg.err = (int)ErrorCode.UpdateDBError; } else { msg.pshPower.power = pd.power; } session.SendMsg(msg); } }
public static byte[] SerializeToObjectByte_GZip <T>(T data) { try { byte[] buffer = SerializeToObjectByte(data); using (MemoryStream ms = new MemoryStream()) { using (GZipStream gzs = new GZipStream(ms, CompressionMode.Compress, true)) { gzs.Write(buffer, 0, buffer.Length); gzs.Close(); return(ms.ToArray()); } } } catch (Exception e) { NETCommon.Log("序列化失败: " + e, NETLogLevel.Error); return(null); } }
public void ReqTakeTaskReward(MsgPack pack) { ReqTakeTaskReward data = pack.msg.reqTakeTask; GameMsg msg = new GameMsg { cmd = (int)CMD.RspTakeTaskReward }; PlayerData pd = cacheSev.GetPlayerDataBySession(pack.session); TaskRewardCfg cfg = cfgService.GetTaskRewardCfg(data.id); TaskRewardData trd = CalcTaskRewardData(pd, data.id); if (trd.prgs != cfg.count || trd.take) { msg.err = (int)ErrorCode.TakeTaskError; pack.session.SendMsg(msg); return; } pd.coin += cfg.coin; NETCommon.CalcExp(pd, cfg.exp); trd.take = true; CalcTaskArr(pd, trd); if (!cacheSev.UpdatePlayerData(pd)) { msg.err = (int)ErrorCode.UpdateDBError; pack.session.SendMsg(msg); return; } msg.rspTakeTask = new RspTakeTaskReward { coin = pd.coin, exp = pd.exp, lv = pd.lv, taskArr = pd.taskArr }; pack.session.SendMsg(msg); }
public void RefreshUI() { PlayerData pd = GameRoot.Instance.PlayerData; SetText(txtLevel, pd.lv); SetText(txtName, pd.name); hp = pd.hp; SetText(txtHp, string.Format("{0}/{1}", hp, hp)); imgHp.fillAmount = 1f; #region ExpPrg int expPrgVal = (int)(pd.exp * 1.0f / NETCommon.GetExpUpValByLv(pd.lv) * 100); SetText(txtExpPrg, expPrgVal + "%"); int index = expPrgVal / 10; float globalRate = 1f * Constans.ScreenStandardHeight / Screen.height; float screenWidth = globalRate * Screen.width; float itemWidht = (screenWidth - 181f) / 10f; expGridGroup.cellSize = new Vector2(itemWidht, 7f); for (int i = 0; i < expItems.Length; i++) { Image item = expItems[i]; if (i < index) { item.fillAmount = 1f; } else if (i == index) { item.fillAmount = (float)(expPrgVal % 10) / 10; } else { item.fillAmount = 0f; } } #endregion }