/// <summary> /// 创建一副牌 /// </summary> private static void CreateDeck(this DeckComponent self) { //创建普通扑克 for (int color = 0; color < 4; color++) { for (int value = 0; value < 13; value++) { Weight w = (Weight)value; Suits s = (Suits)color; Card card = new Card() { CardSuits = s, CardWeight = w }; self.library.Add(card); } } //创建大小王扑克 self.library.Add(new Card() { CardWeight = Weight.Sjoker, CardSuits = Suits.None }); self.library.Add(new Card() { CardWeight = Weight.Ljoker, CardSuits = Suits.None }); }
private void deckSelectChanged(DeckComponent selected) { bool value = selected != null; this.dialogAnimator.SetBool(Constants.OR(), value); this.updatePlayButton(selected); }
protected override async Task Run(Gamer entity, Actor_RobBanker_Ntt message) { Room room = RoomHelp.GetRoom(entity.RoomID); DeckComponent deck = room.GetComponent <DeckComponent>(); deck.AddRobBankGamer(message.ChairId, message.BankerNumber); if (deck.IsRobBankerAll()) { //如果所有人都抢庄结束 ushort ChairId = deck.GetBanker(); room.Broadcast(new Actor_RobBankerResult_Ntt() { ChairId = message.ChairId, BankerNumber = message.BankerNumber }); room.Broadcast(new Actor_SelectBanker_Ntt() { ChairId = ChairId }); //指定庄 room.Get(ChairId).IsRobBanker = true; } else { //如果还没有抢庄完 room.Broadcast(new Actor_RobBankerResult_Ntt() { ChairId = message.ChairId, BankerNumber = message.BankerNumber }); } Log.Debug($"玩家:{message.ChairId},抢庄倍数:{message.BankerNumber},当前抢庄玩家人数:{deck.RobBankerDic.Count}"); await Task.CompletedTask; }
/// <summary> /// 发牌 /// </summary> /// <param name="self"></param> /// <returns></returns> public static byte Deal(this DeckComponent self) { byte Card = self.library[self.CardsCount - 1]; self.library.Remove(Card); return(Card); }
/// <summary> /// 重置数据 /// </summary> /// <param name="self"></param> public static void Reset(this DeckComponent self) { self.BetDic.Clear(); self.RobBankerDic.Clear(); self.ShowCardDic.Clear(); self.XJReady = 0; }
/// <summary> /// 发牌 /// </summary> /// <returns></returns> public static Card Deal(this DeckComponent self) { Card card = self.library[self.CardsCount - 1]; self.library.Remove(card); return(card); }
/// <summary> /// 获取庄 /// </summary> /// <param name="self"></param> /// <returns></returns> public static ushort GetBanker(this DeckComponent self) { List <ushort> MaxChairId = new List <ushort>(); int index = 0; foreach (KeyValuePair <ushort, byte> valuePair in self.RobBankerDic) { if (index < valuePair.Value) { MaxChairId.Clear(); index = valuePair.Value; MaxChairId.Add(valuePair.Key); } else if (index <= valuePair.Value) { MaxChairId.Add(valuePair.Key); } } if (MaxChairId.Count == 1) { //直接指定庄家 return(MaxChairId[0]); } if (MaxChairId.Count >= 2) { //随机指定庄 Random random = new Random(); int randomNumber = random.Next(0, MaxChairId.Count); return(MaxChairId[randomNumber]); } return(0); }
/// <summary> /// 添加下注玩家 /// </summary> /// <param name="self"></param> /// <param name="ChairId"></param> /// <param name="BetNumber"></param> public static void AddBetGamer(this DeckComponent self, ushort ChairId, byte BetNumber) { if (self.BetDic.ContainsKey(ChairId)) { return; } self.BetDic.Add(ChairId, BetNumber); }
private void Start() { DeckGO = FindObjectOfType <DeckComponent> ( ); HandGO = FindObjectOfType <HandComponent> ( ); CardViewGO = FindObjectOfType <CardViewComponent> ( ); cardController = FindObjectOfType <MasterControllerComponent> ( ); cardController.SetOwner(this); }
private void loadDeck(DeckComponent deck) { this.current_deck.Clear(); if (deck != null) { Archetypes archetypes = Finder.FindOrThrow <Archetypes>(); Directory.CreateDirectory("decks"); foreach (KeyValuePair <DeckID, DeckComponent> keyValuePair in Finder.FindOrThrow <Decks>().get_All()) { Pile pile2; if (keyValuePair.Key != null && keyValuePair.Value.get_Piles().TryGetValue(Constants.K(), out pile2)) { string to_write = ""; foreach (KeyValuePair <ArchetypeID, int> keyValuePair2 in pile2) { to_write = string.Concat(new object[] { to_write, archetypes.get_All()[keyValuePair2.Key].GetOne <NameData>().get_Name(), " ", keyValuePair2.Value, "\r\n" }); } File.WriteAllText(Path.Combine("decks", keyValuePair.Value.get_Name() + ".txt"), to_write); } } Pile pile3; if (deck.get_Piles().TryGetValue(Constants.K(), out pile3)) { foreach (KeyValuePair <ArchetypeID, int> keyValuePair3 in pile3) { ArchetypeComponent archetypeComponent; if (this.local_collection_avatars.get_All().TryGetValue(keyValuePair3.Key, out archetypeComponent)) { this.tryToMove(keyValuePair3.Key, keyValuePair3.Value); } else { Debug.LogError(Constants.Fx() + keyValuePair3.Key); } } } foreach (global::H.L l in this.current_deck.get_Stacks()) { l.GetOne <global::g.p>().MarkAsRead(); } ArchetypeComponent avatar = deck.GetAvatar(this.local_collection_avatars); this.deck_avatars.SetAvatar(avatar); } if (deck != null) { this.deck_name.SetName(deck.GetOne <DeckNameData>().get_Name(), deck.GetOne <global::E.y>().get_HasAutoName()); } this.deck_editor_saver.set_UnsavedChanges(false); }
/// <summary> /// 添加摊牌的玩家 /// </summary> /// <param name="self"></param> /// <param name="ChairId"></param> /// <param name="Cards"></param> public static void AddShowCardGamer(this DeckComponent self, ushort ChairId, byte[] Cards) { if (self.ShowCardDic.ContainsKey(ChairId)) { return; } self.ShowCardDic.Add(ChairId, Cards); }
/// <summary> /// 发指定牌数 /// </summary> /// <param name="self"></param> /// <param name="CardNumber"></param> /// <returns></returns> public static byte[] Deals(this DeckComponent self, int CardNumber) { byte[] Cards = new byte[CardNumber]; for (int i = 0; i < CardNumber; i++) { byte Card = self.library[self.CardsCount - 1]; self.library.Remove(Card); Cards[i] = Card; } return(Cards); }
/// <summary> /// 添加抢庄玩家 /// </summary> /// <param name="self"></param> /// <param name="ChairId"></param> /// <param name="RobBankerNumber"></param> public static void AddRobBankGamer(this DeckComponent self, ushort ChairId, byte RobBankerNumber) { if (RobBankerNumber == 0) { RobBankerNumber = 1; } if (self.RobBankerDic.ContainsKey(ChairId)) { return; } self.RobBankerDic.Add(ChairId, RobBankerNumber); }
/// <summary> /// 清空牌桌 /// </summary> /// <param name="self"></param> public static void Clear(this DeskCardsCacheComponent self) { DeckComponent deck = self.Entity.GetComponent <DeckComponent>(); while (self.CardsCount > 0) { Card card = self.library[self.CardsCount - 1]; self.library.Remove(card); deck.AddCard(card); } self.Rule = CardsType.None; }
/// <summary> /// 洗牌 /// </summary> /// <param name="self"></param> public static void Shuffle(this DeckComponent self) { if (self.CardsCount == 52) { Random random = new Random(); List <byte> NewCards = new List <byte>(); foreach (byte temp in self.library) { NewCards.Insert(random.Next(NewCards.Count + 1), temp); } self.library.Clear(); self.library.AddRange(NewCards); } }
/// <summary> /// 洗牌 /// </summary> public static void Shuffle(this DeckComponent self) { if (self.CardsCount == 54) { Random random = new Random(); List <Card> newCards = new List <Card>(); foreach (var card in self.library) { newCards.Insert(random.Next(newCards.Count + 1), card); } self.library.Clear(); self.library.AddRange(newCards); } }
/// <summary> /// 创建一副牌 /// </summary> private static void CreateDeck(this DeckComponent self) { //创建普通扑克 for (int color = 0; color < 4; color++) { for (int value = 0; value < 13; value++) { Card card = Card.Create(value, color); self.library.Add(card); } } //创建大小王扑克 self.library.Add(Card.Create((int)Weight.SJoker, (int)Suits.None)); self.library.Add(Card.Create((int)Weight.LJoker, (int)Suits.None)); }
/// <summary> /// 场上所有牌回收到牌库中 /// </summary> /// <param name="self"></param> public static void BackToDeck(this GameControllerComponent self) { Room room = self.GetParent <Room>(); DeckComponent deckComponent = room.GetComponent <DeckComponent>(); foreach (var gamer in room.GetAll()) { HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); while (handCards.CardsCount > 0) { byte card = handCards.library[handCards.CardsCount - 1]; handCards.PopCard(card); deckComponent.AddCard(card); } } }
private void updatePlayButton(DeckComponent deck) { bool flag = false; if (deck != null) { flag = deck.GetOne <global::H.d>().IsValidFor(DeckFormat.Standard); File.WriteAllText("deck_selection.txt", deck.get_Name()); } this.playButton.interactable = (this.getCanPlay() && deck != null && flag && this.provider.get_Data() != null && !this.provider.get_Data().GetOne <global::D.y>().A); if (deck == null) { this.playButtonTooltip.set_TooltipString(global::L.LT(Constants.OT())); return; } this.playButtonTooltip.set_TooltipString((!flag) ? global::L.LT(Constants.Ot()) : string.Empty); }
private void open() { this.setCanvasGroupsForSelectableItems(true); DataComposition data = this.provider.get_Data(); bool canPlay = this.getCanPlay(); this.setIsVersusUnavailable(canPlay); int value; switch (data.GetOne <global::b.P>().get_Mode()) { case DeckSelectMode.FriendChallenge: value = 3; goto IL_A4; case DeckSelectMode.Gauntlet: value = 4; goto IL_A4; case DeckSelectMode.Play: { value = 2; AIDifficulties selected = data.GetOne <global::e.a>().get_Selected(); this.dialogAnimator.SetInteger(Constants.OQ(), (int)selected); this.SetPlayMode(data.GetOne <global::e.A>().get_Mode(), new bool?(data.GetOne <global::e.A>().get_IsRanked())); goto IL_A4; } } value = 0; IL_A4: DeckComponent selected2 = data.GetOne <global::e.B>().get_Selected(); this.dialogAnimator.SetInteger(Constants.Oq(), value); bool value2 = selected2 != null; this.dialogAnimator.SetBool(Constants.OR(), value2); if (!this.UpdateState()) { global::D.Y.Modes mode = data.GetOne <global::e.A>().get_Mode(); this.dialogAnimator.SetInteger(Constants.Or(), (mode != global::D.Y.Modes.Practice) ? 1 : 0); } this.dialogAnimator.enabled = true; this.dialogAnimator.SetTrigger(Constants.OS()); this.updatePlayButton(selected2); }
/// <summary> /// 创建一副牌 /// </summary> private static void CreateDeck(this DeckComponent self) { //创建普通扑克 for (int color = 0; color < 4; color++) { for (int value = 0; value < 13; value++) { Weight w = (Weight)value; Suits s = (Suits)color; Card card = new Card(w, s); self.library.Add(card); } } //创建大小王扑克 self.library.Add(new Card(Weight.SJoker, Suits.None)); self.library.Add(new Card(Weight.LJoker, Suits.None)); }
protected override async Task Run(Gamer entity, Actor_GamerBet_Ntt message) { Room room = RoomHelp.GetRoom(entity.RoomID); DeckComponent deck = room.GetComponent <DeckComponent>(); deck.AddBetGamer(message.ChairId, message.BetNumber); room.Broadcast(new Actor_BetResult_Ntt() { ChairId = message.ChairId, BetNumber = message.BetNumber }); if (deck.IsBetAll()) { //开始摊牌 room.Broadcast(new Actor_StartShowHand_Ntt()); } await Task.CompletedTask; }
/// <summary> /// 创建一副牌 /// </summary> private static void CreateDeck(this DeckComponent self) { //创建普通扑克 for (byte color = 0; color < 4; color++) { for (byte value = 1; value <= 13; value++) { byte bCard = 0; byte bColor = 0; byte bValue = value; bColor = (byte)((color << 4)); bCard = (byte)(bColor | bValue); self.library.Add(bCard); } } //创建大小王扑克 无大小王 //self.library.Add(new Card(Weight.SJoker, Suits.None)); //self.library.Add(new Card(Weight.LJoker, Suits.None)); }
/// <summary> /// 场上的所有牌回到牌库中 /// </summary> /// <param name="self"></param> public static void BackToDeck(this GameControllerComponent self) { Room room = self.GetEntity <Room>(); DeckComponent deckComponent = room.GetComponent <DeckComponent>(); DeskCardsCacheComponent deskCardsCache = room.GetComponent <DeskCardsCacheComponent>(); //回收牌桌卡牌 deskCardsCache.Clear(); deskCardsCache.LordCards.Clear(); //回收玩家手牌 foreach (var gamer in room.GetAll()) { HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); while (handCards.CardsCount > 0) { Card card = handCards.Library[handCards.CardsCount - 1]; handCards.PopCard(card); deckComponent.AddCard(card); } } }
/// <summary> /// 向牌库中添加牌 /// </summary> /// <param name="card"></param> public static void AddCard(this DeckComponent self, Card card) { self.library.Add(card); }
public static void Awake(this DeckComponent self) { self.CreateDeck(); }
protected override IEnumerator execute() { DeckEditScene scene = Finder.FindOrThrow <DeckEditScene>(); EditDeckProvider sceneProvider = DataProvider.Get <EditDeckProvider>(); CommandExecutor executor = Finder.FindOrThrow <CommandExecutor>(); bool flag = true; LocalizedString failure = null; if (flag && scene.get_Tutorial() != null) { global::h.L request = new global::h.L(); Coroutine coroutine; scene.get_Tutorial().EndorseRequest(request, out coroutine); if (coroutine != null) { yield return(coroutine); } flag = !request.get_Denied(); request = null; } if (flag) { if (scene.get_Validator().IsSaveValid(out failure)) { SaveDeckToServer save = new SaveDeckToServer(this.deckSave.editor.AsSerializableDeck()); yield return(executor.Execute(save)); if (save.get_Success()) { DeckComponent deckComponent = Finder.FindOrThrow <Decks>().get_All()[save.get_SavedDeck().A]; if (!scene.get_Validator().DeckMeetsMinimumCount()) { DataComposition dataComposition = global::h.o.Create(global::L.LT(Constants.FN()), global::L.LT(Constants.Fn(), new object[] { scene.get_Validator().DeckCountMinimum() }), false, new string[] { Constants.FO() }); dataComposition.Add <global::e.b>(new global::e.b(Constants.Fo())); ShowDialog command = new ShowDialog(this.dialogPrefab, dataComposition); yield return(executor.Execute(command)); } this.Success = true; this.deckSave.set_UnsavedChanges(false); Archetypes archetypes = Finder.FindOrThrow <Archetypes>(); Pile pile; if (deckComponent != null && deckComponent.get_Piles().TryGetValue(Constants.K(), out pile)) { string text = ""; foreach (KeyValuePair <ArchetypeID, int> keyValuePair2 in pile) { text = string.Concat(new object[] { text, archetypes.get_All()[keyValuePair2.Key].GetOne <NameData>().get_Name(), " ", keyValuePair2.Value, "\r\n" }); } File.WriteAllText(Path.Combine("decks", deckComponent.get_Name() + ".txt"), text); } deckComponent = null; pile = null; deckComponent = null; pile = null; } else { DataComposition dataComposition2 = global::h.o.Create(global::L.LT(Constants.FP()), global::L.LT(Constants.Fp()), false, new string[] { global::L.LT(Constants.FO()) }); dataComposition2.Add <global::e.b>(new global::e.b(Constants.Fo())); ShowDialog command2 = new ShowDialog(this.dialogPrefab, dataComposition2); yield return(executor.Execute(command2)); yield return(executor.Execute(new ChangeScene(sceneProvider.get_SceneToExitTo()))); } save = null; } } else { this.Success = false; if (failure != null) { yield return(executor.Execute(new FailFeedbackCommand(failure))); } } yield break; yield break; }
/// <summary> /// 准备开始游戏 /// </summary> /// <param name="self"></param> public static async void ReadyStartGame(this GameControllerComponent self) { Room room = self.GetParent <Room>(); Gamer[] gamers = room.GetAll(); if (room.State == RoomState.Game) { DeckComponent deck = room.GetComponent <DeckComponent>(); Log.Info($"当前准备的玩家个数:{deck.XJReady}"); if (deck.XJReady == self.Config.PlayerCount) { Log.Info("重新开始游戏"); //重置庄 foreach (Gamer gamer in gamers) { gamer.IsRobBanker = false; gamer.GetComponent <HandCardsComponent>().Reset(); } //重新洗牌 self.DealCards(); //清理缓存数据 deck.Reset(); //发送游戏开始 room.Broadcast(new Actor_GamerStart_Ntt()); await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000); //发送手牌 foreach (var _gamer in gamers) { ActorMessageSender actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender(); actorProxy.Send(new Actor_SendCard_Ntt() { Cards = _gamer.GetComponent <HandCardsComponent>().GetAll() }); Log.Info($"{_gamer.UserID}手牌:{_gamer.GetComponent<HandCardsComponent>().ShowAllCard()}"); } await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000); } } if (room.State == RoomState.Idle) { if (room.Count == self.Config.PlayerCount && gamers.Count(model => model.IsReady) == self.Config.PlayerCount) { room.State = RoomState.Game; //所有玩家准备!! //发送游戏开始 room.Broadcast(new Actor_GamerStart_Ntt()); await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000); self.DealCards(); foreach (var _gamer in gamers) { ActorMessageSender actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender(); actorProxy.Send(new Actor_SendCard_Ntt() { Cards = _gamer.GetComponent <HandCardsComponent>().GetAll() }); Log.Info($"{_gamer.UserID}手牌:{_gamer.GetComponent<HandCardsComponent>().ShowAllCard()}"); } await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000); Log.Info("可以开始出牌了"); } } }
protected override async Task Run(Gamer entity, Actor_ShowHandCard_Ntt message) { Room room = RoomHelp.GetRoom(entity.RoomID); DeckComponent deck = room.GetComponent <DeckComponent>(); HandCardsComponent handCardsComponent = entity.GetComponent <HandCardsComponent>(); //排序 byte CardType = handCardsComponent.Sort(); //得到排序后的手牌 byte[] HandCards = handCardsComponent.GetAll(); //记录 deck.AddShowCardGamer(entity.uChairID, HandCards); room.Broadcast(new Actor_ShowHandResult_Ntt() { ChairId = entity.uChairID, Cards = HandCards, CardType = CardType }); if (deck.IsShowCardAll()) { //如果所有玩家都摊牌了 Log.Info("所有玩家都摊牌了"); //判断牌最大的玩家 Gamer[] gamers = room.GetAll(); //找到庄 Gamer BankerGamer = gamers.Single(model => model.IsRobBanker); byte BankerCardType = BankerGamer.GetComponent <HandCardsComponent>().CardType; //找到比庄大的玩家 var MoreTranBanker = gamers.Where(model => model.GetComponent <HandCardsComponent>().CardType > BankerCardType); //找到比庄小的玩家 var LessTranBanker = gamers.Where(model => model.GetComponent <HandCardsComponent>().CardType < BankerCardType); int AllMultiple = 0; //赢的玩家处理 foreach (Gamer gamer in MoreTranBanker) { int Multiple = 0; Multiple = gamer.GetComponent <HandCardsComponent>().CardTypeMultiple * deck.GetOrderPlayerBet_Bet(gamer.uChairID) * deck.GetOrderPlayerBet_RobBanker(gamer.uChairID); gamer.SingleMultiple = Multiple; gamer.AllMultiple += Multiple; AllMultiple -= Multiple; } //输的玩家处理 foreach (Gamer gamer in LessTranBanker) { int Multiple = 0; Multiple = BankerGamer.GetComponent <HandCardsComponent>().CardTypeMultiple * deck.GetOrderPlayerBet_Bet(gamer.uChairID) * deck.GetOrderPlayerBet_RobBanker(gamer.uChairID); gamer.SingleMultiple = -Multiple; gamer.AllMultiple += -Multiple; AllMultiple += Multiple; } //庄的得分 BankerGamer.SingleMultiple = AllMultiple; BankerGamer.AllMultiple += AllMultiple; List <XJResultInfo> ResultList = new List <XJResultInfo>(); foreach (Gamer gamer in gamers) { XJResultInfo result = new XJResultInfo(); result.ChairId = gamer.uChairID; result.AllScore = gamer.AllMultiple; result.XJScore = gamer.SingleMultiple; ResultList.Add(result); } room.Broadcast(new Actor_XJGameResult_Ntt() { XJResult = ResultList }); //foreach (Gamer gamer in MoreTranBanker) //{ // gamer.GetComponent<HandCardsComponent>().CardTypeMultiplp //} } await Task.CompletedTask; }
public void Load(DeckComponent deck) { this.local_deck = deck; this.loadDeck(deck); }