void OnLogin(IoBuffer s) { bool ret = s.ReadBool(); Debuger.LogError("登录{0}", ret ? "成功" : "失败"); m_hero = new TestRole(); m_hero.Init(); bool needDeserialize = s.ReadBool(); if (needDeserialize) { m_hero.Deserialize(s); } }
void OnLevelFight(TestServerSocket socket, IoBuffer s) { IoBuffer outStream = socket.GetStream(); TestRole role = socket.m_hero; int levelId = s.ReadInt32(); TestLevelInfo levelInfo = role.m_levelPart.m_levelInfos.Get(levelId); //检查开没开启 if (levelInfo == null && levelId != 1 && role.m_levelPart.m_levelInfos.Get(levelId - 1) == null) { Debuger.LogError("关卡没有开启"); outStream.Write(false); socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, outStream); return; } //检查今天的挑战数 if (levelInfo != null && levelInfo.EnterCount >= 5) { Debuger.LogError("每天只能挑战5次"); outStream.Write(false); socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, outStream); return; } //挑战次数加一 if (levelInfo == null) { levelInfo = new TestLevelInfo(); levelInfo.levelId.Value = levelId; role.m_levelPart.m_levelInfos[levelId] = levelInfo; } levelInfo.star.Value = Mathf.Max((int)levelInfo.star, Random.Range(1, 3)); levelInfo.Add(); //给奖励,50金币,1把武器 role.m_propPart.Add(enTestProp.gold, 50); role.m_bagPart.Add(Random.Range(0, 2), 1); outStream.Write(true); socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, outStream); }