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

            try
            {
                Unit unit = ComponentFactory.Create <Unit>();

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

                unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);
                Game.Scene.GetComponent <UnitComponent>().Add(unit);
                response.UnitId = unit.Id;

                response.Count = Game.Scene.GetComponent <UnitComponent>().Count;
                reply(response);

                if (response.Count == 2)
                {
                    Actor_CreateUnits actorCreateUnits = new Actor_CreateUnits();
                    Unit[]            units            = Game.Scene.GetComponent <UnitComponent>().GetAll();
                    Unit u;
                    for (int i = 0; i < units.Length; i++)
                    {
                        u = units[i];
                        actorCreateUnits.Units.Add(new UnitInfo(u.Id, (int)(u.Position.X * 1000), (int)(u.Position.Z * 1000), i + 1));
                    }
                    MessageHelper.Broadcast(actorCreateUnits);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #2
0
        protected override async void Run(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply)
        {
            M2G_CreateUnit response = new M2G_CreateUnit();

            try
            {
                Unit unit = ComponentFactory.Create <Unit>();
                await unit.AddComponent <ActorComponent, IEntityActorHandler>(new MapUnitEntityActorHandler()).AddLocation();

                unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);
                Game.Scene.GetComponent <UnitComponent>().Add(unit);
                response.UnitId = unit.Id;

                response.Count = Game.Scene.GetComponent <UnitComponent>().Count;
                reply(response);

                if (response.Count == 2)
                {
                    Actor_CreateUnits actorCreateUnits = new Actor_CreateUnits();
                    Unit[]            units            = Game.Scene.GetComponent <UnitComponent>().GetAll();
                    foreach (Unit u in units)
                    {
                        actorCreateUnits.Units.Add(new UnitInfo()
                        {
                            UnitId = u.Id, X = (int)(u.Position.X * 1000), Z = (int)(u.Position.Z * 1000)
                        });
                    }
                    MessageHelper.Broadcast(actorCreateUnits);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #3
0
        protected async ETVoid RunAsync(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply)
        {
            M2G_CreateUnit response = new M2G_CreateUnit();

            try
            {
                Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId());
                unit.AddComponent <MoveComponent>();
                unit.AddComponent <UnitPathComponent>();
                unit.Position = new Vector3(-10, 0, -10);

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

                unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);
                Game.Scene.GetComponent <UnitComponent>().Add(unit);
                response.UnitId = unit.Id;


                // 广播创建的unit
                Actor_CreateUnits createUnits = new Actor_CreateUnits();
                Unit[]            units       = Game.Scene.GetComponent <UnitComponent>().GetAll();
                foreach (Unit u in units)
                {
                    UnitInfo unitInfo = new UnitInfo();
                    unitInfo.X      = u.Position.x;
                    unitInfo.Y      = u.Position.y;
                    unitInfo.Z      = u.Position.z;
                    unitInfo.UnitId = u.Id;
                    createUnits.Units.Add(unitInfo);
                }
                MessageHelper.Broadcast(createUnits);


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