Example #1
0
        public override void OnCoreGameEventHandler(OnCoreGameEvent data)
        {
            base.OnCoreGameEventHandler(data);

            switch (data.EventCode)
            {
            case EventCode.MatchBegan:
            {
                CoreGameRoot.ExecuteRootMatchBegan();
                break;
            }

            case EventCode.ShowCardAndTurnNext:
            {
                int             current_cards_actor_id = Convert.ToInt32(Network.Client.CurrentRoom.CustomProperties ["current_cards_actor_id"]);
                PlayerViewModel currentCardsPlayer     = CoreGameRoot.PlayerCollection.SingleOrDefault(vm => vm.ActorId == current_cards_actor_id);
                currentCardsPlayer.ExecuteShowCardsToPile();
                CoreGameRoot.ExecuteRefreshCoreGame();
                break;
            }

            case EventCode.PassAndTurnNext:
            {
                CoreGameRoot.ExecuteRefreshCoreGame();
                break;
            }

            case EventCode.MatchOver:
            {
                CoreGameRoot.ExecuteRootMatchOver();
                break;
            }

            case EventCode.ClearCardsInPile:
            {
                CoreGameRoot.Pile.Cards.Clear();
                break;
            }

            default:
                break;
            }
        }
        public override void TurnNext(CoreGameRootViewModel viewModel)
        {
            base.TurnNext(viewModel);
            int active_actor_id = Convert.ToInt32(Network.Client.CurrentRoom.CustomProperties ["active_actor_id"]);

            Hashtable ht1 = new Hashtable();

            ht1.Add("my_turn", false);
            Publish(new NetSetPlayerProperties()
            {
                ActorId         = active_actor_id,
                PropertiesToSet = ht1
            });

            int actor_id     = active_actor_id;
            int player_count = viewModel.PlayerCollection.Count;

            do
            {
                int orderIdx = viewModel.PlayerCollection.SingleOrDefault(playerVM => playerVM.ActorId == actor_id).OrderIdx;
                orderIdx++;
                if (orderIdx >= player_count)
                {
                    orderIdx = 0;
                }
                actor_id = viewModel.PlayerCollection.SingleOrDefault(playerVM => playerVM.OrderIdx == orderIdx).ActorId;

                bool correct = true;
                if (Convert.ToBoolean(Network.Client.CurrentRoom.GetPlayer(actor_id).CustomProperties ["is_win"]))
                {
                    correct = false;
                }

                if (correct)
                {
                    break;
                }
            } while(actor_id != active_actor_id);

            if (viewModel.WinPlayersCount == Network.Client.CurrentRoom.PlayerCount - 1)
            {
                Hashtable ht2 = new Hashtable();
                ht2.Add("rank", (int)Network.Client.CurrentRoom.PlayerCount);
                Publish(new NetSetPlayerProperties()
                {
                    ActorId         = actor_id,
                    PropertiesToSet = ht2
                });

                Hashtable ht = new Hashtable();
                ht.Add("active_actor_id", -1);
                Publish(new NetSetRoomProperties()
                {
                    PropertiesToSet = ht
                });

                viewModel.ExecuteCalcMatchResult();

                Publish(new NetRaiseEvent()
                {
                    EventCode = GameService.EventCode.MatchOver
                });

                viewModel.ExecuteRootMatchOver();
            }
            else
            {
                // 自己的牌大,重新轮到自己发牌
                if (Convert.ToInt32(Network.Client.CurrentRoom.CustomProperties ["current_cards_actor_id"]) == actor_id)
                {
                    Hashtable ht3 = new Hashtable();
                    ht3.Add("current_cards", JsonConvert.SerializeObject(new List <CardInfo> ()));
                    Publish(new NetSetRoomProperties()
                    {
                        PropertiesToSet = ht3
                    });

                    Publish(new NetRaiseEvent()
                    {
                        EventCode = GameService.EventCode.ClearCardsInPile
                    });

                    CoreGameRoot.Pile.Cards.Clear();
                }

                Hashtable ht2 = new Hashtable();
                ht2.Add("my_turn", true);
                Publish(new NetSetPlayerProperties()
                {
                    ActorId         = actor_id,
                    PropertiesToSet = ht2
                });

                Hashtable ht = new Hashtable();
                ht.Add("active_actor_id", actor_id);
                Publish(new NetSetRoomProperties()
                {
                    PropertiesToSet = ht
                });
            }
        }