Exemple #1
0
        protected async override void Run(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply)
        {
            M2G_CreateUnit response = new M2G_CreateUnit();

            Log.Debug("请求");
            Model.Fishs.Entitys.Unit unit = ComponentFactory.Create <Model.Fishs.Entitys.Unit, UnitType>(UnitType.Hero);
            await unit.AddComponent <MailBoxComponent>().AddLocation();

            unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);
            unit.AddComponent <PlayerDbComponent, int>(message.AccountId);
            var initRet = await unit.GetComponent <PlayerDbComponent>().InitDataSync();

            if (initRet)
            {
                Log.Debug("unitId:" + unit.Id);
                Game.Scene.GetComponent <UnitManageComponent>().Add(unit);
            }
            response.Tag = 0;
            Log.Debug("数据库结束:" + unit.Id);
            response.UnitId = unit.Id;

            reply(response);

            count++;
        }
        protected async override void Run(Session session, C2S_UserLogin message, Action <S2C_UserLogin> reply)
        {
            S2C_UserLogin response = new S2C_UserLogin();

            //直接创建一个unit
            Model.Fishs.Entitys.Unit unit = ComponentFactory.Create <Model.Fishs.Entitys.Unit, UnitType>(UnitType.Hero);
            unit.AddComponent <MailBoxComponent>();
            unit.AddComponent <UnitGateComponent, long>(session.Id);
            unit.AddComponent <PlayerDbComponent, int>(message.AccountId);
            var initRet = await unit.GetComponent <PlayerDbComponent>().InitDataSync();

            if (initRet)
            {
                Log.Debug("unitId:" + unit.Id);
                Game.Scene.GetComponent <UnitManageComponent>().Add(unit);
            }
            response.Tag = 0;
            Log.Debug("数据库结束:" + unit.Id);
            session.AddComponent <SessionPlayerComponent>().Player = unit;
            response.UnitId = unit.Id;
            reply(response);
        }