/** * 获得提示所需的基础牌,不包含所带的牌 */ public static function getPromptBaseCards($lastCard, $cardNos) { $promptArr = array(); $cardInfo = CardUtil::cardNosToNums($cardNos); $cardNums = $cardInfo['nums']; //卡牌值对应数量 $valNos = $cardInfo['valNos']; //卡牌值对应卡牌编号 $cardValues = $cardInfo['values']; //卡牌对应的值 $maxSameVal = $cardInfo['maxSameVal']; //最多相同的值 $maxLen = $cardInfo['maxLen']; //最多相同的数量 $lastType = $lastCard['type']; $minVal = $lastCard['minValue']; $num = $lastCard['num']; if ($lastType == Constants::CARD_TYPE_BOMB) { $promptArr = CardPrompt::getSimplePrompt($minVal, $cardNums, $valNos, $promptArr, 4); } if ($lastType == Constants::CARD_TYPE_SINGLE) { $promptArr = CardPrompt::getSimplePrompt($minVal, $cardNums, $valNos, $promptArr, 1); } else { if ($lastType == Constants::CARD_TYPE_DOUBLE) { $promptArr = CardPrompt::getSimplePrompt($minVal, $cardNums, $valNos, $promptArr, 2); } else { if ($lastType == Constants::CARD_TYPE_THREE) { $promptArr = CardPrompt::getSimplePrompt($minVal, $cardNums, $valNos, $promptArr, 3); } else { if ($lastType == Constants::CARD_TYPE_SINGLE_STRAIGHT) { $promptArr = CardPrompt::getStraightPrompt($minVal, $num, $cardNums, $valNos, $promptArr, 1); } else { if ($lastType == Constants::CARD_TYPE_DOUBLE_STRAIGHT) { $promptArr = CardPrompt::getStraightPrompt($minVal, $num, $cardNums, $valNos, $promptArr, 2); } else { if ($lastType == Constants::CARD_TYPE_THREE_STRAIGHT) { $promptArr = CardPrompt::getStraightPrompt($minVal, $num, $cardNums, $valNos, $promptArr, 3); } } } } } } return $promptArr; }
/** * 未对table进行存储 * 下一个出牌 * op 1手动操作了,0未手动操作 */ public function nextPlay($playCardNos = array(), $op = 0) { $currOpUid = $this->currOpUid; $this->lastOpUid = $currOpUid; $this->noPlayNums[$currOpUid] = isset($this->noPlayNums[$currOpUid]) ? $this->noPlayNums[$currOpUid] : 0; $this->noPlayNums[$currOpUid] = $op == 0 ? (int) $this->noPlayNums[$currOpUid] + 1 : 0; //托管,则自动出牌 $currUidCards = $this->playerCards[$currOpUid]; if (count($playCardNos) == 0) { if (count($this->lastCardNos) == 0) { if (CardUtil::checkCards($currUidCards)) { $playCardNos = $currUidCards; } else { end($currUidCards); //取最小牌 $no = current($currUidCards); $val = (int) ($no / 10); foreach ($currUidCards as $cardNo) { if ($val == (int) ($cardNo / 10)) { $playCardNos[] = $cardNo; } } } } elseif ($op == 0) { $promptArrs = CardPrompt::getPromptCards($this->lastCardNos, $currUidCards); $promptArrs && $promptArrs[0] && ($playCardNos = $promptArrs[0]); rsort($playCardNos); } } $playCardData = CardUtil::checkPlayCards($this, $playCardNos); if ($playCardData && self::isExistCards($currUidCards, $playCardNos)) { //出牌成功,发送出牌信息-出牌玩家、所出的牌(无牌则为不出) //---客户端重置对手的手牌数量或重置自己的牌 //是否炸弹、牌局倍数 $re['isBomb'] = 0; $re['isSpring'] = 0; if ($playCardData['type'] == Constants::CARD_TYPE_BOMB || $playCardData['type'] == Constants::CARD_TYPE_KING) { $re['isBomb'] = 1; $this->multiple *= 2; } $currUidCards = array_diff($currUidCards, $playCardNos); $this->playerCards[$currOpUid] = $currUidCards; $this->lastCardNos = $playCardNos; $this->lastPlayCardUid = $currOpUid; $this->currOpUid = $this->getNextOpUid($currOpUid); $this->currUnPlayCnt = 0; if (count($currUidCards) == 0) { $this->tableStatus = Constants::TABLE_END; $this->currOpUid = $this->lastPlayCardUid; if ($currOpUid == $this->landlordUid) { $isSpring = true; foreach ($this->playerCards as $_uid => $cards) { if ($_uid != $currOpUid && count($cards) < 17) { $isSpring = false; } } if ($isSpring) { $re['isSpring'] = 1; $this->multiple *= 2; } } //没有手牌 获胜 结算,牌局销毁-进入匹配状态 //是否春天 } $re['playCardType'] = $playCardData; //玩家所出牌的类型 } else { $this->currOpUid = $this->getNextOpUid($currOpUid); } $depositUid = 'no'; //判断是否本轮结束,本轮结束,重置上次出牌并设置上次出牌玩家为当前出牌 if ($this->currUnPlayCnt == 2) { $this->lastCardNos = array(); } $this->currUnPlayCnt++; if ($op == 0 && $this->noPlayNums[$currOpUid] >= Constants::NO_PALY_NUM_TO_DEPOSIT) { if ($this->playerStatus[$currOpUid] != Constants::PLAYER_LEAVE) { $this->playerStatus[$currOpUid] = Constants::PLAYER_DEPOSIT; } //玩家未操作,状态为托管 $depositUid = $currOpUid; } $this->recordTime = time(); TableDao::addTable($this->tableId, $this); $re['type'] = 'play'; $re['s'] = Constants::RESPONSE_SUCCESS; $re['leaveUid'] = $this->playerStatus[$currOpUid] == Constants::PLAYER_LEAVE ? $depositUid : 'no'; $re['depositUid'] = $depositUid; //本轮托管玩家 $re['lastCardNos'] = $this->lastCardNos; $re['lastPlayCardUid'] = $this->lastPlayCardUid; $re['currOpUid'] = $this->currOpUid; $re['lastOpUid'] = $this->lastOpUid; $re['lastOpCardNum'] = count($this->playerCards[$this->lastOpUid]); $re['tableSt'] = $this->tableStatus; $re['rTime'] = $this->recordTime; $re['multiple'] = $this->multiple; $uids = $this->uids; if ($this->tableStatus == Constants::TABLE_END) { $re['winUid'] = $this->lastPlayCardUid; } foreach ($uids as $_uid) { $_player = PlayerDao::getPlayer($_uid); if ($_player && $_player->tableId == $this->tableId) { Gateway::sendToUid($_uid, json_encode($re)); } } if ($this->tableStatus == Constants::TABLE_END) { $this->tableOver($this->lastPlayCardUid); } }