Пример #1
0
        public void Start()
        {
            //添加本地玩家
            Player localPlayer = ClientComponent.Instance.LocalPlayer;
            Gamer  localGamer  = EntityFactory.CreateWithId <Gamer, long>(localPlayer.Id, localPlayer.UserID);

            localGamer.AddComponent <GamerUIComponent, UI>(this.GetEntity <UI>());
            GamerComponent gamerComponent = this.GetComponent <GamerComponent>();

            gamerComponent.Add(localGamer);
            gamerComponent.LocalGamer = localGamer;
        }
Пример #2
0
        protected override Task Run(Room entity, ChangeGameMode message)
        {
            Gamer gamer = entity.Get(message.PlayerId);

            if (gamer != null)
            {
                if (gamer.GetComponent <AutoPlayCardsComponent>() == null)
                {
                    gamer.AddComponent <AutoPlayCardsComponent, Room>(entity);
                    Log.Info($"玩家{gamer.Id}切换为自动模式");
                }
                else
                {
                    gamer.RemoveComponent <AutoPlayCardsComponent>();
                    Log.Info($"玩家{gamer.Id}切换为手动模式");
                }
            }
            return(Task.CompletedTask);
        }
Пример #3
0
        protected override Task Run(Room entity, PlayerQuit message)
        {
            Gamer gamer = entity.Get(message.PlayerID);

            if (gamer != null)
            {
                if (entity.State == RoomState.Game)
                {
                    //玩家操作设置为自动
                    Log.Info($"游戏中,玩家{message.PlayerID}退出房间,切换为自动模式");
                    gamer.isOffline = true;
                    if (gamer.GetComponent <AutoPlayCardsComponent>() == null)
                    {
                        gamer.AddComponent <AutoPlayCardsComponent, Room>(entity);
                    }
                }
                else
                {
                    //房间移除玩家
                    entity.Remove(gamer.Id);

                    //同步匹配服务器移除玩家
                    MapHelper.SendMessage(new GamerQuitRoom()
                    {
                        PlayerID = message.PlayerID, RoomID = entity.Id
                    });

                    //消息广播给其他人
                    entity.Broadcast(new GamerOut()
                    {
                        PlayerID = message.PlayerID
                    });
                    Log.Info($"准备中,玩家{message.PlayerID}退出房间");
                }
            }

            return(Task.CompletedTask);
        }
Пример #4
0
        protected override Task Run(Room unit, GetJoinRoomKeyRt message, Action <GetJoinRoomKeyRe> reply)
        {
            GetJoinRoomKeyRe response = new GetJoinRoomKeyRe();

            try
            {
                //创建玩家
                Gamer gamer = EntityFactory.CreateWithId <Gamer, long>(message.PlayerId, message.UserId);
                gamer.AddComponent <UnitGateComponent, long>(message.GateSeesionId);

                //随机密匙
                long key = RandomHelper.RandInt64();
                unit.GetComponent <RoomJoinKeyComponent>().Add(key, gamer);
                Log.Info($"获取进入房间密匙{key}");

                response.Key = key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
            return(Task.CompletedTask);
        }