Пример #1
0
        private async ETVoid RunAsync(Session session, G2B_CreateTank message, Action <B2G_CreateTank> reply)
        {
            B2G_CreateTank response = new B2G_CreateTank();

            try
            {
                Battle battle = Game.Scene.GetComponent <BattleComponent>().Get(message.BattleId);

                // 随机生成一辆坦克,id和instanceId不相等
                Tank tank = ComponentFactory.CreateWithId <Tank>(IdGenerater.GenerateId());

                tank.PlayerId = message.PlayerId;

                tank.Battle = battle;

                tank.Name = message.Name;

                tank.Level = message.Level;

                tank.AddComponent <NumericComponent>();

                battle.Add(tank);

                tank.TankCamp = message.Camp == 1? TankCamp.Left : TankCamp.Right;

                await tank.AddComponent <MailBoxComponent>().AddLocation();

                tank.AddComponent <TankGateComponent, long>(message.GateSessionId);

                response.TankId = tank.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }