예제 #1
0
        protected override async void Run(ETModel.Session session, A1009_NewArmyWave_M2C message)
        {
            //服务端通知客户端刷新一波士兵 2战士 1法师
            TimerComponent     timerComponent     = ETModel.Game.Scene.GetComponent <TimerComponent>();
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent    config             = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component   moba = Moba5V5Component.instance;

            //创建3个蓝方战士 配置编号31-33
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 31);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            //创建3个红方战士 配置编号40-42
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 40);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }

            await timerComponent.WaitAsync(1000);

            //重复一遍战士配置
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 31);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 40);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }

            await timerComponent.WaitAsync(1000);

            //创建3个蓝方法师 配置编号34-36
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 34);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            //创建3个红方法师 配置编号43-45
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 43);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
        }
        protected override void Run(ETModel.Session session, Actor_GameStart_Ntt message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom);
            LandlordsRoomComponent room = uiRoom.GetComponent <LandlordsRoomComponent>();

            //初始化玩家UI
            foreach (GamerCardNum gamerCardNum in message.GamersCardNum)
            {
                Gamer gamer = room.GetGamer(gamerCardNum.UserID);
                LandlordsGamerPanelComponent gamerUI = gamer.GetComponent <LandlordsGamerPanelComponent>();
                gamerUI.GameStart();

                HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                if (handCards != null)
                {
                    handCards.Reset();
                }
                else
                {
                    //Log.Debug("没有可以复用的HandCardsComponent,创建一个。");
                    handCards = gamer.AddComponent <HandCardsComponent, GameObject>(gamerUI.Panel);
                }

                //显示牌背面或者手牌
                handCards.Appear();

                if (gamer.UserID == LandlordsRoomComponent.LocalGamer.UserID)
                {
                    //本地玩家添加手牌
                    Card[] Tcards = new Card[message.HandCards.Count];
                    for (int i = 0; i < message.HandCards.Count; i++)
                    {
                        Tcards[i] = message.HandCards[i];
                    }
                    //Log.Debug("当前玩家手牌数量"+message.HandCards.array.Length.ToString());
                    //array的数量为32 与牌数不符合
                    handCards.AddCards(Tcards);
                }
                else
                {
                    //设置其他玩家手牌数
                    handCards.SetHandCardsNum(gamerCardNum.Num);
                }
            }

            //显示牌桌UI
            GameObject desk = uiRoom.GameObject.Get <GameObject>("Desk");

            desk.SetActive(true);
            GameObject lordPokers = desk.Get <GameObject>("LordPokers");

            //重置地主牌
            Sprite lordSprite = CardHelper.GetCardSprite("None");

            for (int i = 0; i < lordPokers.transform.childCount; i++)
            {
                lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordSprite;
            }

            LandlordsRoomComponent uiRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>();

            //清空选中牌
            uiRoomComponent.Interaction.Clear();
            //设置初始倍率
            uiRoomComponent.SetMultiples(1);
        }
예제 #3
0
        public static async Task ChangeWealth(long uid, int propId, int propNum, string reason, Room room = null)
        {
            //Log.Debug("ChangeWealth: uid = " + uid + "  propId = " + propId + "propNum = " + propNum);

            try
            {
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                switch (propId)
                {
                // 金币
                case 1:
                {
                    List <PlayerBaseInfo> playerBaseInfos =
                        await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}");

                    playerBaseInfos[0].GoldNum += propNum;
                    if (playerBaseInfos[0].GoldNum < 0)
                    {
                        playerBaseInfos[0].GoldNum = 0;
                    }

                    bool isSendReliefGold = false;

                    // 救济金
                    if (playerBaseInfos[0].GoldNum < 2000)
                    {
                        List <Log_ReliefGold> log_reliefGolds = await proxyComponent.QueryJson <Log_ReliefGold>($"{{CreateTime:/^{DateTime.Now.GetCurrentDay()}/,Uid:{uid}}}");

                        if (log_reliefGolds.Count < 3)
                        {
                            isSendReliefGold = true;

                            int gold = 20000;
                            playerBaseInfos[0].GoldNum += gold;
                            Log_ReliefGold log_ReliefGold = ComponentFactory.CreateWithId <Log_ReliefGold>(IdGenerater.GenerateId());
                            log_ReliefGold.Uid    = uid;
                            log_ReliefGold.reward = "1:" + gold;
                            await proxyComponent.Save(log_ReliefGold);

                            // 通知玩家
                            {
                                Actor_ReliefGold actor = new Actor_ReliefGold();
                                if (log_reliefGolds.Count == 0)
                                {
                                    actor.Reward = "今日第一次赠送金币:" + gold;
                                }
                                else if (log_reliefGolds.Count == 1)
                                {
                                    actor.Reward = "今日第二次赠送金币:" + gold;
                                }
                                else if (log_reliefGolds.Count == 2)
                                {
                                    actor.Reward = "今日最后一次赠送金币:" + gold;
                                }
                                if (room != null)
                                {
                                    Gamer gamer = room.Get(uid);
                                    room.GamerBroadcast(gamer, actor);
                                }
                            }
                        }
                    }

                    await proxyComponent.Save(playerBaseInfos[0]);

                    if (!isSendReliefGold)
                    {
                        await RecordWeekRankLog(uid, propNum, 0);
                    }
                }
                break;

                // 元宝
                case 2:
                {
                    List <PlayerBaseInfo> playerBaseInfos =
                        await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}");

                    playerBaseInfos[0].WingNum += propNum;
                    if (playerBaseInfos[0].WingNum < 0)
                    {
                        playerBaseInfos[0].WingNum = 0;
                    }

                    await proxyComponent.Save(playerBaseInfos[0]);
                }
                break;

                // 话费
                case 3:
                {
                    List <PlayerBaseInfo> playerBaseInfos =
                        await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}");

                    playerBaseInfos[0].HuaFeiNum += propNum;
                    if (playerBaseInfos[0].HuaFeiNum < 0)
                    {
                        playerBaseInfos[0].HuaFeiNum = 0;
                    }

                    await proxyComponent.Save(playerBaseInfos[0]);
                }
                break;

                //积分
                case 4:
                {
                    List <PlayerBaseInfo> playerBaseInfos =
                        await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}");

                    playerBaseInfos[0].Score += propNum;

                    await proxyComponent.Save(playerBaseInfos[0]);
                }
                break;

                // 其他道具
                default:
                {
                    List <UserBag> userBags = await proxyComponent.QueryJson <UserBag>($"{{UId:{uid},BagId:{propId}}}");

                    if (userBags.Count == 0)
                    {
                        UserBag itemInfo = ComponentFactory.CreateWithId <UserBag>(IdGenerater.GenerateId());
                        itemInfo.BagId = propId;
                        itemInfo.UId   = uid;
                        itemInfo.Count = propNum;
                        await proxyComponent.Save(itemInfo);
                    }
                    else
                    {
                        userBags[0].Count += propNum;
                        if (userBags[0].Count < 0)
                        {
                            userBags[0].Count = 0;
                        }

                        await proxyComponent.Save(userBags[0]);
                    }
                }
                break;
                }

                await Log_ChangeWealth(uid, propId, propNum, reason);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
        protected override async Task Run(Room room, Actor_PlayerEnterRoom_Req message, Action <Actor_PlayerEnterRoom_Ack> reply)
        {
            Actor_PlayerEnterRoom_Ack response = new Actor_PlayerEnterRoom_Ack();

            try
            {
                Gamer gamer = room.Get(message.UserID);
                if (gamer == null)
                {
                    //创建房间玩家对象
                    gamer = GamerFactory.Create(message.PlayerID, message.UserID);
                    await gamer.AddComponent <MailBoxComponent>().AddLocation();

                    gamer.AddComponent <UnitGateComponent, long>(message.SessionID);

                    //加入到房间
                    room.Add(gamer);

                    Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(default(GamerInfo));
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //广播房间内玩家消息
                    room.Broadcast(broadcastMessage);

                    Log.Info($"玩家{message.UserID}进入房间");
                }
                else
                {
                    //玩家重连
                    gamer.isOffline = false;
                    gamer.PlayerID  = message.PlayerID;
                    gamer.GetComponent <UnitGateComponent>().GateSessionActorId = message.SessionID;

                    //玩家重连移除托管组件
                    gamer.RemoveComponent <TrusteeshipComponent>();

                    Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(default(GamerInfo));
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //发送房间玩家信息
                    ActorMessageSender actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorMessageSender();
                    actorProxy.Send(broadcastMessage);

                    List <GamerCardNum>      gamersCardNum   = new List <GamerCardNum>();
                    List <GamerState>        gamersState     = new List <GamerState>();
                    GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                    OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                    DeskCardsCacheComponent  deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();

                    foreach (Gamer _gamer in room.GetAll())
                    {
                        HandCardsComponent handCards = _gamer.GetComponent <HandCardsComponent>();
                        gamersCardNum.Add(new GamerCardNum()
                        {
                            UserID = _gamer.UserID,
                            Num    = _gamer.GetComponent <HandCardsComponent>().GetAll().Length
                        });
                        gamersState.Add(new GamerState()
                        {
                            UserID            = _gamer.UserID,
                            UserIdentity      = handCards.AccessIdentity,
                            GrabLandlordState = orderController.GamerLandlordState.ContainsKey(_gamer.UserID)
                            ? orderController.GamerLandlordState[_gamer.UserID]
                            : false
                        });
                    }

                    //发送游戏开始消息
                    Actor_GameStart_Ntt gameStartNotice = new Actor_GameStart_Ntt();
                    gameStartNotice.HandCards.AddRange(gamer.GetComponent <HandCardsComponent>().GetAll());
                    gameStartNotice.GamersCardNum.AddRange(gamersCardNum);
                    actorProxy.Send(gameStartNotice);

                    Card[] lordCards = null;

                    if (gamer.GetComponent <HandCardsComponent>().AccessIdentity == Identity.None)
                    {
                        //广播先手玩家
                        actorProxy.Send(new Actor_AuthorityGrabLandlord_Ntt()
                        {
                            UserID = orderController.CurrentAuthority
                        });
                    }
                    else
                    {
                        if (gamer.UserID == orderController.CurrentAuthority)
                        {
                            //发送可以出牌消息
                            bool isFirst = gamer.UserID == orderController.Biggest;
                            actorProxy.Send(new Actor_AuthorityPlayCard_Ntt()
                            {
                                UserID = orderController.CurrentAuthority, IsFirst = isFirst
                            });
                        }
                        lordCards = deskCardsCache.LordCards.ToArray();
                    }
                    //发送重连数据
                    Actor_GamerReconnect_Ntt reconnectNotice = new Actor_GamerReconnect_Ntt()
                    {
                        UserId    = orderController.Biggest,
                        Multiples = room.GetComponent <GameControllerComponent>().Multiples
                    };
                    reconnectNotice.GamersState.AddRange(gamersState);
                    reconnectNotice.LordCards.AddRange(lordCards);
                    reconnectNotice.Cards.AddRange(deskCardsCache.library);
                    actorProxy.Send(reconnectNotice);

                    Log.Info($"玩家{message.UserID}重连");
                }

                response.GamerID = gamer.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
예제 #5
0
        /// <summary>
        /// 结算用户余额
        /// </summary>
        public static async Task <long> StatisticalIntegral(this GameControllerComponent self, Gamer gamer, long sorce)
        {
            DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

            //结算用户余额
            UserInfo userInfo = await dbProxy.Query <UserInfo>(gamer.UserID, false);

            userInfo.Money = userInfo.Money + sorce < 0 ? 0 : userInfo.Money + sorce;

            //更新用户信息
            await dbProxy.Save(userInfo, false);

            return(userInfo.Money);
        }
        protected override void Run(Session session, C2M_CowCowGamerSubmitCardType message, Action <M2C_CowCowGamerSubmitCardType> reply)
        {
            M2C_CowCowGamerSubmitCardType response = new M2C_CowCowGamerSubmitCardType();

            try
            {
                Room room = Game.Scene.GetComponent <RoomComponent>().Get(message.UserID);
                if (room == null)
                {
                    response.Error = ErrorCode.ERR_NotRoomNumberError;
                    reply(response);
                    return;
                }

                Gamer gamer = room.Get(message.SeatID);
                gamer.IsSubmitHandCards = true;
                gamer.MaxValue          = message.MaxCard;
                gamer.cardType          = message.CardType;
                gamer.FloweColor        = message.FlowerColor;
                gamer.CowNumber         = message.CowNumber;
                gamer.Multiple          = message.Multiple;
                gamer.cards.Clear();
                gamer.cards.AddRange(message.Cards);
                this.ChangeCowCount(gamer, room.CurBankerSeatID == gamer.SeatID, message.CardType, message.CowNumber);

                Actor_CowCowGamerSubmitCardType submits = new Actor_CowCowGamerSubmitCardType();
                submits.SeatIDs = new RepeatedField <int>();
                Dictionary <int, Gamer> gamers = room.GetAll();
                foreach (Gamer g in gamers.Values)
                {
                    if (g.IsSubmitHandCards)
                    {
                        submits.SeatIDs.Add(g.SeatID);
                    }
                }
                reply(response);
                if (submits.SeatIDs.count == room.GamerCount)
                {
                    this.SmallSettlement(gamers, room);
                    // 发送大结算
                    if (room.CurBureau == room.Bureau)
                    {
                        Actor_CowCowBigSettlement bs = new Actor_CowCowBigSettlement();
                        bs.Info = new RepeatedField <CowCowBigSettlementInfo>();
                        foreach (Gamer g in gamers.Values)
                        {
                            CowCowBigSettlementInfo info = new CowCowBigSettlementInfo();
                            info.SeatID        = g.SeatID;
                            info.Banker        = g.BankerCount;
                            info.FiveSmallCow  = g.FiveSmallCowCount;
                            info.FiveFlowerCow = g.FiveFlowerCowCount;
                            info.BombCow       = g.BombCowCount;
                            info.DoubleCow     = g.DoubleCowCount;
                            info.HaveCow       = g.HaveCowCount;
                            info.NotCow        = g.NotCowCount;
                            info.TotalScore    = g.Coin;

                            bs.Info.Add(info);
                        }
                        room.Broadcast(bs);
                    }
                }
                else
                {
                    room.Broadcast(submits);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
예제 #7
0
 /// <summary>
 /// 更新身份
 /// </summary>
 /// <param name="self"></param>
 /// <param name="id"></param>
 /// <param name="identity"></param>
 public static void UpdateInIdentity(this GameControllerComponent self, Gamer gamer, Identity identity)
 {
     gamer.GetComponent <HandCardsComponent>().AccessIdentity = identity;
 }
예제 #8
0
 public void AddGamer(Gamer gamer, int index)
 {
     seats[gamer.UserID] = index;
     gamer.AddComponent <LandlordsGamerPanelComponent>().SetPanel(GamersPanel[index]);
     gamers[index] = gamer;
 }
예제 #9
0
        protected override void Run(ETModel.Session session, Actor_GamerEnterRoom_Ntt message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom);
            LandlordsRoomComponent landlordsRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>();

            //从匹配状态中切换为准备状态
            if (landlordsRoomComponent.Matching)
            {
                landlordsRoomComponent.Matching = false;
                GameObject matchPrompt = uiRoom.GameObject.Get <GameObject>("MatchPrompt");
                if (matchPrompt.activeSelf)
                {
                    matchPrompt.SetActive(false);
                    uiRoom.GameObject.Get <GameObject>("ReadyButton").SetActive(true);
                }
            }

            //服务端发过来3个GamerInfo 当前玩家为其中一个
            //{"Parser":{},"UserID":382339254124924,"IsReady":false}
            int localGamerIndex = -1;

            for (int i = 0; i < message.Gamers.Count; i++)
            {
                if (message.Gamers[i].UserID == LandlordsRoomComponent.LocalGamer.UserID)
                {
                    localGamerIndex = i;
                }
            }

            if (localGamerIndex == -1)
            {
                Log.Error("难道是旁观模式?");
            }

            //添加未显示玩家
            for (int i = 0; i < message.Gamers.Count; i++)
            {
                //如果服务端发来了默认空GamerInfo 跳过
                //{"Parser":{},"UserID":0,"IsReady":false}]}
                GamerInfo gamerInfo = message.Gamers[i];
                if (gamerInfo.UserID == 0)
                {
                    continue;
                }
                //如果这个ID的玩家不在桌上
                if (landlordsRoomComponent.GetGamer(gamerInfo.UserID) == null)
                {
                    Gamer gamer = ETModel.ComponentFactory.Create <Gamer, long>(gamerInfo.UserID);
                    //并没有判断玩家是否已准备

                    //localGamerIndex % 3可以理解为当前玩家在3个玩家(Gamers)中的顺序
                    //localGamerIndex + 1指当前玩家的下一个玩家的相对顺序
                    //如果本地玩家序列为2 localGamerIndex + 1) % 3=0 序列为0的玩家显示在2号位
                    if ((localGamerIndex + 1) % 3 == i)
                    {
                        //玩家在本地玩家右边
                        landlordsRoomComponent.AddGamer(gamer, 2);
                    }
                    else
                    {
                        //玩家在本地玩家左边
                        landlordsRoomComponent.AddGamer(gamer, 0);
                    }
                }
            }
        }
예제 #10
0
        //        public async Task GetPlayerInfo()
//        {
//            tokenSource = new CancellationTokenSource();
//            try
//            {
//                Gamer gamer = this.GetParent<Gamer>();
//                Log.Debug("请求gamer信息:" + gamer.UserID);
//                G2C_PlayerInfo playerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo() { uid = gamer.UserID }, tokenSource.Token);
//                gamer.PlayerInfo = playerInfo.PlayerInfo;
//            }
//            catch (Exception e)
//            {
//                Log.Error(e);
//                tokenSource.Cancel();
//            }
//        }

        /// <summary>
        /// 设置准备界面
        /// </summary>
        /// <param name="gameObject"></param>
        public void SetHeadPanel(GameObject gameObject, int index)
        {
            try
            {
                if (gameObject == null)
                {
                    return;
                }

                Index = index;
                Gamer gamer = this.GetParent <Gamer>();
                this.readyHead = gameObject.Get <GameObject>("Image").GetComponent <Image>();
                this.readyName = gameObject.Get <GameObject>("Name").GetComponent <Text>();
                this.readyText = gameObject.Get <GameObject>("Text").GetComponent <Text>();
                this.vip       = gameObject.Get <GameObject>("vip");
                PlayerInfo playerInfo = gamer.PlayerInfo;

                if (readyName == null)
                {
                    return;
                }
                readyName.text = playerInfo.Name + "";
                HeadManager.setHeadSprite(readyHead, playerInfo.Icon);

                if (gamer.IsReady)
                {
                    gameObject.transform.Find("Text").GetComponent <Text>().text = "已准备";
                }
                else
                {
                    readyText.text = "";
                }

                if (GameUtil.isVIP(playerInfo))
                {
                    vip.transform.localScale = Vector3.one;
                }
                else
                {
                    vip.transform.localScale = Vector3.zero;
                }

                #region 准备界面信息框
                // if(Index != 0)
                {
                    this.headReadyInfo = gameObject.Get <GameObject>("HeadInfo");
                    Image kickOffImage     = this.headReadyInfo.Get <GameObject>("KickOffImage").GetComponent <Image>();
                    Text  uidReadyText     = this.headReadyInfo.Get <GameObject>("Uid").GetComponent <Text>();
                    Text  shenglvReadyText = this.headReadyInfo.Get <GameObject>("Shenglv").GetComponent <Text>();
                    Text  jinbiReadyText   = this.headReadyInfo.Get <GameObject>("Jinbi").GetComponent <Text>();
                    this.headReadyInfo.SetActive(false);
                    this.headReadyInfo.GetComponentInParent <Button>().onClick.RemoveAllListeners();
                    this.headReadyInfo.GetComponentInParent <Button>().onClick.Add(() =>
                    {
                        if (this.headReadyInfo.activeSelf)
                        {
                            this.headReadyInfo.SetActive(false);
                        }
                        else
                        {
                            this.headReadyInfo.SetActive(true);
                        }
                    });
                    uidReadyText.text = playerInfo.Name;


                    UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
                    this.uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>();
                    if (UIRoomComponent.IsFriendRoom)
                    {
                        shenglvReadyText.text = $"积 分:<color=#FFF089FF>{playerInfo.Score}</color>";
                    }
                    else
                    {
                        shenglvReadyText.text = $"金 币:<color=#FFF089FF>{playerInfo.GoldNum}</color>";
                    }

                    float i;
                    if (playerInfo.TotalGameCount == 0)
                    {
                        i = 0;
                    }
                    else
                    {
                        i = GameUtil.GetWinRate(playerInfo.TotalGameCount, playerInfo.WinGameCount);
                    }
                    jinbiReadyText.text = $"胜 率:<color=#FFF089FF>{i}%</color>";

                    //踢人

                    if (uiRoomComponent.masterUserId != 0 && uiRoomComponent.masterUserId == PlayerInfoComponent.Instance.uid && Index != 0)
                    {
                        kickOffImage.gameObject.SetActive(true);
                    }
                    else
                    {
                        kickOffImage.gameObject.SetActive(false);
                    }

                    kickOffImage.gameObject.GetComponent <Button>().onClick.Add(() =>
                    {
                        SessionComponent.Instance.Session.Send(new Actor_GamerKickOff()
                        {
                            KickedUserId = gamer.UserID
                        });
                    });
                }



                #endregion
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
예제 #11
0
        protected override void Run(ETModel.Session session, A1012_NewMonster_M2C message)
        {
            //服务端通知客户端刷新一窝野怪
            TimerComponent     timerComponent     = ETModel.Game.Scene.GetComponent <TimerComponent>();
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent    config             = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component   moba = Moba5V5Component.instance;

            //野怪点ID 编号分别为:49 51 52 54 57 58 59 60 61 62 63 64 65 68 70 71
            int configID;      //配置编号
            int monsterNumber; //野怪数量

            switch (message.MonsterID)
            {
            case 49:     //蜥蜴
                configID      = 49;
                monsterNumber = 2;
                break;

            case 51:     //蓝Buff
                configID      = 51;
                monsterNumber = 1;
                break;

            case 52:     //狼
                configID      = 52;
                monsterNumber = 2;
                break;

            case 54:     //熊
                configID      = 54;
                monsterNumber = 3;
                break;

            case 57:     //红Buff
                configID      = 57;
                monsterNumber = 1;
                break;

            case 58:     //鸟
                configID      = 58;
                monsterNumber = 1;
                break;

            case 59:     //河道蟹
                configID      = 59;
                monsterNumber = 1;
                break;

            case 60:     //河道蟹
                configID      = 60;
                monsterNumber = 1;
                break;

            case 61:     //大Boss
                configID      = 61;
                monsterNumber = 1;
                break;

            case 62:     //小Boss
                configID      = 62;
                monsterNumber = 1;
                break;

            case 63:     //鸟
                configID      = 63;
                monsterNumber = 1;
                break;

            case 64:     //红buff
                configID      = 64;
                monsterNumber = 1;
                break;

            case 65:     //熊
                configID      = 65;
                monsterNumber = 3;
                break;

            case 68:     //狼
                configID      = 68;
                monsterNumber = 2;
                break;

            case 70:     //蓝Buff
                configID      = 70;
                monsterNumber = 1;
                break;

            case 71:     //蜥蜴
                configID      = 71;
                monsterNumber = 2;
                break;

            default:
                throw new Exception("未知野怪点");
            }

            for (int i = 0; i < monsterNumber; i++)
            {
                if (i == 12)
                {
                    continue;
                }

                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + configID);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
            }
        }